public static function getObjectName()
 {
     $page = CMS_tree::getPageByID(CURRENT_PAGE);
     $oembedDefinition = CMS_polymod_oembed_definition_catalog::getByCodename($page->getCodename());
     $parameterName = $oembedDefinition->getParameter();
     if (io::get($parameterName) && ($embededObject = CMS_poly_object_catalog::getObjectByID(io::get($parameterName), false, true))) {
         return $embededObject->getLabel();
     }
     return '';
 }
Example #2
0
 /**
  * get an object value
  *
  * @param string $name : the name of the value to get
  * @param string $parameters (optional) : parameters for the value to get
  * @return multidimentionnal array : the object values structure
  * @access public
  */
 function getValue($name, $parameters = '')
 {
     $href = new CMS_href($this->_subfieldValues[0]->getValue());
     switch ($name) {
         case 'validhref':
             return $href->hasValidHREF();
             break;
         case 'hrefvalue':
             //get module codename
             $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
             //set location
             $location = $this->_public ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED;
             return $href->getHTML(false, $moduleCodename, $location, false, true);
             break;
         case 'hreflabel':
             return io::htmlspecialchars($href->getLabel());
             break;
         case 'hreftarget':
             return $href->getTarget();
             break;
         case 'hreftype':
             return $href->getLinkType();
             break;
         case 'popupWidth':
             $popup = $href->getPopup();
             return $popup['width'];
             break;
         case 'popupHeight':
             $popup = $href->getPopup();
             return $popup['height'];
             break;
         case 'hrefHTML':
             //get module codename
             $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
             //set location
             $location = $this->_public ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED;
             //add link title (if any)
             if ($parameters) {
                 $title = $parameters;
                 //add title attribute to link
                 $href->setAttributes(array('title' => io::htmlspecialchars($href->getLabel() . ' (' . $title . ')')));
             } else {
                 $title = false;
                 //add title attribute to link
                 $href->setAttributes(array('title' => io::htmlspecialchars($href->getLabel())));
             }
             return $href->getHTML($title, $moduleCodename, $location);
             break;
         default:
             return parent::getValue($name, $parameters);
             break;
     }
 }
Example #3
0
                    $selected = $field->getValue("type") == $anObjectType->getID() ? ' selected="selected"' : '';
                    $content .= '<option value="' . $anObjectType->getID() . '"' . $selected . ' title="' . htmlspecialchars($anObjectType->getDescription($cms_language)) . '">' . $anObjectType->getObjectLabel($cms_language) . ' (' . $objectModule->getLabel($cms_language) . ')</option>';
                }
            }
        }
        $content .= '</optgroup>';
    }
    if (sizeof($poly_types) > 1) {
        $content .= '<optgroup label="' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_MULTI) . ' ' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_POLY_OBJECTS) . '">';
        //multi poly objects
        foreach ($poly_types as $anObjectType) {
            //a poly object can't use itself or can't use an object who already use itself (infinite loop)
            if ($object->getID() != $anObjectType->getID() && !in_array($anObjectType->getID(), $objectUseage)) {
                //load fields objects for object
                $objectFields = CMS_poly_object_catalog::getFieldsDefinition($anObjectType->getID());
                $objectModule = CMS_modulesCatalog::getByCodename(CMS_poly_object_catalog::getModuleCodenameForObjectType($anObjectType->getID()));
                //a poly object can't be empty
                if (sizeof($objectFields)) {
                    $selected = $field->getValue("type") == 'multi|' . $anObjectType->getID() ? ' selected="selected"' : '';
                    $content .= '<option value="multi|' . $anObjectType->getID() . '"' . $selected . ' title="' . htmlspecialchars($anObjectType->getDescription($cms_language)) . '">' . $anObjectType->getObjectLabel($cms_language) . ' (' . $objectModule->getLabel($cms_language) . ')</option>';
                }
            }
        }
        $content .= '</optgroup>';
    }
    $content .= '
			</select>';
} else {
    $content .= '
			<strong>' . $typeObject->getObjectLabel($cms_language) . '</strong>
			<input type="hidden" name="type" value="' . $field->getValue("type") . '" />';
 /**
  * Replace vars like {object:field:type} or {var|session|request|page:name:type}. Called during definition compilation
  *
  * @param string $text : the text which need to be replaced
  * @param boolean reverse : reverse single and double quotes useage (default is false : double quotes)
  * @param array $optionalReplacement : optionnal replacement to do
  * @param boolean $cleanNotMatches : remove vars without matches
  * @param mixed $matchCallback : function name or array(object classname, object method) which represent a valid callback function to execute on matches
  * @return text : the text replaced
  * @access public
  */
 function preReplaceVars($text, $reverse = false, $cleanNotMatches = false, $matchCallback = array('CMS_polymod_definition_parsing', 'encloseString'), $returnMatchedVarsArray = false)
 {
     static $replacements;
     //if no text => return
     if (!$text || !trim($text)) {
         return $text;
     }
     //substitute simple replacement values
     $preReplaceCount = 0;
     $text = preg_replace("#{([a-zA-Z]+)}#", '@@@\\1@@@', $text, -1, $preReplaceCount);
     $count = 1;
     //loop on text for vars to replace if any
     while (preg_match_all("#{[^{}\n]+}#", $text, $matches) && $count) {
         $matches = array_unique($matches[0]);
         //get all tags handled by modules
         if (!$replacements) {
             //create replacement array
             $replacements = array();
             $modules = CMS_modulesCatalog::getAll("id");
             foreach ($modules as $codename => $aModule) {
                 $moduleReplacements = $aModule->getModuleReplacements();
                 if (is_array($moduleReplacements) && $moduleReplacements) {
                     foreach ($moduleReplacements as $pattern => $replacement) {
                         $replacements[$pattern] = $replacement;
                     }
                 }
             }
         }
         $replace = $replacements;
         //pr($matches);
         if ($reverse) {
             $reversedReplace = array();
             foreach ($replace as $key => $value) {
                 $reversedReplace[str_replace("'", "\\\\'", $key)] = $value;
             }
             $replace = $reversedReplace;
         }
         $count = 0;
         $matchesValues = preg_replace(array_keys($replace), $replace, $matches, -1, $count);
         //create vars conversion table
         $replace = array();
         if ($matchesValues) {
             if (isset($this->_parameters['module'])) {
                 $externalReferences = CMS_poly_object_catalog::getFieldsReferencesUsage($this->_parameters['module']);
             } else {
                 $externalReferences = CMS_poly_object_catalog::getFieldsReferencesUsage();
             }
             foreach ($matches as $key => $match) {
                 //record external references for cache reference
                 if ($externalReferences) {
                     foreach ($externalReferences as $id => $type) {
                         if (strpos($match, '[\'fields\'][' . $id . ']') !== false || strpos($match, '[\\\'fields\\\'][' . $id . ']') !== false) {
                             //CMS_grandFather::log(print_r($this->_elements, true));
                             $this->_elements = array_merge_recursive($type, (array) $this->_elements);
                             //CMS_grandFather::log(print_r($this->_elements, true));
                         }
                     }
                 }
                 //record used pages for cache reference
                 if (strpos($match, '{page:') !== false) {
                     $this->_elements['module'][] = MOD_STANDARD_CODENAME;
                 }
                 //record used users for cache reference
                 if (strpos($match, '{user:'******'resource'][] = 'users';
                 }
                 if ($match != $matchesValues[$key]) {
                     $matchValue = $matchesValues[$key];
                 } else {
                     $matchValue = null;
                 }
                 //apply callback if any to value
                 if (isset($matchValue)) {
                     if ($matchCallback !== false) {
                         if (is_callable($matchCallback)) {
                             $replace[$match] = call_user_func($matchCallback, $matchValue, $reverse);
                         } else {
                             CMS_grandFather::raiseError("Unknown callback function : " . $matchCallback);
                             return false;
                         }
                     } else {
                         $replace[$match] = $matchValue;
                     }
                 } elseif ($cleanNotMatches) {
                     $replace[$match] = '';
                 }
             }
         }
         //return matched vars if needed
         if ($returnMatchedVarsArray) {
             //substitute simple replacement values
             if ($preReplaceCount) {
                 $replace = preg_replace("#\\@\\@\\@([a-zA-Z]+)\\@\\@\\@#", '{\\1}', $replace);
             }
             return $replace;
         } else {
             //then replace variables in text and return it
             $text = str_replace(array_keys($replace), $replace, $text);
         }
     }
     //substitute simple replacement values
     if ($preReplaceCount) {
         $text = preg_replace("#\\@\\@\\@([a-zA-Z]+)\\@\\@\\@#", '{\\1}', $text);
     }
     return $text;
 }
Example #5
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);
Example #6
0
if ($id) {
    $ids = explode('-', $id);
    $selectedPluginID = (int) $ids[1];
    $selectedItem = (int) $ids[2];
} else {
    $selectedPluginID = $selectedItem = 0;
}
//Select WYSIWYG Plugin
$pluginDefinitions = CMS_poly_object_catalog::getAllPluginDefinitionsForObject();
//check for user rights
$availablePlugin = array();
$availablePluginCount = 0;
if (sizeof($pluginDefinitions)) {
    foreach ($pluginDefinitions as $id => $pluginDefinition) {
        $objectID = $pluginDefinition->getValue('objectID');
        $polyModuleCodename = CMS_poly_object_catalog::getModuleCodenameForObjectType($objectID);
        if ($cms_user->hasModuleClearance($polyModuleCodename, CLEARANCE_MODULE_EDIT)) {
            $availablePlugin[$polyModuleCodename][$id] = $pluginDefinition;
            $availablePluginCount++;
        }
    }
}
//if no plugin available, display error and quit
if (!sizeof($availablePlugin)) {
    //messages
    $cms_message = $cms_language->getMessage(MESSAGE_PAGE_ERROR_NO_PLUGIN, false, MOD_POLYMOD_CODENAME);
    $view->setActionMessage($cms_message);
    $view->show();
}
$items = '';
$activeTab = 0;
Example #7
0
    /**
     * get HTML admin subfields parameters (used to enter object parameters values in admin)
     *
     * @return string : the html admin
     * @access public
     */
    function getHTMLSubFieldsParameters($language, $prefixName)
    {
        if (!is_a($language, 'CMS_language')) {
            $this->raiseError("Language must be a CMS_language object : " . print_r($language, true));
            return false;
        }
        $values = $this->_parameterValues;
        $html = '';
        $parameters = $this->getSubFieldParameters();
        foreach ($parameters as $parameterID => $parameter) {
            $paramValue = $values[$parameterID];
            switch ($parameter['type']) {
                case 'boolean':
                    $yes = $paramValue ? ' selected="selected"' : '';
                    $input = '<select name="' . $prefixName . $parameter['internalName'] . '" class="admin_input_text">
						<option value="0">' . $language->getMessage(self::MESSAGE_FIELD_NO) . '</option>
						<option value="1"' . $yes . '>' . $language->getMessage(self::MESSAGE_FIELD_YES) . '</option>
					</select>';
                    break;
                case 'integer':
                case 'date':
                case 'string':
                    $input = '<input type="text" size="30" name="' . $prefixName . $parameter['internalName'] . '" class="admin_input_text" value="' . io::htmlspecialchars($paramValue) . '" />';
                    break;
                case 'text':
                    $input = '<textarea cols="70" rows="4" name="' . $prefixName . $parameter['internalName'] . '" class="admin_input_text">' . io::htmlspecialchars($paramValue) . '</textarea>';
                    break;
                case 'fields':
                    //get all fields for current object
                    $fields = CMS_poly_object_catalog::getFieldsDefinition($this->_field->getValue('objectID'));
                    $selectValues = array();
                    foreach ($fields as $field) {
                        $label = new CMS_object_i18nm($field->getValue("labelID"));
                        $selectValues[$field->getID()] = $label->getValue($language->getCode());
                    }
                    $selectedValues = explode(';', $paramValue);
                    $listboxesParameters = array('field_name' => $prefixName . $parameter['internalName'], 'items_possible' => $selectValues, 'items_selected' => $selectedValues, 'select_width' => '300px', 'select_height' => '200px', 'form_name' => 'frm');
                    $input = CMS_dialog_listboxes::getListBoxes($listboxesParameters);
                    break;
                default:
                    if ($parameter['type'] && method_exists($this, "getHTMLSubFieldsParameters" . $parameter['type'])) {
                        $method = "getHTMLSubFieldsParameters" . $parameter['type'];
                        $input = $this->{$method}($language, $prefixName, $parameter);
                    } else {
                        $this->raiseError("Can't get parameter HTML for type : " . $parameter['type']);
                        return false;
                    }
                    break;
            }
            if ($input) {
                $paramLabel = sensitiveIO::isPositiveInteger($parameter['externalName']) ? $language->getMessage($parameter['externalName'], false, $this->_messagesModule) : 'Undefined';
                $paramDescription = isset($parameter['description']) && sensitiveIO::isPositiveInteger($parameter['description']) ? '<br /><small>' . $language->getMessage($parameter['description'], false, $this->_messagesModule) . '</small>' : '';
                $required = $parameter['required'] ? '<span class="admin_text_alert">*</span>' : '';
                $html .= '
				<tr>
					<td class="admin" align="right" valign="top">' . $required . $paramLabel . '</td>
					<td class="admin" valign="top">' . $input . $paramDescription . '</td>
				</tr>';
            }
        }
        $html = $html ? '<table border="0" cellpadding="3" cellspacing="0" style="border-left:1px solid #4d4d4d;">' . $html . '</table>' : '';
        return $html;
    }
Example #8
0
                }
            }
        } elseif (CMS_modulesCatalog::isPolymod($codename)) {
            //get object item id
            $itemID = '';
            if (preg_match('#^r[0-9]+_[0-9]+_.*#', $pathinfo['basename'])) {
                $itemID = preg_replace('#^r([0-9]+)_[0-9]+_.*#', '\\1', $pathinfo['basename']);
            }
            if (sensitiveIO::isPositiveInteger($itemID)) {
                if (!is_object($cms_user)) {
                    //no user => LOGIN
                    header('Location: ' . PATH_FRONTEND_SPECIAL_LOGIN_WR . '?referer=' . base64_encode($_SERVER['REQUEST_URI']));
                    exit;
                } else {
                    $public = preg_match('#.*/(edited|edition)$#', $pathinfo['dirname']) ? false : true;
                    $item = CMS_poly_object_catalog::getObjectByID($itemID, false, $public);
                    if (!$item || !is_object($item) || !$item->userHasClearance($cms_user, CLEARANCE_MODULE_VIEW, true)) {
                        if ($cms_user->getLogin() == DEFAULT_USER_LOGIN) {
                            //no rights and anonymous => LOGIN
                            header('Location: ' . PATH_FRONTEND_SPECIAL_LOGIN_WR . '?referer=' . base64_encode($_SERVER['REQUEST_URI']));
                        } else {
                            //no rights and logged => 403
                            header('Location: ' . PATH_FORBIDDEN_WR . '?referer=' . base64_encode($_SERVER['REQUEST_URI']));
                        }
                        exit;
                    }
                }
            }
        }
    }
}
 /**
  * Import module objects 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 categories (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 objects importation ...' . "\n";
         return false;
     }
     $module = CMS_modulesCatalog::getByCodename($params['module']);
     if ($module->hasError()) {
         $infos .= 'Error : invalid module for objects importation : ' . $params['module'] . "\n";
         return false;
     }
     $return = true;
     //first create missing objects to get relation ids
     foreach ($data as $objectDatas) {
         if (!isset($objectDatas['uuid']) || !CMS_poly_object_catalog::objectExists($params['module'], $objectDatas['uuid'])) {
             //create new object if we can
             if (!isset($params['create']) || $params['create'] == true) {
                 //create object
                 $object = new CMS_poly_object_definition();
                 //set module
                 $object->setValue('module', $params['module']);
                 //set uuid
                 $object->setUuid($objectDatas['uuid']);
                 //write object to persistence to get relations ids
                 $object->writeToPersistence();
                 //set id translation
                 if (isset($objectDatas['id']) && $objectDatas['id']) {
                     // && $object->getID() != $objectDatas['id']) {
                     // Fix for bug #3157 : in some cases the imported object will have the same id has the newly created,
                     // we still need the relation table otherwise it will fail to link to the new object
                     $idsRelation['objects'][$objectDatas['id']] = $object->getID();
                 }
                 //set uuid translation
                 if (isset($objectDatas['uuid']) && $objectDatas['uuid'] && $object->getValue('uuid') != $objectDatas['uuid']) {
                     $idsRelation['objects-uuid'][$objectDatas['uuid']] = $object->getValue('uuid');
                 }
             }
         } elseif (isset($objectDatas['uuid']) && isset($objectDatas['id'])) {
             //get relation between imported object id and local id
             $id = CMS_poly_object_catalog::objectExists($params['module'], $objectDatas['uuid']);
             if (io::isPositiveInteger($id)) {
                 $idsRelation['objects'][$objectDatas['id']] = $id;
             }
         }
     }
     //then import objects datas
     foreach ($data as $objectDatas) {
         $importType = '';
         if (isset($objectDatas['uuid']) && ($id = CMS_poly_object_catalog::objectExists($params['module'], $objectDatas['uuid']))) {
             //object already exist : load it if we can update it
             if (!isset($params['update']) || $params['update'] == true) {
                 $object = CMS_poly_object_catalog::getObjectDefinition($id);
                 $importType = ' (Update)';
                 //set id translation
                 $idsRelation['objects'][$objectDatas['id']] = $id;
             }
         } else {
             //check for translated id
             if (isset($objectDatas['id']) && isset($idsRelation['objects'][$objectDatas['id']])) {
                 //object exists with a translated id
                 $objectDatas['id'] = $idsRelation['objects'][$objectDatas['id']];
                 //load translated object
                 $object = CMS_poly_object_catalog::getObjectDefinition($objectDatas['id']);
                 $importType = ' (Creation)';
             }
             //check for translated uuid
             if (isset($objectDatas['uuid']) && isset($idsRelation['objects-uuid'][$objectDatas['uuid']])) {
                 //object exists with a translated uuid
                 $objectDatas['uuid'] = $idsRelation['objects-uuid'][$objectDatas['uuid']];
                 //load translated object
                 if ($id = CMS_poly_object_catalog::objectExists($params['module'], $objectDatas['uuid'])) {
                     $object = CMS_poly_object_catalog::getObjectDefinition($id);
                     $importType = ' (Creation)';
                 }
             }
         }
         if (isset($object)) {
             if ($object->fromArray($objectDatas, $params, $cms_language, $idsRelation, $infos)) {
                 $return &= true;
                 $infos .= 'Object "' . $object->getLabel($cms_language) . '" successfully imported' . $importType . "\n";
             } else {
                 $return = false;
                 $infos .= 'Error during import of object ' . $objectDatas['id'] . $importType . "\n";
             }
         }
     }
     return $return;
 }
 /**
  * Import object from given array datas
  *
  * @param array $data The object datas to import
  * @param array $params The import parameters.
  *		array(
  *				module	=> false|true : the module to create object (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
  */
 function fromArray($data, $params, $cms_language, &$idsRelation, &$infos)
 {
     if (!isset($params['module'])) {
         $infos .= 'Error : missing module codename for object importation ...' . "\n";
         return false;
     }
     $module = CMS_modulesCatalog::getByCodename($params['module']);
     if ($module->hasError()) {
         $infos .= 'Error : invalid module for object importation : ' . $params['module'] . "\n";
         return false;
     }
     if (!$this->getID() && CMS_poly_object_catalog::objectUuidExists($data['uuid'])) {
         //check imported uuid. If objects does not have an Id, the uuid must be unique or must be regenerated
         $uuid = io::uuid();
         //store old uuid relation
         $idsRelation['objects-uuid'][$data['uuid']] = $uuid;
         $data['uuid'] = $uuid;
     }
     //set object uuid if not exists
     if (!$this->_objectValues["uuid"]) {
         $this->_objectValues["uuid"] = $data['uuid'];
     }
     if (isset($data['labels'])) {
         $label = new CMS_object_i18nm($this->getValue("labelID"));
         $label->setValues($data['labels']);
         $label->writeToPersistence();
         $this->setValue("labelID", $label->getID());
     }
     if (isset($data['descriptions'])) {
         $description = new CMS_object_i18nm($this->getValue("descriptionID"));
         $description->setValues($data['descriptions']);
         $description->writeToPersistence();
         $this->setValue("descriptionID", $description->getID());
     }
     if (isset($data['params']['resourceUsage'])) {
         $this->setValue("resourceUsage", $data['params']['resourceUsage']);
     }
     if (isset($data['params']['admineditable'])) {
         $this->setValue("admineditable", $data['params']['admineditable']);
     }
     if (isset($data['params']['indexable'])) {
         $this->setValue("indexable", $data['params']['indexable']);
     }
     if (isset($data['params']['multilanguage'])) {
         $this->setValue("multilanguage", $data['params']['multilanguage']);
     }
     if (isset($data['params']['composedLabel'])) {
         $this->setValue("composedLabel", $module->convertDefinitionString($data['params']['composedLabel'], false));
     }
     if (isset($data['params']['previewURL'])) {
         $this->setValue("previewURL", $module->convertDefinitionString($data['params']['previewURL'], false));
     }
     if (isset($data['params']['indexURL'])) {
         $this->setValue("indexURL", $module->convertDefinitionString($data['params']['indexURL'], false));
     }
     if (isset($data['params']['resultsDefinition'])) {
         $this->setValue("resultsDefinition", $module->convertDefinitionString($data['params']['resultsDefinition'], false));
     }
     //write object
     if (!$this->writeToPersistence()) {
         $infos .= 'Error : can not write object ...' . "\n";
         return false;
     }
     //if current object id has changed from imported id, set relation
     if (isset($data['id']) && $data['id'] && $this->getID() != $data['id']) {
         $idsRelation['objects'][$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;
     //object fields
     if (isset($data['fields'])) {
         foreach ($data['fields'] as $fieldDatas) {
             $importType = '';
             if (isset($fieldDatas['type'])) {
                 if (isset($fieldDatas['uuid']) && ($id = CMS_poly_object_catalog::fieldExists($params['module'], $fieldDatas['uuid']))) {
                     //field already exist : load it if we can update it
                     if (!isset($params['update']) || $params['update'] == true) {
                         $field = new CMS_poly_object_field($id);
                         $importType = ' (Update)';
                     }
                 } else {
                     //create new field if we can
                     if (!isset($params['create']) || $params['create'] == true) {
                         $field = new CMS_poly_object_field();
                         $importType = ' (Creation)';
                     }
                 }
                 if (isset($field)) {
                     if ($field->fromArray($fieldDatas, $params, $cms_language, $idsRelation, $infos)) {
                         $return &= true;
                         $infos .= 'Field "' . $field->getLabel($cms_language) . '" successfully imported' . $importType . "\n";
                     } else {
                         $return = false;
                         $infos .= 'Error during import of field ...' . $importType . "\n";
                     }
                 }
             } else {
                 $return = false;
                 $infos .= 'Error during import of field : missing type' . "\n";
             }
         }
     }
     //object rss feeds
     if (isset($data['rss'])) {
         foreach ($data['rss'] as $rssDatas) {
             $importType = '';
             if (isset($rssDatas['uuid']) && ($id = CMS_poly_object_catalog::rssExists($params['module'], $rssDatas['uuid']))) {
                 //rss already exist : load it if we can update it
                 if (!isset($params['update']) || $params['update'] == true) {
                     $rss = new CMS_poly_rss_definitions($id);
                     $importType = ' (Update)';
                 }
             } else {
                 //create new rss if we can
                 if (!isset($params['create']) || $params['create'] == true) {
                     $rss = new CMS_poly_rss_definitions();
                     $importType = ' (Creation)';
                 }
             }
             if (isset($rss)) {
                 if ($rss->fromArray($rssDatas, $params, $cms_language, $idsRelation, $infos)) {
                     $return &= true;
                     $infos .= 'RSS feed "' . $rss->getLabel($cms_language) . '" successfully imported' . $importType . "\n";
                 } else {
                     $return = false;
                     $infos .= 'Error during import of rss feed ...' . $importType . "\n";
                 }
             }
         }
     }
     //plugins wysiwyg
     if (isset($data['plugins'])) {
         foreach ($data['plugins'] as $pluginDatas) {
             $importType = '';
             if (isset($pluginDatas['uuid']) && ($id = CMS_poly_object_catalog::pluginExists($params['module'], $pluginDatas['uuid']))) {
                 //plugin already exist : load it if we can update it
                 if (!isset($params['update']) || $params['update'] == true) {
                     $plugin = new CMS_poly_plugin_definitions($id);
                     $importType = ' (Update)';
                 }
             } else {
                 //create new plugin if we can
                 if (!isset($params['create']) || $params['create'] == true) {
                     $plugin = new CMS_poly_plugin_definitions();
                     $importType = ' (Creation)';
                 }
             }
             if (isset($plugin)) {
                 if ($plugin->fromArray($pluginDatas, $params, $cms_language, $idsRelation, $infos)) {
                     $return &= true;
                     $infos .= 'Plugin Wysiwyg "' . $plugin->getLabel($cms_language) . '" successfully imported' . $importType . "\n";
                 } else {
                     $return = false;
                     $infos .= 'Error during import of plugin wysiwyg ...' . $importType . "\n";
                 }
             }
         }
     }
     return $return;
 }
Example #11
0
$transformedDefinition = $polymodModule->convertDefinitionString($htmlDefinition, false);
$parameters = array();
$parameters['module'] = CMS_poly_object_catalog::getModuleCodenameForObjectType($oembedDefinition->getObjectdefinition());
$parameters['objectID'] = $oembedDefinition->getObjectdefinition();
$parameters['public'] = true;
$parameters['cache'] = false;
$parameters['pageID'] = CURRENT_PAGE;
$definitionParsing = new CMS_polymod_definition_parsing($transformedDefinition, true, CMS_polymod_definition_parsing::BLOCK_PARAM_MODE, $parameters['module']);
$compiledDefinition = $definitionParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_PHP, $parameters);
$urlParts = parse_url($url);
if (!isset($urlParts['query'])) {
    die("Incorrect parameters");
}
parse_str($urlParts['query']);
$parameterName = $oembedDefinition->getParameter();
$embededObject = CMS_poly_object_catalog::getObjectByID(${$parameterName}, false, true);
if (!$embededObject) {
    die("Incorrect parameters");
}
// get label
ob_start();
eval(sensitiveIO::stripPHPTags($compiledDefinition));
$data = ob_get_contents();
ob_end_clean();
$html = array('html' => $data, 'title' => $embededObject->getLabel(), 'height' => io::get('height'), 'width' => io::get('width'));
$oembed = CMS_polymod_oembed_definition::getResults($html);
if ($format === 'json') {
    print json_encode($oembed, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
} elseif ($format === 'xml') {
    $output = "<?xml version=\"1.0\" encoding=\"utf-8\">\n";
    $output .= "<oembed>\n";
Example #12
0
 /**
  * get an object value
  *
  * @param string $name : the name of the value to get
  * @param string $parameters (optional) : parameters for the value to get
  * @return multidimentionnal array : the object values structure
  * @access public
  */
 function getValue($name, $parameters = '')
 {
     switch ($name) {
         case 'file':
         case 'thumb':
             if ($name == 'file') {
                 $fieldIndex = 4;
                 $fielfPrefix = 'image';
             } else {
                 $fieldIndex = 1;
                 $fielfPrefix = 'thumb';
             }
             // If we have a value and there are additionnal cropping parameters
             if ($this->_subfieldValues[$fieldIndex]->getValue() && $parameters && in_array($this->getValue($name . 'Extension'), array('jpg', 'jpeg', 'png', 'gif'))) {
                 @(list($x, $y) = explode(',', str_replace(';', ',', $parameters)));
                 if (io::isPositiveInteger($x) && $x < $this->getValue($fielfPrefix . 'Width') || io::isPositiveInteger($y) && $y < $this->getValue($fielfPrefix . 'Height')) {
                     $crop = $x && $y ? 1 : 0;
                     //get module codename
                     $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
                     //set location
                     $location = $this->isPublic() ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED;
                     //resized image path
                     $pathInfo = pathinfo($this->_subfieldValues[$fieldIndex]->getValue());
                     $resizedImage = $pathInfo['filename'] . '-' . $x . '-' . $y . ($crop ? '-c' : '') . '.' . $pathInfo['extension'];
                     //resized image path
                     $resizedImagepathFS = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . $location . '/' . $resizedImage;
                     //if file already exists, no need to resize file send it
                     if (file_exists($resizedImagepathFS)) {
                         return $this->getValue('filePath') . '/' . $resizedImage;
                     } else {
                         return CMS_websitesCatalog::getCurrentDomain() . PATH_REALROOT_WR . '/image-file' . (!STRIP_PHP_EXTENSION ? '.php' : '') . '?image=' . $this->_subfieldValues[$fieldIndex]->getValue() . '&amp;module=' . $moduleCodename . '&amp;x=' . $x . '&amp;y=' . $y . '&amp;crop=' . $crop . ($location != RESOURCE_DATA_LOCATION_PUBLIC ? '&amp;location=' . $location : '');
                     }
                 }
             }
             if ($this->_subfieldValues[$fieldIndex]->getValue()) {
                 // If we have a value but no cropping params
                 return $this->getValue('filePath') . '/' . $this->_subfieldValues[$fieldIndex]->getValue();
             }
             return '';
             break;
         case 'fileHTML':
             //get module codename
             $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
             //set location
             $location = $this->_public ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED;
             $filepath = $this->_subfieldValues[3]->getValue() == self::OBJECT_FILE_TYPE_INTERNAL ? PATH_MODULES_FILES_WR . '/' . $moduleCodename . '/' . $location . '/' . $this->_subfieldValues[4]->getValue() : $this->_subfieldValues[4]->getValue();
             //append website url if missing
             if (io::substr($filepath, 0, 1) == '/') {
                 $filepath = CMS_websitesCatalog::getCurrentDomain() . $filepath;
             }
             //link content
             $linkContent = $parameters ? $parameters : $this->_subfieldValues[0]->getValue();
             $file = '<a href="' . $filepath . '" target="_blank" title="' . $this->_subfieldValues[0]->getValue() . '">' . $linkContent . '</a>';
             return $file;
             break;
         case 'fileLabel':
             return $this->_subfieldValues[0]->getValue();
             break;
         case 'filename':
             return $this->_subfieldValues[4]->getValue();
             break;
         case 'thumbnail':
         case 'thumbname':
             return $this->_subfieldValues[1]->getValue();
             break;
         case 'filePath':
             //get module codename
             $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
             //set location
             $location = $this->isPublic() ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED;
             $altDomain = $this->getAlternativeDomain();
             // If we are serving a public file and there is an alternative domain set up, change the url
             if ($this->isPublic() && $altDomain) {
                 return $altDomain . PATH_MODULES_FILES_WR . '/' . $moduleCodename . '/' . $location;
             } else {
                 return CMS_websitesCatalog::getCurrentDomain() . PATH_MODULES_FILES_WR . '/' . $moduleCodename . '/' . $location;
             }
             break;
         case 'thumbMaxWidth':
             //get field parameters
             $params = $this->getParamsValues();
             return $params['thumbMaxWidth'] ? $params['thumbMaxWidth'] : '';
             break;
         case 'thumbMaxHeight':
             //get field parameters
             $params = $this->getParamsValues();
             return $params['thumbMaxHeight'] ? $params['thumbMaxHeight'] : '';
             break;
         case 'thumbWidth':
         case 'thumbHeight':
             //get module codename
             $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
             //set location
             $location = $this->isPublic() ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED;
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . $location;
             $imgPath = $path . "/" . $this->_subfieldValues[1]->getValue();
             $sizeX = $sizeY = 0;
             if (file_exists($imgPath)) {
                 list($sizeX, $sizeY) = @getimagesize($imgPath);
             }
             if ($name == 'thumbWidth') {
                 return (string) $sizeX;
             } else {
                 return (string) $sizeY;
             }
             break;
         case 'imageWidth':
         case 'imageHeight':
             if ($this->_subfieldValues[4]->getValue() && in_array($this->getValue('fileExtension'), array('jpg', 'jpeg', 'png', 'gif'))) {
                 //get module codename
                 $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
                 //set location
                 $location = $this->isPublic() ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED;
                 $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . $location;
                 $imgPath = $path . "/" . $this->_subfieldValues[4]->getValue();
                 $sizeX = $sizeY = 0;
                 if (file_exists($imgPath)) {
                     list($sizeX, $sizeY) = @getimagesize($imgPath);
                 }
                 if ($name == 'imageWidth') {
                     return (string) $sizeX;
                 } else {
                     return (string) $sizeY;
                 }
             }
             return 0;
             break;
         case 'fileSize':
             return $this->_subfieldValues[2]->getValue();
             break;
         case 'fileIcon':
             return $this->_getFileIcon();
             break;
         case 'fileExtension':
             return $this->_getFileExtension();
             break;
         case 'thumbExtension':
             return $this->_getThumbExtension();
             break;
         case 'alternativeDomain':
             return $this->getAlternativeDomain();
         default:
             return parent::getValue($name, $parameters);
             break;
     }
 }
$object = new CMS_poly_object_definition($_POST["object"]);
$availableLanguagesCodes = CMS_object_i18nm::getAvailableLanguages();
$objectsStructure = CMS_poly_module_structure::getModuleStructure($moduleCodename, true);
if ($moduleCodename) {
    $polymod = CMS_modulesCatalog::getByCodename($moduleCodename);
}
$dialog = new CMS_dialog();
$content = '';
$dialog->setTitle($cms_language->getMessage(MESSAGE_PAGE_TITLE_APPLICATIONS) . " :: " . $polymod->getLabel($cms_language) . " :: " . $cms_language->getMessage(MESSAGE_PAGE_TITLE, array($object->getLabel($cms_language))), 'picto_modules.gif');
$dialog->setBacklink("modules_admin.php?moduleCodename=" . $moduleCodename . "&object=" . $object->getID());
if ($cms_message) {
    $dialog->setActionMessage($cms_message);
}
$resourceStatus = array(0 => MESSAGE_PAGE_FIELD_RESOURCE_NONE, 1 => MESSAGE_PAGE_FIELD_RESOURCE_PRIMARY, 2 => MESSAGE_PAGE_FIELD_RESOURCE_SECONDARY);
$adminEditableStatus = array(0 => MESSAGE_PAGE_FIELD_YES, 1 => MESSAGE_PAGE_FIELD_NO, 2 => MESSAGE_PAGE_FIELD_ONLY_FOR_ADMIN);
$objectUseage = CMS_poly_object_catalog::getObjectUsage($object->getID(), true);
if (!sizeof($objectUseage)) {
    $objectUseageLabel = $cms_language->getMessage(MESSAGE_PAGE_FIELD_NO) . '<br />';
} else {
    $objectUseageLabel = $cms_language->getMessage(MESSAGE_PAGE_FIELD_OBJECT_USED) . ' : <ul>';
    foreach ($objectUseage as $anObjectWhichUse) {
        $objectUseageLabel .= '<li>' . $anObjectWhichUse->getLabel() . '</li>';
    }
    $objectUseageLabel .= '</ul>';
}
$content = '
<strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_DESCRIPTION) . ' :</strong> ' . $object->getDescription($cms_language) . '<br />
<strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_RESOURCE) . ' :</strong> ' . $cms_language->getMessage($resourceStatus[$object->getValue("resourceUsage")]) . '<br />
<strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_EDITABLE) . ' :</strong> ' . $cms_language->getMessage($adminEditableStatus[$object->getValue("admineditable")]) . '<br />
<strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_COMPOSED_LABEL) . ' :</strong> ' . $cms_language->getMessage($adminEditableStatus[$object->getValue("composedLabel") ? 0 : 1]) . '<br />
<strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_OBJECT_USEAGE) . ' :</strong> ' . $objectUseageLabel . '
Example #14
0
 /**
  * Return a list of all objects names of given type
  *
  * @param boolean $public are the needed datas public ? /!\ Does not apply for this type of object
  * @param array $searchConditions, search conditions to add. /!\ Does not apply for this type of object
  * @return array(integer objectID => string objectName)
  * @access public
  * @static
  */
 function getListOfNamesForObject($public = false, $searchConditions = array())
 {
     //get module
     $module = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
     // Get languages
     $a_all_languages = CMS_languagesCatalog::getAllLanguages($module);
     $languages = array();
     foreach ($a_all_languages as $code => $language) {
         $languages[$code] = $language->getLabel();
     }
     return $languages;
 }
Example #15
0
    $view->setContent($objectsDatas);
    $view->show();
}
//CHECKS objectId
if (!$objectId && !$fieldId) {
    CMS_grandFather::raiseError('Missing objectId to list in module ' . $codename);
    $view->setContent($objectsDatas);
    $view->show();
} elseif (!$objectId && $fieldId) {
    $objectId = CMS_poly_object_catalog::getObjectIDForField($fieldId);
}
//load current object definition
$object = CMS_poly_object_catalog::getObjectDefinition($objectId);
if (!$object->hasError()) {
    $conditions = $query ? array('keywords' => $query) : array();
    $objectsNames = CMS_poly_object_catalog::getListOfNamesForObject($objectId, false, $conditions);
    if (is_array($objectsNames) && $objectsNames) {
        $objectsDatas['objects'][] = array('id' => '0', 'label' => ' ');
        foreach ($objectsNames as $id => $label) {
            if (!$removeIds || !in_array($id, $removeIds)) {
                $objectsDatas['objects'][] = array('id' => $id, 'label' => io::decodeEntities($label));
            }
        }
    } else {
        $objectsDatas['objects'][] = array('id' => '0', 'label' => $cms_language->getMessage(MESSAGE_PAGE_NO_ITEM, false, MOD_POLYMOD_CODENAME));
    }
} else {
    $objectsDatas['objects'][] = array('id' => '0', 'label' => $cms_language->getMessage(MESSAGE_PAGE_ITEM_NON_EXISTENT, false, MOD_POLYMOD_CODENAME));
}
$view->setContent($objectsDatas);
$view->show();
Example #16
0
 /**
  * Does this module is destroyable ?
  *
  * @return boolean
  * @access public
  */
 function isDestroyable()
 {
     global $cms_user;
     // Check module exists and is polymod
     if ($this->hasError() || !$this->isPolymod()) {
         return false;
     }
     //check if user is admin
     if (!$cms_user->hasAdminClearance(CLEARANCE_ADMINISTRATION_EDITVALIDATEALL)) {
         return false;
     }
     //check if module has objects
     if (CMS_poly_object_catalog::getObjectsForModule($this->_codename)) {
         return false;
     }
     // CHECK USED ROWS
     $usedRows = array();
     $rowsIds = CMS_rowsCatalog::getByModules(array($this->_codename), false, false);
     if ($rowsIds) {
         foreach ($rowsIds as $rowId) {
             if (CMS_rowsCatalog::getPagesByRow($rowId, false, false)) {
                 $usedRows[] = $rowId;
             }
         }
     }
     // If any used rows : alert user and break module deletion
     if ($usedRows) {
         return false;
     }
     return true;
 }
Example #17
0
 /**
  * Return a list of all objects names of given type
  *
  * @param boolean $public are the needed datas public ? (default false)
  * @param array $searchConditions, search conditions to add. Format : array(conditionType => conditionValue)
  * @return array(integer objectID => string objectName)
  * @access public
  * @static
  */
 function getListOfNamesForObject($public = false, $searchConditions = array())
 {
     return CMS_poly_object_catalog::getListOfNamesForObject(io::substr($this->_field->getValue('type'), 6), $public, $searchConditions);
 }
Example #18
0
 /**
  * get an object value
  *
  * @param string $name : the name of the value to get
  * @param string $parameters (optional) : parameters for the value to get
  * @return multidimentionnal array : the object values structure
  * @access public
  */
 function getValue($name, $parameters = '')
 {
     switch ($name) {
         case 'label':
             return $this->getLabel();
             break;
         case 'image':
         case 'imageZoom':
             if ($name == 'image') {
                 $fieldIndex = 0;
             } else {
                 $fieldIndex = 2;
             }
             if ($this->_subfieldValues[$fieldIndex]->getValue() && $parameters) {
                 @(list($x, $y) = explode(',', str_replace(';', ',', $parameters)));
                 if (io::isPositiveInteger($x) && $x < $this->getValue($name . 'Width') || io::isPositiveInteger($y) && $y < $this->getValue($name . 'Height')) {
                     //get module codename
                     $crop = $x && $y ? 1 : 0;
                     //get module codename
                     $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
                     //set location
                     $location = $this->isPublic() ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED;
                     //resized image path
                     $pathInfo = pathinfo($this->_subfieldValues[$fieldIndex]->getValue());
                     $resizedImage = $pathInfo['filename'] . '-' . $x . '-' . $y . ($crop ? '-c' : '') . '.' . $pathInfo['extension'];
                     //resized image path
                     $resizedImagepathFS = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . $location . '/' . $resizedImage;
                     //if file already exists, no need to resize file send it
                     if (file_exists($resizedImagepathFS)) {
                         return $this->getValue('imagePath') . '/' . $resizedImage;
                     } else {
                         return CMS_websitesCatalog::getCurrentDomain() . PATH_REALROOT_WR . '/image-file' . (!STRIP_PHP_EXTENSION ? '.php' : '') . '?image=' . $this->_subfieldValues[$fieldIndex]->getValue() . '&amp;module=' . $moduleCodename . '&amp;x=' . $x . '&amp;y=' . $y . '&amp;crop=' . $crop . ($location != RESOURCE_DATA_LOCATION_PUBLIC ? '&amp;location=' . $location : '');
                     }
                 }
             }
             if ($this->_subfieldValues[$fieldIndex]->getValue()) {
                 return $this->getValue('imagePath') . '/' . $this->_subfieldValues[$fieldIndex]->getValue();
             }
             return '';
             break;
         case 'imageHTML':
             //get module codename
             $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
             //set location
             $location = $this->isPublic() ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED;
             //link content
             $img = '';
             if ($parameters) {
                 $img = $parameters;
             } elseif ($this->_subfieldValues[0]->getValue()) {
                 //bug 1380
                 $img = '<img src="' . $this->getValue('image') . '" alt="' . $this->_subfieldValues[1]->getValue() . '" />';
             }
             //add link to zoom if any
             if ($img && $this->_subfieldValues[2]->getValue()) {
                 $href = CMS_websitesCatalog::getCurrentDomain() . PATH_REALROOT_WR . "/" . self::OBJECT_IMAGE_POPUP_FILE . '?' . ($location != RESOURCE_DATA_LOCATION_PUBLIC ? 'location=' . RESOURCE_DATA_LOCATION_EDITED . '&amp;' : '') . 'file=' . $this->_subfieldValues[2]->getValue() . '&amp;label=' . urlencode($this->_subfieldValues[1]->getValue()) . '&amp;module=' . $moduleCodename;
                 // file informations
                 $popup = OPEN_ZOOMIMAGE_IN_POPUP ? ' onclick="javascript:CMS_openPopUpImage(\'' . addslashes($href) . '\');return false;"' : '';
                 $img = '<a target="_blank" rel="atm-enlarge" href="' . $href . '"' . $popup . ' title="' . $this->_subfieldValues[1]->getValue() . '">' . $img . '</a>';
             }
             return $img;
             break;
         case 'imageLabel':
             return $this->_subfieldValues[1]->getValue();
             break;
         case 'imageName':
             return $this->_subfieldValues[0]->getValue();
             break;
         case 'imageZoomName':
             return $this->_subfieldValues[2]->getValue();
             break;
         case 'imagePath':
             //get module codename
             $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
             //set location
             $location = $this->isPublic() ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED;
             $altDomain = $this->getAlternativeDomain();
             // If we are serving a public file and there is an alternative domain set up, change the url
             if ($this->isPublic() && $altDomain) {
                 return $altDomain . PATH_MODULES_FILES_WR . '/' . $moduleCodename . '/' . $location;
             } else {
                 return CMS_websitesCatalog::getCurrentDomain() . PATH_MODULES_FILES_WR . '/' . $moduleCodename . '/' . $location;
             }
             break;
         case 'imageMaxWidth':
             //get field parameters
             $params = $this->getParamsValues();
             return $params['maxWidth'] ? $params['maxWidth'] : '';
             break;
         case 'imageMaxHeight':
             //get field parameters
             $params = $this->getParamsValues();
             return $params['maxHeight'] ? $params['maxHeight'] : '';
             break;
         case 'imageWidth':
         case 'imageHeight':
             //get module codename
             $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
             //set location
             $location = $this->isPublic() ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED;
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . $location;
             $imgPath = $path . "/" . $this->_subfieldValues[0]->getValue();
             $sizeX = $sizeY = 0;
             if (file_exists($imgPath)) {
                 list($sizeX, $sizeY) = @getimagesize($imgPath);
             }
             if ($name == 'imageWidth') {
                 return (string) $sizeX;
             } else {
                 return (string) $sizeY;
             }
             break;
         case 'imageZoomWidth':
         case 'imageZoomHeight':
             //get module codename
             $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
             //set location
             $location = $this->isPublic() ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED;
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . $location;
             $imgPath = $path . "/" . $this->_subfieldValues[2]->getValue();
             $sizeX = $sizeY = 0;
             if (file_exists($imgPath)) {
                 list($sizeX, $sizeY) = @getimagesize($imgPath);
             }
             if ($name == 'imageZoomWidth') {
                 return (string) $sizeX;
             } else {
                 return (string) $sizeY;
             }
             break;
         case 'imageSize':
             //get module codename
             $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
             //set location
             $location = $this->isPublic() ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED;
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . $location;
             $filesize = @filesize($path . "/" . $this->_subfieldValues[0]->getValue());
             if ($filesize !== false && $filesize > 0) {
                 //convert in MB
                 $filesize = round($filesize / 1048576, 2) . ' M';
             } else {
                 $filesize = '0 M';
             }
             return $filesize;
             break;
         case 'imageZoomSize':
             //get module codename
             $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
             //set location
             $location = $this->isPublic() ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED;
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . $location;
             $filesize = @filesize($path . "/" . $this->_subfieldValues[2]->getValue());
             if ($filesize !== false && $filesize > 0) {
                 //convert in MB
                 $filesize = round($filesize / 1048576, 2) . ' M';
             } else {
                 $filesize = '0 M';
             }
             return $filesize;
             break;
         case 'alternativeDomain':
             return $this->getAlternativeDomain();
         default:
             return parent::getValue($name, $parameters);
             break;
     }
 }
Example #19
0
 /**
  * Import field 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 (isset($data['labels'])) {
         $label = new CMS_object_i18nm($this->getValue("labelID"));
         $label->setValues($data['labels']);
         $label->writeToPersistence();
         $this->setValue("labelID", $label->getID());
     }
     if (isset($data['descriptions'])) {
         $description = new CMS_object_i18nm($this->getValue("descriptionID"));
         $description->setValues($data['descriptions']);
         $description->writeToPersistence();
         $this->setValue("descriptionID", $description->getID());
     }
     if (isset($data['type']) && $data['type']) {
         $type = !io::isPositiveInteger($data['type']) ? $data['type'] : (isset($data['multi']) && $data['multi'] ? 'multi|' . $data['type'] : $data['type']);
         if (!io::isPositiveInteger($data['type'])) {
             $type = $data['type'];
         } else {
             if (isset($idsRelation['objects'][$data['type']])) {
                 $objectId = $idsRelation['objects'][$data['type']];
                 $type = isset($data['multi']) && $data['multi'] ? 'multi|' . $objectId : $objectId;
             } else {
                 // Use UUID to look for the linked object
                 if (isset($data['params']['linkedObjectUuid'])) {
                     //$this->setValue("order", $data['params']['order']);
                     $linkedObjectDef = CMS_poly_object_catalog::getDefinitionFromUuid($data['params']['linkedObjectUuid']);
                     if ($linkedObjectDef) {
                         $objectId = $linkedObjectDef->getID();
                         $type = isset($data['multi']) && $data['multi'] ? 'multi|' . $objectId : $objectId;
                     } else {
                         $type = 'Unknown imported type ' . $data['type'];
                     }
                 } else {
                     $type = 'Unknown imported type ' . $data['type'];
                 }
             }
         }
         $this->setValue("type", $type);
     } else {
         $infos .= 'Error : missing or invalid type for field importation ...' . "\n";
         return false;
     }
     if (!$this->getID() && CMS_poly_object_catalog::fieldUuidExists($data['uuid'])) {
         //check imported uuid. If objects does not have an Id, the uuid must be unique or must be regenerated
         $uuid = io::uuid();
         //store old uuid relation
         $idsRelation['fields-uuid'][$data['uuid']] = $uuid;
         $data['uuid'] = $uuid;
     }
     //set object uuid if not exists
     if (!$this->_objectFieldValues["uuid"]) {
         $this->_objectFieldValues["uuid"] = $data['uuid'];
     }
     //if current object id has changed from imported id, set relation
     if (isset($idsRelation['objects'][$data['objectID']]) && $idsRelation['objects'][$data['objectID']]) {
         $this->setValue("objectID", $idsRelation['objects'][$data['objectID']]);
     } else {
         $this->setValue("objectID", $data['objectID']);
     }
     if (isset($data['params']['order'])) {
         $this->setValue("order", $data['params']['order']);
     }
     if (isset($data['params']['required'])) {
         $this->setValue("required", $data['params']['required']);
     }
     if (isset($data['params']['indexable'])) {
         $this->setValue("indexable", $data['params']['indexable']);
     }
     if (isset($data['params']['searchlist'])) {
         $this->setValue("searchlist", $data['params']['searchlist']);
     }
     if (isset($data['params']['searchable'])) {
         $this->setValue("searchable", $data['params']['searchable']);
     }
     //parameters
     if (!io::isPositiveInteger($data['type']) || isset($data['multi']) && $data['multi']) {
         $fieldObject = $this->getTypeObject();
         $GLOBALS['moduleCodename'] = $params['module'];
         if ($fieldObject && isset($data['params']['params']) && $data['params']['params']) {
             if (method_exists($fieldObject, 'treatParams')) {
                 $params = $fieldObject->treatParams($data['params']['params'], '');
                 if ($params) {
                     $this->setValue("params", $params);
                     //set this object into definition to convert array so it can be converted again at end of import process
                     $idsRelation['definitionToConvert'][] = $this;
                     //store field to convert params at end of import
                     if (method_exists($fieldObject, 'importParams')) {
                         $idsRelation['paramsFieldsToConvert'][] = $this;
                     }
                 } else {
                     $infos .= 'Error : missing or invalid parameters for field importation ...' . "\n";
                     return false;
                 }
             }
         }
     }
     //write field
     if (!$this->writeToPersistence()) {
         $infos .= 'Error : can not write object field ...' . "\n";
         return false;
     }
     //if current field id has changed from imported id, set relation
     if (isset($data['id']) && $data['id'] && $this->getID() != $data['id']) {
         $idsRelation['fields'][$data['id']] = $this->getID();
         if (isset($data['uuid']) && $data['uuid']) {
             $idsRelation['fields'][$data['uuid']] = $this->getID();
         }
     }
     return true;
 }
Example #20
0
 /**
  * Return a list of all objects names of given type
  *
  * @param boolean $public are the needed datas public ? /!\ Does not apply for this type of object
  * @param array $searchConditions, search conditions to add. /!\ Does not apply for this type of object
  * @return array(integer objectID => string objectName)
  * @access public
  * @static
  */
 function getListOfNamesForObject($public = false, $searchConditions = array(), $restrictToUsedCat = true)
 {
     global $cms_language;
     $module = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
     if (APPLICATION_ENFORCES_ACCESS_CONTROL && !$public) {
         $editableOnly = CLEARANCE_MODULE_EDIT;
     } else {
         $editableOnly = CLEARANCE_MODULE_VIEW;
     }
     $a_all_categories = $this->getAllCategoriesAsArray($cms_language, $restrictToUsedCat, $module, $editableOnly);
     $a_all_categories[CMS_moduleCategory::LINEAGE_PARK_POSITION] = '[' . $cms_language->getMessage(self::MESSAGE_OBJECT_CATEGORIES_FIELD_WITHOUT_CATEGORIES, array($this->_field->getLabel($cms_language)), MOD_POLYMOD_CODENAME) . ']';
     return $a_all_categories;
 }
Example #21
0
//This file is an admin file. Interface must be secure
$view->setSecure();
$winId = sensitiveIO::request('winId');
$objectId = sensitiveIO::request('type', 'sensitiveIO::isPositiveInteger');
$itemId = sensitiveIO::request('item', 'sensitiveIO::isPositiveInteger');
$codename = sensitiveIO::request('module', CMS_modulesCatalog::getAllCodenames());
//instanciate module
$cms_module = CMS_modulesCatalog::getByCodename($codename);
//CHECKS user has module clearance
if (!$cms_user->hasModuleClearance($codename, CLEARANCE_MODULE_EDIT)) {
    CMS_grandFather::raiseError('Error, user has no rights on module : ' . $codename);
    $view->show();
}
//load object
if ($objectId) {
    $object = CMS_poly_object_catalog::getObjectDefinition($objectId);
    $objectLabel = sensitiveIO::sanitizeJSString($object->getLabel($cms_language));
}
if (!isset($object) || $object->hasError()) {
    CMS_grandFather::raiseError('Error, objectId does not exists or has an error : ' . $objectId);
    $view->show();
}
//load item if any
if ($itemId) {
    $item = new CMS_poly_object($objectId, $itemId);
    if (!$item || $item->hasError()) {
        CMS_grandFather::raiseError('Error, unknown item Id : ' . $itemId);
        $view->show();
    }
    $itemLabel = sensitiveIO::sanitizeJSString($item->getLabel());
    if ($object->isPrimaryResource()) {
Example #22
0
    if (is_object($object)) {
        $objectUseage = CMS_poly_object_catalog::getObjectUsage($object->getID(), true);
        if (!sizeof($objectUseage)) {
            $objectUseageLabel = $cms_language->getMessage(MESSAGE_PAGE_FIELD_NO) . '<br />';
        } else {
            $objectUseageLabel = $cms_language->getMessage(MESSAGE_PAGE_FIELD_OBJECT_USED) . ' : <ul>';
            foreach ($objectUseage as $anObjectWhichUse) {
                $objectUseageLabel .= '<li>' . $anObjectWhichUse->getLabel() . '</li>';
            }
            $objectUseageLabel .= '</ul>';
        }
        $fields = CMS_poly_object_catalog::getFieldsDefinition($object->getID(), true);
        //get all RSS def for object
        $RRSDefinitions = CMS_poly_object_catalog::getAllRSSDefinitionsForObject($object->getID());
        //get all plugin def for object
        $pluginDefinitions = CMS_poly_object_catalog::getAllPluginDefinitionsForObject($object->getID());
        $content .= '
		<strong>ID :</strong> ' . $object->getID() . '<br />
		<strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_DESCRIPTION) . ' :</strong> ' . $object->getDescription($cms_language) . '<br />
		<strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_RESOURCE) . ' :</strong> ' . $cms_language->getMessage($resourceStatus[$object->getValue("resourceUsage")]) . '<br />
		<strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_EDITABLE) . ' :</strong> ' . $cms_language->getMessage($adminEditableStatus[$object->getValue("admineditable")]) . '<br />
		<strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_COMPOSED_LABEL) . ' :</strong> ' . $cms_language->getMessage($adminEditableStatus[$object->getValue("composedLabel") ? 0 : 1]) . '<br />
		<strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_OBJECT_USEAGE) . ' :</strong> ' . $objectUseageLabel;
        if (class_exists('CMS_module_ase') && CMS_module_ase::isActive()) {
            $content .= '<strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_OBJECT_INDEXABLE, false, MOD_POLYMOD_CODENAME) . ' :</strong> ' . $cms_language->getMessage($adminIndexableStatus[$object->getValue("indexable") ? 0 : 1]) . '<br />';
        }
        $content .= '
		<form action="polymod_object.php" method="post">
		<td class="admin">
			<input type="hidden" name="moduleCodename" value="' . $moduleCodename . '" />
			<input type="hidden" name="object" value="' . $object->getID() . '" />
Example #23
0
    $view->setActionMessage($cms_language->getmessage(MESSAGE_ERROR_MODULE_RIGHTS, array($module->getLabel($cms_language))));
    $view->setContent($itemsDatas);
    $view->show();
}
//CHECKS objectId
if (!$objectId) {
    CMS_grandFather::raiseError('Missing objectId to search in module ' . $codename);
    $view->setContent($itemsDatas);
    $view->show();
}
//load current object definition
$object = CMS_poly_object_catalog::getObjectDefinition($objectId);
// Check if need to use a specific display for search results
$resultsDefinition = $object->getValue('resultsDefinition');
//load fields objects for object
$objectFields = CMS_poly_object_catalog::getFieldsDefinition($object->getID());
//Add all subobjects to search if any
$fields = array();
$possibleTargets = array();
foreach ($objectFields as $fieldID => $field) {
    if (isset($_REQUEST['items_' . $object->getID() . '_' . $fieldID])) {
        $fields[$fieldID] = sensitiveIO::request('items_' . $object->getID() . '_' . $fieldID, '', '');
    }
    // get the value of all possible searchable fields in case a target is specified by the user
    if ($field->getValue('searchable')) {
        $objectType = $field->getTypeObject();
        if (!method_exists($objectType, 'getListOfNamesForObject')) {
            $possibleTargets[] = $fieldID;
        }
    }
}
Example #24
0
 /**
  * Does given user have the requested clearance for this object ?
  * This method is pretty heavy, so if it must be used on a lots of objects, prefer usage of a search on those objects, it is much faster.
  *
  * @param cms_profile_user $user : the user to check clearance
  * @param constant $clearance : the requested clearance to check (default : CLEARANCE_MODULE_VIEW)
  * @param boolean $checkParent : if no categories fields found, check the parent object (if any) to see if it as some (beware this is heavy). Default : false
  * @return boolean
  * @access public
  */
 function userHasClearance($user, $clearance = CLEARANCE_MODULE_VIEW, $checkParent = false)
 {
     if (!$this->_public || APPLICATION_ENFORCES_ACCESS_CONTROL === true) {
         //user is an administrator?
         if ($user->hasAdminClearance(CLEARANCE_ADMINISTRATION_EDITVALIDATEALL)) {
             return true;
         }
         //get Object definition
         $objectDef = $this->getObjectDefinition();
         //get module codename
         $polyModuleCodename = $objectDef->getValue('module');
         //check user right on module (check only minimum needed : VIEW, proper right is checked after on category)
         if (!$user->hasModuleClearance($polyModuleCodename, CLEARANCE_MODULE_VIEW)) {
             return false;
         }
         //object has categories fields ?
         $categoriesFields = CMS_poly_object_catalog::objectHasCategories($this->getObjectID());
         $allCategories = array();
         if (!$categoriesFields && !$checkParent) {
             //no categories on object so user has rights
             return true;
         } elseif (!$categoriesFields && $checkParent) {
             //check for module Categories usage
             if (!CMS_poly_object_catalog::moduleHasCategories($polyModuleCodename)) {
                 //no categories used on module : item is viewvable
                 return true;
             }
             //check for a parent for the given object
             if ($objectParentsIDs = CMS_poly_object_catalog::getParentsObject($this->getObjectID())) {
                 $found = false;
                 //check object for each parent objects found
                 foreach ($objectParentsIDs as $objectParentID => $objectParentFields) {
                     $categoriesFields = CMS_poly_object_catalog::objectHasCategories($objectParentID);
                     if (is_array($categoriesFields) && $categoriesFields) {
                         //load current object definition
                         $object = CMS_poly_object_catalog::getObjectDefinition($objectParentID);
                         foreach ($objectParentFields as $fieldID) {
                             $search = new CMS_object_search($object, $this->_public);
                             $search->addWhereCondition($fieldID, $this->getID());
                             $ids = $search->search(CMS_object_search::POLYMOD_SEARCH_RETURN_IDS);
                             $found = $ids ? true : $found;
                         }
                     }
                 }
                 //if one parent was found then object is visible
                 return $found;
             } else {
                 //no parent object for this object, item is viewvable
                 return true;
             }
         } elseif (is_array($categoriesFields) && $categoriesFields) {
             $search = new CMS_object_search($objectDef, $clearance == CLEARANCE_MODULE_VIEW);
             $search->addWhereCondition('item', $this->getID());
             $search->addWhereCondition("profile", $user);
             $ids = $search->search(CMS_object_search::POLYMOD_SEARCH_RETURN_IDS);
             return $ids ? true : false;
         }
     }
     //user has clearance
     return true;
 }
Example #25
0
 /**
  * Sort and limit found ids by orders and limit clauses
  * This method limit results to existant objects too
  * 
  * @access private
  * @return array of object ids sorted
  */
 protected function _sortIds()
 {
     $statusSuffix = $this->_public ? "_public" : "_edited";
     $ids = array();
     if ($this->_orderConditions) {
         //reverse order conditions (needed to get natural order)
         $orderConditions = array_reverse($this->_orderConditions, true);
         //loop on each order conditions
         foreach ($orderConditions as $type => $value) {
             $sql = '';
             if (!isset($value['direction']) || !$value['direction']) {
                 $value['direction'] = 'asc';
             }
             if (!isset($value['operator']) || !$value['operator']) {
                 $value['operator'] = '';
             }
             $direction = $value['direction'];
             $operator = $value['operator'];
             //add previously found ids to where clause
             if (is_array($this->_resultsIds) && $this->_resultsIds) {
                 //update tmp table with found ids
                 $this->_updateTmpList($this->_resultsIds);
                 $where = ' and objectID in (' . $this->_getSQLTmpList() . ')';
             } else {
                 $where = '';
             }
             switch ($type) {
                 case "publication date after":
                     // Date start
                 // Date start
                 case "publication date before":
                     // Date start
                 // Date start
                 case "publication date start":
                     // Date start
                     $sql = "\n\t\t\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t\t\tdistinct objectID\n\t\t\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t\t\tmod_subobject_integer" . $statusSuffix . ",\n\t\t\t\t\t\t\t\t\tresources,\n\t\t\t\t\t\t\t\t\tresourceStatuses\n\t\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\t\tobjectFieldID = '0'\n\t\t\t\t\t\t\t\t\tand value = id_res\n\t\t\t\t\t\t\t\t\tand status_res=id_rs\n\t\t\t\t\t\t\t\t\t{$where}\n\t\t\t\t\t\t\t\torder by publicationDateStart_rs " . $direction;
                     break;
                 case "publication date end":
                     // Date end
                     $sql = "\n\t\t\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t\t\tdistinct objectID\n\t\t\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t\t\tmod_subobject_integer" . $statusSuffix . ",\n\t\t\t\t\t\t\t\t\tresources,\n\t\t\t\t\t\t\t\t\tresourceStatuses\n\t\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\t\tobjectFieldID = '0'\n\t\t\t\t\t\t\t\t\tand value = id_res\n\t\t\t\t\t\t\t\t\tand status_res=id_rs\n\t\t\t\t\t\t\t\t\t{$where}\n\t\t\t\t\t\t\t\torder by publicationDateEnd_rs " . $direction;
                     break;
                 case 'objectID':
                     $ids = $ids ? $ids : $this->_resultsIds;
                     ksort($ids, SORT_NUMERIC);
                     $ids = $direction == 'asc' ? $ids : array_reverse($ids, true);
                     break;
                 case 'itemsOrdered':
                     $orderedIds = $direction == 'asc' ? $this->_orderConditions['itemsOrdered']['order'] : array_reverse($this->_orderConditions['itemsOrdered']['order'], true);
                     $ids = array_intersect($orderedIds, $ids ? $ids : $this->_resultsIds);
                     unset($orderedIds);
                     break;
                 case 'random':
                     $tmpIds = $ids ? $ids : $this->_resultsIds;
                     shuffle($tmpIds);
                     $ids = array();
                     foreach ($tmpIds as $id) {
                         $ids[$id] = $id;
                     }
                     break;
                 case "relevance":
                     //this order condition is replaced by an itemsOrdered order at the end of _getIds method
                     break;
                 default:
                     if (sensitiveIO::isPositiveInteger($type)) {
                         if (!isset($this->_fieldsDefinitions[$type]) || !is_object($this->_fieldsDefinitions[$type])) {
                             //get object fields definition
                             $this->_fieldsDefinitions = CMS_poly_object_catalog::getFieldsDefinition($this->_object->getID());
                         }
                         if (isset($this->_fieldsDefinitions[$type])) {
                             //get type object for field
                             $objectField = $this->_fieldsDefinitions[$type]->getTypeObject();
                             $operator = isset($operator) ? $operator : '';
                             $sql = $objectField->getFieldOrderSQL($type, $direction, $operator, $where, $this->_public);
                         } else {
                             $this->raiseError('Unknown field ' . $type . ' to use as order with value ' . print_r($value, true));
                         }
                     }
                     break;
             }
             if ($sql) {
                 if (isset($ids) && $ids) {
                     $sql .= " , field(objectID, " . implode(',', array_reverse($ids)) . ") desc ";
                 }
                 $q = new CMS_query($sql);
                 $orderedIds = array();
                 if (!$q->hasError()) {
                     //save ordered ids
                     while ($id = $q->getValue('objectID')) {
                         $orderedIds[$id] = $id;
                     }
                 }
                 $ids = $orderedIds;
             }
         }
     } else {
         $ids = $this->_resultsIds;
     }
     //check for results existance in objects datas tables
     if ($ids) {
         //update tmp table with found ids
         $this->_updateTmpList($ids);
         $where = ' objectID in (' . $this->_getSQLTmpList() . ')';
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\tdistinct objectID\n\t\t\t\tfrom\n\t\t\t\t\tmod_subobject_text" . $statusSuffix . "\n\t\t\t\twhere\n\t\t\t\t\t{$where}\n\t\t\t\tunion distinct\n\t\t\t\tselect\n\t\t\t\t\tdistinct objectID\n\t\t\t\tfrom\n\t\t\t\t\tmod_subobject_integer" . $statusSuffix . "\n\t\t\t\twhere\n\t\t\t\t\t{$where}\n\t\t\t\tunion distinct\n\t\t\t\tselect\n\t\t\t\t\tdistinct objectID\n\t\t\t\tfrom\n\t\t\t\t\tmod_subobject_string" . $statusSuffix . "\n\t\t\t\twhere\n\t\t\t\t\t{$where}\n\t\t\t\tunion distinct\n\t\t\t\tselect\n\t\t\t\t\tdistinct objectID\n\t\t\t\tfrom\n\t\t\t\t\tmod_subobject_date" . $statusSuffix . "\n\t\t\t\twhere\n\t\t\t\t\t{$where}\n\t\t\t";
         $q = new CMS_query($sql);
         if ($q->getNumRows() != count($ids)) {
             $foundIds = $q->getAll(PDO::FETCH_COLUMN, 0);
             if ($foundIds) {
                 $ids = array_intersect($ids, $foundIds);
                 //update count of results
                 $this->_numRows = sizeof($ids);
             } else {
                 $ids = array();
                 $this->_numRows = 0;
             }
         }
     }
     //Limit results if needed
     if ($ids && $this->_numRows > 0 && $this->_itemsPerPage > 0) {
         $ids = array_slice($ids, $this->_page * $this->_itemsPerPage, $this->_itemsPerPage, true);
     }
     return $ids;
 }
Example #26
0
 protected function _evalPHPContent($content)
 {
     //eval() the PHP code
     if ($content != '' && !function_exists((string) $content)) {
         //first, try to get all items ids to search
         $count = preg_match_all("#(<\\?php|<\\?).*'([0-9]*?)', '([0-9]*?)',.*\\?>#Usi", $content, $matches);
         //if more than one item is found in text, it is faster to search them by one search
         if ($count > 1) {
             $ids = $GLOBALS['polymod']['preparedItems'] = array();
             //then sort all items ids by plugin ID
             foreach ($matches[2] as $key => $match) {
                 $ids[$match][] = $matches[3][$key];
             }
             //then search all items
             foreach ($ids as $pluginID => $itemsIds) {
                 //get plugin
                 $plugin = new CMS_poly_plugin_definitions($pluginID);
                 if ($plugin && is_object($plugin) && !$plugin->hasError()) {
                     //then search all objects and put results in a global var usable in CMS_poly_definition_functions::pluginCode method (ugly i know)
                     $GLOBALS['polymod']['preparedItems'][$plugin->getValue('objectID')] = CMS_poly_object_catalog::getAllObjects($plugin->getValue('objectID'), $this->_public, array('items' => $itemsIds), true);
                 }
             }
         }
         //then eval all php codes if any
         if (strpos($content, '<?php') !== false) {
             $content = io::evalPHPCode($content);
         }
         if (isset($GLOBALS['polymod']['preparedItems'])) {
             unset($GLOBALS['polymod']['preparedItems']);
         }
     }
     return $content;
 }
 /** 
  * Get the module primary resource definition
  *
  * @return boolean true
  * @access public
  */
 function getPrimaryResourceDefinition()
 {
     if (!$this->_primaryResourceObjectDefinition instanceof CMS_poly_object_definition) {
         $this->_primaryResourceObjectDefinition = CMS_poly_object_catalog::getObjectDefinition(CMS_poly_object_catalog::getPrimaryResourceObjectType($this->getCodename()));
     }
     return true;
 }
Example #28
0
 /**
  * Get field parameters as an array structure used for export
  *
  * @return array : the object array structure
  * @access public
  */
 public function asArray()
 {
     $aParameters = parent::asArray();
     $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
     $module = CMS_modulesCatalog::getByCodename($moduleCodename);
     //convert definitions
     $aParameters['emailSubject'] = $module->convertDefinitionString($aParameters['emailSubject'], true);
     $aParameters['emailBody']['html'] = $module->convertDefinitionString($aParameters['emailBody']['html'], true);
     $aParameters['emailBody']['pageURL'] = $module->convertDefinitionString($aParameters['emailBody']['pageURL'], true);
     return $aParameters;
 }
Example #29
0
    /**
     * get HTML admin (used to enter object values in admin)
     *
     * @param integer $fieldID, the current field id (only for poly object compatibility)
     * @param CMS_language $language, the current admin language
     * @param string prefixname : the prefix to use for post names
     * @return string : the html admin
     * @access public
     */
    function getHTMLAdmin($fieldID, $language, $prefixName)
    {
        //get module codename
        $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
        //is this field mandatory ?
        $mandatory = $this->_field->getValue('required') ? '<span class="atm-red">*</span> ' : '';
        $desc = $this->getFieldDescription($language);
        if (POLYMOD_DEBUG) {
            $values = array();
            foreach (array_keys($this->_subfieldValues) as $subFieldID) {
                if (is_object($this->_subfieldValues[$subFieldID])) {
                    $values[$subFieldID] = sensitiveIO::ellipsis(strip_tags($this->_subfieldValues[$subFieldID]->getValue()), 50);
                }
            }
            $desc .= $desc ? '<br />' : '';
            $desc .= '<span class="atm-red">Field : ' . $fieldID . ' - Value(s) : <ul>';
            foreach ($values as $subFieldID => $value) {
                $desc .= '<li>' . $subFieldID . '&nbsp;:&nbsp;' . $value . '</li>';
            }
            $desc .= '</ul></span>';
        }
        $label = $desc ? '<span class="atm-help" ext:qtip="' . io::htmlspecialchars($desc) . '">' . $mandatory . $this->getFieldLabel($language) . '</span>' : $mandatory . $this->getFieldLabel($language);
        $ids = 'oembed-' . md5(mt_rand() . microtime());
        $oembedURL = PATH_ADMIN_MODULES_WR . '/' . MOD_POLYMOD_CODENAME . '/oembed.php';
        $loadingURL = PATH_ADMIN_IMAGES_WR . '/loading-old.gif';
        $params = $this->getParamsValues();
        $fields = array();
        $fields[] = array('fieldLabel' => '<span class="atm-help" ext:qtip="' . io::htmlspecialchars($language->getMessage(self::MESSAGE_OBJECT_OEMBED_MEDIA_URL_DESC, false, MOD_POLYMOD_CODENAME)) . '">' . $language->getMessage(self::MESSAGE_OBJECT_OEMBED_MEDIA_URL, false, MOD_POLYMOD_CODENAME) . '</span>', 'xtype' => 'textfield', 'name' => 'polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_0]', 'value' => $this->_subfieldValues[0]->getValue() ? sensitiveIO::decodeEntities($this->_subfieldValues[0]->getValue()) : '', 'enableKeyEvents' => true, 'listeners' => array('blur' => array('fn' => sensitiveIO::sanitizeJSString('function(el){
						/*call server for oembed HTML content*/
						Ext.get(\'' . $ids . '-view\').update(\'<img src="' . $loadingURL . '" />\');
						Automne.server.call({
							url:			\'' . $oembedURL . '\',
							scope:			this,
							fcnCallback:	function(response, options, htmlResponse){
								Ext.get(\'' . $ids . '-view\').update(htmlResponse);
							},
							params:			{
								module:			\'' . $moduleCodename . '\',
								url:			el.getValue(),
								width:			600,
								height:			250,
								key:			\'' . $params['embedlyKey'] . '\'
							}
						});
					}', false, false), 'buffer' => 600)));
        $fields[] = array('xtype' => 'panel', 'border' => false, 'html' => '<div id="' . $ids . '-view" style="overflow:auto;text-align:center;">' . ($this->getValue('hasValue') ? $this->getValue('html', '600,250') : '') . '</div>');
        $return = array();
        $return = array('title' => $label, 'xtype' => 'fieldset', 'autoHeight' => true, 'defaultType' => 'textfield', 'defaults' => array('anchor' => '97%', 'allowBlank' => !$this->_field->getValue('required')), 'items' => $fields);
        return $return;
    }
 /**
  * Import plugin from given array datas
  *
  * @param array $data The plugin datas to import
  * @param array $params The import parameters.
  *		array(
  *				module	=> false|true : the module to create plugin (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
  */
 function fromArray($data, $params, $cms_language, &$idsRelation, &$infos)
 {
     if (!isset($params['module'])) {
         $infos .= 'Error : missing module codename for rss feed importation ...' . "\n";
         return false;
     }
     $module = CMS_modulesCatalog::getByCodename($params['module']);
     if ($module->hasError()) {
         $infos .= 'Error : invalid module for rss feed importation : ' . $params['module'] . "\n";
         return false;
     }
     if (!$this->getID() && CMS_poly_object_catalog::pluginUuidExists($data['uuid'])) {
         //check imported uuid. If plugin does not have an Id, the uuid must be unique or must be regenerated
         $uuid = io::uuid();
         //store old uuid relation
         $idsRelation['plugins-uuid'][$data['uuid']] = $uuid;
         $data['uuid'] = $uuid;
     }
     //set plugin uuid if not exists
     if (!$this->_objectValues["uuid"]) {
         $this->_objectValues["uuid"] = $data['uuid'];
     }
     if (isset($data['labels'])) {
         $label = new CMS_object_i18nm($this->getValue("labelID"));
         $label->setValues($data['labels']);
         $label->writeToPersistence();
         $this->setValue("labelID", $label->getID());
     }
     if (isset($data['descriptions'])) {
         $description = new CMS_object_i18nm($this->getValue("descriptionID"));
         $description->setValues($data['descriptions']);
         $description->writeToPersistence();
         $this->setValue("descriptionID", $description->getID());
     }
     //if current object id has changed from imported id, set relation
     if (isset($idsRelation['objects'][$data['objectID']]) && $idsRelation['objects'][$data['objectID']]) {
         $this->setValue("objectID", $idsRelation['objects'][$data['objectID']]);
     } else {
         $this->setValue("objectID", $data['objectID']);
     }
     //values
     if (isset($data['params']['query'])) {
         //translate ids if needed
         $query = array();
         foreach ($data['params']['query'] as $objectId => $value) {
             if (isset($idsRelation['objects'][$objectId])) {
                 //object exists with a translated id
                 $query[$idsRelation['objects'][$objectId]] = $value;
             } else {
                 $query[$objectId] = $value;
             }
         }
         $this->setValue("query", $query);
     }
     if (isset($data['params']['definition'])) {
         $this->setValue("definition", $module->convertDefinitionString($data['params']['definition'], false));
     }
     //write object
     if (!$this->writeToPersistence()) {
         $infos .= 'Error : can not write object ...' . "\n";
         return false;
     }
     //if current object id has changed from imported id, set relation
     if (isset($data['id']) && $data['id'] && $this->getID() != $data['id']) {
         $idsRelation['plugins'][$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;
 }