Exemplo n.º 1
0
 public function index()
 {
     if (isset($_GET['error'])) {
         throw new \Goteo\Core\Error('418', Text::html('fatal-error-teapot'));
     }
     // orden de los elementos en portada
     $order = Home::getAll();
     // si estamos en easy mode, quitamos el feed
     if (defined('GOTEO_EASY') && \GOTEO_EASY === true && isset($order['feed'])) {
         unset($order['feed']);
     }
     // entradas de blog
     if (isset($order['posts'])) {
         // entradas en portada
         $posts = Post::getAll();
     }
     // Proyectos destacados
     if (isset($order['promotes'])) {
         $promotes = Promote::getAll(true);
         foreach ($promotes as $key => &$promo) {
             try {
                 $promo->projectData = Project::getMedium($promo->project, LANG);
             } catch (\Goteo\Core\Error $e) {
                 unset($promotes[$key]);
             }
         }
     }
     // actividad reciente
     if (isset($order['feed'])) {
         $feed = array();
         $feed['goteo'] = Feed::getAll('goteo', 'public', 15);
         $feed['projects'] = Feed::getAll('projects', 'public', 15);
         $feed['community'] = Feed::getAll('community', 'public', 15);
     }
     // Banners siempre
     $banners = Banner::getAll(true);
     foreach ($banners as $id => &$banner) {
         if (!empty($banner->project)) {
             try {
                 $banner->project = Project::get($banner->project, LANG);
             } catch (\Goteo\Core\Error $e) {
                 unset($banners[$id]);
             }
         }
     }
     return new View('view/index.html.php', array('banners' => $banners, 'posts' => $posts, 'promotes' => $promotes, 'feed' => $feed, 'order' => $order));
 }
Exemplo n.º 2
0
 *  (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;
$banner = $this['banner'];
// proyectos disponibles
// si tenemos ya proyecto seleccionado lo incluimos
$projects = Model\Banner::available($banner->project);
$status = Model\Project::status();
?>
<form method="post" action="/admin/banners" enctype="multipart/form-data">
    <input type="hidden" name="action" value="<?php 
echo $this['action'];
?>
" />
    <input type="hidden" name="order" value="<?php 
echo $banner->order;
?>
" />
    <input type="hidden" name="id" value="<?php 
echo $banner->id;
?>
" />
Exemplo n.º 3
0
 public static function process($action = 'list', $id = null, $filters = array(), $flag = null)
 {
     $errors = array();
     $node = isset($_SESSION['admin_node']) ? $_SESSION['admin_node'] : \GOTEO_NODE;
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         // objeto
         $banner = new Model\Banner(array('id' => $_POST['id'], 'node' => $node, 'project' => $_POST['project'], 'title' => $_POST['title'], 'description' => $_POST['description'], 'url' => $_POST['url'], 'order' => $_POST['order'], 'active' => $_POST['active']));
         // imagen
         if (!empty($_FILES['image']['name'])) {
             $banner->image = $_FILES['image'];
         } else {
             $banner->image = $_POST['prev_image'];
         }
         if ($banner->save($errors)) {
             Message::Info('Datos guardados');
             if ($_POST['action'] == 'add') {
                 $projectData = Model\Project::getMini($_POST['project']);
                 // Evento Feed
                 $log = new Feed();
                 $log->setTarget($projectData->id);
                 $log->populate('nuevo banner de proyecto destacado en portada (admin)', '/admin/promote', \vsprintf('El admin %s ha %s', array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('relevant', 'Publicado un banner', '/'))));
                 $log->doAdmin('admin');
                 unset($log);
             }
             throw new Redirection('/admin/banners');
         } else {
             Message::Error(implode('<br />', $errors));
             switch ($_POST['action']) {
                 case 'add':
                     return new View('view/admin/index.html.php', array('folder' => 'banners', 'file' => 'edit', 'action' => 'add', 'banner' => $banner, 'status' => $status));
                     break;
                 case 'edit':
                     return new View('view/admin/index.html.php', array('folder' => 'banners', 'file' => 'edit', 'action' => 'edit', 'banner' => $banner));
                     break;
             }
         }
     }
     switch ($action) {
         case 'active':
             $set = $flag == 'on' ? true : false;
             Model\Banner::setActive($id, $set);
             throw new Redirection('/admin/banners');
             break;
         case 'up':
             Model\Banner::up($id, $node);
             throw new Redirection('/admin/banners');
             break;
         case 'down':
             Model\Banner::down($id, $node);
             throw new Redirection('/admin/banners');
             break;
         case 'remove':
             if (Model\Banner::delete($id)) {
                 Message::Info('Banner quitado correctamente');
             } else {
                 Message::Error('No se ha podido quitar el banner');
             }
             throw new Redirection('/admin/banners');
             break;
         case 'add':
             // siguiente orden
             $next = Model\Banner::next($node);
             return new View('view/admin/index.html.php', array('folder' => 'banners', 'file' => 'edit', 'action' => 'add', 'banner' => (object) array('order' => $next), 'status' => $status));
             break;
         case 'edit':
             $banner = Model\Banner::get($id);
             return new View('view/admin/index.html.php', array('folder' => 'banners', 'file' => 'edit', 'action' => 'edit', 'banner' => $banner));
             break;
     }
     $bannered = Model\Banner::getAll(false, $node);
     return new View('view/admin/index.html.php', array('folder' => 'banners', 'file' => 'list', 'bannered' => $bannered, 'node' => $node));
 }