Пример #1
0
 /**
  * Does this module is destroyable ?
  *
  * @return boolean
  * @access public
  */
 function isDestroyable()
 {
     global $cms_user;
     // Check module exists and is polymod
     if ($this->hasError() || !$this->isPolymod()) {
         return false;
     }
     //check if user is admin
     if (!$cms_user->hasAdminClearance(CLEARANCE_ADMINISTRATION_EDITVALIDATEALL)) {
         return false;
     }
     //check if module has objects
     if (CMS_poly_object_catalog::getObjectsForModule($this->_codename)) {
         return false;
     }
     // CHECK USED ROWS
     $usedRows = array();
     $rowsIds = CMS_rowsCatalog::getByModules(array($this->_codename), false, false);
     if ($rowsIds) {
         foreach ($rowsIds as $rowId) {
             if (CMS_rowsCatalog::getPagesByRow($rowId, false, false)) {
                 $usedRows[] = $rowId;
             }
         }
     }
     // If any used rows : alert user and break module deletion
     if ($usedRows) {
         return false;
     }
     return true;
 }
Пример #2
0
 /**
  * Get the search.
  *
  * @param integer $searchType : the type of the search (see constants)
  * @return array of CMS_page the result pages
  * @access public
  */
 function getSearch($keywords, $user, $public = false, $withPageContent = false)
 {
     if (is_a($user, 'CMS_profile_user')) {
         $cms_language = $user->getLanguage();
     } else {
         $cms_language = new CMS_language('fr');
     }
     $results = array();
     $count = 0;
     /*$messages = array();
     		$message = '';*/
     $where = $order = '';
     $foundLinkToIDs = $foundLinkFromIDs = $foundPagesFromTemplate = $foundPagesFromRow = $matches = array();
     // Clean keywords
     $keywords = SensitiveIO::sanitizeSQLString($keywords);
     $keywords = strtr($keywords, ",;", "  ");
     $blocks = array();
     $blocks = array_map("trim", array_unique(explode(" ", $keywords)));
     $cleanedBlocks = array();
     foreach ($blocks as $block) {
         if ($block !== '' || sensitiveIO::isPositiveInteger($block)) {
             $block = str_replace(array('%', '_'), array('\\%', '\\_'), $block);
             $cleanedBlocks[] = $block;
         }
     }
     // Separate block codes
     if ($cleanedBlocks) {
         $allDatas = array();
         $allCodes = CMS_search::getAllCodes();
         foreach ($allCodes as $code) {
             $datas = array();
             foreach (array_keys($cleanedBlocks) as $key) {
                 if (strstr($cleanedBlocks[$key], $code . ':')) {
                     $datas[] = $cleanedBlocks[$key];
                     unset($cleanedBlocks[$key]);
                 }
             }
             if ($datas) {
                 $allDatas[$code] = $datas;
             }
         }
         $allDatas[self::SEARCH_TYPE_DEFAULT] = $cleanedBlocks;
         // Get IDs from all specific codes
         $foundIDs = array();
         $allLinksNumber = 0;
         foreach ($allCodes as $code) {
             switch ($code) {
                 case self::SEARCH_TYPE_LINKTO:
                     if (isset($allDatas[self::SEARCH_TYPE_LINKTO])) {
                         $foundLinkToIDs = array();
                         $where = '';
                         $count = 0;
                         foreach ($allDatas[self::SEARCH_TYPE_LINKTO] as $block) {
                             $tabValues = explode(':', $block);
                             if (SensitiveIO::isPositiveInteger($tabValues[1])) {
                                 $where .= $count ? ' or ' : '';
                                 $count++;
                                 $where .= " start_lre = '" . $tabValues[1] . "' ";
                             }
                         }
                         if ($where) {
                             $select = ' stop_lre ';
                             $from = 'linx_real_public';
                             $sql = "\n\t\t\t\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t\t\t\t" . $select . "\n\t\t\t\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t\t\t\t" . $from . "\n\t\t\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\t\t\t" . $where;
                             $q = new CMS_query($sql);
                             $arr = array();
                             while ($arr = $q->getArray()) {
                                 $foundLinkToIDs[] = $arr["stop_lre"];
                             }
                             // Count links number
                             $allLinksNumber += count($foundLinkToIDs);
                             $where = $select = '';
                         }
                     }
                     break;
                 case self::SEARCH_TYPE_LINKFROM:
                     if (isset($allDatas[self::SEARCH_TYPE_LINKFROM])) {
                         $foundLinkFromIDs = array();
                         $where = '';
                         $count = 0;
                         /*$messagesIDs = array();*/
                         foreach ($allDatas[self::SEARCH_TYPE_LINKFROM] as $block) {
                             $tabValues = explode(':', $block);
                             if (SensitiveIO::isPositiveInteger($tabValues[1])) {
                                 $where .= $count ? ' or ' : '';
                                 $count++;
                                 $where .= " stop_lre = '" . $tabValues[1] . "' ";
                             }
                         }
                         if ($where) {
                             $select = ' start_lre ';
                             $from = 'linx_real_public';
                             $sql = "\n\t\t\t\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t\t\t\t" . $select . "\n\t\t\t\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t\t\t\t" . $from . "\n\t\t\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\t\t\t" . $where;
                             $q = new CMS_query($sql);
                             $arr = array();
                             while ($arr = $q->getArray()) {
                                 $foundLinkFromIDs[] = $arr["start_lre"];
                             }
                             // Count links number
                             $allLinksNumber += count($foundLinkFromIDs);
                             $where = $select = '';
                         }
                     }
                     break;
                 case self::SEARCH_TYPE_TEMPLATE:
                     if (isset($allDatas[self::SEARCH_TYPE_TEMPLATE])) {
                         $foundPagesFromTemplate = array();
                         foreach ($allDatas[self::SEARCH_TYPE_TEMPLATE] as $block) {
                             $tabValues = explode(':', $block);
                             if (SensitiveIO::isPositiveInteger($tabValues[1])) {
                                 $foundPagesFromTemplate = array_unique(array_merge(CMS_pageTemplatesCatalog::getPagesByTemplate($tabValues[1]), $foundPagesFromTemplate));
                             }
                         }
                         $allLinksNumber += count($foundPagesFromTemplate);
                     }
                     break;
                 case self::SEARCH_TYPE_ROW:
                     if (isset($allDatas[self::SEARCH_TYPE_ROW])) {
                         $foundPagesFromRow = array();
                         foreach ($allDatas[self::SEARCH_TYPE_ROW] as $block) {
                             $tabValues = explode(':', $block);
                             if (SensitiveIO::isPositiveInteger($tabValues[1])) {
                                 $foundPagesFromRow = array_unique(array_merge(CMS_rowsCatalog::getPagesByRow($tabValues[1]), CMS_rowsCatalog::getPagesByRow($tabValues[1], false, true), $foundPagesFromRow));
                             }
                         }
                         $allLinksNumber += count($foundPagesFromRow);
                     }
                     break;
             }
         }
         $foundIDs = array_unique(array_merge($foundLinkToIDs, $foundLinkFromIDs, $foundPagesFromTemplate, $foundPagesFromRow));
         // Main sql requests (for pageId, pages codenames and keywords)
         if ($allDatas[self::SEARCH_TYPE_DEFAULT]) {
             $count = 0;
             $where = '';
             foreach ($allDatas[self::SEARCH_TYPE_DEFAULT] as $key => $block) {
                 if (SensitiveIO::isPositiveInteger($block)) {
                     $where .= $count ? ' or ' : '';
                     $count++;
                     $where .= " (page_pbd like '%" . $block . "%')";
                     unset($allDatas[self::SEARCH_TYPE_DEFAULT][$key]);
                 }
             }
             $order = '';
             if ($allDatas[self::SEARCH_TYPE_DEFAULT]) {
                 $suffix = $public ? '_public' : '_edited';
                 if (!$withPageContent) {
                     //Search in page metadatas
                     //$count = 0;
                     foreach ($allDatas[self::SEARCH_TYPE_DEFAULT] as $block) {
                         $where .= $count ? ' or ' : '';
                         $count++;
                         $where .= " (\n\t\t\t\t\t\t\t\ttitle_pbd like '%" . $block . "%'\n\t\t\t\t\t\t\t\tor linkTitle_pbd like '%" . $block . "%'\n\t\t\t\t\t\t\t\tor keywords_pbd like '%" . $block . "%'\n\t\t\t\t\t\t\t\tor description_pbd like '%" . $block . "%'\n\t\t\t\t\t\t\t\tor category_pbd like '%" . $block . "%'\n\t\t\t\t\t\t\t\tor codename_pbd = '" . $block . "'\n\t\t\t\t\t\t\t)";
                     }
                     if ($foundIDs) {
                         $where .= " and page_pbd in (" . implode($foundIDs, ',') . ") ";
                     }
                     // Set SQL
                     $sql = "\n\t\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t\tpage_pbd\n\t\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t\tpagesBaseData" . $suffix . "\n\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\t" . $where . "\n\t\t\t\t\t\t";
                     $q = new CMS_query($sql);
                     //pr($sql);
                     $results = array();
                     $count = 0;
                     $foundIDs = array();
                     while ($id = $q->getValue('page_pbd')) {
                         $foundIDs[] = $id;
                     }
                     $order = "\n\t\t\t\t\t \t\torder by title_pbd asc\n\t\t\t\t\t\t";
                 } else {
                     //Search in page content (fulltext search)
                     $keywords = implode(' ', $allDatas[self::SEARCH_TYPE_DEFAULT]);
                     $selects = array('pagesBaseData' . $suffix => array('page' => 'page_pbd', 'match' => 'title_pbd,linkTitle_pbd,keywords_pbd,description_pbd,codename_pbd'), 'blocksVarchars' . $suffix => array('page' => 'page', 'match' => 'value'), 'blocksTexts' . $suffix => array('page' => 'page', 'match' => 'value', 'entities' => true), 'blocksImages' . $suffix => array('page' => 'page', 'match' => 'label'), 'blocksFiles' . $suffix => array('page' => 'page', 'match' => 'label'));
                     $matches = array();
                     foreach ($selects as $table => $select) {
                         // Set SQL
                         $sql = "\n\t\t\t\t\t\t\t\tselect \n\t\t\t\t\t\t\t\t\t" . $select['page'] . " as pageId, MATCH (" . $select['match'] . ") AGAINST ('" . sensitiveIO::sanitizeSQLString($keywords) . "') as m1\n\t\t\t\t\t\t\t\t\t" . (isset($select['entities']) && $keywords != htmlentities($keywords) ? " , MATCH (" . $select['match'] . ") AGAINST ('" . sensitiveIO::sanitizeSQLString(htmlentities($keywords)) . "') as m2 " : '') . "\n\t\t\t\t\t\t\t\tfrom \n\t\t\t\t\t\t\t\t\t" . $table . "\n\t\t\t\t\t\t\t\twhere \n\t\t\t\t\t\t\t\t\tMATCH (" . $select['match'] . ") AGAINST ('" . sensitiveIO::sanitizeSQLString($keywords) . "')\n\t\t\t\t\t\t\t\t\t" . (isset($select['entities']) && $keywords != htmlentities($keywords) ? " or MATCH (" . $select['match'] . ") AGAINST ('" . sensitiveIO::sanitizeSQLString(htmlentities($keywords)) . "') " : '') . "\n\t\t\t\t\t\t\t\t";
                         //pr($sql);
                         $q = new CMS_query($sql);
                         while ($r = $q->getArray()) {
                             if (!isset($matches[$r['pageId']]) || isset($matches[$r['pageId']]) && $r['m1'] > $matches[$r['pageId']]) {
                                 $matches[$r['pageId']] = $r['m1'];
                             }
                             if (isset($r['m2']) && (!isset($matches[$r['pageId']]) || isset($matches[$r['pageId']]) && $r['m2'] > $matches[$r['pageId']])) {
                                 $matches[$r['pageId']] = $r['m2'];
                             }
                         }
                     }
                     //sort page Ids by relevance
                     arsort($matches, SORT_NUMERIC);
                     //$matches = array_keys($matches);
                     $order = "\n\t\t\t\t\t \t\torder by field(page_pbd, " . implode(',', array_reverse(array_keys($matches))) . ") desc\n\t\t\t\t\t\t";
                     $foundIDs = $foundIDs ? array_intersect(array_keys($matches), $foundIDs) : array_keys($matches);
                 }
             } else {
                 $order = " order by page_pbd ";
             }
         }
         if ($foundIDs) {
             $select = ' page_pbd ';
             $from = $public ? 'pagesBaseData_public' : 'pagesBaseData_edited';
             $where .= $where && $foundIDs ? " and " : '';
             $where .= $foundIDs ? " page_pbd in (" . implode($foundIDs, ',') . ") " : '';
             if ($where) {
                 // Set SQL
                 $sql = "\n\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t" . $select . "\n\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t" . $from . "\n\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t" . $where . "\n\t\t\t\t\t\t" . $order . "\n\t\t\t\t\t";
                 $q = new CMS_query($sql);
                 //pr($sql);
                 $results = array();
                 $count = 0;
                 while ($arr = $q->getArray()) {
                     $id = $arr["page_pbd"];
                     if ($user->hasPageClearance($id, CLEARANCE_PAGE_VIEW)) {
                         $count++;
                         $results[$id] = $id;
                     }
                 }
             }
         }
     } else {
         // No results
         $count = 0;
     }
     return array('nbresult' => $count, 'nblinksresult' => $allLinksNumber, 'results' => $results, 'score' => $matches);
 }
Пример #3
0
                     $cms_message = $cms_language->getMessage(MESSAGE_ACTION_XML_UPDATED) . ($pagesIds ? ',<br />' . $cms_language->getMessage(MESSAGE_ACTION_N_PAGES_REGEN, array(sizeof($pagesIds))) : '.');
                 } else {
                     $cms_message = $cms_language->getMessage(MESSAGE_ACTION_XML_UPDATED);
                 }
                 $view->setContent($content);
             } else {
                 $cms_message = $cms_language->getMessage(MESSAGE_ERROR_WRITE_ROW);
             }
         }
     } else {
         $cms_message = $cms_language->getMessage(MESSAGE_ERROR_UNKNOWN_ROW);
     }
     break;
 case 'regenerate':
     //submit all public pages using this row to the regenerator
     $pagesIds = CMS_rowsCatalog::getPagesByRow($rowId, false, true);
     if ($pagesIds) {
         CMS_tree::submitToRegenerator($pagesIds, true);
         $cms_message = $cms_language->getMessage(MESSAGE_ACTION_N_PAGES_REGEN, array(sizeof($pagesIds)));
     } else {
         $cms_message = $cms_language->getMessage(MESSAGE_ACTION_NO_PAGES);
     }
     break;
 case 'copy':
     if (is_a($row, "CMS_row") && !$row->hasError()) {
         //Dupplicate selected row with given label
         $label = $cms_language->getMessage(MESSAGE_PAGE_COPY_OF) . ' ' . $row->getLabel();
         $row = CMS_rowsCatalog::getCloneFromID($rowId, $label);
         $log = new CMS_log();
         $log->logMiscAction(CMS_log::LOG_ACTION_TEMPLATE_EDIT, $cms_user, "Row : " . $label . " (create row)");
         $content = array('success' => array('rowId' => $row->getID()));