public function getPresenters() { if (!empty(self::$presenters)) { return self::$presenters; } $presenters = array("video" => "BASE_ContentPresenterVideo", "image" => "BASE_ContentPresenterImage", "image_content" => "BASE_ContentPresenterImageContent", "content" => "BASE_ContentPresenterContent", "text" => "BASE_ContentPresenterText"); $event = new BASE_CLASS_EventCollector("content.collect_presenters"); OW::getEventManager()->trigger($event); foreach ($event->getData() as $format) { $presenters[$format["name"]] = $format["class"]; } self::$presenters = $presenters; return self::$presenters; }
public function approve($params) { $ownerId = empty($params["userId"]) ? null : $params["userId"]; $this->setPageTitle(OW::getLanguage()->text("base", "moderation_tools")); $this->setPageHeading(OW::getLanguage()->text("base", "moderation_tools")); if (empty($ownerId)) { $this->onlyModerators(); $menu = $this->getMenu(); if ($menu === null) { $this->redirect(OW::getRouter()->urlForRoute("base.moderation_tools")); } $menu->deactivateElements(); $menuItem = $menu->getElement("approve"); if ($menuItem) { $menuItem->setActive(true); } $this->addComponent("menu", $menu); } else { if ($ownerId != OW::getUser()->getId()) { throw new Redirect403Exception(); } $this->setPageHeading(OW::getLanguage()->text("moderation", "console_pending_approval")); } $groups = MODERATION_BOL_Service::getInstance()->getContentGroupsWithCount($ownerId); if (!empty($params["group"]) && empty($groups[$params["group"]])) { if ($ownerId) { return $this->noItems(); } $this->redirect(OW::getRouter()->urlForRoute("moderation.approve_index")); } $currentGroup = empty($params["group"]) ? reset($groups) : $groups[$params["group"]]; if (empty($currentGroup)) { if ($ownerId) { return $this->noItems(); } $this->redirect(OW::getRouter()->urlForRoute("base.moderation_tools")); } $contentMenu = new BASE_CMP_VerticalMenu(); $sideMenuOrder = 1; foreach ($groups as $groupKey => $group) { $item = new BASE_VerticalMenuItem(); $item->setKey($groupKey); $item->setUrl($group["url"]); $item->setNumber($group["count"]); $item->setLabel($group["label"]); $item->setActive($currentGroup["name"] == $group["name"]); $item->setOrder($sideMenuOrder++); $contentMenu->addElement($item); } $this->addComponent("contentMenu", $contentMenu); // Paging $page = isset($_GET['page']) && intval($_GET['page']) > 0 ? $_GET['page'] : 1; $perPage = self::ITEMS_PER_PAGE; $limit = array(($page - 1) * $perPage, $perPage); $this->addComponent("paging", new BASE_CMP_Paging($page, ceil($currentGroup["count"] / $perPage), 5)); // List $entityRecords = MODERATION_BOL_Service::getInstance()->findEntityListByTypes($currentGroup["entityTypes"], $limit, $ownerId); $entityList = array(); $userIds = array(); foreach ($entityRecords as $record) { $entityList[$record->entityType] = empty($entityList[$record->entityType]) ? array() : $entityList[$record->entityType]; $entityList[$record->entityType][] = $record->entityId; } $contentData = array(); foreach ($entityList as $entityType => $entityIds) { $infoList = BOL_ContentService::getInstance()->getContentList($entityType, $entityIds); foreach ($infoList as $entityId => $info) { $userIds[] = $info["userId"]; $contentData[$entityType . ':' . $entityId] = $info; } } $avatarData = BOL_AvatarService::getInstance()->getDataForUserAvatars($userIds); $tplRecords = array(); foreach ($entityRecords as $record) { $recordData = $record->getData(); $content = $contentData[$record->entityType . ":" . $record->entityId]; $contentPresenter = new BASE_CMP_ContentPresenter($content); $label = empty($content["label"]) ? $content["typeInfo"]["entityLabel"] : $content["label"]; $string = null; if (!isset($recordData["string"])) { $string = OW::getLanguage()->text("moderation", "list_string_" . $recordData["reason"], array("content" => strtolower($label))); } else { if (is_string($recordData["string"])) { $string = $recordData["string"]; } else { list($langPrefix, $langKey) = explode("+", $recordData["string"]["key"]); $langVars = empty($recordData["string"]["vars"]) ? array() : $recordData["string"]["vars"]; $string = OW::getLanguage()->text($langPrefix, $langKey, $langVars); } } $tplRecords[] = array("content" => $contentPresenter->render(), "avatar" => $avatarData[$content["userId"]], "string" => $string, "contentLabel" => strtolower($label), "entityType" => $record->entityType, "entityId" => $record->entityId, "reason" => $recordData["reason"], "time" => UTIL_DateTime::formatDate($record->timeStamp)); } $uniqId = uniqid("m-"); $this->assign("uniqId", $uniqId); $this->assign("items", $tplRecords); $this->assign("group", $currentGroup); $this->assign("actions", array("delete" => true, "approve" => empty($ownerId))); $this->assign("responderUrl", OW::getRouter()->urlFor(__CLASS__, "responder", array("group" => $currentGroup["name"], "userId" => $ownerId))); OW::getLanguage()->addKeyForJs("base", "are_you_sure"); OW::getLanguage()->addKeyForJs("base", "moderation_delete_confirmation"); OW::getLanguage()->addKeyForJs("base", "moderation_delete_multiple_confirmation"); OW::getLanguage()->addKeyForJs("base", "moderation_no_items_warning"); $options = array("groupLabel" => strtolower($currentGroup["label"])); $js = UTIL_JsGenerator::newInstance(); $js->callFunction("MODERATION_ApproveInit", array($uniqId, $options)); OW::getDocument()->addOnloadScript($js); }
public function flags($params) { $this->onlyModerators(); $this->setPageTitle(OW::getLanguage()->text("base", "moderation_tools")); $this->setPageHeading(OW::getLanguage()->text("base", "moderation_tools")); $menu = $this->getMenu(); if ($menu === null) { $this->redirect(OW::getRouter()->urlForRoute("base.moderation_tools")); } $menu->deactivateElements(); $menuItem = $menu->getElement("flags"); if ($menuItem) { $menuItem->setActive(true); } $this->addComponent("menu", $menu); $groups = BOL_FlagService::getInstance()->getContentGroupsWithCount(); if (!empty($params["group"]) && empty($groups[$params["group"]])) { $this->redirect(OW::getRouter()->urlForRoute("base.moderation_flags_index")); } $currentGroup = empty($params["group"]) ? reset($groups) : $groups[$params["group"]]; if (empty($currentGroup)) { $this->redirect(OW::getRouter()->urlForRoute("base.moderation_tools")); } $contentMenu = new BASE_CMP_VerticalMenu(); $sideMenuOrder = 1; foreach ($groups as $groupKey => $group) { $item = new BASE_VerticalMenuItem(); $item->setKey($groupKey); $item->setUrl($group["url"]); $item->setNumber($group["count"]); $item->setLabel($group["label"]); $item->setActive($currentGroup["name"] == $group["name"]); $item->setOrder($sideMenuOrder++); $contentMenu->addElement($item); } $this->addComponent("contentMenu", $contentMenu); // Paging $page = isset($_GET['page']) && intval($_GET['page']) > 0 ? $_GET['page'] : 1; $perPage = self::ITEMS_PER_PAGE; $limit = array(($page - 1) * $perPage, $perPage); $this->addComponent("paging", new BASE_CMP_Paging($page, ceil($currentGroup["count"] / $perPage), 5)); // List $flags = BOL_FlagService::getInstance()->findFlagsByEntityTypeList($currentGroup["entityTypes"], $limit); $entityList = array(); $userIds = array(); $reporterIds = array(); foreach ($flags as $flag) { $entityList[$flag->entityType] = empty($entityList[$flag->entityType]) ? array() : $entityList[$flag->entityType]; $entityList[$flag->entityType][] = $flag->entityId; $reporterIds[$flag->userId] = $flag->userId; } $contentData = array(); foreach ($entityList as $entityType => $entityIds) { $infoList = BOL_ContentService::getInstance()->getContentList($entityType, $entityIds); foreach ($infoList as $entityId => $info) { $userIds[] = $info["userId"]; $contentData[$entityType . ':' . $entityId] = $info; } } $avatarData = BOL_AvatarService::getInstance()->getDataForUserAvatars($userIds); $reporterUrls = BOL_UserService::getInstance()->getUserUrlsForList($reporterIds); $reporterNames = BOL_UserService::getInstance()->getDisplayNamesForList($reporterIds); $tplFlags = array(); foreach ($flags as $flag) { $content = $contentData[$flag->entityType . ":" . $flag->entityId]; $contentPresenter = new BASE_CMP_ContentPresenter($content); $userName = $avatarData[$content["userId"]]["title"]; $userUrl = $avatarData[$content["userId"]]["url"]; $label = empty($content["label"]) ? $content["typeInfo"]["entityLabel"] : $content["label"]; $tplFlags[] = array("content" => $contentPresenter->render(), "avatar" => $avatarData[$content["userId"]], "string" => OW::getLanguage()->text("base", "moderation_flags_item_string", array("userName" => $userName, "userUrl" => $userUrl, "content" => strtolower($label))), "contentLabel" => strtolower($label), "entityType" => $flag->entityType, "entityId" => $flag->entityId, "time" => UTIL_DateTime::formatDate($flag->timeStamp), "reason" => $flag->reason, "reporter" => array("url" => $reporterUrls[$flag->userId], "name" => $reporterNames[$flag->userId])); } $uniqId = uniqid("m-"); $this->assign("uniqId", $uniqId); $this->assign("flags", $tplFlags); $this->assign("group", $currentGroup); $this->assign("responderUrl", OW::getRouter()->urlFor(__CLASS__, "flagsResponder", array("group" => $currentGroup["name"]))); OW::getLanguage()->addKeyForJs("base", "are_you_sure"); OW::getLanguage()->addKeyForJs("base", "moderation_delete_confirmation"); OW::getLanguage()->addKeyForJs("base", "moderation_delete_multiple_confirmation"); OW::getLanguage()->addKeyForJs("base", "moderation_no_items_warning"); $options = array("groupLabel" => strtolower($currentGroup["label"])); $js = UTIL_JsGenerator::newInstance(); $js->callFunction("MODERATION_FlagsInit", array($uniqId, $options)); OW::getDocument()->addOnloadScript($js); }