Example #1
0
    /**
     * Return the module code for the specified treatment mode, visualization mode and object.
     *
     * @param mixed $modulesCode the previous modules codes (usually string)
     * @param integer $treatmentMode The current treatment mode (see constants on top of this file for accepted values).
     * @param integer $visualizationMode The current visualization mode (see constants on top of cms_page class for accepted values).
     * @param object $treatedObject The reference object to treat.
     * @param array $treatmentParameters : optionnal parameters used for the treatment. Usually an array of objects.
     *
     * @return string : the module code to add
     * @access public
     */
    function getModuleCode($modulesCode, $treatmentMode, $visualizationMode, &$treatedObject, $treatmentParameters)
    {
        switch ($treatmentMode) {
            case MODULE_TREATMENT_PAGECONTENT_HEADER_CODE:
                //if this page use a row of this module then add the header code to the page
                if ($usage = CMS_module::moduleUsage($treatedObject->getID(), $this->_codename)) {
                    if (isset($usage['headCallback'])) {
                        $modulesCode[$this->_codename] = '';
                        foreach ($usage['headCallback'] as $headCallback) {
                            //add header codes
                            if (isset($headCallback['tagsCallback'])) {
                                foreach ($headCallback['tagsCallback'] as $key => $headcode) {
                                    if (isset($headcode['code'])) {
                                        $modulesCode[$this->_codename] .= '<?php' . "\n" . $headCallback['headcode'] . "\n" . $headcode['code'] . "\n" . '?>';
                                    }
                                }
                            }
                            //add forms header if needed
                            if (isset($headCallback['form']) && $headCallback['form']) {
                                $modulesCode[$this->_codename] .= '<?php CMS_poly_definition_functions::formActions(' . var_export($headCallback['form'], true) . ', \'' . $treatedObject->getID() . '\', \'' . $headCallback['language'] . '\', ' . ($visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC || $visualizationMode == PAGE_VISUALMODE_PRINT || $visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC_INDEXABLE ? 'true' : 'false') . ', $polymodFormsError, $polymodFormsItems); ?>';
                            }
                            //add forms callback if needed
                            if (isset($headCallback['formsCallback']) && is_array($headCallback['formsCallback']) && isset($headCallback['headcode'])) {
                                foreach ($headCallback['formsCallback'] as $formName => $formCallback) {
                                    foreach ($formCallback as $formFieldID => $callback) {
                                        if (io::isPositiveInteger($formFieldID)) {
                                            $modulesCode[$this->_codename] .= '<?php' . "\n" . '//callback function to check field ' . $formFieldID . ' for atm-form ' . $formName . "\n" . 'function form_' . $formName . '_' . $formFieldID . '($formName, $fieldID, &$item_' . $formName . '_' . $formFieldID . ') {' . "\n" . '		global $cms_user;' . "\n" . '		global $public_search;' . "\n" . '		global $cms_language;' . "\n" . '       $object[$item_' . $formName . '_' . $formFieldID . '->getObjectID()] = $item_' . $formName . '_' . $formFieldID . ';' . "\n" . '       ' . $headCallback['headcode'] . "\n" . '       ' . $callback . "\n" . '       return false;' . "\n" . '}' . "\n" . '?>';
                                        } elseif ($formFieldID == 'form') {
                                            $modulesCode[$this->_codename] .= '<?php' . "\n" . '//callback function for atm-form ' . $formName . "\n" . 'function form_' . $formName . '($formName, &$item_' . $formName . ') {' . "\n" . '		global $cms_user;' . "\n" . '		global $public_search;' . "\n" . '		global $cms_language;' . "\n" . '       $object[$item_' . $formName . '->getObjectID()] = $item_' . $formName . ';' . "\n" . '       ' . $headCallback['headcode'] . "\n" . '       ' . $callback . "\n" . '       return true;' . "\n" . '}' . "\n" . '?>';
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                return $modulesCode;
                break;
            case MODULE_TREATMENT_ROWS_EDITION_LABELS:
                $modulesCode[$this->_codename] = '';
                //if user has rights on module
                if ($treatmentParameters["user"]->hasModuleClearance($this->_codename, CLEARANCE_MODULE_EDIT)) {
                    if (!isset($treatmentParameters['request'])) {
                        //add form to choose object to display
                        $modulesCode[$this->_codename] = '
							<h1>' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_ROW_TAGS_CHOOSE, false, MOD_POLYMOD_CODENAME) . '<select onchange="Ext.get(\'help' . $this->_codename . '\').getUpdater().update({url: \'' . PATH_ADMIN_WR . '/help-detail.php\',params: {module: \'' . $this->_codename . '\',object: this.value, mode:' . MODULE_TREATMENT_ROWS_EDITION_LABELS . '}});">
								<option value="">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_CHOOSE) . '</option>
								<optgroup label="' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_ROW_TAGS_EXPLANATION, false, MOD_POLYMOD_CODENAME) . '">
									<option value="block">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_TAGS, false, MOD_POLYMOD_CODENAME) . '</option>
									<option value="search">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_SEARCH_TAGS, false, MOD_POLYMOD_CODENAME) . '</option>
									<option value="working">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_WORKING_TAGS) . '</option>
									<option value="working-polymod">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_WORKING_POLYMOD_TAGS, false, MOD_POLYMOD_CODENAME) . '</option>
									<option value="vars">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_GENERAL_VARS) . '</option>
									<option value="forms">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_FORMS, false, MOD_POLYMOD_CODENAME) . '</option>
								</optgroup>
								<optgroup label="' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_ROW_OBJECTS_VARS_EXPLANATION, false, MOD_POLYMOD_CODENAME) . '">';
                        $modulesCode[$this->_codename] .= CMS_poly_module_structure::viewObjectInfosList($this->_codename, $treatmentParameters["language"], @$treatmentParameters['request'][$this->_codename . 'object']);
                        $modulesCode[$this->_codename] .= '
								</optgroup>';
                        $modulesCode[$this->_codename] .= '
							</select></h1>
							<div id="help' . $this->_codename . '"></div>
						';
                    }
                    //then display chosen object infos
                    if (isset($treatmentParameters['request'][$this->_codename]) && isset($treatmentParameters['request'][$this->_codename . 'object'])) {
                        switch ($treatmentParameters['request'][$this->_codename . 'object']) {
                            case 'block':
                                $moduleLanguages = CMS_languagesCatalog::getAllLanguages($this->_codename);
                                foreach ($moduleLanguages as $moduleLanguage) {
                                    $moduleLanguagesCodes[] = $moduleLanguage->getCode();
                                }
                                $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_TAGS_EXPLANATION, array($this->_codename, implode(', ', $moduleLanguagesCodes)), MOD_POLYMOD_CODENAME);
                                break;
                            case 'search':
                                $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_SEARCH_TAGS_EXPLANATION, false, MOD_POLYMOD_CODENAME);
                                break;
                            case 'working':
                                $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_WORKING_TAGS_EXPLANATION);
                                break;
                            case 'working-polymod':
                                $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_WORKING_POLYMOD_TAGS_EXPLANATION, array(implode(', ', CMS_modulesCatalog::getAllCodenames())), MOD_POLYMOD_CODENAME);
                                break;
                            case 'vars':
                                $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_GENERAL_VARS_EXPLANATION, array($treatmentParameters["language"]->getDateFormatMask(), $treatmentParameters["language"]->getDateFormatMask(), $treatmentParameters["language"]->getDateFormatMask()));
                                break;
                            case 'forms':
                                $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_FORMS_EXPLANATION, false, MOD_POLYMOD_CODENAME);
                                break;
                            default:
                                //object info
                                $modulesCode[$this->_codename] .= CMS_poly_module_structure::viewObjectRowInfos($this->_codename, $treatmentParameters["language"], $treatmentParameters['request'][$this->_codename . 'object']);
                                break;
                        }
                    }
                }
                return $modulesCode;
                break;
            case MODULE_TREATMENT_EDITOR_CODE:
                if ($treatmentParameters["editor"] == "fckeditor" && $treatmentParameters["user"]->hasModuleClearance($this->_codename, CLEARANCE_MODULE_EDIT)) {
                    if (!isset($modulesCode["Default"]['polymod'])) {
                        $pluginDefinitions = CMS_poly_object_catalog::getAllPluginDefinitionsForObject();
                        if (is_array($pluginDefinitions) && $pluginDefinitions) {
                            $languages = implode(',', array_keys(CMS_languagesCatalog::getAllLanguages()));
                            //This is an exception of the method, because here we return an array, see admin/fckeditor/fckconfig.php for the detail
                            $modulesCode["Default"]['polymod'] = "'polymod'";
                            $modulesCode["modulesDeclaration"]['polymod'] = "FCKConfig.Plugins.Add( 'polymod', '" . $languages . "' );";
                        }
                    }
                    $plugins = array();
                    //get all objects for module
                    $moduleObjects = CMS_poly_object_catalog::getObjectsForModule($this->_codename);
                    foreach ($moduleObjects as $object) {
                        $fields = CMS_poly_object_catalog::getFieldsDefinition($object->getID());
                        foreach ($fields as $field) {
                            $fieldObject = $field->getTypeObject(true);
                            if (method_exists($fieldObject, 'getUsedPlugins')) {
                                $plugins = array_merge($plugins, $fieldObject->getUsedPlugins());
                            }
                        }
                    }
                    $plugins = array_unique($plugins);
                    // create specific polymod toolbar
                    $modulesCode["ToolbarSets"][] = "FCKConfig.ToolbarSets[\"" . $this->_codename . "\"] = [\n\t\t\t\t\t\t\t\t['Source','Undo','Redo'],\n\t\t\t\t\t\t\t\t['Cut','Copy','Paste','PasteText','PasteWord'],\n\t\t\t\t\t\t\t\t['OrderedList','UnorderedList','-','Outdent','Indent'],\n\t\t\t\t\t\t\t\t['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],\n\t\t\t\t\t\t\t\t['Link','Unlink','Anchor'" . ($plugins ? ',' . implode(",", $plugins) : '') . "],\n\t\t\t\t\t\t\t\t['Table','Rule','SpecialChar']\n\t\t\t\t\t\t\t];";
                }
                return $modulesCode;
                break;
            case MODULE_TREATMENT_EDITOR_PLUGINS:
                if ($treatmentParameters["editor"] == "fckeditor" && $treatmentParameters["user"]->hasModuleClearance($this->_codename, CLEARANCE_MODULE_EDIT)) {
                    if (!isset($modulesCode['polymod'])) {
                        $modulesCode['polymod'] = '';
                        $pluginDefinitions = CMS_poly_object_catalog::getAllPluginDefinitionsForObject();
                        if (is_array($pluginDefinitions) && $pluginDefinitions) {
                            foreach ($pluginDefinitions as $pluginDefinition) {
                                $modulesCode['polymod'] .= $modulesCode['polymod'] ? ', ' : '';
                                $modulesCode['polymod'] .= $pluginDefinition->getLabel($treatmentParameters["user"]->getLanguage());
                            }
                        }
                    }
                }
                break;
            case MODULE_TREATMENT_AFTER_VALIDATION_TREATMENT:
                //if object is a polyobject and module is the current object's module
                if ($treatedObject instanceof CMS_poly_object && $this->_codename == CMS_poly_object_catalog::getModuleCodenameForObject($treatedObject->getID())) {
                    //send notification of the validation result to polyobject
                    $treatedObject->afterValidation($treatmentParameters['result']);
                }
                break;
            case MODULE_TREATMENT_ALERTS:
                //only if user has validation clearances
                if ($treatmentParameters['user']->hasValidationClearance($this->_codename)) {
                    $modulesCode[$this->_codename] = array(ALERT_LEVEL_VALIDATION => array('label' => self::MESSAGE_ALERT_LEVEL_VALIDATION, 'description' => self::MESSAGE_ALERT_LEVEL_VALIDATION_DESCRIPTION));
                }
                return $modulesCode;
                break;
        }
        return $modulesCode;
    }
Example #2
0
         }
     }
     if (!$cms_message) {
         //save the data
         if (!$item->writeToPersistence(true, $action == 'save')) {
             $cms_message .= $cms_language->getMessage(MESSAGE_ERROR_WRITETOPERSISTENCE);
         }
         if (!$cms_message) {
             $content = array('success' => true, 'id' => $item->getID());
             $cms_message = $cms_language->getMessage(MESSAGE_ACTION_OPERATION_DONE);
             if ($action == 'save') {
                 break;
             }
             //validate saving
             if ($object->isPrimaryResource()) {
                 $codename = CMS_poly_object_catalog::getModuleCodenameForObject($item->getID());
                 if ($cms_user->hasValidationClearance($codename)) {
                     //then validate this item content
                     $validation = new CMS_resourceValidation($codename, RESOURCE_EDITION_CONTENT, $item);
                     $mod = CMS_modulesCatalog::getByCodename($codename);
                     $mod->processValidation($validation, VALIDATION_OPTION_ACCEPT);
                     //Log action
                     $log = new CMS_log();
                     $log->logResourceAction(CMS_log::LOG_ACTION_RESOURCE_DIRECT_VALIDATION, $cms_user, $codename, $item->getStatus(), 'Item \'' . $item->getLabel() . '\' (' . $item->getObjectDefinition()->getLabel($cms_language) . ')', $item);
                 }
             }
         }
     }
     break;
 case 'pluginSelection':
     $view->setDisplayMode(CMS_view::SHOW_RAW);
 /**
  * Return a list of all primary items which uses a secondary item
  *
  * @param integer $secondaryItemId : the secondary item used
  * @param boolean $returnObject : does the method return array of object ? (default : true)
  * @param boolean $public are the needed datas public ? (default false)
  * @return array(CMS_poly_object)
  * @access public
  */
 static function getPrimaryItemsWhichUsesSecondaryItem($secondaryItemId, $returnObject = true, $public = false)
 {
     //get secondary item module
     $codename = CMS_poly_object_catalog::getModuleCodenameForObject($secondaryItemId);
     if (!$codename) {
         CMS_grandFather::raiseError("No module codename found for secondary resource item : " . $secondaryItemId);
         return false;
     }
     $primaryResourceType = CMS_poly_object_catalog::getPrimaryResourceObjectType($codename);
     if (!$primaryResourceType) {
         // no primary resource found for module so return nothing
         return array();
     }
     //get secondary item type
     $secondaryItemType = CMS_poly_object_catalog::getObjectDefinitionByID($secondaryItemId, false);
     //get all primary items which use secondary item
     $statusSuffix = $public ? "_public" : "_edited";
     $sql = "\n\t\t\tselect\n\t\t\t\tobjectID\n\t\t\tfrom\n\t\t\t\tmod_object_field,\n\t\t\t\tmod_subobject_integer" . $statusSuffix . "\n\t\t\twhere\n\t\t\t\tobject_id_mof='" . sensitiveIO::sanitizeSQLString($primaryResourceType) . "'\n\t\t\t\tand (type_mof = '" . sensitiveIO::sanitizeSQLString($secondaryItemType) . "' \n\t\t\t\t\tor type_mof = 'multi|" . sensitiveIO::sanitizeSQLString($secondaryItemType) . "')\n\t\t\t\tand objectFieldID=id_mof\n\t\t\t\tand value='" . sensitiveIO::sanitizeSQLString($secondaryItemId) . "'\n\t\t";
     $q = new CMS_query($sql);
     $results = array();
     if (!$q->getNumRows()) {
         return array();
     }
     while ($r = $q->getArray()) {
         $results[$r['objectID']] = $r['objectID'];
     }
     if (!$returnObject) {
         return $results;
     }
     return CMS_poly_object_catalog::getAllObjects($primaryResourceType, $public, array('items' => $results), true);
 }