Пример #1
0
        if ($count >= $start && $countok < $limit) {
            $searchResultsByType[$result[0]][$result[1]] = $count;
            $countok++;
        }
        $count++;
    }
}
//pr($searchResultsByType);
$resultsDatas = array();
$resultsDatas['results'] = array();
$resultsDatas['total'] = $count;
foreach ($searchResultsByType as $type => $results) {
    $items = array();
    switch ($type) {
        case 'rows':
            $rows = CMS_rowsCatalog::getAll(true, '', array(), array_keys($results));
            foreach ($rows as $row) {
                $items[] = $row->getJSonDescription($cms_user, $cms_language, false);
            }
            break;
        case 'templates':
            $tpls = CMS_pageTemplatesCatalog::getAll(true, '', array(), '', array_keys($results));
            foreach ($tpls as $tpl) {
                $items[] = $tpl->getJSonDescription($cms_user, $cms_language, false);
            }
            break;
        case 'users':
            $users = CMS_profile_usersCatalog::getAll(false, false, true, array('id_pru' => array_keys($results)));
            foreach ($users as $user) {
                $items[] = $user->getJSonDescription($cms_user, $cms_language, false);
            }
Пример #2
0
 /**
  * Import module from given array datas
  *
  * @param array $data The module datas to import
  * @param array $params The import parameters.
  *		array(
  *				create	=> false|true : create missing objects (default : true)
  *				update	=> false|true : update existing objects (default : true)
  *				files	=> false|true : use files from PATH_TMP_FS (default : true)
  *			)
  * @param CMS_language $cms_language The CMS_langage to use
  * @param array $idsRelation : Reference : The relations between import datas ids and real imported ids
  * @param string $infos : Reference : The import infos returned
  * @return boolean : true on success, false on failure
  * @access public
  */
 function fromArray($data, $params, $cms_language, &$idsRelation, &$infos)
 {
     if (!$this->getID()) {
         if (!isset($params['create']) || $params['create'] == true) {
             //if module does not exists yet, add codename and default admin frontend
             $this->setCodename($data['codename']);
             $this->setAdminFrontend('index.php');
         } else {
             $infos .= 'Module does not exists and parameter does not allow to create it ...' . "\n";
             return false;
         }
     }
     if (!$this->getID() && (!isset($params['create']) || $params['create'] == true) || $this->getID() && (!isset($params['update']) || $params['update'] == true)) {
         if (isset($data['labels'])) {
             //create labels
             $this->setLabel($cms_language->createMessage($this->_codename, $data['labels']));
         }
         if (!$this->writeToPersistence()) {
             $infos .= 'Error writing module ...' . "\n";
             return false;
         } elseif (isset($data['parameters']) && is_array($data['parameters']) && $data['parameters']) {
             //write module parameters
             $this->_hasParameters = 1;
             $filename = PATH_MODULES_FS . "/" . $this->_codename . "_rc.xml";
             if (!file_exists($filename)) {
                 $file = new CMS_file($filename);
                 $file->writeToPersistence(true);
             }
             $this->setAndWriteParameters($data['parameters']);
             $this->writeToPersistence();
         }
     }
     //append codename to parameters
     $params['module'] = $this->_codename;
     //add categories
     if (isset($data['categories']) && $data['categories']) {
         if (!CMS_moduleCategories_catalog::fromArray($data['categories'], $params, $cms_language, $idsRelation, $infos)) {
             $infos .= 'Error during categories import ...' . "\n";
             return false;
         }
     }
     if (!isset($params['files']) || $params['files'] == true) {
         //add JS
         if (isset($data['js']) && $data['js']) {
             foreach ($data['js'] as $jsFile) {
                 if ($jsFile && file_exists(PATH_TMP_FS . $jsFile)) {
                     if (file_exists(PATH_REALROOT_FS . $jsFile) && (!isset($params['updateJs']) || $params['updateJs'] == true) || (!isset($params['create']) || $params['create'] == true)) {
                         if (CMS_file::moveTo(PATH_TMP_FS . $jsFile, PATH_REALROOT_FS . $jsFile)) {
                             CMS_file::chmodFile(FILES_CHMOD, PATH_REALROOT_FS . $jsFile);
                         } else {
                             $infos .= 'Error during copy of file ' . $jsFile . ' ...' . "\n";
                         }
                     }
                 }
             }
         }
     }
     if (!isset($params['files']) || $params['files'] == true) {
         //add CSS
         if (isset($data['css']) && $data['css']) {
             foreach ($data['css'] as $cssFile) {
                 if ($cssFile && file_exists(PATH_TMP_FS . $cssFile)) {
                     if (file_exists(PATH_REALROOT_FS . $cssFile) && (!isset($params['updateCss']) || $params['updateCss'] == true) || (!isset($params['create']) || $params['create'] == true)) {
                         if (CMS_file::moveTo(PATH_TMP_FS . $cssFile, PATH_REALROOT_FS . $cssFile)) {
                             CMS_file::chmodFile(FILES_CHMOD, PATH_REALROOT_FS . $cssFile);
                         } else {
                             $infos .= 'Error during copy of file ' . $cssFile . ' ...' . "\n";
                         }
                     }
                 }
             }
         }
     }
     if (!isset($params['files']) || $params['files'] == true) {
         //add IMG
         if (isset($data['img']) && $data['img']) {
             foreach ($data['img'] as $imgFile) {
                 if ($imgFile && file_exists(PATH_TMP_FS . $imgFile)) {
                     if (file_exists(PATH_REALROOT_FS . $imgFile) && (!isset($params['updateImg']) || $params['updateImg'] == true) || (!isset($params['create']) || $params['create'] == true)) {
                         if (CMS_file::moveTo(PATH_TMP_FS . $imgFile, PATH_REALROOT_FS . $imgFile)) {
                             CMS_file::chmodFile(FILES_CHMOD, PATH_REALROOT_FS . $imgFile);
                         } else {
                             $infos .= 'Error during copy of file ' . $imgFile . ' ...' . "\n";
                         }
                     }
                 }
             }
         }
     }
     if (!isset($params['files']) || $params['files'] == true) {
         //add rows
         if (isset($data['rows']) && $data['rows']) {
             if (!CMS_rowsCatalog::fromArray($data['rows'], $params, $cms_language, $idsRelation, $infos)) {
                 $infos .= 'Error during rows import ...' . "\n";
                 return false;
             }
         }
     }
     return true;
 }
Пример #3
0
 /**
  * Import row from given array datas
  *
  * @param array $data The module datas to import
  * @param array $params The import parameters.
  *		array(
  *				create	=> false|true : create missing objects (default : true)
  *				update	=> false|true : update existing objects (default : true)
  *				files	=> false|true : use files from PATH_TMP_FS (default : true)
  *			)
  * @param CMS_language $cms_language The CMS_langage to use
  * @param array $idsRelation : Reference : The relations between import datas ids and real imported ids
  * @param string $infos : Reference : The import infos returned
  * @return boolean : true on success, false on failure
  * @access public
  */
 function fromArray($data, $params, $cms_language, &$idsRelation, &$infos)
 {
     if (!$this->getID() && CMS_rowsCatalog::uuidExists($data['uuid'])) {
         //check imported uuid. If rows does not have an Id, the uuid must be unique or must be regenerated
         $uuid = io::uuid();
         //store old uuid relation
         $idsRelation['rows-uuid'][$data['uuid']] = $uuid;
         $data['uuid'] = $uuid;
     }
     //set uuid if not exists
     if (!$this->_uuid) {
         $this->_uuid = $data['uuid'];
     }
     //icon
     if (!isset($params['files']) || $params['files'] == true) {
         if (isset($data['image'])) {
             $icon = $data['image'];
             //create icon (do not update existing icon)
             if ($icon && file_exists(PATH_TMP_FS . $icon) && !file_exists(PATH_REALROOT_FS . $icon)) {
                 //move and rename icon file
                 $filename = PATH_TMP_FS . $icon;
                 $basename = pathinfo($filename, PATHINFO_BASENAME);
                 if ($basename != 'nopicto.gif') {
                     if (CMS_file::copyTo($filename, PATH_REALROOT_FS . $icon)) {
                         //set it
                         $this->setImage($basename);
                     }
                 }
             }
         }
     }
     //label
     if (isset($data['label'])) {
         $this->setLabel($data['label']);
     }
     //description
     if (isset($data['description'])) {
         $this->setDescription($data['description']);
     }
     //groups
     if (isset($data['groups'])) {
         $this->delAllGroups();
         $groups = explode(';', $data['groups']);
         foreach ($groups as $group) {
             if ($group) {
                 $this->addGroup($group);
             }
         }
     }
     //usability
     if (isset($data['useable'])) {
         $this->setUsability($data['useable']);
     }
     //definition & module
     if (!isset($params['files']) || $params['files'] == true) {
         if (isset($data['definition']) && $data['definition']) {
             if (!isset($params['updateRows']) || $params['updateRows'] == true) {
                 //set definition (and unescape cdata)
                 $return = $this->setDefinition(str_replace(']]\\>', ']]>', $data['definition']), false);
                 if ($return !== true) {
                     $infos .= 'Error : cannot set row definition ... : ' . $return . "\n";
                     return false;
                 }
             }
         }
     }
     //write object
     if (!$this->writeToPersistence()) {
         $infos .= 'Error : cannot write row ...' . "\n";
         return false;
     }
     //if current row id has changed from imported id, set relation
     if (isset($data['id']) && $data['id'] && $this->getID() != $data['id']) {
         $idsRelation['rows'][$data['id']] = $this->getID();
     }
     //set this object into definition to convert array so it can be converted again at end of import process
     $idsRelation['definitionToConvert'][] = $this;
     return true;
 }
Пример #4
0
 /**
  * Add a row to the client space.
  *
  * @param integer $rowID the DB ID of the row to add
  * @param integer $rowTagID the ID attribute of the row tag to add
  * @param integer $index the index position of the row in the CS
  * @return boolean true on success, false on failure.
  * @access public
  */
 function addRow($rowID, $rowTagID, $index)
 {
     //check that another row with same tag ID doesn't exists
     foreach ($this->_rows as $row) {
         if ($row->getTagID() == $rowTagID) {
             return false;
         }
     }
     //row index cannot be more than current rows length
     $sizeofRows = sizeof($this->_rows);
     if ($index > $sizeofRows) {
         $index = $sizeofRows;
     }
     $row = CMS_rowsCatalog::getByID($rowID, $rowTagID);
     if (is_a($row, "CMS_row")) {
         //put row at given index
         $rows = array_slice($this->_rows, 0, $index);
         $after = array_slice($this->_rows, $index);
         $rows[] = $row;
         $this->_rows = array_merge($rows, $after);
         return $row;
     } else {
         $this->raiseError("Row addition was not given a valid rowID");
         return false;
     }
 }
Пример #5
0
//CHECKS user has row edition clearance
if (!$cms_user->hasAdminClearance(CLEARANCE_ADMINISTRATION_TEMPLATES)) {
    //rows
    CMS_grandFather::raiseError('User has no rights on rows editions');
    $view->setActionMessage($cms_language->getMessage(MESSAGE_ERROR_NO_RIGHTS_FOR_ROWS));
    $view->show();
}
//usefull vars
$recordsPerPage = CMS_session::getRecordsPerPage();
//
// Search Panel
//
$searchPanel = '';
// Keywords
$searchPanel .= "{\n\tfieldLabel:\t\t'{$cms_language->getJSMessage(MESSAGE_PAGE_BY_NAME_DESCRIPTION)}',\n\txtype:\t\t\t'textfield',\n\tname: \t\t\t'keyword',\n\tvalue:\t\t\t'',\n\tminLength:\t\t3,\n\tanchor:\t\t\t'-20px',\n\tvalidateOnBlur:\tfalse,\n\tlisteners:\t\t{\n\t\t'valid':{\n\t\t\tfn: \t\t\trowWindow.search, \n\t\t\toptions:\t\t{buffer:300}\n\t\t},\n\t\t'invalid':{\n\t\t\tfn: function(field, event) {\n\t\t\t\tif (!isNaN(parseInt(field.getValue()))) {\n\t\t\t\t\tfield.clearInvalid();\n\t\t\t\t\tfield.fireEvent('valid', field);\n\t\t\t\t} else if (!field.getValue()) {\n\t\t\t\t\tfield.clearInvalid();\n\t\t\t\t}\n\t\t\t}, \n\t\t\toptions:\t\t{buffer:300}\n\t\t}\n\t}\n},";
$allGroups = CMS_rowsCatalog::getAllGroups();
natcasesort($allGroups);
if ($allGroups) {
    $columns = sizeof($allGroups) < 2 ? sizeof($allGroups) : 2;
    $searchPanel .= "{\n\t\txtype: \t\t'checkboxgroup',\n\t\tfieldLabel: '{$cms_language->getJSMessage(MESSAGE_PAGE_GROUPS)}',\n\t\tcolumns: \t{$columns},\n\t\titems: [";
    foreach ($allGroups as $aGroup) {
        $searchPanel .= "{boxLabel: '{$aGroup}', inputValue:'{$aGroup}', name: 'groups[]', listeners: {'check':rowWindow.search}},";
    }
    //remove last comma from groups
    $searchPanel = io::substr($searchPanel, 0, -1);
    $searchPanel .= "\n\t\t]\n\t},";
}
$modules = CMS_modulesCatalog::getAll();
if (sizeof($modules) > 1) {
    $modulesDatas = array();
    $modulesDatas['module'] = array(array('id' => 0, 'label' => '-'));
Пример #6
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);
 }
Пример #7
0
 /**
  * Reset all profile clearances
  *
  * @return boolean
  * @access public
  */
 function resetClearances()
 {
     //admin clearance
     $this->_adminClearance = 0;
     // Initiate Stack objects
     $this->_pageClearances = new CMS_stack();
     $this->_validationClearances = new CMS_stack();
     $this->_validationClearances->setValuesByAtom(1);
     $this->_moduleClearances = new CMS_stack();
     $this->_templateGroupsDenied = CMS_pageTemplatesCatalog::getAllGroups(true);
     $this->_rowGroupsDenied = CMS_rowsCatalog::getAllGroups(true);
     // Categories clearance only
     $this->_moduleCategoriesClearances = new CMS_moduleCategoriesClearances();
     return true;
 }
Пример #8
0
 /**
  * Destroy the module
  *
  * @return void
  * @access public
  */
 function destroy()
 {
     global $cms_user;
     // Check module exists and is polymod
     if (!$this->isDestroyable()) {
         return false;
     }
     // CHECK USED ROWS
     $rowsIds = CMS_rowsCatalog::getByModules(array($this->_codename), false, false);
     //delete all module rows
     foreach ($rowsIds as $rowId) {
         $row = CMS_rowsCatalog::getByID($rowId);
         if (is_object($row)) {
             $row->destroy();
         }
     }
     // TREAT CATEGORIES
     $attrs = array("module" => $this->_codename, "language" => CMS_languagesCatalog::getDefaultLanguage(), "level" => -1, "root" => -1, "cms_user" => $cms_user, "clearanceLevel" => CLEARANCE_MODULE_EDIT, "strict" => false);
     $cats = CMS_moduleCategories_catalog::getAll($attrs);
     if ($cats) {
         foreach ($cats as $cat) {
             // Destroy category
             $cat->destroy();
         }
     }
     // TREAT MODULE & VALIDATIONS RIGHTS
     $sql = "\n\t\t\tselect \n\t\t\t\t*\n\t\t\tfrom\n\t\t\t\tprofiles\n\t\t\twhere\n\t\t\t\tmoduleClearancesStack_pr like '" . io::sanitizeSQLString($this->_codename) . ",%'\n\t\t\t\t or moduleClearancesStack_pr like '%;" . io::sanitizeSQLString($this->_codename) . ",%'\n\t\t ";
     $q = new CMS_query($sql);
     if ($q->getNumRows()) {
         while ($r = $q->getArray()) {
             $stack = new CMS_stack();
             $stack->setTextDefinition($r['moduleClearancesStack_pr']);
             $stack->delAllWithOneKey($this->_codename);
             $qInsert = new CMS_query("update profiles set moduleClearancesStack_pr='" . io::sanitizeSQLString($stack->getTextDefinition()) . "' where id_pr='" . $r['id_pr'] . "'");
         }
     }
     $sql = "\n\t\t\tselect \n\t\t\t\t*\n\t\t\tfrom\n\t\t\t\tprofiles\n\t\t\twhere\n\t\t\t\tvalidationClearancesStack_pr like '" . io::sanitizeSQLString($this->_codename) . ";%'\n\t\t\t\t or validationClearancesStack_pr like '%;" . io::sanitizeSQLString($this->_codename) . ";%'\n\t\t\t\t or validationClearancesStack_pr = '" . io::sanitizeSQLString($this->_codename) . "'\n\t\t\t";
     $q = new CMS_query($sql);
     if ($q->getNumRows()) {
         while ($r = $q->getArray()) {
             $stack = new CMS_stack();
             $stack->setTextDefinition($r['validationClearancesStack_pr']);
             $stack->delAllWithOneKey($this->_codename);
             $qInsert = new CMS_query("update profiles set validationClearancesStack_pr='" . io::sanitizeSQLString($stack->getTextDefinition()) . "' where id_pr='" . $r['id_pr'] . "'");
         }
     }
     //remove module files
     if (CMS_file::deltreeSimulation(PATH_MODULES_FILES_FS . '/' . $this->_codename, true)) {
         CMS_file::deltree(PATH_MODULES_FILES_FS . '/' . $this->_codename, true);
     }
     //remove JS and CSS
     if (is_dir(PATH_JS_FS . '/modules/' . $this->_codename) && CMS_file::deltreeSimulation(PATH_JS_FS . '/modules/' . $this->_codename, true)) {
         CMS_file::deltree(PATH_JS_FS . '/modules/' . $this->_codename, true);
     }
     if (is_dir(PATH_CSS_FS . '/modules/' . $this->_codename) && CMS_file::deltreeSimulation(PATH_CSS_FS . '/modules/' . $this->_codename, true)) {
         CMS_file::deltree(PATH_CSS_FS . '/modules/' . $this->_codename, true);
     }
     $cssFiles = $this->getCSSFiles('', true);
     foreach ($cssFiles as $mediaCssFiles) {
         foreach ($mediaCssFiles as $cssFile) {
             CMS_file::deleteFile(PATH_REALROOT_FS . '/' . $cssFile);
         }
     }
     //Clear polymod cache
     //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $this->_codename));
     CMS_cache::clearTypeCache('polymod');
     // Destroy module
     return parent::destroy();
 }
Пример #9
0
        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()));
            $cms_message = $cms_language->getMessage(MESSAGE_ACTION_DUPICATION_DONE, array($label));
            $view->setContent($content);
        } else {
            $cms_message = $cms_language->getMessage(MESSAGE_ERROR_UNKNOWN_ROW);
        }
        break;
}
//set user message if any
if ($cms_message) {
    $view->setActionMessage($cms_message);
}
$view->show();
Пример #10
0
 /**
  * Import module from given array datas
  *
  * @param array $data The module datas to import
  * @param array $params The import parameters.
  * 		array(
  * 				module	=> false|true : the module to create rows (required)
  * 				create	=> false|true : create missing objects (default : true)
  * 				update	=> false|true : update existing objects (default : true)
  * 				files	=> false|true : use files from PATH_TMP_FS (default : true)
  * 			)
  * @param CMS_language $cms_language The CMS_langage to use
  * @param array $idsRelation : Reference : The relations between import datas ids and real imported ids
  * @param string $infos : Reference : The import infos returned
  * @return boolean : true on success, false on failure
  * @access public
  */
 static function fromArray($data, $params, $cms_language, &$idsRelation, &$infos)
 {
     if (!isset($params['module'])) {
         $infos .= 'Error : missing module codename for rows importation ...' . "\n";
         return false;
     }
     $module = CMS_modulesCatalog::getByCodename($params['module']);
     if ($module->hasError()) {
         $infos .= 'Error : invalid module for rows importation : ' . $params['module'] . "\n";
         return false;
     }
     $return = true;
     foreach ($data as $rowDatas) {
         $importType = '';
         if (isset($rowDatas['uuid']) && ($id = CMS_rowsCatalog::rowExists($params['module'], $rowDatas['uuid']))) {
             //row already exist : load it if we can update it
             if (!isset($params['update']) || $params['update'] == true) {
                 $row = CMS_rowsCatalog::getByID($id);
                 $importType = ' (Update)';
             }
         } else {
             //create new row if we can
             if (!isset($params['create']) || $params['create'] == true) {
                 //create row
                 $row = new CMS_row();
                 $importType = ' (Creation)';
             }
         }
         if (isset($row)) {
             if ($row->fromArray($rowDatas, $params, $cms_language, $idsRelation, $infos)) {
                 $return &= true;
                 $infos .= 'Row ' . $row->getLabel() . ' successfully imported' . $importType . "\n";
             } else {
                 $return = false;
                 $infos .= 'Error during import of row ' . $rowDatas['id'] . $importType . "\n";
             }
         }
     }
     return $return;
 }
Пример #11
0
$imageDatas = sensitiveIO::jsonEncode($imageDatas);
//Groups
$allGroups = CMS_rowsCatalog::getAllGroups();
$groupsfield = '';
if ($allGroups) {
    $columns = sizeof($allGroups) < 5 ? sizeof($allGroups) : 5;
    $groupsfield .= "{\n\t\txtype: \t\t'checkboxgroup',\n\t\tfieldLabel: '<span class=\"atm-help\" ext:qtip=\"{$cms_language->getJsMessage(MESSAGE_FIELD_GROUPS_DESC)}\">{$cms_language->getJsMessage(MESSAGE_FIELD_GROUPS)}</span>',\n\t\tcolumns: \t{$columns},\n\t\titems: [";
    foreach ($allGroups as $aGroup) {
        $groupsfield .= "{boxLabel: '{$aGroup}', inputValue:'{$aGroup}', name: 'groups[]', checked:" . (isset($rowGroups[$aGroup]) ? 'true' : 'false') . "},";
    }
    //remove last comma from groups
    $groupsfield = io::substr($groupsfield, 0, -1);
    $groupsfield .= "\n\t\t]\n\t},";
}
//images
$allIcons = CMS_rowsCatalog::getAllIcons();
$iconsField = '';
if ($allIcons) {
    //get max icons height
    $maxheight = 0;
    foreach ($allIcons as $icon) {
        list($sizeX, $sizeY) = @getimagesize($_SERVER["DOCUMENT_ROOT"] . "/" . $icon);
        $maxheight = $sizeY > $maxheight ? $sizeY : $maxheight;
    }
    $maxheight += 10;
    $columns = sizeof($allIcons) < 5 ? sizeof($allIcons) : 5;
    $iconsField .= "{\n\t\txtype: \t\t'radiogroup',\n\t\tfieldLabel: '<span class=\"atm-help\" ext:qtip=\"{$cms_language->getJsMessage(MESSAGE_FIELD_ICON_DESC)}\">{$cms_language->getJsMessage(MESSAGE_FIELD_ICON)}</span>',\n\t\tcolumns: \t{$columns},\n\t\titems: [";
    foreach ($allIcons as $icon) {
        $iconsField .= "{boxLabel: '<img src=\"{$icon}\">', height:" . $maxheight . ", inputValue:'{$icon}', name: 'image', checked:" . ($row->getImage() == $icon ? 'true' : 'false') . "},";
    }
    //remove last comma from groups
Пример #12
0
            $skipSearch = true;
        }
    }
} else {
    $rowIds = $items;
}
if ($currentTpl) {
    //check if template is a clone
    $tplId = CMS_pageTemplatesCatalog::getTemplateIDForCloneID($currentTpl);
    if ($tplId && $tplId != $currentTpl) {
        $currentTpl = $tplId;
    }
}
if (!$skipSearch) {
    $rows = CMS_rowsCatalog::getAll($viewinactive, $keyword, $groups, $rowIds, $cms_user, $currentTpl, $currentCS, $start, $limit);
    $rowsDatas['total'] = sizeof(CMS_rowsCatalog::getAll($viewinactive, $keyword, $groups, $rowIds, $cms_user, $currentTpl, $currentCS, 0, 0, false));
} else {
    $rows = array();
    $rowsDatas['total'] = 0;
}
foreach ($rows as $row) {
    if ($cms_user->hasAdminClearance(CLEARANCE_ADMINISTRATION_TEMPLATES)) {
        //rows
        if ($delete) {
            if (is_a($row, "CMS_row") && !$row->hasClientSpaces()) {
                $log = new CMS_log();
                $log->logMiscAction(CMS_log::LOG_ACTION_TEMPLATE_DELETE, $cms_user, "Row : " . $row->getLabel());
                $row->destroy();
                unset($row);
                $rowsDatas['total']--;
                continue;