示例#1
0
 function fetch_assets($args)
 {
     # load assets
     if (isset($args['blog_id'])) {
         $blog_filter = 'and asset_blog_id = ' . intval($args['blog_id']);
     }
     # Adds a thumbnail filter to the filters list.
     if (isset($args['exclude_thumb']) && $args['exclude_thumb']) {
         $thumb_filter = ' and asset_parent is null';
     }
     # Adds a tag filter to the filters list.
     if (isset($args['tags']) or isset($args['tag'])) {
         $tag_arg = isset($args['tag']) ? $args['tag'] : $args['tags'];
         require_once "MTUtil.php";
         if (!preg_match('/\\b(AND|OR|NOT)\\b|\\(|\\)/i', $tag_arg)) {
             $not_clause = false;
         } else {
             $not_clause = preg_match('/\\bNOT\\b/i', $tag_arg);
         }
         $include_private = 0;
         $tag_array = tag_split($tag_arg);
         foreach ($tag_array as $tag) {
             if ($tag && substr($tag, 0, 1) == '@') {
                 $include_private = 1;
             }
         }
         $tags =& $this->fetch_asset_tags(array('blog_id' => $blog_id, 'tag' => $tag_arg, 'include_private' => $include_private));
         if (!is_array($tags)) {
             $tags = array();
         }
         $cexpr = create_tag_expr_function($tag_arg, $tags, 'asset');
         if ($cexpr) {
             $tmap = array();
             $tag_list = array();
             foreach ($tags as $tag) {
                 $tag_list[] = $tag['tag_id'];
             }
             $ot =& $this->fetch_objecttags(array('tag_id' => $tag_list, 'datasource' => 'asset'));
             if ($ot) {
                 foreach ($ot as $o) {
                     $tmap[$o['objecttag_object_id']][$o['objecttag_tag_id']]++;
                     if (!$not_clause) {
                         $asset_list[$o['objecttag_object_id']] = 1;
                     }
                 }
             }
             $ctx['t'] =& $tmap;
             $filters[] = $cexpr;
         } else {
             return null;
         }
     }
     # Adds an author filter
     if (isset($args['author'])) {
         $author_filter = 'and author_name = \'' . $this->escape($args['author']) . "'";
     }
     # Adds an entry filter
     if (isset($args['entry_id'])) {
         $entry_filter = 'and (objectasset_object_ds = \'entry\' and objectasset_object_id = \'' . $this->escape($args['entry_id']) . '\' and asset_id = objectasset_asset_id)';
         $entry_join = ', mt_objectasset.*';
         $entry_join_tbl = ', mt_objectasset';
     }
     # Adds an ID filter
     if (isset($args['id'])) {
         if ($args['id'] == '') {
             return null;
         }
         $id_filter = 'and asset_id = ' . $args['id'];
     }
     # Adds a days filter
     if (isset($args['days'])) {
         $day_filter = 'and ' . $this->limit_by_day_sql('asset_created_on', intval($args['days']));
     }
     # Adds a type filter
     if (isset($args['type'])) {
         $type_filter = "and asset_class ='" . $args['type'] . "'";
     }
     # Adds a file extension filter
     if (isset($args['file_ext'])) {
         $ext_filter = "and asset_file_ext ='" . $args['file_ext'] . "'";
     }
     # Adds a score or rate filter to the filters list.
     if (isset($args['namespace'])) {
         require_once "MTUtil.php";
         $arg_names = array('min_score', 'max_score', 'min_rate', 'max_rate', 'min_count', 'max_count');
         foreach ($arg_names as $n) {
             if (isset($args[$n])) {
                 $rating_args = $args[$n];
                 $cexpr = create_rating_expr_function($rating_args, $n, $args['namespace'], 'asset');
                 if ($cexpr) {
                     $filters[] = $cexpr;
                 } else {
                     return null;
                 }
             }
         }
         if (isset($args['scored_by'])) {
             $voter = $this->fetch_author_by_name($args['scored_by']);
             if (!$voter) {
                 echo "Invalid scored by filter: " . $args['scored_by'];
                 return null;
             }
             $cexpr = create_rating_expr_function($voter['author_id'], 'scored_by', $args['namespace'], 'asset');
             if ($cexpr) {
                 $filters[] = $cexpr;
             } else {
                 return null;
             }
         }
     }
     # Adds sort order
     $order = 'desc';
     $sort_by = 'asset_created_on';
     if (isset($args['sort_order'])) {
         if ($args['sort_order'] == 'ascend') {
             $order = 'asc';
         } else {
             if ($args['sort_order'] == 'descend') {
                 $order = 'desc';
             }
         }
     }
     if (isset($args['sort_by'])) {
         if ('score' != $args['sort_by'] && 'rate' != $args['sort_by']) {
             $sort_by = 'asset_' . $args['sort_by'];
         }
     }
     if (isset($args['lastn'])) {
         $order = 'desc';
     }
     $join_score = "";
     $distinct = "";
     if (isset($args['sort_by']) && ($args['sort_by'] == 'score' || $args['sort_by'] == 'rate')) {
         $join_score = "left join mt_objectscore on objectscore_object_id = asset_id";
         $distinct = " distinct";
     }
     $limit = 0;
     $offset = 0;
     if (isset($args['lastn'])) {
         $limit = $args['lastn'];
     }
     if (isset($args['limit'])) {
         $limit = $args['limit'];
     }
     if (isset($args['offset'])) {
         $offset = $args['offset'];
     }
     if (count($filters)) {
         $post_select_limit = $limit;
         $post_select_offset = $offset;
         $limit = 0;
         $offset = 0;
     }
     # Build SQL
     $sql = "\n            select {$distinct} mt_asset.*, mt_author.* {$entry_join}\n            from mt_asset {$join_score}, mt_author {$entry_join_tbl}\n            where\n                author_id = asset_created_by\n                {$id_filter}\n                {$blog_filter}\n                {$author_filter}\n                {$entry_filter}\n                {$day_filter}\n                {$type_filter}\n                {$ext_filter}\n                {$thumb_filter}\n            order by\n                {$sort_by} {$order}\n                <LIMIT>\n        ";
     # Added Limit and offset
     $sql = $this->apply_limit_sql($sql, $limit, $offset);
     # Fetch resultset
     $result = $this->query_start($sql);
     if (!$result) {
         return null;
     }
     $assets = array();
     $offset = $post_select_offset ? $post_select_offset : 0;
     $limit = $post_select_limit ? $post_select_limit : 0;
     while (true) {
         $e = $this->query_fetch(ARRAY_A);
         if ($offset && $j++ < $offset) {
             continue;
         }
         if (!isset($e)) {
             break;
         }
         if (count($filters)) {
             foreach ($filters as $f) {
                 if (!$f($e, $ctx)) {
                     continue 2;
                 }
             }
         }
         $e = $this->expand_meta($e);
         $assets[] = $e;
         if ($limit > 0 && count($assets) >= $limit) {
             break;
         }
     }
     $order = 'desc';
     if (isset($args['sort_order'])) {
         if ($args['sort_order'] == 'ascend') {
             $order = 'asc';
         } else {
             if ($args['sort_order'] == 'descend') {
                 $order = 'desc';
             }
         }
     }
     if (isset($args['sort_by']) && 'score' == $args['sort_by']) {
         $assets_tmp = array();
         foreach ($assets as $a) {
             $assets_tmp[$a['asset_id']] = $a;
         }
         $scores = $this->fetch_sum_scores($args['namespace'], 'asset', $order, $id_filter . "\n" . $blog_filter . "\n" . $author_filter . "\n" . $day_filter . "\n" . $type_filter . "\n" . $ext_filter . "\n" . $thumb_filter . "\n");
         $assets_sorted = array();
         foreach ($scores as $score) {
             if (array_key_exists($score['objectscore_object_id'], $assets_tmp)) {
                 array_push($assets_sorted, $assets_tmp[$score['objectscore_object_id']]);
                 unset($assets_tmp[$score['objectscore_object_id']]);
             }
         }
         foreach ($assets_tmp as $et) {
             if ($order == 'asc') {
                 array_unshift($assets_sorted, $et);
             } else {
                 array_push($assets_sorted, $et);
             }
         }
         $assets = $assets_sorted;
     } elseif (isset($args['sort_by']) && 'rate' == $args['sort_by']) {
         $assets_tmp = array();
         foreach ($assets as $a) {
             $assets_tmp[$a['asset_id']] = $a;
         }
         $scores = $this->fetch_avg_scores($args['namespace'], 'asset', $order, $id_filter . "\n" . $blog_filter . "\n" . $author_filter . "\n" . $day_filter . "\n" . $type_filter . "\n" . $ext_filter . "\n" . $thumb_filter . "\n");
         $assets_sorted = array();
         foreach ($scores as $score) {
             if (array_key_exists($score['objectscore_object_id'], $assets_tmp)) {
                 array_push($assets_sorted, $assets_tmp[$score['objectscore_object_id']]);
                 unset($assets_tmp[$score['objectscore_object_id']]);
             }
         }
         foreach ($assets_tmp as $et) {
             if ($order == 'asc') {
                 array_unshift($assets_sorted, $et);
             } else {
                 array_push($assets_sorted, $et);
             }
         }
         $assets = $assets_sorted;
     }
     return $assets;
 }
示例#2
0
 function fetch_assets($args)
 {
     # load assets
     $extras = array();
     if (isset($args['blog_id'])) {
         $blog_filter = 'and asset_blog_id = ' . intval($args['blog_id']);
     }
     # Adds a thumbnail filter to the filters list.
     if (isset($args['exclude_thumb']) && $args['exclude_thumb']) {
         $thumb_filter = ' and asset_parent is null';
     }
     # Adds a tag filter to the filters list.
     if (isset($args['tags']) or isset($args['tag'])) {
         $tag_arg = isset($args['tag']) ? $args['tag'] : $args['tags'];
         require_once "MTUtil.php";
         if (!preg_match('/\\b(AND|OR|NOT)\\b|\\(|\\)/i', $tag_arg)) {
             $not_clause = false;
         } else {
             $not_clause = preg_match('/\\bNOT\\b/i', $tag_arg);
         }
         $include_private = 0;
         $tag_array = tag_split($tag_arg);
         foreach ($tag_array as $tag) {
             if ($tag && substr($tag, 0, 1) == '@') {
                 $include_private = 1;
             }
         }
         $tags = $this->fetch_asset_tags(array('blog_id' => $blog_id, 'tag' => $tag_arg, 'include_private' => $include_private));
         if (!is_array($tags)) {
             $tags = array();
         }
         $cexpr = create_tag_expr_function($tag_arg, $tags, 'asset');
         if ($cexpr) {
             $tmap = array();
             $tag_list = array();
             foreach ($tags as $tag) {
                 $tag_list[] = $tag->tag_id;
             }
             $ot = $this->fetch_objecttags(array('tag_id' => $tag_list, 'datasource' => 'asset'));
             if (!empty($ot)) {
                 foreach ($ot as $o) {
                     $tmap[$o->objecttag_object_id][$o->objecttag_tag_id]++;
                     if (!$not_clause) {
                         $asset_list[$o->objecttag_object_id] = 1;
                     }
                 }
             }
             $ctx['t'] =& $tmap;
             $filters[] = $cexpr;
         } else {
             return null;
         }
     }
     # Adds an author filter
     if (isset($args['author'])) {
         $author_filter = "and author_name = '" . $this->escape($args['author']) . "'";
         $extras['join']['mt_author'] = array('condition' => "author_id = asset_created_by");
     }
     # Adds an entry filter
     if (isset($args['entry_id'])) {
         $extras['join']['mt_objectasset'] = array('condition' => "(objectasset_object_ds = 'entry' and objectasset_object_id = " . intval($this->escape($args['entry_id'])) . " and asset_id = objectasset_asset_id)");
     }
     # Adds an ID filter
     if (isset($args['id'])) {
         if ($args['id'] == '') {
             return null;
         }
         $id_filter = 'and asset_id = ' . intval($args['id']);
     }
     # Adds a days filter
     if (isset($args['days'])) {
         $day_filter = 'and ' . $this->limit_by_day_sql('asset_created_on', intval($args['days']));
     }
     # Adds a type filter
     if (isset($args['type'])) {
         $type_filter = "and asset_class ='" . $args['type'] . "'";
     }
     # Adds a file extension filter
     if (isset($args['file_ext'])) {
         $ext_filter = "and asset_file_ext ='" . $args['file_ext'] . "'";
     }
     $date_filter = $args['ignore_archive_context'] ? '' : $this->build_date_filter($args, 'asset_created_on');
     # Adds a score or rate filter to the filters list.
     if (isset($args['namespace'])) {
         require_once "MTUtil.php";
         $arg_names = array('min_score', 'max_score', 'min_rate', 'max_rate', 'min_count', 'max_count');
         foreach ($arg_names as $n) {
             if (isset($args[$n])) {
                 $rating_args = $args[$n];
                 $cexpr = create_rating_expr_function($rating_args, $n, $args['namespace'], 'asset');
                 if ($cexpr) {
                     $filters[] = $cexpr;
                 } else {
                     return null;
                 }
             }
         }
         if (isset($args['scored_by'])) {
             $voter = $this->fetch_author_by_name($args['scored_by']);
             if (!$voter) {
                 echo "Invalid scored by filter: " . $args['scored_by'];
                 return null;
             }
             $cexpr = create_rating_expr_function($voter->author_id, 'scored_by', $args['namespace'], 'asset');
             if ($cexpr) {
                 $filters[] = $cexpr;
             } else {
                 return null;
             }
         }
     }
     # Adds sort order
     $order = 'desc';
     $sort_by = 'asset_created_on';
     if (isset($args['sort_order'])) {
         if ($args['sort_order'] == 'ascend') {
             $order = 'asc';
         } else {
             if ($args['sort_order'] == 'descend') {
                 $order = 'desc';
             }
         }
     }
     if (isset($args['sort_by'])) {
         if ('score' != $args['sort_by'] && 'rate' != $args['sort_by']) {
             $sort_by = 'asset_' . $args['sort_by'];
         }
     }
     if (isset($args['lastn'])) {
         $order = 'desc';
     }
     $join_score = "";
     $distinct = "";
     if (isset($args['sort_by']) && ($args['sort_by'] == 'score' || $args['sort_by'] == 'rate')) {
         $extras['join']['mt_objectscore'] = array('type' => 'left', 'condition' => "objectscore_object_id = asset_id");
         $extras['distinct'] = 'distinct';
     }
     $limit = 0;
     $offset = 0;
     if (isset($args['lastn'])) {
         $limit = $args['lastn'];
     }
     if (isset($args['limit'])) {
         $limit = $args['limit'];
     }
     if (isset($args['offset'])) {
         $offset = $args['offset'];
     }
     if (count($filters)) {
         $post_select_limit = $limit;
         $post_select_offset = $offset;
         $limit = 0;
         $offset = 0;
     }
     if ($limit) {
         $extras['limit'] = $limit;
     }
     if ($offset) {
         $extras['offset'] = $offset;
     }
     # Build SQL
     $where = "1 = 1\n                {$id_filter}\n                {$blog_filter}\n                {$author_filter}\n                {$entry_filter}\n                {$day_filter}\n                {$type_filter}\n                {$ext_filter}\n                {$thumb_filter}\n                {$date_filter}\n            order by\n                {$sort_by} {$order}\n        ";
     require_once 'class.mt_asset.php';
     $asset = new Asset();
     $result = $asset->Find($where, false, false, $extras);
     if (empty($result)) {
         return null;
     }
     $assets = array();
     $offset = $post_select_offset ? $post_select_offset : 0;
     $limit = $post_select_limit ? $post_select_limit : 0;
     $i = -1;
     while (true) {
         $i++;
         $e = $result[$i];
         if ($offset && $j++ < $offset) {
             continue;
         }
         if (!isset($e)) {
             break;
         }
         if (count($filters)) {
             foreach ($filters as $f) {
                 if (!$f($e, $ctx)) {
                     continue 2;
                 }
             }
         }
         $assets[] = $e;
         if ($limit > 0 && count($assets) >= $limit) {
             break;
         }
     }
     $no_resort = 0;
     if (isset($args['sort_by']) && $asset->has_column($args['sort_by'])) {
         $no_resort = 1;
     }
     if (isset($args['lastn'])) {
         if (isset($args['sort_by'])) {
             $no_resort = 0;
         }
     } else {
         if (!isset($args['sort_by'])) {
             $no_resort = 1;
         }
     }
     $order = 'desc';
     if (isset($args['sort_order'])) {
         if ($args['sort_order'] == 'ascend') {
             $order = 'asc';
         } else {
             if ($args['sort_order'] == 'descend') {
                 $order = 'desc';
             }
         }
     }
     # Resort assets
     if (isset($args['sort_by']) && 'score' == $args['sort_by']) {
         $assets_tmp = array();
         foreach ($assets as $a) {
             $assets_tmp[$a->asset_id] = $a;
         }
         $scores = $this->fetch_sum_scores($args['namespace'], 'asset', $order, $id_filter . "\n" . $blog_filter . "\n" . $author_filter . "\n" . $day_filter . "\n" . $type_filter . "\n" . $ext_filter . "\n" . $thumb_filter . "\n");
         $assets_sorted = array();
         foreach ($scores as $score) {
             if (array_key_exists($score['objectscore_object_id'], $assets_tmp)) {
                 array_push($assets_sorted, $assets_tmp[$score['objectscore_object_id']]);
                 unset($assets_tmp[$score['objectscore_object_id']]);
             }
         }
         foreach ($assets_tmp as $et) {
             if ($order == 'asc') {
                 array_unshift($assets_sorted, $et);
             } else {
                 array_push($assets_sorted, $et);
             }
         }
         $assets = $assets_sorted;
     } elseif (isset($args['sort_by']) && 'rate' == $args['sort_by']) {
         $assets_tmp = array();
         foreach ($assets as $a) {
             $assets_tmp[$a->asset_id] = $a;
         }
         $scores = $this->fetch_avg_scores($args['namespace'], 'asset', $order, $id_filter . "\n" . $blog_filter . "\n" . $author_filter . "\n" . $day_filter . "\n" . $type_filter . "\n" . $ext_filter . "\n" . $thumb_filter . "\n");
         $assets_sorted = array();
         foreach ($scores as $score) {
             if (array_key_exists($score['objectscore_object_id'], $assets_tmp)) {
                 array_push($assets_sorted, $assets_tmp[$score['objectscore_object_id']]);
                 unset($assets_tmp[$score['objectscore_object_id']]);
             }
         }
         foreach ($assets_tmp as $et) {
             if ($order == 'asc') {
                 array_unshift($assets_sorted, $et);
             } else {
                 array_push($assets_sorted, $et);
             }
         }
         $assets = $assets_sorted;
     } elseif (!$no_resort) {
         $sort_field = 'asset_created_on';
         if (isset($args['sort_by']) && $asset->has_column($args['sort_by'])) {
             if (preg_match('/^field[:\\.](.+)$/', $args['sort_by'], $match)) {
                 $sort_field = 'asset_field.' . $match[1];
             } else {
                 $sort_field = 'asset_' . $args['sort_by'];
             }
         }
         if ($sort_field == 'asset_blog_id' || $sort_field == 'asset_created_by' || $sort_field == 'asset_created_on' || $sort_field == 'asset_id' || $sort_field == 'asset_parent') {
             $sort_fn = "if (\$a->{$sort_field} == \$b->{$sort_field}) return 0; return \$a->{$sort_field} < \$b->{$sort_field} ? -1 : 1;";
         } else {
             $sort_fn = "\$f = '" . addslashes($sort_field) . "'; return strcmp(\$a->\$f,\$b->\$f);";
         }
         $sorter = create_function($order == 'asc' ? '$a,$b' : '$b,$a', $sort_fn);
         usort($assets, $sorter);
     }
     return $assets;
 }
示例#3
0
 function doSave()
 {
     //    	print_r($_POST);
     //    	exit;
     set_time_limit(0);
     $aid = (int) $_POST['aid'];
     $fid = (int) $_POST['fid'];
     $userid = (int) $_POST['userid'];
     $type = (int) $_POST['type'];
     $orderNum = (int) $_POST['orderNum'];
     $title = dhtmlspecialchars($_POST['title']);
     $subtitle = dhtmlspecialchars($_POST['subtitle']);
     $stitle = dhtmlspecialchars($_POST['stitle']);
     $pic = dhtmlspecialchars($_POST['pic']);
     $source = dhtmlspecialchars($_POST['source']);
     $author = dhtmlspecialchars($_POST['author']);
     $editor = dhtmlspecialchars($_POST['editor']);
     $description = dhtmlspecialchars($_POST['description']);
     $keywords = dhtmlspecialchars($_POST['keywords']);
     $tags = dhtmlspecialchars($_POST['tags']);
     $clink = dhtmlspecialchars($_POST['clink']);
     $url = dhtmlspecialchars($_POST['url']);
     $tpl = dhtmlspecialchars($_POST['template']);
     $top = _int($_POST['top']);
     $vlink = empty($_POST['vlink']) ? "" : implode(',', $_POST['vlink']);
     $related = empty($_POST['related']) ? "" : implode(',', $_POST['related']);
     $pubdate = _strtotime($_POST['pubdate']);
     $remote = isset($_POST['remote']) ? true : false;
     $dellink = isset($_POST['dellink']) ? true : false;
     $this->autopic = isset($_POST['autopic']) ? true : false;
     $status = isset($_POST['draft']) ? "0" : "1";
     $postype = $_POST['postype'] ? $_POST['postype'] : "1";
     $body = implode('<!--iCMS.PageBreak-->', $_POST['body']);
     $body = str_replace(array("\n", "\r", "\t", '<p>&nbsp;</p><p>&nbsp;</p>', '<p>&nbsp;</p><p>&nbsp;</p>', '<p>&nbsp;</p><p>&nbsp;</p>'), "", $body);
     $body = preg_replace(array('/<script.+?<\\/script>/is', '/<form.+?<\\/form>/is', '/<div\\s+style=\\\\"page-break-after:.*?<\\/div>/is'), array('', '', '<!--iCMS.PageBreak-->'), $body);
     //$body       = strip_tags($body,'<div><br><p><img><a><embed><span><b><strong><u><em>');
     empty($title) && javascript::alert('标题不能为空!');
     empty($fid) && javascript::alert('请选择所属栏目');
     empty($body) && empty($url) && javascript::alert('文章内容不能为空!');
     WordFilter($title) && javascript::alert('标题包含被系统屏蔽的字符,请返回重新填写。');
     WordFilter($body) && javascript::alert('文章内容包含被系统屏蔽的字符,请返回重新填写。');
     if ($clink) {
         for ($i = 0; $i < strlen($clink); $i++) {
             !preg_match("/[a-zA-Z0-9_\\-~" . preg_quote($this->iCMS->config['CLsplit'], '/') . "]/", $clink[$i]) && javascript::alert('自定链接只能由英文字母、数字或_-~组成(不支持中文)');
         }
     }
     isset($_POST['keywordToTag']) && empty($tags) && ($tags = $keywords);
     $tags = implode(',', (array) tag_split($tags));
     if ($this->iCMS->config['autodesc'] == "1" && !empty($this->iCMS->config['descLen']) && empty($description) && empty($url)) {
         $description = csubstr(HtmToText($body), $this->iCMS->config['descLen']);
     }
     $remote && FS::remotepic($body, $title);
     !$remote && $this->autopic && FS::remotepic($body, $title, true);
     if (empty($clink)) {
         include iPATH . 'include/cn.class.php';
         $clink = CN::pinyin($title, $this->iCMS->config['CLsplit']);
     }
     $isPic = empty($pic) ? 0 : 1;
     $dellink && ($body = preg_replace("/<a[^>].*?>(.*?)<\\/a>/si", "\\1", $body));
     $SELFURL = __SELF__ . (empty($_POST['REFERER']) ? '?mo=article&do=manage' : $_POST['REFERER']);
     $forum = new forum();
     if (empty($aid)) {
         empty($userid) && ($userid = Admin::$uId);
         $hits = $good = $bad = $comments = 0;
         $checkCL = iCMS_DB::getValue("SELECT `id` FROM `#iCMS@__article` where `clink` ='{$clink}'");
         if ($this->iCMS->config['repeatitle']) {
             iCMS_DB::getValue("SELECT `id` FROM `#iCMS@__article` where `title` = '{$title}'") && javascript::alert('该标题的文章已经存在!请检查是否重复');
             $checkCL && javascript::alert('该自定链接已经存在!请另选一个');
         } else {
             $checkCL && ($clink .= $this->iCMS->config['CLsplit'] . random(6, 1));
         }
         iCMS_DB::insert('article', compact('fid', 'title', 'stitle', 'clink', 'orderNum', 'url', 'source', 'author', 'editor', 'userid', 'postype', 'keywords', 'tags', 'description', 'related', 'isPic', 'pic', 'pubdate', 'hits', 'good', 'bad', 'comments', 'type', 'vlink', 'top', 'status'));
         $aid = iCMS_DB::$insert_id;
         if (empty($url)) {
             //            	$body	= addslashes($body);
             iCMS_DB::insert('article_data', compact('aid', 'subtitle', 'tpl', 'body'));
             $this->insert_db_remote($body, $aid);
             //$iCMS->setCache('system/search',$res,0);
         }
         addtags($tags, $aid, $forum->rootid($fid));
         $vlink = empty($vlink) ? $fid : $vlink . ',' . $fid;
         vlinkDiff($vlink, '', $aid);
         if (!strstr($forum->forum[$fid]['contentRule'], '{PHP}') && !$forum->forum[$fid]['url'] && $forum->forum[$fid]['mode'] == "1" && $status) {
             include iPATH . 'include/iHtml.class.php';
             iHtml::Article($aid);
             iHtml::forum($fid, 1, 0, 1);
         }
         iCMS_DB::query("UPDATE `#iCMS@__forum` SET `count` = count+1 WHERE `fid` ='{$fid}' LIMIT 1 ");
         $moreaction = array(array("text" => "查看该文章", "url" => $this->iCMS->iurl('show', array(array('id' => $aid, 'link' => $clink, 'url' => $url, 'fid' => $fid, 'pubdate' => $pubdate), $forum->forum[$fid]))->href, "o" => 'target="_blank"'), array("text" => "编辑该文章", "url" => __SELF__ . "?mo=article&do=add&id=" . $aid), array("text" => "继续添加文章", "url" => __SELF__ . "?mo=article&do=add&fid=" . $fid), array("text" => "返回文章列表", "url" => $SELFURL), array("text" => "查看网站首页", "url" => "../index.php", "o" => 'target="_blank"'));
         javascript::dialog('文章添加完成!<br />10秒后返回文章列表', 'url:' . $SELFURL, $moreaction, 10);
     } else {
         $checkCL = iCMS_DB::getValue("SELECT `id` FROM `#iCMS@__article` where `clink` ='{$clink}' AND `id` !='{$aid}'");
         if ($this->iCMS->config['repeatitle']) {
             $checkCL && javascript::alert('该自定链接已经存在!请另选一个');
         } else {
             $checkCL && ($clink .= $this->iCMS->config['CLsplit'] . random(6, 1));
         }
         $art = iCMS_DB::getRow("SELECT `fid`,`tags`,`vlink` FROM `#iCMS@__article` where `id` ='{$aid}'");
         TagsDiff($tags, $art->tags, $aid, $forum->rootid($fid));
         iCMS_DB::update('article', compact('fid', 'title', 'stitle', 'orderNum', 'clink', 'url', 'source', 'author', 'editor', 'userid', 'postype', 'keywords', 'tags', 'description', 'related', 'isPic', 'pic', 'pubdate', 'type', 'vlink', 'top', 'status'), array('id' => $aid));
         $vlink = empty($vlink) ? $fid : $vlink . ',' . $fid;
         vlinkDiff($vlink, $art->vlink, $aid);
         if (empty($url)) {
             //            	$body	= addslashes($body);
             if (iCMS_DB::getValue("SELECT `id` FROM `#iCMS@__article_data` where `aid` ='{$aid}'")) {
                 iCMS_DB::update('article_data', compact('tpl', 'subtitle', 'body'), compact('aid'));
             } else {
                 iCMS_DB::insert('article_data', compact('aid', 'subtitle', 'tpl', 'body'));
             }
             $this->insert_db_remote($body, $aid);
         }
         if (!strstr($forum->forum[$fid]['contentRule'], '{PHP}') && !$forum->forum[$fid]['url'] && $forum->forum[$fid]['mode'] == "1" && $status) {
             include iPATH . 'include/iHtml.class.php';
             iHtml::Article($aid);
             iHtml::forum($fid, 1, 0, 1);
         }
         if ($art->fid != $fid) {
             iCMS_DB::query("UPDATE `#iCMS@__forum` SET `count` = count-1 WHERE `fid` ='{$art->fid}' LIMIT 1 ");
             iCMS_DB::query("UPDATE `#iCMS@__forum` SET `count` = count+1 WHERE `fid` ='{$fid}' LIMIT 1 ");
         }
         javascript::dialog('文章编辑完成!<br />3秒后返回文章列表', 'url:' . $SELFURL);
     }
 }
示例#4
0
 function &fetch_tags_by_entry($args)
 {
     $class = 'entry';
     if (isset($args['class'])) {
         $class = $args['class'];
     }
     # load tags by entry_id
     if (isset($args['entry_id'])) {
         $entry_filter = 'and B.objecttag_object_id = ' . intval($args['entry_id']);
     }
     if (isset($args['blog_id'])) {
         $blog_filter = 'and A.objecttag_blog_id = ' . intval($args['blog_id']);
     }
     if (!isset($args['include_private'])) {
         $private_filter = 'and (tag_is_private = 0 or tag_is_private is null)';
     }
     if (isset($args['tags']) && $args['tags'] != '') {
         $tag_list = '';
         require_once "MTUtil.php";
         $tag_array = tag_split($args['tags']);
         foreach ($tag_array as $tag) {
             if ($tag_list != '') {
                 $tag_list .= ',';
             }
             $tag_list .= "'" . $this->escape($tag) . "'";
         }
         if ($tag_list != '') {
             $tag_filter = 'and (tag_name in (' . $tag_list . '))';
             $private_filter = '';
         }
     }
     $sql = "\n            select\n                A.objecttag_tag_id tag_id\n                , C.tag_name\n                , count(A.objecttag_tag_id) as tag_count\n                , B.objecttag_object_id\n                , A.objecttag_blog_id\n            from\n                mt_objecttag A\n                left join mt_objecttag B on A.objecttag_tag_id = B.objecttag_tag_id\n                left join mt_entry D on A.objecttag_object_id = D.entry_id {$entry_filter} {$blog_filter}\n                ,mt_tag C\n            where\n                D.entry_class='{$class}'\n                and A.objecttag_object_datasource='entry'\n                and C.tag_id=A.objecttag_tag_id\n                and entry_status = 2\n                {$tag_filter}\n                {$private_filter}\n            group by\n                A.objecttag_blog_id\n                , A.objecttag_tag_id\n                , B.objecttag_object_id\n          order by\n                C.tag_name";
     $tags = $this->get_results($sql, ARRAY_A);
     return $tags;
 }
 public function fetch_object_tags($ctx, $args, $blog_filter = NULL)
 {
     $tags = array();
     $_datasource = $args['_datasource'];
     if (!$_datasource) {
         return $tags;
     }
     $_datasource = strtolower($_datasource);
     $cacheable = empty($args['tags']) && empty($args['include_private']);
     if (empty($args['include_private'])) {
         $private_filter = 'and (tag_is_private = 0 or tag_is_private is NULL)';
     }
     if (isset($args['object_id'])) {
         if ($cacheable) {
             if (isset($this->_object_tag_cache[$_datasource . '_' . $args['object_id']])) {
                 return $this->_object_tag_cache[$_datasource . '_' . $args['object_id']];
             }
         }
         $object_filter = 'and objecttag_object_id = ' . intval($args['object_id']);
     }
     if ($blog_filter) {
         $blog_filter = "and objecttag_blog_id {$blog_filter} ";
         if (isset($this->_tag_cache[$blog_filter])) {
             return $this->_tag_cache[$blog_filter];
         }
     } else {
         if (isset($args['blog_id'])) {
             if ($cacheable) {
                 if (isset($this->_blog_object_tag_cache[$args['blog_id']])) {
                     return $this->_blog_object_tag_cache[$args['blog_id']];
                 }
             }
             $blog_filter = 'and objecttag_blog_id = ' . intval($args['blog_id']);
         }
     }
     if (!empty($args['tags'])) {
         $tag_list = '';
         require_once 'MTUtil.php';
         $tag_array = tag_split($args['tags']);
         foreach ($tag_array as $tag) {
             if ($tag_list != '') {
                 $tag_list .= ',';
             }
             $tag_list .= "'" . $ctx->mt->db()->escape($tag) . "'";
         }
         if ($tag_list != '') {
             $tag_filter = 'and (tag_name in (' . $tag_list . '))';
             $private_filter = '';
         }
     }
     $sort_col = isset($args['sort_by']) ? $args['sort_by'] : 'name';
     $sort_col = "tag_{$sort_col}";
     if (isset($args['sort_order']) and $args['sort_order'] == 'descend') {
         $order = 'desc';
     } else {
         $order = 'asc';
     }
     $id_order = '';
     if ($sort_col == 'tag_name') {
         $sort_col = 'lower(tag_name)';
     } else {
         $id_order = ', lower(tag_name)';
     }
     $sql = "\n            select tag_id, tag_name, count(*) as tag_count\n            from mt_tag, mt_objecttag, mt_{$_datasource}\n            where objecttag_tag_id = tag_id\n                and {$_datasource}_id = objecttag_object_id and objecttag_object_datasource='{$_datasource}'\n                {$blog_filter}\n                {$private_filter}\n                {$tag_filter}\n                {$object_filter}\n            group by tag_id, tag_name\n            order by {$sort_col} {$order} {$id_order}\n        ";
     $rs = $ctx->mt->db()->SelectLimit($sql);
     require_once 'class.mt_tag.php';
     $tags = array();
     while (!$rs->EOF) {
         $tag = new Tag();
         $tag->tag_id = $rs->Fields('tag_id');
         $tag->tag_name = $rs->Fields('tag_name');
         if (isset($object_filter)) {
             $tag->tag_count = '';
         } else {
             $tag->tag_count = $rs->Fields('tag_count');
         }
         $tags[] = $tag;
         $rs->MoveNext();
     }
     if ($cacheable) {
         if ($args['object_id']) {
             $this->_object_tag_cache[$args['object_id']] = $tags;
         } elseif ($args['blog_id']) {
             $this->_blog_object_tag_cache[$args['blog_id']] = $tags;
         }
     }
     if ($blog_filter) {
         $this->_tag_cache[$blog_filter] = $tags;
     }
     return $tags;
 }