error(tra('Expecting three arguments for article-info.')); } $supported = [ 'rating', 'age-second', 'age-hour', 'age-day', 'age-week', 'age-month', 'view-count' ]; if (! in_array($element[2], $supported)) { $this->error(tra('Unsupported property. Supported properties are: ') . implode(', ', $supported)); } if ($prefs['feature_articles'] != 'y') { $this->error(tra('The Articles feature is not activated.')); } $type = $this->evaluateChild($element[0]); $object = $this->evaluateChild($element[1]); $property = $element[2]; if ($type == 'article') { $artlib = TikiLib::lib('art'); $article = $artlib->get_article($object, false); if ($property == 'rating') { return $article['rating']; } elseif ($property == 'view-count') { return $article[ 'nbreads' ]; } elseif (substr($property, 0, 4) == 'age-') { $age = time() - $article['publishDate']; switch ($property) { case 'age-hour': return max(0, floor($age / 3600)); case 'age-day': return max(0, floor($age / (3600 * 24))); case 'age-week': return max(0, floor($age / (3600 * 24 * 7))); case 'age-month': return max(0, floor($age / (3600 * 24 * 30))); default: return max(0, $age); } } } elseif ($type !== 0) { $this->error('Only available for articles.'); } } }