示例#1
0
 /**
  * 详请
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2013-02-21 13:47:40
  * @lastmodify      2013-04-26 23:13:01
  *
  * @return void 无返回值
  */
 public function detailAction()
 {
     $blog_id = Filter::int('id', 'get');
     $date = Filter::int('date', 'get');
     if (!$blog_id || !$date) {
         //非法参数
         $this->triggerError(__METHOD__ . ': ' . __LINE__ . ',' . "date=({$date}),id=({$blog_id})");
         $this->_showMessage('error' . $blog_id . $date, null, 404);
     }
     if ($blog_info = $this->_model->find($blog_id)) {
         if (date('Ymd', $blog_info['add_time']) != $date) {
             //日期与id不匹配
             $this->triggerError(__METHOD__ . ': ' . __LINE__ . ',' . "date=({$date}),id=({$blog_id})");
             $this->_showMessage('error' . $blog_id . ',' . $date, null, 404);
         }
         $filename = str_replace(BASE_SITE_URL, WWWROOT, $blog_info['link_url']);
         new_mkdir(dirname($filename));
         $o = $this->getViewTemplate('build_html')->assign('blog_info', $blog_info)->assign(array('web_title' => L('MINIBLOG,DETAIL') . TITLE_SEPARATOR . L('MINIBLOG'), 'comments_html' => $this->_getBlogComments($blog_id)));
         $content = $o->fetch(CONTROLLER_NAME, 'detail', $blog_id);
         //file_put_contents($filename, $content);
         echo $content;
     } else {
         //微博不存在
         $this->_showMessage(L('MINIBLOG,NOT_EXIST'), null, 404);
     }
 }
示例#2
0
 /**
  * 获取写缓存数据
  * @date            2012-09-05 14:22:04
  * @lastmodify      2013-01-21 15:44:59 by mrmsl
  *
  * @return mixed 查询成功,返回数组,否则false
  */
 protected function _setCacheData()
 {
     $data = $this->_model->key_column($this->_pk_field)->order('sort_order ASC,' . $this->_pk_field . ' ASC')->select();
     $path = FRONT_THEME_PATH . 'mail/';
     $suffix = C('TEMPLATE_SUFFIX');
     new_mkdir($path);
     foreach ($data as $item) {
         $template_name = $path . $item['template_name'] . $suffix;
         file_put_contents($template_name, $item['content']);
         //邮件模板
     }
     return $data;
 }
示例#3
0
 /**
  * 渲染博客列表
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2013-04-28 16:55:45
  *
  * @param string|array $cate_info 数组为分类,否则为标签
  *
  * @return void 无返回值
  */
 private function _fetchBlog($cate_info = null)
 {
     if (is_array($cate_info)) {
         //分类
         $is_tag = false;
         $cate_id = $cate_info['cate_id'];
         $table = TB_BLOG;
         $where = array('b.is_delete' => 0, 'b.is_issue' => 1);
         if ($cate_id) {
             //category.shtml
             $where['b.cate_id'] = array('IN', $this->_getChildrenIds($cate_id));
         }
         $url_tpl = str_replace('.shtml', '/page/\\1.shtml', $cate_info['link_url']);
         $cache_flag = $cate_id;
         $total = $this->_model->table(TB_BLOG)->alias('b')->where($where)->count();
         $this->_model->alias('b');
         //b.title
     } else {
         //标签
         $this->_model->table(TB_TAG)->where(array('tag' => $cate_info))->setInc('searches');
         //搜索次数+1
         $is_tag = true;
         $table = TB_BLOG . ' AS b JOIN ' . TB_TAG . ' AS t ON t.blog_id=b.blog_id';
         $where = array('t.tag' => array('IN', $cate_info), 'b.is_delete' => 0, 'b.is_issue' => 1);
         $url_tpl = BASE_SITE_URL . 'tag/' . urlencode($cate_info) . '/page/\\1.shtml';
         $cache_flag = md5(strtolower($cate_info));
         $total = $this->_model->table(TB_BLOG)->alias('b')->join(' JOIN ' . TB_TAG . ' AS t ON b.blog_id=t.blog_id')->where($where)->count('DISTINCT b.blog_id');
     }
     $page_info = Filter::page($total, 'page', PAGE_SIZE);
     $page = $page_info['page'];
     $page_one = $page < 2;
     $blog_arr = $this->_model->table($table)->where($where)->order('b.blog_id DESC')->limit($page_info['limit'])->field('b.blog_id,b.title,b.link_url,b.cate_id,b.add_time,b.summary,b.seo_keyword,b.seo_description')->select();
     $paging = new Paging(array('_url_tpl' => $url_tpl, '_total_page' => $page_info['total_page'], '_now_page' => $page, '_page_size' => PAGE_SIZE));
     $o = $this->getViewTemplate($page_one && !$is_tag ? 'build_html' : null)->assign(array('blog_arr' => $blog_arr, 'paging' => $paging->getHtml(), 'page' => $page_one ? '' : $page));
     if ($is_tag) {
         //标签
         $o->assign(array('web_title' => $cate_info . TITLE_SEPARATOR . L('TAG'), 'tag' => $cate_info, 'seo_keywords' => $cate_info));
     } else {
         //分类
         $o->assign(array('web_title' => $cate_id ? $this->nav($cate_id, 'cate_name', null, TITLE_SEPARATOR) : $cate_info['cate_name'], 'cate_info' => $cate_info, 'tag' => ''));
     }
     $content = $o->fetch(CONTROLLER_NAME, ACTION_NAME, $cache_flag . '-' . $page);
     if ($page_one && !$is_tag) {
         $filename = str_replace(BASE_SITE_URL, WWWROOT, $cate_info['link_url']);
         new_mkdir(dirname($filename));
         //file_put_contents($filename, $content);
     }
     echo $content;
 }
示例#4
0
 /**
  * 编译并获取编译文件内容
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2013-04-06 09:20:43
  *
  * @param string $controller 控制器
  * @param string $action     操作方法
  * @param string $cache_id   缓存标识。默认''
  * @param bool   $return     true返回编译文件内容。默认true
  *
  * @return string|true $return=true返回编译文件内容,否则true
  */
 public function fetch($controller = CONTROLLER_NAME, $action = ACTION_NAME, $cache_id = '', $return = true)
 {
     $controller = strtolower($controller ? $controller : CONTROLLER_NAME);
     $action = $action ? $action : ACTION_NAME;
     $compile_file = $this->compile($controller, $action);
     if (!$this->_force_compile && $this->_caching) {
         //缓存
         $cache_dir = $this->_cache_path . $controller . '/';
         new_mkdir($cache_dir);
         $cache_file = $cache_dir . $action . ($cache_id ? $cache_id : $this->_cache_id) . C('HTML_SUFFIX');
         if (is_file($cache_file) && filemtime($cache_file) > time() - $this->_cache_lifetime) {
             //缓存未过期
             if ($return) {
                 return file_get_contents($cache_file);
             }
         }
     }
     ob_start();
     extract($this->_tpl_vars, EXTR_OVERWRITE);
     require $compile_file;
     if ($return || $this->_caching) {
         //返回内容或写入缓存
         $content = ob_get_contents();
         ob_end_clean();
         if (!$this->_force_compile && $this->_caching) {
             file_put_contents($cache_file, $content);
         }
         return $content;
     }
     return true;
 }
示例#5
0
 /**
  * 生成静态页
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2013-04-12 15:01:54
  *
  * @param string $filename 文件路径
  * @param string $content  文件内容
  *
  * @return void 无返回值
  */
 protected function _buildHtml($filename, $content)
 {
     new_mkdir(dirname($filename));
     file_put_contents($filename, $content);
 }
示例#6
0
/**
 * 取字符串前N位作为目录
 *
 * @author          mrmsl <*****@*****.**>
 * @date            2013-04-17 09:08:23
 *
 * @param string $str  待取字符串
 * @param string $base 基路径。默认WWWROOT,网站根目录
 * @param int    $n    前N位
 *
 * @return string 路径
 */
function get_substr_dir($str, $base = WWWROOT, $n = 4)
{
    $dir = $base;
    if ('/' != substr($dir, -1)) {
        $dir .= '/';
    }
    $dir .= strlen($str) > $n ? substr($str, 0, $n) : $str;
    $dir .= '/';
    new_mkdir($dir);
    return $dir;
}
示例#7
0
 /**
  * 详请
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2013-02-21 15:26:00
  * @lastmodify      2013-04-23 14:32:00 by mrmsl
  *
  * @return void 无返回值
  */
 public function detailAction()
 {
     $blog_id = Filter::int('id', 'get');
     $date = Filter::int('date', 'get');
     if (!$blog_id || !$date) {
         //非法参数
         $this->triggerError(__METHOD__ . ': ' . __LINE__ . ',' . "date=({$date}),id=({$blog_id})");
         $this->_showMessage('error' . $blog_id . $date, null, 404);
     }
     if ($blog_info = $this->_model->find($blog_id)) {
         if (date('Ymd', $blog_info['add_time']) != $date) {
             //日期与id不匹配
             $this->triggerError(__METHOD__ . ': ' . __LINE__ . ',' . "date=({$date}),id=({$blog_id})");
             $this->_showMessage('error' . $blog_id . ',' . $date, null, 404);
         }
         if (!$blog_info['is_issue'] || $blog_info['is_delete']) {
             //未发布或已删除
             $this->triggerError(__METHOD__ . ': ' . __LINE__ . ',' . "is_delete=({$blog_info['is_delete']}),is_issue=({$blog_info['is_issue']})");
             $this->_showMessage('error' . $blog_info['is_issue'] . ',' . $blog_info['is_delete'], null, 404);
         }
         $filename = str_replace(BASE_SITE_URL, WWWROOT, $blog_info['link_url']);
         new_mkdir(dirname($filename));
         $o = $this->getViewTemplate('build_html')->assign($this->_getNextAndPrevBlog($blog_id))->assign('blog_info', $blog_info)->assign(array('web_title' => $blog_info['title'] . TITLE_SEPARATOR . $this->nav($blog_info['cate_id'], 'cate_name', 'Category', TITLE_SEPARATOR) . TITLE_SEPARATOR . L('CN_WANGWEN'), 'seo_keywords' => $blog_info['seo_keyword'], 'seo_description' => $blog_info['seo_description'], 'tags' => $this->tags($blog_info['seo_keyword']), 'relative_blog' => $this->_getRelativeBlog($blog_id, $blog_info['seo_keyword']), 'comments_html' => $this->_getBlogComments($blog_id)));
         $content = $o->fetch(CONTROLLER_NAME, 'detail', $blog_id);
         //file_put_contents($filename, $content);
         echo $content;
     } else {
         //博客不存在
         $this->_showMessage(L('BLOG,NOT_EXIST'), null, 404);
     }
 }
示例#8
0
 /**
  * 写日志
  *
  * @author          liu21st <*****@*****.**>
  * @lastmodify      2013-01-17 09:26:44 by mrmsl
  *
  * @param string $message       日志信息。默认'',取已保存日志
  * @param string $destination   写入目标。默认'',日志路径+Y/md/+文件名
  * @param int    $type          日志记录方式。默认'',取C('LOG_TYPE')
  * @param string $extra         额外信息。默认''
  *
  * @return void 无返回值
  */
 public static function write($message = '', $destination = '', $type = '', $extra = '')
 {
     $log = $message ? $message : join(PHP_EOL, self::$log);
     if (!$log) {
         return;
     }
     $log .= PHP_EOL;
     $now = new_date(self::$date_format);
     $type = $type ? $type : C('LOG_TYPE');
     if (!$type || self::FILE == $type) {
         //文件方式记录日志
         if (defined('TODAY_LOG_PATH')) {
             $log_path = TODAY_LOG_PATH;
         } else {
             new_mkdir($log_path = LOG_PATH . new_date('Y/md/'));
             define('TODAY_LOG_PATH', $log_path);
         }
         if ('' === $destination) {
             $filename = 'php' . C('LOG_FILE_SUFFIX');
         } elseif ($destination) {
             if (false === strpos($destination, C('LOG_FILE_SUFFIX'))) {
                 //sql.log, slowquery.log, errorsql.log...
                 $filename = $destination . C('LOG_FILE_SUFFIX');
             }
         }
         $destination = empty($filename) ? $destination : $log_path . $filename;
         //检测日志文件大小,超过配置大小则备份日志文件重新生成
         if (is_file($destination) && ($filesize = sys_config('sys_log_filesize')) && $filesize * 1024 <= filesize($destination)) {
             rename($destination, $log_path . basename($filename, C('LOG_FILE_SUFFIX')) . new_date('_His') . C('LOG_FILE_SUFFIX'));
         }
     } else {
         $destination = $destination ? $destination : C('LOG_DEST');
         $extra = $extra ? $extra : C('LOG_EXTRA');
     }
     if (APP_DEBUG && strpos($log, 'PHP ')) {
         //调试模式,输出php错误
         send_http_status(HTTP_STATUS_SERVER_ERROR);
         if (!IS_AJAX) {
             echo nl2br($log);
         }
     }
     error_log($log, $type, $destination, $extra);
 }
 /**
  * 生成缓存
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2013-03-21 13:38:34
  *
  * @return object $this
  */
 public function createAction()
 {
     $data = $this->_model->order('parent_id ASC,is_show DESC,sort_order ASC, cate_id ASC')->index($this->_pk_field)->select();
     if ($data === false) {
         $this->_ajaxReturn(false, L('CREATE_CATEGORY_CACHE,FAILURE'), 'EXIT');
     }
     new_mkdir($ssi_path = SSI_PATH . 'category/');
     $suffix = C('HTML_SUFFIX');
     $nav = '<a href="' . BASE_SITE_URL . 'category' . $suffix . '">' . L('CN_WANGWEN') . '</a>' . BREAD_SEPARATOR;
     file_put_contents($ssi_path . 'nav0' . $suffix, $nav);
     foreach ($data as $v) {
         //生成分类ssi导航
         $html = $nav;
         foreach (explode(',', $v['node']) as $item) {
             $info = $data[$item];
             $html .= '<a href="' . $info['link_url'] . '">' . $info['cate_name'] . '</a>' . BREAD_SEPARATOR;
         }
         file_put_contents($ssi_path . 'nav' . $v[$this->_pk_field] . $suffix, $html);
     }
     $tree_data = Tree::array2tree($data, $this->_pk_field);
     //树形式
     return $this->cache(null, null, $data)->cache(null, $this->_getControllerName() . '_tree', $tree_data);
 }