コード例 #1
0
 /**
  * This method validates unique URL.
  *
  * @param string $data
  * @param object $contentObjectAttribute
  * @return boolean
  */
 public static function validateUniqueURLHTTPInput($data, $contentObjectAttribute)
 {
     $ini = eZINI::instance('uniquedatatypes.ini');
     $uniqueURLINI = $ini->group('UniqueURLSettings');
     if (count($uniqueURLINI['AllowedSchemaList'])) {
         if (!eregi("^(" . implode('|', $uniqueURLINI['AllowedSchemaList']) . ")", $data)) {
             $contentObjectAttribute->setValidationError(ezpI18n::tr('extension/ezuniquedatatypes', 'Only URLs beginning with  "%schemas" are accepted!', '', array('%schemas' => implode('", "', $uniqueURLINI['AllowedSchemaList']))));
             return eZInputValidator::STATE_INVALID;
         }
     }
     $url = eZURL::urlByURL($data);
     if (is_object($url)) {
         $contentObjectID = $contentObjectAttribute->ContentObjectID;
         $contentClassAttributeID = $contentObjectAttribute->ContentClassAttributeID;
         $db = eZDB::instance();
         if ($uniqueURLINI['CurrentVersionOnly'] == 'true') {
             $query = "SELECT COUNT(*) AS row_counter\n\t\t\t\t\tFROM ezcontentobject co, ezcontentobject_attribute coa\n\t\t\t\t\tWHERE co.id = coa.contentobject_id\n\t\t\t\t\tAND co.current_version = coa.version\n\t\t\t\t\tAND coa.contentclassattribute_id = " . $db->escapeString($contentClassAttributeID) . "\n\t\t\t\t\tAND coa.contentobject_id <> " . $db->escapeString($contentObjectID) . "\n                    AND coa.data_int = " . $db->escapeString($url->ID);
         } else {
             $query = "SELECT COUNT(*) AS row_counter\n\t\t\t\t\tFROM ezcontentobject_attribute coa\n\t\t\t\t\tWHERE coa.contentclassattribute_id = " . $db->escapeString($contentClassAttributeID) . "\n\t\t\t\t\tAND coa.contentobject_id <> " . $db->escapeString($contentObjectID) . "\n                    AND coa.data_int = " . $db->escapeString($url->ID);
         }
         if (self::EZUNIQUEURL_DEBUG) {
             eZDebug::writeDebug('Query: ' . $query, 'eZUniqueURLType::validateUniqueURLHTTPInput');
         }
         $rows = $db->arrayQuery($query);
         $rowCount = (int) $rows[0]['row_counter'];
         if ($rowCount >= 1) {
             $contentObjectAttribute->setValidationError(ezpI18n::tr('extension/ezuniquedatatypes', 'Given URL already exists in another content object of this type!'));
             return eZInputValidator::STATE_INVALID;
         }
     }
     return eZInputValidator::STATE_ACCEPTED;
 }
コード例 #2
0
ファイル: ezxmltexttype.php プロジェクト: nlescure/ezpublish
 function unserializeContentObjectAttribute($package, $objectAttribute, $attributeNode)
 {
     /* For all links found in the XML, do the following:
      * Search for url specified in 'href' link attribute (in ezurl table).
      * If the url not found then create a new one.
      * Then associate the found (or created) URL with the object attribute by creating new url-object link.
      * After that, remove "href" attribute, add new "id" attribute.
      * This new 'id' will always refer to the existing url object.
      */
     $linkNodes = $attributeNode->getElementsByTagName('link');
     foreach ($linkNodes as $linkNode) {
         $href = $linkNode->getAttribute('href');
         if (!$href) {
             continue;
         }
         $urlObj = eZURL::urlByURL($href);
         if (!$urlObj) {
             $urlObj = eZURL::create($href);
             $urlObj->store();
         }
         $linkNode->removeAttribute('href');
         $linkNode->setAttribute('url_id', $urlObj->attribute('id'));
         $urlObjectLink = eZURLObjectLink::create($urlObj->attribute('id'), $objectAttribute->attribute('id'), $objectAttribute->attribute('version'));
         $urlObjectLink->store();
     }
     foreach ($attributeNode->childNodes as $childNode) {
         if ($childNode->nodeType == XML_ELEMENT_NODE) {
             $xmlString = $childNode->ownerDocument->saveXML($childNode);
             $objectAttribute->setAttribute('data_text', $xmlString);
             break;
         }
     }
 }