Esempio n. 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;
 }
Esempio n. 2
0
 protected function parseUrl()
 {
     $pattern = '/^\\/' . '(?<class>[^\\/?]+)?' . '\\/?' . '(?<func>[^\\/?]+)?' . '\\/?' . '(?<params>[^\\/?]+(\\/[^\\/?]+)*)?' . '/is';
     if (preg_match($pattern, URI, $uri_infos) == false) {
         header('Location: /index/notfound');
         exit;
     }
     $uri_infos['class'] = isset($uri_infos['class']) ? ucfirst(strtolower($uri_infos['class'])) . 'Controller' : 'IndexController';
     $uri_infos['func'] = isset($uri_infos['func']) ? StringOpt::unlinetocamel($uri_infos['func']) . 'Action' : 'listAction';
     $uri_infos['params'] = isset($uri_infos['params']) ? explode('/', $uri_infos['params']) : array();
     return array($uri_infos['class'], $uri_infos['func'], $uri_infos['params']);
 }
Esempio n. 3
0
 private static function getList($infos, $params)
 {
     $infos = StringOpt::cameltounline($infos['index']);
     $infos = explode('_', $infos);
     if (empty($infos[0]) || empty($infos[1])) {
         return false;
     }
     $index = $infos[0];
     $type = $infos[1];
     $url = 'http://localhost:9200/' . $index . '/' . $type . '/_search';
     $ret = HttpCurl::get($url, json_encode($params[0]));
     $body = json_decode($ret['body'], true);
     if ($body == false || empty($body['hits']['total'])) {
         return false;
     }
     return $body;
 }
Esempio n. 4
0
 $sure = fgets(STDIN);
 if (trim($sure[0]) != 'Y' && trim($sure[0]) != 'y') {
     continue;
 }
 $draft_file = DRAFT_PATH . '/draft' . $article_id . '.tpl';
 $infos = array();
 $infos['draft'] = file_get_contents($draft_file);
 $contents = TechlogTools::pre_treat_article($infos['draft']);
 $indexs = json_encode(TechlogTools::get_index($contents));
 if ($indexs != null) {
     $infos['indexs'] = $indexs;
 }
 $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;
Esempio n. 5
0
 public static function get_index($html_str)
 {
     $str = $html_str;
     $index = array();
     while (1) {
         $value = '';
         $key = StringOpt::spider_string($str, '<div', '</div>', $str);
         if ($key === null) {
             break;
         } else {
             if ($key === false) {
                 return false;
             }
         }
         $key = StringOpt::spider_string($key, 'class="page-header"<![&&]>id="', '"', $value);
         if ($key === null) {
             continue;
         }
         $value = StringOpt::spider_string($value, '>', '<');
         if ($value === null) {
             continue;
         } else {
             if ($value === false) {
                 return false;
             }
         }
         $index[$key] = $value;
     }
     return $index;
 }
Esempio n. 6
0
<?php

require_once __DIR__ . '/../app/register.php';
$options = getopt('t:');
if (!isset($options['t'])) {
    echo 'usage: php create_model.php' . ' -t table' . PHP_EOL;
    exit;
}
$table = $options['t'];
$table_class = ucfirst(StringOpt::unlinetocamel($table) . 'Model');
$file = MODEL_PATH . '/' . $table_class . '.php';
if (file_exists($file)) {
    echo '文件已存在,是否替换 [y/N]';
    $sure = fgets(STDIN);
    if (trim($sure[0]) != 'Y' && trim($sure[0]) != 'y') {
        exit;
    }
}
$rp = new Repository('db', true);
$pdo = $rp->getInstance();
$sql = 'describe ' . $table;
$rs = $pdo->query($sql);
$model = '<?php' . PHP_EOL . 'class ' . $table_class . PHP_EOL . '{' . PHP_EOL;
$rows = $rs->fetchAll();
foreach ($rows as $row) {
    $model .= "\t" . 'private $' . $row['Field'] . ';' . PHP_EOL;
}
$model .= PHP_EOL;
$model .= "\t" . 'public function __construct($params = array())' . PHP_EOL . "\t{" . PHP_EOL . "\t\t" . 'foreach (get_object_vars($this) as $key=>$value)' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . 'if ($key != $this->get_pri_key() && isset($params[$key]))' . PHP_EOL . "\t\t\t\t" . '$this->$key = $params[$key];' . PHP_EOL . "\t\t\t" . 'else if (empty($this->$key))' . PHP_EOL . "\t\t\t\t" . '$this->$key = "";' . PHP_EOL . "\t\t}" . PHP_EOL . "\t}" . PHP_EOL . PHP_EOL;
$model .= "\t" . 'public function get_model_fields()' . PHP_EOL . "\t" . '{' . PHP_EOL . "\t\t" . 'return array_keys(get_object_vars($this));' . PHP_EOL . "\t" . '}' . PHP_EOL;
foreach ($rows as $row) {
Esempio n. 7
0
 public static function __callStatic($method, $params)
 {
     // {{{
     $pattern = '/^find(?<sth>(.*){0,1})From(?<table>.*)$/';
     $method_infos = array();
     if (preg_match($pattern, $method, $method_infos) == false) {
         echo 'ERROR: method error' . PHP_EOL;
         return false;
     }
     $table = StringOpt::cameltounline(lcfirst($method_infos['table']));
     self::setTable($table);
     switch ($method_infos['sth']) {
         case '':
         case 'One':
         case 'Count':
             $func = 'find' . $method_infos['sth'] . 'By';
             $params = empty($params) ? array('') : $params;
             return self::$func($params[0]);
         default:
             $field = StringOpt::cameltounline(lcfirst($method_infos['sth']));
             return self::findOneByField($field, $params[0]);
     }
 }
Esempio n. 8
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;
 }