public function Render($data) { Phalanx::loadClasses('Profile'); $posts = array(); foreach ($data as $key => $each) { $v = new Views(); $v->accept_nsfw = Profile::acceptNSFW($this->session->user->id); $v->original_id = $each->original_id; $v->reblog_count = $each->reblog_count; $v->is_reblogged = $each->is_reblogged; $v->current_user = $this->session->user->login; $v->user = $each->user; $v->title = $each->title; $v->name = $each->name; $v->when = $each->when ? $each->when : $each->date; $v->content = $each->content; $v->via = $each->via; $v->comments = $each->comments; $v->replies = $each->replies; $v->rating = $each->rating; $v->my_rating = $each->my_rating; $v->post_id = $each->id; $v->avatar = $each->avatar; $v->categories = $each->categories; $v->is_favorite = $each->is_favorite; $v->is_reblogged = $each->is_reblogged; $v->its_mine = $each->user_id == $this->session->user->id ? true : false; $v->user_points = $each->user_points; $v->promoted = (bool) $each->promoted; 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("post_body.phtml"); $posts[] = $content; } return $posts; }
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; }
public function DisplayOldPosts() { $profile_data = Profile::get_profile($this->post->profile, 0, 0, 0, 0, 0, 0, 0); $profile = $this->post->profile; if (property_exists($this->session->times_reloaded, "profile_{$profile}")) { $this->session->times_reloaded->{"profile_{$profile}"} += 1; } else { $this->session->times_reloaded->{"profile_{$profile}"} = 1; } $p = Posts::from_user($profile_data->id, false, $this->post->min_id, $this->post->max_id); $posts = array(); foreach ($p as $key => $each) { $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->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; 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->rating->reblog_count = $originalPost->rating->reblog_count; $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("post_body.phtml"); $posts[] = $content; } header("Content-type: text/html; charset=utf-8"); foreach ($posts as $postHTML) { echo $postHTML; } }
public static function build_from_list($uid, $list_id, stdClass $config) { Phalanx::loadClasses('Friendship'); $friends_ids = Friendship::get_friend_array($uid); $friends_ids = implode(', ', $friends_ids); $where = ""; if (property_exists($config, 'min')) { $where .= " AND p.id < '{$config->min}'"; } if (property_exists($config, 'max')) { $where .= " AND p.id < '{$config->max}'"; } Phalanx::loadClasses('Lists', 'SocialNetwork', 'Facebook', 'Twitter', 'twitteroauth', 'Instagram', 'PostCategory', 'Favorites', 'Profile'); $list = Lists::from_user($uid, $list_id); $categories = array(); foreach ($list->categories as $category) { $categories[] = $category->id; } if (sizeof($categories) > 0) { Phalanx::loadClasses('Posts', 'PostComments'); $categories_ids = implode("', '", $categories); $custom_tl = array(); $m = Model::Factory('posts p', false, 0); $m->fields('DISTINCT p.id AS id', 'p.original_posts_id AS original_id', 'p.user_id AS user_id', 'p.content AS content', 'p.date AS date', 'p.title AS title', 'p.promoted AS promoted', 'u.name AS name', 'u.login AS user', 'ud.avatar AS avatar', 'p.like_count AS likes', 'p.dislike_count AS dislikes', 'p.comment_count AS comments', 'p.reblog_count AS reblogs', 'p.reply_count AS replies'); $m->innerJoin('user u', 'u.id = p.user_id'); $m->innerJoin('user_data ud', 'ud.user_id = p.user_id'); $m->innerJoin('posts_has_category phc', 'p.id = phc.posts_id'); $m->where("p.user_id IN({$friends_ids}) AND phc.category_id IN ('{$categories_ids}') {$where} AND u.banned IS NULL AND p.status=1 AND p.date > DATE_SUB(NOW(), INTERVAL 1 MONTH)"); # $m->group("p.original_posts_id"); $m->order('p.id DESC'); $m->limit(NUMBER_OF_POSTS_LOADED_PER_TIME); $skynerd_posts = $m->all(); foreach ($skynerd_posts as $each) { $o = new stdClass(); $o->date = Date::RelativeTime($each->date); $o->id = $each->id; $o->user = $each->user; $o->name = $each->name; $o->title = $each->title; $o->avatar = $each->avatar; $o->user_id = $each->user_id; $o->rating = new stdClass(); $o->rating->megaboga = $each->likes; $o->rating->whatever = $each->dislikes; $o->my_rating = Posts::userRating($uid, $each->id); $o->content = trim($each->content); $o->comments = $v->comments; $o->replies = $v->replies; $o->categories = PostCategory::from_post($each->id); $o->is_reblogged = Posts::userHasReblogged($each->id, $uid); $o->is_favorite = Favorites::is_favorite($uid, $each->id); $o->user_points = Profile::experience($v->user_id); $o->promoted = (bool) $each->promoted; if (!empty($o->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, $o->original_id); $originalPost = reset($originalPost); $o->content = $originalPost->content; $o->title = $originalPost->title; $o->reblogged_from = $originalPost->user; $o->original_date = $originalPost->date; $o->rating->reblog_count = $originalPost->rating->reblog_count; $o->is_reblogged = Posts::userHasReblogged($originalPost->id, $uid); } $custom_tl[] = $o; } } return $custom_tl; }
public function DisplayPost() { if ($this->get->username == 'wordpressagent') { Request::redirect(HOST); } Phalanx::loadClasses('Profile', 'Friendship', 'Posts'); $profile_data = Profile::get_profile($this->get->username, 0, 0, 0, 0, 0, 0, 0); if ($profile_data->banned == 1) { $this->views->display("profile_banned.phtml"); return; } if ($profile_data->active == 0) { $this->views->display("profile_deactivated.phtml"); return; } $friendship_status = Friendship::get_status($this->session->user->id, $profile_data->id); $this->views->data->friendship_status = $friendship_status; $this->views->data = $profile_data; $p = Posts::from_user($profile_data->id, $this->get->post_id); if (!$p) { $this->views->display("post_unavailable.phtml"); return; } $p = reset($p); $can_be_displayed = true; #Verifica se o post é privado. if ($p->privacy == 1) { if (!$this->session->user->id) { $this->views->display("post_unavailable.phtml"); die; } if ($this->session->user->id == $p->user_id) { $can_be_displayed = true; } else { $can_be_displayed = Friendship::get_status($this->session->user->id, $p->user_id); } } if (!$can_be_displayed) { $this->views->display("post_unavailable.phtml"); die; } $v = new Views(); $v->title = $p->title; $v->user = $p->user; $v->name = $p->name; $v->content = $p->content; $v->comments = $p->comments; $v->comments_array = PostComments::get($this->get->post_id); $v->replies = $p->replies; $v->post_id = $p->id; $v->original_id = $p->original_id; $v->avatar = $p->avatar; $v->rating = $p->rating; $v->promoted = (bool) $p->promoted; $v->accept_nsfw = Profile::acceptNSFW($this->session->user->id); $v->when = $p->date; $v->my_rating = $p->my_rating; $v->current_user = $this->session->user->login; $v->categories = PostCategory::from_post($p->id); $v->its_mine = $profile_data->id == $this->session->user->id ? true : false; $v->is_favorite = $p->is_favorite; $v->user_points = $p->user_points; if (!empty($p->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, $p->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->rating = $originalPost->rating; $v->comments = $originalPost->comments; $v->replies = $originalPost->replies; $v->is_favorite = $originalPost->is_favorite; $v->categories = PostCategory::from_post($p->original_id); $v->comments_array = PostComments::get($p->original_id); $v->id = $p->id; $v->post_id = $originalPost->id; } $content = $v->render("post_body.phtml"); $template = new Template("default"); $template->og = new stdClass(); $template->og->title = $v->user . ': ' . $v->title; $template->og->description = $p->content; $template->og->type = FACEBOOK_APPNAMESPACE . ':article_'; $template->og->img = MEDIA_DIR . 'images/avatar/big/' . $p->avatar; if (!$this->isLoggedIn) { $template->show_login_bar = true; } $this->views = new Views($template); $this->views->data = $profile_data; $this->views->data->friendship_status = $friendship_status; $this->views->data->post = $content; $this->views->display("single_post_display.phtml"); }