Beispiel #1
0
 private function getArticle($article_id)
 {
     $params = array();
     $params = array('eq' => array('article_id' => $article_id));
     if (!$this->is_root) {
         $params['lt'] = array('category_id' => 5);
     }
     $article = Repository::findOneFromArticle($params);
     if ($article == false) {
         header("Location: /index/notfound");
         return;
     }
     $params['tags'] = SqlRepository::getTags($article_id);
     $params['title'] = $article->get_title();
     $params['indexs'] = json_decode($article->get_indexs());
     $params['contents'] = \TechlogTools::pre_treat_article($article->get_draft());
     $params['title_desc'] = $article->get_title_desc();
     $params['article_category_id'] = $article->get_category_id();
     if (StringOpt::spider_string($params['contents'], '"page-header"', '</div>') === null) {
         $params['contents'] = '<div class="page-header"><h1>' . $article->get_title() . '</h1></div>' . $params['contents'];
     }
     $article->set_access_count($article->get_access_count() + 1);
     Repository::persist($article);
     $params['inserttime'] = $article->get_inserttime() . '&nbsp;&nbsp;&nbsp;最后更新: ' . $article->get_updatetime() . '&nbsp;&nbsp;&nbsp;访问数量:' . ($article->get_access_count() + 1);
     return $params;
 }
 public function insertAction()
 {
     if (!$this->is_root) {
         header("Location: /index/notfound");
         return;
     }
     $url = '/pictures';
     if ($_FILES["file"]["error"] > 0) {
         $this->display('IndexController::notfoundAction', array('msg' => 'Error: ' . $_FILES["file"]["error"], 'url' => $url));
     }
     $params_key = array('insert_id', 'insert_category');
     $request = $this->getParams($_REQUEST, $params_key);
     $request['insert_id'] = intval($request['insert_id']) >= 0 ? intval($request['insert_id']) : null;
     $request['name'] = trim($_FILES["file"]["name"]);
     $file = '/home/zeyu/Documents/images/' . $request['name'];
     $ret = copy($_FILES["file"]["tmp_name"], $file);
     if ($ret == false) {
         $this->display('IndexController::notfoundAction', array('msg' => '临时文件不存在', 'url' => $url));
     }
     $ret = TechlogTools::picture_insert($request['name'], $request['insert_category'], $request['insert_id']);
     switch ($ret) {
         case -1:
             $message = '源文件不存在';
             break;
         case -2:
             $message = '文件替换失败,请查看权限';
             break;
         case -3:
             $message = '目录创建失败,请查看权限';
             break;
         case -4:
             $message = '指定被替换文件 ID 不存在';
             break;
         case -5:
             $message = '文件添加失败,请查看权限';
             break;
         default:
             $message = '文件添加成功';
             $url .= '?image_id=' . $ret;
     }
     $this->display('IndexController::notfoundAction', array('msg' => $message, 'url' => $url));
 }
Beispiel #3
0
 public function display($func, $params)
 {
     $params['background'] = $this->is_root ? 'url(images/17183518883b16614c2fe8.jpg)' : 'url(images/37fa8df7da45fd6c8a44a1664021a5df.jpg)';
     if (TechlogTools::isMobile()) {
         $params['background'] = '#F2F0F1';
     }
     $pattern = '/^(?<class>.+)Controller::(?<func>.+)Action/is';
     if (preg_match($pattern, $func, $arr) == false) {
         header('Location: /index/notfound');
         exit;
     }
     $class = strtolower($arr['class']);
     $func = strtolower($arr['func']);
     $file = $class . '/' . $func . '.php';
     $params['is_root'] = $this->is_root;
     $params['is_mobile'] = TechlogTools::isMobile();
     if (empty($class) || empty($func) || !file_exists(VIEW_PATH . '/' . $file)) {
         header("Location: /index/notfound");
     } else {
         require VIEW_PATH . '/' . $file;
     }
 }
Beispiel #4
0
 $infos['updatetime'] = 'now()';
 $image_ids = array();
 while (1) {
     $image_path = StringOpt::spider_string($contents, 'img<![&&]>src="', '"', $contents);
     if ($image_path === null || $image_path === false || trim($image_path) == '') {
         break;
     }
     $image_path = trim($image_path);
     if (!file_exists(WEB_PATH . '/resource/' . $image_path)) {
         LogOpt::set('exception', '文中目标图片不存在', 'image_path', $image_path);
         return;
     }
     $image_id = Repository::findImageIdFromImages(array('eq' => array('path' => $image_path)));
     if ($image_id == false) {
         $full_path = WEB_PATH . '/resource/' . $image_path;
         $image_id = TechlogTools::load_image($full_path, 'article');
         if ($image_id == false) {
             LogOpt::set('exception', '添加图片到数据库失败', 'image_path', $image_path);
             return;
         }
         LogOpt::set('info', '添加图片到数据库成功', 'image_id', $image_id, 'image_path', $image_path);
         $image_ids[] = $image_id;
     }
 }
 $article = Repository::findOneFromArticle(array('eq' => array('article_id' => $article_id)));
 foreach ($infos as $key => $value) {
     $func = 'set_' . $key;
     $article->{$func}($value);
 }
 $ret = Repository::persist($article);
 if ($ret == false) {
Beispiel #5
0
 private function getArticleInfos($articles, $is_moode = false)
 {
     if (empty($articles)) {
         return array();
     }
     $ret = array();
     foreach ($articles as $article) {
         $ret_infos = array();
         preg_match('/^(?<month>\\d{4}-\\d{2})-(?<date>\\d{2})/is', $article->get_inserttime(), $arr);
         $ret_infos['month'] = str_replace('-', '/', $arr['month']);
         $ret_infos['date'] = $arr['date'];
         $tags = SqlRepository::getTags($article->get_article_id());
         if (is_array($tags)) {
             $ret_infos['tags'] = array_slice($tags, 0, 4);
         }
         $contents = TechlogTools::pre_treat_article($article->get_draft());
         $imgpath = StringOpt::spider_string($contents, 'img<![&&]>src="', '"');
         if ($imgpath == null) {
             $ret_infos['contents'] = strip_tags($contents);
             $ret_infos['contents'] = mb_substr($ret_infos['contents'], 0, 500, 'utf-8');
         } else {
             $ret_infos['contents'] = '<p><a href="/article/list/' . $article->get_article_id() . '" target="_blank">' . '<img class="img-thumbnail" alt="200x200" style="height: 200px;"' . ' src="' . $imgpath . '"></a></p><br /><p>' . mb_substr(strip_tags($contents), 0, 100, 'utf-8') . '</p>';
         }
         $ret_infos['title'] = $article->get_title();
         $ret_infos['article_id'] = $article->get_article_id();
         $ret[] = $ret_infos;
     }
     return $ret;
 }
Beispiel #6
0
    $image_id = Repository::findImageIdFromImages(array('eq' => array('path' => $image_path)));
    if ($image_id == false) {
        $full_path = WEB_PATH . '/resource/' . $image_path;
        $image_id = TechlogTools::load_image($full_path, 'article');
        if ($image_id == false) {
            LogOpt::set('exception', '添加图片到数据库失败', 'image_path', $image_path);
        }
        LogOpt::set('info', '添加图片到数据库成功', 'image_id', $image_id, 'image_path', $image_path);
        $image_ids[] = $image_id;
    }
}
$infos['title'] = date('Y-m-d H:i:s');
if (isset($options['t'])) {
    $infos['title'] = $options['t'] . ' -- ' . date('Y-m-d');
}
$infos['category_id'] = '5';
// 获取 index
$indexs = json_encode(TechlogTools::get_index($contents));
if ($indexs != null) {
    $infos['indexs'] = $indexs;
}
$infos['updatetime'] = 'now()';
$infos['inserttime'] = 'now()';
$article = new ArticleModel($infos);
$article_id = Repository::persist($article);
if ($article_id == false) {
    LogOpt::set('exception', 'article insert error');
    return;
}
LogOpt::set('info', '添加日志成功', 'article_id', $article_id, 'title', $infos['title']);
unlink($draft_file);