/**
  * 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;
 }
 /**
  * @group ezurl
  */
 public function testFetchByUrl()
 {
     $url = 'http://ez.no/ezpublish';
     $urlObj = eZURL::create($url);
     $urlObj->store();
     $urlObj2 = eZURL::fetchByUrl($url);
     self::assertInstanceOf('eZURL', $urlObj2);
 }
 function fetchListCount($isValid, $onlyPublished)
 {
     $parameters = array('is_valid' => $isValid, 'only_published' => $onlyPublished);
     $listCount = eZURL::fetchListCount($parameters);
     if ($listCount === null) {
         $result = array('error' => array('error_type' => 'kernel', 'error_code' => eZError::KERNEL_NOT_FOUND));
     } else {
         $result = array('result' => $listCount);
     }
     return $result;
 }
Esempio n. 4
0
 /**
  * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize
  * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize
  * @return array
  */
 public static function getAttributeContent( eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute )
 {
     $url = eZURL::fetch( $contentObjectAttribute->attribute( 'data_int' ) );
     return array(
         'content' => array(
             'url' => ( $url instanceof eZURL ) ? $url->attribute( 'url' ) : null,
             'text' => $contentObjectAttribute->attribute( 'data_text' ),
         ),
         'has_rendered_content' => false,
         'rendered' => null,
     );
 }
 function publishHandlerObject($element, &$params)
 {
     $ret = null;
     $objectID = $element->getAttribute('id');
     // protection from self-embedding
     if ($objectID == $this->contentObjectID) {
         $this->isInputValid = false;
         $this->Messages[] = ezpI18n::tr('kernel/classes/datatypes', 'Object %1 can not be embeded to itself.', false, array($objectID));
         return $ret;
     }
     if (!in_array($objectID, $this->relatedObjectIDArray)) {
         $this->relatedObjectIDArray[] = $objectID;
     }
     // If there are any image object with links.
     $href = $element->getAttributeNS($this->Namespaces['image'], 'ezurl_href');
     //washing href. single and double quotes inside url replaced with their urlencoded form
     $href = str_replace(array('\'', '"'), array('%27', '%22'), $href);
     $urlID = $element->getAttributeNS($this->Namespaces['image'], 'ezurl_id');
     if ($href != null) {
         $urlID = eZURL::registerURL($href);
         $element->setAttributeNS($this->Namespaces['image'], 'image:ezurl_id', $urlID);
         $element->removeAttributeNS($this->Namespaces['image'], 'ezurl_href');
     }
     if ($urlID != null) {
         $this->urlIDArray[] = $urlID;
     }
     $this->convertCustomAttributes($element);
     return $ret;
 }
 function unserializeContentObjectAttribute($package, $objectAttribute, $attributeNode)
 {
     $urlNode = $attributeNode->getElementsByTagName('url')->item(0);
     if (is_object($urlNode)) {
         unset($url);
         $url = urldecode($urlNode->textContent);
         $urlID = eZURL::registerURL($url);
         if ($urlID) {
             $urlObject = eZURL::fetch($urlID);
             $urlObject->setAttribute('original_url_md5', $urlNode->getAttribute('original-url-md5'));
             $urlObject->setAttribute('is_valid', $urlNode->getAttribute('is-valid'));
             $urlObject->setAttribute('last_checked', $urlNode->getAttribute('last-checked'));
             $urlObject->setAttribute('created', time());
             $urlObject->setAttribute('modified', time());
             $urlObject->store();
             $objectAttribute->setAttribute('data_int', $urlID);
         }
     }
     $textNode = $attributeNode->getElementsByTagName('text')->item(0);
     if ($textNode) {
         $objectAttribute->setAttribute('data_text', $textNode->textContent);
     }
 }
Esempio n. 7
0
 /**
  * publishHandlerLink (Publish handler, pass 2 after schema validation)
  * Publish handler for link element, converts href to [object|node|link]_id.
  *
  * @param DOMElement $element
  * @param array $param parameters for xml element
  * @return null|array changes structure if it contains 'result' key
  */
 function publishHandlerLink($element, &$params)
 {
     $ret = null;
     $href = $element->getAttribute('href');
     if ($href) {
         $objectID = false;
         if (strpos($href, 'ezobject') === 0 && preg_match("@^ezobject://([0-9]+)/?(#.+)?@i", $href, $matches)) {
             $objectID = $matches[1];
             if (isset($matches[2])) {
                 $anchorName = substr($matches[2], 1);
             }
             $element->setAttribute('object_id', $objectID);
             if (!eZContentObject::exists($objectID)) {
                 $this->Messages[] = ezpI18n::tr('design/standard/ezoe/handler', 'Object %1 does not exist.', false, array($objectID));
             }
         } elseif (strpos($href, 'eznode') === 0 && preg_match("@^eznode://([^#]+)(#.+)?@i", $href, $matches)) {
             $nodePath = trim($matches[1], '/');
             if (isset($matches[2])) {
                 $anchorName = substr($matches[2], 1);
             }
             if (is_numeric($nodePath)) {
                 $nodeID = $nodePath;
                 $node = eZContentObjectTreeNode::fetch($nodeID);
                 if (!$node instanceof eZContentObjectTreeNode) {
                     $this->Messages[] = ezpI18n::tr('design/standard/ezoe/handler', 'Node %1 does not exist.', false, array($nodeID));
                 }
             } else {
                 $node = eZContentObjectTreeNode::fetchByURLPath($nodePath);
                 if (!$node instanceof eZContentObjectTreeNode) {
                     $this->Messages[] = ezpI18n::tr('design/standard/ezoe/handler', 'Node &apos;%1&apos; does not exist.', false, array($nodePath));
                 } else {
                     $nodeID = $node->attribute('node_id');
                 }
                 $element->setAttribute('show_path', 'true');
             }
             if (isset($nodeID) && $nodeID) {
                 $element->setAttribute('node_id', $nodeID);
             }
             if (isset($node) && $node instanceof eZContentObjectTreeNode) {
                 $objectID = $node->attribute('contentobject_id');
             }
         } elseif (strpos($href, '#') === 0) {
             $anchorName = substr($href, 1);
         } else {
             $temp = explode('#', $href);
             $url = $temp[0];
             if (isset($temp[1])) {
                 $anchorName = $temp[1];
             }
             if ($url) {
                 // Protection from XSS attack
                 if (preg_match("/^(java|vb)script:.*/i", $url)) {
                     $this->isInputValid = false;
                     $this->Messages[] = "Using scripts in links is not allowed, '{$url}' has been removed";
                     $element->removeAttribute('href');
                     return $ret;
                 }
                 // Check mail address validity following RFC 5322 and RFC 5321
                 if (preg_match("/^mailto:([^.][a-z0-9!#\$%&'*+-\\/=?`{|}~^]+@([a-z0-9.-]+))/i", $url, $mailAddr)) {
                     if (!eZMail::validate($mailAddr[1])) {
                         $this->isInputValid = false;
                         if ($this->errorLevel >= 0) {
                             $this->Messages[] = ezpI18n::tr('kernel/classes/datatypes/ezxmltext', "Invalid e-mail address: '%1'", false, array($mailAddr[1]));
                         }
                         $element->removeAttribute('href');
                         return $ret;
                     }
                 }
                 // Store urlID instead of href
                 $url = str_replace(array('&amp;', '%28', '%29'), array('&', '(', ')'), $url);
                 $urlID = eZURL::registerURL($url);
                 if ($urlID) {
                     if (!in_array($urlID, $this->urlIDArray)) {
                         $this->urlIDArray[] = $urlID;
                     }
                     $element->setAttribute('url_id', $urlID);
                 }
             }
         }
         if ($objectID && !in_array($objectID, $this->linkedObjectIDArray)) {
             $this->linkedObjectIDArray[] = $objectID;
         }
         if (isset($anchorName) && $anchorName) {
             $element->setAttribute('anchor_name', $anchorName);
         }
     }
     return $ret;
 }
Esempio n. 8
0
}
if ($Module->isCurrentAction('SetValid')) {
    $urlSelection = $Module->actionParameter('URLSelection');
    eZURL::setIsValid($urlSelection, true);
} else {
    if ($Module->isCurrentAction('SetInvalid')) {
        $urlSelection = $Module->actionParameter('URLSelection');
        eZURL::setIsValid($urlSelection, false);
    }
}
if ($ViewMode == 'all') {
    $listParameters = array('is_valid' => null, 'offset' => $offset, 'limit' => $limit, 'only_published' => true);
    $countParameters = array('only_published' => true);
} elseif ($ViewMode == 'valid') {
    $listParameters = array('is_valid' => true, 'offset' => $offset, 'limit' => $limit, 'only_published' => true);
    $countParameters = array('is_valid' => true, 'only_published' => true);
} elseif ($ViewMode == 'invalid') {
    $listParameters = array('is_valid' => false, 'offset' => $offset, 'limit' => $limit, 'only_published' => true);
    $countParameters = array('is_valid' => false, 'only_published' => true);
}
$list = eZURL::fetchList($listParameters);
$listCount = eZURL::fetchListCount($countParameters);
$viewParameters = array('offset' => $offset, 'limit' => $limit);
$tpl = eZTemplate::factory();
$tpl->setVariable('view_parameters', $viewParameters);
$tpl->setVariable('url_list', $list);
$tpl->setVariable('url_list_count', $listCount);
$tpl->setVariable('view_mode', $ViewMode);
$Result = array();
$Result['content'] = $tpl->fetch("design:url/list.tpl");
$Result['path'] = array(array('url' => false, 'text' => ezpI18n::tr('kernel/url', 'URL')), array('url' => false, 'text' => ezpI18n::tr('kernel/url', 'List')));
Esempio n. 9
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 );
            }
        }
    }
 static function handleInlineNode($child, $generator, $prevLineBreak = false)
 {
     $paragraphParameters = array();
     $imageArray = array();
     switch ($child->localName) {
         case "line":
             // @todo: (Alex) check why this is needed here and not after the next line
             if ($prevLineBreak) {
                 $paragraphParameters[] = array(eZOOGenerator::LINE, '');
             }
             // Todo: support inline tags
             $paragraphParameters[] = array(eZOOGenerator::TEXT, $child->textContent);
             foreach ($child->childNodes as $lineChild) {
                 if ($lineChild->localName == 'embed') {
                     // Only support objects of image class for now
                     $object = eZContentObject::fetch($lineChild->getAttribute("object_id"));
                     if ($object && $object->canRead()) {
                         $classIdentifier = $object->attribute("class_identifier");
                         // Todo: read class identifiers from configuration
                         if ($classIdentifier == "image") {
                             $imageSize = $lineChild->getAttribute('size');
                             if ($imageSize == "") {
                                 $imageSize = "large";
                             }
                             $imageAlignment = $lineChild->getAttribute('align');
                             if ($imageAlignment == "") {
                                 $imageAlignment = "center";
                             }
                             $dataMap = $object->dataMap();
                             $imageAttribute = $dataMap['image'];
                             $imageHandler = $imageAttribute->content();
                             $originalImage = $imageHandler->attribute('original');
                             $fileHandler = eZClusterFileHandler::instance($originalImage['url']);
                             $uniqueFile = $fileHandler->fetchUnique();
                             $displayImage = $imageHandler->attribute($imageSize);
                             $displayWidth = $displayImage['width'];
                             $displayHeight = $displayImage['height'];
                             $imageArray[] = array("FileName" => $uniqueFile, "Alignment" => $imageAlignment, "DisplayWidth" => $displayWidth, "DisplayHeight" => $displayHeight);
                         }
                     } else {
                         eZDebug::writeError("Image (object_id = " . $child->getAttribute('object_id') . " ) could not be used (does not exist or due to insufficient privileges)");
                     }
                 }
             }
             break;
             // text nodes
         // text nodes
         case "":
             $paragraphParameters[] = array(eZOOGenerator::TEXT, $child->textContent);
             break;
         case "link":
             $href = $child->getAttribute('href');
             if (!$href) {
                 $url_id = $child->getAttribute('url_id');
                 if ($url_id) {
                     $eZUrl = eZURL::fetch($url_id);
                     if (is_object($eZUrl)) {
                         $href = $eZUrl->attribute('url');
                     }
                 }
             }
             $paragraphParameters[] = array(eZOOGenerator::LINK, $href, $child->textContent);
             break;
         case "emphasize":
         case "strong":
             $style = $child->localName == 'strong' ? 'bold' : 'italic';
             $paragraphParameters[] = array(eZOOGenerator::STYLE_START, $style);
             foreach ($child->childNodes as $inlineNode) {
                 $return = self::handleInlineNode($inlineNode);
                 $paragraphParameters = array_merge($paragraphParameters, $return['paragraph_parameters']);
             }
             $paragraphParameters[] = array(eZOOGenerator::STYLE_STOP);
             break;
         case "literal":
             $literalContent = $child->textContent;
             $literalContentArray = explode("\n", $literalContent);
             foreach ($literalContentArray as $literalLine) {
                 $generator->addParagraph("Preformatted_20_Text", htmlspecialchars($literalLine));
             }
             break;
         case "custom":
             $customTagName = $child->getAttribute('name');
             // Check if the custom tag is inline
             $ini = eZINI::instance('content.ini');
             $isInlineTagList = $ini->variable('CustomTagSettings', 'IsInline');
             $isInline = array_key_exists($customTagName, $isInlineTagList) && $isInlineTagList[$customTagName];
             // Handle inline custom tags
             if ($isInline) {
                 $paragraphParameters[] = array(eZOOGenerator::STYLE_START, "eZCustominline_20_{$customTagName}");
                 $paragraphParameters[] = array(eZOOGenerator::TEXT, $child->textContent);
                 $paragraphParameters[] = array(eZOOGenerator::STYLE_STOP);
             } else {
                 $GLOBALS['CustomTagStyle'] = "eZCustom_20_{$customTagName}";
                 foreach ($child->childNodes as $customParagraph) {
                     // Alex 2008-06-03: changed $level (3rd argument) to $prevLineBreak
                     self::handleNode($customParagraph, $generator, $prevLineBreak);
                 }
                 $GLOBALS['CustomTagStyle'] = false;
             }
             break;
         case "ol":
         case "ul":
             $listType = $child->localName == "ol" ? "ordered" : "unordered";
             $generator->startList($listType);
             foreach ($child->childNodes as $listItem) {
                 foreach ($listItem->childNodes as $childNode) {
                     if ($childNode->nodeType == XML_TEXT_NODE) {
                         $generator->addParagraph($childNode->textContent);
                     } else {
                         // Alex 2008-06-03: changed $level (3rd argument) to $prevLineBreak
                         self::handleNode($childNode, $generator, $prevLineBreak);
                     }
                 }
                 $generator->nextListItem();
             }
             $generator->endList();
             break;
         case "table":
             $generator->startTable();
             $rows = 1;
             foreach ($child->childNodes as $row) {
                 foreach ($row->childNodes as $cell) {
                     // Set the correct col span
                     $colSpan = $cell->getAttribute("colspan");
                     if (is_numeric($colSpan)) {
                         $generator->setCurrentColSpan($colSpan);
                     }
                     // Check for table header
                     if ($cell->localName == 'th' and $rows == 1) {
                         $generator->setIsInsideTableHeading(true);
                     }
                     // If the cell is empty, create a dummy so the cell is properly exported
                     if (!$cell->hasChildNodes()) {
                         $dummy = $cell->ownerDocument->createElement("paragraph");
                         $cell->appendChild($dummy);
                         // Alex 2008-06-03: changed $level (3rd argument) to $prevLineBreak
                         eZOOConverter::handleNode($dummy, $generator, $prevLineBreak);
                     }
                     eZDebug::writeDebug($cell->ownerDocument->saveXML($cell), 'ezxmltext table cell');
                     foreach ($cell->childNodes as $cellNode) {
                         // Alex 2008-06-03: changed $level (3rd argument) to $prevLineBreak
                         self::handleNode($cellNode, $generator, $prevLineBreak);
                     }
                     $generator->nextCell();
                 }
                 $generator->nextRow();
                 ++$rows;
             }
             $generator->endTable();
             break;
         case 'object':
         case 'embed':
             $objectID = $child->localName == 'embed' ? $child->getAttribute("object_id") : $child->getAttribute("id");
             // Only support objects of image class for now
             $object = eZContentObject::fetch($objectID);
             if ($object && $object->canRead()) {
                 $classIdentifier = $object->attribute("class_identifier");
                 // Todo: read class identifiers from configuration
                 if ($classIdentifier == "image") {
                     $imageSize = $child->getAttribute('size');
                     $imageAlignment = $child->getAttribute('align');
                     $dataMap = $object->dataMap();
                     $imageAttribute = $dataMap['image'];
                     $imageHandler = $imageAttribute->content();
                     $originalImage = $imageHandler->attribute('original');
                     $fileHandler = eZClusterFileHandler::instance($originalImage['url']);
                     $uniqueFile = $fileHandler->fetchUnique();
                     $displayImage = $imageHandler->attribute($imageSize);
                     $displayWidth = $displayImage['width'];
                     $displayHeight = $displayImage['height'];
                     $imageArray[] = array("FileName" => $uniqueFile, "Alignment" => $imageAlignment, "DisplayWidth" => $displayWidth, "DisplayHeight" => $displayHeight);
                 }
             } else {
                 eZDebug::writeError("Image (object_id = " . $child->getAttribute('object_id') . " ) could not be used (does not exist or insufficient privileges)");
             }
             break;
         default:
             eZDebug::writeError("Unsupported node at this level" . $child->localName);
     }
     return array("paragraph_parameters" => $paragraphParameters, "image_array" => $imageArray);
 }
Esempio n. 11
0
        $translateResult = eZURLAliasML::translate($url);
        if (!$translateResult) {
            $isInternal = false;
            // Check if it is a valid internal link.
            foreach ($siteURLs as $siteURL) {
                $siteURL = preg_replace("/\\/\$/e", "", $siteURL);
                $fp = @fopen($siteURL . "/" . $url, "r");
                if (!$fp) {
                    // do nothing
                } else {
                    $isInternal = true;
                    fclose($fp);
                }
            }
            $translateResult = $isInternal;
        }
        if ($translateResult) {
            if (!$isValid) {
                eZURL::setIsValid($linkID, true);
            }
            $cli->output($cli->stylize('success', "valid"));
        } else {
            if ($isValid) {
                eZURL::setIsValid($linkID, false);
            }
            $cli->output($cli->stylize('warning', "invalid"));
        }
    }
    eZURL::setLastChecked($linkID);
}
$cli->output("All links have been checked!");
Esempio n. 12
0
<?php

/**
 * Vue gérant les redirections de liens référencés dans eZ Publish
 * Utile pour les liens sponsorisés, notamment pour éviter les problèmes de validation HTML
 * ou pour cacher les régies publicitaires
 * @copyright Copyright (C) 2011 - Metal France. All rights reserved
 * @author Jerome Vieilledent
 * @version 3.0
 * @package metalfrance
 * @subpackage mf
 */
$Module = $Params['Module'];
$Result = array();
$http = eZHTTPTool::instance();
$mfINI = eZINI::instance('metalfrance.ini');
$url = eZURL::url((int) $Params['LinkID']);
eZHTTPTool::redirect($url, array(), '302');
Esempio n. 13
0
 static function fetchLinkList($contentObjectAttributeID, $contentObjectAttributeVersion, $asObject = true)
 {
     $linkList = array();
     $urlObjectLinkList = self::fetchLinkObjectList($contentObjectAttributeID, $contentObjectAttributeVersion, $asObject);
     foreach ($urlObjectLinkList as $urlObjectLink) {
         if ($asObject) {
             $linkID = $urlObjectLink->attribute('url_id');
             $linkList[] = eZURL::fetch($linkID);
         } else {
             $linkID = $urlObjectLink['url_id'];
             $linkList[] = $linkID;
         }
     }
     return $linkList;
 }
Esempio n. 14
0
 function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters)
 {
     switch ($operatorName) {
         case $this->ININameHasVariable:
         case $this->ININame:
             if (count($operatorParameters) > 0) {
                 $iniGroup = $tpl->elementValue($operatorParameters[0], $rootNamespace, $currentNamespace);
                 if (count($operatorParameters) == 1) {
                     $tpl->error($operatorName, "Missing variable name parameter");
                     return;
                 }
                 $iniVariable = $tpl->elementValue($operatorParameters[1], $rootNamespace, $currentNamespace);
                 $iniName = isset($operatorParameters[2]) ? $tpl->elementValue($operatorParameters[2], $rootNamespace, $currentNamespace) : false;
                 $iniPath = isset($operatorParameters[3]) ? $tpl->elementValue($operatorParameters[3], $rootNamespace, $currentNamespace) : false;
                 // If we should check for existence of variable.
                 // You can use like:
                 //     ezini( <BlockName>, <SettingName>, <FileName>, <IniPath>, _use under template compiling mode_ , <Should We Check for existence: 'hasVariable' or true()> )
                 //     ezini_hasvariable( <BlockName>, <SettingName>, <FileName>, <IniPath>... )
                 if ($operatorName == $this->ININameHasVariable) {
                     $checkExistence = true;
                 } else {
                     $checkExistence = isset($operatorParameters[5]) ? ($tpl->elementValue($operatorParameters[5], $rootNamespace, $currentNamespace) === true or $tpl->elementValue($operatorParameters[5], $rootNamespace, $currentNamespace) == 'hasVariable') ? true : false : false;
                 }
                 if ($iniPath !== false) {
                     $ini = eZINI::instance($iniName, $iniPath, null, null, null, true);
                 } elseif ($iniName !== false) {
                     $ini = eZINI::instance($iniName);
                 } else {
                     $ini = eZINI::instance();
                 }
                 if ($ini->hasVariable($iniGroup, $iniVariable)) {
                     $operatorValue = !$checkExistence ? $ini->variable($iniGroup, $iniVariable) : true;
                 } else {
                     if ($checkExistence) {
                         $operatorValue = false;
                         return;
                     }
                     if ($iniPath !== false) {
                         // Return empty string instead of displaying error when using 'path' parameter
                         // and DirectAccess mode for ezini.
                         $operatorValue = '';
                     } else {
                         if ($iniName === false) {
                             $iniName = 'site.ini';
                         }
                         $tpl->error($operatorName, "!!!No such variable '{$iniVariable}' in group '{$iniGroup}' for {$iniName}");
                     }
                 }
                 return;
             } else {
                 $tpl->error($operatorName, "Missing group name parameter");
             }
             break;
         case $this->HTTPNameHasVariable:
         case $this->HTTPName:
             $http = eZHTTPTool::instance();
             if (count($operatorParameters) > 0) {
                 $httpType = eZURLOperator::HTTP_OPERATOR_TYPE_POST;
                 $httpName = $tpl->elementValue($operatorParameters[0], $rootNamespace, $currentNamespace);
                 if (count($operatorParameters) > 1) {
                     $httpTypeName = strtolower($tpl->elementValue($operatorParameters[1], $rootNamespace, $currentNamespace));
                     if ($httpTypeName == 'post') {
                         $httpType = eZURLOperator::HTTP_OPERATOR_TYPE_POST;
                     } else {
                         if ($httpTypeName == 'get') {
                             $httpType = eZURLOperator::HTTP_OPERATOR_TYPE_GET;
                         } else {
                             if ($httpTypeName == 'session') {
                                 $httpType = eZURLOperator::HTTP_OPERATOR_TYPE_SESSION;
                             } else {
                                 if ($httpTypeName == 'cookie') {
                                     $httpType = eZURLOperator::HTTP_OPERATOR_TYPE_COOKIE;
                                 } else {
                                     $tpl->warning($operatorName, "Unknown http type '{$httpTypeName}'");
                                 }
                             }
                         }
                     }
                 }
                 // If we should check for existence of http variable
                 // You can use like:
                 //     ezhttp( <Variable>, <Method: post, get, session>, <Should We Check for existence: 'hasVariable' or true()> )
                 //     ezhttp_hasvariable( <Variable>, <Method> )
                 if ($operatorName == $this->HTTPNameHasVariable) {
                     $checkExistence = true;
                 } else {
                     $checkExistence = isset($operatorParameters[2]) ? ($tpl->elementValue($operatorParameters[2], $rootNamespace, $currentNamespace) === true or $tpl->elementValue($operatorParameters[2], $rootNamespace, $currentNamespace) == 'hasVariable') ? true : false : false;
                 }
                 switch ($httpType) {
                     case eZURLOperator::HTTP_OPERATOR_TYPE_POST:
                         if ($http->hasPostVariable($httpName)) {
                             $operatorValue = !$checkExistence ? $http->postVariable($httpName) : true;
                         } else {
                             // If only check for existence - return false
                             if ($checkExistence) {
                                 $operatorValue = false;
                                 return;
                             }
                             $tpl->error($operatorName, "Unknown post variable '{$httpName}'");
                         }
                         break;
                     case eZURLOperator::HTTP_OPERATOR_TYPE_GET:
                         if ($http->hasGetVariable($httpName)) {
                             $operatorValue = !$checkExistence ? $http->getVariable($httpName) : true;
                         } else {
                             if ($checkExistence) {
                                 $operatorValue = false;
                                 return;
                             }
                             $tpl->error($operatorName, "Unknown get variable '{$httpName}'");
                         }
                         break;
                     case eZURLOperator::HTTP_OPERATOR_TYPE_SESSION:
                         if ($http->hasSessionVariable($httpName)) {
                             $operatorValue = !$checkExistence ? $http->sessionVariable($httpName) : true;
                         } else {
                             if ($checkExistence) {
                                 $operatorValue = false;
                                 return;
                             }
                             $tpl->error($operatorName, "Unknown session variable '{$httpName}'");
                         }
                         break;
                     case eZURLOperator::HTTP_OPERATOR_TYPE_COOKIE:
                         if (array_key_exists($httpName, $_COOKIE)) {
                             $operatorValue = !$checkExistence ? $_COOKIE[$httpName] : true;
                         } else {
                             if ($checkExistence) {
                                 $operatorValue = false;
                                 return;
                             }
                             $tpl->error($operatorName, "Unknown cookie variable '{$httpName}'");
                         }
                         break;
                 }
             } else {
                 $operatorValue = $http;
             }
             return;
             break;
         case $this->URLName:
             eZURI::transformURI($operatorValue, false, $namedParameters['server_url']);
             break;
         case $this->URLRootName:
             if (preg_match("#^[a-zA-Z0-9]+:#", $operatorValue) or substr($operatorValue, 0, 2) == '//') {
                 break;
             }
             if (strlen($operatorValue) > 0 and $operatorValue[0] != '/') {
                 $operatorValue = '/' . $operatorValue;
             }
             // Same as "ezurl" without "index.php" and the siteaccess name in the returned address.
             eZURI::transformURI($operatorValue, true, $namedParameters['server_url']);
             break;
         case $this->SysName:
             if (count($operatorParameters) == 0) {
                 $tpl->warning('eZURLOperator' . $operatorName, 'Requires attributename');
             } else {
                 $sysAttribute = $tpl->elementValue($operatorParameters[0], $rootNamespace, $currentNamespace);
                 if (!$this->Sys->hasAttribute($sysAttribute)) {
                     $tpl->warning('eZURLOperator' . $operatorName, "No such attribute '{$sysAttribute}' for eZSys");
                 } else {
                     $operatorValue = $this->Sys->attribute($sysAttribute);
                 }
             }
             return;
             break;
         case $this->ImageName:
             if (count($operatorParameters) == 2 && $tpl->elementValue($operatorParameters[1], $rootNamespace, $currentNamespace) == true && strlen($this->Sys->wwwDir()) == 0) {
                 $skipSlash = true;
             } else {
                 $skipSlash = false;
             }
             $operatorValue = $this->eZImage($tpl, $operatorValue, $operatorName, $skipSlash);
             break;
         case $this->ExtName:
             $urlMD5 = md5($operatorValue);
             $url = eZURL::urlByMD5($urlMD5);
             if ($url === false) {
                 eZURL::registerURL($operatorValue);
             } else {
                 $operatorValue = $url;
             }
             break;
         case $this->DesignName:
             $operatorValue = $this->eZDesign($tpl, $operatorValue, $operatorName);
             break;
     }
     $quote = "\"";
     $val = $namedParameters['quote_val'];
     if ($val == 'single') {
         $quote = "'";
     } else {
         if ($val == 'no') {
             $quote = false;
         }
     }
     $http = eZHTTPTool::instance();
     if (isset($http->UseFullUrl) and $http->UseFullUrl and strncasecmp($operatorValue, '/', 1) === 0) {
         $operatorValue = $http->createRedirectUrl($operatorValue, array('pre_url' => false));
     }
     if ($quote !== false) {
         $operatorValue = $quote . $operatorValue . $quote;
     }
 }
 function outputObject( $element, &$attributes, &$sectionLevel )
 {
     $ret = null;
     if ( isset( $attributes['image:ezurl_id'] ) )
     {
         $linkID = $attributes['image:ezurl_id'];
         if ( $linkID != null )
         {
             $href = eZURL::url( $linkID );
             $attributes['href'] = $href;
         }
     }
     return $ret;
 }
Esempio n. 16
0
            break;
        case '3':
            $limit = 50;
            break;
        default:
            $limit = 10;
            break;
    }
} else {
    $limit = 10;
}
$offset = $Params['Offset'];
if (!is_numeric($offset)) {
    $offset = 0;
}
$url = eZURL::fetch($urlID);
if (!$url) {
    return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
}
$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);
Esempio n. 17
0
/**
 * Imports a value to an attribute adapting it to the proper type.
 * Not written by me, downloaded from ez.no! Extended it only!
 * @param data The value (string/int/float).
 * @param contentObjectAttribute The attribute to modify.
 */
function importAttribute($data, &$contentObjectAttribute)
{
    $contentClassAttribute = $contentObjectAttribute->attribute('contentclass_attribute');
    $dataTypeString = $contentClassAttribute->attribute('data_type_string');
    ezDebug::writeDebug("Converting " . $data . " to expected " . $dataTypeString);
    switch ($dataTypeString) {
        case 'ezfloat':
        case 'ezprice':
            $contentObjectAttribute->setAttribute('data_float', $data);
            $contentObjectAttribute->store();
            break;
        case 'ezboolean':
        case 'ezdate':
        case 'ezdatetime':
        case 'ezinteger':
        case 'ezsubtreesubscription':
        case 'eztime':
            $contentObjectAttribute->setAttribute('data_int', $data);
            $contentObjectAttribute->store();
            break;
        case 'ezobjectrelation':
            // $data is contentobject_id to relate to
            //            $oldData = $contentObjectAttribute->attribute( 'data_int' );
            $contentObjectAttribute->setAttribute('data_int', $data);
            $contentObjectAttribute->store();
            $object = $contentObjectAttribute->object();
            $contentObjectVersion = $contentObjectAttribute->attribute('version');
            $contentClassAttributeID = $contentObjectAttribute->attribute('contentclassattribute_id');
            // Problem with translations if removing old relations ?!
            //            $object->removeContentObjectRelation( $oldData, $contentObjectVersion, $contentClassAttributeID, eZContentObject::RELATION_ATTRIBUTE );
            $object->addContentObjectRelation($data, $contentObjectVersion, $contentClassAttributeID, RELATION_ATTRIBUTE);
            break;
        case 'ezurl':
            $urlID = eZURL::registerURL($data);
            $contentObjectAttribute->setAttribute('data_int', $urlID);
            // Fall through to set data_text
        // Fall through to set data_text
        case 'ezemail':
        case 'ezisbn':
        case 'ezstring':
        case 'eztext':
            $contentObjectAttribute->setAttribute('data_text', $data);
            $contentObjectAttribute->store();
            break;
        case 'ezxmltext':
            /*            $parser = new eZXMLInputParser();
                    $document = $parser->process( $data );
                    $data = eZXMLTextType::domString( $document );
                    $contentObjectAttribute->fromString( $data );*/
            $contentObjectAttribute->setAttribute('data_text', $data);
            $contentObjectAttribute->store();
            break;
            //    case 'ezimage':
            //        $this->saveImage( $data, $contentObjectAttribute );
            //        break;
            //    case 'ezbinaryfile':
            //        $this->saveFile( $data, $contentObjectAttribute );
            //        break;
            //    case 'ezenum':
            //removed enum - function can be found at ez.no
            //        break;
        //    case 'ezimage':
        //        $this->saveImage( $data, $contentObjectAttribute );
        //        break;
        //    case 'ezbinaryfile':
        //        $this->saveFile( $data, $contentObjectAttribute );
        //        break;
        //    case 'ezenum':
        //removed enum - function can be found at ez.no
        //        break;
        case 'ezuser':
            // $data is assumed to be an associative array( login, password, email );
            $user = new eZUser($contentObjectAttribute->attribute('contentobject_id'));
            if (isset($data['login'])) {
                $user->setAttribute('login', $data['login']);
            }
            if (isset($data['email'])) {
                $user->setAttribute('email', $data['email']);
            }
            if (isset($data['password'])) {
                $hashType = eZUser::hashType() . '';
                $newHash = $user->createHash($data['login'], $data['password'], eZUser::site(), $hashType);
                $user->setAttribute('password_hash_type', $hashType);
                $user->setAttribute('password_hash', $newHash);
            }
            $user->store();
            break;
        default:
            die('Can not store ' . $data . ' as datatype: ' . $dataTypeString);
    }
}
 static function fetchLinkList( $contentObjectAttributeID, $contentObjectAttributeVersion, $asObject = true )
 {
     $linkList = array();
     $conditions = array( 'contentobject_attribute_id' => $contentObjectAttributeID );
     if ( $contentObjectAttributeVersion !== false )
         $conditions['contentobject_attribute_version'] = $contentObjectAttributeVersion;
     $urlObjectLinkList = eZPersistentObject::fetchObjectList( eZURLObjectLink::definition(),
                                                                null,
                                                                $conditions,
                                                                null,
                                                                null,
                                                                $asObject );
     foreach ( $urlObjectLinkList as $urlObjectLink )
     {
         if ( $asObject )
         {
             $linkID = $urlObjectLink->attribute( 'url_id' );
             $linkList[] = eZURL::fetch( $linkID );
         }
         else
         {
             $linkID = $urlObjectLink['url_id'];
             $linkList[] = $linkID;
         }
     }
     return $linkList;
 }
    /**
     * Bug in link rendering related to GET parameters (& double encoded to &amp;amp;)
     *
     * @link http://issues.ez.no/016668: links in ezxmltext double escapes.
     * @note Test depends on template output!!
     */
    public function testLinkEscape()
    {
        $url = '/index.php?c=6&kat=company';
        $urlID = eZURL::registerURL( $url );
        $XMLString = '<?xml version="1.0" encoding="utf-8"?>
<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/" xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/" xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"><paragraph xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/"><link url_id="' . $urlID . '">My link</link></paragraph></section>';

        $outputHandler = new eZXHTMLXMLOutput( $XMLString, false );
        $result = $outputHandler->outputText();

        $expected = '<p><a href="/index.php?c=6&amp;kat=company" target="_self">My link</a></p>';

        $this->assertEquals( $expected, $result );
    }
    function &inputTagXML( &$tag, $currentSectionLevel, $tdSectionLevel = null )
    {
        $output       = '';
        $tagName      = $tag instanceof DOMNode ? $tag->nodeName : '';
        $childTagText = '';

        // render children tags
        if ( $tag->hasChildNodes() )
        {
            $tagChildren = $tag->childNodes;
            foreach ( $tagChildren as $childTag )
            {
                $childTagText .= $this->inputTagXML( $childTag, $currentSectionLevel, $tdSectionLevel );
            }
        }
        switch ( $tagName )
        {
            case '#text' :
            {
                $tagContent = $tag->textContent;
                if ( !strlen( $tagContent ) )
                {
                    break;
                }

                $tagContent = htmlspecialchars( $tagContent );
                $tagContent = str_replace ( '&amp;nbsp;', '&nbsp;', $tagContent );

                if ( $this->allowMultipleSpaces )
                {
                    $tagContent = str_replace( '  ', ' &nbsp;', $tagContent );
                }
                else
                {
                    $tagContent = preg_replace( "/ {2,}/", ' ', $tagContent );
                }

                if ( $tagContent[0] === ' ' && !$tag->previousSibling )//- Fixed "first space in paragraph" issue (ezdhtml rev.12246)
                {
                    $tagContent[0] = ';';
                    $tagContent = '&nbsp' . $tagContent;
                }

                if ( $this->allowNumericEntities )
                    $tagContent = preg_replace( '/&amp;#([0-9]+);/', '&#\1;', $tagContent );

                $output .= $tagContent;

            }break;

            case 'embed' :
            case 'embed-inline' :
            {
                $view      = $tag->getAttribute( 'view' );
                $size      = $tag->getAttribute( 'size' );
                $alignment = $tag->getAttribute( 'align' );
                $objectID  = $tag->getAttribute( 'object_id' );
                $nodeID    = $tag->getAttribute( 'node_id' );
                $showPath  = $tag->getAttribute( 'show_path' );
                $htmlID    = $tag->getAttributeNS( 'http://ez.no/namespaces/ezpublish3/xhtml/', 'id' );
                $className = $tag->getAttribute( 'class' );
                $idString  = '';
                $tplSuffix = '';

                if ( !$size )
                {
                    $contentIni = eZINI::instance( 'content.ini' );
                    $size       = $contentIni->variable( 'ImageSettings', 'DefaultEmbedAlias' );
                }

                if ( !$view )
                {
                    $view = $tagName;
                }

                $objectAttr = '';
                $objectAttr .= ' alt="' . $size . '"';
                $objectAttr .= ' view="' . $view . '"';

                if ( $htmlID != '' )
                {
                    $objectAttr .= ' html_id="' . $htmlID . '"';
                }
                if ( $showPath === 'true' )
                {
                    $objectAttr .= ' show_path="true"';
                }

                if ( $tagName === 'embed-inline' )
                    $objectAttr .= ' inline="true"';
                else
                    $objectAttr .= ' inline="false"';

                $customAttributePart = self::getCustomAttrPart( $tag, $styleString );
                $object              = false;

                if ( is_numeric( $objectID ) )
                {
                    $object = eZContentObject::fetch( $objectID );
                    $idString = 'eZObject_' . $objectID;
                }
                elseif ( is_numeric( $nodeID ) )
                {
                    $node      = eZContentObjectTreeNode::fetch( $nodeID );
                    $object    = $node instanceof eZContentObjectTreeNode ? $node->object() : false;
                    $idString  = 'eZNode_' . $nodeID;
                    $tplSuffix = '_node';
                }

                if ( $object instanceof eZContentObject )
                {
                    $objectName = $object->attribute( 'name' );
                    $classIdentifier = $object->attribute( 'class_identifier' );
                    if ( !$object->attribute( 'can_read' ) ||
                         !$object->attribute( 'can_view_embed' ) )
                    {
                        $tplSuffix = '_denied';
                    }
                    else if ( $object->attribute( 'status' ) == eZContentObject::STATUS_ARCHIVED )
                    {
                        $className .= ' ezoeItemObjectInTrash';
                        if ( self::$showEmbedValidationErrors )
                        {
                            $oeini = eZINI::instance( 'ezoe.ini' );
                            if ( $oeini->variable('EditorSettings', 'ValidateEmbedObjects' ) === 'enabled' )
                                $className .= ' ezoeItemValidationError';
                        }
                    }
                }
                else
                {
                    $objectName = 'Unknown';
                    $classIdentifier = false;
                    $tplSuffix = '_denied';
                    $className .= ' ezoeItemObjectDeleted';
                    if ( self::$showEmbedValidationErrors )
                    {
                        $className .= ' ezoeItemValidationError';
                    }
                }

                $embedContentType = self::embedTagContentType( $classIdentifier );
                if ( $embedContentType === 'images' )
                {
                    $ini = eZINI::instance();
                    $URL = self::getServerURL();
                    $objectAttributes = $object->contentObjectAttributes();
                    $imageDatatypeArray = $ini->variable('ImageDataTypeSettings', 'AvailableImageDataTypes');
                    $imageWidth = 32;
                    $imageHeight = 32;
                    foreach ( $objectAttributes as $objectAttribute )
                    {
                        $classAttribute = $objectAttribute->contentClassAttribute();
                        $dataTypeString = $classAttribute->attribute( 'data_type_string' );
                        if ( in_array ( $dataTypeString, $imageDatatypeArray ) && $objectAttribute->hasContent() )
                        {
                            $content = $objectAttribute->content();
                            if ( $content == null )
                                continue;

                            if ( $content->hasAttribute( $size ) )
                            {
                                $imageAlias  = $content->imageAlias( $size );
                                $srcString   = $URL . '/' . $imageAlias['url'];
                                $imageWidth  = $imageAlias['width'];
                                $imageHeight = $imageAlias['height'];
                                break;
                            }
                            else
                            {
                                eZDebug::writeError( "Image alias does not exist: $size, missing from image.ini?",
                                    __METHOD__ );
                            }
                        }
                    }

                    if ( !isset( $srcString ) )
                    {
                        $srcString = self::getDesignFile('images/tango/mail-attachment32.png');
                    }

                    if ( $alignment === 'center' )
                    {
                        $objectAttr .= ' align="middle"';
                        $className .= ' ezoeAlignmiddle'; // align="middle" is not taken into account by browsers on img
                    }
                    else if ( $alignment )
                        $objectAttr .= ' align="' . $alignment . '"';

                    if ( $className != '' )
                        $objectAttr .= ' class="' . $className . '"';

                    $output .= '<img id="' . $idString . '" title="' . $objectName . '" src="' .
                               $srcString . '" width="' . $imageWidth . '" height="' . $imageHeight .
                               '" ' . $objectAttr . $customAttributePart . $styleString . ' />';
                }
                else if ( self::embedTagIsCompatibilityMode() )
                {
                    $srcString = self::getDesignFile('images/tango/mail-attachment32.png');
                    if ( $alignment === 'center' )
                        $objectAttr .= ' align="middle"';
                    else if ( $alignment )
                        $objectAttr .= ' align="' . $alignment . '"';

                    if ( $className != '' )
                        $objectAttr .= ' class="' . $className . '"';

                    $output .= '<img id="' . $idString . '" title="' . $objectName . '" src="' .
                               $srcString . '" width="32" height="32" ' . $objectAttr .
                               $customAttributePart . $styleString . ' />';
                }
                else
                {
                    if ( $alignment )
                        $objectAttr .= ' align="' . $alignment . '"';

                    if ( $className )
                        $objectAttr .= ' class="ezoeItemNonEditable ' . $className . ' ezoeItemContentType' .
                                       ucfirst( $embedContentType ) . '"';
                    else
                        $objectAttr .= ' class="ezoeItemNonEditable ezoeItemContentType' .
                                       ucfirst( $embedContentType ) . '"';

                    if ( $tagName === 'embed-inline' )
                        $htmlTagName = 'span';
                    else
                        $htmlTagName = 'div';

                    $objectParam = array( 'size' => $size, 'align' => $alignment, 'show_path' => $showPath );
                    if ( $htmlID ) $objectParam['id'] = $htmlID;

                    $res = eZTemplateDesignResource::instance();
                    $res->setKeys( array( array('classification', $className) ) );

                    if ( isset( $node ) )
                    {
                        $templateOutput = self::fetchTemplate( 'design:content/datatype/view/ezxmltags/' . $tagName . $tplSuffix . '.tpl', array(
                            'view' => $view,
                            'object' => $object,
                            'link_parameters' => array(),
                            'classification' => $className,
                            'object_parameters' => $objectParam,
                            'node' => $node,
                        ));
                    }
                    else
                    {
                        $templateOutput = self::fetchTemplate( 'design:content/datatype/view/ezxmltags/' . $tagName . $tplSuffix . '.tpl', array(
                            'view' => $view,
                            'object' => $object,
                            'link_parameters' => array(),
                            'classification' => $className,
                            'object_parameters' => $objectParam,
                        ));
                    }

                    $output .= '<' . $htmlTagName . ' id="' . $idString . '" title="' . $objectName . '"' .
                               $objectAttr . $customAttributePart . $styleString . '>' . $templateOutput .
                               '</' . $htmlTagName . '>';
                }
            }break;

            case 'custom' :
            {
                $name = $tag->getAttribute( 'name' );
                $align = $tag->getAttribute( 'align' );
                $customAttributePart = self::getCustomAttrPart( $tag, $styleString );
                $inline = self::customTagIsInline( $name );
                if ( $align )
                {
                    $customAttributePart .= ' align="' . $align . '"';
                }

                if ( isset( self::$nativeCustomTags[ $name ] ))
                {
                    if ( !$childTagText ) $childTagText = '&nbsp;';
                    $output .= '<' . self::$nativeCustomTags[ $name ] . $customAttributePart . $styleString .
                               '>' . $childTagText . '</' . self::$nativeCustomTags[ $name ] . '>';
                }
                else if ( $inline === true )
                {
                    if ( !$childTagText ) $childTagText = '&nbsp;';
                    $output .= '<span class="ezoeItemCustomTag ' . $name . '" type="custom"' .
                               $customAttributePart . $styleString . '>' . $childTagText . '</span>';
                }
                else if ( $inline )
                {
                    $imageUrl = self::getCustomAttribute( $tag, 'image_url' );
                    if ( $imageUrl === null || !$imageUrl )
                    {
                        $imageUrl = self::getDesignFile( $inline );
                        $customAttributePart .= ' width="22" height="22"';
                    }
                    $output .= '<img src="' . $imageUrl . '" class="ezoeItemCustomTag ' . $name .
                               '" type="custom"' . $customAttributePart . $styleString . ' />';
                }
                else if ( $tag->textContent === '' && !$tag->hasChildNodes() )
                {
                    // for empty custom tag, just put a paragraph with the name
                    // of the custom tag in to handle it in the rich text editor
                    $output .= '<div class="ezoeItemCustomTag ' . $name . '" type="custom"' .
                                    $customAttributePart . $styleString . '><p>' . $name . '</p></div>';
                }
                else
                {
                    $customTagContent = $this->inputSectionXML( $tag, $currentSectionLevel, $tdSectionLevel );
                    /*foreach ( $tag->childNodes as $tagChild )
                    {
                        $customTagContent .= $this->inputTdXML( $tagChild,
                                                                $currentSectionLevel,
                                                                $tdSectionLevel );
                    }*/
                    $output .= '<div class="ezoeItemCustomTag ' . $name . '" type="custom"' .
                               $customAttributePart . $styleString . '>' . $customTagContent . '</div>';
                }
            }break;

            case 'literal' :
            {
                $literalText = '';
                foreach ( $tagChildren as $childTag )
                {
                    $literalText .= $childTag->textContent;
                }
                $className = $tag->getAttribute( 'class' );

                $customAttributePart = self::getCustomAttrPart( $tag, $styleString );

                $literalText = htmlspecialchars( $literalText );
                $literalText = str_replace( "\n", '<br />', $literalText );

                if ( $className != '' )
                    $customAttributePart .= ' class="' . $className . '"';

                $output .= '<pre' . $customAttributePart . $styleString . '>' . $literalText . '</pre>';

            }break;

            case 'ul' :
            case 'ol' :
            {
                $listContent = '';

                $customAttributePart = self::getCustomAttrPart( $tag, $styleString );

                // find all list elements
                foreach ( $tag->childNodes as $listItemNode )
                {
                    if ( !$listItemNode instanceof DOMElement )
                    {
                        continue;// ignore whitespace
                    }

                    $LIcustomAttributePart = self::getCustomAttrPart( $listItemNode, $listItemStyleString );

                    $noParagraphs = self::childTagCount( $listItemNode ) <= 1;
                    $listItemContent = '';
                    foreach ( $listItemNode->childNodes as $itemChildNode )
                    {
                        $listSectionLevel = $currentSectionLevel;
                        if ( $itemChildNode instanceof DOMNode
                        && ( $itemChildNode->nodeName === 'section'
                          || $itemChildNode->nodeName === 'paragraph' ) )
                        {
                            $listItemContent .= $this->inputListXML( $itemChildNode,
                                                                     $currentSectionLevel,
                                                                     $listSectionLevel,
                                                                     $noParagraphs );
                        }
                        else
                        {
                            $listItemContent .= $this->inputTagXML( $itemChildNode,
                                                                    $currentSectionLevel,
                                                                    $tdSectionLevel );
                        }
                    }

                    $LIclassName = $listItemNode->getAttribute( 'class' );

                    if ( $LIclassName )
                        $LIcustomAttributePart .= ' class="' . $LIclassName . '"';

                    $listContent .= '<li' . $LIcustomAttributePart . $listItemStyleString . '>' .
                                    $listItemContent . '</li>';
                }
                $className = $tag->getAttribute( 'class' );
                if ( $className != '' )
                    $customAttributePart .= ' class="' . $className . '"';

                $output .= '<' . $tagName . $customAttributePart . $styleString . '>' . $listContent . '</' .
                           $tagName . '>';
            }break;

            case 'table' :
            {
                $tableRows = '';
                $border = $tag->getAttribute( 'border' );
                $width = $tag->getAttribute( 'width' );
                $align = $tag->getAttribute( 'align' );
                $tableClassName = $tag->getAttribute( 'class' );

                $customAttributePart = self::getCustomAttrPart( $tag, $styleString );

                // find all table rows
                foreach ( $tag->childNodes as $tableRow )
                {
                    if ( !$tableRow instanceof DOMElement )
                    {
                        continue; // ignore whitespace
                    }
                    $TRcustomAttributePart = self::getCustomAttrPart( $tableRow, $tableRowStyleString );
                    $TRclassName = $tableRow->getAttribute( 'class' );

                    $tableData = '';
                    foreach ( $tableRow->childNodes as $tableCell )
                    {
                        if ( !$tableCell instanceof DOMElement )
                        {
                            continue; // ignore whitespace
                        }

                        $TDcustomAttributePart = self::getCustomAttrPart( $tableCell, $tableCellStyleString );

                        $className = $tableCell->getAttribute( 'class' );
                        $cellAlign = $tableCell->getAttribute( 'align' );

                        $colspan = $tableCell->getAttributeNS( 'http://ez.no/namespaces/ezpublish3/xhtml/',
                                                               'colspan' );
                        $rowspan = $tableCell->getAttributeNS( 'http://ez.no/namespaces/ezpublish3/xhtml/',
                                                               'rowspan' );
                        $cellWidth = $tableCell->getAttributeNS( 'http://ez.no/namespaces/ezpublish3/xhtml/',
                                                                 'width' );
                        if ( $className != '' )
                        {
                            $TDcustomAttributePart .= ' class="' . $className . '"';
                        }
                        if ( $cellWidth != '' )
                        {
                            $TDcustomAttributePart .= ' width="' . $cellWidth . '"';
                        }
                        if ( $colspan && $colspan !== '1' )
                        {
                            $TDcustomAttributePart .= ' colspan="' . $colspan . '"';
                        }
                        if ( $rowspan && $rowspan !== '1' )
                        {
                            $TDcustomAttributePart .= ' rowspan="' . $rowspan . '"';
                        }
                        if ( $cellAlign )
                        {
                                $TDcustomAttributePart .= ' align="' . $cellAlign . '"';
                        }
                        $cellContent = '';
                        $tdSectionLevel = $currentSectionLevel;
                        foreach ( $tableCell->childNodes as $tableCellChildNode )
                        {
                            $cellContent .= $this->inputTdXML( $tableCellChildNode,
                                                               $currentSectionLevel,
                                                               $tdSectionLevel - $currentSectionLevel );
                        }
                        if ( $cellContent === '' )
                        {
                            // tinymce has some issues with empty content in some browsers
                            if ( self::browserSupportsDHTMLType() != 'Trident' )
                                $cellContent = '<p><br data-mce-bogus="1"/></p>';
                        }
                        if ( $tableCell->nodeName === 'th' )
                        {
                            $tableData .= '<th' . $TDcustomAttributePart . $tableCellStyleString . '>' .
                                          $cellContent . '</th>';
                        }
                        else
                        {
                            $tableData .= '<td' . $TDcustomAttributePart . $tableCellStyleString . '>' .
                                          $cellContent . '</td>';
                        }
                    }
                    if ( $TRclassName )
                        $TRcustomAttributePart .= ' class="' . $TRclassName . '"';

                    $tableRows .= '<tr' . $TRcustomAttributePart . $tableRowStyleString . '>' .
                                  $tableData . '</tr>';
                }
                //if ( self::browserSupportsDHTMLType() === 'Trident' )
                //{
                    $customAttributePart .= ' width="' . $width . '"';
                /*}
                else
                {
                    // if this is reenabled merge it with $styleString
                    $customAttributePart .= ' style="width:' . $width . ';"';
                }*/

                if ( $border !== '' && is_string( $border ) )
                {
                    if ( $border === '0%' )
                        $border = '0';// Strip % if 0 to make sure TinyMCE shows a dotted border

                    $customAttributePart .= ' border="' . $border . '"';
                }

                if ( $align )
                {
                    $customAttributePart .= ' align="' . $align . '"';
                }

                if ( $tableClassName )
                {
                    $customAttributePart .= ' class="' . $tableClassName . '"';
                }

                $output .= '<table' . $customAttributePart . $styleString . '><tbody>' . $tableRows .
                           '</tbody></table>';
            }break;

            // normal content tags
            case 'emphasize' :
            {
                $customAttributePart = self::getCustomAttrPart( $tag, $styleString );

                $className = $tag->getAttribute( 'class' );
                if ( $className )
                {
                    $customAttributePart .= ' class="' . $className . '"';
                }
                $output .= '<em' . $customAttributePart . $styleString . '>' . $childTagText  . '</em>';
            }break;

            case 'strong' :
            {
                $customAttributePart = self::getCustomAttrPart( $tag, $styleString );

                $className = $tag->getAttribute( 'class' );
                if ( $className  )
                {
                    $customAttributePart .= ' class="' . $className . '"';
                }
                $output .= '<strong' . $customAttributePart . $styleString . '>' . $childTagText  . '</strong>';
            }break;

            case 'line' :
            {
                $output .= $childTagText . '<br />';
            }break;

            case 'anchor' :
            {
                $name = $tag->getAttribute( 'name' );

                $customAttributePart = self::getCustomAttrPart( $tag, $styleString );

                $output .= '<a name="' . $name . '" class="mceItemAnchor"' . $customAttributePart .
                           $styleString . '></a>';
            }break;

            case 'link' :
            {
                $customAttributePart = self::getCustomAttrPart( $tag, $styleString );

                $linkID = $tag->getAttribute( 'url_id' );
                $target = $tag->getAttribute( 'target' );
                $className = $tag->getAttribute( 'class' );
                $viewName = $tag->getAttribute( 'view' );
                $objectID = $tag->getAttribute( 'object_id' );
                $nodeID = $tag->getAttribute( 'node_id' );
                $anchorName = $tag->getAttribute( 'anchor_name' );
                $showPath = $tag->getAttribute( 'show_path' );
                $htmlID = $tag->getAttributeNS( 'http://ez.no/namespaces/ezpublish3/xhtml/', 'id' );
                $htmlTitle = $tag->getAttributeNS( 'http://ez.no/namespaces/ezpublish3/xhtml/', 'title' );
                $attributes = array();

                if ( $objectID != null )
                {
                    $href = 'ezobject://' .$objectID;
                }
                elseif ( $nodeID != null )
                {
                    if ( $showPath === 'true' )
                    {
                        $node = eZContentObjectTreeNode::fetch( $nodeID );
                        $href = $node ?
                                'eznode://' . $node->attribute('path_identification_string') :
                                'eznode://' . $nodeID;
                    }
                    else
                    {
                        $href = 'eznode://' . $nodeID;
                    }
                }
                elseif ( $linkID != null )
                {
                    $href = eZURL::url( $linkID );
                }
                else
                {
                    $href = $tag->getAttribute( 'href' );
                }

                if ( $anchorName != null )
                {
                    $href .= '#' . $anchorName;
                }

                if ( $className != '' )
                {
                    $attributes[] = 'class="' . $className . '"';
                }

                if ( $viewName != '' )
                {
                    $attributes[] = 'view="' . $viewName . '"';
                }

                $attributes[] = 'href="' . $href . '"';
                // Also set mce_href for use by OE to make sure href attribute is not messed up by IE 6 / 7
                $attributes[] = 'data-mce-href="' . $href . '"';
                if ( $target != '' )
                {
                    $attributes[] = 'target="' . $target . '"';
                }
                if ( $htmlTitle != '' )
                {
                    $attributes[] = 'title="' . $htmlTitle . '"';
                }
                if ( $htmlID != '' )
                {
                   $attributes[] = 'id="' . $htmlID . '"';
                }

                $attributeText = '';
                if ( !empty( $attributes ) )
                {
                    $attributeText = ' ' .implode( ' ', $attributes );
                }
                $output .= '<a' . $attributeText . $customAttributePart . $styleString . '>' .
                           $childTagText . '</a>';
            }break;
            case 'tr' :
            case 'td' :
            case 'th' :
            case 'li' :
            case 'paragraph' :
            {
            }break;
            default :
            {

            }break;
        }
        return $output;
    }
Esempio n. 21
0
 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;
         }
     }
 }
 /**
  * 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);
     }
 }
 /**
  * Test scenario for issue #018211: URL datatype is not case sensitive
  *
  * @link http://issues.ez.no/18211
  * @group issue18211
  */
 public function testUrlCaseSensitivity()
 {
     $url = 'http://ez.no/EZPUBLISH';
     $urlId = eZURL::registerURL($url);
     $urlObject = eZURL::fetch($urlId);
     self::assertEquals($url, $urlObject->attribute('url'));
     unset($urlId, $urlObject);
     $url2 = 'http://ez.no/ezpublish';
     $url2Id = eZURL::registerURL($url2);
     $url2Object = eZURL::fetch($url2Id);
     self::assertEquals($url2, $url2Object->attribute('url'));
     self::assertEquals(md5($url2), $url2Object->attribute('original_url_md5'));
     unset($url2Id, $url2Object);
 }