<?php
// ------------------------------------------------------------------------ //
// EIS - Extensible Information System //
// Copyright (c) Technical 2008 - 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;
private $CategoryExists;
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)
{
global $Language;
global $DatabaseConnection;
$this->Exists = FALSE;
$Condition = " id='".$Id."'";
if($Group)
{
$Condition = " AND".$Condition;
} else {
$Condition = " WHERE".$Condition;
}
if(!empty($Id) && $Query = Database::GetItems('content', 0, 1, null, $Group, $Condition))
{
$this->Id = $Id;
$this->Exists = TRUE;
$this->Group = $Query[0]['group'];
$this->Title = $Query[0]['title'];
$this->Author = $Query[0]['author'];
if($CategoryQuery = Database::GetItems('categories', 0, 1, null, FALSE, " WHERE id='".$Query[0]['category']."' AND module='content'"))
{
$this->Category = $CategoryQuery[0]['id'];
$this->CategoryExists = TRUE;
} else {
$this->Category = null;
$this->CategoryExists = FALSE;
}
$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 = $Query[0]['active'];
}
}
function Display()
{
global $Language;
global $DatabaseConnection;
echo "<br><b>".$this->Title." : </b><br>";
$Toolbar = new Toolbar();
$Toolbar->AddCustom(BookmarkButton('content', $this->Id)." $Language[3] : ");
if(InRow("SELECT * FROM users WHERE login='".$this->Author."' LIMIT 1", array('login' => $this->Author)))
{
$Toolbar->AddCustom("<a href=\"?module=profiles&user=".$this->Author."\">".$this->Author."</a>");
} else {
$Toolbar->AddCustom($this->Author);
}
$Toolbar->AddSeparator();
$Toolbar->AddCustom("<img src=\"images/modules/date.png\" align=\"absmiddle\"> ".date('j.m.y G:i', $this->Date));
$Toolbar->AddSeparator();
$Toolbar->AddCustom("<a href=\"print.php?module=content&id=".$this->Id."\" target=\"_blank\"><img src=\"images/modules/print.png\" title=\"$Language[4]\" border=\"0\" align=\"absmiddle\"> $Language[4]</a>");
$Toolbar->AddSeparator();
$Toolbar->AddCustom(AddThisButton($this->Title));
$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);
}
echo "\n<hr>".MakeTags('content', $this->Tags)."<hr>";
}
function DisplayPrintable()
{
global $Language;
global $DatabaseConnection;
echo "<br><b>".$this->Title." : </b><br>";
echo " $Language[3] : ".$this->Author." | <img src=\"images/modules/date.png\" align=\"absmiddle\"> ".date('j.m.y G:i', $this->Date);
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);
$QueryText = "INSERT INTO content(id,title,`group`,category,date,author,shorttext,fulltext,tags,comments,rating,home,type,image,active) VALUES(NULL, '".sqlite_escape_string($this->Title)."', '".$Group."', '".$Category."', '".time()."', '".$this->Author."', '".sqlite_escape_string($this->ShortText)."', '".sqlite_escape_string($this->FullText)."', '".$Tags."', '".$Comments."', '".$Rating."', '".$Home."', '".$Type."', '".sqlite_escape_string($this->Image)."', '".$Active."')";
if($this->Exists)
{
$QueryText = "UPDATE content SET title='".sqlite_escape_string($this->Title)."', [group]='".$Group."', category='".$Category."', date='".$this->Date."', author='".$this->Author."', shorttext='".sqlite_escape_string($this->ShortText)."', fulltext='".sqlite_escape_string($this->FullText)."', tags='".$Tags."', comments='".$Comments."', rating='".$Rating."', home='".$Home."', type='".$Type."', image='".sqlite_escape_string($this->Image)."', active='".$Active."' WHERE id=".$this->Id;
}
if($DatabaseConnection->Query($QueryText) && !$this->Exists)
{
$DatabaseConnection->Query("UPDATE content SET sort=id WHERE id=".$DatabaseConnection->lastInsertId('id'));
$this->Id = $DatabaseConnection->lastInsertId('id');
}
}
}
class ContentGroup extends ItemGroup
{
public $Items = array();
private $Category;
private $Start;
private $Limit;
function __construct($IsArray, $Start = 0, $Limit = 10, $Category = null, $Home = FALSE)
{
$this->Start = $Start;
$this->Limit = $Limit;
$this->Category = $Category;
$this->Home = $Home;
$Optional = " AND active='1'";
if($Home)
{
$Optional .= " AND home='1' AND type='0'";
}
if(!is_array($IsArray))
{
parent::__construct('content', $Start, $Limit, $Category, TRUE, TRUE, TRUE, TRUE, $Optional);
} else {
parent::FromArray('content', $IsArray);
}
}
function GetCategory()
{
return $this->Category;
}
function DisplayItem($Index)
{
global $Page;
global $Language;
global $DatabaseConnection;
if (!empty($this->Items[$Index]))
{
$Item = $this->Items[$Index];
echo "<b>";
if(!empty($this->Categories[$this->Items[$Index]['category']]))
{
$Category = $this->Categories[$this->Items[$Index]['category']];
echo "<a href=\"?module=content&category=".$Item['category']."\">".$Category['title']."</a> : ";
}
echo "<a href=\"?module=content&id=".$Item['id']."\">".$Item['title']."</a>";
if(IsNew($Item['date']))
{
echo " <img src=\"images/modules/new.png\" border=\"0\">";
}
echo "</b><br>";
$Toolbar = new Toolbar();
$Toolbar->AddCustom(BookmarkButton('content', $Item['id'])." $Language[3] : ");
if(!empty($this->Authors[$Item['author']]))
{
$Toolbar->AddCustom("<a href=\"?module=profiles&user=".$Item['author']."\">".$Item['author']."</a>");
} else {
$Toolbar->AddCustom($Item['author']);
}
$Toolbar->AddSeparator();
$Toolbar->AddCustom("<img src=\"images/modules/date.png\" align=\"absmiddle\"> ".date('j.m.y G:i', $Item['date']));
$Toolbar->AddSeparator();
$Toolbar->AddCustom(AddThisButton($Item['title']));
$Toolbar->Display('left');
echo "<hr>";
if(is_file('images/articles/'.$Item['image']))
{
echo "\n<img src=\"images/articles/".$Item['image']."\">";
}
echo stripslashes($Item['shorttext']);
echo "<hr>\n".MakeTags('content', $Item['tags'])."\n<hr>\n";
$Comments = 0;
if(!empty($this->Comments[$Item['id']]))
{
$Comments = $this->Comments[$Item['id']];
}
$Toolbar = new Toolbar();
if($Item['comments'] != 0)
{
$Toolbar->Add("?module=content&id=".$Item['id'], '', 'images/modules/comment.png', $Language[6]."(".$Comments.")");
}
if ($Item['fulltext'] != null && $Item['fulltext'] != "<br>" && UTF8::strwidth(str_replace("\n", '', $Item['fulltext'])) > 0)
{
$Toolbar->Add("?module=content&id=".$Item['id']."", '', 'images/modules/content.png', $Language[36]);
}
$Toolbar->Add("print.php?module=content&id=".$Item['id'], '', 'images/modules/print.png', $Language[4]);
$Toolbar->Display('right');
echo "<hr>";
}
}
function DisplayListItem($Index)
{
global $Language;
if (!empty($this->Items[$Index]))
{
$Item = $this->Items[$Index];
$Comments = 0;
if(!empty($this->Comments[$Item['id']]))
{
$Comments = $this->Comments[$Item['id']];
}
echo "<tr><td><img src=\"images/modules/date.png\" align=\"absmiddle\"> ".date('j.m.y G:i', $Item['date'])."</td><td><a href=\"?module=content&id=".$Item['id']."\">".$Item['title'];
if(IsNew($Item['date']))
{
echo " <img src=\"images/modules/new.png\" border=\"0\">";
}
echo "</a></td><td>";
if(!empty($this->Authors[$Item['author']]))
{
echo "<a href=\"?module=profiles&user=".$Item['author']."\">".$Item['author']."</a>";
} else {
echo $Item['author'];
}
echo "</td><td><a href=\"?module=content&id=".$Item['id']."\"><img src=\"images/modules/comment.png\" align=\"absmiddle\"> ".$Language[6]."(".$Comments.")"."</a></td></tr>\n";
}
}
function Display()
{
global $Page;
$Keys = array_keys($this->Items);
if(!$this->Home && !empty($this->Categories[$this->Category]))
{
echo "<img src=\"images/modules/cats.png\" align=\"baseline\" border=\"0\"> <b>".$this->Categories[$this->Category]['title']." : </b><br>\n";
}
if(!$this->Home)
{
echo "<table width=\"100%\">\n";
}
foreach($Keys as $Key)
{
if($this->Home)
{
$this->DisplayItem($Key);
} else {
$this->DisplayListItem($Key);
}
}
if(!$this->Home)
{
echo "</table>\n";
}
PageNavigation(count(Database::GetItems('content', CalculateStart($Page), 1, $this->Category, FALSE)), $Page, "?module=content&category=".$this->Category, 1);
}
}
?>