Esempio n. 1
0
 public static function get($owner, $type = 'project')
 {
     $query = static::query("\n                    SELECT\n                        id,\n                        type,\n                        owner,\n                        active\n                    FROM    blog\n                    WHERE owner = :owner\n                    AND type = :type\n                    ", array(':owner' => $owner, ':type' => $type));
     $blog = $query->fetchObject(__CLASS__);
     switch ($blog->type) {
         case 'node':
             $blog->node = $blog->owner;
             break;
         case 'project':
             $blog->project = $blog->owner;
             break;
     }
     if ($blog->node == \GOTEO_NODE) {
         $blog->posts = Blog\Post::getAll();
     } elseif (!empty($blog->id)) {
         $blog->posts = Blog\Post::getAll($blog->id);
     } else {
         $blog->posts = array();
     }
     return $blog;
 }
Esempio n. 2
0
 public function index($post = null)
 {
     if (!empty($post)) {
         $show = 'post';
         // -- Mensaje azul molesto para usuarios no registrados
         if (empty($_SESSION['user'])) {
             $_SESSION['jumpto'] = '/blog/' . $post;
             Message::Info(Text::html('user-login-required'));
         }
     } else {
         $show = 'list';
     }
     // sacamos su blog
     $blog = Model\Blog::get(\GOTEO_NODE, 'node');
     $filters = array();
     if (isset($_GET['tag'])) {
         $tag = Model\Blog\Post\Tag::get($_GET['tag']);
         if (!empty($tag->id)) {
             $filters['tag'] = $tag->id;
         }
     } else {
         $tag = null;
     }
     if (isset($_GET['author'])) {
         $author = Model\User::getMini($_GET['author']);
         if (!empty($author->id)) {
             $filters['author'] = $author->id;
         }
     } else {
         $author = null;
     }
     if (!empty($filters)) {
         $blog->posts = Model\Blog\Post::getList($filters);
     }
     if (isset($post) && !isset($blog->posts[$post]) && $_GET['preview'] != $_SESSION['user']->id) {
         throw new \Goteo\Core\Redirection('/blog');
     }
     // segun eso montamos la vista
     return new View('view/blog/index.html.php', array('blog' => $blog, 'show' => $show, 'filters' => $filters, 'post' => $post, 'owner' => \GOTEO_NODE));
 }
Esempio n. 3
0
 /**
  *  Metodo para sacar los eventos
  *
  * @param string $type  tipo de evento (public: columnas goteo, proyectos, comunidad;  admin: categorias de filtro)
  * @param string $scope ambito de eventos (public | admin)
  * @param numeric $limit limite de elementos
  * @return array list of items
  */
 public static function getAll($type = 'all', $scope = 'public', $limit = '99', $node = null)
 {
     $list = array();
     try {
         $values = array(':scope' => $scope);
         $sqlType = '';
         if ($type != 'all') {
             $sqlType = " AND feed.type = :type";
             $values[':type'] = $type;
         } else {
             // acciones del web service ultra secreto
             $sqlType = " AND feed.type != 'usws'";
         }
         $sqlNode = '';
         if (!empty($node) && $node != \GOTEO_NODE) {
             /* segun el objetivo del feed sea:
              * proyectos del nodo
              * usuarios del nodo
              * convocatorias destacadas por el nodo (aunque inactivas)
              * el propio nodo
              * el blog
              */
             $sqlNode = " AND (\n                        (feed.target_type = 'project' AND feed.target_id IN (\n                            SELECT id FROM project WHERE node = :node\n                            )\n                        )\n                        OR (feed.target_type = 'user' AND feed.target_id IN (\n                            SELECT id FROM user WHERE node = :node\n                            )\n                        )\n                        OR (feed.target_type = 'call' AND feed.target_id IN (\n                            SELECT `call` FROM campaign WHERE node = :node\n                            )\n                        )\n                        OR (feed.target_type = 'node' AND feed.target_id = :node)\n                        OR (feed.target_type = 'blog')\n                    )";
             $values[':node'] = $node;
         }
         $sql = "SELECT\n                            feed.id as id,\n                            feed.title as title,\n                            feed.url as url,\n                            feed.image as image,\n                            DATE_FORMAT(feed.datetime, '%H:%i %d|%m|%Y') as date,\n                            feed.datetime as timer,\n                            feed.html as html\n                        FROM feed\n                        WHERE feed.scope = :scope \n                        {$sqlType}\n                        {$sqlNode}\n                        ORDER BY datetime DESC\n                        LIMIT {$limit}\n                        ";
         $query = Model::query($sql, $values);
         foreach ($query->fetchAll(\PDO::FETCH_CLASS, __CLASS__) as $item) {
             // si es la columan goteo, vamos a cambiar el html por el del post traducido
             if ($type == 'goteo') {
                 // primero sacamos la id del post de la url
                 $matches = array();
                 \preg_match('(\\d+)', $item->url, $matches);
                 if (!empty($matches[0])) {
                     //  luego hacemos get del post
                     $post = Post::get($matches[0], LANG);
                     if ($post->owner_type == 'node' && $post->owner_id != \GOTEO_NODE) {
                         if (!\Goteo\Core\NodeSys::isActive($post->owner_id)) {
                             continue;
                         }
                     }
                     // y substituimos el $item->html por el $post->html
                     $item->html = Text::recorta($post->text, 250);
                     $item->title = $post->title;
                     $item->image = $post->image->id;
                     // arreglo la fecha de publicación
                     $parts = explode(' ', $item->timer);
                     $item->timer = $post->date . ' ' . $parts[1];
                 }
             }
             //hace tanto
             $item->timeago = self::time_ago($item->timer);
             $list[] = $item;
         }
         return $list;
     } catch (\PDOException $e) {
         throw new Exception(Text::_('No se ha guardado correctamente. ') . $e->getMessage() . "<br />{$sql}<br /><pre>" . print_r($values, 1) . "</pre>");
     }
 }
Esempio n. 4
0
 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);
     }
 }
Esempio n. 5
0
    Goteo\Model\Blog\Post;

$project = $this['project'];
$blog    = $this['blog'];
if (empty($this['post'])) {
    $posts = $blog->posts;
    $action = 'list';
    $this['show'] = 'list';
} else {
    $post = $this['post'];
    if (!in_array($post, array_keys($blog->posts))) {
        $posts = $blog->posts;
        $action = 'list';
        $this['show'] = 'list';
    } else {
        $post = Post::get($post, LANG);
        $action = 'post';
        $this['show'] = 'post';
    }
}

if ($this['show'] == 'list') {
    // paginacion
    require_once 'library/pagination/pagination.php';

    //recolocamos los post para la paginacion
    $the_posts = array();
    foreach ($posts as $i=>$p) {
        $the_posts[] = $p;
    }
Esempio n. 6
0
 private function view($id, $show, $post = null)
 {
     $project = Model\Project::get($id, LANG);
     // recompensas
     foreach ($project->individual_rewards as &$reward) {
         $reward->none = false;
         $reward->taken = $reward->getTaken();
         // cofinanciadores quehan optado por esta recompensas
         // si controla unidades de esta recompensa, mirar si quedan
         if ($reward->units > 0 && $reward->taken >= $reward->units) {
             $reward->none = true;
         }
     }
     // mensaje cuando, sin estar en campaña, tiene fecha de publicación, es que la campaña ha sido cancelada
     if ($project->status < 3 && !empty($project->published)) {
         Message::Info(Text::get('project-unpublished'));
     } elseif ($project->status < 3) {
         // mensaje de no publicado siempre que no esté en campaña
         Message::Info(Text::get('project-not_published'));
     }
     // solamente se puede ver publicamente si...
     $grant = false;
     if ($project->status > 2) {
         // está publicado
         $grant = true;
     } elseif ($project->owner == $_SESSION['user']->id) {
         // es el dueño
         $grant = true;
     } elseif (ACL::check('/project/edit/todos')) {
         // es un admin
         $grant = true;
     } elseif (ACL::check('/project/view/todos')) {
         // es un usuario con permiso
         $grant = true;
     } elseif (isset($_SESSION['user']->roles['checker']) && Model\User\Review::is_assigned($_SESSION['user']->id, $project->id)) {
         // es un revisor y lo tiene asignado
         $grant = true;
     }
     // (Callsys)
     // si lo puede ver
     if ($grant) {
         $viewData = array('project' => $project, 'show' => $show);
         // sus entradas de novedades
         $blog = Model\Blog::get($project->id);
         // si está en modo preview, ponemos  todas las entradas, incluso las no publicadas
         if (isset($_GET['preview']) && $_GET['preview'] == $_SESSION['user']->id) {
             $blog->posts = Model\Blog\Post::getAll($blog->id, null, false);
         }
         $viewData['blog'] = $blog;
         // tenemos que tocar esto un poquito para motrar las necesitades no economicas
         if ($show == 'needs-non') {
             $viewData['show'] = 'needs';
             $viewData['non-economic'] = true;
         }
         // -- Mensaje azul molesto para usuarios no registrados
         if (($show == 'messages' || $show == 'updates') && empty($_SESSION['user'])) {
             Message::Info(Text::html('user-login-required'));
         }
         //tenemos que tocar esto un poquito para gestionar los pasos al aportar
         if ($show == 'invest') {
             // si no está en campaña no pueden estar aqui ni de coña
             if ($project->status != 3) {
                 Message::Info(Text::get('project-invest-closed'));
                 throw new Redirection('/project/' . $id, Redirection::TEMPORARY);
             }
             $viewData['show'] = 'supporters';
             /* pasos de proceso aporte
              *
              * 1, 'start': ver y seleccionar recompensa (y cantidad)
              * 2, 'login': loguear con usuario/contraseña o con email (que crea el usuario automáticamente)
              * 3, 'confirm': confirmar los datos y saltar a la pasarela de pago
              * 4, 'ok'/'fail': al volver de la pasarela de pago, la confirmación nos dice si todo bien o algo mal
              * 5, 'continue': recuperar aporte incompleto (variante de confirm)
              */
             // usamos la variable de url $post para movernos entre los pasos
             $step = isset($post) && in_array($post, array('start', 'login', 'confirm', 'continue')) ? $post : 'start';
             // si llega confirm ya ha terminado el proceso de aporte
             if (isset($_GET['confirm']) && \in_array($_GET['confirm'], array('ok', 'fail'))) {
                 unset($_SESSION['invest-amount']);
                 // confirmación
                 $step = $_GET['confirm'];
             } else {
                 // si no, a ver en que paso estamos
                 if (isset($_GET['amount'])) {
                     $_SESSION['invest-amount'] = $_GET['amount'];
                 }
                 // si el usuario está validado, recuperamos posible amount y mostramos
                 if ($_SESSION['user'] instanceof Model\User) {
                     $step = 'confirm';
                 } elseif ($step != 'start' && empty($_SESSION['user'])) {
                     // si no está validado solo puede estar en start
                     Message::Info(Text::get('user-login-required-to_invest'));
                     $step = 'start';
                 } elseif ($step == 'start') {
                     // para cuando salte
                     $_SESSION['jumpto'] = SEC_URL . '/project/' . $id . '/invest/#continue';
                 } else {
                     $step = 'start';
                 }
             }
             $viewData['step'] = $step;
         }
         if ($show == 'updates') {
             $viewData['post'] = $post;
             $viewData['owner'] = $project->owner;
         }
         if ($show == 'messages' && $project->status < 3) {
             Message::Info(Text::get('project-messages-closed'));
         }
         return new View('view/project/view.html.php', $viewData);
     } else {
         // no lo puede ver
         throw new Redirection("/");
     }
 }
Esempio n. 7
0
 *  Goteo is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Goteo is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with Goteo.  If not, see <http://www.gnu.org/licenses/agpl.txt>.
 *
 */
use Goteo\Library\Text, Goteo\Model\Blog\Post;
$post = Post::get($this['post'], LANG);
$level = (int) $this['level'] ?: 3;
//@TODO: Si el usuario es el dueño del blog o tiene permiso para moderar, boton de borrar comentario
?>
<h<?php 
echo $level;
?>
 class="title"><?php 
echo Text::get('blog-coments-header');
?>
</h<?php 
echo $level;
?>
>
<div class="widget post-comments">
Esempio n. 8
0
File: blog.php Progetto: kenjs/Goteo
 public static function process($action = 'list', $id = null, $filters = array())
 {
     $errors = array();
     $node = empty($_SESSION['admin_node']) ? \GOTEO_NODE : $_SESSION['admin_node'];
     $blog = Model\Blog::get($node, 'node');
     if (!$blog instanceof \Goteo\Model\Blog) {
         $blog = new Model\Blog(array('type' => 'node', 'owner' => $node, 'active' => 1));
         if ($blog->save($errors)) {
             Message::Info(Text::get('admin-blog-info-initialize'));
         } else {
             Message::Error(Text::get('admin-blog-error-initialize'));
             throw new Redirection('/admin');
         }
     } elseif (!$blog->active) {
         Message::Error(Text::get('admin-blog-error-no_blog'));
         throw new Redirection('/admin');
     }
     // primero comprobar que tenemos blog
     if (!$blog instanceof Model\Blog) {
         Message::Error(Text::get('admin-blog-error-not_found'));
         throw new Redirection('/admin');
     }
     $url = '/admin/blog';
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         if (empty($_POST['blog'])) {
             Message::Error(Text::get('admin-blog-error_missing_blog'));
             break;
         }
         $editing = false;
         if (!empty($_POST['id'])) {
             $post = Model\Blog\Post::get($_POST['id']);
         } else {
             $post = new Model\Blog\Post();
         }
         // campos que actualizamos
         $fields = array('id', 'blog', 'title', 'text', 'image', 'media', 'legend', 'date', 'publish', 'home', 'footer', 'allow', 'author');
         foreach ($fields as $field) {
             $post->{$field} = $_POST[$field];
         }
         // tratar la imagen y ponerla en la propiedad image
         if (!empty($_FILES['image_upload']['name'])) {
             $post->image = $_FILES['image_upload'];
             $editing = true;
         }
         // tratar las imagenes que quitan
         foreach ($post->gallery as $key => $image) {
             if (!empty($_POST["gallery-{$image->id}-remove"])) {
                 $image->remove('post');
                 unset($post->gallery[$key]);
                 if ($post->image == $image->id) {
                     $post->image = '';
                 }
                 $editing = true;
             }
         }
         if (!empty($post->media)) {
             $post->media = new Model\Project\Media($post->media);
         }
         $post->tags = $_POST['tags'];
         // si tenemos un nuevio tag hay que añadirlo
         if (!empty($_POST['new-tag_save']) && !empty($_POST['new-tag'])) {
             // grabar el tag en la tabla de tag,
             $new_tag = new Model\Blog\Post\Tag(array('id' => '', 'name' => $_POST['new-tag']));
             if ($new_tag->save($errors)) {
                 $post->tags[] = $new_tag->id;
                 // asignar al post
             } else {
                 Message::Error(implode('<br />', $errors));
             }
             $editing = true;
             // seguir editando
         }
         /// este es el único save que se lanza desde un metodo process_
         if ($post->save($errors)) {
             if ($action == 'edit') {
                 Message::Info(Text::get('admin-blog-info-updates-saved'));
             } else {
                 Message::Info(Text::get('admin-blog-info-add_new'));
                 $id = $post->id;
             }
             $action = $editing ? 'edit' : 'list';
             if ((bool) $post->publish) {
                 // Evento Feed
                 $log = new Feed();
                 $log->setTarget('goteo', 'blog');
                 $log->populate('nueva entrada blog Goteo (admin)', '/admin/blog', \vsprintf('El admin %s ha %s en el blog Goteo la entrada "%s"', array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('relevant', 'Publicado'), Feed::item('blog', $post->title, $post->id))));
                 $log->doAdmin('admin');
                 // evento público
                 $log->unique = true;
                 $log->populate($post->title, '/blog/' . $post->id, Text::recorta($post->text, 250), $post->gallery[0]->id);
                 $log->doPublic('goteo');
                 unset($log);
             } else {
                 //sino lo quitamos
                 \Goteo\Core\Model::query("DELETE FROM feed WHERE url = '/blog/{$post->id}' AND scope = 'public' AND type = 'goteo'");
             }
         } else {
             Message::Error(Text::get('admin-blog-error-save-fail') . ':<br />' . \implode('<br />', $errors));
         }
     }
     switch ($action) {
         case 'list':
             // lista de entradas
             // obtenemos los datos
             $filters['node'] = $node;
             $show = array('all' => 'Todas las entradas existentes', 'published' => 'Solamente las publicadas en el blog', 'owned' => 'Solamente las del propio nodo', 'home' => 'Solamente las de portada', 'entries' => 'Solamente las de cierto nodo', 'updates' => 'Solamente las de proyectos');
             // filtro de blogs de proyectos/nodos
             switch ($filters['show']) {
                 case 'updates':
                     $blogs = Model\Blog::getListProj();
                     break;
                 case 'entries':
                     $blogs = Model\Blog::getListNode();
                     break;
             }
             if (!in_array($filters['show'], array('entries', 'updates')) || !isset($blogs[$filters['blog']])) {
                 unset($filters['blog']);
             }
             $posts = Model\Blog\Post::getList($filters, false);
             $homes = Model\Post::getList('home', $node);
             $footers = Model\Post::getList('footer', $node);
             if ($node == \GOTEO_NODE) {
                 $show['footer'] = 'Solamente las del footer';
             }
             return new View('view/admin/index.html.php', array('folder' => 'blog', 'file' => 'list', 'posts' => $posts, 'filters' => $filters, 'show' => $show, 'blogs' => $blogs, 'homes' => $homes, 'footers' => $footers, 'node' => $node));
             break;
         case 'add':
             // nueva entrada con wisiwig
             // obtenemos datos basicos
             $post = new Model\Blog\Post(array('blog' => $blog->id, 'date' => date('Y-m-d'), 'publish' => false, 'allow' => true, 'tags' => array(), 'author' => $_SESSION['user']->id));
             $message = 'Añadiendo una nueva entrada';
             return new View('view/admin/index.html.php', array('folder' => 'blog', 'file' => 'edit', 'action' => 'add', 'post' => $post, 'tags' => Model\Blog\Post\Tag::getAll(), 'message' => $message));
             break;
         case 'edit':
             if (empty($id)) {
                 Message::Error(Text::get('admin-blog-error-nopost'));
                 throw new Redirection('/admin/blog');
                 break;
             } else {
                 $post = Model\Blog\Post::get($id);
                 if (!$post instanceof Model\Blog\Post) {
                     Message::Error(Text::get('admin-blog-error-break_entry'));
                     $action = 'list';
                     break;
                 } elseif ($node != \GOTEO_NODE && $post->owner_type == 'node' && $post->owner_id != $node) {
                     Message::Error(Text::get('admin-blog-error-noedit'));
                     throw new Redirection('/admin/blog/list');
                 }
             }
             $message = 'Editando una entrada existente';
             return new View('view/admin/index.html.php', array('folder' => 'blog', 'file' => 'edit', 'action' => 'edit', 'post' => $post, 'tags' => Model\Blog\Post\Tag::getAll(), 'message' => $message));
             break;
         case 'remove':
             // eliminar una entrada
             $tempData = Model\Blog\Post::get($id);
             if ($node != \GOTEO_NODE && $tempData->owner_type == 'node' && $tempData->owner_id != $node) {
                 Message::Error(Text::get('admin-blog-error-nodelete'));
                 throw new Redirection('/admin/blog');
             }
             if (Model\Blog\Post::delete($id)) {
                 // Evento Feed
                 $log = new Feed();
                 $log->setTarget('goteo', 'blog');
                 $log->populate('Quita entrada de blog (admin)', '/admin/blog', \vsprintf('El admin %s ha %s la entrada "%s" del blog de Goteo', array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('relevant', 'Quitado'), Feed::item('blog', $tempData->title))));
                 $log->doAdmin('admin');
                 unset($log);
                 Message::Info(Text::get('admin-blog-info-deleted_entry'));
             } else {
                 Message::Error(Text::get('admin-blog-error-delete-fail'));
             }
             throw new Redirection('/admin/blog/list');
             break;
             // acciones portada
         // acciones portada
         case 'reorder':
             // lista de entradas en portada
             // obtenemos los datos
             $posts = Model\Post::getAll('home', $node);
             return new View('view/admin/index.html.php', array('folder' => 'blog', 'file' => 'order', 'posts' => $posts));
             break;
         case 'up':
             if ($node != \GOTEO_NODE) {
                 Model\Post::up_node($id, $node);
             } else {
                 Model\Post::up($id, 'home');
             }
             throw new Redirection('/admin/blog/reorder');
             break;
         case 'down':
             if ($node != \GOTEO_NODE) {
                 Model\Post::up_node($id, $node);
             } else {
                 Model\Post::down($id, 'home');
             }
             throw new Redirection('/admin/blog/reorder');
             break;
         case 'add_home':
             // siguiente orden
             if ($node != \GOTEO_NODE) {
                 $next = Model\Post::next_node($node);
                 $data = (object) array('post' => $id, 'node' => $node, 'order' => $next);
                 if (Model\Post::update_node($data, $errors)) {
                     Message::Info(Text::get('admin-blog-info-add-home'));
                 } else {
                     Message::Error(Text::get('admin-blog-error-any-problem') . ':<br />' . \implode('<br />', $errors));
                 }
             } else {
                 $next = Model\Post::next('home');
                 $post = new Model\Post(array('id' => $id, 'order' => $next, 'home' => 1));
                 if ($post->update($errors)) {
                     Message::Info(Text::get('admin-blog-info-add-home'));
                 } else {
                     Message::Error(Text::get('admin-blog-error-any-problem') . ':<br />' . \implode('<br />', $errors));
                 }
             }
             throw new Redirection('/admin/blog/list');
             break;
         case 'remove_home':
             // se quita de la portada solamente
             $ok = false;
             if ($node != \GOTEO_NODE) {
                 $ok = Model\Post::remove_node($id, $node);
             } else {
                 $ok = Model\Post::remove($id, 'home');
             }
             if ($ok) {
                 Message::Info(Text::get('admin-blog-info-removecover'));
             } else {
                 Message::Error(Text::get('admin-blog-error-cover-deletefail'));
             }
             throw new Redirection('/admin/blog/list');
             break;
             // acciones footer (solo para superadmin y admins de goteo
         // acciones footer (solo para superadmin y admins de goteo
         case 'footer':
             if ($node == \GOTEO_NODE) {
                 // lista de entradas en el footer
                 // obtenemos los datos
                 $posts = Model\Post::getAll('footer');
                 return new View('view/admin/index.html.php', array('folder' => 'blog', 'file' => 'footer', 'posts' => $posts));
             } else {
                 throw new Redirection('/admin/blog/list');
             }
             break;
         case 'up_footer':
             if ($node == \GOTEO_NODE) {
                 Model\Post::up($id, 'footer');
                 throw new Redirection('/admin/blog/footer');
             } else {
                 throw new Redirection('/admin/blog');
             }
             break;
         case 'down_footer':
             if ($node == \GOTEO_NODE) {
                 Model\Post::down($id, 'footer');
                 throw new Redirection('/admin/blog/footer');
             } else {
                 throw new Redirection('/admin/blog');
             }
             break;
         case 'add_footer':
             if ($node == \GOTEO_NODE) {
                 // siguiente orden
                 $next = Model\Post::next('footer');
                 $post = new Model\Post(array('id' => $id, 'order' => $next, 'footer' => 1));
                 if ($post->update($errors)) {
                     Message::Info(Text::get('admin-blog-info-footer-complete'));
                 } else {
                     Message::Error(Text::get('admin-blog-error-any-problem') . ':<br />' . \implode('<br />', $errors));
                 }
             }
             throw new Redirection('/admin/blog');
             break;
         case 'remove_footer':
             if ($node == \GOTEO_NODE) {
                 // se quita del footer solamente
                 if (Model\Post::remove($id, 'footer')) {
                     Message::Info(Text::get('admin-blog-info-footer-delete'));
                 } else {
                     Message::Error(Text::get('admin-blog-error-footer-deletefail'));
                 }
             }
             throw new Redirection('/admin/blog/list');
             break;
     }
 }
Esempio n. 9
0
 /**
  * Graba un registro de novedad con lo recibido por POST
  * 
  * @param array  $action (add o edit) y $id del post
  * @param object $project Instancia de proyecto de trabajo
  * @param array $errors (por referncia)
  * @return array $action por si se queda editando o sale a la lista y $id por si es un add y se queda editando
  */
 public static function process_updates($action, $project, &$errors = array())
 {
     $editing = false;
     if (!empty($_POST['id'])) {
         $post = Model\Blog\Post::get($_POST['id']);
     } else {
         $post = new Model\Blog\Post();
     }
     // campos que actualizamos
     $fields = array('id', 'blog', 'title', 'text', 'image', 'media', 'legend', 'date', 'publish', 'allow');
     foreach ($fields as $field) {
         $post->{$field} = $_POST[$field];
     }
     // tratar la imagen y ponerla en la propiedad image
     if (!empty($_FILES['image_upload']['name'])) {
         $post->image = $_FILES['image_upload'];
         $editing = true;
     }
     // tratar las imagenes que quitan
     foreach ($post->gallery as $key => $image) {
         if (!empty($_POST["gallery-{$image->id}-remove"])) {
             $image->remove('post');
             unset($post->gallery[$key]);
             if ($post->image == $image->id) {
                 $post->image = '';
             }
             $editing = true;
         }
     }
     if (!empty($post->media)) {
         $post->media = new Model\Project\Media($post->media);
     }
     // el blog de proyecto no tiene tags?¿?
     // $post->tags = $_POST['tags'];
     /// este es el único save que se lanza desde un metodo process_
     if ($post->save($errors)) {
         $id = $post->id;
         if ($action == 'edit') {
             Message::Info(Text::get('dashboard-project-updates-saved'));
         } else {
             Message::Info(Text::get('dashboard-project-updates-inserted'));
         }
         $action = $editing ? 'edit' : 'list';
         // si ha marcado publish, grabamos evento de nueva novedad en proyecto
         if ((bool) $post->publish) {
             // Evento Feed
             $log = new Feed();
             $log->setTarget($project->id);
             $log->populate('usuario publica una novedad en su proyecto (dashboard)', '/project/' . $project->id . '/updates/' . $post->id, \vsprintf('%s ha publicado un nuevo post en %s sobre el proyecto %s, con el título "%s"', array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('blog', Text::get('project-menu-updates')), Feed::item('project', $project->name, $project->id), Feed::item('update', $post->title, $project->id . '/updates/' . $post->id))));
             $log->unique = true;
             $log->doAdmin('user');
             // evento público
             $log->populate($post->title, '/project/' . $project->id . '/updates/' . $post->id, Text::html('feed-new_update', Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('blog', Text::get('project-menu-updates')), Feed::item('project', $project->name, $project->id)), $post->gallery[0]->id);
             $log->doPublic('projects');
             // si no ha encontrado otro, lanzamos la notificación a cofinanciadores
             if (!$log->unique_issue) {
                 \Goteo\Controller\Cron\Send::toInvestors('update', $project, $post);
             }
             unset($log);
         }
     } else {
         $errors[] = Text::get('dashboard-project-updates-fail');
     }
     return array($action, $id);
 }
Esempio n. 10
0
 public function translates($option = 'overview', $action = 'list', $id = null)
 {
     $user = $_SESSION['user'];
     $errors = array();
     $langs = \Goteo\Library\i18n\Lang::getAll();
     if ($action == 'lang' && !empty($_POST['lang'])) {
         $_SESSION['translate_lang'] = $_POST['lang'];
     } elseif (empty($_SESSION['translate_lang'])) {
         $_SESSION['translate_lang'] = 'en';
     }
     $projects = Model\User\Translate::getMyProjects($user->id);
     // al seleccionar controlamos: translate_type
     if ($action == 'select' && !empty($_POST['type'])) {
         unset($_SESSION['translate_project']);
         // quitamos el proyecto de traducción
         $type = $_POST['type'];
         if (!empty($_POST[$type])) {
             $_SESSION['translate_type'] = $type;
             $_SESSION['translate_' . $type] = $_POST[$type];
         } else {
             $_SESSION['translate_type'] = 'profile';
         }
     }
     // view data basico para esta seccion
     $viewData = array('menu' => self::menu(), 'section' => __FUNCTION__, 'option' => $option, 'action' => $action, 'langs' => $langs, 'projects' => $projects, 'errors' => $errors, 'success' => $success);
     // aqui, segun lo que este traduciendo, necesito tener un proyecto de trabajo, una convocatoria o mi perfil personal
     switch ($_SESSION['translate_type']) {
         case 'project':
             try {
                 // si lo que tenemos en sesion no es una instancia de proyecto (es una id de proyecto)
                 if ($_SESSION['translate_project'] instanceof Model\Project) {
                     $project = Model\Project::get($_SESSION['translate_project']->id, $_SESSION['translate_lang']);
                 } else {
                     $project = Model\Project::get($_SESSION['translate_project'], $_SESSION['translate_lang']);
                 }
             } catch (\Goteo\Core\Error $e) {
                 $project = null;
             }
             if (!$project instanceof Model\Project) {
                 Message::Error('Ha fallado al cargar los datos del proyecto');
                 $_SESSION['translate_type'] = 'profile';
                 throw new Redirection('/dashboard/translates');
             }
             $_SESSION['translate_project'] = $project;
             $project->lang_name = $langs[$project->lang]->name;
             unset($viewData['langs'][$project->lang]);
             // quitamos el idioma original
             //// Control de traduccion de proyecto
             if ($option == 'updates') {
                 // sus novedades
                 $blog = Model\Blog::get($project->id);
                 if ($action != 'edit') {
                     $action = 'list';
                 }
             }
             // tratar lo que llega por post para guardar los datos
             if ($_SERVER['REQUEST_METHOD'] == 'POST') {
                 switch ($option) {
                     case 'profile':
                         if ($action == 'save') {
                             $user = Model\User::get($_POST['id'], $_SESSION['translate_lang']);
                             $user->about_lang = $_POST['about'];
                             $user->keywords_lang = $_POST['keywords'];
                             $user->contribution_lang = $_POST['contribution'];
                             $user->lang = $_SESSION['translate_lang'];
                             $user->saveLang($errors);
                         }
                         break;
                     case 'overview':
                         if ($action == 'save') {
                             $project->description_lang = $_POST['description'];
                             $project->motivation_lang = $_POST['motivation'];
                             $project->video_lang = $_POST['video'];
                             $project->about_lang = $_POST['about'];
                             $project->goal_lang = $_POST['goal'];
                             $project->related_lang = $_POST['related'];
                             $project->reward_lang = $_POST['reward'];
                             $project->keywords_lang = $_POST['keywords'];
                             $project->media_lang = $_POST['media'];
                             $project->subtitle_lang = $_POST['subtitle'];
                             $project->lang_lang = $_SESSION['translate_lang'];
                             $project->saveLang($errors);
                         }
                         break;
                     case 'costs':
                         if ($action == 'save') {
                             foreach ($project->costs as $key => $cost) {
                                 if (isset($_POST['cost-' . $cost->id . '-cost'])) {
                                     $cost->cost_lang = $_POST['cost-' . $cost->id . '-cost'];
                                     $cost->description_lang = $_POST['cost-' . $cost->id . '-description'];
                                     $cost->lang = $_SESSION['translate_lang'];
                                     $cost->saveLang($errors);
                                 }
                             }
                         }
                         break;
                     case 'rewards':
                         if ($action == 'save') {
                             foreach ($project->social_rewards as $k => $reward) {
                                 if (isset($_POST['social_reward-' . $reward->id . '-reward'])) {
                                     $reward->reward_lang = $_POST['social_reward-' . $reward->id . '-reward'];
                                     $reward->description_lang = $_POST['social_reward-' . $reward->id . '-description'];
                                     $reward->other_lang = $_POST['social_reward-' . $reward->id . '-other'];
                                     $reward->lang = $_SESSION['translate_lang'];
                                     $reward->saveLang($errors);
                                 }
                             }
                             foreach ($project->individual_rewards as $k => $reward) {
                                 if (isset($_POST['individual_reward-' . $reward->id . '-reward'])) {
                                     $reward->reward_lang = $_POST['individual_reward-' . $reward->id . '-reward'];
                                     $reward->description_lang = $_POST['individual_reward-' . $reward->id . '-description'];
                                     $reward->other_lang = $_POST['individual_reward-' . $reward->id . '-other'];
                                     $reward->lang = $_SESSION['translate_lang'];
                                     $reward->saveLang($errors);
                                 }
                             }
                         }
                         break;
                     case 'supports':
                         if ($action == 'save') {
                             // tratar colaboraciones existentes
                             foreach ($project->supports as $key => $support) {
                                 if (isset($_POST['support-' . $support->id . '-support'])) {
                                     // guardamos los datos traducidos
                                     $support->support_lang = $_POST['support-' . $support->id . '-support'];
                                     $support->description_lang = $_POST['support-' . $support->id . '-description'];
                                     $support->lang = $_SESSION['translate_lang'];
                                     $support->saveLang($errors);
                                     // actualizar el Mensaje correspondiente, solamente actualizar
                                     $msg = Model\Message::get($support->thread);
                                     $msg->message_lang = "{$support->support_lang}: {$support->description_lang}";
                                     $msg->lang = $_SESSION['translate_lang'];
                                     $msg->saveLang($errors);
                                 }
                             }
                         }
                         break;
                     case 'updates':
                         if (empty($_POST['blog']) || empty($_POST['id'])) {
                             break;
                         }
                         $post = Model\Blog\Post::get($_POST['id']);
                         $post->title_lang = $_POST['title'];
                         $post->text_lang = $_POST['text'];
                         $post->media_lang = $_POST['media'];
                         $post->legend_lang = $_POST['legend'];
                         $post->lang = $_SESSION['translate_lang'];
                         $post->saveLang($errors);
                         $action = 'edit';
                         break;
                 }
             }
             switch ($option) {
                 case 'profile':
                     $viewData['user'] = Model\User::get($project->owner, $_SESSION['translate_lang']);
                     break;
                 case 'overview':
                     break;
                 case 'costs':
                     if ($_POST) {
                         foreach ($_POST as $k => $v) {
                             if (!empty($v) && preg_match('/cost-(\\d+)-edit/', $k, $r)) {
                                 $viewData[$k] = true;
                             }
                         }
                     }
                     break;
                 case 'rewards':
                     if ($_POST) {
                         foreach ($_POST as $k => $v) {
                             if (!empty($v) && preg_match('/((social)|(individual))_reward-(\\d+)-edit/', $k)) {
                                 $viewData[$k] = true;
                                 break;
                             }
                         }
                     }
                     break;
                 case 'supports':
                     if ($_POST) {
                         foreach ($_POST as $k => $v) {
                             if (!empty($v) && preg_match('/support-(\\d+)-edit/', $k, $r)) {
                                 $viewData[$k] = true;
                                 break;
                             }
                         }
                     }
                     break;
                     // publicar actualizaciones
                 // publicar actualizaciones
                 case 'updates':
                     $viewData['blog'] = $blog;
                     if ($action == 'edit') {
                         $post = Model\Blog\Post::get($id, $_SESSION['translate_lang']);
                         $viewData['post'] = $post;
                     } else {
                         $posts = array();
                         foreach ($blog->posts as $post) {
                             $posts[] = Model\Blog\Post::get($post->id, $_SESSION['translate_lang']);
                         }
                         $viewData['posts'] = $posts;
                     }
                     break;
             }
             $viewData['project'] = $project;
             //// FIN Control de traduccion de proyecto
             break;
         default:
             // profile
             $viewData['option'] = 'profile';
             unset($langs['es']);
             if ($_SERVER['REQUEST_METHOD'] == 'POST') {
                 if ($action == 'save') {
                     $user = Model\User::get($_POST['id'], $_SESSION['translate_lang']);
                     $user->about_lang = $_POST['about'];
                     $user->keywords_lang = $_POST['keywords'];
                     $user->contribution_lang = $_POST['contribution'];
                     $user->lang = $_SESSION['translate_lang'];
                     $user->saveLang($errors);
                 }
             }
             $viewData['user'] = Model\User::get($user->id, $_SESSION['translate_lang']);
     }
     if (!empty($errors)) {
         Message::Error('HA HABIDO ERRORES: <br />' . implode('<br />', $errors));
     }
     return new View('view/dashboard/index.html.php', $viewData);
 }
Esempio n. 11
0
        <p><?php 
        echo Text::get('blog-no_posts');
        ?>
</p>
    <?php 
    }
    ?>

</div>

<?php 
} else {
    // sueprform!
    $post = $this['post'];
    // si edit
    $original = \Goteo\Model\Blog\Post::get($post->id);
    if (!empty($post->media->url)) {
        $media = array('type' => 'media', 'title' => Text::get('overview-field-media_preview'), 'class' => 'inline media', 'type' => 'html', 'html' => !empty($post->media) ? $post->media->getEmbedCode() : '');
    } else {
        $media = array('type' => 'hidden', 'class' => 'inline');
    }
    ?>

    <form method="post" action="/dashboard/translates/updates/save/<?php 
    echo $post->id;
    ?>
" class="project" enctype="multipart/form-data">

    <?php 
    echo new SuperForm(array('action' => '', 'level' => 3, 'method' => 'post', 'title' => '', 'hint' => Text::get('guide-project-updates'), 'class' => 'aqua', 'footer' => array('view-step-preview' => array('type' => 'submit', 'name' => 'save-post', 'label' => Text::get('regular-save'), 'class' => 'next')), 'elements' => array('id' => array('type' => 'hidden', 'value' => $post->id), 'blog' => array('type' => 'hidden', 'value' => $post->blog), 'title-orig' => array('type' => 'html', 'title' => 'Título', 'html' => $original->title), 'title' => array('type' => 'textbox', 'size' => 20, 'class' => 'inline', 'title' => '', 'hint' => Text::get('tooltip-updates-title'), 'errors' => array(), 'value' => $post->title), 'text-orig' => array('type' => 'html', 'title' => 'Texto de la entrada', 'html' => nl2br($original->text)), 'text' => array('type' => 'textarea', 'cols' => 40, 'rows' => 4, 'class' => 'inline', 'title' => '', 'hint' => Text::get('tooltip-updates-text'), 'errors' => array(), 'value' => $post->text), 'media-orig' => array('type' => 'html', 'title' => 'Vídeo', 'html' => (string) $original->media->url), 'media' => array('type' => 'textbox', 'title' => '', 'class' => 'inline media', 'hint' => Text::get('tooltip-updates-media'), 'errors' => array(), 'value' => (string) $post->media), 'media-upload' => array('name' => "upload", 'type' => 'submit', 'label' => Text::get('form-upload-button'), 'class' => 'inline media-upload'), 'media-preview' => $media, 'legend-orig' => array('type' => 'html', 'title' => Text::get('regular-media_legend'), 'html' => nl2br($original->legend)), 'legend' => array('type' => 'textarea', 'title' => '', 'class' => 'inline', 'value' => $post->legend))));
    ?>
Esempio n. 12
0
 *  Goteo is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Goteo is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with Goteo.  If not, see <http://www.gnu.org/licenses/agpl.txt>.
 *
 */
use Goteo\Library\Text, Goteo\Model\Blog\Post;
$allow = Post::allowed($this['post']);
$level = (int) $this['level'] ?: 3;
if ($allow == 1) {
    ?>
<script type="text/javascript">
	jQuery(document).ready(function ($) { 
	    //change div#preview content when textarea lost focus
		$("#message").blur(function(){
			$("#preview").html($("#message").val());
		});
		
		//add fancybox on #a-preview click
		$("#a-preview").fancybox({
			'titlePosition'		: 'inside',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none'
Esempio n. 13
0
 *  Goteo is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with Goteo.  If not, see <http://www.gnu.org/licenses/agpl.txt>.
 *
 */
use Goteo\Library\Text, Goteo\Model\Blog\Post;
$blog = $this['blog'];
$list = array();
switch ($this['type']) {
    case 'posts':
        $title = Text::get('blog-side-last_posts');
        $items = Post::getAll($blog->id, 7);
        // enlace a la entrada
        foreach ($items as $item) {
            $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;
Esempio n. 14
0
         <meta property="og:type" content="article" />
     <? endif; ?>
     <meta property="og:site_name" content="<?php echo $ogmeta['title'] ?>" />
     <meta property="og:description" content="<?php echo $ogmeta['description'] ?>" />
     <?php if (is_array($ogmeta['image'])) :
         foreach ($ogmeta['image'] as $ogimg) : ?>
             <meta property="og:image" content="<?php echo $ogimg ?>" />
         <?php endforeach;
     else : ?>
         <meta property="og:image" content="<?php echo $ogmeta['image'] ?>" />
     <?php endif; ?>
     <meta property="og:url" content="<?php echo $ogmeta['url'] ?>" />
     <meta property="og:locale" content="ja_JP" />
     <meta property="fb:app_id" content="<?= OAUTH_FACEBOOK_ID ?>" />
 <?php elseif (isset($ogmeta) && $blog_post): ?>
     <? $_blog = Post::get($this['post'], LANG);
     $blog_post = $this['blog'];
     $blog_key = key($this['blog']->posts);
     if($_blog->image):
         ?>
         <meta property="og:image" content="<?php echo $_blog->image->getLink(500, 285) ?>" />
         <?
     else:
         if (is_array($ogmeta['image'])) :
             foreach ($ogmeta['image'] as $ogimg) : ?>
                 <meta property="og:image" content="<?php echo $ogimg ?>" />
                 <?php
             endforeach;
         else :
             ?>
             <meta property="og:image" content="<?php echo $ogmeta['image'] ?>" />
Esempio n. 15
0
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with Goteo.  If not, see <http://www.gnu.org/licenses/agpl.txt>.
 *
 */
use Goteo\Library\Text, Goteo\Model\Blog\Post, Goteo\Core\View;
$bodyClass = 'news';
$read_more = Text::get('regular-read_more');
// noticias
$news = $this['news'];
// últimas entradas del blog goteo
$list = array();
$title = Text::get('blog-side-last_posts');
$items = Post::getAll(1, 7);
// enlace a la entrada
foreach ($items as $item) {
    $list[] = '<a href="/blog/' . $item->id . '"> ' . Text::recorta($item->title, 100) . '</a>';
}
// paginacion
require_once 'library/pagination/pagination.php';
$pagedResults = new \Paginated($news, 7, isset($_GET['page']) ? $_GET['page'] : 1);
include 'view/prologue.html.php';
include 'view/header.html.php';
?>
<div id="sub-header-secondary">
    <div class="clearfix">
        <h2>GOTEO<span class="red">NEWS</span></h2>
        <?php 
echo new View('view/header/share.html.php');