<?php
// ------------------------------------------------------------------------ //
// EIS - Extensible Information System //
// Copyright (c) Technical 2009 - http://sourceforge.net/projects/eiscms //
// <http://sourceforge.net/projects/eiscms> //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// 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 General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
class ContentItem
{
private $Id;
private $Exists;
public $Group;
public $Title;
public $Author;
public $Category;
public $Date;
public $ShortText;
public $FullText;
public $Tags;
public $Comments;
public $Rating;
public $Home;
public $Type;
public $Image;
public $Active;
function __construct($Id = null, $Group = TRUE, $MustExists = TRUE)
{
global $Language;
global $DatabaseConnection;
$this->Exists = FALSE;
$Conditions = array();
$Optional = null;
if(!$MustExists)
{
$Optional = "ORDER BY id DESC";
}
if(!empty($Id))
{
$Options = array('=', $Id, null);
if($Group)
{
$Options[2] = 'AND';
}
$Conditions['id'] = $Options;
}
if($Group)
{
$Conditions['[group]'] = array('IN', Group(), null);
}
if((empty($Id) or $MustExists) && $Query = Database::GetItems('*', 'content', 0, 1, array(), $Conditions, $Optional))
{
$this->Id = $Query[0]['id'];
$this->Exists = TRUE;
$this->Group = $Query[0]['group'];
$this->Title = $Query[0]['title'];
$this->Author = $Query[0]['author'];
$this->Category = $Query[0]['category'];
$this->Date = $Query[0]['date'];
$this->ShortText = $Query[0]['shorttext'];
$this->FullText = $Query[0]['fulltext'];
$this->Tags = $Query[0]['tags'];
$this->Comments = (bool) $Query[0]['comments'];
$this->Rating = (bool) $Query[0]['rating'];
$this->Home = (bool) $Query[0]['home'];
$this->Image = $Query[0]['image'];
$this->Active = (bool) $Query[0]['active'];
}
}
function Display()
{
if(Database::GetCount('id', 'bookmarks', array('module' => array('=', 'content', 'AND'), 'item' => array('=', $this->Id, null))))
{
$Bookmark = "<img src=\"images/icons/star.png\" align=\"absmiddle\" border=\"0\"> ";
} else {
$Bookmark = BookmarkButton('content', $this->Id);
}
$Author = null;
if($UserInfo = UserInfo($this->Author))
{
$Author = array('id' => $this->Author, 'login' => $UserInfo['login']);
}
$Image = null;
if(is_file('images/articles/'.$this->Image))
{
$Image = "\n<img src=\"images/articles/".$this->Image."\">";
}
$Text = stripslashes($this->ShortText);
if(UTF8::strwidth($this->FullText) > 0)
{
$Text .= "\n".stripslashes($this->FullText);
}
Template::Article($this->Id, $this->Title, $this->Date, $Author, $Image, $Text, MakeTags('content', $this->Tags), TRUE, $Bookmark);
}
function DisplayPrintable()
{
global $Language;
global $DatabaseConnection;
echo "<br><b>".$this->Title." : </b><br>";
$Toolbar = new Toolbar();
$Toolbar->AddText("date.png", MakeDate($this->Date));
$Toolbar->Display('left');
echo "<hr>";
if(is_file('images/articles/'.$this->Image))
{
echo "\n<img src=\"images/articles/".$this->Image."\">";
}
echo stripslashes($this->ShortText);
if(UTF8::strwidth($this->FullText) > 0)
{
echo stripslashes($this->FullText);
}
}
function Exists()
{
return $this->Exists;
}
function GetId()
{
return $this->Id;
}
function Save()
{
global $Language;
global $DatabaseConnection;
$Tags = array();
foreach(explode(',', $this->Tags) as $Tag)
{
$Tags[] = SecureQuery($Tag);
}
$Tags = implode(',', $Tags);
$Group = intval($this->Group);
$Category = intval($this->Category);
$Comments = intval((bool) $this->Comments);
$Rating = intval((bool) $this->Rating);
$Home = intval((bool) $this->Home);
$Type = intval((bool) $this->Type);
$Active = intval((bool) $this->Active);
if($this->Exists)
{
$Result = Database::Update('content', array('title' => $this->Title, '[group]' => $Group, 'category' => $Category, 'date' => $this->Date, 'author' => $this->Author, 'shorttext' => $this->ShortText, 'fulltext' => $this->FullText, 'tags' => $Tags, 'comments' => $Comments, 'rating' => $Rating, 'home' => $Home, 'type' => $Type, 'image' => $this->Image, 'active' => $Active), array('id' => array('=', $this->Id, null)));
} elseif(Database::Insert('content', array('title', 'group', 'category', 'date', 'author', 'shorttext', 'fulltext', 'tags', 'comments', 'rating', 'home', 'type', 'image', 'active'), array($this->Title, $Group, $Category, time(), $this->Author, $this->ShortText, $this->FullText, $Tags, $Comments, $Rating, $Home, $Type, $this->Image, $Active))) {
Database::Update('content', array('sort' => 'id'), array('id' => array('=', $DatabaseConnection->lastInsertId('id'), null)), null, FALSE);
$this->Id = $DatabaseConnection->lastInsertId('id');
}
}
}
/*--------------------------------------------------------------------------*/
class ContentGroup
{
public $Items = array();
public $Comments = array();
private $Category;
private $Start;
private $Limit;
private $Home;
private $Pagination;
private $Search;
private $Tag;
private $Bookmarked;
private $Categories;
function __construct($Start = 0, $Limit = 10, $Search = null, $Tag = null, $Category = null, $Home = FALSE, $Pagination = TRUE)
{
$this->Start = (int) $Start;
$this->Limit = (int) $Limit;
$this->Search = SecureSearch($Search);
$this->Tag = SecureSearch($Tag);
$this->Category = (int) $Category;
$this->Home = (bool) $Home;
$this->Pagination = (bool) $Pagination;
$Conditions = array('content.active' => array('=', 1, 'AND'));
if(!empty($this->Search))
{
$Conditions = array_merge($Conditions, array('(title' => array('LIKE', '%'.$this->Search.'%', 'OR'), 'shorttext' => array('LIKE', '%'.$this->Search.'%', 'OR'), 'fulltext' => array('LIKE', '%'.$this->Search.'%', ') AND')));
} elseif(!empty($this->Tag)) {
$Conditions['tags'] = array('LIKE', '%'.$this->Tag.'%', 'AND');
}
if(!empty($this->Category))
{
$Conditions['category'] = array('=', $this->Category, 'AND');
}
if(!empty($Home))
{
$Conditions = array_merge($Conditions, array('home' => array('=', 1, 'AND'), 'type' => array('=', 0, 'AND')));
}
$Conditions['content.[group]'] = array('IN', Group(), null);
if($Query = Database::GetItems('content.id AS cid, content.[group] AS cgroup, *', 'content', $Start, $Limit, array('LEFT' => array('users', 'content.author', 'users.id')), $Conditions, 'ORDER BY sort DESC'))
{
$this->Items = $Query;
$List = array();
$Categories = array();
foreach($this->Items as $Item)
{
$List[] = $Item['cid'];
$List2[] = $Item['category'];
}
if($Categories = Database::GetItems('*', 'categories', 0, FALSE, array(), array('module' => array('=', 'content', 'AND'), 'id' => array('IN', array_unique($List2), null))))
{
foreach($Categories as $Category)
{
$this->Categories[$Category['id']] = $Category;
}
}
if(IsUser() && !empty($List))
{
if($Bookmarked = Database::GetItems('*', 'bookmarks', 0, FALSE, array(), array('module' => array('=', 'content', 'AND'), 'item' => array('IN', $List, 'AND'), 'user' => array('=', Id, null))))
{
foreach($Bookmarked as $Bookmark)
{
$this->Bookmarked[$Bookmark['item']] = $Bookmark;
}
}
$this->Comments = Database::GetComments('content', $List);
}
}
}
function GetCategory()
{
return $this->Category;
}
function DisplayItem($Index)
{
global $Page;
global $Language;
global $DatabaseConnection;
if (!empty($this->Items[$Index]))
{
$Item = $this->Items[$Index];
if(!empty($this->Bookmarked[$Item['cid']]))
{
$Bookmark = "<img src=\"images/icons/star.png\" align=\"absmiddle\" border=\"0\"> ";
} else {
$Bookmark = BookmarkButton('content', $Item['cid']);
}
$Image = null;
if(is_file('images/articles/'.$Item['image']))
{
$Image = "\n<img src=\"images/articles/".$Item['image']."\">";
}
$Comments = 0;
if(!empty($this->Comments[$Item['cid']]))
{
$Comments = $this->Comments[$Item['cid']];
}
$Author = null;
if(!empty($Item['id']))
{
$Author = array('id' => $Item['id'], 'login' => $Item['login']);
}
$Title = "<a href=\"?module=content&id=".$Item['cid']."\">".$Item['title']."</a>";
if(IsNew($Item['date']))
{
$Title .= " <img src=\"images/icons/new.png\" border=\"0\">";
}
$Category = $this->Categories[$this->Items[$Index]['category']];
Template::Item($Item['cid'], $Title, $Item['date'], $Author, $Image, stripslashes($Item['shorttext']), MakeTags('content', $Item['tags']), "<a href=\"?module=content&category=".$Category['id']."\">".$Category['title']."</a>", $Bookmark);
echo "<hr>\n";
$Toolbar = new Toolbar();
if(!empty($Author))
{
$Toolbar->Add("?module=profiles&id=".$Author['id'], null, 'user.png', $Author['login']);
} else {
$Toolbar->AddText("guest.png", $Language[173]);
}
$Toolbar->AddText("date.png", MakeDate($Item['date']));
$Toolbar->AddSeparator();
if(!empty($Item['comments']))
{
$Toolbar->Add("?module=content&id=".$Item['cid']."#Comments", '', 'comment.png', $Language[6]."(".$Comments.")");
}
$Toolbar->Add("print.php?module=content&id=".$Item['cid'], '', 'print.png', $Language[4]);
if (UTF8::strwidth(str_replace("\n", '', $Item['fulltext'])) > 0)
{
$Toolbar->AddSeparator();
$Toolbar->Add("?module=content&id=".$Item['cid']."", '', 'content.png', $Language[36]);
}
$Toolbar->Display('right');
if(count($this->Items) > 1)
{
echo "\n<br><br>\n";
}
}
}
function DisplayListItem($Index)
{
global $Language;
if (!empty($this->Items[$Index]))
{
$Item = $this->Items[$Index];
if($this->Bookmarked[$Item['cid']])
{
$Bookmark = "<img src=\"images/icons/star.png\" align=\"absmiddle\" border=\"0\"> ";
} else {
$Bookmark = BookmarkButton('content', $Item['cid']);
}
$Image = null;
if(is_file('images/articles/'.$Item['image']))
{
$Image = "\n<img src=\"images/articles/".$Item['image']."\">";
}
$Count = 0;
if(!empty($this->Comments[$Item['cid']]))
{
$Count = $this->Comments[$Item['cid']];
}
$Comments = null;
if(!empty($Item['comments']))
{
$Comments = "<a href=\"?module=content&id=".$Item['cid']."#Comments\"><img src=\"images/icons/comment.png\" align=\"absmiddle\"> ".$Language[6]."(".$Count.")"."</a>";
}
$Title = "<a href=\"?module=content&id=".$Item['cid']."\">".$Item['title']."</a>";
if($Item['type'] == 0)
{
$Title = "<img src=\"images/icons/news.png\" align=\"absmiddle\" border=\"0\"> ".$Title;
} else {
$Title = "<img src=\"images/icons/content.png\" align=\"absmiddle\" border=\"0\"> ".$Title;
}
if(IsNew($Item['date']))
{
$Title .= " <img src=\"images/icons/new.png\" border=\"0\">";
}
Template::ListItem($Item['cid'], $Title, $Item['date'], array('id' => $Item['id'], 'login' => $Item['login']), $Comments, $Bookmark);
}
}
function Display()
{
global $Page;
$Keys = array_keys($this->Items);
if(!$this->Home && !empty($this->Categories[$this->Category]))
{
echo "<img src=\"images/icons/cats.png\" align=\"baseline\" border=\"0\"> <b>".$this->Categories[$this->Category]['title']." : </b><br>\n";
if(count($this->Items))
{
echo "<a href=\"rss.php?type=content&category=".$this->Category."\"><img src=\"images/icons/feed.png\" align=\"absmiddle\" border=\"0\"> RSS</a> <hr>";
}
}
foreach($Keys as $Key)
{
if($this->Home)
{
$this->DisplayItem($Key);
} else {
$this->DisplayListItem($Key);
}
}
if($this->Pagination)
{
$Optional = null;
$Conditions = array('active' => array('=', 1, 'AND'));
if(!empty($this->Search))
{
$Conditions = array_merge($Conditions, array('title' => array('LIKE', '%'.$this->Search.'%', 'AND')), array('shorttext' => array('LIKE', '%'.$this->Search.'%', 'AND')), array('fulltext' => array('LIKE', '%'.$this->Search.'%', 'AND')));
$Optional .= "&search=".SecureQuery($this->Search);
}
if(!empty($this->Tag))
{
$Conditions['tags'] = array('LIKE', '%'.$this->Tag.'%', 'AND');
$Optional .= "&tag=".SecureQuery($this->Tag);
}
if(!empty($this->Category) && is_numeric($this->Category))
{
$Conditions['category'] = array('=', $this->Category, 'AND');
$Optional .= "&category=".SecureQuery($this->Category);
}
if(!empty($this->Home))
{
$Conditions['home'] = array('=', 1, 'AND');
}
$Conditions['[group]'] = array('IN', Group(), null);
PageNavigation(Database::GetCount('id', 'content', $Conditions), $Page, "?module=content".$Optional, $this->Limit);
}
}
}
?>