Esempio n. 1
0
 /**
  * get search results of keywords.
  * 
  * @param  string    $keywords 
  * @param  object    $pager 
  * @access public
  * @return array
  */
 public function getList($keywords, $pager)
 {
     $spliter = $this->app->loadClass('spliter');
     $words = explode(' ', seo::unify($keywords, ' '));
     $against = '';
     foreach ($words as $word) {
         $splitedWords = $spliter->utf8Split($word);
         $against .= '"' . $splitedWords['words'] . '"';
     }
     $words = str_replace('"', '', $against);
     $words = str_pad($words, 5, '_');
     /*$scoreColumn = "((1 * (MATCH(title) AGAINST('{$against}' IN BOOLEAN MODE))) + (0.6 * (MATCH(title) AGAINST('{$against}' IN BOOLEAN MODE))) )";
       $results = $this->dao->select("*, {$scoreColumn} as score")
           ->from(TABLE_SEARCH_INDEX)
           ->where("MATCH(title,content) AGAINST('+{$against}' IN BOOLEAN MODE) >= 1")
           ->andWhere('status')->eq('normal')
           ->andWhere('addedDate')->le(helper::now())
           ->orderBy('score_desc, editedDate_desc')
           ->page($pager)
           ->fetchAll('id');*/
     $words = str_replace('_', '', $words);
     $results = $this->dao->select("*")->from(TABLE_SEARCH_INDEX)->where("title")->like("%{$words}%")->orWhere("content")->like("%{$words}%")->orderBy('editedDate_desc')->page($pager)->fetchAll();
     foreach ($results as $record) {
         $record->title = str_replace('</span> ', '</span>', $this->decode($this->markKeywords($record->title, $words)));
         $record->title = str_replace('_', '', $this->decode($this->markKeywords($record->title, $words)));
         $record->summary = $this->getSummary($record->content, $words);
         $record->summary = str_replace('_', '', $record->summary);
     }
     return $this->processLinks($results);
 }
Esempio n. 2
0
 /**
  * Set upload configures.
  * 
  * @access public
  * @return void
  */
 public function setUpload()
 {
     if (!empty($_POST)) {
         $setting = fixer::input('post')->remove('allowedFiles')->setDefault('allowUpload', '0')->get();
         $dangers = explode(',', $this->config->file->dangers);
         $allowedFiles = trim(strtolower($this->post->allowedFiles), ',');
         $allowedFiles = str_replace($dangers, '', $allowedFiles);
         $allowedFiles = seo::unify($allowedFiles, ',');
         $allowedFiles = ',' . $allowedFiles . ',';
         $fileConfig = array('allowed' => $allowedFiles);
         $this->loadModel('setting')->setItems('system.common.file', $fileConfig);
         $result = $this->loadModel('setting')->setItems('system.common.site', $setting);
         $cache = $this->loadModel('cache')->createConfigCache();
         if (!$cache) {
             $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->error->noWritable, $this->app->getTmpRoot() . 'cache')));
         }
         if ($result) {
             $this->send(array('result' => 'success', 'message' => $this->lang->setSuccess, 'locate' => inlink('setupload')));
         }
         $this->send(array('result' => 'fail', 'message' => $this->lang->fail));
     }
     $this->view->title = $this->lang->site->setBasic;
     $this->display();
 }
Esempio n. 3
0
 /**
  * Set upload configures.
  *
  * @access public
  * @return void
  */
 public function setUpload()
 {
     $this->lang->site->menu = $this->lang->security->menu;
     $this->lang->menuGroups->site = 'security';
     $this->loadModel('file');
     if (!empty($_POST)) {
         $setting = fixer::input('post')->remove('allowedFiles,thumbs')->setDefault('allowUpload', '0')->get();
         $dangers = explode(',', $this->config->file->dangers);
         $allowedFiles = trim(strtolower($this->post->allowedFiles), ',');
         $allowedFiles = str_replace($dangers, '', $allowedFiles);
         $allowedFiles = seo::unify($allowedFiles, ',');
         if (!preg_match('/^[a-z0-9,]+$/', $allowedFiles)) {
             $this->send(array('result' => 'fail', 'message' => $this->lang->fail));
         }
         $allowedFiles = explode(',', $allowedFiles);
         foreach ($allowedFiles as $extension) {
             if (strlen($extension) > 5) {
                 $this->send(array('result' => 'fail', 'message' => $this->lang->fail));
             }
         }
         $allowedFiles = implode(',', $allowedFiles);
         foreach ($dangers as $danger) {
             if (strpos($allowedFiles, $danger) !== false) {
                 $this->send(array('result' => 'fail', 'message' => $this->lang->fail));
             }
         }
         $allowedFiles = ',' . $allowedFiles . ',';
         $result = $this->loadModel('setting')->setItem('system.common.file.allowed', $allowedFiles);
         if (!$result) {
             $this->send(array('result' => 'fail', 'message' => $this->lang->fail));
         }
         $result = $this->loadModel('setting')->setItems('system.common.site', $setting);
         if ($result) {
             $this->send(array('result' => 'success', 'message' => $this->lang->setSuccess, 'locate' => inlink('setupload')));
         }
         $this->send(array('result' => 'fail', 'message' => $this->lang->fail));
     }
     $this->view->title = $this->lang->site->setUpload;
     $this->display();
 }
Esempio n. 4
0
 /**
  * Update an article.
  * 
  * @param string   $articleID 
  * @access public
  * @return void
  */
 public function update($articleID, $type = 'article')
 {
     $article = $this->getByID($articleID);
     $category = array_keys($article->categories);
     $article = fixer::input('post')->stripTags('content,link', $this->config->allowedTags->admin)->join('categories', ',')->add('editor', $this->app->user->account)->add('editedDate', helper::now())->setIF(!$this->post->isLink, 'link', '')->get();
     $article->keywords = seo::unify($article->keywords, ',');
     $article->alias = seo::unify($article->alias, '-');
     $article->content = $this->rtrimContent($article->content);
     $this->dao->update(TABLE_ARTICLE)->data($article, $skip = 'categories,uid,isLink')->autoCheck()->batchCheckIF($type != 'page' and !$this->post->isLink, $this->config->article->require->edit, 'notempty')->batchCheckIF($type == 'page' and !$this->post->isLink, $this->config->article->require->page, 'notempty')->batchCheckIF($type != 'page' and $this->post->isLink, $this->config->article->require->link, 'notempty')->batchCheckIF($type == 'page' and $this->post->isLink, $this->config->article->require->pageLink, 'notempty')->checkIF($type == 'page' and $this->post->alias, 'alias', 'unique', "type='page' and id<>{$articleID}")->where('id')->eq($articleID)->exec();
     $this->loadModel('file')->updateObjectID($this->post->uid, $articleID, $type);
     $this->file->copyFromContent($this->post->content, $articleID, $type);
     if (dao::isError()) {
         return false;
     }
     $this->loadModel('tag')->save($article->keywords);
     if ($type != 'page') {
         $this->processCategories($articleID, $type, $this->post->categories);
     }
     if (dao::isError()) {
         return false;
     }
     $article = $this->getByID($articleID);
     if (empty($article)) {
         return false;
     }
     return $this->loadModel('search')->save($type, $article);
 }
Esempio n. 5
0
 /**
  * Unify keywords of article, product and category, count tag's rank and save.
  *
  * @access public
  * @return void
  */
 public function processTag()
 {
     $tags = '';
     $articles = $this->dao->select('id, keywords')->from(TABLE_ARTICLE)->fetchPairs('id', 'keywords');
     foreach ($articles as $id => $keywords) {
         $keywords = seo::unify($keywords, ',');
         $this->dao->update(TABLE_ARTICLE)->set('keywords')->eq($keywords)->where('id')->eq($id)->exec();
         $tags = $keywords;
     }
     $products = $this->dao->select('id, keywords')->from(TABLE_PRODUCT)->fetchPairs('id', 'keywords');
     foreach ($products as $id => $keywords) {
         $keywords = seo::unify($keywords, ',');
         $this->dao->update(TABLE_PRODUCT)->set('keywords')->eq($keywords)->where('id')->eq($id)->exec();
         $tags .= ',' . $keywords;
     }
     $categories = $this->dao->select('id, keywords')->from(TABLE_CATEGORY)->fetchPairs('id', 'keywords');
     foreach ($categories as $id => $keywords) {
         $keywords = seo::unify($keywords, ',');
         $this->dao->update(TABLE_CATEGORY)->set('keywords')->eq($keywords)->where('id')->eq($id)->exec();
         $tags .= ',' . $keywords;
     }
     $this->loadModel('tag')->save($tags);
 }
Esempio n. 6
0
 /**
  * Update a product.
  * 
  * @param  int $productID 
  * @access public
  * @return void
  */
 public function update($productID)
 {
     $product = fixer::input('post')->join('categories', ',')->stripTags('content,desc', $this->config->allowedTags->admin)->setDefault('price', 0)->setDefault('amount', 0)->setDefault('promotion', 0)->setDefault('unsaleable', 0)->add('editor', $this->app->user->account)->add('editedDate', helper::now())->get();
     $product->alias = seo::unify($product->alias, '-');
     $product->keywords = seo::unify($product->keywords, ',');
     $this->dao->update(TABLE_PRODUCT)->data($product, $skip = 'categories,uid,label,value')->autoCheck()->batchCheck($this->config->product->require->edit, 'notempty')->checkIF($product->mall, 'mall', 'URL')->where('id')->eq($productID)->exec();
     $attributes = $this->saveAttributes($productID);
     if ($attributes === false) {
         return false;
     }
     $this->loadModel('file')->updateObjectID($this->post->uid, $productID, 'product');
     $this->file->copyFromContent($this->post->content, $productID, 'product');
     if (dao::isError()) {
         return false;
     }
     $this->loadModel('tag')->save($product->keywords);
     $this->processCategories($productID, $this->post->categories);
     $product = $this->getByID($productID);
     if (empty($product)) {
         return false;
     }
     $product->attributes = $attributes;
     return $this->loadModel('search')->save('product', $product);
 }
Esempio n. 7
0
 /**
  * Update a node.
  *
  * @param int $nodeID
  * @access public
  * @return bool
  */
 public function update($nodeID)
 {
     $oldNode = $this->getNodeByID($nodeID);
     $node = fixer::input('post')->add('id', $nodeID)->add('editor', $this->app->user->account)->add('editedDate', helper::now())->setForce('keywords', seo::unify($this->post->keywords, ','))->setForce('alias', seo::unify($this->post->alias, '-'))->setForce('type', $oldNode->type)->stripTags('content', $this->config->allowedTags->admin)->get();
     $this->dao->update(TABLE_BOOK)->data($node, $skip = 'uid,referer')->autoCheck()->batchCheckIF($node->type == 'book', $this->config->book->require->book, 'notempty')->batchCheckIF($node->type != 'book', $this->config->book->require->node, 'notempty')->checkIF($node->type == 'book', 'alias', 'unique', "`type` = 'book' AND id != '{$nodeID}'")->where('id')->eq($nodeID)->exec();
     if (dao::isError()) {
         return false;
     }
     $this->fixPath($oldNode->book->id);
     if (dao::isError()) {
         return false;
     }
     $this->loadModel('tag')->save($node->keywords);
     if (dao::isError()) {
         return false;
     }
     if ($node->type == 'article') {
         $this->loadModel('file')->updateObjectID($this->post->uid, $nodeID, 'book');
         $this->file->copyFromContent($this->post->content, $nodeID, 'book');
         if (dao::isError()) {
             return false;
         }
     }
     $book = $this->getNodeByID($nodeID);
     return $this->loadModel('search')->save('book', $book);
 }
Esempio n. 8
0
 /**
  * Manage children of one category.
  * 
  * @param string $type 
  * @param string $children 
  * @access public
  * @return void
  */
 public function manageChildren($type, $parent, $children)
 {
     /* Get parent. */
     $parent = $this->getByID($parent);
     /* Init the category object. */
     $category = new stdclass();
     $category->parent = $parent ? $parent->id : 0;
     $category->grade = $parent ? $parent->grade + 1 : 1;
     $category->type = $type;
     $category->postedDate = helper::now();
     $i = 1;
     foreach ($children as $key => $categoryName) {
         $alias = $this->post->alias[$key];
         $alias = seo::unify($alias, '-');
         $order = $i * 10;
         if (empty($categoryName)) {
             continue;
         }
         /* First, save the child without path field. */
         $category->name = $categoryName;
         $category->alias = $alias;
         $category->order = $order;
         $mode = $this->post->mode[$key];
         /* Add id to check alias. */
         $category->id = $mode == 'new' ? 0 : ($category->id = $key);
         if (!$this->checkAlias($category)) {
             return sprintf($this->lang->tree->aliasRepeat, $alias);
         }
         if ($category->type == 'forum' or $category->type == 'blog') {
             if (is_numeric($category->alias)) {
                 return $this->lang->tree->aliasNumber;
             }
         }
         if ($mode == 'new') {
             unset($category->id);
             $this->dao->insert(TABLE_CATEGORY)->data($category)->exec();
             /* After saving, update it's path. */
             $categoryID = $this->dao->lastInsertID();
             $categoryPath = $parent ? $parent->path . $categoryID . ',' : ",{$categoryID},";
             $this->dao->update(TABLE_CATEGORY)->set('path')->eq($categoryPath)->where('id')->eq($categoryID)->exec();
         } else {
             $categoryID = $key;
             $this->dao->update(TABLE_CATEGORY)->set('name')->eq($categoryName)->set('alias')->eq($alias)->set('order')->eq($order)->where('id')->eq($categoryID)->exec();
         }
         $i++;
     }
     return !dao::isError();
 }