コード例 #1
0
ファイル: Profile.php プロジェクト: Anpix/rede-social
 public static function get_profile($u, $privacy = true, $badges = true, $social_networks = true, $friends = true, $exp = true, $aditional_info = true, $gamertags = true)
 {
     Phalanx::loadClasses('Privacy', 'Badges', 'Friendship', 'SocialNetwork', 'Posts', 'GamerTags');
     $m = Model::Factory('user u');
     $m->where("login='******'");
     $user = $m->get();
     if (!$user) {
         return false;
     }
     # Em alguns casos, não é necessário utilizarmos todos os dados do usuário
     if ($privacy) {
         $user->privacy = Privacy::from_user($user->id);
     }
     if ($badges) {
         $user->badges = Badges::from_user($user->id);
     }
     if ($social_networks) {
         $user->social_networks = SocialNetwork::from_user($user->id);
     }
     if ($friends) {
         $user->friends = Friendship::from_user($user->id, 12);
     }
     if ($exp) {
         $user->experience = self::experience($user->id);
     }
     if ($aditional_info) {
         $user->aditional_info = self::other_data($user->id);
     }
     if ($gamertags) {
         $user->gamertags = GamerTags::from_user($user->id);
     }
     return $user;
 }
コード例 #2
0
ファイル: PostComments.php プロジェクト: Anpix/rede-social
 public static function get($post_id, $cache_time = 0, $sort = null)
 {
     Phalanx::loadClasses('public.Profile', 'public.Badges');
     $cache_time = $cache_time ? $cache_time : MEMCACHE_SECONDS;
     $m = Model::Factory('comment c', true, $cache_time);
     $m->fields('c.id	AS id', 'u.id			AS user_id', 'c.comment			AS comment', 'c.date				AS date', 'c.in_reply_to		AS in_reply_to', 'c.like_count		AS likes', 'c.dislike_count	AS dislikes', 'u.login			AS user', 'ud.avatar			AS avatar', 'c.wp_comment_author		AS wp_comment_author', 'c.wp_comment_author_email	AS wp_comment_author_email');
     $m->leftJoin('user u', 'u.id = c.user_id');
     $m->leftJoin('user_data ud', 'ud.user_id = u.id');
     $m->where("posts_id='{$post_id}' AND c.status=1 AND u.banned IS NULL");
     if (is_null($sort)) {
         $m->order("c.id ASC");
     } elseif ($sort == 'like') {
         $m->order("c.like_count DESC");
     }
     $data = $m->all();
     $comments = array();
     $Session = new Session();
     if (is_array($data)) {
         foreach ($data as $each) {
             $o = new stdClass();
             $o->id = $each->id;
             $o->comment = $each->comment;
             $o->date = Date::RelativeTime($each->date);
             $o->rating = new stdClass();
             $o->rating->megaboga = (int) $each->likes;
             $o->rating->whatever = (int) $each->dislikes;
             $o->my_rating = self::userRating($Session->user->id, $each->id);
             $o->user = new stdClass();
             $o->create_links = $each->user_id == 0 ? false : true;
             $o->user->login = $each->user_id == 0 ? $each->wp_comment_author : $each->user;
             $o->user->avatar = $each->user_id == 0 ? "http://www.gravatar.com/avatar/" . md5(strtolower(trim($each->wp_comment_author_email))) . "?d=" . urlencode(MEDIA_DIR . 'images/avatar/square/default.jpg') . "&s=44" : $each->avatar;
             $o->user->id = $each->user_id;
             if ($each->user_id != 0) {
                 $o->user->experience = Profile::experience($each->user_id);
                 $o->user->badges = Badges::from_user($each->user_id, 4);
             }
             if ($each->in_reply_to == '' || $each->in_reply_to == '0') {
                 $o->replies = is_array($comments[$each->id]->replies) ? $comments[$each->id]->replies : array();
                 $comments[$each->id] = $o;
             } else {
                 $comments[$each->in_reply_to]->replies[] = $o;
             }
         }
     }
     return $comments;
 }
コード例 #3
0
ファイル: UsersController.php プロジェクト: Anpix/rede-social
 public function Login()
 {
     $user = Profile::login($this->post->username, md5($this->post->password));
     $o = new stdClass();
     if ($user and $user->banned != 1) {
         $this->session->logged_in = true;
         $this->session->user = $user;
         $this->session->accept_token = md5(REQUEST_IP) . sha1('SkyNerd a REDE SOCIAL do JoVemNerd');
         $o->status = true;
         $o->login = $user->login;
         $o->avatar = $user->other_data->avatar;
         $o->experience = Profile::experience($this->session->user->id);
         $o->badges = Badges::from_user($this->session->user->id, 4);
     } else {
         $o->status = false;
         $o->reason = $user->banned == 1 ? 'banned' : 'incorrect_info';
     }
     header("Access-Control-Allow-Origin: *");
     header("Access-Control-Allow-Methods: POST");
     header("Content-type: text/html; charset=utf-8");
     echo json_encode($o);
 }
コード例 #4
0
 public function Export()
 {
     Phalanx::loadClasses('Profile', 'Badges');
     $profile = Profile::get_profile($this->session->user->login, 0, 0, 0, 0, 1, 1, 1);
     $profile->badges = Badges::from_user($this->sessio->user->id, false);
     $t = new Template("export");
     $t->show_login_bar = true;
     $userPosts = Posts::exportFromUser($this->session->user->id);
     $postsImages = array();
     $avatarImages = array();
     $posts = array();
     Phalanx::loadExtension('simple_html_dom');
     foreach ($userPosts as $key => $each) {
         $html = str_get_html($each->content);
         /*
          * Em alguns casos o objeto não está sendo criado, gerando um fatal error.
          * Conteúdo vazio? Estranho, ainda não sei o que está rolando.
          * Isso aqui resolve.
          * */
         if (is_object($html)) {
             $images = $html->find('img');
             foreach ($images as &$image) {
                 if (stripos($image, HOST)) {
                     $postsImages[] = basename($image->src);
                     $image->src = "./images/posts/" . basename($image->src);
                 }
             }
             $each->content = $html;
         }
         $avatarImages[] = $each->avatar;
         $v = new Views();
         $v->accept_nsfw = Profile::acceptNSFW($this->session->user->id);
         $v->current_user = $this->session->user->login;
         $v->user = $each->user;
         $v->name = $each->name;
         $v->when = $each->date;
         $v->title = $each->title;
         $v->content = $each->content;
         $v->comments = $each->comments;
         $v->comments_array = $each->comments_array;
         $v->replies = $each->replies;
         $v->post_id = $each->id;
         $v->original_id = $each->original_id;
         $v->is_reblogged = $each->is_reblogged;
         $v->avatar = $each->avatar;
         $v->rating = $each->rating;
         $v->my_rating = $each->my_rating;
         $v->categories = $each->categories;
         $v->its_mine = $profile_data->id == $this->session->user->id ? true : false;
         $v->is_favorite = $each->is_favorite;
         $v->user_points = $each->user_points;
         foreach ($each->comments_array as $eachComment) {
             $avatarImages[] = $eachComment->user->avatar;
             foreach ($eachComment->replies as $eachReply) {
                 $avatarImages[] = $eachReply->user->avatar;
             }
         }
         if (!empty($each->original_id)) {
             //Se o post for um reblog, então o conteúdo dele deve ser o do reblogado, mostrando as ações
             $originalPost = Posts::from_user(false, $v->original_id);
             $originalPost = reset($originalPost);
             $v->content = $originalPost->content;
             $v->title = $originalPost->title;
             $v->reblogged_from = $originalPost->user;
             $v->reblog_avatar = $originalPost->avatar;
             $v->reblog_points = $originalPost->user_points;
             $v->original_date = $originalPost->date;
             $v->comments = $originalPost->comments;
             $v->replies = $originalPost->replies;
             $v->is_favorite = $originalPost->is_favorite;
             $v->categories = $originalPost->categories;
             $v->rating = $originalPost->rating;
             $v->id = $v->post_id;
             $v->post_id = $originalPost->id;
         }
         $content = $v->render("export/post_body.phtml");
         $posts[] = $content;
     }
     $v = new Views($t);
     $v->data = $profile;
     $v->data->timeline = $posts;
     ob_start();
     $v->display("export/profile.phtml");
     $profile_html_data = ob_get_contents();
     ob_end_clean();
     if (!is_dir(TMP_DIR . DIRECTORY_SEPARATOR . 'export')) {
         mkdir(TMP_DIR . DIRECTORY_SEPARATOR . 'export', 0755, true);
     }
     $dirname = TMP_DIR . DIRECTORY_SEPARATOR . 'export' . DIRECTORY_SEPARATOR . $this->session->user->login . DIRECTORY_SEPARATOR;
     if (!is_dir($dirname)) {
         mkdir($dirname, 0755, true);
     }
     $filename = "perfil-{$this->session->user->login}.html";
     file_put_contents($dirname . $filename, $profile_html_data);
     $zip = new ZipArchive();
     if ($zip->open("{$dirname}data.zip", ZipArchive::CREATE) === TRUE) {
         $zip->addEmptyDir('css');
         foreach (glob(TEMPLATE_DIR . '/export/css/*') as $file) {
             $zip->addFile($file, "/css/" . basename($file));
         }
         $zip->addEmptyDir('js');
         foreach (glob(TEMPLATE_DIR . '/export/js/*') as $file) {
             $zip->addFile($file, "/js/" . basename($file));
         }
         $zip->addEmptyDir('fonts');
         $zip->addEmptyDir('fonts/Engschrift');
         foreach (glob(TEMPLATE_DIR . '/export/fonts/Engschrift/*') as $file) {
             $zip->addFile($file, "/fonts/Engschrift/" . basename($file));
         }
         $zip->addEmptyDir('images');
         foreach (glob(TEMPLATE_DIR . '/export/images/*.*') as $file) {
             $zip->addFile($file, "/images/" . basename($file));
         }
         $zip->addEmptyDir('images/socialnetworks');
         foreach (glob(TEMPLATE_DIR . '/export/images/socialnetworks/*') as $file) {
             $zip->addFile($file, "/images/socialnetworks/" . basename($file));
         }
         $zip->addEmptyDir('images/images');
         foreach (glob(TEMPLATE_DIR . '/export/images/images/*') as $file) {
             $zip->addFile($file, "/images/images/" . basename($file));
         }
         $zip->addEmptyDir('images/avatar');
         $zip->addEmptyDir('images/avatar/big');
         $zip->addEmptyDir('images/avatar/small');
         $zip->addEmptyDir('images/avatar/square');
         foreach ($avatarImages as $avatar) {
             $zip->addFile(AVATAR_UPLOAD_DIR . "/big/{$avatar}", "/images/avatar/big/{$avatar}");
             $zip->addFile(AVATAR_UPLOAD_DIR . "/small/{$avatar}", "/images/avatar/small/{$avatar}");
             $zip->addFile(AVATAR_UPLOAD_DIR . "/square/{$avatar}", "/images/avatar/square/{$avatar}");
         }
         $zip->addEmptyDir('images/posts');
         foreach ($postsImages as $image) {
             $zip->addFile(POST_IMAGES_UPLOAD_DIR . "/{$image}", "/images/posts/{$image}");
         }
         $zip->addEmptyDir('images/badges');
         foreach (glob(ROOT . PROJECT_DIR . '/media/images/badges/*') as $file) {
             $zip->addFile($file, "/images/badges/" . basename($file));
         }
         $zip->addFile("{$dirname}{$filename}", "/{$filename}");
     }
     $zip->close();
     header("Content-disposition: attachment; filename={$this->session->user->login}.zip");
     header("Content-type: application/zip");
     readfile("{$dirname}data.zip");
     $t = new Template("export", "thankyou.phtml");
     $v = new Views($t);
     $v->display("");
     $c = new Cookies();
     $c->setExpire(strtotime("+15 days"));
     $c->data_exported = 1;
 }
コード例 #5
0
 public function DisplayUserBadges()
 {
     Phalanx::loadClasses('Badges', 'Profile');
     if (isset($this->get->id)) {
         $template = new Template("default");
         $template->show_login_bar = $this->isLoggedIn;
         $badge = Badges::get($this->get->id);
         $template->og = new stdClass();
         $template->og->description = $badge->description;
         $template->og->type = 'skynerd_jn:badge';
         $template->og->title = $badge->name;
         $template->og->img = MEDIA_DIR . "images/badges/{$badge->icon_url}";
         $this->views = new Views($template);
     }
     if (isset($this->get->username)) {
         $username = $this->get->username;
     } else {
         if (!$this->session->user) {
             Request::redirect(HOST . 'login');
         }
         $username = $this->session->user->login;
     }
     $profile_data = Profile::get_profile($username);
     $this->views->data = $profile_data;
     if ($username != $this->session->user->login) {
         $this->views->data->friendship_status = Friendship::get_status($this->session->user->id, $profile_data->id);
     }
     $this->views->data->badges_list = Badges::from_user($profile_data->id, false);
     $this->views->display("profile.phtml");
 }
コード例 #6
0
ファイル: PostsController.php プロジェクト: Anpix/rede-social
 public function Comment()
 {
     if (!$this->isLoggedIn) {
         return;
     }
     if (!$this->session->recent_comments) {
         $this->session->recent_comments = new stdClass();
     }
     if (!$this->session->recent_comments->{"pid" . $this->post->post_id}) {
         $this->session->recent_comments->{"pid" . $this->post->post_id} = array();
     }
     if (in_array(md5($this->post->comment), $this->session->recent_comments->{"pid" . $this->post->post_id})) {
         header("Content-type:application/json;charset=utf-8");
         $o = new stdClass();
         $o->status = 0;
         $o->message = "Comentário duplicado";
         die(json_encode($o));
     }
     if (trim($this->post->comment) == '') {
         header("Content-type:application/json;charset=utf-8");
         $o = new stdClass();
         $o->status = 0;
         $o->message = "Comentário vazio";
         die(json_encode($o));
     }
     $m = Model::Factory('comment', false, false);
     $m->posts_id = $this->post->post_id;
     $m->comment = trim($this->post->comment);
     $m->user_id = $this->session->user->id;
     if ($this->post->in_reply_to) {
         $m->in_reply_to = $this->post->in_reply_to;
     }
     $m->date = date('Y-m-d H:i:s');
     if (isset($this->post->in_reply_to)) {
         $m->in_reply_to = $this->post->in_reply_to;
         $n = new Notification(Notification::REPLYED_COMMENT, $this->session->user->id, $this->post->in_reply_to);
     } else {
         $n = new Notification(Notification::COMMENTED_POST, $this->session->user->id, $this->post->post_id);
     }
     $s = $m->insert();
     if ($s) {
         $this->session->recent_comments->{"pid" . $this->post->post_id}[] = md5($this->post->comment);
         Phalanx::loadClasses('Profile');
         preg_match_all('/(?<=|(?<=[.A-Za-z0-9_-]))@([.A-Za-z0-9_-]+[.A-Za-z0-9_-]+)/', $this->post->comment, $usernames);
         foreach ($usernames[1] as $username) {
             $user = Profile::get_user_info($username);
             if ($user) {
                 $n = new Notification(Notification::TAGGED_IN_A_COMMENT, $this->session->user->id, $this->post->post_id, $user->id);
             }
         }
         if ($this->post->in_reply_to) {
             Model::ExecuteQuery("UPDATE posts SET reply_count = reply_count+1 WHERE id='{$this->post->post_id}'");
         } else {
             Model::ExecuteQuery("UPDATE posts SET comment_count = comment_count+1 WHERE id='{$this->post->post_id}'");
         }
         Phalanx::loadClasses('Profile', 'Badges');
         header("Content-type:application/json;charset=utf-8");
         $o = new stdClass();
         $o->status = 1;
         $o->isReply = $this->post->in_reply_to ? true : false;
         $o->id = $s;
         $o->avatar = $this->session->user->other_data->avatar;
         $o->user = $this->session->user->login;
         $o->comment = nl2br(trim(preg_replace('/(?<=|(?<=[.A-Za-z0-9_-]))@([.A-Za-z0-9_-]+[.A-Za-z0-9_-]+)/', '<a class="profile-link" href="' . HOST . 'perfil/$1"e>@$1</a>', $this->post->comment)));
         $o->comment_id = $s;
         $o->post_id = $this->post->post_id;
         if ($this->post->in_reply_to) {
             $o->in_reply_to = $this->post->in_reply_to;
         }
         $o->experience = Profile::experience($this->session->user->id);
         $o->badges = Badges::from_user($this->session->user->id, 4);
         die(json_encode($o));
     }
 }