Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- @session_start();
- Class PostsController extends AppController
- {
- public function vote()
- {
- $post_id = $_GET['post_id'];
- $table = "vote_" . $_GET['vote'];
- if ($_GET && $_GET['post_id'] && $_GET['vote'] && ($_GET['vote'] == "true" || $_GET['vote'] == "false"))
- {
- if (!isset($_SESSION['posts_votes'][date("Y-m-d")][$post_id]) && !isset($_COOKIE[date("Ymd").$post_id]))
- {
- $this->SQL->query("UPDATE posts SET $table=$table+1 WHERE id='$post_id'");
- $salida = $this->SQL->query("SELECT $table FROM posts WHERE id='$post_id'");
- $_SESSION['posts_votes'][date("Y-m-d")][$post_id] = "1";
- setcookie(date("Ymd").$post_id, "cookie", time() + 86400);
- echo "Gracias (".$salida['0'][$table].")";
- }else{
- $salida = $this->SQL->query("SELECT $table FROM posts WHERE id='$post_id'");
- echo "Ya has votado (".$salida['0'][$table].")";
- }
- }
- exit;
- }
- public function report_comment()
- {
- if ($_GET && $_SESSION['login'] == "1")
- {
- if (!isset($_SESSION['report_comments'][date("Y-m-d")][$comment_id]) && !isset($_COOKIE[date("Ymd")."-c-".$comment_id]))
- {
- $comment_id = $_GET['comment_id'];
- $this->SQL->query("UPDATE comments SET report=1 WHERE id='$comment_id'");
- $_SESSION['report_comments'][date("Y-m-d")][$comment_id] = "1";
- setcookie(date("Ymd")."-c-".$comment_id, "cookie", time() + 86400);
- }
- echo "Gracias. En breve revisaremos este comentario";
- }else if ($_SESSION['login'] != "1"){
- echo "Debes estar registrado para denunciar";
- }
- exit;
- }
- public function index($params)
- {
- global $mysql_username;
- global $mysql_password;
- global $mysql_database;
- if ($mysql_username == "" || $mysql_password == "" || $mysql_database == "")
- {
- header("Location: /install/step1");
- }
- $config = $this->SQL->query("SELECT * FROM config");
- $tmp=array();
- foreach ($config as $c)
- {
- $tmp[$c['entry']]=$c['value'];
- }
- $baned = $this->SQL->query("SELECT word FROM baned_words");
- $_SESSION['site_config']=$tmp;
- $_SESSION['site_config']['baned_words']=$baned;
- $pagina = $params['page'];
- $registrosAMostrar = "12";
- if ($pagina != "")
- {
- $registrosAEmpezar = ($pagina - 1) * $registrosAMostrar;
- $PagAct = $pagina;
- } else
- {
- $registrosAEmpezar = "0";
- $PagAct = 1;
- }
- $posts = $this->SQL->query("
- SELECT
- Post.id as post_id,
- Post.date as post_date,
- Post.*,
- User.*,
- Cat.name as category_name
- FROM
- categories Cat,
- posts Post,
- users User
- WHERE
- Post.category_id = Cat.id AND
- Post.user_id = User.id
- ORDER BY Post.id DESC LIMIT $registrosAEmpezar,$registrosAMostrar
- ");
- $tmp = $this->SQL->query("
- SELECT
- COUNT(*) as num
- FROM
- categories Cat,
- posts Post,
- users User
- WHERE
- Post.category_id = Cat.id AND
- Post.user_id = User.id");
- $NroRegistros = $tmp[0]['num'];
- $PagUlt = $NroRegistros / $registrosAMostrar;
- $Res = $NroRegistros % $registrosAMostrar;
- if ($Res > 0)
- $PagUlt = floor($PagUlt) + 1;
- if ($PagUlt == 0)
- {
- $PagUlt = 1;
- }
- $this->set('totalPages',$PagUlt);
- $Posts = array();
- foreach ($posts as $post)
- {
- $comments = $this->SQL->count_records("comments","post_id",$post['post_id']);
- $post['comments'] = $comments;
- $Posts[] = $post;
- }
- $this->set('Posts',$Posts);
- $this->set('PageTitle',$_SESSION['site_config']['site_name']);
- $this->set('MetaDescription',$_SESSION['site_config']['site_description']);
- $this->set('MetaKeywords',$_SESSION['site_config']['meta_tags']);
- }
- public function filter($params)
- {
- $pagina = $params['page'];
- $registrosAMostrar = "12";
- if ($pagina != "")
- {
- $registrosAEmpezar = ($pagina - 1) * $registrosAMostrar;
- $PagAct = $pagina;
- } else
- {
- $registrosAEmpezar = "0";
- $PagAct = 1;
- }
- if (!$_POST)
- {
- if ($params[0] == "" && $_SERVER['REQUEST_URI'] != "/suerte")
- {
- header("Location: /");
- }
- if ($_SERVER['REQUEST_URI'] == "/suerte")
- {
- $extra = "";
- $order = "RAND()";
- }else{
- $extra = "Cat.uri='{$params[0]}' AND ";
- $order = "Post.id DESC";
- }
- $posts = $this->SQL->query("
- SELECT
- Post.id as post_id,
- Post.date as post_date,
- Post.*,
- User.*,
- Cat.name as category_name
- FROM
- categories Cat,
- posts Post,
- users User
- WHERE ".$extra."Post.category_id = Cat.id AND
- Post.user_id = User.id
- ORDER BY $order LIMIT $registrosAEmpezar,$registrosAMostrar");
- $tmp = $this->SQL->query("
- SELECT
- COUNT(*) as num
- FROM
- categories Cat,
- posts Post,
- users User
- WHERE ".$extra."Post.category_id = Cat.id AND
- Post.user_id = User.id");
- }else{
- if ($_POST['text'] == "" || strlen($_POST['text']) < 3)
- {
- header("Location: /");
- }
- $posts = $this->SQL->query("
- SELECT
- Post.id as post_id,
- Post.date as post_date,
- Post.*,
- User.*,
- Cat.name as category_name
- FROM
- categories Cat,
- posts Post,
- users User
- WHERE
- Post.post LIKE '%".$_POST['text']."%' AND
- Post.category_id = Cat.id AND
- Post.user_id = User.id
- ORDER BY Post.id DESC LIMIT $registrosAEmpezar,$registrosAMostrar");
- $tmp = $this->SQL->query("
- SELECT
- COUNT(*) as num
- FROM
- categories Cat,
- posts Post,
- users User
- WHERE
- Post.post LIKE '%".$_POST['text']."%' AND
- Post.category_id = Cat.id AND
- Post.user_id = User.id");
- }
- $NroRegistros = $tmp[0]['num'];
- $PagUlt = $NroRegistros / $registrosAMostrar;
- $Res = $NroRegistros % $registrosAMostrar;
- if ($Res > 0)
- $PagUlt = floor($PagUlt) + 1;
- if ($PagUlt == 0)
- {
- $PagUlt = 1;
- }
- $this->set('totalPages',$PagUlt);
- $Posts = array();
- foreach ($posts as $post)
- {
- $comments = $this->SQL->count_records("comments","post_id",$post['post_id']);
- $post['comments'] = $comments;
- $Posts[] = $post;
- }
- if (!$_POST)
- {
- if (count($Posts) > 0)
- {
- $Title = $Posts['0']['category_name'];
- }else{
- $pt = $this->SQL->query("
- SELECT
- name
- FROM
- categories
- WHERE
- uri='{$params[0]}'");
- $Title = $pt['0']['name'];
- }
- }else{
- $Title = $_POST['text'];
- }
- $this->set('PageTitle',"{$Title}");
- $this->set('Posts',$Posts);
- }
- public function details($params)
- {
- if ($params['action'] == "comment")
- {
- $this->checkAuth("?URI=/entrada/" . $params[0]);
- $this->set('leave_a_comment',"true");
- }else{
- $this->set('leave_a_comment',"false");
- }
- if ($_POST)
- {
- $comment_id = $this->SQL->insert("comments",$_POST['data']);
- $this->SQL->query("UPDATE users SET comments=comments + 1 WHERE id='".$_SESSION['user']['id']."'");
- unset($_POST);
- }
- $posts = $this->SQL->query("
- SELECT
- Post.id as post_id,
- Post.date as post_date,
- Post.*,
- User.*,
- Cat.name as category_name
- FROM
- categories Cat,
- posts Post,
- users User
- WHERE
- Post.category_id = Cat.id AND
- Post.user_id = User.id AND
- Post.id = '{$params[0]}'
- ");
- $Posts = array();
- foreach ($posts as $post)
- {
- $comments = $this->SQL->query("
- SELECT
- Comment.date as comment_date,
- Comment.comments as comment,
- Comment.id as comment_id,
- Comment.*,
- User.*
- FROM
- comments Comment,
- users User
- WHERE
- Comment.post_id = '".$post['post_id']."' AND
- Comment.user_id = User.id
- ");
- $post['comments'] = $comments;
- $Posts = $post;
- }
- $this->set('PageTitle',$Posts['title']);
- $this->set('Post',$Posts);
- }
- public function add($params)
- {
- $publickey = "6LeQ6sYSAAAAAKBut3vVXJNHmioTtZ-ZxEtC3THs";
- $privatekey = "6LeQ6sYSAAAAALCdjb9hQ0ZH_E9JZIN8ZJG7IbtC";
- $resp = null;
- $this->checkAuth("?URI=/publicar");
- if ($_POST){
- if ($_POST['captcha']) {
- if(md5($_POST['captcha']) != $_SESSION['key']){
- die('Codigo incorrecto.');
- } else {
- $post_id = $this->SQL->insert("posts",$_POST['data']);
- $cat_id = $_POST['data']['category_id'];
- $cat = $this->SQL->query("SELECT uri FROM categories WHERE id='$cat_id'");
- $this->SQL->query("UPDATE users SET posts=posts + 1 WHERE id='".$_SESSION['user']['id']."'");
- header("Location: /categoria/" . $cat[0]['uri']);
- }
- } else {
- die('Codigo incorrecto.');
- }
- }else{
- $categorias = $this->SQL->query("SELECT * FROM categories");
- $this->set('categories',$categorias);
- }
- $this->set('PageTitle',"Publicar");
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement