/** * Get the readme text from the specified folder. */ public function fromFolder($folder) { /** @var FolderModel $folderModel */ $folderModel = MidasLoader::loadModel('Folder'); /** @var ItemModel $itemModel */ $itemModel = MidasLoader::loadModel('Item'); $readmeItem = null; $candidates = array('readme.md', 'readme.txt', 'readme'); foreach ($candidates as $candidate) { $readmeItem = $folderModel->getItemByName($folder, $candidate, false); if ($readmeItem != null) { break; } } if ($readmeItem == null) { return array('text' => ''); } $revisionDao = $itemModel->getLastRevision($readmeItem); if ($revisionDao === false) { return array('text' => ''); } $bitstreams = $revisionDao->getBitstreams(); if (count($bitstreams) === 0) { return array('text' => ''); } $bitstream = $bitstreams[0]; $path = $bitstream->getAssetstore()->getPath() . '/' . $bitstream->getPath(); $contents = file_get_contents($path); MidasLoader::loadComponent('Utility'); $parsedContents = UtilityComponent::markdown(htmlspecialchars($contents, ENT_COMPAT, 'UTF-8')); return array('text' => $parsedContents); }
/** index action */ public function indexAction() { $textDaos = $this->Landingpage_Text->getAll(); if (isset($textDaos[0])) { $textDao = $textDaos[0]; $this->view->landingText = UtilityComponent::markdown(htmlspecialchars($textDao->getText(), ENT_COMPAT, 'UTF-8')); } else { $this->callCoreAction(); } }
/** * Markdown view helper. * * @param string $text Markdown or Markdown Extra text * @return string HTML text */ public function markdown($text) { return UtilityComponent::markdown(htmlspecialchars($text, ENT_COMPAT, 'UTF-8')); }
/** View a community */ public function viewAction() { $this->view->Utility = $this->Component->Utility; $this->view->Date = $this->Component->Date; $communityId = $this->getParam('communityId'); if (!isset($communityId) || !is_numeric($communityId)) { throw new Zend_Exception('Community ID should be a number'); } $communityDao = $this->Community->load($communityId); if ($communityDao === false || !$this->Community->policyCheck($communityDao, $this->userSession->Dao)) { throw new Zend_Exception("This community doesn't exist or you don't have the permissions.", 403); } $joinCommunity = $this->getParam('joinCommunity'); $leaveCommunity = $this->getParam('leaveCommunity'); $canJoin = $communityDao->getCanJoin() == MIDAS_COMMUNITY_CAN_JOIN; $this->view->isInvited = $this->CommunityInvitation->isInvited($communityDao, $this->userSession->Dao); $this->view->canJoin = $canJoin; if ($this->userSession->Dao != null && isset($joinCommunity) && ($canJoin || $this->view->isInvited)) { $member_group = $communityDao->getMemberGroup(); $this->Group->addUser($member_group, $this->userSession->Dao); Zend_Registry::get('notifier')->callback('CALLBACK_CORE_USER_JOINED_COMMUNITY', array('user' => $this->userSession->Dao, 'community' => $communityDao)); if ($this->view->isInvited) { $invitationDao = $this->CommunityInvitation->isInvited($communityDao, $this->userSession->Dao, true); if ($invitationDao->getGroupId() !== $member_group->getKey()) { // If user is invited to something besides the member group, we should add them to that group also $this->Group->addUser($invitationDao->getGroup(), $this->userSession->Dao); } $this->CommunityInvitation->removeInvitation($communityDao, $this->userSession->Dao); } } if ($this->userSession->Dao != null && isset($leaveCommunity)) { $member_group = $communityDao->getMemberGroup(); $this->Group->removeUser($member_group, $this->userSession->Dao); $this->redirect('/community'); } $this->Community->incrementViewCount($communityDao); $this->view->communityDao = $communityDao; $this->view->information = array(); $this->view->feeds = $this->Feed->getFeedsByCommunity($this->userSession->Dao, $communityDao); $group_member = $communityDao->getMemberGroup(); $this->view->members = $group_member->getUsers(); $this->view->mainFolder = $communityDao->getFolder(); $this->view->folders = $this->Folder->getChildrenFoldersFiltered($this->view->mainFolder, $this->userSession->Dao, MIDAS_POLICY_READ); $this->view->items = $this->Folder->getItemsFiltered($this->view->mainFolder, $this->userSession->Dao, MIDAS_POLICY_READ); $this->view->isMember = false; if ($this->userSession->Dao != null) { foreach ($this->view->members as $member) { if ($member->getKey() == $this->userSession->Dao->getKey()) { $this->view->isMember = true; break; } } } $this->view->isModerator = $this->Community->policyCheck($communityDao, $this->userSession->Dao, MIDAS_POLICY_WRITE); $this->view->isAdmin = $this->Community->policyCheck($communityDao, $this->userSession->Dao, MIDAS_POLICY_ADMIN); $this->view->json['community'] = $communityDao->toArray(); $this->view->json['community']['sendInvitation'] = $this->t('Send invitation'); if ($this->view->isMember) { $this->view->shareItems = $this->Item->getSharedToCommunity($communityDao); } $this->view->title .= ' - ' . $communityDao->getName(); $this->view->metaDescription = substr(UtilityComponent::markdown(htmlspecialchars($communityDao->getDescription(), ENT_COMPAT, 'UTF-8')), 0, 160); $this->view->customJSs = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_GET_COMMUNITY_VIEW_JSS', array()); $this->view->customCSSs = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_GET_COMMUNITY_VIEW_CSSS', array()); $this->addDynamicHelp('#tabDataLink', 'Public and Private Data hosted by the community.'); $this->addDynamicHelp('#tabFeedLink', 'What\'s new?'); $this->addDynamicHelp('#tabInfoLink', 'Description of the community.'); $this->addDynamicHelp('#tabSharedLink', 'Data shared to the member of the community.'); $this->view->extraHtml = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_GET_COMMUNITY_VIEW_EXTRA_HTML', array('community' => $communityDao)); $this->view->customTabs = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_GET_COMMUNITY_VIEW_TABS', array('community' => $communityDao)); $this->view->customManageActions = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_GET_COMMUNITY_VIEW_ADMIN_ACTIONS', array('community' => $communityDao)); }