public static function getList($filters = array(), $published = true) { $values = array(':lang' => \LANG); $list = array(); $sql = "\n SELECT\n post.id as id,\n post.blog as blog,\n IFNULL(post_lang.title, post.title) as title,\n IFNULL(post_lang.text, post.text) as `text`,\n IFNULL(post_lang.legend, post.legend) as `legend`,\n post.image as `image`,\n post.media as `media`,\n DATE_FORMAT(post.date, '%d-%m-%Y') as fecha,\n post.publish as publish,\n post.home as home,\n post.footer as footer,\n post.author as author,\n blog.type as owner_type,\n blog.owner as owner_id\n FROM post\n INNER JOIN blog\n ON blog.id = post.blog\n LEFT JOIN post_lang\n ON post_lang.id = post.id\n AND post_lang.lang = :lang\n "; if (in_array($filters['show'], array('all', 'home', 'footer'))) { $sql .= " WHERE blog.id IS NOT NULL\n "; } elseif ($filters['show'] == 'updates') { $sql .= " WHERE blog.type = 'project'\n "; } else { $sql .= " WHERE blog.type = 'node'\n "; } if (!empty($filters['blog'])) { $sql .= " AND post.blog = :blog\n "; $values[':blog'] = $filters['blog']; } if (!empty($filters['tag'])) { $sql .= " AND post.id IN (SELECT post FROM post_tag WHERE tag = :tag)\n "; $values[':tag'] = $filters['tag']; } if (!empty($filters['author'])) { $sql .= " AND post.author = :author\n "; $values[':author'] = $filters['author']; } // solo las publicadas if ($published || $filters['show'] == 'published') { $sql .= " AND post.publish = 1\n "; if (empty($filters['blog'])) { $sql .= " AND blog.owner IN (SELECT id FROM node WHERE active = 1)\n AND blog.owner != 'testnode'\n "; } } // solo las del propio blog if ($filters['show'] == 'owned') { $sql .= " AND blog.owner = :node\n "; $values[':node'] = $filters['node']; } // solo las de la portada if ($filters['show'] == 'home') { if ($filters['node'] == \GOTEO_NODE) { $sql .= " AND post.home = 1\n "; } else { $sql .= " AND post.id IN (SELECT post FROM post_node WHERE node = :node)\n "; $values[':node'] = $filters['node']; } } if ($filters['show'] == 'footer') { if ($filters['node'] == \GOTEO_NODE) { $sql .= " AND post.footer = 1\n "; } } $sql .= "\n ORDER BY post.date DESC, post.id DESC\n "; $query = static::query($sql, $values); foreach ($query->fetchAll(\PDO::FETCH_CLASS, __CLASS__) as $post) { // galeria $post->gallery = Image::getAll($post->id, 'post'); $post->image = $post->gallery[0]; // video if (isset($post->media)) { $post->media = new Media($post->media); } $post->num_comments = Post\Comment::getCount($post->id); // datos del autor del post switch ($post->owner_type) { case 'project': $proj_blog = Project::getMini($post->owner_id); $post->author = $proj_blog->owner; $post->user = $proj_blog->user; $post->owner_name = $proj_blog->name; break; case 'node': $post->user = User::getMini($post->author); $node_blog = Node::get($post->owner_id); $post->owner_name = $node_blog->name; break; } $list[$post->id] = $post; } return $list; }
public function post($post, $project = null) { if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['message'])) { $comment = new Model\Blog\Post\Comment(array('user' => $_SESSION['user']->id, 'post' => $post, 'date' => date('Y-m-d H:i:s'), 'text' => $_POST['message'])); if ($comment->save($errors)) { // a ver los datos del post $postData = Model\Blog\Post::get($post); // Evento Feed $log = new Feed(); if (!empty($project)) { $projectData = Model\Project::getMini($project); $log->setTarget($projectData->id); $log_html = \vsprintf('%s ha escrito un %s en la entrada "%s" en las %s del proyecto %s', array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('message', 'Comentario'), Feed::item('update-comment', $postData->title, $projectData->id . '/updates/' . $postData->id . '#comment' . $comment->id), Feed::item('update-comment', 'Novedades', $projectData->id . '/updates/'), Feed::item('project', $projectData->name, $projectData->id))); } else { $log->setTarget('goteo', 'blog'); $log_html = \vsprintf('%s ha escrito un %s en la entrada "%s" del blog de %s', array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('message', 'Comentario'), Feed::item('blog', $postData->title, $postData->id . '#comment' . $comment->id), Feed::item('blog', 'Goteo', '/'))); } $log->populate('usuario escribe comentario en blog/novedades', '/admin/projects', $log_html); $log->doAdmin('user'); // Evento público if (!empty($project)) { $projectData = Model\Project::getMini($project); $log_html = Text::html('feed-updates-comment', Feed::item('update-comment', $postData->title, $projectData->id . '/updates/' . $postData->id . '#comment' . $comment->id), Feed::item('update-comment', 'Novedades', $projectData->id . '/updates/'), Feed::item('project', $projectData->name, $projectData->id)); } else { $log_html = Text::html('feed-blog-comment', Feed::item('blog', $postData->title, $postData->id . '#comment' . $comment->id), Feed::item('blog', 'Goteo', '/')); } $log->populate($_SESSION['user']->name, '/user/profile/' . $_SESSION['user']->id, $log_html, $_SESSION['user']->avatar->id); $log->doPublic('community'); unset($log); //Notificación al autor del proyecto // Obtenemos la plantilla para asunto y contenido $template = Template::get(31); // Sustituimos los datos $subject = str_replace('%PROJECTNAME%', $projectData->name, $template->title); $response_url = SITE_URL . '/user/profile/' . $_SESSION['user']->id . '/message'; $project_url = SITE_URL . '/project/' . $projectData->id . '/updates/' . $postData->id . '#comment' . $comment->id; $search = array('%MESSAGE%', '%OWNERNAME%', '%USERNAME%', '%PROJECTNAME%', '%PROJECTURL%', '%RESPONSEURL%'); $replace = array($_POST['message'], $projectData->user->name, $_SESSION['user']->name, $projectData->name, $project_url, $response_url); $content = \str_replace($search, $replace, $template->text); $mailHandler = new Mail(); $mailHandler->to = $projectData->user->email; $mailHandler->toName = $projectData->user->name; $mailHandler->subject = $subject; $mailHandler->content = $content; $mailHandler->html = true; $mailHandler->template = $template->id; $mailHandler->send($errors); unset($mailHandler); } else { // error } } if (!empty($project)) { throw new Redirection("/project/{$project}/updates/{$post}#comment" . $comment->id, Redirection::TEMPORARY); } else { throw new Redirection("/blog/{$post}#comment" . $comment->id, Redirection::TEMPORARY); } }
$list[] = '<a href="/blog/' . $item->id . '"> ' . Text::recorta($item->title, 100) . '</a>'; } break; case 'tags': $title = Text::get('blog-side-tags'); $items = Post\Tag::getList($blog->id); // enlace a la lista de entradas con filtro tag foreach ($items as $item) { if ($item->used > 0) { $list[] = '<a href="/blog/?tag=' . $item->id . '">' . $item->name . '</a>'; } } break; case 'comments': $title = Text::get('blog-side-last_comments'); $items = Post\Comment::getList($blog->id); // enlace a la entrada en la que ha comentado foreach ($items as $item) { $text = Text::recorta($item->text, 200); $list[] = "\n\t\t\t\t<div>\n\t\t\t\t\t<!--span class='avatar'><img src='/image/{$item->user}->avatar->id/50/50/1' alt='' /></span-->\n\t\t\t\t\t<span class='date'>{$item->date}</span>\n\t\t\t\t\t<div class='high-comment'>\n\t\t\t\t\t\t<strong><a href=\"/blog/{$item->post}\">{$item->user->name}</a></strong>\n\t\t\t\t\t\t<p>{$text}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</div>"; } break; } if (!empty($list)) { ?> <div class="widget blog-sidebar-module"> <h3 class="supertitle"><?php echo $title; ?> </h3> <ul id="blog-side-<?php