diff --git a/app/Http/Home/Controllers/HelpController.php b/app/Http/Home/Controllers/HelpController.php
index 6ea78c31..ff1dfc70 100644
--- a/app/Http/Home/Controllers/HelpController.php
+++ b/app/Http/Home/Controllers/HelpController.php
@@ -30,6 +30,8 @@ class HelpController extends Controller
return $this->response->redirect($location);
}
+ $featuredCourses = $this->getFeaturedCourses();
+
$service = new HelpListService();
$items = $service->handle();
@@ -37,6 +39,7 @@ class HelpController extends Controller
$this->seo->prependTitle('帮助');
$this->view->setVar('items', $items);
+ $this->view->setVar('featured_courses', $featuredCourses);
}
/**
diff --git a/app/Http/Home/Views/article/show.volt b/app/Http/Home/Views/article/show.volt
index e4dda5af..98dbb75c 100644
--- a/app/Http/Home/Views/article/show.volt
+++ b/app/Http/Home/Views/article/show.volt
@@ -4,6 +4,8 @@
{{ partial('macros/article') }}
+ {% set share_url = share_url('article',article.id,auth_user.id) %}
+ {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
{% set article_edit_url = url({'for':'home.article.edit','id':article.id}) %}
{% set article_delete_url = url({'for':'home.article.delete','id':article.id}) %}
{% set article_private_url = url({'for':'home.article.private','id':article.id}) %}
@@ -102,9 +104,6 @@
{{ partial('article/sticky') }}
- {% set share_url = full_url({'for':'home.share'},{'id':article.id,'type':'article'}) %}
- {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
-
diff --git a/app/Http/Home/Views/chapter/live/active.volt b/app/Http/Home/Views/chapter/live/active.volt
index fdbb1946..a6b4753a 100644
--- a/app/Http/Home/Views/chapter/live/active.volt
+++ b/app/Http/Home/Views/chapter/live/active.volt
@@ -2,6 +2,8 @@
{% block content %}
+ {% set share_url = full_url('chapter',chapter.id,auth_user.id) %}
+ {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
{% set course_url = url({'for':'home.course.show','id':chapter.course.id}) %}
{% set learning_url = url({'for':'home.chapter.learning','id':chapter.id}) %}
{% set live_chats_url = url({'for':'home.live.chats','id':chapter.id}) %}
@@ -58,9 +60,6 @@
- {% set share_url = full_url({'for':'home.share'},{'id':chapter.id,'type':'chapter'}) %}
- {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
-
diff --git a/app/Http/Home/Views/chapter/read.volt b/app/Http/Home/Views/chapter/read.volt
index 534d3f38..2566d51d 100644
--- a/app/Http/Home/Views/chapter/read.volt
+++ b/app/Http/Home/Views/chapter/read.volt
@@ -2,6 +2,8 @@
{% block content %}
+ {% set share_url = full_url('chapter',chapter.id,auth_user.id) %}
+ {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
{% set course_url = url({'for':'home.course.show','id':chapter.course.id}) %}
{% set learning_url = url({'for':'home.chapter.learning','id':chapter.id}) %}
@@ -44,9 +46,6 @@
- {% set share_url = full_url({'for':'home.share'},{'id':chapter.id,'type':'chapter'}) %}
- {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
-
diff --git a/app/Http/Home/Views/chapter/vod.volt b/app/Http/Home/Views/chapter/vod.volt
index 52044075..0226cd4d 100644
--- a/app/Http/Home/Views/chapter/vod.volt
+++ b/app/Http/Home/Views/chapter/vod.volt
@@ -2,6 +2,8 @@
{% block content %}
+ {% set share_url = share_url('chapter',chapter.id,auth_user.id) %}
+ {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
{% set course_url = url({'for':'home.course.show','id':chapter.course.id}) %}
{% set learning_url = url({'for':'home.chapter.learning','id':chapter.id}) %}
@@ -47,9 +49,6 @@
- {% set share_url = full_url({'for':'home.share'},{'id':chapter.id,'type':'chapter'}) %}
- {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
-
diff --git a/app/Http/Home/Views/course/show.volt b/app/Http/Home/Views/course/show.volt
index 5d429389..b3a60cca 100644
--- a/app/Http/Home/Views/course/show.volt
+++ b/app/Http/Home/Views/course/show.volt
@@ -4,6 +4,9 @@
{{ partial('macros/course') }}
+ {% set share_url = share_url('course',course.id,auth_user.id) %}
+ {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
+
首页
@@ -93,9 +96,6 @@
{{ partial('course/sticky') }}
- {% set share_url = full_url({'for':'home.share'},{'id':course.id,'type':'course'}) %}
- {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
-
diff --git a/app/Http/Home/Views/help/index.volt b/app/Http/Home/Views/help/index.volt
index c691a0e4..71003dcb 100644
--- a/app/Http/Home/Views/help/index.volt
+++ b/app/Http/Home/Views/help/index.volt
@@ -2,6 +2,8 @@
{% block content %}
+ {{ partial('macros/course') }}
+
diff --git a/app/Http/Home/Views/help/show.volt b/app/Http/Home/Views/help/show.volt
index 0ccb2c8a..a816ca07 100644
--- a/app/Http/Home/Views/help/show.volt
+++ b/app/Http/Home/Views/help/show.volt
@@ -4,12 +4,20 @@
{{ partial('macros/course') }}
+ {% set share_url = share_url('help',help.id,auth_user.id) %}
+ {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
+
@@ -34,6 +42,12 @@
+
+
+
+
+
+
{% endblock %}
{% block link_css %}
diff --git a/app/Http/Home/Views/page/show.volt b/app/Http/Home/Views/page/show.volt
index 1a7f6af4..67ee4643 100644
--- a/app/Http/Home/Views/page/show.volt
+++ b/app/Http/Home/Views/page/show.volt
@@ -4,11 +4,19 @@
{{ partial('macros/course') }}
+ {% set share_url = share_url('page',page.id,auth_user.id) %}
+ {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
+
@@ -33,6 +41,12 @@
+
+
+
+
+
+
{% endblock %}
{% block link_css %}
diff --git a/app/Http/Home/Views/question/show.volt b/app/Http/Home/Views/question/show.volt
index 9f1f37a1..6f08ca1b 100644
--- a/app/Http/Home/Views/question/show.volt
+++ b/app/Http/Home/Views/question/show.volt
@@ -4,6 +4,8 @@
{{ partial('macros/question') }}
+ {% set share_url = share_url('question',question.id,auth_user.id) %}
+ {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
{% set question_report_url = url({'for':'home.report.add'},{'item_id':question.id,'item_type':107}) %}
{% set question_edit_url = url({'for':'home.question.edit','id':question.id}) %}
{% set question_delete_url = url({'for':'home.question.delete','id':question.id}) %}
@@ -98,9 +100,6 @@
{{ partial('question/sticky') }}
- {% set share_url = full_url({'for':'home.share'},{'id':question.id,'type':'question'}) %}
- {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
-
diff --git a/app/Http/Home/Views/user/show.volt b/app/Http/Home/Views/user/show.volt
index 0f4517cb..29b4684d 100644
--- a/app/Http/Home/Views/user/show.volt
+++ b/app/Http/Home/Views/user/show.volt
@@ -4,6 +4,8 @@
{{ partial('macros/user') }}
+ {% set share_url = share_url('user',user.id,auth_user.id) %}
+ {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
{% set avatar_class = user.vip == 1 ? 'avatar vip' : 'avatar' %}
- {% set share_url = full_url({'for':'home.share'},{'id':user.id,'type':'user'}) %}
- {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
-
diff --git a/app/Library/Helper.php b/app/Library/Helper.php
index 69b50c1a..0240e6ec 100644
--- a/app/Library/Helper.php
+++ b/app/Library/Helper.php
@@ -8,8 +8,8 @@
use App\Caches\Setting as SettingCache;
use App\Library\Purifier as HtmlPurifier;
use App\Library\Validators\Common as CommonValidator;
+use App\Services\Logic\Url\ShareUrl as ShareUrlService;
use App\Services\Storage as StorageService;
-use Koogua\Ip2Region\Searcher as Ip2RegionSearcher;
use Phalcon\Config;
use Phalcon\Di;
use Phalcon\Text;
@@ -727,6 +727,21 @@ function kg_full_url($uri, $args = null)
return $baseUrl . $url->get($uri, $args);
}
+/**
+ * 构造分享url
+ *
+ * @param string $type
+ * @param int $id
+ * @param int $referer
+ * @return string
+ */
+function kg_share_url($type, $id, $referer = 0)
+{
+ $service = new ShareUrlService();
+
+ return $service->handle($type, $id, $referer);
+}
+
/**
* 获取H5首页地址
*
diff --git a/app/Providers/Volt.php b/app/Providers/Volt.php
index eedcb6be..1e4b4e3a 100644
--- a/app/Providers/Volt.php
+++ b/app/Providers/Volt.php
@@ -39,6 +39,10 @@ class Volt extends Provider
return 'kg_full_url(' . $resolvedArgs . ')';
});
+ $compiler->addFunction('share_url', function ($resolvedArgs) {
+ return 'kg_share_url(' . $resolvedArgs . ')';
+ });
+
$compiler->addFunction('static_url', function ($resolvedArgs) {
return 'kg_static_url(' . $resolvedArgs . ')';
});
diff --git a/app/Services/Logic/Url/FullH5Url.php b/app/Services/Logic/Url/FullH5Url.php
new file mode 100644
index 00000000..eabc5e3a
--- /dev/null
+++ b/app/Services/Logic/Url/FullH5Url.php
@@ -0,0 +1,192 @@
+baseUrl = $this->getBaseUrl();
+ }
+
+ public function getHomeUrl()
+ {
+ return $this->getFullUrl('/index/index');
+ }
+
+ public function getAccountRegisterUrl()
+ {
+ return $this->getFullUrl('/account/register');
+ }
+
+ public function getAccountLoginUrl()
+ {
+ return $this->getFullUrl('/account/login');
+ }
+
+ public function getAccountForgetUrl()
+ {
+ return $this->getFullUrl('/account/forget');
+ }
+
+ public function getVipIndexUrl()
+ {
+ return $this->getFullUrl('/vip/index');
+ }
+
+ public function getHelpIndexUrl()
+ {
+ return $this->getFullUrl('/help/index');
+ }
+
+ public function getCourseListUrl()
+ {
+ return $this->getFullUrl('/course/list');
+ }
+
+ public function getArticleListUrl()
+ {
+ return $this->getFullUrl('/article/list');
+ }
+
+ public function getQuestionListUrl()
+ {
+ return $this->getFullUrl('/question/list');
+ }
+
+ public function getLiveListUrl()
+ {
+ return $this->getFullUrl('/live/list');
+ }
+
+ public function getTeacherListUrl()
+ {
+ return $this->getFullUrl('/teacher/list');
+ }
+
+ public function getFlashSaleListUrl()
+ {
+ return $this->getFullUrl('/flash-sale/list');
+ }
+
+ public function getPointGiftListUrl()
+ {
+ return $this->getFullUrl('/point/gift/list');
+ }
+
+ public function getPageInfoUrl($id)
+ {
+ return $this->getFullUrl('/page/info', ['id' => $id]);
+ }
+
+ public function getHelpInfoUrl($id)
+ {
+ return $this->getFullUrl('/help/info', ['id' => $id]);
+ }
+
+ public function getArticleInfoUrl($id)
+ {
+ return $this->getFullUrl('/article/info', ['id' => $id]);
+ }
+
+ public function getQuestionInfoUrl($id)
+ {
+ return $this->getFullUrl('/question/info', ['id' => $id]);
+ }
+
+ public function getAnswerInfoUrl($id)
+ {
+ return $this->getFullUrl('/answer/info', ['id' => $id]);
+ }
+
+ public function getTopicInfoUrl($id)
+ {
+ return $this->getFullUrl('/topic/info', ['id' => $id]);
+ }
+
+ public function getPackageInfoUrl($id)
+ {
+ return $this->getFullUrl('/package/info', ['id' => $id]);
+ }
+
+ public function getCourseInfoUrl($id)
+ {
+ return $this->getFullUrl('/course/info', ['id' => $id]);
+ }
+
+ public function getChapterInfoUrl($id)
+ {
+ $chapterRepo = new ChapterRepo();
+
+ $chapter = $chapterRepo->findById($id);
+
+ if ($chapter->model == CourseModel::MODEL_VOD) {
+ return $this->getFullUrl('/chapter/vod', ['id' => $id]);
+ } elseif ($chapter->model == CourseModel::MODEL_LIVE) {
+ return $this->getFullUrl('/chapter/live', ['id' => $id]);
+ } elseif ($chapter->model == CourseModel::MODEL_READ) {
+ return $this->getFullUrl('/chapter/read', ['id' => $id]);
+ } else {
+ return $this->getHomeUrl();
+ }
+ }
+
+ public function getUserIndexUrl($id)
+ {
+ return $this->getFullUrl('/user/index', ['id' => $id]);
+ }
+
+ public function getTeacherIndexUrl($id)
+ {
+ return $this->getFullUrl('/teacher/index', ['id' => $id]);
+ }
+
+ public function getPointGiftInfoUrl($id)
+ {
+ return $this->getFullUrl('/point/gift/info', ['id' => $id]);
+ }
+
+ protected function getFullUrl($path, $params = [])
+ {
+ $extra = ['source' => $this->source];
+
+ $data = array_merge($params, $extra);
+
+ $query = http_build_query($data);
+
+ return sprintf('%s%s?%s', $this->baseUrl, $path, $query);
+ }
+
+ protected function getBaseUrl()
+ {
+ return sprintf('%s/h5/#/pages', kg_site_url());
+ }
+
+}
diff --git a/app/Services/Logic/Url/FullWebUrl.php b/app/Services/Logic/Url/FullWebUrl.php
new file mode 100644
index 00000000..f941aba8
--- /dev/null
+++ b/app/Services/Logic/Url/FullWebUrl.php
@@ -0,0 +1,139 @@
+baseUrl = $this->getBaseUrl();
+ }
+
+ public function getHomeUrl()
+ {
+ return $this->baseUrl;
+ }
+
+ public function getVipUrl()
+ {
+ $route = $this->url->get(['for' => 'home.vip.index']);
+
+ return $this->getFullUrl($route);
+ }
+
+ public function getHelpShowUrl($id)
+ {
+ $route = $this->url->get(['for' => 'home.help.show', 'id' => $id]);
+
+ return $this->getFullUrl($route);
+ }
+
+ public function getPageShowUrl($id)
+ {
+ $route = $this->url->get(['for' => 'home.page.show', 'id' => $id]);
+
+ return $this->getFullUrl($route);
+ }
+
+ public function getArticleShowUrl($id)
+ {
+ $route = $this->url->get(['for' => 'home.article.show', 'id' => $id]);
+
+ return $this->getFullUrl($route);
+ }
+
+ public function getQuestionShowUrl($id)
+ {
+ $route = $this->url->get(['for' => 'home.question.show', 'id' => $id]);
+
+ return $this->getFullUrl($route);
+ }
+
+ public function getTopicShowUrl($id)
+ {
+ $route = $this->url->get(['for' => 'home.topic.show', 'id' => $id]);
+
+ return $this->getFullUrl($route);
+ }
+
+ public function getPackageShowUrl($id)
+ {
+ $route = $this->url->get(['for' => 'home.package.show', 'id' => $id]);
+
+ return $this->getFullUrl($route);
+ }
+
+ public function getCourseShowUrl($id)
+ {
+ $route = $this->url->get(['for' => 'home.course.show', 'id' => $id]);
+
+ return $this->getFullUrl($route);
+ }
+
+ public function getChapterShowUrl($id)
+ {
+ $route = $this->url->get(['for' => 'home.chapter.show', 'id' => $id]);
+
+ return $this->getFullUrl($route);
+ }
+
+ public function getUserShowUrl($id)
+ {
+ $route = $this->url->get(['for' => 'home.user.show', 'id' => $id]);
+
+ return $this->getFullUrl($route);
+ }
+
+ public function getTeacherShowUrl($id)
+ {
+ $route = $this->url->get(['for' => 'home.teacher.show', 'id' => $id]);
+
+ return $this->getFullUrl($route);
+ }
+
+ public function getPointGiftShowUrl($id)
+ {
+ $route = $this->url->get(['for' => 'home.point_gift.show', 'id' => $id]);
+
+ return $this->getFullUrl($route);
+ }
+
+ protected function getFullUrl($path, $params = [])
+ {
+ $extra = ['source' => $this->source];
+
+ $data = array_merge($params, $extra);
+
+ $query = http_build_query($data);
+
+ return sprintf('%s%s?%s', $this->baseUrl, $path, $query);
+ }
+
+ protected function getBaseUrl()
+ {
+ return kg_site_url();
+ }
+
+}
\ No newline at end of file
diff --git a/app/Services/Logic/Url/ShareUrl.php b/app/Services/Logic/Url/ShareUrl.php
new file mode 100644
index 00000000..7741a6b6
--- /dev/null
+++ b/app/Services/Logic/Url/ShareUrl.php
@@ -0,0 +1,228 @@
+fullWebUrl = new FullWebUrl();
+ $this->fullH5Url = new FullH5Url();
+ }
+
+ public function handle($type, $id = 0, $referer = 0)
+ {
+ if ($type == 'article') {
+ $result = $this->getArticleUrl($id);
+ } elseif ($type == 'page') {
+ $result = $this->getPageUrl($id);
+ } elseif ($type == 'question') {
+ $result = $this->getQuestionUrl($id);
+ } elseif ($type == 'course') {
+ $result = $this->getCourseUrl($id);
+ } elseif ($type == 'chapter') {
+ $result = $this->getChapterUrl($id);
+ } elseif ($type == 'user') {
+ $result = $this->getUserUrl($id);
+ } elseif ($type == 'teacher') {
+ $result = $this->getTeacherUrl($id);
+ } elseif ($type == 'topic') {
+ $result = $this->getTopicUrl($id);
+ } elseif ($type == 'package') {
+ $result = $this->getPackageUrl($id);
+ } elseif ($type == 'vip') {
+ $result = $this->getVipUrl();
+ } elseif ($type == 'point_gift') {
+ $result = $this->getPointGiftUrl($id);
+ } else {
+ $result = $this->getHomeUrl();
+ }
+
+ if ($referer > 0) {
+ $result['h5'] = $this->withReferer($result['h5'], $referer);
+ $result['web'] = $this->withReferer($result['web'], $referer);
+ }
+
+ $gotoH5 = $this->gotoH5Url();
+
+ return $gotoH5 ? $result['h5'] : $result['web'];
+ }
+
+ public function getHomeUrl()
+ {
+ $webUrl = $this->fullWebUrl->getHomeUrl();
+
+ $h5Url = $this->fullH5Url->getHomeUrl();
+
+ return ['web' => $webUrl, 'h5' => $h5Url];
+ }
+
+ public function getVipUrl()
+ {
+ $webUrl = $this->fullWebUrl->getVipUrl();
+
+ $h5Url = $this->fullH5Url->getVipIndexUrl();
+
+ return ['web' => $webUrl, 'h5' => $h5Url];
+ }
+
+ public function getHelpUrl($id)
+ {
+ $webUrl = $this->fullWebUrl->getHelpShowUrl($id);
+
+ $h5Url = $this->fullH5Url->getHelpInfoUrl($id);
+
+ return ['web' => $webUrl, 'h5' => $h5Url];
+ }
+
+ public function getPageUrl($id)
+ {
+ $webUrl = $this->fullWebUrl->getPageShowUrl($id);
+
+ $h5Url = $this->fullH5Url->getPageInfoUrl($id);
+
+ return ['web' => $webUrl, 'h5' => $h5Url];
+ }
+
+ public function getArticleUrl($id)
+ {
+ $webUrl = $this->fullWebUrl->getArticleShowUrl($id);
+
+ $h5Url = $this->fullH5Url->getArticleInfoUrl($id);
+
+ return ['web' => $webUrl, 'h5' => $h5Url];
+ }
+
+ public function getQuestionUrl($id)
+ {
+ $webUrl = $this->fullWebUrl->getQuestionShowUrl($id);
+
+ $h5Url = $this->fullH5Url->getQuestionInfoUrl($id);
+
+ return ['web' => $webUrl, 'h5' => $h5Url];
+ }
+
+ public function getTopicUrl($id)
+ {
+ $webUrl = $this->fullWebUrl->getTopicShowUrl($id);
+
+ $h5Url = $this->fullH5Url->getTopicInfoUrl($id);
+
+ return ['web' => $webUrl, 'h5' => $h5Url];
+ }
+
+ public function getPackageUrl($id)
+ {
+ $webUrl = $this->fullWebUrl->getPackageShowUrl($id);
+
+ $h5Url = $this->fullH5Url->getPackageInfoUrl($id);
+
+ return ['web' => $webUrl, 'h5' => $h5Url];
+ }
+
+ public function getCourseUrl($id)
+ {
+ $webUrl = $this->fullWebUrl->getCourseShowUrl($id);
+
+ $h5Url = $this->fullH5Url->getCourseInfoUrl($id);
+
+ return ['web' => $webUrl, 'h5' => $h5Url];
+ }
+
+ public function getChapterUrl($id)
+ {
+ $webUrl = $this->fullWebUrl->getChapterShowUrl($id);
+
+ $h5Url = $this->fullH5Url->getChapterInfoUrl($id);
+
+ return ['web' => $webUrl, 'h5' => $h5Url];
+ }
+
+ public function getUserUrl($id)
+ {
+ $webUrl = $this->fullWebUrl->getUserShowUrl($id);
+
+ $h5Url = $this->fullH5Url->getUserIndexUrl($id);
+
+ return ['web' => $webUrl, 'h5' => $h5Url];
+ }
+
+ public function getTeacherUrl($id)
+ {
+ $webUrl = $this->fullWebUrl->getTeacherShowUrl($id);
+
+ $h5Url = $this->fullH5Url->getTeacherIndexUrl($id);
+
+ return ['web' => $webUrl, 'h5' => $h5Url];
+ }
+
+ public function getPointGiftUrl($id)
+ {
+
+ $webUrl = $this->fullWebUrl->getPointGiftShowUrl($id);
+
+ $h5Url = $this->fullH5Url->getPointGiftInfoUrl($id);
+
+ return ['web' => $webUrl, 'h5' => $h5Url];
+ }
+
+ public function setTargetType($targetType)
+ {
+ $this->targetType = $targetType;
+ }
+
+ protected function withReferer($url, $referer)
+ {
+ $params = ['referer' => $referer];
+
+ if (strpos($url, '?') === false) {
+ $url .= '?' . http_build_query($params);
+ } else {
+ $url .= '&' . http_build_query($params);
+ }
+
+ return $url;
+ }
+
+ protected function gotoH5Url()
+ {
+ if (!$this->h5Enabled()) return false;
+
+ if ($this->targetType == 'h5') return true;
+
+ return $this->isMobileBrowser();
+ }
+
+}