static function fetchTopList($classID = false, $sectionID = false, $offset = false, $limit = false) { if (!$classID && !$sectionID) { return eZPersistentObject::fetchObjectList(eZViewCounter::definition(), null, null, null, array('length' => $limit, 'offset' => $offset), false); } $queryPart = ""; if ($classID != false) { $classID = (int) $classID; $queryPart .= "ezcontentobject.contentclass_id={$classID} AND "; } if ($sectionID != false) { $sectionID = (int) $sectionID; $queryPart .= "ezcontentobject.section_id={$sectionID} AND "; } $db = eZDB::instance(); $query = "SELECT ezview_counter.*\n FROM\n ezcontentobject_tree,\n ezcontentobject,\n ezview_counter\n WHERE\n ezview_counter.node_id=ezcontentobject_tree.node_id AND\n {$queryPart}\n ezcontentobject_tree.contentobject_id=ezcontentobject.id\n ORDER BY ezview_counter.count DESC"; if (!$offset && !$limit) { $countListArray = $db->arrayQuery($query); } else { $countListArray = $db->arrayQuery($query, array("offset" => $offset, "limit" => $limit)); } return $countListArray; }
public static function fetchMostViewedTopList($classID, $sectionID, $offset, $limit) { $topList = eZViewCounter::fetchTopList($classID, $sectionID, $offset, $limit); $contentNodeList = array(); foreach (array_keys($topList) as $key) { $nodeID = $topList[$key]['node_id']; $contentNode = eZContentObjectTreeNode::fetch($nodeID); if ($contentNode === null) { return array('error' => array('error_type' => 'kernel', 'error_code' => eZError::KERNEL_NOT_FOUND)); } $contentNodeList[] = $contentNode; } return array('result' => $contentNodeList); }
// Try prepending each of the existing pathPrefixes, to see if one of them matches an existing node $nodeID = eZURLAliasML::fetchNodeIDByPath($pathPrefixes[$pathPrefixIndex] . $path); } if ($nodeID) { if (!isset($nodeIDHashCounter[$nodeID])) { $nodeIDHashCounter[$nodeID] = $count; } else { $nodeIDHashCounter[$nodeID] += $count; } } } foreach ($nodeIDHashCounter as $nodeID => $count) { if (eZContentObjectTreeNode::fetch($nodeID) != null) { $counter = eZViewCounter::fetch($nodeID); if ($counter == null) { $counter = eZViewCounter::create($nodeID); $counter->setAttribute('count', $count); $counter->store(); } else { $counter->increase($count); } } } $dt = new eZDateTime(); $fh = fopen($updateViewLogPath, "w"); if ($fh) { fwrite($fh, "# Finished at " . $dt->toString() . "\n" . "# Last updated entry:" . "\n" . $lastLine . "\n"); fclose($fh); } $cli->output("Finished at " . $dt->toString() . "\n"); $cli->output("View count have been updated!\n");
function removeThis() { $ini = eZINI::instance(); $object = $this->object(); $nodeID = $this->attribute('node_id'); $objectID = $object->attribute('id'); if (eZAudit::isAuditEnabled()) { // Set audit params. $objectName = $object->attribute('name'); eZAudit::writeAudit('content-delete', array('Node ID' => $nodeID, 'Object ID' => $objectID, 'Content Name' => $objectName, 'Comment' => 'Removed the current node: eZContentObjectTreeNode::removeNode()')); } $db = eZDB::instance(); $db->begin(); $nodePath = $this->attribute('path_string'); $childrensPath = $nodePath; $pathString = " path_string like '{$childrensPath}%' "; $urlAlias = $this->attribute('url_alias'); // Remove static cache if ($ini->variable('ContentSettings', 'StaticCache') == 'enabled') { $optionArray = array('iniFile' => 'site.ini', 'iniSection' => 'ContentSettings', 'iniVariable' => 'StaticCacheHandler'); $options = new ezpExtensionOptions($optionArray); $staticCacheHandler = eZExtension::getHandlerClass($options); $staticCacheHandler->removeURL("/" . $urlAlias); $staticCacheHandler->generateAlwaysUpdatedCache(); $parent = $this->fetchParent(); } $db->query("DELETE FROM ezcontentobject_tree\n WHERE {$pathString} OR\n path_string = '{$nodePath}'"); // Re-cache parent node if ($ini->variable('ContentSettings', 'StaticCache') == 'enabled') { if ($parent) { $staticCacheHandler->cacheURL("/" . $parent->urlAlias()); } } // Clean up URL alias entries eZURLAliasML::removeByAction('eznode', $nodeID); // Clean up content cache eZContentCacheManager::clearContentCacheIfNeeded($this->attribute('contentobject_id')); // clean up user cache if (in_array($object->attribute('contentclass_id'), eZUser::contentClassIDs())) { eZUser::removeSessionData($objectID); eZUser::purgeUserCacheByUserId($objectID); } $parentNode = $this->attribute('parent'); if (is_object($parentNode)) { eZContentCacheManager::clearContentCacheIfNeeded($parentNode->attribute('contentobject_id')); $parentNode->updateAndStoreModified(); eZNodeAssignment::purgeByParentAndContentObjectID($parentNode->attribute('node_id'), $objectID); } // Clean up policies and limitations eZRole::cleanupByNode($this); // Clean up recent items eZContentBrowseRecent::removeRecentByNodeID($nodeID); // Clean up bookmarks eZContentBrowseBookmark::removeByNodeID($nodeID); // Clean up tip-a-friend counter eZTipafriendCounter::removeForNode($nodeID); // Clean up view counter eZViewCounter::removeCounter($nodeID); $db->commit(); }
/** * {@inheritdoc} */ public function getMostPopular() { // Sanity check, we need eZ Publish classes. if (!class_exists('eZFunctionHandler') or !class_exists('eZViewCounter')) { throw new Exceptions\ProviderFailureException('Cannot use the EzPublishLegacyProvider without eZ Publish.', 404); } // Default to 'article'. $contentClasses = $this->contentClasses; if (empty($contentClasses)) { $contentClasses[] = 'article'; } $limit = $this->limit; if (0 !== $this->offset) { trigger_error('Offset is not supported by EzPublishLegacyProvider', E_USER_NOTICE); } if (0 > $this->offset) { trigger_error('Ascending sort is not supported by EzPublishLegacyProvider', E_USER_NOTICE); } // Retrieve content classes. $contentClasses = \eZFunctionHandler::execute('class', 'list', ['class_filter' => $contentClasses]); $mostPopularArray = []; $names = []; $sortedArray = []; foreach ($contentClasses as $contentClass) { $contentObjectArray = \eZFunctionHandler::execute('content', 'view_top_list', ['class_id' => $contentClass->ID, 'section_id' => $sectionId, 'limit' => $limit]); foreach ($contentObjectArray as $contentObject) { // Fetch view count of current node id. $mostPopularArray[$contentObject->NodeID] = $contentObject; $viewCount = \eZViewCounter::fetch($contentObject->NodeID); if (is_object($viewCount)) { $names[$contentObject->NodeID] = $contentObject->attribute('name'); $sortedArray[$contentObject->NodeID] = $viewCount->Count; // Use as index. } } } // Reverse sort so that things are in order of view count. arsort($sortedArray); $mostPopular = []; foreach ($sortedArray as $nodeId => $count) { if (array_key_exists($nodeId, $mostPopularArray)) { $mostPopular[] = $mostPopularArray[$nodeId]; } } // Finally return our results. return array_map(function ($node) use($names) { $name = $names[$node]; return new Results\Result($node, $name); }, array_slice($mostPopular, 0, $limit)); }
} } foreach (array_keys($topList) as $key) { $nodeID = $topList[$key]['node_id']; /** Iterate over node **/ $contentNode = eZContentObjectTreeNode::fetch($nodeID); /** Content object node missing from database **/ if ($contentNode === null) { $viewCountRemoveRequiredDetected++; if ($troubleshoot && $scriptVerboseLevel >= 3) { $cli->warning("\nFound! Node missing from database. NodeID: " . $nodeID . "\n"); } /** Only modify view count database when needed AND when not in test-only mode **/ if (!$test) { /** Modify objects and publish a new version with the published and modified attribute values modified **/ eZViewCounter::removeCounter($nodeID); $viewCountRemoveCount++; /** Iterate cli script progress tracker **/ $script->iterate($cli, $status); continue; } else { /** Iterate cli script progress tracker **/ $script->iterate($cli, $status); } } } } /** Inform the script user of the results **/ if ($test) { $cli->warning("\n\nTotal nodes found needing to be removed: {$viewCountRemoveRequiredDetected}"); } else {
$object = $childNode->attribute('object'); $objectID = $object->attribute('id'); //$cli->output( "Key: $nodeViewCount\n" ); /** Only iterate over objects with lng in the lat field **/ if ($nodeViewCount >= $threshold) { $viewCountChangeRequiredDetected++; /** Debug verbose output **/ if ($troubleshoot && $scriptVerboseLevel >= 3) { $cli->warning("\nFound! Node with view count equal to or above threshold: " . $nodeUrl . ", NodeID " . $nodeID . "\n"); $notice = "Node view count: {$nodeViewCount}"; $cli->warning($notice); } /** Only modify node view count when needed AND when not in test-only mode **/ if (!$test) { /** Modify objects and publish a new version with the published and modified attribute values modified **/ $viewCounterObject = eZViewCounter::fetch($nodeID); $viewCounterObject->setAttribute('count', $resetNumber); $viewCounterObject->store(); $viewCountChangeCount++; /** Iterate cli script progress tracker **/ $script->iterate($cli, $status); continue; } else { /** Iterate cli script progress tracker **/ $script->iterate($cli, $status); } } else { /** Iterate cli script progress tracker **/ $script->iterate($cli, $status); } }
function addVideo(eZContentObjectTreeNode $node) { $ini = eZINI::instance('xrowsitemap.ini'); $video = new xrowSitemapItemVideo(); $video->title = $node->attribute('name'); $video->categories = array($node->attribute('parent')->attribute('name')); $object = $node->object(); $video->view_count = eZViewCounter::fetch($node->attribute('node_id'))->Count; $video->publication_date = new DateTime('@' . $object->attribute('published')); $dm = $node->attribute('data_map'); foreach ($dm as $attribute) { switch ($attribute->DataTypeString) { case 'xrowmetadata': if ($attribute->hasContent()) { $keywordattribute = $attribute->content(); $video->tags = array_merge($video->tags, $keywordattribute->keywords); } break; case 'ezkeyword': if ($attribute->hasContent()) { $keywordattribute = $attribute->content(); $video->tags = array_merge($video->tags, $keywordattribute->KeywordArray); } break; case 'ezimage': if ($attribute->hasContent()) { $imagedata = $attribute->content(); if ($ini->hasVariable('SitemapSettings', 'ImageAlias')) { $aliasdata = $imagedata->attribute($ini->variable('SitemapSettings', 'ImageAlias')); $video->thumbnail_loc = 'http://' . xrowSitemapTools::domain() . '/' . $aliasdata['url']; } else { $aliasdata = $imagedata->attribute('original'); $video->thumbnail_loc = 'http://' . xrowSitemapTools::domain() . '/' . $aliasdata['url']; } } break; case 'ezmedia': if ($attribute->hasContent()) { $content = $attribute->content(); $uri = "content/download/" . $attribute->attribute('contentobject_id') . '/' . $content->attribute('contentobject_attribute_id') . '/' . $content->attribute('original_filename'); $video->content_loc = 'http://' . xrowSitemapTools::domain() . '/' . $uri; } break; case 'xrowvideo': if ($attribute->hasContent()) { $content = $attribute->content(); $uri = "content/download/" . $content["media"]->attribute->ContentObjectID . '/' . $content["media"]->attribute->ID . '/' . $content["binary"]->OriginalFilename; $video->content_loc = 'http://' . xrowSitemapTools::domain() . '/' . $uri; $video->duration = (int) $content["video"]["duration"]; } break; } switch ($attribute->ContentClassAttributeIdentifier) { case 'description': if ($attribute->hasContent()) { $content = $attribute->content(); $descriptions = substr(strip_tags($content->ContentObjectAttribute->DataText), 0, 2048); $video->description = $descriptions; } break; } } return $video; }