public function publishTagByRemoteID($tagRemoteID, $tagParentID, $tagKeyword)
 {
     $ezTagsObject = eZTagsObject::fetchByRemoteID($tagRemoteID);
     if (!$ezTagsObject instanceof eZTagsObject) {
         $ezTagsObject = new eZTagsObject(array('remote_id' => $tagRemoteID));
     }
     $ezTagsObject->setAttribute('parent_id', $tagParentID);
     // ParentID
     $ezTagsObject->setAttribute('keyword', $tagKeyword);
     // Keyword
     $ezTagsObject->store();
     return true;
 }
 public function getData()
 {
     $ezTagsObject = new eZTagsObject();
     $returnArray = array();
     $childrenArray = array();
     // recupero la lista dei remoteID dei tags che il server gestisce
     $tagsGestiti = explode(',', $this->runtimeSettingsINI->variable('serverSyncTags', 'serverSyncTagsList'));
     $numtagreturned = count($tagsGestiti);
     // Ciclo per recuperare gli array degli oggetti ritornati
     for ($i = 0; $i < $numtagreturned; $i++) {
         $parentFields = array();
         #$eZTagParentObj = eZTagsObject::fetchByRemoteID('e4fd6bcf76ab7ce0e04684bdb867a76d');
         #$eZTagParentObj = eZTagsObject::fetchByRemoteID(trim($tagsGestiti[$i]));
         $eZTagParentObj_array = eZTagsObject::fetchByKeyword(trim($tagsGestiti[$i]), true);
         $eZTagParentObj = $eZTagParentObj_array[0];
         /*
         $eZTagParentObj->RemoteID;
         $eZTagParentObj->getAttribute('RemoteID');
         $eZTagParentObj->attributes('remote_id');
         */
         # recupero e trasformo in array l'oggetto parentID
         $parentFields = itobjectsutils::getObjectAsArray($eZTagParentObj);
         # recupero tutti i children tags
         $childrenArray = eZTagsObject::fetchByParentID($eZTagParentObj->ID);
         # aggiungo al mio array generale il blocco dei children tags
         $parentFields['subTags'] = $childrenArray;
         $returnArray[$eZTagParentObj->RemoteID] = $parentFields;
     }
     return $returnArray;
 }
 /**
  * Creates and returns SQL parts used in fetch functions
  *
  * @return array
  */
 function createSqlParts($params)
 {
     $returnArray = array('tables' => '', 'joins' => '', 'columns' => '');
     if (isset($params['tag_id'])) {
         if (is_array($params['tag_id'])) {
             $tagIDsArray = $params['tag_id'];
         } else {
             if ((int) $params['tag_id'] > 0) {
                 $tagIDsArray = array((int) $params['tag_id']);
             } else {
                 return $returnArray;
             }
         }
         if (!isset($params['include_synonyms']) || isset($params['include_synonyms']) && (bool) $params['include_synonyms'] == true) {
             $result = eZTagsObject::fetchList(array('main_tag_id' => array($tagIDsArray)), null, false);
             if (is_array($result) && !empty($result)) {
                 foreach ($result as $r) {
                     array_push($tagIDsArray, (int) $r['id']);
                 }
             }
         }
         $returnArray['tables'] = " INNER JOIN eztags_attribute_link i1 ON (i1.object_id = ezcontentobject.id AND i1.objectattribute_version = ezcontentobject.current_version)";
         $db = eZDB::instance();
         $dbString = $db->generateSQLINStatement($tagIDsArray, 'i1.keyword_id', false, true, 'int');
         $returnArray['joins'] = " {$dbString} AND ";
     }
     return $returnArray;
 }
 function node()
 {
     if ($this->Tag == null) {
         $this->Tag = eZTagsObject::fetch($this->attribute('tag_id'));
     }
     return $this->Tag;
 }
 /**
  * Generates tag hierarchy string for given tag ID
  *
  * @static
  *
  * @param int $tagID
  *
  * @return string
  */
 public static function generateParentString($tagID)
 {
     $tag = eZTagsObject::fetchWithMainTranslation($tagID);
     if (!$tag instanceof eZTagsObject) {
         return '(' . ezpI18n::tr('extension/eztags/tags/edit', 'no parent') . ')';
     }
     return $tag->getParentString();
 }
 function findTags($id)
 {
     if (is_numeric($id)) {
         $tags = array(eZTagsObject::fetch($id));
     } else {
         $tags = eZTagsObject::fetchByKeyword($id);
     }
     return $tags;
 }
 /**
  * Provides suggestion results when adding tags to object
  *
  * @static
  * @param mixed $args
  * @return array
  */
 public static function suggest($args)
 {
     $tags = array();
     $siteINI = eZINI::instance('site.ini');
     if ($siteINI->variable('SearchSettings', 'SearchEngine') == 'ezsolr' && class_exists('eZSolr')) {
         $tagsCount = 1;
         $filteredTagsArray = array();
         $http = eZHTTPTool::instance();
         $tagsString = $http->postVariable('tags_string');
         $tagsArray = explode('|#', $tagsString);
         $subTreeLimit = $http->postVariable('subtree_limit');
         $hideRootTag = $http->postVariable('hide_root_tag') == '1' ? true : false;
         if (!empty($tagsArray) && strlen(trim($tagsArray[0])) > 0) {
             $solrFilter = '"' . trim($tagsArray[0]) . '"';
             $filteredTagsArray[] = strtolower(trim($tagsArray[0]));
             for ($i = 1; $i < count($tagsArray); $i++) {
                 if (strlen(trim($tagsArray[$i])) > 0) {
                     $solrFilter = $solrFilter . ' OR "' . trim($tagsArray[$i]) . '"';
                     $filteredTagsArray[] = strtolower(trim($tagsArray[$i]));
                     $tagsCount++;
                 }
             }
             $solrFilter = 'ezf_df_tags:(' . $solrFilter . ')';
             $solrSearch = new eZSolr();
             $params = array('SearchOffset' => 0, 'SearchLimit' => 0, 'Facet' => array(array('field' => 'ezf_df_tags', 'limit' => 5 + $tagsCount, 'mincount', 1)), 'SortBy' => null, 'Filter' => $solrFilter, 'QueryHandler' => 'ezpublish', 'FieldsToReturn' => null);
             $searchResult = $solrSearch->search('', $params);
             $facetResult = $searchResult['SearchExtras']->attribute('facet_fields');
             $facetResult = $facetResult[0]['nameList'];
             $tags = array();
             foreach ($facetResult as $facetValue) {
                 if (!in_array(strtolower($facetValue), $filteredTagsArray)) {
                     $tags[] = trim($facetValue);
                 }
             }
             if (!empty($tags)) {
                 $tags = eZTagsObject::fetchByKeyword(array($tags));
             }
         }
     }
     $returnArray = array();
     $returnArray['status'] = 'success';
     $returnArray['message'] = '';
     $returnArray['tags'] = array();
     foreach ($tags as $tag) {
         if (!$subTreeLimit > 0 || $subTreeLimit > 0 && strpos($tag->attribute('path_string'), '/' . $subTreeLimit . '/') !== false) {
             if (!$hideRootTag || $hideRootTag && $tag->attribute('id') != $subTreeLimit) {
                 $returnArrayChild = array();
                 $returnArrayChild['tag_parent_id'] = (int) $tag->attribute('parent_id');
                 $returnArrayChild['tag_parent_name'] = $tag->hasParent() ? $tag->getParent()->attribute('keyword') : '';
                 $returnArrayChild['tag_name'] = $tag->attribute('keyword');
                 $returnArrayChild['tag_id'] = (int) $tag->attribute('id');
                 $returnArray['tags'][] = $returnArrayChild;
             }
         }
     }
     return $returnArray;
 }
 /**
  * Ritorna l'elengo dei tag disponibili
  * 
  * @return eZTagsObject[]
  */
 public static function notificationAvailableTags()
 {
     $class = eZContentClass::fetchByIdentifier(self::CLASS_IDENTIFIER);
     if ($class instanceof eZContentClass) {
         $classAttribute = $class->fetchAttributeByIdentifier(self::TAG_ATTRIBUTE_IDENTIFIER);
         if ($classAttribute instanceof eZContentClassAttribute) {
             $tagRoot = eZTagsObject::fetch(intval($classAttribute->attribute(eZTagsType::SUBTREE_LIMIT_FIELD)));
             return $tagRoot->getChildren();
         }
     }
     return array();
 }
Beispiel #9
0
 /**
  * Returns the JSON encoded string of children tags for supplied GET params
  * Used in YUI version of children tags list in admin interface
  *
  * @static
  *
  * @param array $args
  *
  * @return string
  */
 public static function tagsChildren($args)
 {
     $http = eZHTTPTool::instance();
     $filter = urldecode(trim($http->getVariable('filter', '')));
     if (!isset($args[0]) || !is_numeric($args[0])) {
         return array('count' => 0, 'offset' => false, 'filter' => $filter, 'data' => array());
     }
     $offset = false;
     $limits = null;
     if ($http->hasGetVariable('offset')) {
         $offset = (int) $http->getVariable('offset');
         if ($http->hasGetVariable('limit')) {
             $limit = (int) $http->getVariable('limit');
         } else {
             $limit = 10;
         }
         $limits = array('offset' => $offset, 'limit' => $limit);
     }
     $sorts = null;
     if ($http->hasGetVariable('sortby')) {
         $sortBy = trim($http->getVariable('sortby'));
         $sortDirection = 'asc';
         if ($http->hasGetVariable('sortdirection') && trim($http->getVariable('sortdirection')) == 'desc') {
             $sortDirection = 'desc';
         }
         $sorts = array($sortBy => $sortDirection);
     }
     $fetchParams = array('parent_id' => (int) $args[0], 'main_tag_id' => 0);
     if (!empty($filter)) {
         $fetchParams['keyword'] = array('like', '%' . $filter . '%');
     }
     /** @var eZTagsObject[] $children */
     $children = eZTagsObject::fetchList($fetchParams, $limits, $sorts);
     $childrenCount = eZTagsObject::fetchListCount($fetchParams);
     if (!is_array($children) || empty($children)) {
         return array('count' => 0, 'offset' => false, 'filter' => $filter, 'data' => array());
     }
     $dataArray = array();
     foreach ($children as $child) {
         $tagArray = array();
         $tagArray['id'] = $child->attribute('id');
         $tagArray['keyword'] = htmlspecialchars($child->attribute('keyword'), ENT_QUOTES);
         $tagArray['modified'] = $child->attribute('modified');
         $tagArray['translations'] = array();
         foreach ($child->getTranslations() as $translation) {
             $tagArray['translations'][] = htmlspecialchars($translation->attribute('locale'), ENT_QUOTES);
         }
         $dataArray[] = $tagArray;
     }
     return array('count' => $childrenCount, 'offset' => $offset, 'filter' => $filter, 'data' => $dataArray);
 }
Beispiel #10
0
<?php

$http = eZHTTPTool::instance();
$tagID = (int) $Params['TagID'];
if ($tagID <= 0) {
    return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel');
}
$tag = eZTagsObject::fetch($tagID);
if (!$tag instanceof eZTagsObject) {
    return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel');
}
if ($tag->attribute('main_tag_id') == 0) {
    return $Module->redirectToView('delete', array($tagID));
}
if ($http->hasPostVariable('NoButton')) {
    return $Module->redirectToView('id', array($tagID));
}
if ($http->hasPostVariable('YesButton')) {
    $db = eZDB::instance();
    $db->begin();
    $parentTag = $tag->getParent();
    if ($parentTag instanceof eZTagsObject) {
        $parentTag->updateModified();
    }
    $mainTagID = $tag->attribute('main_tag_id');
    $tag->registerSearchObjects();
    if ($http->hasPostVariable('TransferObjectsToMainTag')) {
        foreach ($tag->getTagAttributeLinks() as $tagAttributeLink) {
            $link = eZTagsAttributeLinkObject::fetchByObjectAttributeAndKeywordID($tagAttributeLink->attribute('objectattribute_id'), $tagAttributeLink->attribute('objectattribute_version'), $tagAttributeLink->attribute('object_id'), $mainTagID);
            if (!$link instanceof eZTagsAttributeLinkObject) {
                $tagAttributeLink->setAttribute('keyword_id', $mainTagID);
Beispiel #11
0
                $oldParentTag->updateModified();
            }
        }
        /* Extended Hook */
        if (class_exists('ezpEvent', false)) {
            ezpEvent::getInstance()->filter('tag/merge', array('tag' => $tag, 'newParentTag' => $mainTag, 'oldParentTag' => $oldParentTag));
        }
        $tag->moveChildrenBelowAnotherTag($mainTag);
        foreach ($tag->getSynonyms(true) as $synonym) {
            $synonym->registerSearchObjects();
            $synonym->transferObjectsToAnotherTag($mainTag);
            $synonym->remove();
        }
        $tag->registerSearchObjects();
        $tag->transferObjectsToAnotherTag($mainTag);
        $tag->remove();
        $mainTag->updateModified();
        $db->commit();
        return $Module->redirectToView('id', array($mainTag->attribute('id')));
    }
}
$tpl = eZTemplate::factory();
$tpl->setVariable('tag', $tag);
$tpl->setVariable('merge_allowed', $mergeAllowed);
$tpl->setVariable('warning', $warning);
$tpl->setVariable('error', $error);
$Result = array();
$Result['content'] = $tpl->fetch('design:tags/merge.tpl');
$Result['ui_context'] = 'edit';
$Result['path'] = eZTagsObject::generateModuleResultPath($tag);
Beispiel #12
0
<?php

/** @var eZModule $Module */
/** @var array $Params */
$http = eZHTTPTool::instance();
$keywordArray = $Params['Parameters'];
if (!is_array($keywordArray) || empty($keywordArray)) {
    return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel');
}
$tag = eZTagsObject::fetchByUrl($keywordArray);
if (!$tag instanceof eZTagsObject) {
    return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel');
}
$viewParameters = array();
if (isset($Params['Offset'])) {
    $viewParameters['offset'] = (int) $Params['Offset'];
}
$tpl = eZTemplate::factory();
$tpl->setVariable('tag', $tag);
$tpl->setVariable('view_parameters', $viewParameters);
$tpl->setVariable('show_reindex_message', false);
if ($http->hasSessionVariable('eZTagsShowReindexMessage')) {
    $http->removeSessionVariable('eZTagsShowReindexMessage');
    $tpl->setVariable('show_reindex_message', true);
}
$Result = array();
$Result['content'] = $tpl->fetch('design:tags/view.tpl');
$Result['path'] = eZTagsObject::generateModuleResultPath($tag, true, false, false);
Beispiel #13
0
if ($http->hasPostVariable('DiscardButton')) {
    return $Module->redirectToView('id', array($mainTagID));
}
if ($http->hasPostVariable('SaveButton')) {
    if (!($http->hasPostVariable('TagEditKeyword') && strlen(trim($http->postVariable('TagEditKeyword'))) > 0)) {
        $error = ezpI18n::tr('extension/eztags/errors', 'Name cannot be empty.');
    }
    $newKeyword = trim($http->postVariable('TagEditKeyword'));
    if (empty($error) && eZTagsObject::exists(0, $newKeyword, $mainTag->attribute('parent_id'))) {
        $error = ezpI18n::tr('extension/eztags/errors', 'Tag/synonym with that name already exists in selected location.');
    }
    if (empty($error)) {
        $parentTag = eZTagsObject::fetch($mainTag->attribute('parent_id'));
        $db = eZDB::instance();
        $db->begin();
        $tag = new eZTagsObject(array('parent_id' => $mainTag->attribute('parent_id'), 'main_tag_id' => $mainTagID, 'keyword' => $newKeyword, 'depth' => $mainTag->attribute('depth'), 'path_string' => $parentTag instanceof eZTagsObject ? $parentTag->attribute('path_string') : '/'));
        $tag->store();
        $tag->setAttribute('path_string', $tag->attribute('path_string') . $tag->attribute('id') . '/');
        $tag->store();
        $tag->updateModified();
        $db->commit();
        return $Module->redirectToView('id', array($tag->attribute('id')));
    }
}
$tpl = eZTemplate::factory();
$tpl->setVariable('main_tag', $mainTag);
$tpl->setVariable('error', $error);
$tpl->setVariable('ui_context', 'edit');
$Result = array();
$Result['content'] = $tpl->fetch('design:tags/addsynonym.tpl');
$Result['ui_context'] = 'edit';
Beispiel #14
0
 /**
  * Returns tags within this instance
  *
  * @return array
  */
 function tags()
 {
     if (!is_array($this->IDArray) || empty($this->IDArray)) {
         return array();
     }
     return eZTagsObject::fetchList(array('id' => array($this->IDArray)));
 }
Beispiel #15
0
 $updateDepth = false;
 $updatePathString = false;
 $newParentTag = $mainTag->getParent();
 $db = eZDB::instance();
 $db->begin();
 if ($tag->attribute('depth') != $mainTag->attribute('depth')) {
     $updateDepth = true;
 }
 if ($tag->attribute('parent_id') != $mainTag->attribute('parent_id')) {
     $oldParentTag = $tag->getParent();
     if ($oldParentTag instanceof eZTagsObject) {
         $oldParentTag->updateModified();
     }
     $updatePathString = true;
 }
 eZTagsObject::moveChildren($tag, $mainTag);
 $synonyms = $tag->getSynonyms();
 foreach ($synonyms as $synonym) {
     $synonym->setAttribute('parent_id', $mainTag->attribute('parent_id'));
     $synonym->setAttribute('main_tag_id', $mainTag->attribute('id'));
     $synonym->store();
 }
 $tag->setAttribute('parent_id', $mainTag->attribute('parent_id'));
 $tag->setAttribute('main_tag_id', $mainTag->attribute('id'));
 $tag->store();
 if (!$newParentTag instanceof eZTagsObject) {
     $newParentTag = false;
 }
 if ($updatePathString) {
     $tag->updatePathString($newParentTag);
 }
Beispiel #16
0
    return $Module->redirectToView('id', array($tagID));
}
if ($tag->isInsideSubTreeLimit()) {
    $warning = ezpI18n::tr('extension/eztags/warnings', 'TAKE CARE: Tag is inside class attribute subtree limit(s). If moved outside those limits, it could lead to inconsistency as objects could end up with tags that they are not supposed to have.');
}
if ($http->hasPostVariable('SaveButton')) {
    if (!($http->hasPostVariable('TagEditKeyword') && strlen(trim($http->postVariable('TagEditKeyword'))) > 0)) {
        $error = ezpI18n::tr('extension/eztags/errors', 'Name cannot be empty.');
    }
    if (empty($error) && !($http->hasPostVariable('TagEditParentID') && (int) $http->postVariable('TagEditParentID') >= 0)) {
        $error = ezpI18n::tr('extension/eztags/errors', 'Selected target tag is invalid.');
    }
    $newParentTag = eZTagsObject::fetch((int) $http->postVariable('TagEditParentID'));
    $newParentID = $newParentTag instanceof eZTagsObject ? $newParentTag->attribute('id') : 0;
    $newKeyword = trim($http->postVariable('TagEditKeyword'));
    if (empty($error) && eZTagsObject::exists($tag->attribute('id'), $newKeyword, $newParentID)) {
        $error = ezpI18n::tr('extension/eztags/errors', 'Tag/synonym with that name already exists in selected location.');
    }
    if (empty($error)) {
        $updateDepth = false;
        $updatePathString = false;
        $db = eZDB::instance();
        $db->begin();
        $oldParentDepth = $tag->attribute('depth') - 1;
        $newParentDepth = $newParentTag instanceof eZTagsObject ? $newParentTag->attribute('depth') : 0;
        if ($oldParentDepth != $newParentDepth) {
            $updateDepth = true;
        }
        if ($tag->attribute('parent_id') != $newParentID) {
            $oldParentTag = $tag->getParent();
            if ($oldParentTag instanceof eZTagsObject) {
 /**
  * Fetches latest modified tags by specified parameters
  *
  * @static
  *
  * @param int|bool $parentTagID
  * @param int $limit
  * @param mixed $language
  *
  * @return array
  */
 public static function fetchLatestTags($parentTagID = false, $limit = 0, $language = false)
 {
     $parentTagID = (int) $parentTagID;
     $filterArray = array();
     $filterArray['main_tag_id'] = 0;
     $filterArray['id'] = array('!=', $parentTagID);
     if ($parentTagID > 0) {
         $filterArray['path_string'] = array('like', '%/' . $parentTagID . '/%');
     }
     if ($language) {
         if (!is_array($language)) {
             $language = array($language);
         }
         eZContentLanguage::setPrioritizedLanguages($language);
     }
     $result = eZTagsObject::fetchList($filterArray, array('offset' => 0, 'limit' => $limit), array('modified' => 'desc'));
     if ($language) {
         eZContentLanguage::clearPrioritizedLanguages();
     }
     if (is_array($result) && !empty($result)) {
         return array('result' => $result);
     }
     return array('result' => false);
 }
Beispiel #18
0
 /**
  * Generates output for use with autocomplete and suggest methods
  *
  * @static
  *
  * @param array $params
  * @param int $subTreeLimit
  * @param bool $hideRootTag
  * @param string $locale
  *
  * @return array
  */
 private static function generateOutput(array $params, $subTreeLimit, $hideRootTag, $locale)
 {
     $subTreeLimit = (int) $subTreeLimit;
     $hideRootTag = (bool) $hideRootTag;
     $locale = (string) $locale;
     if (empty($locale)) {
         return array('status' => 'success', 'message' => '', 'tags' => array());
     }
     // @TODO Fix synonyms not showing up in autocomplete
     // when subtree limit is defined in class attribute
     if ($subTreeLimit > 0) {
         if ($hideRootTag) {
             $params['id'] = array('<>', $subTreeLimit);
         }
         $params['path_string'] = array('like', '%/' . $subTreeLimit . '/%');
     }
     // first fetch tags that exist in selected locale
     /** @var eZTagsObject[] $tags */
     $tags = eZTagsObject::fetchList($params, null, null, false, $locale);
     if (!is_array($tags)) {
         $tags = array();
     }
     $tagsIDsToExclude = array_map(function ($tag) {
         /** @var eZTagsObject $tag */
         return (int) $tag->attribute('id');
     }, $tags);
     // then fetch the rest of tags, but exclude already fetched ones
     // fetch with main translation to be consistent with eztags attribute content
     $customConds = eZTagsObject::fetchCustomCondsSQL($params, true);
     if (!empty($tagsIDsToExclude)) {
         $customConds .= " AND " . eZDB::instance()->generateSQLINStatement($tagsIDsToExclude, 'eztags.id', true, true, 'int') . " ";
     }
     $tagsRest = eZPersistentObject::fetchObjectList(eZTagsObject::definition(), array(), $params, null, null, true, false, array('DISTINCT eztags.*', array('operation' => 'eztags_keyword.keyword', 'name' => 'keyword'), array('operation' => 'eztags_keyword.locale', 'name' => 'locale')), array('eztags_keyword'), $customConds);
     if (!is_array($tagsRest)) {
         $tagsRest = array();
     }
     // finally, return both set of tags as one list
     $tags = array_merge($tags, $tagsRest);
     $returnArray = array('status' => 'success', 'message' => '', 'tags' => array());
     foreach ($tags as $tag) {
         $returnArrayChild = array();
         $returnArrayChild['tag_parent_id'] = $tag->attribute('parent_id');
         $returnArrayChild['tag_parent_name'] = $tag->hasParent(true) ? $tag->getParent(true)->attribute('keyword') : '';
         $returnArrayChild['tag_name'] = $tag->attribute('keyword');
         $returnArrayChild['tag_id'] = $tag->attribute('id');
         $returnArrayChild['tag_locale'] = $tag->attribute('current_language');
         $returnArray['tags'][] = $returnArrayChild;
     }
     return $returnArray;
 }
Beispiel #19
0
if (!empty($tagsSearchText)) {
    $sorts = array('eztags_keyword.keyword' => 'asc');
    $limits = array('offset' => $offset, 'limit' => $limit);
    $params = array('eztags_keyword.keyword' => array('like', '%' . $tagsSearchText . '%'));
    $customConds = eZTagsObject::fetchCustomCondsSQL($params);
    if ($tagsSearchSubTree > 0) {
        if ($tagsIncludeSynonyms) {
            $customConds .= ' AND ( path_string LIKE "%/' . $tagsSearchSubTree . '/%" OR main_tag_id = ' . $tagsSearchSubTree . ' ) ';
        } else {
            $params['path_string'] = array('like', '%/' . $tagsSearchSubTree . '/%');
        }
    } else {
        if (!$tagsIncludeSynonyms) {
            $params['main_tag_id'] = 0;
        }
    }
    $tagsSearchResults = eZPersistentObject::fetchObjectList(eZTagsObject::definition(), array(), $params, $sorts, $limits, true, false, array('DISTINCT eztags.*', array('operation' => 'eztags_keyword.keyword', 'name' => 'keyword'), array('operation' => 'eztags_keyword.locale', 'name' => 'locale')), array('eztags_keyword'), $customConds);
    $tagsSearchCount = eZPersistentObject::fetchObjectList(eZTagsObject::definition(), array(), $params, array(), null, false, false, array(array('operation' => 'COUNT( * )', 'name' => 'row_count')), array('eztags_keyword'), $customConds);
    $tagsSearchCount = $tagsSearchCount[0]['row_count'];
}
$tpl = eZTemplate::factory();
$tpl->setVariable('tags_search_text', $tagsSearchText);
$tpl->setVariable('tags_search_subtree', $tagsSearchSubTree);
$tpl->setVariable('tags_include_synonyms', $tagsIncludeSynonyms);
$tpl->setVariable('tags_search_count', $tagsSearchCount);
$tpl->setVariable('tags_search_results', $tagsSearchResults);
$tpl->setVariable('view_parameters', $viewParameters);
$Result = array();
$Result['content'] = $tpl->fetch('design:tags/search.tpl');
$Result['path'] = eZTagsObject::generateModuleResultPath(false, null, ezpI18n::tr('extension/eztags/tags/search', 'Tags search'));
Beispiel #20
0
    return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel');
}
$error = '';
if ($http->hasPostVariable('SaveButton')) {
    $newKeyword = trim($http->postVariable('TagEditKeyword', ''));
    if (empty($newKeyword)) {
        $error = ezpI18n::tr('extension/eztags/errors', 'Name cannot be empty.');
    }
    if (empty($error) && eZTagsObject::exists(0, $newKeyword, $parentTag instanceof eZTagsObject ? $parentTag->attribute('id') : 0)) {
        $error = ezpI18n::tr('extension/eztags/errors', 'Tag/synonym with that translation already exists in selected location.');
    }
    if (empty($error)) {
        $db = eZDB::instance();
        $db->begin();
        $languageMask = eZContentLanguage::maskByLocale(array($language->attribute('locale')), $http->hasPostVariable('AlwaysAvailable'));
        $tag = new eZTagsObject(array('parent_id' => $parentTagID, 'main_tag_id' => 0, 'depth' => $parentTag instanceof eZTagsObject ? $parentTag->attribute('depth') + 1 : 1, 'path_string' => $parentTag instanceof eZTagsObject ? $parentTag->attribute('path_string') : '/', 'main_language_id' => $language->attribute('id'), 'language_mask' => $languageMask), $language->attribute('locale'));
        $tag->store();
        $translation = new eZTagsKeyword(array('keyword_id' => $tag->attribute('id'), 'language_id' => $language->attribute('id'), 'keyword' => $newKeyword, 'locale' => $language->attribute('locale'), 'status' => eZTagsKeyword::STATUS_PUBLISHED));
        if ($http->hasPostVariable('AlwaysAvailable')) {
            $translation->setAttribute('language_id', $translation->attribute('language_id') + 1);
        }
        $translation->store();
        $tag->setAttribute('path_string', $tag->attribute('path_string') . $tag->attribute('id') . '/');
        $tag->store();
        $tag->updateModified();
        /* Extended Hook */
        if (class_exists('ezpEvent', false)) {
            ezpEvent::getInstance()->filter('tag/add', array('tag' => $tag, 'parentTag' => $parentTag));
        }
        $db->commit();
        return $Module->redirectToView('id', array($tag->attribute('id')));
 /**
  * Fetches latest modified tags by specified parameters
  *
  * @static
  * @param integer $parentTagID
  * @param integer $limit
  * @return array
  */
 public static function fetchLatestTags($parentTagID = false, $limit = 0)
 {
     $filterArray = array('main_tag_id' => 0);
     if ($parentTagID !== false) {
         $filterArray['parent_id'] = (int) $parentTagID;
     }
     $result = eZPersistentObject::fetchObjectList(eZTagsObject::definition(), null, $filterArray, array('modified' => 'desc'), array('offset' => 0, 'limit' => $limit));
     if (is_array($result) && !empty($result)) {
         return array('result' => $result);
     } else {
         return array('result' => false);
     }
 }
 /**
  * Extracts data to be indexed from the tag
  *
  * @param eZTagsObject $tag
  * @param array $tagIDs
  * @param array $keywords
  * @param bool $indexParentTags
  * @param bool $includeSynonyms
  */
 private function processTag(eZTagsObject $tag, array &$tagIDs, array &$keywords, $indexParentTags = false, $includeSynonyms = false)
 {
     if (!$this->indexSynonyms && $tag->isSynonym()) {
         $tag = $tag->getMainTag();
     }
     //get keyword in content's locale
     $keyword = $tag->getKeyword($this->ContentObjectAttribute->attribute('language_code'));
     if (!$keyword) {
         //fall back to main language
         /** @var eZContentLanguage $mainLanguage */
         $mainLanguage = eZContentLanguage::fetch($tag->attribute('main_language_id'));
         if ($mainLanguage instanceof eZContentLanguage) {
             $keyword = $tag->getKeyword($mainLanguage->attribute('locale'));
         }
     }
     if ($keyword) {
         $tagIDs[] = (int) $tag->attribute('id');
         $keywords[] = $keyword;
     }
     if ($indexParentTags) {
         $parentTags = $tag->getPath(true);
         foreach ($parentTags as $parentTag) {
             if ($parentTag instanceof eZTagsObject) {
                 $this->processTag($parentTag, $tagIDs, $keywords);
             }
         }
     }
     if ($this->indexSynonyms && $includeSynonyms) {
         foreach ($tag->getSynonyms() as $synonym) {
             if ($synonym instanceof eZTagsObject) {
                 $this->processTag($synonym, $tagIDs, $keywords);
             }
         }
     }
 }
Beispiel #23
0
    } else {
        return $Module->redirectToView('dashboard', array());
    }
}
if ($http->hasPostVariable('SaveButton')) {
    if (!($http->hasPostVariable('TagEditKeyword') && strlen(trim($http->postVariable('TagEditKeyword'))) > 0)) {
        $error = ezpI18n::tr('extension/eztags/errors', 'Name cannot be empty.');
    }
    $newKeyword = trim($http->postVariable('TagEditKeyword'));
    if (empty($error) && eZTagsObject::exists(0, $newKeyword, $parentTag instanceof eZTagsObject ? $parentTag->attribute('id') : 0)) {
        $error = ezpI18n::tr('extension/eztags/errors', 'Tag/synonym with that name already exists in selected location.');
    }
    if (empty($error)) {
        $db = eZDB::instance();
        $db->begin();
        $tag = new eZTagsObject(array('parent_id' => $parentTag instanceof eZTagsObject ? $parentTag->attribute('id') : 0, 'main_tag_id' => 0, 'keyword' => $newKeyword, 'depth' => $parentTag instanceof eZTagsObject ? (int) $parentTag->attribute('depth') + 1 : 1, 'path_string' => $parentTag instanceof eZTagsObject ? $parentTag->attribute('path_string') : '/'));
        $tag->store();
        $tag->setAttribute('path_string', $tag->attribute('path_string') . $tag->attribute('id') . '/');
        $tag->store();
        $tag->updateModified();
        /* Extended Hook */
        if (class_exists('ezpEvent', false)) {
            $tag = ezpEvent::getInstance()->filter('tag/add', $tag);
        }
        $db->commit();
        return $Module->redirectToView('id', array($tag->attribute('id')));
    }
}
$tpl = eZTemplate::factory();
$tpl->setVariable('parent_id', $parentTagID);
$tpl->setVariable('error', $error);
Beispiel #24
0
 /**
  * Returns the tag cloud for specified parameters using eZ Find
  *
  * @param array $params
  *
  * @return array
  */
 private function solrTagCloud($params)
 {
     $offset = 0;
     if (isset($params['offset']) && is_numeric($params['offset'])) {
         $offset = (int) $params['offset'];
     }
     // It seems that Solr doesn't like PHP_INT_MAX constant on 64bit operating systems
     $limit = 1000000;
     if (isset($params['limit']) && is_numeric($params['limit'])) {
         $limit = (int) $params['limit'];
     }
     $searchFilter = array();
     if (isset($params['class_identifier'])) {
         if (!is_array($params['class_identifier'])) {
             $params['class_identifier'] = array($params['class_identifier']);
         }
         if (!empty($params['class_identifier'])) {
             $searchFilter['meta_class_identifier_ms'] = '(' . implode(' OR ', $params['class_identifier']) . ')';
         }
     }
     if (isset($params['parent_node_id'])) {
         $searchFilter['meta_path_si'] = (int) $params['parent_node_id'];
     }
     $solrSearch = new eZSolr();
     $solrParams = array('SearchOffset' => 0, 'SearchLimit' => 1000000, 'Facet' => array(array('field' => 'ezf_df_tag_ids', 'limit' => 1000000)), 'Filter' => $searchFilter, 'QueryHandler' => 'ezpublish', 'AsObjects' => false);
     $searchResult = $solrSearch->search('*:*', $solrParams);
     if (!isset($searchResult['SearchExtras']) || !$searchResult['SearchExtras'] instanceof ezfSearchResultInfo) {
         return array();
     }
     $facetResult = $searchResult['SearchExtras']->attribute('facet_fields');
     if (!is_array($facetResult) || empty($facetResult[0]['countList'])) {
         return array();
     }
     $tagsCountList = $facetResult[0]['countList'];
     /** @var eZTagsObject[] $tags */
     $tags = eZTagsObject::fetchList(array('id' => array(array_keys($tagsCountList))));
     if (!is_array($tags) || empty($tags)) {
         return array();
     }
     $tagSortArray = array();
     $tagKeywords = array();
     $tagCounts = array();
     foreach ($tags as $tag) {
         $tagKeyword = $tag->attribute('keyword');
         $tagCount = $tagsCountList[(int) $tag->attribute('id')];
         $tagSortArray[] = array('keyword' => $tagKeyword, 'count' => $tagCount, 'tag' => $tag);
         $tagKeywords[] = $tagKeyword;
         $tagCounts[] = $tagCount;
     }
     // calling call_user_func_array requires all arguments to be references
     // this is the reason for $sortFlags array and $sortArgs[] = &....
     $sortArgs = array();
     $sortFlags = array(SORT_ASC, SORT_DESC, SORT_LOCALE_STRING, SORT_NUMERIC);
     if (isset($params['sort_by']) && is_array($params['sort_by']) && !empty($params['sort_by'])) {
         $params['sort_by'] = is_string($params['sort_by'][0]) ? array($params['sort_by']) : $params['sort_by'];
         foreach ($params['sort_by'] as $sortItem) {
             if (is_array($sortItem) && !empty($sortItem)) {
                 switch ($sortItem[0]) {
                     case 'keyword':
                         $sortArgs[] =& $tagKeywords;
                         if (isset($sortItem[1]) && $sortItem[1]) {
                             $sortArgs[] =& $sortFlags[0];
                         } else {
                             $sortArgs[] =& $sortFlags[1];
                         }
                         $sortArgs[] =& $sortFlags[2];
                         break;
                     case 'count':
                         $sortArgs[] =& $tagCounts;
                         if (isset($sortItem[1]) && $sortItem[1]) {
                             $sortArgs[] =& $sortFlags[0];
                         } else {
                             $sortArgs[] =& $sortFlags[1];
                         }
                         $sortArgs[] =& $sortFlags[3];
                         break;
                 }
             }
         }
     }
     if (empty($sortArgs)) {
         $sortArgs[] =& $tagKeywords;
         $sortArgs[] =& $sortFlags[0];
     }
     $sortArgs[] =& $tagSortArray;
     call_user_func_array('array_multisort', $sortArgs);
     $tagSortArray = array_slice($tagSortArray, $offset, $limit);
     if (empty($tagSortArray)) {
         return array();
     }
     $tagKeywords = array_slice($tagKeywords, $offset, $limit);
     $tagCounts = array_slice($tagCounts, $offset, $limit);
     if (isset($params['post_sort_by'])) {
         if ($params['post_sort_by'] === 'keyword') {
             array_multisort($tagKeywords, SORT_ASC, SORT_LOCALE_STRING, $tagSortArray);
         } else {
             if ($params['post_sort_by'] === 'keyword_reverse') {
                 array_multisort($tagKeywords, SORT_DESC, SORT_LOCALE_STRING, $tagSortArray);
             } else {
                 if ($params['post_sort_by'] === 'count') {
                     array_multisort($tagCounts, SORT_ASC, SORT_NUMERIC, $tagSortArray);
                 } else {
                     if ($params['post_sort_by'] === 'count_reverse') {
                         array_multisort($tagCounts, SORT_DESC, SORT_NUMERIC, $tagSortArray);
                     }
                 }
             }
         }
     }
     $this->normalizeTagCounts($tagSortArray, $tagCounts);
     return $tagSortArray;
 }
Beispiel #25
0
        $db = eZDB::instance();
        foreach ($tagsList as $tag) {
            if ($tag->getSubTreeLimitationsCount() > 0 || $tag->attribute('main_tag_id') != 0) {
                continue;
            }
            $db->begin();
            $parentTag = $tag->getParent(true);
            if ($parentTag instanceof eZTagsObject) {
                $parentTag->updateModified();
            }
            /* Extended Hook */
            if (class_exists('ezpEvent', false)) {
                ezpEvent::getInstance()->filter('tag/delete', $tag);
            }
            $tag->recursivelyDeleteTag();
            $db->commit();
        }
        $http->removeSessionVariable('eZTagsDeleteIDArray');
        if ($parentTagID > 0) {
            return $Module->redirectToView('id', array($parentTagID));
        }
        return $Module->redirectToView('dashboard', array());
    }
}
$tpl = eZTemplate::factory();
$tpl->setVariable('tags', $tagsList);
$Result = array();
$Result['content'] = $tpl->fetch('design:tags/deletetags.tpl');
$Result['ui_context'] = 'edit';
$Result['path'] = eZTagsObject::generateModuleResultPath(false, null, ezpI18n::tr('extension/eztags/tags/edit', 'Delete tags'));
#!/usr/bin/env php
<?php 
require 'autoload.php';
$cli = eZCLI::instance();
$script = eZScript::instance(array('description' => '\\nUpdates depth of all the tags.\\n', 'use-session' => false, 'use-modules' => false, 'use-extensions' => true));
$script->startup();
$options = $script->getOptions('', '', array());
$script->initialize();
$limit = 20;
$offset = 0;
$db = eZDB::instance();
$script->setIterationData('.', '~');
while ($firstLevelTags = eZPersistentObject::fetchObjectList(eZTagsObject::definition(), null, array('parent_id' => 0, 'main_tag_id' => 0), null, array('offset' => $offset, 'limit' => $limit))) {
    foreach ($firstLevelTags as $tag) {
        $tagID = $tag->attribute('id');
        $db->begin();
        $tag->updateDepth(false);
        $db->commit();
        $script->iterate($cli, true, "Updated depth of tag ID = {$tagID} and all its children.");
    }
    $offset += $limit;
}
$script->shutdown();
if (!($tag instanceof eZTagsObject || $TagID == 0)) {
    header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
} else {
    $children = eZTagsObject::fetchByParentID($tagID);
    $response = array();
    $response['error_code'] = 0;
    $response['id'] = $tagID;
    $response['parent_id'] = $tag instanceof eZTagsObject ? (int) $tag->attribute('parent_id') : -1;
    $response['children_count'] = count($children);
    $response['children'] = array();
    foreach ($children as $child) {
        $childResponse = array();
        $childResponse['id'] = (int) $child->attribute('id');
        $childResponse['parent_id'] = (int) $child->attribute('parent_id');
        $childResponse['has_children'] = eZTagsObject::childrenCountByParentID($child->attribute('id')) ? 1 : 0;
        $childResponse['synonyms_count'] = eZTagsObject::synonymsCount($child->attribute('id'));
        $childResponse['subtree_limitations_count'] = $child->getSubTreeLimitationsCount();
        $childResponse['keyword'] = $child->attribute('keyword');
        $childResponse['url'] = 'tags/id/' . $child->attribute('id');
        $childResponse['icon'] = lookupIcon($eztagsINI, $child);
        eZURI::transformURI($childResponse['url']);
        $childResponse['modified'] = (int) $child->attribute('modified');
        $response['children'][] = $childResponse;
    }
    $httpCharset = eZTextCodec::httpCharset();
    $jsonText = arrayToJSON($response);
    $codec = eZTextCodec::instance($httpCharset, 'unicode');
    $jsonTextArray = $codec->convertString($jsonText);
    $jsonText = '';
    foreach ($jsonTextArray as $character) {
        if ($character < 128) {
Beispiel #28
0
    $params = array('keyword' => array('like', '%' . $tagsSearchText . '%'));
    $customFields = array(array('operation' => 'COUNT( * )', 'name' => 'row_count'));
    $customConds = null;
    if ($tagsSearchSubTree > 0) {
        if ($tagsIncludeSynonyms) {
            $customConds = ' AND ( path_string LIKE "%/' . $tagsSearchSubTree . '/%" OR main_tag_id = ' . $tagsSearchSubTree . ' ) ';
        } else {
            $params['path_string'] = array('like', '%/' . $tagsSearchSubTree . '/%');
        }
    } else {
        if (!$tagsIncludeSynonyms) {
            $params['main_tag_id'] = 0;
        }
    }
    $tagsSearchResults = eZPersistentObject::fetchObjectList(eZTagsObject::definition(), null, $params, null, $limits, true, false, null, null, $customConds);
    $tagsSearchCount = eZPersistentObject::fetchObjectList(eZTagsObject::definition(), array(), $params, array(), null, false, false, $customFields, null, $customConds);
    $tagsSearchCount = $tagsSearchCount[0]['row_count'];
}
$tpl = eZTemplate::factory();
$tpl->setVariable('tags_search_text', $tagsSearchText);
$tpl->setVariable('tags_search_subtree', $tagsSearchSubTree);
$tpl->setVariable('tags_include_synonyms', $tagsIncludeSynonyms);
$tpl->setVariable('tags_search_count', $tagsSearchCount);
$tpl->setVariable('tags_search_results', $tagsSearchResults);
$tpl->setVariable('view_parameters', $viewParameters);
$tpl->setVariable('persistent_variable', false);
$Result = array();
$Result['content'] = $tpl->fetch('design:tags/search.tpl');
$Result['path'] = array(array('text' => ezpI18n::tr('extension/eztags/tags/search', 'Tags search'), 'url' => false));
$contentInfoArray = array();
$contentInfoArray['persistent_variable'] = false;
Beispiel #29
0
 /**
  * Validates class attribute HTTP input
  *
  * @param eZHTTPTool $http
  * @param string $base
  * @param eZContentClassAttribute $attribute
  *
  * @return bool
  */
 public function validateClassAttributeHTTPInput($http, $base, $attribute)
 {
     $classAttributeID = $attribute->attribute('id');
     $maxTags = trim($http->postVariable($base . self::MAX_TAGS_VARIABLE . $classAttributeID, ''));
     if (!is_numeric($maxTags) && !empty($maxTags) || (int) $maxTags < 0) {
         return eZInputValidator::STATE_INVALID;
     }
     $subTreeLimit = (int) $http->postVariable($base . self::SUBTREE_LIMIT_VARIABLE . $classAttributeID, -1);
     if ($subTreeLimit < 0) {
         return eZInputValidator::STATE_INVALID;
     }
     if ($subTreeLimit > 0) {
         $tag = eZTagsObject::fetchWithMainTranslation($subTreeLimit);
         if (!$tag instanceof eZTagsObject || $tag->attribute('main_tag_id') > 0) {
             return eZInputValidator::STATE_INVALID;
         }
     }
     return eZInputValidator::STATE_ACCEPTED;
 }
Beispiel #30
0
    public static function fetchByPathName($path)
    {
        if (!is_array($path) && is_string($path))
            $path = array($path);

        if (count($path) == 0)
            return false;

        $db         = eZDB::instance();
        $definition = eZTagsObject::definition();
        $table      = $definition['name'];
        $from       = array();
        $where      = array();
        $lastIndex  = 0;

        reset($path);

        while(list($index, $keyword) = each($path))
        {
            if ($index == 0)
            {
                $from[]     = sprintf('%1$s as t%2$d', $table, $index);
                $where[]    = sprintf('t%1$d.keyword like "%2$s" AND t%1$d.depth = 1', $index, $db->escapeString($keyword));
            }
            else
            {
                $from[]     = sprintf('INNER JOIN %1$s as t%3$d ON t%2$d.id = t%3$d.parent_id', $table, $index - 1, $index);
                $where[]    = sprintf('t%d.keyword like "%s"', $index, $db->escapeString($keyword));
            }

            $lastIndex = $index;
        }

        $query = sprintf(
            'SELECT t%d.id From %s Where %s;',
            $lastIndex,
            implode(' ', $from),
            implode(' AND ', $where)
        );

        $result = $db->arrayQuery($query);

        if (is_array($result) && count($result))
            return eZTagsObject::fetch($result[0]['id']);

        return false;
    }