예제 #1
0
 static function clear($node_id)
 {
     $counter = eZViewCounter::fetch($node_id);
     if ($counter != null) {
         $counter->setAttribute('count', 0);
         $counter->store();
     }
 }
    // Support for PathPrefix
    for ($pathPrefixIndex = 0; !$nodeID && $pathPrefixIndex < $pathPrefixesCount; ++$pathPrefixIndex) {
        // 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);
}
 function viewCount()
 {
     $count = eZViewCounter::fetch($this->attribute('node_id'), false);
     return (int) $count['count'];
 }
 /**
  * {@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));
 }
     $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);
     }
 }
예제 #6
0
 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;
 }