/**
  * 更新文章
  * 
  */
 function actionEdit()
 {
     $form = Form_Admin_News::createForm('article', url('article/edit'));
     $newId = $this->_context->id;
     $news = Articles::find('id =?', $newId)->query();
     $form->import($news);
     if ($this->_context->isPOST() && $form->validate($_POST)) {
         try {
             $news->changeProps($form->values());
             $news->save();
             return $this->_redirectMessage('更新文章信息成功', '如果你不做出选择系统将自动跳转', url('article/index'), 3);
         } catch (QValidator_ValidateFailedException $ex) {
             $form->invalidate($ex);
         }
     }
     $this->_view['form'] = $form;
 }
 /**
  * Searches for articles
  */
 public function searchAction()
 {
     $numberPage = 1;
     if ($this->request->isPost()) {
         $query = Criteria::fromInput($this->di, "Articles", $_POST);
         $this->persistent->parameters = $query->getParams();
     } else {
         $numberPage = $this->request->getQuery("page", "int");
     }
     $parameters = $this->persistent->parameters;
     if (!is_array($parameters)) {
         $parameters = array();
     }
     $parameters["order"] = "id";
     $articles = Articles::find($parameters);
     if (count($articles) == 0) {
         $this->flash->notice("The search did not find any articles");
         return $this->dispatcher->forward(array("controller" => "articles", "action" => "index"));
     }
     $paginator = new Paginator(array("data" => $articles, "limit" => 10, "page" => $numberPage));
     $this->view->page = $paginator->getPaginate();
 }
 /**
  * This is a comment
  *
  * @Cache(lifetime=86400)
  */
 public function showAllAction()
 {
     $this->view->article = Articles::find();
 }
示例#4
0
 public function articleBatchModify()
 {
     $ids = explode(',', Input::get('id'));
     $action = Input::get('action');
     $value = Input::get('values');
     $cus_id = Auth::id();
     $relation = array('set_star' => 'is_star', 'set_top' => 'is_top', 'set_pcshow' => 'pc_show', 'set_mobileshow' => 'mobile_show', 'set_wechatshow' => 'wechat_show');
     if (count($ids) > 1) {
         $data = array();
         $err = false;
         foreach ($ids as $id) {
             $article = Articles::find($id);
             $article->{$relation}[$action] = $value;
             if ($relation[$action] == 'pc_show') {
                 $pushed = websiteInfo::where('cus_id', $cus_id)->pluck('pushed');
                 if ($pushed == 1 || $pushed == '3') {
                     $pushed = 1;
                 } else {
                     $pushed = 2;
                 }
             } else {
                 if ($relation[$action] == 'mobile_show') {
                     $pushed = websiteInfo::where('cus_id', $cus_id)->pluck('pushed');
                     if ($pushed == 1 || $pushed == '2') {
                         $pushed = 1;
                     } else {
                         $pushed = 3;
                     }
                 } else {
                     $pushed = 1;
                     $article->pushed = 1;
                 }
             }
             websiteInfo::where('cus_id', $cus_id)->update(['pushed' => $pushed]);
             $result = $article->save();
             if ($result) {
                 $data[] = $id;
             } else {
                 $err = true;
             }
         }
         if ($err) {
             $return_msg = array('err' => 3001, 'msg' => '部分变更失败', 'data' => $data);
         } else {
             $return_msg = array('err' => 0, 'msg' => '');
         }
     } else {
         $article = Articles::find($ids[0]);
         $article->{$relation}[$action] = $value;
         if ($relation[$action] == 'pc_show') {
             $pushed = websiteInfo::where('cus_id', $cus_id)->pluck('pushed');
             if ($pushed == 1 || $pushed == '3') {
                 $pushed = 1;
             } else {
                 $pushed = 2;
             }
         } else {
             if ($relation[$action] == 'mobile_show') {
                 $pushed = websiteInfo::where('cus_id', $cus_id)->pluck('pushed');
                 if ($pushed == 1 || $pushed == '2') {
                     $pushed = 1;
                 } else {
                     $pushed = 3;
                 }
             } else {
                 $pushed = 1;
                 $article->pushed = 1;
             }
         }
         websiteInfo::where('cus_id', $cus_id)->update(['pushed' => $pushed]);
         $result = $article->save();
         if ($result) {
             $return_msg = array('err' => 0, 'msg' => '');
         } else {
             $return_mag = array('err' => 3001, 'msg' => '变更失败');
         }
     }
     return Response::json($return_msg);
 }
示例#5
0
<?php

include "Mapper.php";
include "MapperCollection.php";
include "Articles.php";
$map = new Articles("articles");
// Find
echo "Find\n";
$result = $map->find(2);
print_r($result);
// insert
echo "\nInsert\n";
$obj = new stdClass();
$obj->name = "Ny artikel";
$obj->body = "Blah blah yada yada";
$obj->author_id = 2;
$map->insert($obj);
echo "Inserted object:\n";
print_r($obj);
echo "delete\n";
$map->delete($obj);
//update
echo "\nUpdate:\n";
$result->name = "Modified";
$map->update($result);
示例#6
0
 /**
  * 显示文章页
  *
  * @param int $id 文章id
  */
 public function articlePreview($id, $result = array())
 {
     if ($_SERVER["HTTP_HOST"] != "ht.5067.org") {
         $article = Articles::find($id);
         $customer_info = CustomerInfo::where('cus_id', $this->cus_id)->first();
         if ($customer_info->lang == 'en') {
             $lang['the_last'] = 'The last one';
             $lang['the_first'] = 'The first one';
         } else {
             $lang['the_last'] = '已经是最后一篇';
             $lang['the_first'] = '已经是第一篇';
         }
         $a_moreimg = Moreimg::where('a_id', $id)->get()->toArray();
         array_unshift($a_moreimg, array('title' => $article->title, 'img' => $article->img));
         $images = array();
         if (count($a_moreimg)) {
             $i = 0;
             foreach ($a_moreimg as $a_img) {
                 $images[$i]['title'] = $a_img['title'];
                 $images[$i]['image'] = $a_img['img'] ? $this->source_dir . 'l/articles/' . $a_img['img'] : '';
                 $i++;
             }
         }
         $list_id = Articles::where('c_id', $article->c_id)->where($this->type . '_show', '1')->where('use_url', '0')->orderBy('is_top', 'desc')->orderBy('sort', 'asc')->orderBy('created_at', 'desc')->select('id', 'title', 'img', 'introduction', 'created_at')->lists('id');
         foreach ((array) $list_id as $key => $val) {
             $article_prev = NULL;
             $article_next = NULL;
             if ($val == $id) {
                 if ($key != 0) {
                     $prev_id = $list_id[$key - 1];
                     $article_prev = Articles::find($prev_id);
                 }
                 if ($key < count($list_id) - 1) {
                     $next_id = $list_id[$key + 1];
                     $article_next = Articles::find($next_id);
                 }
                 break;
             }
         }
         $result = $this->pagePublic($article->c_id);
         if (is_array($result['navs']) && !empty($result['navs'])) {
             foreach ((array) $result['navs'] as $nav) {
                 if ($nav['current'] == 1) {
                     $pagenavs = $nav['childmenu'];
                     break;
                 } else {
                     $pagenavs = array();
                 }
             }
         }
         if (empty($pagenavs)) {
             $pagenavs = array();
         }
         $result['pagenavs'] = $pagenavs;
         $result['posnavs'] = $this->getPosNavs($article->c_id);
         $result['title'] = $customer_info->title != "" ? $customer_info->title . '-' . $article->title : $article->title;
         $result['keywords'] = $article->keywords != "" ? $article->keywords : $customer_info->keywords;
         $result['description'] = $article->introduction != "" ? $article->introduction : $customer_info->description;
         $result['article']['title'] = $article->title;
         $result['article']['keywords'] = $article->keywords;
         $result['article']['description'] = $article->introduction;
         $result['article']['viewcount'] = '<em id="article-viewcount">0</em>';
         $result['enlarge'] = 0;
         $article_type = Articles::leftJoin('classify', 'classify.id', '=', 'article.c_id')->where('article.id', $id)->pluck('article_type');
         if ($article_type == 1) {
             //新闻内容
             $viewname = 'content-news';
         } elseif ($article_type == 2) {
             //产品内容
             $viewname = 'content-product';
             $result['enlarge'] = $customer_info->enlarge;
             if ($result['enlarge'] && $this->type == 'pc') {
                 $result['footscript'] .= '<script type="text/javascript" src="http://swap.5067.org/js/img.js"></script>';
             }
         } else {
             //跳转404
         }
         //关联文章查询
         //        $pa = new PhpAnalysis();
         //
         //        $pa->SetSource($article->title);
         //
         //        //设置分词属性
         //        $pa->resultType = 2;
         //        $pa->differMax = true;
         //        $pa->StartAnalysis();
         //
         //        //获取你想要的结果
         //        $keywords = $pa->GetFinallyIndex();
         //        if (count($keywords)) {
         //            $relation_where = "";
         //            foreach ((array) $keywords as $key => $word) {
         //                $relation_where.="or title like '%$key%' ";
         //            }
         //            $relation_where = ltrim($relation_where, 'or');
         //            $prefix = Config::get('database.connections.mysql.prefix');
         //            $related_data = DB::select("select id,title,img as image,introduction,created_at,c_id from {$prefix}article where cus_id={$this->cus_id} and ($relation_where)");
         //            $related = array();
         //            if (count($related_data)) {
         //                foreach ((array) $related_data as $val) {
         //                    $temp_arr = [];
         //                    $temp_arr['title'] = $val->title;
         //                    $temp_arr['description'] = $val->introduction;
         //                    $temp_arr['image'] = $this->source_dir . 'l/articles/' . $val->image;
         //                    if ($this->showtype == 'preview') {
         //                        $temp_arr['link'] = $this->domain . '/detail/' . $val->id;
         //                        $temp_arr['category']['link'] = $this->domain . '/category/' . $val->id . '.html';
         //                    } else {
         //                        $temp_arr['link'] = $this->domain . '/detail/' . $val->id . '.html';
         //                        $temp_arr['category']['link'] = $this->domain . '/category/' . $val->id . '.html';
         //                    }
         //                    $temp_arr['pubdate'] = $val->created_at;
         //                    $temp_arr['pubtimestamp'] = strtotime($val->created_at);
         //                    $a_c_info = Classify::where('id', $val->c_id)->first();
         //                    $temp_arr['category']['name'] = $a_c_info->name;
         //                    $temp_arr['category']['en_name'] = $a_c_info->en_name;
         //                    $temp_arr['category']['icon'] = '<i class="iconfont">' . $a_c_info->icon . '</i>';
         //                    $related[] = $temp_arr;
         //                }
         //            }
         //        }
         $articles = Articles::where($this->type . '_show', '1')->where('c_id', $article->c_id)->where('use_url', '0')->orderBy('is_top', 'desc')->orderBy('sort', 'asc')->orderBy('created_at', 'desc')->get()->toArray();
         $related = array();
         for (; count($related) < 6 && count($related) < count($articles);) {
             $k = rand(0, count($articles) - 1);
             if ($this->showtype == 'preview') {
                 $related[$k]['link'] = $this->domain . '/detail/' . $articles[$k]['id'];
                 $related[$k]['category']['link'] = $this->domain . '/category/' . $articles[$k]['id'] . '.html';
             } else {
                 $related[$k]['link'] = $this->domain . '/detail/' . $articles[$k]['id'] . '.html';
                 $related[$k]['category']['link'] = $this->domain . '/category/' . $articles[$k]['id'] . '.html';
             }
             $related[$k]['title'] = $articles[$k]['title'];
             $related[$k]['description'] = $articles[$k]['introduction'];
             $related[$k]['image'] = $articles[$k]['img'] ? $this->source_dir . 'l/articles/' . $articles[$k]['img'] : '';
             $related[$k]['pubdate'] = $articles[$k]['created_at'];
             $related[$k]['pubtimestamp'] = strtotime($articles[$k]['created_at']);
             $a_c_info = Classify::where('id', $articles[$k]['c_id'])->first();
             $related[$k]['category']['name'] = $a_c_info->name;
             $related[$k]['category']['en_name'] = $a_c_info->en_name;
             $related[$k]['category']['icon'] = '<i class="iconfont">' . $a_c_info->icon . '</i>';
         }
         //dd($article_prev);
         if ($this->showtype == 'preview') {
             if ($article_next === NULL) {
                 $result['article']['next']['title'] = $lang['the_last'];
                 $result['article']['next']['link'] = '';
             } else {
                 $result['article']['next']['title'] = $article_next->title;
                 $result['article']['next']['link'] = $this->domain . '/detail/' . $article_next->id;
             }
             if ($article_prev === NULL) {
                 $result['article']['prev']['title'] = $lang['the_first'];
                 $result['article']['prev']['link'] = '';
             } else {
                 $result['article']['prev']['title'] = $article_prev->title;
                 $result['article']['prev']['link'] = $this->domain . '/detail/' . $article_prev->id;
             }
             $result['article']['image'] = $article->img ? $this->source_dir . 'l/articles/' . $article->img : '';
             $result['article']['images'] = $images;
             $result['article']['content'] = $article->content;
         } else {
             if ($article_next === NULL) {
                 $result['article']['next']['title'] = $lang['the_last'];
                 $result['article']['next']['link'] = '';
             } else {
                 $result['article']['next']['title'] = $article_next->title;
                 $result['article']['next']['link'] = $this->domain . '/detail/' . $article_next->id . '.html';
             }
             if ($article_prev === NULL) {
                 $result['article']['prev']['title'] = $lang['the_first'];
                 $result['article']['prev']['link'] = '';
             } else {
                 $result['article']['prev']['title'] = $article_prev->title;
                 $result['article']['prev']['link'] = $this->domain . '/detail/' . $article_prev->id . '.html';
             }
             $result['article']['image'] = $article->img ? $this->source_dir . 'l/articles/' . $article->img : '';
             $result['article']['images'] = $images;
             $result['article']['content'] = preg_replace('/\\/customers\\/' . $this->customer . '/i', '', $article->content);
         }
         $result['article']['description'] = $article->introduction;
         $result['article']['pubdate'] = (string) $article->created_at;
         $result['article']['pubtimestamp'] = strtotime($article->created_at);
         $result['article']['category'] = $result['posnavs'][count($result['posnavs']) - 1];
         $result['related'] = $related;
         $json_keys = $this->getJsonKey($viewname . '.html');
         if (count($json_keys)) {
             foreach ((array) $json_keys as $key) {
                 $result[$key] = $this->detailList($this->pagedata($key));
             }
         }
         $result["viewname"] = $viewname;
     }
     if ($_SERVER["HTTP_HOST"] == "172.16.0.17") {
         return json_encode($result);
     }
     //        var_dump($result['pubdate']);
     //        exit();
     $smarty = new Smarty();
     $smarty->setTemplateDir(app_path('views/templates/' . $this->themename));
     $smarty->setCompileDir(app_path('storage/views/compile'));
     $smarty->registerPlugin('function', 'mapExt', array('PrintController', 'createMap'));
     $smarty->registerPlugin('function', 'shareExt', array('PrintController', 'createShare'));
     $smarty->assign($result);
     @$smarty->display($result["viewname"] . '.html');
 }
示例#7
0
 /**
  * 显示文章页
  *
  * @param int $id 文章id
  */
 public function articlePreview($id)
 {
     $article = Articles::find($id);
     $a_moreimg = Moreimg::where('a_id', $id)->get()->toArray();
     array_unshift($a_moreimg, array('title' => $article->title, 'img' => $article->img));
     $images = array();
     if (count($a_moreimg)) {
         $i = 0;
         foreach ($a_moreimg as $a_img) {
             $images[$i]['title'] = $a_img['title'];
             $images[$i]['image'] = $this->source_dir . 'l/articles/' . $a_img['img'];
             $i++;
         }
     }
     $list_id = Articles::where('c_id', $article->c_id)->where($this->type . '_show', '1')->orderBy('is_top', 'desc')->orderBy('created_at', 'desc')->select('id', 'title', 'img', 'introduction', 'created_at')->lists('id');
     foreach ($list_id as $key => $val) {
         $article_prev = NULL;
         $article_next = NULL;
         if ($val == $id) {
             if ($key != 0) {
                 $prev_id = $list_id[$key - 1];
                 $article_prev = Articles::find($prev_id);
             }
             if ($key < count($list_id) - 1) {
                 $next_id = $list_id[$key + 1];
                 $article_next = Articles::find($next_id);
             }
             break;
         }
     }
     $result = $this->pagePublic($article->c_id);
     foreach ($result['navs'] as $nav) {
         if ($nav['current'] == 1) {
             $pagenavs = $nav['childmenu'];
             break;
         } else {
             $pagenavs = [];
         }
     }
     $result['pagenavs'] = $pagenavs;
     $result['posnavs'] = $this->getPosNavs($article->c_id);
     $result['title'] = $article->title;
     $result['keywords'] = $article->keywords;
     $result['description'] = $article->introduction;
     $result['article']['title'] = $article->title;
     $result['article']['keywords'] = $article->keywords;
     $result['article']['description'] = $article->introduction;
     $result['article']['viewcount'] = '<em id="article-viewcount">0</em>';
     $article_type = Articles::leftJoin('classify', 'classify.id', '=', 'article.c_id')->where('article.id', $id)->pluck('article_type');
     if ($article_type == 1) {
         //新闻内容
         $viewname = 'content-news';
     } elseif ($article_type == 2) {
         //产品内容
         $viewname = 'content-product';
     } else {
         //跳转404
     }
     //关联文章查询
     $pa = new PhpAnalysis();
     $pa->SetSource($article->title);
     //设置分词属性
     $pa->resultType = 2;
     $pa->differMax = true;
     $pa->StartAnalysis();
     //获取你想要的结果
     $keywords = $pa->GetFinallyIndex();
     if (count($keywords)) {
         $relation_where = "";
         foreach ($keywords as $key => $word) {
             $relation_where .= "or title like '%{$key}%' ";
         }
         $relation_where = ltrim($relation_where, 'or');
         $prefix = Config::get('database.connections.mysql.prefix');
         $related_data = DB::select("select id,title,img as image,introduction,created_at,c_id from {$prefix}article where cus_id={$this->cus_id} and ({$relation_where})");
         $related = array();
         if (count($related_data)) {
             foreach ($related_data as $val) {
                 $temp_arr = [];
                 $temp_arr['title'] = $val->title;
                 $temp_arr['description'] = $val->introduction;
                 $temp_arr['image'] = $this->source_dir . 'l/articles/' . $val->image;
                 if ($this->showtype == 'preview') {
                     $temp_arr['link'] = $this->domain . '/detail/' . $val->id;
                     $temp_arr['category']['link'] = $this->domain . '/category/' . $val->id . '.html';
                 } else {
                     $temp_arr['link'] = $this->domain . '/detail/' . $val->id . '.html';
                     $temp_arr['category']['link'] = $this->domain . '/category/' . $val->id . '.html';
                 }
                 $temp_arr['pubdate'] = $val->created_at;
                 $temp_arr['pubtimestamp'] = strtotime($val->created_at);
                 $a_c_info = Classify::where('id', $val->c_id)->first();
                 $temp_arr['category']['name'] = $a_c_info->name;
                 $temp_arr['category']['en_name'] = $a_c_info->en_name;
                 $temp_arr['category']['icon'] = '<i class="iconfont">' . $a_c_info->icon . '</i>';
                 $related[] = $temp_arr;
             }
         }
     }
     //dd($article_prev);
     if ($this->showtype == 'preview') {
         if ($article_next === NULL) {
             $result['article']['next']['title'] = '已经是最后一篇';
             $result['article']['next']['link'] = '';
         } else {
             $result['article']['next']['title'] = $article_next->title;
             $result['article']['next']['link'] = $this->domain . '/detail/' . $article_next->id;
         }
         if ($article_prev === NULL) {
             $result['article']['prev']['title'] = '已经是第一篇';
             $result['article']['prev']['link'] = '';
         } else {
             $result['article']['prev']['title'] = $article_prev->title;
             $result['article']['prev']['link'] = $this->domain . '/detail/' . $article_prev->id;
         }
         $result['article']['image'] = $this->source_dir . 'l/articles/' . $article->img;
         $result['article']['images'] = $images;
         $result['article']['content'] = $article->content;
     } else {
         if ($article_next === NULL) {
             $result['article']['next']['title'] = '已经是最后一篇';
             $result['article']['next']['link'] = '';
         } else {
             $result['article']['next']['title'] = $article_next->title;
             $result['article']['next']['link'] = $this->domain . '/detail/' . $article_next->id . '.html';
         }
         if ($article_prev === NULL) {
             $result['article']['prev']['title'] = '已经是第一篇';
             $result['article']['prev']['link'] = '';
         } else {
             $result['article']['prev']['title'] = $article_prev->title;
             $result['article']['prev']['link'] = $this->domain . '/detail/' . $article_prev->id . '.html';
         }
         $result['article']['image'] = $this->source_dir . 'l/articles/' . $article->img;
         $result['article']['images'] = $images;
         $result['article']['content'] = preg_replace('/\\/customers\\/' . $this->customer . '/i', '', $article->content);
     }
     $result['article']['description'] = $article->introduction;
     $result['article']['pubdate'] = $article->created_at;
     $result['article']['pubtimestamp'] = strtotime($article->created_at);
     $result['article']['category'] = $result['posnavs'][count($result['posnavs']) - 1];
     $result['related'] = $related;
     $json_keys = $this->getJsonKey($viewname . '.html');
     if (count($json_keys)) {
         foreach ($json_keys as $key) {
             $result[$key] = $this->detailList($this->pagedata($key));
         }
     }
     $smarty = new Smarty();
     $smarty->setTemplateDir(app_path('views/templates/' . $this->themename));
     $smarty->setCompileDir(app_path('storage/views/compile'));
     $smarty->registerPlugin('function', 'mapExt', array('PrintController', 'createMap'));
     $smarty->registerPlugin('function', 'shareExt', array('PrintController', 'createShare'));
     $smarty->assign($result);
     $smarty->display($viewname . '.html');
     //return View::make('templates.'.$this->themename.'.'.$viewname,$result);
 }
示例#8
0
 public function articleBatchModify()
 {
     $ids = explode(',', Input::get('id'));
     $action = Input::get('action');
     $value = Input::get('values');
     $relation = array('set_star' => 'is_star', 'set_top' => 'is_top', 'set_pcshow' => 'pc_show', 'set_mobileshow' => 'mobile_show', 'set_wechatshow' => 'wechat_show');
     if (count($ids) > 1) {
         $data = array();
         $err = false;
         foreach ($ids as $id) {
             $article = Articles::find($id);
             $article->{$relation}[$action] = $value;
             $result = $article->save();
             if ($result) {
                 $data[] = $id;
             } else {
                 $err = true;
             }
         }
         if ($err) {
             $return_msg = array('err' => 3001, 'msg' => '部分变更失败', 'data' => $data);
         } else {
             $return_msg = array('err' => 0, 'msg' => '');
         }
     } else {
         $article = Articles::find($ids[0]);
         $article->{$relation}[$action] = $value;
         $result = $article->save();
         if ($result) {
             $return_msg = array('err' => 0, 'msg' => '');
         } else {
             $return_mag = array('err' => 3001, 'msg' => '变更失败');
         }
     }
     return Response::json($return_msg);
 }