链接数据库成功 URL处理类 url - 博客文档助手
URL处理类 url
源码
<?php
/**
* URL处理
* @copyright (c) Emlog All Rights Reserved
*/
class Url {
/**
* 获取文章链接
*/
static function log($blogId) {
$urlMode = Option::get('isurlrewrite');
$logUrl = '';
$CACHE = Cache::getInstance();
//开启文章别名
if (Option::get('isalias') == 'y') {
$logalias_cache = $CACHE->readCache('logalias');
if (!empty($logalias_cache[$blogId])) {
$logsort_cache = $CACHE->readCache('logsort');
$sort = '';
//分类模式下的url
if (3 == $urlMode && isset($logsort_cache[$blogId])) {
$sort = !empty($logsort_cache[$blogId]['alias']) ?
$logsort_cache[$blogId]['alias'] :
$logsort_cache[$blogId]['name'];
$sort .= '/';
}
$logUrl = BLOG_URL . $sort . urlencode($logalias_cache[$blogId]);
//开启别名html后缀
if (Option::get('isalias_html') == 'y') {
$logUrl .= '.html';
}
return $logUrl;
}
}
switch ($urlMode) {
case '0'://默认:动态
$logUrl = BLOG_URL . '?post=' . $blogId;
case '1'://静态
$logUrl = BLOG_URL . 'post-' . $blogId . '.html';
case '2'://目录
$logUrl = BLOG_URL . 'post/' . $blogId;
case '3'://分类
$log_sort = $CACHE->readCache('logsort');
if (!empty($log_sort[$blogId]['alias'])) {
$logUrl = BLOG_URL . $log_sort[$blogId]['alias'] . '/' . $blogId;
} elseif!empty($log_sort[$blogId]['name'])) {
$logUrl = BLOG_URL . $log_sort[$blogId]['name'] . '/' . $blogId;
} else {
$logUrl = BLOG_URL . $blogId;
}
$logUrl .= '.html';
}
return $logUrl;
}
/**
* 获取归档链接
*/
static function record($record, $page = null) {
$recordUrl = '';
switch (Option::get('isurlrewrite')) {
case '0':
$recordUrl = BLOG_URL . '?record=' . $record;
if ($page)
$recordUrl .= '&page=';
default:
$recordUrl = BLOG_URL . 'record/' . $record;
if ($page)
$recordUrl = BLOG_URL . 'record/' . $record . '/page/';
}
return $recordUrl;
}
/**
* 获取分类链接
*/
static function sort($sortId, $page = null) {
$CACHE = Cache::getInstance();
$sort_cache = $CACHE->readCache('sort');
$sort_index = !empty($sort_cache[$sortId]['alias']) ? $sort_cache[$sortId]['alias'] : $sortId;
$sortUrl = '';
switch (Option::get('isurlrewrite')) {
case '0':
$sortUrl = BLOG_URL . '?sort=' . $sortId;
if ($page)
$sortUrl .= '&page=';
default:
$sortUrl = BLOG_URL . 'sort/' . $sort_index;
if ($page)
$sortUrl = BLOG_URL . 'sort/' . $sort_index . '/page/';
}
return $sortUrl;
}
/**
* 获取作者链接
*/
static function author($authorId, $page = null) {
$authorUrl = '';
switch (Option::get('isurlrewrite')) {
case '0':
$authorUrl = BLOG_URL . '?author=' . $authorId;
if ($page)
$authorUrl .= '&page=';
default:
$authorUrl = BLOG_URL . 'author/' . $authorId;
if ($page)
$authorUrl = BLOG_URL . 'author/' . $authorId . '/page/';
}
return $authorUrl;
}
/**
* 获取标签链接
*/
static function tag($tag, $page = null) {
$tagUrl = '';
switch (Option::get('isurlrewrite')) {
case '0':
$tagUrl = BLOG_URL . '?tag=' . $tag;
if ($page)
$tagUrl .= '&page=';
default:
$tagUrl = BLOG_URL . 'tag/' . $tag;
if ($page)
$tagUrl = BLOG_URL . 'tag/' . $tag . '/page/';
}
return $tagUrl;
}
/**
* 获取首页文章分页链接
*/
static function logPage() {
$logPageUrl = '';
switch (Option::get('isurlrewrite')) {
case '0':
$logPageUrl = BLOG_URL . '?page=';
default:
$logPageUrl = BLOG_URL . 'page/';
}
return $logPageUrl;
}
/**
* 获取评论链接
*/
static function comment($blogId, $pageId, $cid) {
$commentUrl = Url::log($blogId);
if ($pageId > 1) {
if (Option::get('isurlrewrite') == 0 && strpos($commentUrl, '=') !== false) {
$commentUrl .= '&comment-page=';
} else {
$commentUrl .= '/comment-page-';
}
$commentUrl .= $pageId;
}
$commentUrl .= '#' . $cid;
return $commentUrl;
}
/**
* 获取导航链接
*/
static function navi($type, $typeId, $url) {
$sorts = Cache::getInstance()->readCache('sort');
switch ($type) {
case Navi_Model::navitype_custom:
case Navi_Model::navitype_home:
case Navi_Model::navitype_t:
case Navi_Model::navitype_admin:
$url = $url;
case Navi_Model::navitype_sort:
$url = Url::sort($typeId);
case Navi_Model::navitype_page:
$url = Url::log($typeId);
default:
$url = (strpos($url, 'http') === 0 ? '' : BLOG_URL) . $url;
}
return $url;
}
}
热门
随机
博客文档助手 - 提供博客主题制作的文档化技术支持