Exemple #1
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();
 }
Exemple #2
0
 /**
  * Get object as an array structure used for export
  *
  * @param array $params The export parameters.
  *		array(
  *				categories	=> false|true : export module categories (default : true)
  *				rows		=> false|true : export module rows (default : true)
  *				css			=> false|true : export module JS (default : true)
  *				js			=> false|true : export module CSS (default : true)
  *			)
  * @param array $files The reference to the found files used by object
  * @return array : the object array structure
  * @access public
  */
 public function asArray($params = array(), &$files)
 {
     if (!is_array($files)) {
         $files = array();
     }
     $aModule = array('codename' => $this->_codename, 'polymod' => false, 'labels' => CMS_language::getMessages(1, $this->_codename), 'parameters' => $this->getParameters(false, true));
     $defaultLanguage = CMS_languagesCatalog::getDefaultLanguage();
     if (in_array('categories', $params)) {
         global $cms_user;
         if (APPLICATION_ENFORCES_ACCESS_CONTROL != false && isset($cms_user)) {
             $categories = $this->getModuleCategories(array('language' => $defaultLanguage, 'root' => 0, 'cms_user' => $cms_user));
         } else {
             $categories = $this->getModuleCategories(array('language' => $defaultLanguage, 'root' => 0));
         }
         foreach ($categories as $category) {
             $aModule['categories'][] = $category->asArray($params, $files);
         }
     }
     if (in_array('rows', $params)) {
         $modulesRows = CMS_rowsCatalog::getByModules(array($this->_codename));
         if ($this->_codename != MOD_STANDARD_CODENAME) {
             $modulesStandardRows = CMS_rowsCatalog::getByModules(array($this->_codename, MOD_STANDARD_CODENAME));
             foreach ($modulesStandardRows as $id => $row) {
                 $modulesRows[$id] = $row;
             }
         }
         foreach ($modulesRows as $row) {
             $aModule['rows'][] = $row->asArray($params, $files);
         }
     }
     if (in_array('js', $params)) {
         $jsFiles = $this->getJSFiles('', true);
         $aModule['js'] = array();
         if ($jsFiles) {
             foreach ($jsFiles as $key => $jsFile) {
                 $jsFiles[$key] = '/' . $jsFile;
             }
             $aModule['js'] = $jsFiles;
             $files = array_merge($files, $jsFiles);
         }
     }
     if (in_array('css', $params)) {
         $cssFiles = $this->getCSSFiles('', true);
         $aModule['css'] = array();
         if ($cssFiles) {
             foreach ($cssFiles as $media => $cssMediaFiles) {
                 if ($cssMediaFiles) {
                     foreach ($cssMediaFiles as $key => $cssFile) {
                         $cssMediaFiles[$key] = '/' . $cssFile;
                     }
                     $files = array_merge($files, $cssMediaFiles);
                     $aModule['css'] = array_merge($aModule['css'], $cssMediaFiles);
                 }
             }
         }
     }
     if (in_array('img', $params)) {
         $imgFiles = array();
         $aModule['css'] = array();
         if (is_dir(PATH_REALROOT_FS . '/img/modules/' . $this->getCodename())) {
             $imgFiles = glob(PATH_REALROOT_FS . '/img/modules/' . $this->getCodename() . '/*.*', GLOB_NOSORT);
         }
         if ($imgFiles && is_array($imgFiles)) {
             foreach ($imgFiles as $key => $imgFile) {
                 $imgFiles[$key] = str_replace(PATH_REALROOT_FS, '', $imgFile);
             }
             $aModule['img'] = $imgFiles;
             $files = array_merge($files, $imgFiles);
         }
     }
     return $aModule;
 }
    $rowIds = array();
    if ($pageId) {
        //filter by page if needed
        $rowIds = CMS_rowsCatalog::getRowsByPage($pageId);
        if (!$rowIds) {
            $skipSearch = true;
        }
    }
    if (io::isPositiveInteger($keyword)) {
        //filter by id
        $rowIds = array($keyword);
        $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;
    }
}