Пример #1
0
 /**
  * Return a recursive structure for all objects of a given module based on objects definition
  *
  * @param string $module the module codename
  * @param boolean $withObjectInfos returned structure contain objects infos (default false)
  * @return multidimensionnal array : the recursive structure of all objects of the given module
  * @access public
  * @static
  */
 function getModuleStructure($module, $withObjectInfos = false)
 {
     $sql = "select\n\t\t\t\t\tobject_id_mof as objectID,\n\t\t\t\t\ttype_mof as fieldType,\n\t\t\t\t\tid_mof as fieldID\n\t\t\t\tfrom\n\t\t\t\t\tmod_object_definition,\n\t\t\t\t\tmod_object_field\n\t\t\t\twhere\n\t\t\t\t\tid_mod = object_id_mof\n\t\t\t\torder by objectID, order_mof\n\t\t";
     //SQL where clause removed when add cross modules link into objects
     /*module_mod='".sensitiveIO::sanitizeSQLString($module)."'
     		and */
     $q = new CMS_query($sql);
     $flatStructure = array();
     if ($q->getNumRows()) {
         while ($r = $q->getArray()) {
             $flatStructure['object' . $r['objectID']]['field' . $r['fieldID']] = $r['fieldType'];
         }
     }
     //append objects without fields
     $sql = "select\n\t\t\t\t\tid_mod as objectID\n\t\t\t\tfrom\n\t\t\t\t\tmod_object_definition\n\t\t\t\torder by objectID\n\t\t";
     $q = new CMS_query($sql);
     if ($q->getNumRows()) {
         while ($r = $q->getArray()) {
             if (!isset($flatStructure['object' . $r['objectID']])) {
                 $flatStructure['object' . $r['objectID']] = array();
             }
         }
     }
     if ($withObjectInfos) {
         $objectInfos = array();
     }
     $structure = CMS_poly_module_structure::_createRecursiveStructure($flatStructure, $flatStructure, $objectInfos);
     if ($withObjectInfos) {
         $structure['objectInfos'] = $objectInfos;
     }
     return $structure;
 }
 /**
  * Constructor.
  * initialize object.
  *
  * @param integer $id DB id
  * @param array $dbValues DB values
  * @return void
  * @access public
  */
 function __construct($id = 0, $dbValues = array())
 {
     $datas = array();
     if ($id && !$dbValues) {
         if (!SensitiveIO::isPositiveInteger($id)) {
             $this->raiseError("Id is not a positive integer : " . $id);
             return;
         }
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\t*\n\t\t\t\tfrom\n\t\t\t\t\tmod_object_plugin_definition\n\t\t\t\twhere\n\t\t\t\t\tid_mowd='" . $id . "'\n\t\t\t";
         $q = new CMS_query($sql);
         if ($q->getNumRows()) {
             $datas = $q->getArray();
         } else {
             $this->raiseError("Unknown ID :" . $id);
             return;
         }
     } elseif (is_array($dbValues) && $dbValues) {
         $datas = $dbValues;
     }
     if (is_array($datas) && $datas) {
         $this->_ID = (int) $datas['id_mowd'];
         $this->_objectValues["objectID"] = (int) $datas['object_id_mowd'];
         $this->_objectValues["labelID"] = (int) $datas['label_id_mowd'];
         $this->_objectValues["descriptionID"] = (int) $datas['description_id_mowd'];
         $this->_objectValues["query"] = $datas['query_mowd'] ? unserialize($datas['query_mowd']) : array();
         $this->_objectValues["definition"] = $datas['definition_mowd'];
         $this->_objectValues["compiledDefinition"] = $datas['compiled_definition_mowd'];
         $this->_objectValues["uuid"] = isset($datas['uuid_mowd']) ? $datas['uuid_mowd'] : '';
         //for compatibility with version < 0.97
         if ($this->_objectValues["definition"] && !$this->_objectValues["compiledDefinition"]) {
             $this->compileDefinition();
             $this->writeToPersistence();
         }
     }
 }
Пример #3
0
 /**
  * Constructor.
  * initialize object.
  *
  * @param integer $id DB id
  * @param array $dbValues DB values
  * @return void
  * @access public
  */
 function __construct($id = 0, $dbValues = array())
 {
     $datas = array();
     if ($id && !$dbValues) {
         if (!SensitiveIO::isPositiveInteger($id)) {
             $this->raiseError("Id is not a positive integer : " . $id);
             return;
         }
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\t*\n\t\t\t\tfrom\n\t\t\t\t\tmod_object_rss_definition\n\t\t\t\twhere\n\t\t\t\t\tid_mord='" . $id . "'\n\t\t\t";
         $q = new CMS_query($sql);
         if ($q->getNumRows()) {
             $datas = $q->getArray();
         } else {
             $this->raiseError("Unknown ID :" . $id);
             return;
         }
     } elseif (is_array($dbValues) && $dbValues) {
         $datas = $dbValues;
     }
     if (is_array($datas) && $datas) {
         $this->_ID = (int) $datas['id_mord'];
         $this->_objectValues["objectID"] = (int) $datas['object_id_mord'];
         $this->_objectValues["labelID"] = (int) $datas['label_id_mord'];
         $this->_objectValues["descriptionID"] = (int) $datas['description_id_mord'];
         $this->_objectValues["link"] = $datas['link_mord'];
         $this->_objectValues["author"] = $datas['author_mord'];
         $this->_objectValues["copyright"] = $datas['copyright_mord'];
         $this->_objectValues["namespaces"] = $datas['namespaces_mord'];
         $this->_objectValues["categories"] = $datas['categories_mord'];
         $this->_objectValues["ttl"] = (int) $datas['ttl_mord'];
         $this->_objectValues["email"] = $datas['email_mord'];
         $this->_objectValues["definition"] = $datas['definition_mord'];
         $this->_objectValues["compiledDefinition"] = $datas['compiled_definition_mord'];
         $this->_objectValues["lastCompilation"] = new CMS_date();
         $this->_objectValues["lastCompilation"]->setFromDBValue($datas['last_compilation_mord']);
         $this->_objectValues["uuid"] = isset($datas['uuid_mord']) ? $datas['uuid_mord'] : '';
     } else {
         $this->_objectValues["lastCompilation"] = new CMS_date();
     }
     //check for last compilation date (recompile Feed each day)
     if ($this->_objectValues["compiledDefinition"]) {
         $lastCompilation = $this->_objectValues["lastCompilation"];
         $lastCompilation->moveDate('+1 day');
         $today = new CMS_date();
         $today->setNow();
         if (CMS_date::compare($today, $lastCompilation, '>')) {
             $this->compileDefinition();
             $this->writeToPersistence();
         }
     }
 }
Пример #4
0
 /**
  * Constructor.
  * initializes the resource if the id is given
  *
  * @param integer $id DB id
  * @return void
  * @access public
  */
 function CMS_resource($id = 0)
 {
     if ($id) {
         if (SensitiveIO::isPositiveInteger($id)) {
             $sql = "\n\t\t\t\t\tselect\n\t\t\t\t\t\t*\n\t\t\t\t\tfrom\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\tid_res='{$id}'\n\t\t\t\t\t\tand status_res=id_rs\n\t\t\t\t";
             $q = new CMS_query($sql);
             if ($q->getNumRows()) {
                 $data = $q->getArray();
                 $this->_id = $id;
                 $this->_status = new CMS_resourceStatus($data);
                 if ($this->_status->hasError()) {
                     $this->raiseError("Unfound status :" . $data["status_res"]);
                     return;
                 }
                 //build editors stack. If stack is malformed, it's a minor error, so proceed.
                 $this->_editors = new CMS_stack();
                 if (!$this->_editors->setTextDefinition($data["editorsStack_res"])) {
                     $this->raiseError("Editors stack malformed");
                     $this->_editors->emptyStack();
                 }
             } else {
                 $this->raiseError("Unknown ID :" . $id);
             }
         } elseif (is_array($id)) {
             $data = $id;
             $this->_id = $data["id_res"];
             $this->_status = new CMS_resourceStatus($data);
             if ($this->_status->hasError()) {
                 $this->raiseError("Unfound status :" . $data["status_res"]);
                 return;
             }
             //build editors stack. If stack is malformed, it's a minor error, so proceed.
             $this->_editors = new CMS_stack();
             if (!$this->_editors->setTextDefinition($data["editorsStack_res"])) {
                 $this->raiseError("Editors stack malformed");
                 $this->_editors->emptyStack();
             }
         } else {
             $this->raiseError("Id is not a positive integer nor array");
             return;
         }
     } else {
         $this->_status = new CMS_resourceStatus();
         $this->_editors = new CMS_stack();
     }
 }
Пример #5
0
 /**
  * Constructor
  * 
  * @access public
  * @param integer $id
  * @return void 
  */
 function __construct($id = 0)
 {
     if ($id) {
         if (!SensitiveIO::isPositiveInteger($id)) {
             $this->raiseError("Id is not a positive integer");
             return;
         }
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\t*\n\t\t\t\tfrom\n\t\t\t\t\tmod_cms_forms_records\n\t\t\t\twhere\n\t\t\t\t\tid_rec='" . $id . "'\n\t\t\t";
         $q = new CMS_query($sql);
         if ($q->getNumRows()) {
             $data = $q->getArray();
             $this->_recordID = $id;
             $this->_fieldID = $data["field_rec"];
             $this->_senderID = $data["sending_rec"];
             $this->_value = $data["value_rec"];
         } else {
             $this->raiseError("Unknown ID :" . $id);
         }
     }
 }
Пример #6
0
 /**
  * Constructor.
  * initialize object.
  *
  * @param integer $id DB id
  * @param array $dbValues DB values
  * @return void
  * @access public
  */
 function __construct($id = 0, $dbValues = array())
 {
     $datas = array();
     if ($id && !$dbValues) {
         if (!SensitiveIO::isPositiveInteger($id)) {
             $this->raiseError("Id is not a positive integer : " . $id);
             return;
         }
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\t*\n\t\t\t\tfrom\n\t\t\t\t\tmod_object_field,\n\t\t\t\t\tmod_object_definition\n\t\t\t\twhere\n\t\t\t\t\tid_mof='" . $id . "'\n\t\t\t\t\tand object_id_mof = id_mod\n\t\t\t";
         $q = new CMS_query($sql);
         if ($q->getNumRows()) {
             $datas = $q->getArray();
         } else {
             $this->raiseError("Unknown ID :" . $id);
             return;
         }
     } elseif (is_array($dbValues) && $dbValues) {
         $datas = $dbValues;
     }
     if (is_array($datas) && $datas) {
         //set parent values
         parent::__construct($datas['object_id_mof'], $datas);
         //set field values
         $this->_fieldID = (int) $datas['id_mof'];
         $this->_objectFieldValues["objectID"] = (int) $datas['object_id_mof'];
         $this->_objectFieldValues["labelID"] = (int) $datas['label_id_mof'];
         $this->_objectFieldValues["descriptionID"] = (int) $datas['desc_id_mof'];
         $this->_objectFieldValues["type"] = $datas['type_mof'];
         $this->_objectFieldValues["order"] = (int) $datas['order_mof'];
         $this->_objectFieldValues["system"] = $datas['system_mof'] ? true : false;
         $this->_objectFieldValues["required"] = $datas['required_mof'] ? true : false;
         $this->_objectFieldValues["indexable"] = $datas['indexable_mof'] ? true : false;
         $this->_objectFieldValues["searchlist"] = $datas['searchlist_mof'] ? true : false;
         $this->_objectFieldValues["searchable"] = $datas['searchable_mof'] ? true : false;
         $this->_objectFieldValues["params"] = $datas['params_mof'] ? unserialize($datas['params_mof']) : array();
         $this->_objectFieldValues["uuid"] = isset($datas['uuid_mof']) ? $datas['uuid_mof'] : '';
     } else {
         parent::__construct(0, array());
     }
 }
 /**
  * Returns a resourceValidation object instance from a DB id or from GetValidationByID function if exists.
  * Static function.
  *
  * @param integer $id the id of the saved object
  * @return resourceValidation the instance unserialized, false if not found.
  * @access public
  */
 static function getValidationInstance($id, $user = false)
 {
     if (!SensitiveIO::isPositiveInteger($id) && base64_decode($id) && $user) {
         //load validation form encoded ID (new validations system)
         $decodedID = explode('||', base64_decode($id));
         $module = CMS_modulesCatalog::getByCodename($decodedID[0]);
         $editions = $decodedID[1];
         $resourceID = $decodedID[2];
         if (isset($module) && isset($editions) && isset($resourceID)) {
             return $module->getValidationByID($resourceID, $user, $editions);
         }
     }
     $sql = "\n\t\t\tselect\n\t\t\t\tserializedObject_rv as data\n\t\t\tfrom\n\t\t\t\tresourceValidations\n\t\t\twhere\n\t\t\t\tid_rv='" . $id . "'\n\t\t";
     $q = new CMS_query($sql);
     if ($q->getNumRows()) {
         $instance = unserialize(stripslashes($q->getValue("data")));
         $instance->setID($id);
         return $instance;
     } else {
         parent::raiseError("Unknown id : " . $id);
         return false;
     }
 }
Пример #8
0
 /**
  * Constructor.
  * initializes the contactData if the id is given
  *
  * @param integer $id DB id
  * @return void
  * @access public
  */
 function __construct($id = 0)
 {
     if ($id) {
         if (SensitiveIO::isPositiveInteger($id)) {
             $sql = "\n\t\t\t\t\tselect\n\t\t\t\t\t\t*\n\t\t\t\t\tfrom\n\t\t\t\t\t\tcontactDatas\n\t\t\t\t\twhere\n\t\t\t\t\t\tid_cd='{$id}'\n\t\t\t\t";
             $q = new CMS_query($sql);
             if ($q->getNumRows()) {
                 $data = $q->getArray();
             } else {
                 $this->raiseError("Unknown DB ID : " . $id);
                 return;
             }
         } elseif (is_array($id)) {
             $data = $id;
         } else {
             $this->raiseError("Id is not a positive integer nor array");
             return;
         }
         $this->_id = $data["id_cd"];
         $this->_service = $data["service_cd"];
         $this->_jobTitle = $data["jobTitle_cd"];
         $this->_addressField1 = $data["addressField1_cd"];
         $this->_addressField2 = $data["addressField2_cd"];
         $this->_addressField3 = $data["addressField3_cd"];
         $this->_zip = $data["zip_cd"];
         $this->_city = $data["city_cd"];
         $this->_state = $data["state_cd"];
         $this->_country = $data["country_cd"];
         $this->_phone = $data["phone_cd"];
         $this->_cellphone = $data["cellphone_cd"];
         $this->_fax = $data["fax_cd"];
         $this->_email = $data["email_cd"];
         $this->_company = isset($data["company_cd"]) ? $data["company_cd"] : '';
         $this->_gender = isset($data["gender_cd"]) ? $data["gender_cd"] : '';
     }
 }
Пример #9
0
 /**
  * Does the row participates to one or more client spaces ?
  *
  * @return boolean true if it's the case
  * @access public
  */
 function hasClientSpaces()
 {
     $sql = "\n\t\t\tselect\n\t\t\t\t1\n\t\t\tfrom\n\t\t\t\tmod_standard_clientSpaces_edited\n\t\t\twhere\n\t\t\t\ttype_cs = '" . $this->_id . "'\n\t\t";
     $q = new CMS_query($sql);
     if ($q->getNumRows() > 0) {
         return true;
     }
     $sql = "\n\t\t\tselect\n\t\t\t\t1\n\t\t\tfrom\n\t\t\t\tmod_standard_clientSpaces_public\n\t\t\twhere\n\t\t\t\ttype_cs = '" . $this->_id . "'\n\t\t";
     $q = new CMS_query($sql);
     return $q->getNumRows() > 0 ? true : false;
 }
Пример #10
0
 /**
  * Get all the sub-aliases of a given alias which contain the given page in tree
  *
  * @param CMS_resource_cms_aliases $parent The parent of the sub-aliases to get or 0 to get first level or false to get all aliases recursively
  * @param boolean $returnObject function return array of id (default) or array of CMS_resource_cms_aliases
  * @return array
  * @access public
  * @static
  */
 static function getAllByPage($parent, $pageId, $returnObject = false)
 {
     if (io::isPositiveInteger($parent)) {
         $id = $parent;
     } elseif (is_a($parent, "CMS_resource_cms_aliases")) {
         $id = $parent->getID();
     } elseif ($parent === false) {
         $id = null;
     } else {
         $id = 0;
     }
     $sql = "\n\t\t\tselect \n\t\t\t\tid_ma\n\t\t\tfrom\n\t\t\t\tmod_cms_aliases\n\t\t\twhere\n\t\t\t\tpage_ma='" . io::sanitizeSQLString($pageId) . "'";
     $q = new CMS_query($sql);
     if (!$q->getNumRows()) {
         return array();
     }
     $aliasesIds = array();
     while ($r = $q->getArray()) {
         $aliasesIds[$r['id_ma']] = $r['id_ma'];
         $alias = CMS_module_cms_aliases::getByID($r["id_ma"]);
         if ($alias) {
             $lineage = $alias->getAliasLineAge(true);
             foreach ($lineage as $anAlias) {
                 $aliasesIds[$anAlias->getID()] = $anAlias->getID();
             }
         }
     }
     $sql = "\n\t\t\tselect\n\t\t\t\tid_ma\n\t\t\tfrom\n\t\t\t\tmod_cms_aliases\n\t\t\t where \n\t\t\t \tid_ma in (" . implode(',', $aliasesIds) . ")";
     if ($id !== null) {
         $sql .= " and parent_ma=" . io::sanitizeSQLString($id);
     }
     $q = new CMS_query($sql);
     $result = array();
     while ($arr = $q->getArray()) {
         if ($returnObject) {
             $alias = CMS_module_cms_aliases::getByID($arr["id_ma"]);
             if ($alias && !$alias->hasError()) {
                 $result[strtolower($alias->getAlias()) . $alias->getID()] = $alias;
             }
         } else {
             $result[$arr["id_ma"]] = $arr["id_ma"];
         }
     }
     if ($returnObject) {
         ksort($result);
     }
     return $result;
 }
Пример #11
0
 /**
  * Get module categories usage
  *
  * @return boolean
  * @access public
  */
 function useCategories()
 {
     $sql = "\n\t\t\tselect\n\t\t\t\t1\n\t\t\tfrom\n\t\t\t\tmodulesCategories\n\t\t\twhere\n\t\t\t\tmodule_mca = '" . $this->_codename . "'\n\t\t\t\tand root_mca != '" . CMS_moduleCategory::LINEAGE_PARK_POSITION . "'\n\t\t";
     $q = new CMS_query($sql);
     return $q->getNumRows() ? true : false;
 }
Пример #12
0
 /**
  * Returns all categories IDs who has used by this type of object (ie : this field)
  *
  * @param mixed (boolean or array) $restrictToItemsIds, restrict results to given items ids. False to restrict to only used categories (default)
  * @access public
  * @return array(interger id => integer id) the object ids
  * @static
  */
 function getAllUsedCategoriesForField($restrictToItemsIds = false)
 {
     if (is_array($restrictToItemsIds) && (!$restrictToItemsIds || !implode($restrictToItemsIds, ', '))) {
         //restrict to no ids so return nothing
         return array();
     }
     //get field of categories for searched object type (assume it uses categories)
     $categoriesFields = CMS_poly_object_catalog::objectHasCategories(CMS_poly_object_catalog::getObjectIDForField($this->_field->getID()));
     $fieldsDefinitions = array();
     //bypass field categories rights if needed
     foreach ($categoriesFields as $key => $catFieldID) {
         if (!isset($fieldsDefinitions[$catFieldID]) || !is_object($fieldsDefinitions[$catFieldID])) {
             //get object fields definition
             $fieldsDefinitions = CMS_poly_object_catalog::getFieldsDefinition(CMS_poly_object_catalog::getObjectIDForField($this->_field->getID()));
         }
         /*if ($fieldsDefinitions[$catFieldID]->getParameter('bypassRights')) {
         			unset($categoriesFields[$key]);
         		}*/
     }
     if (!$categoriesFields) {
         return array();
     }
     //if this field is the only one which use categories
     if (sizeof($categoriesFields) == 1 && in_array($this->_field->getID(), $categoriesFields)) {
         if ($this->_public) {
             //check for publication dates
             $sql = "\n\t\t\t\t\tselect\n\t\t\t\t\t\tdistinct objectID\n\t\t\t\t\tfrom\n\t\t\t\t\t\tmod_subobject_integer_public,\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\tobjectFieldID = '0'\n\t\t\t\t\t\tand value = id_res\n\t\t\t\t\t\tand status_res=id_rs\n\t\t\t\t\t\tand location_rs='" . RESOURCE_LOCATION_USERSPACE . "'\n\t\t\t\t\t\tand publication_rs='" . RESOURCE_PUBLICATION_PUBLIC . "'\n\t\t\t\t\t\tand publicationDateStart_rs <= '" . date('Y-m-d') . "'\n\t\t\t\t\t\tand publicationDateStart_rs != '0000-00-00'\n\t\t\t\t\t\tand (publicationDateEnd_rs >= '" . date('Y-m-d') . "'\n\t\t\t\t\t\tor publicationDateEnd_rs = '0000-00-00')\n\t\t\t\t\t";
             if ($restrictToItemsIds) {
                 $sql .= " and objectID in (" . implode($restrictToItemsIds, ', ') . ")";
             } else {
                 $sql .= " and objectID in (select objectID from mod_subobject_integer_public where objectFieldID = '" . $this->_field->getID() . "')";
             }
             $q = new CMS_query($sql);
             $restrictToItemsIds = array();
             if ($q->getNumRows()) {
                 while ($arr = $q->getArray()) {
                     $restrictToItemsIds[] = $arr['objectID'];
                 }
             }
         }
         $table = $this->_public ? 'mod_subobject_integer_public' : 'mod_subobject_integer_edited';
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\tvalue\n\t\t\t\tfrom\n\t\t\t\t\t{$table}\n\t\t\t\twhere\n\t\t\t\t\tobjectFieldID = '" . $this->_field->getID() . "'\n\t\t\t";
         if ($restrictToItemsIds) {
             $sql .= " and objectID in (" . implode($restrictToItemsIds, ', ') . ")";
         }
         $q = new CMS_query($sql);
         $r = array();
         if ($q->getNumRows()) {
             while ($arr = $q->getArray()) {
                 //check for value because it can be null !
                 if ($arr['value']) {
                     $r[$arr['value']] = $arr['value'];
                 }
             }
         }
     } else {
         //if this field is not only one which use categories
         global $cms_user;
         if (APPLICATION_ENFORCES_ACCESS_CONTROL && !is_object($cms_user)) {
             $this->raiseError("Valid user missing");
             return false;
         }
         if (!is_object($cms_user)) {
             //TODO : ugly but missing time (need to redo the getAllCategoriesAsArray to accept no valid cms_user : append only in frontend without APPLICATION_ENFORCES_ACCESS_CONTROL. Medias module already doing something like this)
             $user = new CMS_profile_user(ROOT_PROFILEUSER_ID);
         } else {
             $user = $cms_user;
         }
         //get a list of all viewvable categories for current user
         $viewvableCats = array_keys(CMS_moduleCategories_catalog::getViewvableCategoriesForProfile($user, CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID()), true));
         //if no viewvable categories, user has no rights to view anything
         if (!$viewvableCats) {
             return array();
         }
         $table = $this->_public ? 'mod_subobject_integer_public' : 'mod_subobject_integer_edited';
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\tdistinct objectID\n\t\t\t\tfrom\n\t\t\t\t\t{$table}\n\t\t\t\twhere\n\t\t\t\t\tobjectFieldID in (" . @implode(',', $categoriesFields) . ")\n\t\t\t\t\tand value in (" . @implode(',', $viewvableCats) . ")\n\t\t\t\t\t";
         if ($restrictToItemsIds) {
             $sql .= " and objectID in (" . implode($restrictToItemsIds, ', ') . ")";
         }
         $q = new CMS_query($sql);
         $r = array();
         if ($q->getNumRows()) {
             while ($arr = $q->getArray()) {
                 //check for value because it can be null !
                 if ($arr['objectID']) {
                     $r[$arr['objectID']] = $arr['objectID'];
                 }
             }
         }
         if (!$r) {
             return array();
         }
         //add previously found IDs to where clause
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\tdistinct value\n\t\t\t\tfrom\n\t\t\t\t\t{$table}\n\t\t\t\twhere\n\t\t\t\t\tobjectFieldID = '" . $this->_field->getID() . "'\n\t\t\t\t\tand objectID in(" . @implode(',', $r) . ")\n\t\t\t";
         $q = new CMS_query($sql);
         $r = array();
         if ($q->getNumRows()) {
             while ($arr = $q->getArray()) {
                 //check for value because it can be null !
                 if ($arr['value']) {
                     $r[$arr['value']] = $arr['value'];
                 }
             }
         }
     }
     return $r;
 }
Пример #13
0
 /**
  * Gets the data in array mode.
  *
  * @param integer $pageID The page DB ID which contains the client space
  * @param integer $clientSpaceID The client space DB ID which contains the row
  * @param integer $rowID The row DB ID which contains the block
  * @param integer $location The location of the page
  * @param boolean $public The needed precision for USERSPACE location
  * @return array(mixed=>mixed) The data indexed by data type (value, file, alt_tag, ...), or false on failure (table not found)
  * @access public
  */
 function getRawData($pageID, $clientSpaceID, $rowID, $location, $public)
 {
     parent::getRawData($pageID, $clientSpaceID, $rowID, $location, $public);
     $table = $this->_getDataTableName($location, $public);
     if (!$table) {
         $this->raiseError("Unknown table");
         return false;
     }
     $sql = "\n\t\t\tselect\n\t\t\t\t*\n\t\t\tfrom\n\t\t\t\t" . $table . "\n\t\t\twhere\n\t\t\t\tpage='" . $pageID . "'\n\t\t\t\tand clientSpaceID='" . $clientSpaceID . "'\n\t\t\t\tand rowID='" . $rowID . "'\n\t\t\t\tand blockID='" . $this->_tagID . "'\n\t\t";
     $q = new CMS_query($sql);
     if (!$q->hasError()) {
         if ($q->getNumRows()) {
             return $q->getArray();
         } else {
             return array("file" => "", "enlargedFile" => "", "label" => "", "externalLink" => "");
         }
     } else {
         return false;
     }
 }
Пример #14
0
 /**
  * activates the script function.
  *
  * @return void
  * @access public
  */
 function activate()
 {
     parent::activate();
     if ($_SERVER['argv']['1'] == '-s' && SensitiveIO::isPositiveInteger($_SERVER['argv']['2'])) {
         // SUB-SCRIPT : Processes one script task
         @ini_set('max_execution_time', SUB_SCRIPT_TIME_OUT);
         //set max execution time for sub script
         @set_time_limit(SUB_SCRIPT_TIME_OUT);
         //set the PHP timeout for sub script
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\t*\n\t\t\t\tfrom\n\t\t\t\t\tregenerator\n\t\t\t\twhere\n\t\t\t\t\tid_reg = '" . $_SERVER['argv']['2'] . "'\n\t\t\t";
         $q = new CMS_query($sql);
         if ($q->getNumRows()) {
             $data = $q->getArray();
             //send script informations to process manager
             $this->_processManager->setParameters($data['module_reg'], $data['parameters_reg']);
             //instanciate script module
             $module = CMS_modulesCatalog::getByCodename($data['module_reg']);
             //then send script task to module (return task title by reference)
             $task = $module->scriptTask(unserialize($data['parameters_reg']));
             //delete the current script task
             $sql_delete = "\n\t\t\t\t\tdelete\n\t\t\t\t\tfrom\n\t\t\t\t\t\tregenerator\n\t\t\t\t\twhere\n\t\t\t\t\t\tid_reg='" . $data['id_reg'] . "'";
             $q = new CMS_query($sql_delete);
             if ($this->_debug) {
                 $this->raiseError($this->_processManager->getPIDFilePath() . " : task " . $_SERVER['argv']['2'] . " seems " . (!$task ? 'NOT ' : '') . "done !");
                 $this->raiseError($this->_processManager->getPIDFilePath() . " : PID file exists ? " . @file_exists($this->_processManager->getPIDFilePath()));
             }
             $fpath = $this->_processManager->getPIDFilePath() . '.ok';
             if (@touch($fpath) && @chmod($fpath, octdec(FILES_CHMOD))) {
                 $f = @fopen($fpath, 'a');
                 if (!@fwrite($f, 'Script OK')) {
                     $this->raiseError($this->_processManager->getPIDFilePath() . " : Can't write into file: " . $fpath);
                 }
                 @fclose($f);
             } else {
                 $this->raiseError($this->_processManager->getPIDFilePath() . " : Can't create file: " . $fpath);
             }
         }
     } else {
         // MASTER SCRIPT : Processes all sub-scripts
         @ini_set('max_execution_time', MASTER_SCRIPT_TIME_OUT);
         //set max execution time for master script
         @set_time_limit(MASTER_SCRIPT_TIME_OUT);
         //set the PHP timeout  for master script
         //max simultaneous scripts
         $maxScripts = $_SERVER['argv']['2'];
         $scriptsArray = array();
         //send script informations to process manager
         $this->_processManager->setParameters(processManager::MASTER_SCRIPT_NAME, '');
         //the sql script which selects one script task at a time
         $sql_select = "\n\t\t\t\tselect\n\t\t\t\t\t*\n\t\t\t\tfrom\n\t\t\t\t\tregenerator\n\t\t\t\tlimit\n\t\t\t\t\t" . $maxScripts . "\n\t\t\t";
         //and now, launch all sub-scripts until table is empty.
         while (true) {
             //get scripts
             $q = new CMS_query($sql_select);
             if ($q->getNumRows()) {
                 while (count($scriptsArray) < $maxScripts && ($data = $q->getArray())) {
                     // Launch sub-process
                     if (!APPLICATION_IS_WINDOWS) {
                         // On unix system
                         $sub_system = PATH_PACKAGES_FS . "/scripts/script.php -s " . $data["id_reg"] . " > /dev/null 2>&1 &";
                         if (!defined('PATH_PHP_CLI_UNIX') || !PATH_PHP_CLI_UNIX) {
                             CMS_patch::executeCommand("cd " . PATH_REALROOT_FS . "; php " . $sub_system, $error);
                             if ($error) {
                                 CMS_grandFather::raiseError('Error during execution of sub script command (cd ' . PATH_REALROOT_FS . '; php ' . $sub_system . '), please check your configuration : ' . $error);
                                 return false;
                             }
                         } else {
                             CMS_patch::executeCommand("cd " . PATH_REALROOT_FS . "; " . PATH_PHP_CLI_UNIX . " " . $sub_system, $error);
                             if ($error) {
                                 CMS_grandFather::raiseError('Error during execution of sub script command (cd ' . PATH_REALROOT_FS . '; ' . PATH_PHP_CLI_UNIX . ' ' . $sub_system . '), please check your configuration : ' . $error);
                                 return false;
                             }
                         }
                         $PIDfile = $this->_processManager->getTempPath() . "/" . SCRIPT_CODENAME . "_" . $data["id_reg"];
                         if ($this->_debug) {
                             $this->raiseError(processManager::MASTER_SCRIPT_NAME . " : Executes system(" . $sub_system . ")");
                         }
                         //sleep a little
                         @sleep(SLEEP_TIME);
                     } else {
                         // On windows system
                         //Create the BAT file
                         $command = '@echo off' . "\r\n" . '@start /B /BELOWNORMAL ' . realpath(PATH_PHP_CLI_WINDOWS) . ' ' . realpath(PATH_PACKAGES_FS . '\\scripts\\script.php') . ' -s ' . $data["id_reg"];
                         if (!@touch(realpath(PATH_WINDOWS_BIN_FS) . DIRECTORY_SEPARATOR . "sub_script.bat")) {
                             $this->raiseError(processManager::MASTER_SCRIPT_NAME . " : Create file error : sub_script.bat");
                         }
                         $replace = array('program files (x86)' => 'progra~2', 'program files' => 'progra~1', 'documents and settings' => 'docume~1');
                         $command = str_ireplace(array_keys($replace), $replace, $command);
                         $fh = fopen(realpath(PATH_WINDOWS_BIN_FS . DIRECTORY_SEPARATOR . "sub_script.bat"), "wb");
                         if (is_resource($fh)) {
                             if (!fwrite($fh, $command, io::strlen($command))) {
                                 CMS_grandFather::raiseError(processManager::MASTER_SCRIPT_NAME . " : Save file error : sub_script.bat");
                             }
                             fclose($fh);
                         }
                         $WshShell = new COM("WScript.Shell");
                         $oExec = $WshShell->Run(str_ireplace(array_keys($replace), $replace, realpath(PATH_WINDOWS_BIN_FS . '\\sub_script.bat')), 0, false);
                         $PIDfile = $this->_processManager->getTempPath() . DIRECTORY_SEPARATOR . SCRIPT_CODENAME . "_" . $data["id_reg"];
                         //sleep a little
                         @sleep(SLEEP_TIME);
                     }
                     if ($this->_debug) {
                         $this->raiseError(processManager::MASTER_SCRIPT_NAME . " : script : " . $data["id_reg"] . " - sub_system : " . $sub_system);
                     }
                     $scriptsArray[] = array("PID" => $PIDfile, "startTime" => CMS_stats::getmicrotime(), "scriptID" => $data["id_reg"], "scriptDatas" => $data);
                 }
             } else {
                 // no more scripts to process
                 // > delete all temporary files
                 // > end script
                 if (APPLICATION_IS_WINDOWS) {
                     $files = glob(realpath($this->_processManager->getTempPath()) . DIRECTORY_SEPARATOR . SCRIPT_CODENAME . '*.ok', GLOB_NOSORT);
                     if (is_array($files)) {
                         foreach ($files as $file) {
                             if (!CMS_file::deleteFile($file)) {
                                 $this->raiseError("Can't delete file " . $file);
                                 return false;
                             }
                         }
                     }
                 } else {
                     $tmpDir = dir($this->_processManager->getTempPath());
                     while (false !== ($file = $tmpDir->read())) {
                         if (io::strpos($file, SCRIPT_CODENAME) !== false) {
                             @unlink($this->_processManager->getTempPath() . '/' . $file);
                         }
                     }
                 }
                 break;
             }
             while (true) {
                 @sleep(SLEEP_TIME);
                 //wait a little to check sub_scripts
                 $break = false;
                 $timeStop = CMS_stats::getmicrotime();
                 if ($this->_debug) {
                     $this->raiseError(processManager::MASTER_SCRIPT_NAME . " Scripts in progress : " . sizeof($scriptsArray));
                 }
                 foreach ($scriptsArray as $nb => $aScript) {
                     if ($this->_debug) {
                         $this->raiseError(processManager::MASTER_SCRIPT_NAME . " PID : " . $aScript["PID"] . " - time : " . ($timeStop - $aScript["startTime"]));
                     }
                     $ok = '';
                     $ok = is_file($aScript["PID"] . '.ok');
                     if ($ok) {
                         //$break = true;
                         if ($this->_debug) {
                             $this->raiseError(processManager::MASTER_SCRIPT_NAME . " Script : " . $aScript["PID"] . " OK !");
                         }
                         unset($scriptsArray[$nb]);
                     } elseif ($timeStop - $aScript["startTime"] >= SUB_SCRIPT_TIME_OUT) {
                         if ($this->_debug) {
                             $this->raiseError(processManager::MASTER_SCRIPT_NAME . " : Script : " . $aScript["PID"] . " NOT OK !");
                         }
                         $this->raiseError(processManager::MASTER_SCRIPT_NAME . ' : Error on task : ' . $aScript["scriptID"] . ' ... skip it. Task parameters : ' . print_r($aScript['scriptDatas'], true));
                         //$break = true;
                         unset($scriptsArray[$nb]);
                         //delete the script in error from task list
                         $q_del = "\n\t\t\t\t\t\t\t\tdelete\n\t\t\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t\t\tregenerator\n\t\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\t\tid_reg='" . $aScript["scriptID"] . "'";
                         $q_del = new CMS_query($q_del);
                     }
                 }
                 if (!$scriptsArray) {
                     break;
                 }
             }
         }
     }
 }
Пример #15
0
 /**
  * Check that the base data is loaded (edited base data can't be loaded from DELETED or ARCHIVED locations)
  *
  * @param boolean $public Is it the public or edited base data we want ?
  * @return boolean true on success, false on failure (because users can't edit the data)
  * @access private
  */
 protected function _checkBaseData($public = false)
 {
     $var = $public ? "_publicBaseData" : "_editedBaseData";
     if (!$this->{$var}) {
         //can't have edited base data when page is in DELETED or ARCHIVED locations
         if (!$public && ($this->_status->getLocation() == RESOURCE_LOCATION_ARCHIVED || $this->_status->getLocation() == RESOURCE_LOCATION_DELETED)) {
             //$this->raiseError('Page '.$this->getID().' : Can\'t get edited base data from DELETED or ARCHIVED locations');
             return false;
         }
         $this->{$var} = array();
         $this->{$var}["title"] = '';
         $this->{$var}["linkTitle"] = '';
         $this->{$var}["keywords"] = '';
         $this->{$var}["description"] = '';
         $this->{$var}["reminderPeriodicity"] = '';
         $this->{$var}["reminderOnMessage"] = '';
         $this->{$var}["category"] = '';
         $this->{$var}["author"] = '';
         $this->{$var}["replyto"] = '';
         $this->{$var}["copyright"] = '';
         $this->{$var}["language"] = '';
         $this->{$var}["robots"] = '';
         $this->{$var}["pragma"] = '';
         $this->{$var}["refresh"] = '';
         $this->{$var}["refreshUrl"] = '';
         $this->{$var}["metas"] = '';
         $this->{$var}["codename"] = '';
         $this->{$var}["reminderOn"] = new CMS_date();
         $this->{$var}["redirect"] = new CMS_href();
         switch ($this->_status->getLocation()) {
             case RESOURCE_LOCATION_ARCHIVED:
                 $table = "pagesBaseData_archived";
                 break;
             case RESOURCE_LOCATION_DELETED:
                 $table = "pagesBaseData_deleted";
                 break;
             case RESOURCE_LOCATION_USERSPACE:
             default:
                 $table = $public ? "pagesBaseData_public" : "pagesBaseData_edited";
                 break;
         }
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\t*\n\t\t\t\tfrom\n\t\t\t\t\t" . $table . "\n\t\t\t\twhere\n\t\t\t\t\tpage_pbd='" . $this->_pageID . "'\n\t\t\t";
         $q = new CMS_query($sql);
         if ($q->getNumRows()) {
             $data = $q->getArray();
             $this->_baseDataID = $data["id_pbd"];
             $this->{$var}["title"] = $data["title_pbd"];
             $this->{$var}["linkTitle"] = $data["linkTitle_pbd"];
             $this->{$var}["keywords"] = $data["keywords_pbd"];
             $this->{$var}["description"] = $data["description_pbd"];
             $this->{$var}["reminderPeriodicity"] = $data["reminderPeriodicity_pbd"];
             $this->{$var}["reminderOn"]->setFromDBValue($data["reminderOn_pbd"]);
             $this->{$var}["reminderOnMessage"] = $data["reminderOnMessage_pbd"];
             $this->{$var}["category"] = $data["category_pbd"];
             $this->{$var}["author"] = $data["author_pbd"];
             $this->{$var}["replyto"] = $data["replyto_pbd"];
             $this->{$var}["copyright"] = $data["copyright_pbd"];
             $this->{$var}["language"] = $data["language_pbd"];
             $this->{$var}["robots"] = $data["robots_pbd"];
             $this->{$var}["pragma"] = $data["pragma_pbd"];
             $this->{$var}["refresh"] = $data["refresh_pbd"];
             $this->{$var}["refreshUrl"] = $data["refreshUrl_pbd"];
             $this->{$var}["metas"] = $data["metas_pbd"];
             $this->{$var}["redirect"] = new CMS_href($data["redirect_pbd"]);
             $this->{$var}["codename"] = $data["codename_pbd"];
         }
     }
     return true;
 }
Пример #16
0
 /**
  * Constructor.
  *
  * @return void
  * @access public
  */
 function __construct($id = 0, $user = false)
 {
     // Loads up CMS_log with Id from database or with DB array
     if ($id) {
         if (SensitiveIO::isPositiveInteger($id)) {
             $sql = "\n\t\t\t\t\tselect\n\t\t\t\t\t\t*\n\t\t\t\t\tfrom\n\t\t\t\t\t\tlog\n\t\t\t\t\twhere\n\t\t\t\t\t\tid_log='" . $id . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
             if ($q->getNumRows()) {
                 $this->_id = $id;
                 $data = $q->getArray();
             } else {
                 $this->raiseError("Unknown DB ID : " . $id);
                 return;
             }
         } elseif (is_array($id)) {
             $data = $id;
             $this->_id = $data['id_log'];
         } else {
             $this->raiseError("Id is not a positive integer nor array");
             return;
         }
         if (is_array($data) && $data) {
             if ($user === false) {
                 $this->_user = new CMS_profile_user($data["user_log"]);
             } else {
                 $this->_user = $user;
             }
             $this->_action = $data["action_log"];
             $date = new CMS_date();
             $date->setFromDBValue($data["datetime_log"]);
             $this->_datetime = $date;
             $this->_textData = $data["textData_log"];
             $this->_label = $data["label_log"];
             $this->_module = $data["module_log"];
             $this->_resource = $data["resource_log"];
             // Create resource objects and populate
             $this->_resourceStatusAfter = new CMS_resourceStatus();
             $this->_resourceStatusAfter->setDebug(false);
             $this->_resourceStatusAfter->setLog(false);
             $this->_resourceStatusAfter->setLocation($data["rsAfterLocation_log"]);
             $this->_resourceStatusAfter->setProposedFor($data["rsAfterProposedFor_log"]);
             $this->_resourceStatusAfter->setAllEditions($data["rsAfterEditions_log"]);
             $this->_resourceStatusAfter->setAllValidationsRefused($data["rsAfterValidationsRefused_log"]);
             $this->_resourceStatusAfter->setPublication($data["rsAfterPublication_log"]);
             //specific draft status
             if ($this->_action == CMS_log::LOG_ACTION_RESOURCE_EDIT_DRAFT) {
                 $this->_resourceStatusAfter->setDraft(true);
             }
         }
     } else {
         $this->_user = new CMS_profile_user();
         $this->_resourceStatusAfter = new CMS_resourceStatus();
         $this->_datetime = new CMS_date();
     }
 }
Пример #17
0
 /**
  * Constructor.
  * initializes the profile from the database if the id
  * is given
  *
  * @param integer $id if of profile 
  * @return void
  * @access public
  */
 function __construct($id = 0)
 {
     // Initiate Stack objects
     $this->_pageClearances = new CMS_stack();
     $this->_validationClearances = new CMS_stack();
     $this->_validationClearances->setValuesByAtom(1);
     $this->_moduleClearances = new CMS_stack();
     $this->_templateGroupsDenied = new CMS_stack();
     $this->_templateGroupsDenied->setValuesByAtom(1);
     // Assume 1 atom
     $this->_rowGroupsDenied = new CMS_stack();
     $this->_rowGroupsDenied->setValuesByAtom(1);
     // Assume 1 atom
     // Categories clearance only
     $this->_moduleCategoriesClearances = new CMS_moduleCategoriesClearances();
     if ($id) {
         if (SensitiveIO::isPositiveInteger($id)) {
             $this->_id = $id;
             $sql = "\n\t\t\t\t\tselect\n\t\t\t\t\t\t*\n\t\t\t\t\tfrom\n\t\t\t\t\t\tprofiles\n\t\t\t\t\twhere\n\t\t\t\t\t\tid_pr='{$id}'\n\t\t\t\t";
             $q = new CMS_query($sql);
             if ($q->getNumRows()) {
                 $data = $q->getArray();
                 // Get integer values
                 $this->_adminClearance = $data["administrationClearance_pr"];
                 // Categories clearance only
                 $this->_moduleCategoriesClearances = new CMS_moduleCategoriesClearances($this->_id);
                 //Get values Catch errors?
                 if (!$this->_pageClearances->setTextDefinition($data["pageClearancesStack_pr"]) || !$this->_validationClearances->setTextDefinition($data["validationClearancesStack_pr"]) || !$this->_moduleClearances->setTextDefinition($data["moduleClearancesStack_pr"]) || !$this->_templateGroupsDenied->setTextDefinition($data["templateGroupsDeniedStack_pr"]) || !$this->_rowGroupsDenied->setTextDefinition($data["rowGroupsDeniedStack_pr"])) {
                     $this->raiseError("Incorrect Stack formation in profile id " . $id);
                 }
             } else {
                 $this->raiseError("Unknown DB ID : " . $id);
             }
         } elseif (is_array($id)) {
             $data = $id;
             // Get integer values
             $this->_id = $data["id_pr"];
             $this->_adminClearance = $data["administrationClearance_pr"];
             // Categories clearance only
             $this->_moduleCategoriesClearances = new CMS_moduleCategoriesClearances($this->_id);
             //Get values Catch errors?
             if (!$this->_pageClearances->setTextDefinition($data["pageClearancesStack_pr"]) || !$this->_validationClearances->setTextDefinition($data["validationClearancesStack_pr"]) || !$this->_moduleClearances->setTextDefinition($data["moduleClearancesStack_pr"]) || !$this->_templateGroupsDenied->setTextDefinition($data["templateGroupsDeniedStack_pr"]) || !$this->_rowGroupsDenied->setTextDefinition($data["rowGroupsDeniedStack_pr"])) {
                 $this->raiseError("Incorrect Stack formation in profile id " . $id);
             }
         } else {
             $this->raiseError("Id is not a positive integer nor array");
             return;
         }
     } else {
         //set default templates groups
         $this->_templateGroupsDenied = CMS_pageTemplatesCatalog::getAllGroups(true);
         //set default rows groups
         $this->_rowGroupsDenied = CMS_rowsCatalog::getAllGroups(true);
     }
     if ($this->hasAdminClearance(CLEARANCE_ADMINISTRATION_EDITVALIDATEALL)) {
         $this->_moduleCategoriesClearances->setAdminLevel(true);
     }
 }
Пример #18
0
 /**
  * Returns The instance of the website whose page is a root of, or false if page is not a website root
  * Static function.
  *
  * @param CMS_page|integer $root The supposed root page or root page ID
  * @return CMS_website the website whose page is a root, or false
  * @access public
  */
 static function getWebsiteFromRoot($root)
 {
     static $roots;
     if (is_object($root)) {
         $rootID = $root->getID();
     } elseif (sensitiveIO::isPositiveInteger($root)) {
         $rootID = $root;
     } else {
         CMS_grandFather::raiseError('Root must be instance of CMS_page or valid root ID');
         return false;
     }
     if (!isset($roots[$rootID])) {
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\tid_web\n\t\t\t\tfrom\n\t\t\t\t\twebsites\n\t\t\t\twhere\n\t\t\t\t\troot_web='" . $rootID . "'\n\t\t\t";
         $q = new CMS_query($sql);
         if ($q->getNumRows()) {
             $roots[$rootID] = CMS_websitesCatalog::getByID($q->getValue("id_web"));
         } else {
             $roots[$rootID] = false;
         }
     }
     return $roots[$rootID];
 }
Пример #19
0
 /**
  * Search messages
  * Static function.
  *
  * @param string module : module to search messages
  * @param string search : search message by value
  * @param array languagesOnly : limit search to given languages codes
  * @param array options : search options
  * @param string direction : search is ordered by results id. Specify order direction (asc or desc). Default : asc
  * @param integer start : search start offset
  * @param integer limit : search limit (default : 0 : unlimited)
  * @param integer resultsnb : return results count by reference
  * @return array(id => msg)
  * @access public
  */
 static function searchMessages($module, $search = '', $languagesOnly = array(), $options = array(), $direction = 'asc', $start = 0, $limit = 0, &$resultsnb)
 {
     $start = (int) $start;
     $limit = (int) $limit;
     $direction = in_array(io::strtolower($direction), array('asc', 'desc')) ? io::strtolower($direction) : 'asc';
     $emptyOnly = $idsOnly = false;
     if (is_array($options)) {
         $emptyOnly = isset($options['empty']) && $options['empty'] ? true : false;
         $idsOnly = isset($options['ids']) && is_array($options['ids']) ? $options['ids'] : false;
     }
     $keywordsWhere = $languagesWhere = $emptyWhere = $orderBy = $orderClause = $idsWhere = '';
     //get ids for which one message is missing
     if ($emptyOnly) {
         $qLanguages = new CMS_query("\n\t\t\t\tselect \n\t\t\t\t\tdistinct language_mes\n\t\t\t\tfrom \n\t\t\t\t\tmessages\n\t\t\t\twhere\n\t\t\t\t\tmodule_mes = '" . io::sanitizeSQLString($module) . "'\n\t\t\t");
         $qIds = new CMS_query("\n\t\t\t\tselect \n\t\t\t\t\tdistinct id_mes\n\t\t\t\tfrom \n\t\t\t\t\tmessages\n\t\t\t\twhere\n\t\t\t\t\tmodule_mes = '" . io::sanitizeSQLString($module) . "'\n\t\t\t");
         $allIds = $qIds->getAll(PDO::FETCH_COLUMN | PDO::FETCH_UNIQUE, 0);
         $missingIds = array();
         while ($language = $qLanguages->getValue('language_mes')) {
             $qLang = new CMS_query("\n\t\t\t\t\tselect \n\t\t\t\t\t\tdistinct id_mes\n\t\t\t\t\tfrom \n\t\t\t\t\t\tmessages\n\t\t\t\t\twhere\n\t\t\t\t\t\tmodule_mes = '" . io::sanitizeSQLString($module) . "'\n\t\t\t\t\t\tand language_mes='" . $language . "'\n\t\t\t\t\t\tand message_mes != ''\n\t\t\t\t");
             $ids = $qLang->getAll(PDO::FETCH_COLUMN | PDO::FETCH_UNIQUE, 0);
             $missingIds = array_merge($missingIds, array_diff($allIds, $ids));
         }
         if (!$missingIds) {
             $resultsnb = 0;
             return array();
         }
         $emptyWhere = ' and id_mes in (' . implode($missingIds, ',') . ')';
     }
     if ($idsOnly) {
         $idsWhere = ' and id_mes in (' . io::sanitizeSQLString(implode($idsOnly, ',')) . ')';
     }
     if ($search) {
         //clean user keywords (never trust user input, user is evil)
         $search = strtr($search, ",;", "  ");
         if (isset($options['phrase']) && $options['phrase']) {
             $search = str_replace(array('%', '_'), array('\\%', '\\_'), $search);
             if (htmlentities($search) != $search) {
                 $keywordsWhere .= " and (\n\t\t\t\t\t\tmessage_mes like '%" . sensitiveIO::sanitizeSQLString($search) . "%' or message_mes like '%" . sensitiveIO::sanitizeSQLString(htmlentities($search)) . "%'\n\t\t\t\t\t)";
             } else {
                 $keywordsWhere .= " and message_mes like '%" . sensitiveIO::sanitizeSQLString($search) . "%'";
             }
         } else {
             $words = array();
             $words = array_map("trim", array_unique(explode(" ", io::strtolower($search))));
             $cleanedWords = array();
             foreach ($words as $aWord) {
                 if ($aWord && $aWord != '' && io::strlen($aWord) >= 3) {
                     $aWord = str_replace(array('%', '_'), array('\\%', '\\_'), $aWord);
                     $cleanedWords[] = $aWord;
                 }
             }
             if (!$cleanedWords) {
                 //if no words after cleaning, return
                 return array();
             }
             foreach ($cleanedWords as $cleanedWord) {
                 $keywordsWhere .= $keywordsWhere ? " and " : '';
                 if (htmlentities($aWord) != $aWord) {
                     $keywordsWhere .= " (\n\t\t\t\t\t\t\tmessage_mes like '%" . sensitiveIO::sanitizeSQLString($cleanedWord) . "%' or message_mes like '%" . sensitiveIO::sanitizeSQLString(htmlentities($cleanedWord)) . "%'\n\t\t\t\t\t\t)";
                 } else {
                     $keywordsWhere .= " (\n\t\t\t\t\t\t\tmessage_mes like '%" . sensitiveIO::sanitizeSQLString($cleanedWord) . "%'\n\t\t\t\t\t\t)";
                 }
             }
             $keywordsWhere = ' and (' . $keywordsWhere . ')';
         }
     }
     if (is_array($languagesOnly) && $languagesOnly) {
         $languagesWhere = ' and language_mes in (\'' . implode($languagesOnly, '\',\'') . '\')';
     }
     $orderClause = "order by\n\t\t\tid_mes\n\t\t\t" . $direction;
     $sql = "\n\t\t\tselect\n\t\t\t\tid_mes as id\n\t\t\tfrom\n\t\t\t\tmessages\n\t\t\twhere \n\t\t\tmodule_mes = '" . io::sanitizeSQLString($module) . "'\n\t\t\t" . $keywordsWhere . "\n\t\t\t" . $languagesWhere . "\n\t\t\t" . $emptyWhere . "\n\t\t\t" . $idsWhere . "\n\t\t";
     $q = new CMS_query($sql);
     if (!$q->getNumRows()) {
         $resultsnb = 0;
         return array();
     }
     $messageIds = array();
     $messageIds = $q->getAll(PDO::FETCH_COLUMN | PDO::FETCH_UNIQUE, 0);
     $sql = "\n\t\t\tselect\n\t\t\t\tid_mes as id,\n\t\t\t\tmodule_mes as module,\n\t\t\t\tlanguage_mes as language,\n\t\t\t\tmessage_mes as message\n\t\t\tfrom\n\t\t\t\tmessages\n\t\t\twhere \n\t\t\t\tmodule_mes = '" . io::sanitizeSQLString($module) . "'\n\t\t\t\tand id_mes in (" . implode($messageIds, ',') . ")\n\t\t\t\t" . $orderClause . "\n\t\t";
     $q = new CMS_query($sql);
     if (!$q->getNumRows()) {
         $resultsnb = 0;
         return array();
     }
     $messageGroups = array();
     $messageGroups = $q->getAll(PDO::FETCH_GROUP | PDO::FETCH_ASSOC);
     $resultsnb = count($messageGroups);
     if ($limit) {
         $messageGroups = array_slice($messageGroups, $start, $limit, true);
     }
     $messages = array();
     foreach ($messageGroups as $key => $messageGroup) {
         $messages[$key]['id'] = $key;
         foreach ($messageGroup as $message) {
             $messages[$key][$message['language']] = $message['message'];
         }
     }
     return $messages;
 }
Пример #20
0
 /**
  * check if scripts are currently running
  *
  * @return boolean
  * @access public
  */
 function hasRunningScript()
 {
     //check the table
     $sql = "\n\t        select\n\t        \t1\n\t        from\n\t        \tscriptsStatuses\n\t        where\n\t        \tmodule_ss = '" . self::MASTER_SCRIPT_NAME . "'\n\t        ";
     $q = new CMS_query($sql);
     return $q->getNumRows() ? true : false;
 }
Пример #21
0
 /**
  * Constructor
  * 
  * @access public
  * @param integer $id
  * @return void 
  */
 function __construct($id = 0, $formID = false)
 {
     if ($id) {
         if (!SensitiveIO::isPositiveInteger($id)) {
             $this->raiseError("Id is not a positive integer");
             return;
         }
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\t*\n\t\t\t\tfrom\n\t\t\t\t\tmod_cms_forms_fields\n\t\t\t\twhere\n\t\t\t\t\tid_fld='" . $id . "'\n\t\t\t";
         if (sensitiveIO::isPositiveInteger($formID)) {
             $sql .= " and form_fld='" . $formID . "' ";
         }
         $q = new CMS_query($sql);
         if ($q->getNumRows()) {
             $data = $q->getArray();
             $this->_fieldID = $id;
             if (SensitiveIO::isPositiveInteger($formID)) {
                 $this->_formID = $formID;
             }
             if (SensitiveIO::isPositiveInteger($data["form_fld"])) {
                 $this->_formID = $data["form_fld"];
             }
             $this->_label = $data["label_fld"];
             $this->_type = $data["type_fld"];
             $this->_options = unserialize($data["options_fld"]);
             $this->_name = $data["name_fld"];
             $this->_required = $data["required_fld"] ? true : false;
             $this->_active = $data["active_fld"] ? true : false;
             $this->_value = $data["defaultValue_fld"];
             $this->_dataValidation = $data["dataValidation_fld"];
             $this->_order = $data["order_fld"];
             $this->_params = unserialize($data["params_fld"]);
         } else {
             $this->raiseError("Unknown ID :" . $id);
             /*
             				if (SensitiveIO::isPositiveInteger($formID)) {
             					$this->_formID = $formID;
             				}
             				if (SensitiveIO::isPositiveInteger($id)) {
             					$this->_fieldID = $id;
             				}*/
         }
     } else {
         if (SensitiveIO::isPositiveInteger($formID)) {
             $this->_formID = $formID;
         }
     }
 }
Пример #22
0
 /**
  * Proceed to serach and returns the array of results, null if none 
  * found. All search options had been set yet.
  * 
  * @access public
  * @return array(CMS_resources_cms_news)
  */
 function search()
 {
     $items = array();
     if (!$this->_sql) {
         $this->_buildSQL();
     }
     $sql = str_replace('{{select}}', implode($this->_select, ','), $this->_sql);
     if ($this->_itemsPerPage > 0) {
         $sql .= "\n\t\t\tlimit\n\t\t\t\t" . $this->_page * $this->_itemsPerPage . ", " . $this->_itemsPerPage . "";
     }
     $q = new CMS_query($sql);
     if (!$q->getNumRows()) {
         return $items;
     }
     while ($data = $q->getArray()) {
         $obj = CMS_module_cms_forms::getResourceByID($data[0]);
         if (!$obj->hasError()) {
             $items[] = $obj;
         }
     }
     return $items;
 }
Пример #23
0
 /**
  * This form has records attached to it ?
  * 
  * @access public
  * @return boolean
  */
 function hasRecords()
 {
     $sql = "\n\t\t\tselect\n\t\t\t\t1\n\t\t\tfrom\n\t\t\t\tmod_cms_forms_fields,\n\t\t\t\tmod_cms_forms_records\n\t\t\twhere\n\t\t\t\tform_fld = '" . $this->getID() . "'\n\t\t\t\tand id_fld = field_rec\n\t\t";
     $q = new CMS_query($sql);
     return $q->getNumRows() ? true : false;
 }
 /**
  * Get all groups labels
  *
  * @return array(id => label) groups label
  * @access public
  * @static
  */
 static function getGroupsLabels()
 {
     $sql = "\n\t\t\tselect\n\t\t\t\tid_prg as id,\n\t\t\t\tlabel_prg as label\n\t\t\tfrom\n\t\t\t\tprofilesUsersGroups\n\t\t\torder by \n\t\t\t\tlabel_prg asc\n\t\t";
     $q = new CMS_query($sql);
     $groupsLabel = array();
     if ($q->getNumRows()) {
         while ($r = $q->getArray()) {
             $groupsLabel[$r['id']] = $r['label'];
         }
     }
     return $groupsLabel;
 }
Пример #25
0
 /**
  * is this template content in draft ?
  *
  * @return boolean
  * @access public
  */
 function isDraft()
 {
     if (!sensitiveIO::isPositiveInteger($this->getID())) {
         return false;
     }
     $sql = "select \n\t\t\t\t\t1\n\t\t\t\tfrom \n\t\t\t\t\tmod_standard_clientSpaces_edition \n\t\t\t\twhere \n\t\t\t\t\ttemplate_cs='" . $this->getID() . "'";
     $q = new CMS_query($sql);
     return $q->getNumRows(true) ? true : false;
 }
Пример #26
0
 /**
  * Initialize rows depending on location user space
  *
  * @param integer $location The location we want tag definition from
  * @param boolean $public The precision needed for USERSPACE location
  * @return string The table name
  * @access public
  */
 protected function _checkRows($location = RESOURCE_LOCATION_USERSPACE, $public = false)
 {
     if ($this->_templateID && $this->_tagID) {
         if (!SensitiveIO::isPositiveInteger($this->_templateID)) {
             $this->raiseError("id is not a positive integer");
             return;
         }
         $this->_rows = array();
         $table = $this->_getDataTableName($location, $public);
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\t*\n\t\t\t\tfrom\n\t\t\t\t\t" . $table . "\n\t\t\t\twhere\n\t\t\t\t\ttemplate_cs='" . SensitiveIO::sanitizeSQLString($this->_templateID) . "'\n\t\t\t\t\tand tagID_cs='" . SensitiveIO::sanitizeSQLString($this->_tagID) . "'\n\t\t\t\t\tand type_cs != 0\n\t\t\t\torder by \n\t\t\t\t\torder_cs asc\n\t\t\t";
         $q = new CMS_query($sql);
         if ($q->getNumRows()) {
             while ($data = $q->getArray()) {
                 $this->_rows[$data['order_cs']] = new CMS_row($data["type_cs"], $data["rowsDefinition_cs"]);
             }
         }
     }
 }
Пример #27
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;
 }
Пример #28
0
 /**
  * Is given module is a poly module ?
  *
  * @param string $codename the codename of the module to check
  * @return boolean true if yes, false otherwise
  * @access public
  */
 static function isPolymod($codename)
 {
     $sql = "select\n\t\t\t\t\t1\n\t\t\t\tfrom\n\t\t\t\t\tmodules\n\t\t\t\twhere\n\t\t\t\t\tcodename_mod='" . sensitiveIO::sanitizeSQLString($codename) . "'\n\t\t\t\t\tand isPolymod_mod='1'\n\t\t\t\t";
     $q = new CMS_query($sql);
     return $q->getNumRows() ? true : false;
 }
 /**
  * Check if item is deleted
  *
  * @param integer $itemID The item ID to check as deleted
  * @return boolean true if ite is deleted, false otherwise
  */
 function isDeletedItem($itemID)
 {
     static $deletedItems;
     if (!isset($deletedItems[$itemID])) {
         //set deleted status to item
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\t1\n\t\t\t\tfrom\n\t\t\t\t\tmod_object_polyobjects\n\t\t\t\twhere\n\t\t\t\t\tid_moo = '" . sensitiveIO::sanitizeSQLString($itemID) . "'\n\t\t\t\t\tand deleted_moo = '1'\n\t\t\t";
         $q = new CMS_query($sql);
         $deletedItems[$itemID] = $q->getNumRows() ? true : false;
     }
     return $deletedItems[$itemID];
 }
Пример #30
0
 /**
  * Gets the data in array mode.
  *
  * @param integer $pageID The page DB ID which contains the client space
  * @param integer $clientSpaceID The client space DB ID which contains the row
  * @param integer $rowID The row DB ID which contains the block
  * @param integer $location The location of the page
  * @param boolean $public The needed precision for USERSPACE location
  * @return array(mixed=>mixed) The data indexed by data type (value, file, alt_tag, ...), or false on failure (table not found)
  * @access public
  */
 function getRawData($pageID, $clientSpaceID, $rowID, $location, $public)
 {
     parent::getRawData($pageID, $clientSpaceID, $rowID, $location, $public);
     $table = $this->_getDataTableName($location, $public);
     if (!$table) {
         $this->raiseError("Unknown table");
         return false;
     }
     $sql = "\n\t\t\tselect\n\t\t\t\t*\n\t\t\tfrom\n\t\t\t\t" . $table . "\n\t\t\twhere\n\t\t\t\tpage='" . $pageID . "'\n\t\t\t\tand clientSpaceID='" . $clientSpaceID . "'\n\t\t\t\tand rowID='" . $rowID . "'\n\t\t\t\tand blockID='" . $this->_tagID . "'\n\t\t";
     $q = new CMS_query($sql);
     if (!$q->hasError()) {
         if ($q->getNumRows()) {
             $r = $q->getArray();
             $r['value'] = unserialize($r['value']);
             $this->_dbID = $r["id"];
             $this->_pageID = $r["page"];
             $this->_clientSpaceID = $r["clientSpaceID"];
             $this->_rowID = $r["rowID"];
             $this->_tagID = $r["blockID"];
             $this->_value = $r["value"];
             return $r;
         } else {
             return array("value" => array());
         }
     } else {
         return false;
     }
 }