/** * On before render * * @return void */ public function onBeforeRender() { // get all registered content groups $contentGroups = BOL_ContentService::getInstance()->getContentGroups(); // check the received group if (!array_key_exists($this->defaultContentGroup, $contentGroups)) { $this->setVisible(false); return false; } // get all group's entity types // e.g. forum-topic, forum-post, etc $entityTypes = $contentGroups[$this->defaultContentGroup]['entityTypes']; // TODO: Delete me or fix in a next version!!! if (in_array('forum-post', $entityTypes)) { $key = array_search('forum-post', $entityTypes); unset($entityTypes[$key]); } // get detailed content types info $contentTypes = BOL_ContentService::getInstance()->getContentTypes(); // get entity labels $entityLabels = array(); foreach ($entityTypes as $entityType) { $entityLabels[$entityType] = $contentTypes[$entityType]['entityLabel']; } // register components $this->addComponent('statistics', new BASE_CMP_SiteStatistic('content-statistics-chart', $entityTypes, $entityLabels, $this->defaultPeriod)); }
/** * Returns an instance of class (singleton pattern implementation). * * @return BOL_ContentService */ public static function getInstance() { if (self::$classInstance === null) { self::$classInstance = new self(); } return self::$classInstance; }
public function flag() { if (!OW::getUser()->isAuthenticated()) { return; } $entityType = $_POST["entityType"]; $entityId = $_POST["entityId"]; $data = BOL_ContentService::getInstance()->getContent($entityType, $entityId); $ownerId = $data["userId"]; $userId = OW::getUser()->getId(); if ($ownerId == $userId) { exit(json_encode(array('result' => 'success', 'js' => 'OW.error("' . OW::getLanguage()->text('base', 'flag_own_content_not_accepted') . '")'))); } $service = BOL_FlagService::getInstance(); $service->addFlag($entityType, $entityId, $_POST['reason'], $userId); exit(json_encode(array('result' => 'success', 'js' => 'OW.info("' . OW::getLanguage()->text('base', 'flag_accepted') . '")'))); }
protected function processImage() { $imageSet =& $this->content["image"]; if (is_string($imageSet)) { $imageSet = array("fullsize" => $imageSet); } // Processing image data to ensure all image types are defined $contentDefaults = BOL_ContentService::getInstance()->_contentDataDefaults(); $imageTypes = array_keys($contentDefaults["image"]); $imageTypesCount = count($imageTypes); $filledType = null; for ($typeIndex = 0; $typeIndex < $imageTypesCount * 2; $typeIndex++) { $imageType = $imageTypes[$typeIndex >= $imageTypesCount ? $imageTypesCount - ($typeIndex - $imageTypesCount) - 1 : $typeIndex]; $filledType = empty($imageSet[$imageType]) ? $filledType : $imageType; if ($filledType && empty($imageSet[$imageType])) { $imageSet[$imageType] = $imageSet[$filledType]; } } }
public function getContentTypeListWithCount() { $contentTypes = BOL_ContentService::getInstance()->getContentTypes(); $entityTypes = array_keys($contentTypes); $counts = $this->findCountForEntityTypeList($entityTypes); $out = array(); foreach ($counts as $entityType => $count) { if (!OW::getUser()->isAuthorized($contentTypes[$entityType]["authorizationGroup"])) { continue; } $out[$entityType] = $contentTypes[$entityType]; $out[$entityType]["count"] = $count; } return $out; }
public function deletePhoto($photoId) { BOL_ContentService::getInstance()->deleteContent("photo_comments", $photoId); }
public function responder($params) { if (!OW::getRequest()->isPost() || !OW::getUser()->isAuthenticated()) { throw new Redirect403Exception(); } $data = $_POST; $data["items"] = empty($data["items"]) ? array() : $data["items"]; list($command, $type) = explode(".", $data["command"]); $backUrl = empty($params["userId"]) ? OW::getRouter()->urlForRoute("moderation.approve", array("group" => $params["group"])) : OW::getRouter()->urlForRoute("moderation.user.approve", array("group" => $params["group"], "userId" => $params["userId"])); $itemKeys = $type == "single" ? array($data["item"]) : $data["items"]; if (empty($itemKeys)) { OW::getFeedback()->warning(OW::getLanguage()->text("base", "moderation_no_items_warning")); $this->redirect($backUrl); } $itemIds = array(); foreach ($itemKeys as $itemKey) { list($entityType, $entityId) = explode(":", $itemKey); $itemIds[$entityType] = empty($itemIds[$entityType]) ? array() : $itemIds[$entityType]; $itemIds[$entityType][] = $entityId; } $affected = 0; $lastEntityType = null; foreach ($itemIds as $entityType => $entityIds) { if ($command == "delete") { $entityListToDelete = array(); if (empty($params["userId"])) { $entityListToDelete = $entityIds; } else { $contentList = BOL_ContentService::getInstance()->getContentList($entityType, $entityIds); foreach ($contentList as $entityId => $content) { if ($content["userId"] == $params["userId"]) { $entityListToDelete[] = $entityId; } } } BOL_ContentService::getInstance()->deleteContentList($entityType, $entityListToDelete); } if ($command == "approve") { BOL_ContentService::getInstance()->updateContentList($entityType, $entityIds, array("status" => BOL_ContentService::STATUS_ACTIVE)); } MODERATION_BOL_Service::getInstance()->deleteEntityList($entityType, $entityIds); $lastEntityType = $entityType; $affected += count($entityIds); } // Feedback $assigns = array(); $multiple = $affected > 1; if ($multiple) { $tmp = BOL_ContentService::getInstance()->getContentGroups(); $groupInfo = $tmp[$params["group"]]; $assigns["content"] = strtolower($groupInfo["label"]); $assigns["count"] = $affected; } else { $typeInfo = BOL_ContentService::getInstance()->getContentTypeByEntityType($lastEntityType); $assigns["content"] = $typeInfo["entityLabel"]; } $feedbackKey = $command == "delete" ? "base+moderation_feedback_delete" : "moderation+feedback_approve"; list($langPrefix, $langKey) = explode("+", $feedbackKey); OW::getFeedback()->info(OW::getLanguage()->text($langPrefix, $langKey . ($multiple ? "_multiple" : ""), $assigns)); // Redirection $this->redirect($backUrl); }
public function approveEntity(OW_Event $event) { $params = $event->getParams(); $data = $event->getData(); $content = BOL_ContentService::getInstance()->getContent($params["entityType"], $params['entityId']); if (empty($content)) { $data["error"] = "Content not found"; return; } $type = $content["typeInfo"]; $authorized = OW::getUser()->isAdmin() || OW::getUser()->isAuthorized($type["authorizationGroup"]); if (!$authorized) { $data["error"] = "Not authorized"; return; } BOL_ContentService::getInstance()->updateContentList($params["entityType"], array($params['entityId']), array("status" => BOL_ContentService::STATUS_ACTIVE)); MODERATION_BOL_Service::getInstance()->deleteEntityList($params["entityType"], array($params['entityId'])); $data["message"] = OW::getLanguage()->text("moderation", "feedback_approve", array("content" => $type["entityLabel"])); $event->setData($data); return $data; }
public function onCommentAdd(OW_Event $event) { $params = $event->getParams(); $contentInfo = BOL_ContentService::getInstance()->getContent($params["entityType"], $params["entityId"]); $label = strtolower($contentInfo["label"]); OW::getEventManager()->trigger(new OW_Event(BOL_ContentService::EVENT_AFTER_ADD, array("entityType" => self::ENTITY_TYPE_COMMENT, "entityId" => $params["commentId"]), array("string" => array("key" => "base+comment_added_string", "vars" => array("content" => $contentInfo["url"] ? '<a href="' . $contentInfo["url"] . '">' . $label . '</a>' : $label))))); }
public function findMostCommentedEntityList($entityType, $first, $count) { $queryParts = BOL_ContentService::getInstance()->getQueryFilter(array(BASE_CLASS_QueryBuilderEvent::TABLE_USER => 'c', BASE_CLASS_QueryBuilderEvent::TABLE_CONTENT => 'c', 'comment_entity' => 'ce'), array(BASE_CLASS_QueryBuilderEvent::FIELD_USER_ID => 'userId', BASE_CLASS_QueryBuilderEvent::FIELD_CONTENT_ID => 'id'), array(BASE_CLASS_QueryBuilderEvent::OPTION_METHOD => __METHOD__, BASE_CLASS_QueryBuilderEvent::OPTION_TYPE => $entityType)); $query = 'SELECT `ce`.`entityId` AS `id`, COUNT(*) AS `commentCount` FROM `' . $this->getTableName() . '` AS `c` LEFT JOIN `' . BOL_CommentEntityDao::getInstance()->getTableName() . '` AS `ce` ON (`c`.`' . self::COMMENT_ENTITY_ID . '` = `ce`.`id`) ' . $queryParts['join'] . ' WHERE `ce`.`' . BOL_CommentEntityDao::ENTITY_TYPE . '` = :entityType AND `ce`.`' . BOL_CommentEntityDao::ACTIVE . '` = 1 AND ' . $queryParts['where'] . ' GROUP BY `' . BOL_CommentEntityDao::ENTITY_ID . '` ORDER BY `commentCount` DESC, `id` DESC LIMIT :first, :count'; return $this->dbo->queryForList($query, array('entityType' => $entityType, 'first' => $first, 'count' => $count)); }
public function genericItemRender(OW_Event $e) { $params = $e->getParams(); $data = $e->getData(); if (in_array($params['action']['entityType'], array('user-comment', 'user-status')) && $params['feedType'] == 'user' && $params['createActivity']->userId != $params['feedId']) { $data['context'] = null; } $actionUserId = $userId = (int) $data['action']['userId']; if (in_array($params['feedType'], array('site', 'my')) && $actionUserId != OW::getUser()->getId() && !BOL_AuthorizationService::getInstance()->isSuperModerator($actionUserId) && OW::getUser()->isAuthorized('base')) { $callbackUrl = OW_URL_HOME . OW::getRequest()->getRequestUri(); array_unshift($data['contextMenu'], array('label' => OW::getLanguage()->text('newsfeed', 'delete_feed_item_user_label'), 'attributes' => array('onclick' => UTIL_JsGenerator::composeJsString('if ( confirm($(this).data(\'confirm-msg\')) ) OW.Users.deleteUser({$userId}, \'' . $callbackUrl . '\', true);', array('userId' => $actionUserId)), "data-confirm-msg" => OW::getLanguage()->text('base', 'are_you_sure')), "class" => "owm_red_btn")); } $isFeedOwner = $params['feedType'] == "user" && $params["feedId"] == OW::getUser()->getId(); $isStatus = in_array($params['action']['entityType'], array('user-comment', 'user-status')); $canRemove = OW::getUser()->isAuthenticated() && ($params['action']['userId'] == OW::getUser()->getId() || OW::getUser()->isAuthorized('newsfeed') || $isFeedOwner && $isStatus && $params['action']['onOriginalFeed']); if ($canRemove && in_array($params['feedType'], array('site', 'my', 'user'))) { array_unshift($data['contextMenu'], array('label' => OW::getLanguage()->text('newsfeed', 'feed_delete_item_label'), 'attributes' => array('data-confirm-msg' => OW::getLanguage()->text('base', 'are_you_sure')), "class" => "newsfeed_remove_btn owm_red_btn")); } // Flags $contentType = BOL_ContentService::getInstance()->getContentTypeByEntityType($params['action']['entityType']); $flagsAllowed = !empty($contentType) && in_array(BOL_ContentService::MODERATION_TOOL_FLAG, $contentType["moderation"]); if ($params['action']['userId'] != OW::getUser()->getId() && $flagsAllowed) { array_unshift($data['contextMenu'], array('label' => OW::getLanguage()->text('base', 'flag'), 'attributes' => array('onclick' => 'OW.flagContent($(this).data().etype, $(this).data().eid)', "data-etype" => $params['action']['entityType'], "data-eid" => $params['action']['entityId']))); } $e->setData($data); }
/** * Get content types * * @return array */ public static function getContentTypes() { $contentGroups = BOL_ContentService::getInstance()->getContentGroups(); $processedGroups = array(); $disallowedEntityTypes = explode(',', OW::getConfig()->getValue('base', 'site_statistics_disallowed_entity_types')); foreach ($contentGroups as $group => $data) { $skip = false; foreach ($data['entityTypes'] as $entityType) { if (in_array($entityType, $disallowedEntityTypes)) { $skip = true; break; } } if ($skip) { continue; } $processedGroups[$group] = $data['label']; } return $processedGroups; }
<?php $_entityList = MODERATION_BOL_Service::getInstance()->findAllEntityList(); $entityList = array(); foreach ($_entityList as $entity) { /* @var $entity MODERATION_BOL_Entity */ $entityList[$entity->entityType] = empty($entityList[$entity->entityType]) ? array() : $entityList[$entity->entityType]; $entityList[$entity->entityType][] = $entity->entityId; } foreach ($entityList as $entityType => $entityIds) { try { BOL_ContentService::getInstance()->updateContentList($entityType, $entityIds, array("status" => BOL_ContentService::STATUS_ACTIVE)); } catch (Exception $ex) { // Pass } }
public function flagsResponder($params) { if (!OW::getRequest()->isPost() || !(OW::getUser()->isAdmin() || BOL_AuthorizationService::getInstance()->isModerator())) { throw new Redirect403Exception(); } $data = $_POST; $data["items"] = empty($data["items"]) ? array() : $data["items"]; list($command, $type) = explode(".", $data["command"]); $backUrl = OW::getRouter()->urlForRoute("base.moderation_flags", array("group" => $params["group"])); $itemKeys = $type == "single" ? array($data["item"]) : $data["items"]; if (empty($itemKeys)) { OW::getFeedback()->warning(OW::getLanguage()->text("base", "moderation_no_items_warning")); $this->redirect($backUrl); } $itemIds = array(); foreach ($itemKeys as $itemKey) { list($entityType, $entityId) = explode(":", $itemKey); $itemIds[$entityType] = empty($itemIds[$entityType]) ? array() : $itemIds[$entityType]; $itemIds[$entityType][] = $entityId; } $affected = 0; $lastEntityType = null; foreach ($itemIds as $entityType => $entityIds) { if ($command == "delete") { BOL_ContentService::getInstance()->deleteContentList($entityType, $entityIds); } if ($command == "unflag") { // Pass } BOL_FlagService::getInstance()->deleteFlagList($entityType, $entityIds); $affected = count($entityIds); $lastEntityType = $entityType; } // Feedback $assigns = array(); $multiple = $affected > 1; if ($multiple) { $tmp = BOL_ContentService::getInstance()->getContentGroups(); $groupInfo = $tmp[$params["group"]]; $assigns["content"] = strtolower($groupInfo["label"]); $assigns["count"] = $affected; } else { $typeInfo = BOL_ContentService::getInstance()->getContentTypeByEntityType($lastEntityType); $assigns["content"] = $typeInfo["entityLabel"]; } $feedbackKey = $command == "delete" ? "base+moderation_feedback_delete" : "base+moderation_feedback_unflag"; list($langPrefix, $langKey) = explode("+", $feedbackKey); OW::getFeedback()->info(OW::getLanguage()->text($langPrefix, $langKey . ($multiple ? "_multiple" : ""), $assigns)); // Redirection $this->redirect($backUrl); }
public function findMostRatedEntityList($entityType, $first, $count, $exclude) { $queryParts = BOL_ContentService::getInstance()->getQueryFilter(array(BASE_CLASS_QueryBuilderEvent::TABLE_USER => 'r', BASE_CLASS_QueryBuilderEvent::TABLE_CONTENT => 'r'), array(BASE_CLASS_QueryBuilderEvent::FIELD_USER_ID => 'userId', BASE_CLASS_QueryBuilderEvent::FIELD_CONTENT_ID => 'id'), array(BASE_CLASS_QueryBuilderEvent::OPTION_METHOD => __METHOD__, BASE_CLASS_QueryBuilderEvent::OPTION_TYPE => $entityType)); $excludeCond = $exclude ? ' AND `' . self::ENTITY_ID . '` NOT IN (' . $this->dbo->mergeInClause($exclude) . ')' : ''; $query = 'SELECT `' . self::ENTITY_ID . '` AS `id`, COUNT(*) as `ratesCount`, AVG(`score`) as `avgScore` FROM `' . $this->getTableName() . '` AS `r` ' . $queryParts['join'] . ' WHERE `' . self::ENTITY_TYPE . '` = :entityType AND `' . self::ACTIVE . '` = 1 ' . $excludeCond . ' AND ' . $queryParts['where'] . ' GROUP BY `' . self::ENTITY_ID . '` ORDER BY `avgScore` DESC, `ratesCount` DESC, MAX(`timeStamp`) DESC LIMIT :first, :count'; return $this->dbo->queryForList($query, array('entityType' => $entityType, 'first' => (int) $first, 'count' => (int) $count)); }
public function getQueryCondition($listType, $aliases, array $params = array()) { $event = new BASE_CLASS_QueryBuilderEvent('photo.getPhotoList', array('listType' => $listType, 'aliases' => $aliases, 'params' => $params)); OW::getEventManager()->trigger($event); $queryParts = BOL_ContentService::getInstance()->getQueryFilter(array(BASE_CLASS_QueryBuilderEvent::TABLE_USER => $aliases['album'], BASE_CLASS_QueryBuilderEvent::TABLE_CONTENT => $aliases['album']), array(BASE_CLASS_QueryBuilderEvent::FIELD_USER_ID => 'userId', BASE_CLASS_QueryBuilderEvent::FIELD_CONTENT_ID => 'id'), array(BASE_CLASS_QueryBuilderEvent::OPTION_METHOD => __METHOD__, BASE_CLASS_QueryBuilderEvent::OPTION_TYPE => $listType)); $event->addJoin($queryParts['join']); $event->addWhere($queryParts['where']); $event->addOrder($queryParts['order']); return array('join' => $event->getJoin(), 'where' => $event->getWhere(), 'order' => $event->getOrder(), 'params' => $event->getQueryParams()); }