/**
  * Code taken from content/urlalias module
  */
 static function addUrlALias($node, $aliasText, $languageId, $aliasRedirects = false, $parentIsRoot = false)
 {
     $infoCode = 'no-errors';
     $language = eZContentLanguage::fetch($languageId);
     if (!$language) {
         $infoCode = "error-invalid-language";
         $infoData['language'] = $languageCode;
     } else {
         $parentID = 0;
         $linkID = 0;
         $filter = new eZURLAliasQuery();
         $filter->actions = array('eznode:' . $node->attribute('node_id'));
         $filter->type = 'name';
         $filter->limit = false;
         $existingElements = $filter->fetchAll();
         // TODO: add error handling when $existingElements is empty
         if (count($existingElements) > 0) {
             $parentID = (int) $existingElements[0]->attribute('parent');
             $linkID = (int) $existingElements[0]->attribute('id');
         }
         if ($parentIsRoot) {
             $parentID = 0;
             // Start from the top
         }
         $mask = $language->attribute('id');
         $obj = $node->object();
         $alwaysMask = $obj->attribute('language_mask') & 1;
         $mask |= $alwaysMask;
         $origAliasText = $aliasText;
         $result = eZURLAliasML::storePath($aliasText, 'eznode:' . $node->attribute('node_id'), $language, $linkID, $alwaysMask, $parentID, true, false, false, $aliasRedirects);
         if ($result['status'] === eZURLAliasML::LINK_ALREADY_TAKEN) {
             $lastElements = eZURLAliasML::fetchByPath($result['path']);
             if (count($lastElements) > 0) {
                 $lastElement = $lastElements[0];
                 $infoCode = "feedback-alias-exists";
                 $infoData['new_alias'] = $aliasText;
                 $infoData['url'] = $lastElement->attribute('path');
                 $infoData['action_url'] = $lastElement->actionURL();
                 //$aliasText = $origAliasText;
             }
         } else {
             if ($result['status'] === true) {
                 $aliasText = $result['path'];
                 if (strcmp($aliasText, $origAliasText) != 0) {
                     $infoCode = "feedback-alias-cleanup";
                     $infoData['orig_alias'] = $origAliasText;
                     $infoData['new_alias'] = $aliasText;
                 } else {
                     $infoData['new_alias'] = $aliasText;
                 }
                 if ($infoCode == 'no-errors') {
                     $infoCode = "feedback-alias-created";
                 }
                 //$aliasText = false;
             }
         }
     }
     return array('infoCode' => $infoCode, 'infoData' => $infoData);
 }
 public static function fetchNamedByParentID($parentID, $name)
 {
     $filter = new eZURLAliasQuery();
     $filter->paren = $parentID;
     $filter->text = $name;
     $filter->limit = false;
     return $filter->fetchAll();
 }
Beispiel #3
0
                            } else {
                                $infoData['new_alias'] = $aliasText;
                            }
                            if ($infoCode == 'no-errors') {
                                $infoCode = "feedback-alias-created";
                            }
                            $aliasText = false;
                        }
                    }
                }
            }
        }
    }
}
// Fetch generated names of node
$filter = new eZURLAliasQuery();
$filter->actions = array('eznode:' . $node->attribute('node_id'));
$filter->type = 'name';
$filter->limit = false;
$elements = $filter->fetchAll();
// Fetch custom aliases for node
$limit = 25;
$filter->prepare();
// Reset SQLs from previous calls
$filter->actions = array('eznode:' . $node->attribute('node_id'));
$filter->type = 'alias';
$filter->offset = $Offset;
$filter->limit = $limit;
$count = $filter->count();
$aliasList = $filter->fetchAll();
$path = array();
Beispiel #4
0
            }
        }
    }
}
// User preferences
$limitList = array(array('id' => 1, 'value' => 10), array('id' => 2, 'value' => 25), array('id' => 3, 'value' => 50), array('id' => 4, 'value' => 100));
$limitID = eZPreferences::value('admin_urlalias_list_limit');
foreach ($limitList as $limitEntry) {
    $limitIDs[] = $limitEntry['id'];
    $limitValues[$limitEntry['id']] = $limitEntry['value'];
}
if (!in_array($limitID, $limitIDs)) {
    $limitID = 2;
}
// Fetch global custom aliases (excluding eznode)
$filter = new eZURLAliasQuery();
$filter->actionTypesEx = array('eznode', 'nop');
$filter->offset = $Offset;
$filter->limit = $limitValues[$limitID];
// Prime the internal data for the template, for PHP5 this is no longer needed since objects will not be copied anymore in the template code.
$count = $filter->count();
$aliasList = $filter->fetchAll();
$path = array();
$path[] = array('url' => false, 'text' => ezpI18n::tr('kernel/content/urlalias_global', 'Global URL aliases'));
$languages = eZContentLanguage::prioritizedLanguages();
$tpl->setVariable('filter', $filter);
$tpl->setVariable('languages', $languages);
$tpl->setVariable('info_code', $infoCode);
$tpl->setVariable('info_data', $infoData);
$tpl->setVariable('aliasSourceText', $aliasOutputText);
$tpl->setVariable('aliasDestinationText', $aliasOutputDestinationText);
    /**
     * Removes a translation from the current object
     *
     * @param int $languageID
     * @return bool
     */
    function removeTranslation( $languageID )
    {
        $language = eZContentLanguage::fetch( $languageID );

        if ( !$language )
        {
            return false;
        }

        // check permissions for editing
        if ( !$this->checkAccess( 'edit', false, false, false, $languageID ) )
        {
            return false;
        }

        // check if it is not the initial language
        $objectInitialLanguageID = $this->attribute( 'initial_language_id' );
        if ( $objectInitialLanguageID == $languageID )
        {
            return false;
        }

        // change language_mask of the object
        $languageMask = (int) $this->attribute( 'language_mask' );
        $languageMask = (int) $languageMask & ~ (int) $languageID;
        $this->setAttribute( 'language_mask', $languageMask );

        $db = eZDB::instance();
        $db->begin();

        $this->store();

        $objectID = $this->ID;

        // If the current version has initial_language_id $languageID, change it to the initial_language_id of the object.
        $currentVersion = $this->currentVersion();
        if ( $currentVersion->attribute( 'initial_language_id' ) == $languageID )
        {
            $currentVersion->setAttribute( 'initial_language_id', $objectInitialLanguageID );
            $currentVersion->store();
        }

        // Remove all versions which had the language as its initial ID. Because of previous checks, it is sure we will not remove the published version.
        $versionsToRemove = $this->versions( true, array( 'conditions' => array( 'initial_language_id' => $languageID ) ) );
        foreach ( $versionsToRemove as $version )
        {
            $version->removeThis();
        }

        $altLanguageID = $languageID++;

        // Remove all attributes in the language
        $attributes = $db->arrayQuery( "SELECT * FROM ezcontentobject_attribute
                                        WHERE contentobject_id='$objectID'
                                          AND ( language_id='$languageID' OR language_id='$altLanguageID' )" );
        foreach ( $attributes as $attribute )
        {
            $attributeObject = new eZContentObjectAttribute( $attribute );
            $attributeObject->remove( $attributeObject->attribute( 'id' ), $attributeObject->attribute( 'version' ) );
            unset( $attributeObject );
        }

        // Remove all names in the language
        $db->query( "DELETE FROM ezcontentobject_name
                     WHERE contentobject_id='$objectID'
                       AND ( language_id='$languageID' OR language_id='$altLanguageID' )" );

        // Update masks of the objects
        $mask = eZContentLanguage::maskForRealLanguages() - (int) $languageID;

        if ( $db->databaseName() == 'oracle' )
        {
            $db->query( "UPDATE ezcontentobject_version SET language_mask = bitand( language_mask, $mask )
                         WHERE contentobject_id='$objectID'" );
        }
        else
        {
            $db->query( "UPDATE ezcontentobject_version SET language_mask = language_mask & $mask
                         WHERE contentobject_id='$objectID'" );
        }

        $urlElementfilter = new eZURLAliasQuery();
        $urlElementfilter->type = 'name';
        // We want all languages present here, so we are turning off
        // language filtering
        $urlElementfilter->languages = false;
        $urlElementfilter->limit = false;

        $nodes = $this->assignedNodes();

        foreach ( $nodes as $node )
        {
            $parent = null;
            $textMD5 = null;

            $urlElementfilter->actions = array( 'eznode:' . $node->attribute( 'node_id' ) );
            $urlElementfilter->prepare();
            $urlElements = $urlElementfilter->fetchAll();

            foreach ($urlElements as $url )
            {
                if ( $url->attribute( 'lang_mask' ) === (int)$languageID or
                     $url->attribute( 'lang_mask') === (int)$altLanguageID )
                {
                    $parent = $url->attribute( 'parent');
                    $textMD5 = $url->attribute( 'text_md5' );
                    break;
                }
            }

            if ( $parent !== null and $textMD5 !== null )
                eZURLAliasML::removeSingleEntry( $parent, $textMD5, $language );
        }
        $db->commit();

        return true;
    }
 function fetchAll()
 {
     if ($this->items !== null) {
         return $this->items;
     }
     if ($this->query === null) {
         $this->query = $this->generateSQL();
     }
     if ($this->query === false) {
         return array();
     }
     $query = "SELECT * {$this->query} ORDER BY {$this->order}";
     $params = array('offset' => $this->offset, 'limit' => $this->limit);
     $db = eZDB::instance();
     $rows = $db->arrayQuery($query, $params);
     if (count($rows) == 0) {
         $this->items = array();
     } else {
         $this->items = eZURLAliasQuery::makeList($rows);
     }
     return $this->items;
 }
Beispiel #7
0
            }
            else
            {
                $infoData['new_alias'] = $aliasText;
            }
            if ( $infoCode == 'no-errors' )
            {
                $infoCode = "feedback-alias-created";
            }
            $aliasText = false;
        }
    }
}

// Fetch generated names of node
$filter = new eZURLAliasQuery();
$filter->actions = array( 'eznode:' . $node->attribute( 'node_id' ) );
$filter->type = 'name';
$filter->limit = false;
$elements = $filter->fetchAll();

// Fetch custom aliases for node
$limit = 25;
$filter->prepare(); // Reset SQLs from previous calls
$filter->actions = array( 'eznode:' . $node->attribute( 'node_id' ) );
$filter->type = 'alias';
$filter->offset = $Offset;
$filter->limit = $limit;
$count = $filter->count();
$aliasList = $filter->fetchAll();