コード例 #1
0
ファイル: post.php プロジェクト: difra-org/difra
 /**
  * Создаёт пост (или несколько) из результатов выборки из базы
  * @static
  * @param array $data
  * @return array|null
  */
 public static function makeList($data)
 {
     // нет данных
     if (empty($data) or !is_array($data)) {
         return null;
     }
     // в $data один пост
     if (isset($data['id'])) {
         $data = [$data];
     }
     $groups = [];
     $Auth = Auth::getInstance();
     if ($userId = $Auth->getEmail()) {
         $groups = Group::getOwnedGroupsIds($userId);
     }
     $posts = [];
     foreach ($data as $row) {
         $post = new self();
         foreach ($row as $k => $v) {
             if (property_exists($post, $k)) {
                 $post->{$k} = $v;
             }
         }
         if ($userId and $post->getUser() == $userId || $Auth->isModerator()) {
             $post->canModify = true;
         } elseif ($userId and $post->groupId and in_array($post->groupId, $groups)) {
             $post->canModify = true;
         } else {
             $post->canModify = false;
         }
         $posts[] = $post;
     }
     return $posts;
 }
コード例 #2
0
ファイル: comment.php プロジェクト: difra-org/difra
 public static function checkDeleteRights($id, $module)
 {
     $db = \Difra\MySQL::getInstance();
     $parentOwner = false;
     switch ($module) {
         case 'blogs':
             $query = "SELECT bl.`user`, bl.`group`\n\t\t\t\t\t\tFROM `blogs_posts` bp\n\t\t\t\t\t\tRIGHT JOIN `blogs` AS `bl` ON bl.`id`=bp.`blog`\n\t\t\t\t\t\tWHERE bp.`id`='" . intval($id) . "'";
             break;
         case 'albums':
             $query = "SELECT al.`group_id` as `group`\n\t\t\t\t\t\tFROM `albums` al\n\t\t\t\t\t\tWHERE al.`id` = '" . intval($id) . "'";
             break;
         default:
             $query = false;
     }
     if ($query) {
         $parentOwner = $db->fetchRow($query);
     }
     $groups = [];
     $Auth = \Difra\Auth::getInstance();
     $userId = $Auth->getEmail();
     if ($userId && \Difra\Plugger::getInstance()->isEnabled('blogs')) {
         $groups = \Difra\Plugins\Blogs\Group::getOwnedGroupsIds($userId);
     }
     $commentData = $db->fetchRow("SELECT `user` FROM `{$module}_comments` WHERE `id`='" . intval($id) . "'");
     if ($userId && ($userId == $commentData['user'] || $Auth->isModerator())) {
         return true;
     } elseif ($userId && $parentOwner && in_array($parentOwner['group'], $groups)) {
         return true;
     } elseif ($userId && $parentOwner && isset($parentOwner['user']) && $parentOwner['user'] == $userId) {
         return true;
     }
     return false;
 }