Example #1
0
 /**
  * Duplicate current page into another one
  * All contents and external datas are duplicated too
  *
  * @param CMS_user user, the user processing to creation
  * @param integer templateID, a new template to duplicate the page with
  * @param boolean $dontDuplicateContent If true, the content of the page is not duplicated
  * @return CMS_page newly created, or null on error
  */
 function duplicate(&$user, $templateID = 0, $dontDuplicateContent = false)
 {
     $pg = null;
     if ($user->hasPageClearance($this->getID(), CLEARANCE_PAGE_VIEW) && $user->hasModuleClearance(MOD_STANDARD_CODENAME, CLEARANCE_MODULE_EDIT)) {
         $pg = new CMS_page();
         $pg->lock($user);
         $pg->addEdition(RESOURCE_EDITION_CONTENT, $user);
         //Which template to use?
         if (!$templateID) {
             $newTpl = CMS_pageTemplatesCatalog::getCloneFromID($this->_templateID, false, true, false, $this->_templateID);
         } else {
             $newTpl = CMS_pageTemplatesCatalog::getCloneFromID($templateID, false, true, false, $this->_templateID);
         }
         if (!is_a($newTpl, 'CMS_pageTemplate') || $newTpl->hasError()) {
             $this->raiseError("Error during template clone creation.");
         } else {
             $pg->setTemplate($newTpl->getID());
         }
         //Duplicate page base datas
         $pg->setTitle($this->getTitle(), $user);
         $pg->setLinkTitle($this->getLinkTitle(), $user);
         $pg->setDescription($this->getDescription(false, false), $user);
         $pg->setKeywords($this->getKeywords(false, false), $user);
         $pg->setPublicationDates($this->getPublicationDateStart(false), $this->getPublicationDateEnd(false));
         $pg->setReminderOn($this->getReminderOn(false, false), $user);
         $pg->setReminderOnMessage($this->getReminderOnMessage(false, false), $user);
         $pg->setCategory($this->getCategory(false, false), $user);
         $pg->setAuthor($this->getAuthor(false, false), $user);
         $pg->setReplyto($this->getReplyto(false, false), $user);
         $pg->setCopyright($this->getCopyright(false, false), $user);
         $pg->setLanguage($this->getLanguage(false, false), $user);
         $pg->setRobots($this->getRobots(false, false), $user);
         $pg->setPragma($this->getPragma(false, false), $user);
         $pg->setRefresh($this->getRefresh(false, false), $user);
         $pg->setRedirectLink($this->getRedirectLink(), $user);
         $pg->setMetas($this->getMetas(false, false), $user);
         $pg->setCodename($this->getCodename(), $user, false);
         if (SensitiveIO::isPositiveInteger($this->getReminderPeriodicity())) {
             $pg->setReminderPeriodicity($this->getReminderPeriodicity(), $user);
         }
         $pg->writeToPersistence();
         $pg->unlock();
         //Duplicate contents, get all blocks and duplicate them
         if (!$dontDuplicateContent) {
             $this->duplicateContent($user, $pg);
         }
     } else {
         $this->raiseError("User doesn't have rights to do this creation");
     }
     return $pg;
 }
Example #2
0
}
//check for view rights for user
if (!$cms_user->hasPageClearance($cms_page->getID(), CLEARANCE_PAGE_VIEW)) {
    CMS_grandFather::raiseError('Error, user has no rights on page : ' . $cms_page->getID());
    $view->show();
}
$pageId = $cms_page->getID();
$pageTitle = sensitiveIO::sanitizeJSString($cms_page->getTitle(true));
$onClick = base64_encode("\n\tthis.node.select();\n");
//Page templates replacement
$pageTemplate = $cms_page->getTemplate();
//hack if page has no valid template attached
if (!is_a($pageTemplate, "CMS_pageTemplate")) {
    $pageTemplate = new CMS_pageTemplate();
}
$pageTplId = CMS_pageTemplatesCatalog::getTemplateIDForCloneID($pageTemplate->getID());
$pageTplLabel = sensitiveIO::sanitizeJSString($pageTemplate->getLabel());
$jscontent = <<<END
\tvar copyPageWindow = Ext.getCmp('{$winId}');
\t//if we are in a window context
\t
\t//set window title
\tcopyPageWindow.setTitle('{$cms_language->getJsMessage(MESSAGE_PAGE_COPY)} \\'{$pageTitle}\\'');
\t//set help button on top of page
\tcopyPageWindow.tools['help'].show();
\t//add a tooltip on button
\tvar pageTip = new Ext.ToolTip({
\t\ttarget: \t\tcopyPageWindow.tools['help'],
\t\ttitle: \t\t\t'{$cms_language->getJsMessage(MESSAGE_TOOLBAR_HELP)}',
\t\thtml: \t\t\t'{$cms_language->getJsMessage(MESSAGE_PAGE_COPY_INFO)}',
\t\tdismissDelay:\t0
Example #3
0
}
//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);
            }
            break;
        case 'groups':
            $groups = CMS_profile_usersGroupsCatalog::search('', '', false, array_keys($results));
            foreach ($groups as $group) {
                $items[] = $group->getJSonDescription($cms_user, $cms_language, false);
            }
            if ($page->getPublication() == RESOURCE_PUBLICATION_PUBLIC) {
                $pagesIds[] = $page->getID();
            }
        }
        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_ERROR_NO_PUBLIC_PAGE);
        }
        break;
    case 'copy':
        if (is_a($template, "CMS_pageTemplate") && !$template->hasError()) {
            //Dupplicate selected template with given label
            $label = $cms_language->getMessage(MESSAGE_PAGE_COPY_OF) . ' ' . $template->getLabel();
            $template = CMS_pageTemplatesCatalog::getCloneFromID($templateId, $label);
            $log = new CMS_log();
            $log->logMiscAction(CMS_log::LOG_ACTION_TEMPLATE_EDIT, $cms_user, "Template : " . $label . " (create template)");
            $content = array('success' => array('templateId' => $template->getID()));
            $cms_message = $cms_language->getMessage(MESSAGE_ACTION_DUPICATION_DONE, array($label));
            $view->setContent($content);
        } else {
            $cms_message = $cms_language->getMessage(MESSAGE_ERROR_UNKNOWN_TEMPLATE);
        }
        break;
}
//set user message if any
if ($cms_message) {
    $view->setActionMessage($cms_message);
}
$view->show();
Example #5
0
 function getJSonDescription($user, $cms_language, $withDefinition = false)
 {
     $hasClientSpaces = $this->hasClientSpaces();
     $shortdesc = sensitiveIO::ellipsis($this->getDescription(), 60);
     if ($shortdesc != nl2br($this->getDescription())) {
         $shortdesc = '<span class="atm-help" ext:qtip="' . nl2br(io::htmlspecialchars(strip_tags($this->getDescription()))) . '">' . io::htmlspecialchars($shortdesc) . '</span>';
     }
     $shortdesc = $shortdesc ? $shortdesc . '<br />' : '';
     $mediumdesc = sensitiveIO::ellipsis($this->getDescription(), 200);
     if ($mediumdesc != $this->getDescription()) {
         $mediumdesc = '<span class="atm-help" ext:qtip="' . nl2br(io::htmlspecialchars(strip_tags($this->getDescription()))) . '">' . nl2br(io::htmlspecialchars($mediumdesc)) . '</span>';
     } else {
         $mediumdesc = io::htmlspecialchars($mediumdesc);
     }
     $mediumdesc = $mediumdesc ? $mediumdesc . '<br />' : '';
     //append template definition if needed
     $definitionDatas = $withDefinition ? $this->getDefinition() : '';
     //templates filters
     $filteredTemplates = '';
     if ($this->getFilteredTemplates()) {
         foreach ($this->getFilteredTemplates() as $tplId) {
             $template = CMS_pageTemplatesCatalog::getByID($tplId);
             if (is_object($template) && !$template->hasError()) {
                 $filteredTemplates .= $filteredTemplates ? ', ' : '';
                 $filteredTemplates .= $template->getLabel();
             }
         }
     }
     $filtersInfos = '';
     $filtersInfos .= $filteredTemplates ? $cms_language->getMessage(self::MESSAGE_DESC_TEMPLATES) . ' ' . $filteredTemplates : '';
     $filtersInfos = $filtersInfos ? '<br />' . $cms_language->getMessage(self::MESSAGE_DESC_USAGE_RESTRICTION) . ' <strong>' . $filtersInfos . '</strong>' : '';
     if ($user->hasAdminClearance(CLEARANCE_ADMINISTRATION_TEMPLATES)) {
         $edit = array('url' => 'row.php', 'params' => array('row' => $this->getID()));
     } else {
         $edit = false;
     }
     return array('id' => $this->getID(), 'label' => $this->getLabel(), 'type' => $cms_language->getMessage(self::MESSAGE_DESC_ROW_TEMPLATE), 'image' => $this->getImage(), 'groups' => implode(', ', $this->getGroups()), 'filter' => $this->getLabel() . ' ' . implode(', ', $this->getGroups()), 'tplfilter' => implode(',', $this->getFilteredTemplates()), 'description' => '<div' . (!$this->isUseable() ? ' class="atm-inactive"' : '') . '>' . '<img src="' . $this->getImage() . '" style="float:left;margin-right:3px;width:70px;" />' . $mediumdesc . $cms_language->getMessage(self::MESSAGE_DESC_GROUPS) . ' <strong>' . ($this->getGroups() ? implode(', ', $this->getGroups()) : $cms_language->getMessage(self::MESSAGE_DESC_NONE)) . '</strong><br />' . $cms_language->getMessage(self::MESSAGE_DESC_ACTIVE) . ' <strong>' . ($this->isUseable() ? $cms_language->getMessage(self::MESSAGE_DESC_YES) : $cms_language->getMessage(self::MESSAGE_DESC_NO)) . '</strong><br />' . $cms_language->getMessage(self::MESSAGE_DESC_USED) . ' <strong>' . ($hasClientSpaces ? $cms_language->getMessage(self::MESSAGE_DESC_YES) : $cms_language->getMessage(self::MESSAGE_DESC_NO)) . '</strong>' . ($hasClientSpaces ? ' - <a href="#" onclick="Automne.view.search(\'row:' . $this->getID() . '\');return false;">' . $cms_language->getMessage(self::MESSAGE_DESC_SEE) . '</a>' . ($user->hasAdminClearance(CLEARANCE_ADMINISTRATION_REGENERATEPAGES) ? ' / <a href="#" onclick="Automne.server.call(\'rows-controler.php\', \'\', {rowId:' . $this->getID() . ', action:\'regenerate\'});return false;">' . $cms_language->getMessage(self::MESSAGE_DESC_REGENERATE) . '</a>' : '') . ' ' . $cms_language->getMessage(self::MESSAGE_DESC_PAGES) : '') . '<br />' . $cms_language->getMessage(self::MESSAGE_DESC_FILE) . ' <strong>' . $this->getDefinitionFileName() . '</strong>' . $filtersInfos . '<br class="x-form-clear" />' . '</div>', 'activated' => $this->isUseable() ? true : false, 'used' => $hasClientSpaces, 'definition' => $definitionDatas, 'edit' => $edit, 'shortdesc' => $shortdesc);
 }
Example #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);
 }
Example #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;
 }
Example #8
0
 function duplicatePage($user, $page, $pageToAttachTo)
 {
     global $pageDuplicated, $duplicatedCodenames, $cms_user;
     if (is_a($page, "CMS_page") && is_a($pageToAttachTo, "CMS_page") && $page->getTemplate()) {
         //check codename duplication
         $removeCodename = false;
         if ($page->getCodename()) {
             //if codename already exists in website destination, then we must remove it
             if (CMS_tree::getPageByCodename($page->getCodename(), $pageToAttachTo->getWebsite(), false, false)) {
                 $removeCodename = true;
             }
         }
         //Duplicate page template
         $tpl = $page->getTemplate();
         $tpl_copy = CMS_pageTemplatesCatalog::getCloneFromID($tpl->getID(), false, true, false, $tpl->getID());
         $_tplID = $tpl_copy->getID();
         //Create copy of given page
         $newPage = $page->duplicate($user, $_tplID);
         if ($removeCodename) {
             $newPage->setCodename('', $cms_user);
             $newPage->writeToPersistence();
             $duplicatedCodenames[] = $page->getCodename();
         }
         //Move to destination in tree
         if (is_null($newPage) || !CMS_tree::attachPageToTree($newPage, $pageToAttachTo)) {
             return null;
         }
         $pageDuplicated[] = $newPage->getID();
         //Proceed with siblings
         $sibs = CMS_tree::getSiblings($page);
         if (!$sibs || !sizeof($sibs)) {
             return $pageToAttachTo;
         } else {
             $pageToAttachTo = $newPage;
         }
         foreach ($sibs as $sib) {
             if ($user->hasPageClearance($sib->getID(), CLEARANCE_PAGE_EDIT) && !in_array($sib->getID(), $pageDuplicated)) {
                 duplicatePage($user, $sib, $pageToAttachTo);
             }
         }
     }
 }
Example #9
0
         $group->delValidationClearance($moduleCodename);
         if ($validation) {
             $group->addValidationClearance($moduleCodename);
         }
         $group->writeToPersistence();
         $group->applyToUsers();
         $log = new CMS_log();
         $log->logMiscAction(CMS_log::LOG_ACTION_PROFILE_GROUP_EDIT, $cms_user, "Group : " . $group->getLabel() . " (edit module clearance)");
         $cms_message = $cms_language->getMessage(MESSAGE_PAGE_DATA_SAVED_GROUP);
     } else {
         $cms_message = $cms_language->getMessage(MESSAGE_PAGE_UNKNOWN_USER);
     }
     break;
 case 'templates-rights':
     if (is_a($group, "CMS_profile_usersGroup")) {
         $templateGroups = CMS_pageTemplatesCatalog::getAllGroups();
         $newTemplateGroups = new CMS_Stack();
         $newTemplateGroups->setValuesByAtom(1);
         foreach ($templateGroups as $templateGroup) {
             if (!isset($templates[base64_encode($templateGroup)]) || $templates[base64_encode($templateGroup)] != 'on') {
                 $newTemplateGroups->add($templateGroup);
             }
         }
         $group->setTemplateGroupsDenied($newTemplateGroups);
         $group->writeToPersistence();
         $group->applyToUsers();
         $log = new CMS_log();
         $log->logMiscAction(CMS_log::LOG_ACTION_PROFILE_GROUP_EDIT, $cms_user, "Group : " . $group->getLabel() . " (edit templates groups)");
         $cms_message = $cms_language->getMessage(MESSAGE_PAGE_DATA_SAVED_GROUP);
     } else {
         $cms_message = $cms_language->getMessage(MESSAGE_PAGE_UNKNOWN_USER);
Example #10
0
        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
    $iconsField = io::substr($iconsField, 0, -1);
    $iconsField .= "\n\t\t]\n\t},";
}
//Templates filters
$filteredTemplates = $row->getFilteredTemplates();
$templates = CMS_pageTemplatesCatalog::getAll(true, '', array(), '', array(), $cms_user, 0, 0, true);
$availableTemplates = $selectedTemplates = array();
foreach ($templates as $id => $template) {
    if (in_array($id, $filteredTemplates)) {
        $selectedTemplates[] = array($id, $template->getLabel());
    } else {
        $availableTemplates[] = array($id, $template->getLabel());
    }
}
$availableTemplates = sensitiveIO::jsonEncode($availableTemplates);
$selectedTemplates = sensitiveIO::jsonEncode($selectedTemplates);
//DEFINITION TAB
$rowDefinition = $rowDefinition ? $rowDefinition : '<row></row>';
$content = '<textarea id="row-definition-' . $rowId . '" style="display:none;">' . htmlspecialchars($rowDefinition) . '</textarea>';
$view->setContent($content);
$title = sensitiveIO::sanitizeJSString(sensitiveIO::isPositiveInteger($rowId) ? $cms_language->getMessage(MESSAGE_PAGE_ROW) . ' ' . $label : $cms_language->getMessage(MESSAGE_PAGE_ROW_CREATE));
Example #11
0
        $keyword = '';
    }
    if ($module) {
        //filter by module
        $ids = CMS_rowsCatalog::getByModules(array($module), false, false);
        $rowIds = $rowIds ? array_intersect($rowIds, $ids) : $ids;
        if (!$rowIds) {
            $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) {
                 $pageTplIds = array(CMS_pageTemplatesCatalog::getTemplateIDForCloneID($pageTemplate->getID()));
             }
         }
     }
     if (io::isPositiveInteger($keyword)) {
         $pageTplIds[] = $keyword;
         $keyword = '';
     }
 } else {
     $pageTplIds = $items;
 }
 $templatesDatas = array();
 $templatesDatas['results'] = array();
 //get array of available templates
 $templates = CMS_pageTemplatesCatalog::getAll($viewinactive, $keyword, $groups, $website, $pageTplIds, $cms_user, $start, $limit);
 $templatesDatas['total'] = sizeof(CMS_pageTemplatesCatalog::getAll($viewinactive, $keyword, $groups, $website, $pageTplIds, $cms_user, 0, 0, false));
 foreach ($templates as $template) {
     if ($cms_user->hasAdminClearance(CLEARANCE_ADMINISTRATION_EDIT_TEMPLATES)) {
         //templates
         if ($delete) {
             if (is_a($template, "CMS_pageTemplate") && !$template->hasPages()) {
                 $log = new CMS_log();
                 $log->logMiscAction(CMS_log::LOG_ACTION_TEMPLATE_DELETE, $cms_user, "Template : " . $template->getLabel());
                 if ($template->isPrivate()) {
                     $template->destroy();
                 } else {
                     //destroy with definition file
                     $template->destroy(true);
                 }
                 unset($template);
                 $templatesDatas['total']--;
Example #13
0
 * @package Automne
 * @subpackage admin
 * @author Antoine Pouch <*****@*****.**> &
 * @author Sébastien Pauchet <*****@*****.**>
 */
require_once dirname(__FILE__) . '/../../cms_rc_admin.php';
define("MESSAGE_PAGE_TITLE", 852);
$view = CMS_view::getInstance();
$templateId = sensitiveIO::request('template', 'sensitiveIO::isPositiveInteger');
//unset request to avoid it to have interaction with page code
sensitiveIO::unsetRequest(array('template'));
//CHECKS
if (!SensitiveIO::isPositiveInteger($templateId)) {
    die("Invalid template");
}
$template = CMS_pageTemplatesCatalog::getByID($templateId);
if (!is_object($template) || $template->hasError()) {
    die("Invalid template or template error");
}
//RIGHTS CHECK
if (!$cms_user->hasAdminClearance(CLEARANCE_ADMINISTRATION_EDIT_TEMPLATES)) {
    //templates
    die("User has no rights on template edition");
}
$dummy_page = CMS_tree::getRoot();
$dummy_page->setTitle($cms_language->getMessage(MESSAGE_PAGE_TITLE, array($template->getLabel())), $cms_user);
//add ext and edit JS files
$view->addJSFile('ext');
$view->addJSFile('edit');
//get page content
$dummy_page->setTemplate($template->getID());
 /**
  * Get all templates replacement for a given template
  *
  * @param CMS_pageTemplate $tplFrom : the template to get replacements
  * @param CMS_profile_user $cms_user : user to get template replacements (to check rights)
  * @param integer $pageId : user to get template replacements (to check websites)
  * @return array : templates replacements array('match' => array(CMS_pageTemplate), 'nomatch' => array(CMS_pageTemplate));
  * @access public
  */
 static function getTemplatesReplacement($tplFrom, $user, $pageId = false)
 {
     if (!is_a($tplFrom, "CMS_pageTemplate")) {
         CMS_grandFather::raiseError('Template must be a valid CMS_pageTemplate object');
         return array('match' => array(), 'nomatch' => array());
     }
     //get website id if page id is provided
     $websiteId = '';
     if (sensitiveIO::isPositiveInteger($pageId)) {
         $page = CMS_tree::getPageByID($pageId);
         if ($page) {
             $website = $page->getWebsite();
             if ($website) {
                 $websiteId = $website->getID();
             }
         }
     }
     //All templates avalaibles for this user and page website
     $templatesReplacements = CMS_pageTemplatesCatalog::getAll(false, '', array(), $websiteId, array(), $user);
     $matchTpl = array();
     $notMatchTpl = array();
     //modules called in tplFrom
     $tplFromModules = $tplFrom->getModules();
     //clientSpaces in tplFrom
     $csFrom = $tplFrom->getClientSpacesTags();
     $oldClientSpaces = array();
     foreach ($csFrom as $tag) {
         $id = $tag->getAttribute("id") ? $tag->getAttribute("id") : 'NO ID';
         $oldClientSpaces[$tag->getAttribute("module")][] = $id;
     }
     //then check each templates
     foreach ($templatesReplacements as $tplTo) {
         $match = true;
         //remove templates wich not use same modules
         $tplToModules = $tplTo->getModules();
         if ($tplToModules != $tplFromModules) {
             $match = false;
         }
         //check for template number (must be greater or egual)
         if ($match) {
             $csTo = $tplTo->getClientSpacesTags();
             if (sizeof($csTo) < sizeof($csFrom)) {
                 $match = false;
             }
         }
         //search all tpl from in tpl to
         if ($match) {
             $newClientSpaces = array();
             foreach ($csTo as $tag) {
                 $id = $tag->getAttribute("id") ? $tag->getAttribute("id") : 'NO ID';
                 $newClientSpaces[$tag->getAttribute("module")][] = $id;
             }
             foreach ($oldClientSpaces as $module => $moduleCs) {
                 foreach ($moduleCs as $csId) {
                     //search id in from tpl
                     if (!isset($newClientSpaces[$module]) || !in_array($csId, $newClientSpaces[$module])) {
                         $match = false;
                     }
                 }
             }
         }
         if ($match) {
             //here templates match so add it to the array
             $matchTpl[] = $tplTo;
         } else {
             $notMatchTpl[] = $tplTo;
         }
     }
     //sort tables by template labels
     $sortfunc = create_function('$a,$b', 'return strnatcasecmp($a->getLabel(), $b->getLabel());');
     if ($sortfunc) {
         if ($matchTpl) {
             usort($matchTpl, $sortfunc);
         }
         if ($notMatchTpl) {
             usort($notMatchTpl, $sortfunc);
         }
     }
     //then return array of templates
     return array('match' => $matchTpl, 'nomatch' => $notMatchTpl);
 }