* @license PHP License * @package WB * @subpackage datasource */ WBClass::load('WBDatasource_Sitemap' ); /** * Datasource Sitemap VFS * * Add recent VFS files to sitemap * * @version 1.0.1 * @package WB * @subpackage datasource */ class WBDatasource_Sitemap_VFS extends WBDatasource_Sitemap { /** * VFS config * @var WBConfig */ private $conf; /** * table access * @var WBDatasource_Table */ private $table; /** * Find all the URLs * * Get recent blog posts */ public function find() { // configure $this->conf = WBClass::create('WBConfig'); $this->conf->load('vfs'); $pathFormat = $this->conf->get('sitemap/vfs/path', 'media/%obscureid/%name'); $priority = floatval($this->conf->get('sitemap/vfs/priority', 0.7)); $limit = intval($this->conf->get('sitemap/vfs/limit', 500)); $mimemajor = $this->conf->get('sitemap/vfs/mimemajor', array('image', 'video')); $this->table = WBClass::create('WBDatasource_Table'); $list = $this->getIds($limit, $mimemajor); $search = array( '%obscureid', '%name' ); $file = WBClass::create('WBVFS_File'); /** @var $file WBVFS_File */ $this->setPriority($priority); foreach ($list as $l) { $file = $file->loadById($l); if (!$file->isOK()) { continue; } /** * @todo check for file references? */ $major = $file->getMime(WBVFS_File::MIME_MAJOR); // add vfs file view page $replace = array( $file->getObscureId(), urlencode($file->getName()) ); $path = str_replace($search, $replace, $pathFormat); $snip = array(); $snip[] = sprintf(' <%s:%1$s>', $major); $snip[] = sprintf(' <%s:title>', $major, $file->getName()); switch ($major) { case 'image': $snip[] = sprintf(' <%s:loc>[[PROTOCOL]]://[[SERVER]][[SERVICE_FILE]]%s', $major, $file->getUri()); $snip[] = sprintf(' <%s:caption>', $major, $file->getDescription()); break; case 'video': $created = strtotime($file->getCreated()); $snip[] = sprintf(' <%s:publication_date>%s', $major, strftime('%Y-%m-%dT%H:%M:%S+00:00', $created)); $snip[] = sprintf(' <%s:content_loc>[[PROTOCOL]]://[[SERVER]][[SERVICE_FILE]]%s', $major, $file->getUri()); $snip[] = sprintf(' <%s:thumbnail_loc>[[PROTOCOL]]://[[SERVER]][[SERVICE_FILE]]%s', $major, $file->getUri('image')); $snip[] = sprintf(' <%s:description>', $major, $file->getDescription()); $snip[] = sprintf(' <%s:duration>%d', $major, round($file->getInfo('seconds'))); $snip[] = sprintf(' <%s:view_count>%d', $major, $file->getViews()); break; default: continue 2; break; } $snip[] = sprintf(' ', $major); $this->setPath($path, implode("\n", $snip)); $this->notify(); } WBDatasource_Table::flushCache(); } /** * Get ids of recent media files * * Order by created (desc) and select all media files that have a description. * If list of major mimetypes is given, use it as filter * * @param int $limit * @param array $mimemajor * @return array */ private function getIds($limit, $mimemajor = array()) { // get list $opt = array( 'limit' => $limit, 'order' => array( 'field' => 'created', 'asc' => 0 ) ); $clause = array(); // description is required $clause[] = array( 'field' => 'description', 'relation' => 'not', 'value' => '' ); // just a view mime-types if (!empty($mimemajor)) { $clause[] = array( 'field' => 'mimemajor', 'relation' => 'IN', 'value' => $mimemajor ); } return $this->table->getIds('vfsfile', null, $clause, $opt); } }