Example #1
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;
 }
 /**
  * Gets a validation for a given item
  *
  * @param integer $itemID The item we want the validations for
  * @param CMS_user $user The user we want the validations for
  * @param integer $getEditionType The validation type we want.
  *  by default function return RESOURCE_EDITION_LOCATION then RESOURCE_EDITION_CONTENT then RESOURCE_EDITION_SIBLINGSORDER
  * @return array(CMS_resourceValidation) The resourceValidations objects, false if none found for the given user.
  * @access public
  */
 function getValidationByID($itemID, &$user, $getEditionType = false)
 {
     if (!$user instanceof CMS_profile_user) {
         $this->raiseError("User is not a valid CMS_profile_user object");
         return false;
     }
     if (!$user->hasValidationClearance($this->_codename)) {
         return false;
     }
     if (CMS_poly_object_catalog::hasPrimaryResource($this->getCodename())) {
         //get object type ID
         $objectID = CMS_poly_object_catalog::getPrimaryResourceObjectType($this->getCodename());
         //get viewvable objects list for current user
         if (CMS_poly_object_catalog::objectHasCategories($objectID)) {
             $objects = CMS_poly_object_catalog::getAllObjects($objectID, false, array(), false);
             //$where = (is_array($objects) && $objects) ? ' and objectID in ('.implode(',',$objects).')' : '';
             if (is_array($objects) && $objects) {
                 $where = ' and objectID in (' . implode(',', $objects) . ')';
             } else {
                 return false;
             }
         } else {
             $where = '';
         }
         $this->getPrimaryResourceDefinition();
         if (!$getEditionType) {
             $getEditionType = RESOURCE_EDITION_LOCATION + RESOURCE_EDITION_CONTENT;
         }
         $sql = "\n\t\t\t\t\tselect\n\t\t\t\t\t\tobjectID as id,\n\t\t\t\t\t\tlocation_rs as location,\n\t\t\t\t\t\tproposedFor_rs as proposedFor,\n\t\t\t\t\t\tvalidationsRefused_rs as validationsRefused,\n\t\t\t\t\t\teditions_rs as editions,\n\t\t\t\t\t\tmod_subobject_integer_edited.id as fieldID\n\t\t\t\t\tfrom\n\t\t\t\t\t\tmod_subobject_integer_edited,\n\t\t\t\t\t\tmod_object_polyobjects,\n\t\t\t\t\t\tresources,\n\t\t\t\t\t\tresourceStatuses\n\t\t\t\t\twhere\n\t\t\t\t\t\tobjectID = '" . $itemID . "'\n\t\t\t\t\t\tand value = id_res\n\t\t\t\t\t\tand object_type_id_moo = '" . $objectID . "'\n\t\t\t\t\t\tand id_moo = objectID\n\t\t\t\t\t\tand objectFieldID = 0\n\t\t\t\t\t\tand objectSubFieldID = 0\n\t\t\t\t\t\tand status_res = id_rs\n\t\t\t\t\t\t{$where}\n\t\t\t\t";
         $q = new CMS_query($sql);
         if ($q->getNumRows() >= 1) {
             $r = $q->getArray();
             $id = $r["id"];
             //here, this is an ugly hack to resolve a strange bug (multiple resources for an unique object).
             //not time to found the real cause for now ...
             if ($q->getNumRows() > 1) {
                 while ($exceptionFiledID = $q->getValue('fieldID')) {
                     $sql_delete = "delete from mod_subobject_integer_edited where id = '" . $exceptionFiledID . "'";
                     $q_delete = new CMS_query($sql_delete);
                 }
             }
             //search the type of edition
             //RESOURCE_EDITION_LOCATION
             if ($r["location"] == RESOURCE_LOCATION_USERSPACE && $r["proposedFor"] != 0 && !($r["validationsRefused"] & RESOURCE_EDITION_LOCATION) && $getEditionType & RESOURCE_EDITION_LOCATION) {
                 $language = $user->getLanguage();
                 $item = $this->getResourceByID($id);
                 $validation = new CMS_resourceValidation($this->_codename, RESOURCE_EDITION_LOCATION, $item);
                 if (!$validation->hasError()) {
                     $validation->setValidationTypeLabel($language->getMessage(self::MESSAGE_MOD_POLYMOD_VALIDATION_LOCATIONCHANGE, array($this->_primaryResourceObjectDefinition->getLabel($language)), MOD_POLYMOD_CODENAME));
                     $validation->setValidationLabel($language->getMessage(self::MESSAGE_MOD_POLYMOD_VALIDATION_LOCATIONCHANGE_OFRESOURCE, array($this->_primaryResourceObjectDefinition->getLabel($language)), MOD_POLYMOD_CODENAME) . " " . io::decodeEntities($item->{$this->_resourceNameMethod}()));
                     $validation->setValidationShortLabel(io::decodeEntities($item->{$this->_resourceNameMethod}()));
                     $previzURL = $item->getPrevizPageURL();
                     if ($previzURL) {
                         $validation->addHelpUrl($language->getMessage(self::MESSAGE_PAGE_ACTION_PREVIZ), $previzURL);
                     }
                     $validation->setEditorsStack($item->getEditorsStack());
                     return $validation;
                 } else {
                     return false;
                 }
                 //RESOURCE_EDITION_CONTENT
             } elseif ($r["location"] == RESOURCE_LOCATION_USERSPACE && $r["proposedFor"] == 0 && ($r["editions"] & RESOURCE_EDITION_CONTENT && !($r["validationsRefused"] & RESOURCE_EDITION_CONTENT)) && $getEditionType & RESOURCE_EDITION_CONTENT) {
                 $language = $user->getLanguage();
                 $editions = $r["editions"];
                 //RESOURCE_EDITION_CONTENT
                 $item = $this->getResourceByID($id);
                 $validation = new CMS_resourceValidation($this->_codename, $editions, $item);
                 if (!$validation->hasError()) {
                     $validation->setValidationTypeLabel($language->getMessage(self::MESSAGE_MOD_POLYMOD_VALIDATION_EDITION, array($this->_primaryResourceObjectDefinition->getLabel($language)), MOD_POLYMOD_CODENAME));
                     $validation->setValidationLabel($language->getMessage(self::MESSAGE_MOD_POLYMOD_VALIDATION_EDITION_OFRESOURCE, array($this->_primaryResourceObjectDefinition->getLabel($language)), MOD_POLYMOD_CODENAME) . " " . io::decodeEntities($item->{$this->_resourceNameMethod}()));
                     $validation->setValidationShortLabel(io::decodeEntities($item->{$this->_resourceNameMethod}()));
                     $previzURL = $item->getPrevizPageURL();
                     if ($previzURL) {
                         $validation->addHelpUrl($language->getMessage(self::MESSAGE_PAGE_ACTION_PREVIZ), $previzURL);
                     }
                     $validation->setEditorsStack($item->getEditorsStack());
                     return $validation;
                 } else {
                     return false;
                 }
             }
         } elseif ($q->getNumRows() == 0) {
             return false;
         } else {
             $this->raiseError("Can't have more than one item for a given ID");
             return false;
         }
     } else {
         return false;
     }
 }
 /**
  * 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);
 }