/** * 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 mixed : the object values structure * @access public */ function getValue($name, $parameters = '') { global $cms_language; // @TODOV4 : Manage language into database ! $languages = array(); $languages['fr'] = array('January' => 'Janvier', 'February' => 'Février', 'March' => 'Mars', 'April' => 'Avril', 'May' => 'Mai', 'June' => 'Juin', 'July' => 'Juillet', 'August' => 'Août', 'September' => 'Septembre', 'October' => 'Octobre', 'November' => 'Novembre', 'December' => 'Décembre', 'Monday' => 'Lundi', 'Tuesday' => 'Mardi', 'Wednesday' => 'Mercredi', 'Thursday' => 'Jeudi', 'Friday' => 'Vendredi', 'Saturday' => 'Samedi', 'Sunday' => 'Dimanche', 'Jan' => 'Jan', 'Feb' => 'Fév', 'Mar' => 'Mar', 'Apr' => 'Avr', 'May' => 'Mai', 'Jun' => 'Jui', 'Jul' => 'Jui', 'Aug' => 'Aoû', 'Sep' => 'Sep', 'Oct' => 'Oct', 'Nov' => 'Nov', 'Dec' => 'Déc', 'Mon' => 'Lun', 'Tue' => 'Mar', 'Wed' => 'Mer', 'Thu' => 'Jeu', 'Fri' => 'Ven', 'Sat' => 'Sam', 'Sun' => 'Dim'); switch ($name) { case 'id': return (string) $this->_ID; break; case 'label': if ($parameters == 'js') { return sensitiveIO::sanitizeJSString($this->getLabel()); } else { return $this->getLabel(); } break; case 'objectname': return $this->getFieldLabel($cms_language); break; case 'objectdescription': return $this->getFieldDesc($cms_language); break; case 'objecttype': return $this->_objectID; break; case 'resource': if ($this->_objectResourceStatus == 1) { return parent::getID(); } return; break; case 'formatedDateStart': if ($this->_objectResourceStatus == 1) { $date = parent::getPublicationDateStart(); if (io::strtolower($parameters) == 'rss') { $date = date('r', $date->getTimeStamp()); } else { $date = date($parameters, $date->getTimeStamp()); if (is_object($cms_language) && isset($languages[$cms_language->getCode()])) { $date = str_replace(array_keys($languages[$cms_language->getCode()]), $languages[$cms_language->getCode()], $date); } } return io::htmlspecialchars($date); } break; case 'formatedDateEnd': if ($this->_objectResourceStatus == 1) { $date = parent::getPublicationDateEnd(); if (is_a($date, 'CMS_date')) { if (io::strtolower($parameters) == 'rss') { $date = date('r', $date->getTimeStamp()); } else { $date = date($parameters, $date->getTimeStamp()); if (is_object($cms_language) && isset($languages[$cms_language->getCode()])) { $date = str_replace(array_keys($languages[$cms_language->getCode()]), $languages[$cms_language->getCode()], $date); } } return io::htmlspecialchars($date); } } break; case 'dateStartNotNull': if ($this->_objectResourceStatus == 1) { $date = parent::getPublicationDateStart(); return !$date->isNull(); } break; case 'dateStartTimestamp': if ($this->_objectResourceStatus == 1) { $date = parent::getPublicationDateStart(); return $date->getTimestamp(); } break; case 'dateEndNotNull': if ($this->_objectResourceStatus == 1) { $date = parent::getPublicationDateEnd(); return !$date->isNull(); } break; case 'dateEndTimestamp': if ($this->_objectResourceStatus == 1) { $date = parent::getPublicationDateEnd(); return $date->getTimestamp(); } break; //field related values, may not exists ... //field related values, may not exists ... case 'fieldID': if (!is_a($this->_field, 'CMS_poly_object_field')) { $this->raiseError("Can't get 'fieldID' value for an object which is not a field of another object ..."); return ''; } return $this->_field->getID(); break; case 'description': if (!is_a($this->_field, 'CMS_poly_object_field')) { $this->raiseError("Can't get 'description' value for an object which is not a field of another object ..."); return ''; } return io::htmlspecialchars($this->_field->getFieldDescription($cms_language)); break; case 'required': if (!is_a($this->_field, 'CMS_poly_object_field')) { $this->raiseError("Can't get 'required' value for an object which is not a field of another object ..."); return false; } return $this->_field->getValue("required") ? true : false; break; case 'fieldname': if (!is_a($this->_field, 'CMS_poly_object_field')) { $this->raiseError("Can't get 'fieldname' value for an object which is not a field of another object ..."); return ''; } //get label of current field $fieldLabel = new CMS_object_i18nm($this->_field->getValue("labelID")); return $fieldLabel->getValue($cms_language->getCode()); break; default: $this->raiseError("Unknown value to get : " . $name); return false; break; } }
/** * Writes the page into persistence (MySQL for now), along with base data. * * @return boolean true on success, false on failure * @access public */ function writeToPersistence() { parent::writeToPersistence(); $isNew = $this->_pageID === NULL; // Inform modules of the page creation $modules = CMS_modulesCatalog::getAll('id'); foreach ($modules as $codename => $module) { if (method_exists($module, 'pagePreSave')) { $module->pagePreSave($this, $isNew); } } //save page data $sql_fields = "\n\t\t\tresource_pag='" . parent::getID() . "',\n\t\t\tremindedEditorsStack_pag='" . SensitiveIO::sanitizeSQLString($this->_remindedEditors->getTextDefinition()) . "',\n\t\t\tlastReminder_pag='" . $this->_lastReminder->getDBValue() . "',\n\t\t\ttemplate_pag='" . $this->_templateID . "',\n\t\t\tlastFileCreation_pag='" . $this->_lastFileCreation->getDBValue() . "',\n\t\t\turl_pag='" . SensitiveIO::sanitizeSQLString($this->_pageURL) . "',\n\t\t\tprotected_pag='" . ($this->_protected ? 1 : 0) . "',\n\t\t\thttps_pag='" . ($this->_https ? 1 : 0) . "'\n\t\t"; if ($this->_pageID) { $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tpages\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields . "\n\t\t\t\twhere\n\t\t\t\t\tid_pag='" . $this->_pageID . "'\n\t\t\t"; } else { $sql = "\n\t\t\t\tinsert into\n\t\t\t\t\tpages\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields; } $q = new CMS_query($sql); if ($q->hasError()) { return false; } elseif (!$this->_pageID) { $this->_pageID = $q->getLastInsertedID(); } //save base data if modified if ($this->_editedBaseData) { $sql_fields = "\n\t\t\t\tpage_pbd='" . $this->_pageID . "',\n\t\t\t\ttitle_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["title"]) . "',\n\t\t\t\tlinkTitle_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["linkTitle"]) . "',\n\t\t\t\tkeywords_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["keywords"]) . "',\n\t\t\t\tdescription_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["description"]) . "',\n\t\t\t\treminderPeriodicity_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["reminderPeriodicity"]) . "',\n\t\t\t\treminderOn_pbd='" . $this->_editedBaseData["reminderOn"]->getDBValue() . "',\n\t\t\t\treminderOnMessage_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["reminderOnMessage"]) . "',\n\t\t\t\tcategory_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["category"]) . "',\n\t\t\t\tauthor_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["author"]) . "',\n\t\t\t\treplyto_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["replyto"]) . "',\n\t\t\t\tcopyright_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["copyright"]) . "',\n\t\t\t\tlanguage_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["language"]) . "',\n\t\t\t\trobots_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["robots"]) . "',\n\t\t\t\tpragma_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["pragma"]) . "',\n\t\t\t\trefresh_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["refresh"]) . "',\n\t\t\t\tredirect_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["redirect"]->getTextDefinition()) . "',\n\t\t\t\trefreshUrl_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["refreshUrl"]) . "',\n\t\t\t\tmetas_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["metas"]) . "',\n\t\t\t\tcodename_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["codename"]) . "'\n\t\t\t"; if ($this->_baseDataID) { $sql = "\n\t\t\t\t\tupdate\n\t\t\t\t\t\tpagesBaseData_edited\n\t\t\t\t\tset\n\t\t\t\t\t\t" . $sql_fields . "\n\t\t\t\t\twhere\n\t\t\t\t\t\tid_pbd='" . $this->_baseDataID . "'\n\t\t\t\t"; } else { $sql = "\n\t\t\t\t\tinsert into\n\t\t\t\t\t\tpagesBaseData_edited\n\t\t\t\t\tset\n\t\t\t\t\t\t" . $sql_fields; } $q = new CMS_query($sql); if (!$q->hasError() && !$this->_baseDataID) { $this->_baseDataID = $q->getLastInsertedID(); } } // Inform modules of the page creation $modules = CMS_modulesCatalog::getAll('id'); foreach ($modules as $codename => $module) { if (method_exists($module, 'pagePostSave')) { $module->pagePostSave($this, $isNew); } } return true; }
/** * Writes the object data into persistence (MySQL for now), along with base data. * * @return boolean true on success, false on failure * @access public */ function writeToPersistence() { if ($this->_hasResource()) { //write parent parent::writeToPersistence(); } //save data $sql_fields = ""; $count = 0; foreach ($this->_tableData as $label => $aData) { $sql_fields .= $count ? "," : ''; $count++; switch ($aData[0]) { case 'integer': case 'positiveInteger': case 'email': if (is_null($this->_tableData[$label][1])) { $sql_fields .= " `" . $label . $this->_tableSufix . "`=NULL"; } else { $sql_fields .= " `" . $label . $this->_tableSufix . "`='" . SensitiveIO::sanitizeSQLString($this->_tableData[$label][1]) . "'"; } break; case 'string': case 'html': case 'image': case 'file': case 'internalLink': case 'externalLink': case 'boolean': case 'linkType': $sql_fields .= " `" . $label . $this->_tableSufix . "`='" . SensitiveIO::sanitizeSQLString($this->_tableData[$label][1]) . "'"; break; case 'date': $sql_fields .= " `" . $label . $this->_tableSufix . "`='" . $this->_tableData[$label][1]->getDBValue() . "'"; break; case 'resource': $sql_fields .= " `" . $label . $this->_tableSufix . "`='" . parent::getID() . "'"; break; case 'order': /* * ici il manque un truc pour pouvoir attribuer automatiquement les nouveaux ordres (lors de la création d'un objet) * pb : savoir à quoi il se rapporte (clause where dans les fonctions associées aux ordre) * solution ? lier ça direct dans la definition de la table (tableau _tableData ou autre variable) avantages, inconvénients ??? à voir */ $sql_fields .= " `" . $label . $this->_tableSufix . "`='" . $this->_tableData[$label][1] . "'"; break; default: if (class_exists($aData[0])) { if (method_exists($this->_tableData[$label][1], "getID")) { $sql_fields .= " `" . $label . $this->_tableSufix . "`='" . $this->_tableData[$label][1]->getID() . "'"; } elseif (method_exists($this->_tableData[$label][1], "getTextDefinition")) { $sql_fields .= " `" . $label . $this->_tableSufix . "`='" . SensitiveIO::sanitizeSQLString($this->_tableData[$label][1]->getTextDefinition()) . "'"; } else { $this->raiseError("Unknown save method for object " . $aData[0]); return false; } } else { $sql_fields .= " `" . $label . $this->_tableSufix . "`='" . SensitiveIO::sanitizeSQLString($this->_tableData[$label][1]) . "'"; } break; } } $from = $this->_hasResource() ? $this->_tableName . '_edited' : $this->_tableName; if ($this->_ID) { $sql = "\n\t\t\t\tupdate\n\t\t\t\t\t" . $from . "\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields . "\n\t\t\t\twhere\n\t\t\t\t\t" . $this->_idName . $this->_tableSufix . "='" . $this->_ID . "'\n\t\t\t"; } else { $sql = "\n\t\t\t\tinsert into\n\t\t\t\t\t" . $from . "\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields; } //pr($sql); $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Database write error"); return false; } elseif (!$this->_ID) { $this->_ID = $q->getLastInsertedID(); } return true; }