public function initializeForCommand() { $this->feeds = $this->loadFeedData(); switch ($this->command) { case 'sections': $this->setResponse(VideoModuleUtils::getSectionsFromFeeds($this->feeds)); $this->setResponseVersion($this->requestedVersion); break; case 'videos': case 'search': // videos commands requires one argument: section. // search requires two arguments: section and q (query). $section = $this->getArg('section'); $controller = $this->getFeed($section); $videos = array(); // TODO: this isn't the right place to hard code paging limits if ($this->command == 'search') { $limit = 20; $query = $this->getArg('q'); if ($this->legacyController) { $items = $controller->search($query, 0, $limit); } else { $controller->setLimit($limit); $items = $controller->search($query); } } else { $limit = 50; if ($this->legacyController) { $items = $controller->items(0, 50); } else { $controller->setLimit($limit); $items = $controller->items(); } } foreach ($items as $video) { $videos[] = $this->arrayFromVideo($video); } $this->setResponse($videos); $this->setResponseVersion($this->requestedVersion); break; case 'detail': $section = $this->getArg('section'); $controller = $this->getFeed($section); $videoid = $this->getArg('videoid'); if ($video = $controller->getItem($videoid)) { $result = $this->arrayFromVideo($video); $this->setResponse($result); $this->setResponseVersion($this->requestedVersion); } else { $this->throwError(new KurogoError(1, "Video Not Found", "Video not found")); } break; default: $this->invalidCommand(); break; } }
public static function getListItemForVideo(VideoObject $video, $section) { $desc = $video->getDescription(); return array( 'title'=>$video->getTitle(), 'subtitle'=> "(" . VideoModuleUtils::getDuration($video->getDuration()) . ") " . $desc, 'imgWidth'=>120, 'imgHeight'=>100, 'img'=>$video->getImage() ); }
public function initializeForCommand() { $this->feeds = $this->loadFeedData(); switch ($this->command) { case 'sections': error_log(print_r(VideoModuleUtils::getSectionsFromFeeds($this->feeds), true)); $this->setResponse(VideoModuleUtils::getSectionsFromFeeds($this->feeds)); $this->setResponseVersion(1); break; case 'videos': case 'search': // videos commands requires one argument: section. // search requires two arguments: section and q (query). $section = $this->getArg('section'); $query = $this->getArg('q'); $feedData = $this->feeds[$section]; $controller = DataController::factory($feedData['CONTROLLER_CLASS'], $feedData); $totalItems = $controller->getTotalItems(); $videos = array(); if ($this->command == 'search') { $items = $controller->search($query, 0, 20); } else { $items = $controller->items(0, 50); } foreach ($items as $video) { $videos[] = VideoAPIModule::cleanVideoArray((array)$video); } $this->setResponse($videos); $this->setResponseVersion(1); break; default: $this->invalidCommand(); break; } }
protected function initializeForPage() { if ($this->pagetype == 'basic') { return; } if (count($this->feeds) == 0) { throw new KurogoConfigurationException("No video feeds configured"); } // Categories / Sections $section = $this->getArg('section', $this->getDefaultSection()); if (!isset($this->feeds[$section])) { $section = $this->getDefaultSection(); } $this->assign('currentSection', $section); $this->assign('sections', VideoModuleUtils::getSectionsFromFeeds($this->feeds)); $controller = $this->getFeed($section); $this->assign('feedData', $this->feeds[$section]); switch ($this->page) { case 'pane': if ($this->ajaxContentLoad) { $start = 0; $maxPerPage = $this->getOptionalModuleVar('MAX_PANE_RESULTS', 5); $data = array('noBreadcrumbs' => true, 'section' => $section); if ($this->legacyController) { $items = $controller->items($start, $maxPerPage); } else { $controller->setStart($start); $controller->setLimit($maxPerPage); $items = $controller->items(); } $videos = array(); foreach ($items as $video) { $videos[] = $this->linkForItem($video, $data); } foreach ($videos as $i => $video) { $videos[$i]['url'] = $this->buildURL('index') . '#' . urlencode(FULL_URL_PREFIX . ltrim($video['url'], '/')); } $this->assign('stories', $videos); } $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js'); $this->addInternalJavascript('/common/javascript/lib/paneStories.js'); break; case 'search': case 'index': $maxPerPage = $this->getOptionalModuleVar('MAX_RESULTS', 10); $start = $this->getArg('start', 0); if (!$this->legacyController) { $controller->setStart($start); $controller->setLimit($maxPerPage); } if ($this->page == 'search') { if ($filter = $this->getArg('filter')) { $searchTerms = trim($filter); $this->setLogData($searchTerms); if ($this->legacyController) { $items = $controller->search($searchTerms, $start, $maxPerPage); } else { $items = $controller->search($searchTerms); } $this->assign('searchTerms', $searchTerms); } else { $this->redirectTo('index', array('section' => $section), false); } } else { $this->setLogData($section, $controller->getTitle()); if ($this->legacyController) { $items = $controller->items($start, $maxPerPage); } else { $items = $controller->items(); } } $totalItems = $controller->getTotalItems(); $videos = array(); foreach ($items as $video) { $videos[] = $this->linkForItem($video, array('section' => $section)); } $this->assign('videos', $videos); $this->assign('totalItems', $totalItems); $previousURL = null; $nextURL = null; if ($totalItems > $maxPerPage) { $args = $this->args; if ($start > 0) { $args['start'] = $start - $maxPerPage; $previousURL = $this->buildBreadcrumbURL($this->page, $args, false); } if ($totalItems - $start > $maxPerPage) { $args['start'] = $start + $maxPerPage; $nextURL = $this->buildBreadcrumbURL($this->page, $args, false); } } /* only assign section if it's the search page, otherwise section comes from select box */ if ($this->page == 'search') { $hiddenArgs = array('section' => $section); } else { $hiddenArgs = array(); } $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js'); $this->addOnLoad('setupVideosListing();'); $this->assign('placeholder', $this->getLocalizedString('SEARCH_MODULE', $this->getModuleName())); $this->assign('start', $start); $this->assign('previousURL', $previousURL); $this->assign('nextURL', $nextURL); $this->assign('hiddenArgs', $hiddenArgs); $this->assign('maxPerPage', $maxPerPage); if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) { $this->generateBookmarkLink(); } break; case 'bookmarks': if (!$this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) { $this->redirectTo('index'); } $controllerCache = array($section => $controller); $videos = array(); foreach ($this->getBookmarks() as $aBookmark) { if (!$aBookmark) { continue; } parse_str(stripslashes($aBookmark), $params); if (isset($params['section'], $this->feeds[$params['section']], $params['videoid'])) { if (!isset($controllerCache[$params['section']])) { $controllerCache[$params['section']] = $this->getFeed($params['section']); } if ($video = $controllerCache[$params['section']]->getItem($params['videoid'])) { $videos[] = $this->linkForItem($video, $params); } } } $this->assign('videos', $videos); $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js'); $this->addOnLoad('setupVideosListing();'); break; case 'detail': $videoid = $this->getArg('videoid'); if ($video = $controller->getItem($videoid)) { $this->setLogData($videoid, $video->getTitle()); $this->setTemplatePage('detail-' . $video->getType()); if ($video->canPlay(Kurogo::deviceClassifier())) { $this->assign('videoTitle', $video->getTitle()); $this->assign('videoid', $video->getID()); $this->assign('videoStreamingURL', $video->getStreamingURL()); $this->assign('videoStillImage', $video->getStillFrameImage()); $this->assign('videoDescription', $video->getDescription()); $this->assign('videoAuthor', $video->getAuthor()); $this->assign('videoDate', $video->getPublished()->format('M j, Y')); $body = $video->getDescription() . "\n\n" . $video->getURL(); if ($this->getOptionalModuleVar('SHARING_ENABLED', 1)) { $this->assign('shareEmailURL', $this->buildMailToLink("", $video->getTitle(), $body)); $this->assign('shareTitle', 'Share this video'); $this->assign('videoURL', $video->getURL()); $this->assign('shareRemark', $video->getTitle()); } // Bookmark if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) { $cookieParams = array('section' => $section, 'videoid' => $videoid); $cookieID = http_build_query($cookieParams); $this->generateBookmarkOptions($cookieID); } } else { $this->setTemplatePage('videoError.tpl'); } } else { $this->redirectTo('index', array('section' => $section), false); } break; } }
protected function initializeForPage() { if ($this->pagetype=='basic') { return; } if (count($this->feeds)==0) { throw new Exception("No video feeds configured"); } // Categories / Sections $section = $this->getArg('section'); if (!isset($this->feeds[$section])) { $section = key($this->feeds); } $feedData = $this->feeds[$section]; $this->assign('currentSection', $section); $this->assign('sections' , VideoModuleUtils::getSectionsFromFeeds($this->feeds)); $this->assign('feedData' , $feedData); $controller = DataController::factory($feedData['CONTROLLER_CLASS'], $feedData); switch ($this->page) { case 'pane': $start = 0; $maxPerPage = $this->getOptionalModuleVar('MAX_RESULTS', 10); $items = $controller->items($start, $maxPerPage); $videos = array(); foreach ($items as $video) { $videos[] = $this->getListItemForVideo($video, $section, true); } $this->assign('videos', $videos); break; case 'search': case 'index': $maxPerPage = $this->getOptionalModuleVar('MAX_RESULTS', 10); $start = $this->getArg('start', 0); if ($this->page == 'search') { if ($filter = $this->getArg('filter')) { $searchTerms = trim($filter); $items = $controller->search($searchTerms, $start, $maxPerPage); $this->assign('searchTerms', $searchTerms); } else { $this->redirectTo('index', array('section'=>$section), false); } } else { $items = $controller->items($start, $maxPerPage); } $totalItems = $controller->getTotalItems(); $videos = array(); foreach ($items as $video) { $videos[] = $this->getListItemForVideo($video, $section); } $this->assign('videos', $videos); $this->assign('totalItems', $totalItems); $previousURL = null; $nextURL = null; if ($totalItems > $maxPerPage) { $args = $this->args; if ($start > 0) { $args['start'] = $start - $maxPerPage; $previousURL = $this->buildBreadcrumbURL($this->page, $args, false); } if (($totalItems - $start) > $maxPerPage) { $args['start'] = $start + $maxPerPage; $nextURL = $this->buildBreadcrumbURL($this->page, $args, false); } } $hiddenArgs = array( 'section'=>$section ); $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js'); $this->addOnLoad('setupVideosListing();'); $this->assign('start', $start); $this->assign('previousURL', $previousURL); $this->assign('nextURL', $nextURL); $this->assign('hiddenArgs', $hiddenArgs); $this->assign('maxPerPage', $maxPerPage); $this->generateBookmarkLink(); break; case 'bookmarks': $videos_bkms = array(); foreach ($this->getBookmarks() as $aBookmark) { if ($aBookmark) { // prevent counting empty string $titles = $this->getTitleForBookmark($aBookmark); $subtitle = count($titles) > 1 ? $titles[1] : null; $videos_bkms[] = array( 'title' => $titles[0], 'subtitle' => $subtitle, 'url' => $this->detailURLForBookmark($aBookmark), ); } } $this->assign('videos', $videos_bkms); break; case 'detail': $videoid = $this->getArg('videoid'); if ($video = $controller->getItem($videoid)) { $this->setTemplatePage('detail-' . $video->getType()); $this->assign('videoTitle', $video->getTitle()); $this->assign('videoURL', $video->getURL()); $this->assign('videoid', $video->getID()); $this->assign('videoDescription', $video->getDescription()); $this->assign('videoAuthor' , $video->getAuthor()); $this->assign('videoDate' , $video->getPublished()->format('M n, Y')); $body = $video->getDescription() . "\n\n" . $video->getURL(); $this->assign('shareEmailURL', $this->buildMailToLink("", $video->getTitle(), $body)); $this->assign('videoURL', $video->getURL()); $this->assign('shareRemark', $video->getTitle()); // Bookmark $cookieParams = array( 'section' => $section, 'title' => $video->getTitle(), 'videoid' => $videoid ); $cookieID = http_build_query($cookieParams); $this->generateBookmarkOptions($cookieID); } else { $this->redirectTo('index', array('section'=>$section),false); } break; } }