websiteWebsite
codingteam CodingTeam
A free forge, lightweight and extensible.

 

Browse the code

Revision log Information on the revision
Revision: 511 (differences)
Author: xbright
Log message: * Enhanced roadmap
Change revision:
<?php
//   This file is a part of CodingTeam. Take a look at <http://codingteam.org>.
//   Copyright © 2007-2012 Erwan Briand <erwan@codingteam.net>
//
//   This program 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, version 3 only.
//
//   This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
 
class View {
    private $ct_session, $ct_db, $page, $error, $langlist, $lang;
    public $metatags, $maincontent;
    
    function __construct($session, $db, $page, $error, $langlist, $lang)
    {
        // Variables
        $this->ct_session = $session;
        $this->ct_db = $db;
        $this->page = $page;
        $this->error = $error;
        $this->langlist = $langlist;
        $this->lang = $lang;
 
        // Meta tags
        $this->metatags = array('title' => i18n('Projects'),
                                'feed'  => 'projects');
    }
 
    function showFeed()
    {
        $rss_array['title'] = i18n('Projects');
        $rss_array['link'] = CT_BASEURL.'projects';
        $rss_array['description'] = i18n('Latest projects registered.');
 
        $projects = getClass('projects.projects', $this->ct_db);
        $list = $projects->listProjects(array('is_valid'   => TRUE,
                                              'is_private' => FALSE), 'id DESC', 5);
 
        if ($list)
        {
            for ($i=0; $i<count($list); $i++)
            {
                $textview = getClass('textview', $this->ct_db);
                $text = $textview->prepare($list[$i]['text']);
 
                $user = getUser($list[$i]['userid'], $this->ct_db);
                $nick = htmlspecialchars($user->getNickname());
 
                $rss_array['threads'][$i]['title'] = htmlspecialchars($list[$i]['name']);
                $rss_array['threads'][$i]['pubDate'] = $list[$i]['date'];
                $rss_array['threads'][$i]['guid'] = CT_BASEURL.'project/'.$list[$i]['dbname'];
                $rss_array['threads'][$i]['link'] = CT_BASEURL.'project/'.$list[$i]['dbname'];
                $rss_array['threads'][$i]['dc:creator'] = $nick;
                $rss_array['threads'][$i]['description'] = htmlspecialchars($text);
            }
        }
 
        return $rss_array;
    }
 
    function treatForms()
    {
    }
 
    function constructView()
    {
        $construct = array();
        $construct['__tpl__'] = 'default.tpl';
 
        // Categories
        require_once(CT_BASEDIR.'/inc/data/categories.php');
 
        $construct['categories'] = $categories;
        asort($construct['categories']);
 
        // Projects
        $projects = getClass('projects.projects', $this->ct_db);
        $projects_list = $projects->listProjects(array('is_valid' => TRUE,
                                                       'is_private' => FALSE),
                                                       'id DESC', 5);
 
        $this->config = getClass('config', $this->ct_db);
        $overall = $this->config->get('projects', 'overall-popularity');
 
        $construct['projects'] = array();
        foreach ($projects_list as $project)
        {
            $name = htmlspecialchars($project['name']);
            $dbname = htmlspecialchars($project['dbname']);
            $logo = htmlspecialchars($project['logo']);
            $text = htmlspecialchars($project['oneline']);
            $website = htmlspecialchars($project['website']);
            $downloads = $project['downloads'];
            $category = $project['category'];
            $popularity = $project['popularity'];
            $date = mb_substr($project['date'], 0, 10);
 
            $file = 'public/upload/projects/'.$dbname.'/'.$logo;
        
            if ($logo == '!none!')
                $logourl = 'public/images/icons/mimetypes/application-x-executable_big.png';
            elseif (file_exists(CT_BASEDIR.'/'.$file))
                $logourl = 'project/'.$dbname.'/upload/'.$logo;
            else
                $logourl = $logo;
 
            $catarray = explode('-', $category);
            $pjcat = '';
            for ($j=0; $j<count($catarray); $j++)
            {
                if ($j == 0)
                    $cat = $catarray[$j];
                else
                    $cat = $catarray[0].'-'.$catarray[$j];
 
                $pjcat .= '<a href="projects/browse/category/'.$cat.'">'.$categories[$cat].'</a>';
                if (count($catarray) > 1 && $j == 0)
                    $pjcat .= ' » ';
            }
 
            if ($overall > 0)
                $pop = number_format(($popularity / $overall * 100), 2);
            else
                $pop = 0;
 
            array_push($construct['projects'],
                        array('name'       => $name,
                              'dbname'     => $dbname,
                              'logourl'    => $logourl,
                              'text'       => $text,
                              'website'    => $website,
                              'downloads'  => $downloads,
                              'category'   => $category,
                              'popularity' => $pop,
                              'date'       => i18nDate($date, $this->lang),
                              'categories' => $pjcat));
        }
 
        // Feed
        $construct['feed'] = i18n('Feed subscription: %(rss)s or %(atom)s.',
                                  array('rss' => '<a href="rss/projects">'.
                                                 i18n('RSS').'</a>',
                                        'atom' => '<a href="atom/projects">'.
                                                  i18n('Atom').'</a>'));
 
        return $construct;
    }
}
?>