static function updateUrlObjectLinks($contentObjectAttribute, $urlIDArray)
 {
     $objectAttributeID = $contentObjectAttribute->attribute('id');
     $objectAttributeVersion = $contentObjectAttribute->attribute('version');
     foreach ($urlIDArray as $urlID) {
         $linkObjectLink = eZURLObjectLink::fetch($urlID, $objectAttributeID, $objectAttributeVersion);
         if ($linkObjectLink == null) {
             $linkObjectLink = eZURLObjectLink::create($urlID, $objectAttributeID, $objectAttributeVersion);
             $linkObjectLink->store();
         }
     }
 }
 /**
  * Almost identical with the one in extended class, just injects
  * call for uniqness validation method
  *
  * @param unknown_type $http
  * @param unknown_type $base
  * @param unknown_type $contentObjectAttribute
  * @return unknown
  */
 function validateObjectAttributeHTTPInput($http, $base, $contentObjectAttribute)
 {
     if ($http->hasPostVariable($base . "_ezurl_url_" . $contentObjectAttribute->attribute("id")) and $http->hasPostVariable($base . "_ezurl_text_" . $contentObjectAttribute->attribute("id"))) {
         $url = $http->PostVariable($base . "_ezurl_url_" . $contentObjectAttribute->attribute("id"));
         $text = $http->PostVariable($base . "_ezurl_text_" . $contentObjectAttribute->attribute("id"));
         if ($contentObjectAttribute->validateIsRequired()) {
             if ($url == "" or $text == "") {
                 $contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'Input required.'));
                 return eZInputValidator::STATE_INVALID;
             }
         }
         return self::validateUniqueURLHTTPInput($url, $contentObjectAttribute);
         // Remove all url-object links to this attribute.
         eZURLObjectLink::removeURLlinkList($contentObjectAttribute->attribute("id"), $contentObjectAttribute->attribute('version'));
     }
     return eZInputValidator::STATE_ACCEPTED;
 }
 /**
  * Search through valid ezxmltext occurrences, and fix missing url object links if
  * specified.
  *
  * @return void
  */
 public function processData()
 {
     while ($this->processedCount < $this->xmlTextContentObjectAttributeCount()) {
         $limit = array('offset' => $this->offset, 'length' => $this->fetchLimit);
         $xmlAttributeChunk = eZContentObjectAttribute::fetchListByClassID($this->xmlClassAttributeIds(), false, $limit, true, false);
         foreach ($xmlAttributeChunk as $xmlAttr) {
             $result = true;
             // If the current entry has been logged, we don't increment the running number
             // so that the entries can be displayed together on output.
             $currentEntryLogged = false;
             $currentId = $xmlAttr->attribute('id');
             $objectId = $xmlAttr->attribute('contentobject_id');
             $version = $xmlAttr->attribute('version');
             $languageCode = $xmlAttr->attribute('language_code');
             $label = "Attribute [id:{$currentId}] - [Object-id:{$objectId}] - [Version:{$version}] - [Language:{$languageCode}]";
             $xmlText = eZXMLTextType::rawXMLText($xmlAttr);
             if (empty($xmlText)) {
                 if ($this->verboseLevel > 0) {
                     $this->outputString("Empty XML-data", $label, $currentEntryLogged);
                     $currentEntryLogged = true;
                 }
                 $result = false;
                 continue;
             }
             $dom = new DOMDocument('1.0', 'utf-8');
             $success = $dom->loadXML($xmlText);
             if (!$success) {
                 if ($this->verboseLevel > 0) {
                     $this->outputString("XML not loaded correctly for attribute", $label, $currentEntryLogged);
                     $currentEntryLogged = true;
                 }
                 $result = false;
                 continue;
             }
             $linkNodes = $dom->getElementsByTagName('link');
             $urlIdArray = array();
             foreach ($linkNodes as $link) {
                 // We are looking for external 'http://'-style links, not the internal
                 // object or node links.
                 if ($link->hasAttribute('url_id')) {
                     $urlIdArray[] = $link->getAttribute('url_id');
                 }
             }
             if (count($urlIdArray) > 0) {
                 if ($this->verboseLevel > 0) {
                     $this->outputString("Found http-link elements in xml-block", $label, $currentEntryLogged);
                     $currentEntryLogged = true;
                 }
                 $urlIdArray = array_unique($urlIdArray);
                 foreach ($urlIdArray as $url) {
                     $linkObjectLink = eZURLObjectLink::fetch($url, $currentId, $version);
                     if ($linkObjectLink === null) {
                         $result = false;
                         $this->outputString("Missing url object link: [id:{$currentId}] - [version:{$version}] - [url:{$url}]", $label, $currentEntryLogged);
                         $currentEntryLogged = true;
                     }
                     $storedUrl = eZURL::url($url);
                     if ($storedUrl === false) {
                         $result = false;
                         $this->outputString("Missing URL, the referenced url does not exist, [url_id:{$url}]", $label, $currentEntryLogged);
                         $currentEntryLogged = true;
                     }
                 }
                 if ($this->doFix and $linkObjectLink === null and $storedUrl !== false) {
                     $this->outputString("Reconstructing ezurl-object-link", $label, $currentEntryLogged);
                     $currentEntryLogged = true;
                     eZSimplifiedXMLInput::updateUrlObjectLinks($xmlAttr, $urlIdArray);
                 }
             }
             $this->script->iterate($this->cli, $result);
             $label = null;
         }
         $this->processedCount += count($xmlAttributeChunk);
         $this->offset += $this->fetchLimit;
         unset($xmlAttributeChunk);
     }
 }
 function storeObjectAttribute($attribute)
 {
     $urlValue = $attribute->content();
     if (trim($urlValue) != '') {
         $oldURLID = $attribute->attribute('data_int');
         $urlID = eZURL::registerURL($urlValue);
         $attribute->setAttribute('data_int', $urlID);
         if ($oldURLID && $oldURLID != $urlID && !eZURLObjectLink::hasObjectLinkList($oldURLID)) {
             eZURL::removeByID($oldURLID);
         }
     } else {
         $attribute->setAttribute('data_int', 0);
     }
 }
Ejemplo n.º 5
0
    static function handleList( $parameters = array(), $asCount = false )
    {
        $parameters = array_merge( array( 'as_object' => true,
                                          'is_valid' => null,
                                          'offset' => false,
                                          'limit' => false,
                                          'only_published' => false ),
                                   $parameters );
        $asObject = $parameters['as_object'];
        $isValid = $parameters['is_valid'];
        $offset = $parameters['offset'];
        $limit = $parameters['limit'];
        $onlyPublished = $parameters['only_published'];
        $limitArray = null;
        if ( !$asCount and $offset !== false and $limit !== false )
            $limitArray = array( 'offset' => $offset,
                                 'length' => $limit );
        $conditions = array();
        if( $isValid === false ) $isValid = 0;
        if ( $isValid !== null )
        {
            $conditions['is_valid'] = $isValid;
        }
        if ( count( $conditions ) == 0 )
            $conditions = null;

        if ( $onlyPublished )  // Only fetch published urls
        {
            $conditionQuery = "";
            if ( $isValid !== null )
            {
                $isValid = (int) $isValid;
                $conditionQuery = " AND ezurl.is_valid=$isValid ";
            }
            $db = eZDB::instance();
            $cObjAttrVersionColumn = eZPersistentObject::getShortAttributeName( $db, eZURLObjectLink::definition(), 'contentobject_attribute_version' );

            if ( $asCount )
            {
                $urls = $db->arrayQuery( "SELECT count( DISTINCT ezurl.id ) AS count
                                            FROM
                                                 ezurl,
                                                 ezurl_object_link,
                                                 ezcontentobject_attribute,
                                                 ezcontentobject_version
                                            WHERE
                                                 ezurl.id                                     = ezurl_object_link.url_id
                                             AND ezurl_object_link.contentobject_attribute_id = ezcontentobject_attribute.id
                                             AND ezurl_object_link.$cObjAttrVersionColumn     = ezcontentobject_attribute.version
                                             AND ezcontentobject_attribute.contentobject_id   = ezcontentobject_version.contentobject_id
                                             AND ezcontentobject_attribute.version            = ezcontentobject_version.version
                                             AND ezcontentobject_version.status               = " . eZContentObjectVersion::STATUS_PUBLISHED . "
                                                 $conditionQuery" );
                return $urls[0]['count'];
            }
            else
            {
                $query = "SELECT DISTINCT ezurl.*
                            FROM
                                  ezurl,
                                  ezurl_object_link,
                                  ezcontentobject_attribute,
                                  ezcontentobject_version
                            WHERE
                                  ezurl.id                                     = ezurl_object_link.url_id
                              AND ezurl_object_link.contentobject_attribute_id = ezcontentobject_attribute.id
                              AND ezurl_object_link.$cObjAttrVersionColumn     = ezcontentobject_attribute.version
                              AND ezcontentobject_attribute.contentobject_id   = ezcontentobject_version.contentobject_id
                              AND ezcontentobject_attribute.version            = ezcontentobject_version.version
                              AND ezcontentobject_version.status               = " . eZContentObjectVersion::STATUS_PUBLISHED . "
                             $conditionQuery";

                if ( !$offset && !$limit )
                {
                    $urlArray = $db->arrayQuery( $query );
                }
                else
                {
                    $urlArray = $db->arrayQuery( $query, array( 'offset' => $offset,
                                                                 'limit'  => $limit ) );
                }
                if ( $asObject )
                {
                    $urls = array();
                    foreach ( $urlArray as $url )
                    {
                        $urls[] = new eZURL( $url );
                    }
                    return $urls;
                }
                else
                    $urls = $urlArray;
                return $urls;
            }
        }
        else
        {
            if ( $asCount )
            {
                $urls = eZPersistentObject::fetchObjectList( eZURL::definition(),
                                                             array(),
                                                             $conditions,
                                                             false,
                                                             null,
                                                             false,
                                                             false,
                                                             array( array( 'operation' => 'count( id )',
                                                                           'name' => 'count' ) ) );
                return $urls[0]['count'];
            }
            else
            {
                return eZPersistentObject::fetchObjectList( eZURL::definition(),
                                                            null, $conditions, null, $limitArray,
                                                            $asObject );
            }
        }
    }
Ejemplo n.º 6
0
 function deleteStoredObjectAttribute($contentObjectAttribute, $version = null)
 {
     $contentObjectAttributeID = $contentObjectAttribute->attribute("id");
     $db = eZDB::instance();
     /* First we remove the link between the keyword and the object
      * attribute to be removed */
     if ($version == null) {
         eZPersistentObject::removeObject(eZURLObjectLink::definition(), array('contentobject_attribute_id' => $contentObjectAttributeID));
     } else {
         eZPersistentObject::removeObject(eZURLObjectLink::definition(), array('contentobject_attribute_id' => $contentObjectAttributeID, 'contentobject_attribute_version' => $version));
     }
     /* Here we figure out which which URLs are not in use at all */
     if ($db->databaseName() == 'oracle') {
         $res = $db->arrayQuery("SELECT DISTINCT id\n                                     FROM ezurl, ezurl_object_link\n                                     WHERE ezurl.id = ezurl_object_link.url_id(+)\n                                         AND url_id IS NULL");
     } else {
         $res = $db->arrayQuery(" SELECT DISTINCT id\n                                     FROM ezurl LEFT JOIN ezurl_object_link ON (ezurl.id  = ezurl_object_link.url_id)\n                                     WHERE url_id IS NULL");
     }
     /* And if there are some, we delete them */
     if (count($res)) {
         $unusedUrlIDs = array();
         foreach ($res as $record) {
             $unusedUrlIDs[] = $record['id'];
         }
         $unusedUrlIDString = implode(', ', $unusedUrlIDs);
         $db->query("DELETE FROM ezurl WHERE id IN ({$unusedUrlIDString})");
     }
 }
Ejemplo n.º 7
0
 static function clearCacheForObjectLink($urlID)
 {
     $urlObjectLinkList = eZPersistentObject::fetchObjectList(eZURLObjectLink::definition(), null, array('url_id' => $urlID), null, null, true);
     foreach ($urlObjectLinkList as $urlObjectLink) {
         $objectAttributeID = $urlObjectLink->attribute('contentobject_attribute_id');
         $objectAttributeVersion = $urlObjectLink->attribute('contentobject_attribute_version');
         $objectAttribute = eZContentObjectAttribute::fetch($objectAttributeID, $objectAttributeVersion);
         if ($objectAttribute) {
             $objectID = $objectAttribute->attribute('contentobject_id');
             $objectVersion = $objectAttribute->attribute('version');
             eZContentCacheManager::clearContentCacheIfNeeded($objectID, $objectVersion);
         }
     }
 }
Ejemplo n.º 8
0
}
$link = $url->attribute('url');
if (preg_match("/^(http:)/i", $link) or preg_match("/^(ftp:)/i", $link) or preg_match("/^(https:)/i", $link) or preg_match("/^(file:)/i", $link) or preg_match("/^(mailto:)/i", $link)) {
    // No changes
} else {
    $domain = getenv('HTTP_HOST');
    $protocol = eZSys::serverProtocol();
    $preFix = $protocol . "://" . $domain;
    $preFix .= eZSys::wwwDir();
    $link = preg_replace("/^\\//e", "", $link);
    $link = $preFix . "/" . $link;
}
$viewParameters = array('offset' => $offset, 'limit' => $limit);
$http = eZHTTPTool::instance();
$objectList = eZURLObjectLink::fetchObjectVersionList($urlID, $viewParameters);
$urlViewCount = eZURLObjectLink::fetchObjectVersionCount($urlID);
if ($Module->isCurrentAction('EditObject')) {
    if ($http->hasPostVariable('ObjectList')) {
        $versionID = $http->postVariable('ObjectList');
        $version = eZContentObjectVersion::fetch($versionID);
        $contentObjectID = $version->attribute('contentobject_id');
        $versionNr = $version->attribute('version');
        $Module->redirect('content', 'edit', array($contentObjectID, $versionNr));
    }
}
$tpl = eZTemplate::factory();
$tpl->setVariable('Module', $Module);
$tpl->setVariable('url_object', $url);
$tpl->setVariable('full_url', $link);
$tpl->setVariable('object_list', $objectList);
$tpl->setVariable('view_parameters', $viewParameters);
Ejemplo n.º 9
0
if (is_numeric($urlID)) {
    $url = eZURL::fetch($urlID);
    if (!$url) {
        return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
    }
} else {
    return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
}
$http = eZHTTPTool::instance();
if ($Module->isCurrentAction('Cancel')) {
    $Module->redirectToView('list');
    return;
}
if ($Module->isCurrentAction('Store')) {
    if ($http->hasPostVariable('link')) {
        $link = $http->postVariable('link');
        $url->setAttribute('url', $link);
        $url->store();
        eZURLObjectLink::clearCacheForObjectLink($urlID);
    }
    $Module->redirectToView('list');
    return;
}
$Module->setTitle("Edit link " . $url->attribute("id"));
// Template handling
$tpl = eZTemplate::factory();
$tpl->setVariable("Module", $Module);
$tpl->setVariable("url", $url);
$Result = array();
$Result['content'] = $tpl->fetch("design:url/edit.tpl");
$Result['path'] = array(array('url' => '/url/edit/', 'text' => ezpI18n::tr('kernel/url', 'URL edit')));