/** * Visit a Block * * @param object BlockSiteComponent $siteComponent * @return mixed * @access public * @since 1/26/09 */ public function visitBlock(BlockSiteComponent $siteComponent) { $view = new Participation_View($siteComponent); $idMgr = Services::getService('Id'); $azMgr = Services::getService('AuthZ'); // get create actions if ($azMgr->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.modify'), $siteComponent->getQualifierId()) == TRUE) { $this->_actions[] = new Participation_CreateAction($view, $siteComponent); } // get comment actions $commentsManager = CommentManager::instance(); $comments = $commentsManager->getAllComments($siteComponent->getAsset(), DESC); while ($comments->hasNext()) { $comment = $comments->next(); if ($azMgr->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.comment'), $siteComponent->getQualifierId()) == TRUE) { $this->_actions[] = new Participation_CommentAction($view, $comment); } } // get history actions $pluginManager = Services::getService('PluginManager'); $plugin = $pluginManager->getPlugin($siteComponent->getAsset()); if ($plugin->supportsVersioning()) { $versions = $plugin->getVersions(); $firstVersion = 0; foreach ($versions as $version) { if ($version->getNumber() != 1) { if ($azMgr->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.modify'), $siteComponent->getQualifierId()) == TRUE) { $this->_actions[] = new Participation_HistoryAction($view, $siteComponent, $version); } } } } }
/** * Constructor * * @param object BlockSiteComponent $block * @return null * @access public * @since 4/3/06 */ function __construct(BlockSiteComponent $block) { $pluginManager = Services::getService('PluginManager'); $this->plugin = $pluginManager->getPlugin($block->getAsset()); $this->agentManager = Services::getService("Agent"); $this->block = $block; }
/** * Visit a Block * * @param object BlockSiteComponent $siteComponent * @return mixed * @access public * @since 8/31/07 */ public function visitBlock(BlockSiteComponent $siteComponent) { // check to see if user is authorized to view block $authZ = Services::getService("AuthZ"); $idManager = Services::getService("Id"); if (!$authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.view_comments"), $idManager->getId($siteComponent->getId()))) { return; } $harmoni = Harmoni::instance(); //get all comments for site component $commentsManager = CommentManager::instance(); $comments = $commentsManager->getAllComments($siteComponent->getAsset()); while ($comments->hasNext()) { $comment = $comments->next(); $item = $this->addItem(new RSSItem()); $item->setTitle($comment->getSubject()); $item->setLink(SiteDispatcher::quickURL("view", "html", array("node" => $siteComponent->getId())) . "#comment_" . $comment->getIdString(), true); $item->setPubDate($comment->getModificationDate()); $agentMgr = Services::getService("Agent"); $agent = $comment->getAuthor(); $item->setAuthor($agent->getDisplayName()); $item->setCommentsLink(SiteDispatcher::quickURL("view", "html", array("node" => $siteComponent->getId()))); $pluginMgr = Services::getService("PluginManager"); $plugin = $pluginMgr->getPlugin($comment->getAsset()); $item->setDescription($plugin->executeAndGetMarkup()); // MediaFile eclosures. try { foreach ($plugin->getRelatedMediaFiles() as $file) { $item->addEnclosure($file->getUrl(), $file->getSize()->value(), $file->getMimeType()); } } catch (UnimplementedException $e) { } } }
/** * Visit a Block * * @param object BlockSiteComponent $siteComponent * @return mixed * @access public * @since 8/31/07 */ public function visitBlock(BlockSiteComponent $siteComponent) { $cm = CommentManager::instance(); if ($cm->getNumComments($siteComponent->getAsset())) { return 1; } else { return 0; } }
/** * Visit a Block * * @param object BlockSiteComponent $siteComponent * @return mixed * @access public * @since 6/11/08 */ public function visitBlock(BlockSiteComponent $siteComponent) { $orig = $siteComponent->getDisplayName(); $new = $this->replacePlaceholders($orig); if ($orig != $new) { $siteComponent->updateDisplayName($new); } // $orig = $siteComponent->getDescription(); // $new = $this->replacePlaceholders($orig); // if ($orig != $new) // $siteComponent->updateDescription($new); $asset = $siteComponent->getAsset(); $orig = $asset->getContent()->asString(); $new = $this->replacePlaceholders($orig); if ($orig != $new) { $asset->updateContent(Blob::withValue($new)); } }
/** * Answer the files attached to a site component. * * @param object BlockSiteComponent $siteComponent * @access protected */ protected function addAttachedMedia(BlockSiteComponent $siteComponent) { $mediaAssetType = new Type('segue', 'edu.middlebury', 'media_file', 'A file that is uploaded to Segue.'); $children = $siteComponent->getAsset()->getAssets(); while ($children->hasNext()) { $child = $children->next(); if ($mediaAssetType->isEqual($child->getAssetType())) { try { $this->addMediaAsset($child); } catch (PermissionDeniedException $e) { } catch (OperationFailedException $e) { } } } }
/** * Visit a Block * * @param object BlockSiteComponent $siteComponent * @return mixed * @access public * @since 8/5/08 */ public function visitBlock(BlockSiteComponent $siteComponent) { if (!$this->firstSeen) { $this->firstSeen = true; } else { $this->blocks++; } // Discussions $cm = CommentManager::instance(); $this->posts += $cm->getNumComments($siteComponent->getAsset()); // Media $mediaAssets = $this->getAllMediaAssets($siteComponent->getAsset()); $this->media += $mediaAssets->count(); }
/** * Rewrite file urls that weren't properly localized. * * @param object BlockSiteComponent $siteComponent * @return void */ protected function rewriteNonlocalFileUrls(BlockSiteComponent $siteComponent) { static $baseUrls; if (empty($baseUrls)) { $baseUrls = array('http://segue.middlebury.edu', 'https://segue.middlebury.edu', 'http://seguecommunity.middlebury.edu', 'https://seguecommunity.middlebury.edu'); foreach (SlotAbstract::getLocationCategories() as $locationCategory) { $baseUrls[] = rtrim(SiteDispatcher::getBaseUrlForLocationCategory($locationCategory), '/'); } $baseUrls = array_unique($baseUrls); } $content = $siteComponent->getAsset()->getContent(); foreach ($baseUrls as $baseUrl) { if (preg_match_all('#[\'"]' . $baseUrl . '/repository/(viewfile|viewfile_flash|viewthumbnail|viewthumbnail_flash)/polyphony-repository___repository_id/edu.middlebury.segue.sites_repository/polyphony-repository___asset_id/([0-9]+)/polyphony-repository___record_id/([0-9]+)(?:polyphony-repository___file_name/(.+))?[\'"]#', $content->asString(), $matches, PREG_SET_ORDER)) { foreach ($matches as $m) { $urlParts = array('module' => 'repository', 'action' => $m[1], 'polyphony-repository___repository_id' => 'edu.middlebury.segue.sites_repository', 'polyphony-repository___asset_id' => $m[2], 'polyphony-repository___record_id' => $m[3]); if (!empty($m[4])) { $urlParts['polyphony-repository___file_name'] = $m[4]; } else { if ($m[1] == 'viewfile') { try { $file = MediaFile::withIdStrings('edu.middlebury.segue.sites_repository', $m[2], $m[3]); $urlParts['polyphony-repository___file_name'] = $file->getFilename(); } catch (UnknownIdException $e) { } } } $url = http_build_query($urlParts, '', '&'); $content->_setValue(str_replace($m[0], '"' . '[[localurl:' . $url . ']]' . '"', $content->value())); } } } }
/** * Apply the comments to a block * * @param BlockSiteComponent $siteComponent * @param object DOMElement $element * @return void * @access protected * @since 1/24/08 */ protected function applyComments(BlockSiteComponent $siteComponent, DOMElement $element) { $asset = $siteComponent->getAsset(); $commentMgr = CommentManager::instance(); $commentElements = $this->xpath->query('./comments/Comment', $element); foreach ($commentElements as $commentElement) { $comment = $commentMgr->createRootComment($asset, new Type($this->getSingleNode("./type/domain/text()", $commentElement)->nodeValue, $this->getSingleNode("./type/authority/text()", $commentElement)->nodeValue, $this->getSingleNode("./type/keyword/text()", $commentElement)->nodeValue)); $this->applyCommentData($comment, $commentElement); } }