| Server IP : 195.130.67.5 / Your IP : 216.73.216.231 Web Server : Microsoft-IIS/10.0 System : Windows NT WEBSERVER1 10.0 build 17763 (Windows Server 2016) i586 User : IUSR ( 0) PHP Version : 7.4.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/includes/ |
Upload File : |
<?
////////////////////////////////////////////////////////////////////////////////////////
// Class: Content
// Purpose: Κλάση περιεχομένου (άρθρων και συνδέσμων)
///////////////////////////////////////////////////////////////////////////////////////
require_once('Attachments.php');
require_once("mpdf/mpdf.php");
class Content
{
public $contents_array = array();
public $contents_per_page = 0;
public $total_contents = 0;
private $connector;
private $system;
private $translator;
public function __construct($db, $system, $translator)
{
$this->connector = $db;
$this->system = $system;
$this->translator = $translator;
}
// Άντληση περιεχομένου με το δοσμένο id
public function getContentById($id)
{
$this->contents_array = array();
$result = $this->connector->query("SELECT * FROM content WHERE id='$id'");
$this->contents_array = $this->connector->fetchArray($result);
$this->total_contents = $this->connector->getNumRows($result);
return $this->contents_array;
}
// Άντληση συγκεκριμένου περιεχομένου με δοσμένο id, λαμβάνοντας υπόψην την κατάσταση του περιεχομένου, αν είναι εμπρόθεσμο, και την πολιτική για το αμετάφραστο περιεχόμενο
public function getSingleContent($id, $show_active=false, $show_outdated=false)
{
if (empty($id))
$id=0;
$sql = "SELECT * FROM content WHERE content.id=$id";
if ($show_active==false)
$sql .= " and state=1";
if ($show_outdated==false)
$sql .= " and publish_up<=NOW() and (publish_down > NOW() or publish_down='0000-00-00 00:00:00')";
$sql = $this->translator->fixSqlStatement($sql, $this->translator->current_lang["id"], "content", $this->system->general_settings["untranslated_articles_policy"]);
$this->getContents($sql);
if ($this->total_contents>0)
$this->updateContentHits($id);
return $this->contents_array;
}
// Πραγματοποιείται άντληση των δεδομένων των άρθρων ή των συνδέσμων από τη βάση στην τρέχουσα γλώσσα
// και αν δεν υπάρχουν μεταφράσεις αντλούνται Τίτλος και Κυρίως Περιεχόμενο από την default γλώσσα
public function getContents($sql)
{
$attachments = new Attachments($this->connector);
$this->contents_array = array();
$this->contents_per_page = 0;
$this->setTotalNumOfContents($sql);
$result = $this->connector->query($sql);
while ($myrow = $this->connector->fetchArray($result))
{
++$this->contents_per_page;
$this->contents_array["id"][] = $myrow["id"];
$this->contents_array["category_id"][] = $myrow["category_id"];
$fetch_default = true;
if ($this->translator->current_lang["id"] != $this->translator->default_lang["id"]) // Αν δεν έχουμε Default γλώσσα
{
$translated_fields = $this->translator->fetchTranslatedContent($this->translator->current_lang["id"], $myrow["id"], "content");
if (count($translated_fields)>0)
{
$fetch_default = false;
foreach ($translated_fields as $field_name=>$value)
{
${"ar_".$field_name} = $value;
}
$this->contents_array["title"][] = $ar_title;
$this->contents_array["body"][] = $ar_body;
if ($ar_summary!="")
$this->contents_array["body_preview"][] = nl2br($ar_summary);
else
$this->contents_array["body_preview"][] = $this->makePreview($ar_body, $this->system->general_settings["article_summary_length"], "<br><img>");
}
}
if ($fetch_default == true) // Πάρε τα δεδομένα από την Default γλώσσα
{
$this->contents_array["title"][] = $myrow["title"];
$this->contents_array["body"][] = $myrow["body"];
if ($myrow["summary"]!="")
$this->contents_array["body_preview"][] = nl2br($myrow["summary"]);
else
$this->contents_array["body_preview"][] = $this->makePreview($myrow["body"], $this->system->general_settings["article_summary_length"], "<br><img>");
}
$this->contents_array["created"][] = $myrow["created"];
$this->contents_array["type"][] = $myrow["article_type"];
$this->contents_array["access"][] = $myrow["access"];
$this->contents_array["link"][] = $myrow["link"];
$this->contents_array["link_target"][] = $myrow["weblink_target"];
$this->contents_array["show_meta"][] = $myrow["show_meta"];
$this->contents_array["show_pdf_icon"][] = $myrow["show_pdf_icon"];
$this->contents_array["show_print_icon"][] = $myrow["show_print_icon"];
$this->contents_array["show_email_icon"][] = $myrow["show_email_icon"];
$this->contents_array["show_comments"][] = $myrow["show_comments"];
$result2 = $this->connector->query("SELECT * FROM users WHERE id=".$myrow["userid"]);
if ($myrow2 = $this->connector->fetchArray($result2))
{
$this->contents_array["author"][] = $myrow2["username"];
$this->contents_array["author_email"][] = $myrow2["email"];
}
else
{
$this->contents_array["author"][] = "";
$this->contents_array["author_email"][] = "";
}
if ($myrow2["email"]!="" and $myrow["show_meta"]==1)
$this->contents_array["metadata"][] = _SUBMITED_BY.' <a href="mailto:'.$myrow2["email"].'">'.$myrow2["username"].'</a> '._SUBMITED_ON.' '.$this->system->formatDateTextual($myrow["created"], "d F Y H:i");
else if ($myrow2["email"]=="" and $myrow["show_meta"]==1)
$this->contents_array["metadata"][] = _SUBMITED_BY.' '.$myrow2["username"].' '._SUBMITED_ON.' '.$this->system->formatDateTextual($myrow["created"], "d F Y H:i");
else
$this->contents_array["metadata"][] = "";
$this->contents_array["attachments"][] = $attachments->getAttachmentsByParentId($myrow["id"]);
}
return $this->contents_array;
}
// Επιστρέφει το συνολικό αριθμό των αποτελεσμάτων
public function setTotalNumOfContents($sql)
{
$sql = preg_replace('/\s+(ORDER BY|LIMIT).+/ui','',$sql);
$result = $this->connector->query($sql);
$this->total_contents = $this->connector->getNumRows($result);
}
// Αυξάνει τα Hits του συγκεκριμένου περιεχομένου κατά ένα
public function updateContentHits($content_id)
{
$this->connector->query("UPDATE content SET hits=hits+1 WHERE id=".$content_id);
}
// Εισάγει στη βάση νέο άρθρο ή σύνδεσμο
public function insertContent($category_id, $title, $summary, $body, $created, $publish_up, $publish_down, $state, $frontpage, $article_type, $userid, $show_meta, $show_pdf_icon, $show_print_icon, $show_email_icon, $show_comments, $access, $link, $weblink_target)
{
if ($article_type==0)
$sql = "INSERT INTO content (category_id, title, summary, body, created, publish_up, publish_down, state, frontpage, article_type, userid, show_meta, show_pdf_icon, show_print_icon, show_email_icon, show_comments, access) VALUES ('$category_id','$title','$summary','$body','$created','$publish_up','$publish_down','$state','$frontpage','$article_type','$userid','$show_meta','$show_pdf_icon','$show_print_icon','$show_email_icon', '$show_comments','$access')";
else if ($article_type==1)
$sql = "INSERT INTO content (category_id, title, body, created, publish_up, publish_down, state, frontpage, article_type, link, weblink_target, userid, access) VALUES ('$category_id','$title','$body','$created','$publish_up','$publish_down','$state',0,'$article_type','$link','$weblink_target','$userid','$access')";
$result = $this->connector->query($sql);
return $result;
}
// Ενημερώνει ένα ήδη υπάρχον άρθρο ή σύνδεσμο
public function updateContent($id, $category_id, $title, $summary, $body, $created, $publish_up, $publish_down, $state, $frontpage, $article_type, $show_meta, $show_pdf_icon, $show_print_icon, $show_email_icon, $show_comments, $access, $link, $weblink_target)
{
if ($article_type==0)
$sql = "UPDATE content SET category_id='$category_id', title='$title', summary='$summary', body='$body', created='$created', modified=NOW(), publish_up='$publish_up', publish_down='$publish_down', state='$state', frontpage='$frontpage', article_type='$article_type', show_meta='$show_meta', show_pdf_icon='$show_pdf_icon', show_print_icon='$show_print_icon', show_email_icon='$show_email_icon', show_comments='$show_comments', access='$access' WHERE id=$id";
else if ($article_type==1)
$sql = "UPDATE content SET category_id='$category_id', title='$title', body='$body', created='$created', modified=NOW(), publish_up='$publish_up', publish_down='$publish_down', state='$state', frontpage=0, article_type='".$_SESSION["cms_article_type"]."', link='$link', weblink_target='$weblink_target', access='$access' WHERE id=$id";
$result = $this->connector->query($sql);
return $result;
}
// Διαγράφει το περιεχόμενο με το συγκεκριμένο id
public function deleteContent($id)
{
$result = $this->connector->query("DELETE FROM content WHERE id=$id");
return $result;
}
// Επιστρέφει πίνακα που περιέχει ανά μέρα του δοσμένου μήνα τον αριθμό των άρθρων των επιλεγμένων κατηγοριών που αναρτ. To $date είναι της μορφής yyyy-mm-dd
public function getNumOfContentsPerDay($date, $cat_ids_array=array(), $state=2)
{
if (strtotime($date) == false || $date == '')
return false;
$criteria = "created LIKE '".$date."%'";
if ($state==0 or $state==1)
$criteria = " and state=".$state;
if (is_array($cat_ids_array) and count($cat_ids_array)>0)
{
$c=0;
foreach($cat_ids_array as $catid)
{
if ($c==0)
$criteria .= " and (category_id=".$catid;
else
$criteria .= " or category_id=".$catid;
++$c;
}
$criteria .= ")";
}
if ($_SESSION["perm_frontend_view_registered_content"]==0)
$criteria .= " and access=0";
$sql = "SELECT * FROM content WHERE ".$criteria;
$result = $this->connector->query($sql);
$contents_per_day = array_fill(1, 31, 0); // Βάλε αρχική τιμή 0 στο πλήθος ανακοινώσεων ανά ημέρα
while ($myrow = $this->connector->fetchArray($result))
{
$monthday = (int) substr($myrow["created"], 8,2); // Εύρεση της ημέρας του μήνα από την ημερομηνία
++$contents_per_day[$monthday];
}
return $contents_per_day;
}
// Εναλλάσει τη κατάσταση (ενεργό/ανενεργό) του περιεχομένου με το συγκεκριμένο id
public function toggleContentState($id)
{
$myrow = $this->getContentById($id);
if ($myrow["state"]==1)
$new_state = 0;
else
$new_state = 1;
$result = $this->connector->query("UPDATE content SET state='$new_state' WHERE id=".$myrow["id"]);
return $result;
}
// Εναλλάσει την παράμετρο frontpage του περιεχομένου με το συγκεκριμένο id
public function toggleContentFrontpage($id)
{
$myrow = $this->getContentById($id);
if ($myrow["frontpage"]==1)
$new_frontpage_state = 0;
else
$new_frontpage_state = 1;
$result = $this->connector->query("UPDATE content SET frontpage='$new_frontpage_state' WHERE id=".$myrow["id"]);
return $result;
}
// Εναλλάσει το επίπεδο πρόσβασης (0=Δημόσιο, 1=Μέλη) του περιεχομένου με το συγκεκριμένο id
public function toggleContentAccess($id)
{
$myrow = $this->getContentById($id);
if ($myrow["access"]==1)
$new_access_level = 0;
else
$new_access_level = 1;
$result = $this->connector->query("UPDATE content SET access='$new_access_level' WHERE id=".$myrow["id"]);
return $result;
}
// Μηδενίζει το πεδίο γονικής κατηγορίας των περιεχομένων τη κατηγορίας με το δοσμένο category_id
public function resetContentsParentCategory($category_id)
{
$result = $this->connector->query("SELECT * FROM content WHERE category_id=".$category_id);
while ($myrow = $this->connector->fetchArray($result))
{
$this->connector->query("UPDATE content SET category_id=0 WHERE id=".$myrow["id"]);
}
}
// Επιστρέφει μια εισαγωγή του κειμένου μεγέθους $numofletters χαρακτήρων
public function makePreview($txt, $numofletters,$included_tags)
{
global $system;
$html = $system->stripHTMLTags($txt,$included_tags);
if (strlen($html)>$numofletters)
$html = substr($html,0,$numofletters).substr($html,$numofletters,strpos($html," ",$numofletters)-($numofletters-1))." ...";
return $html;
}
// Δημιουργεί και παρουσιάζει το rss περιεχόμενο από τη δοσμένη κατηγορία $cat_ids. Το $cat_ids μπορεί να είναι περιέχει πολλές κατηγορίες (πχ 23,45,67,89)
public function rss($current_lang_id=0, $cat_ids=0)
{
$now = date("D, d M Y H:i:s T");
$general_description = $this->system->general_settings["site_title"];
// Αν το $cat_ids είναι της σωστής μορφής πχ 23,45,67,89 φτιάξε τον πίνακα με τα ids
if (preg_match("/^\d+(,\d+)*$/", $cat_ids))
{
$cat_ids_array = explode(",", $cat_ids);
}
else
{
$cat_ids_array = array();
}
$where = "";
if (count($cat_ids_array)>0)
{
$c = 0;
foreach ($cat_ids_array as $cid)
{
if ($where=="")
$where .= 'and (category_id='.$cid;
else
$where .= ' or category_id='.$cid;
$result = $this->connector->query("SELECT * FROM categories WHERE id=".$cid);
if ($myrow = $this->connector->fetchArray($result))
{
if ($c==0)
$general_description .= " - ".$myrow["title"];
else
$general_description .= ", ".$myrow["title"];
}
++$c;
}
$where .= ')';
}
if ($current_lang_id==0)
$current_lang_id = $this->translator->default_lang["id"];
if ($_SESSION["perm_frontend_view_registered_content"]==0)
$access_level = "and access=0";
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<rss version=\"2.0\">\n\t<channel>\n\t\t<title><![CDATA[".$this->system->general_settings["site_title"]."]]></title>\n\t\t<link>".$this->system->fullURL(false)."</link>\n\t\t<description><![CDATA[".$general_description."]]></description>\n\t\t<language>en-us</language>\n\t\t<pubDate>$now</pubDate>\n\t\t<lastBuildDate>$now</lastBuildDate>";
$sql = "SELECT * FROM content WHERE article_type=0 and state=1 $where $access_level ORDER BY created DESC, id DESC LIMIT ".$this->system->general_settings["rss_articles"];
$result = $this->connector->query($this->translator->fixSqlStatement($sql, $current_lang_id, "content", $this->system->general_settings["untranslated_articles_policy"]));
while ($myrow = $this->connector->fetchArray($result))
{
if ($current_lang_id != $this->translator->default_lang["id"]) // Αν δεν έχουμε Default γλώσσα
{
$result2 = $this->connector->query("SELECT * FROM translations WHERE language_id=".$current_lang_id." and reference_id=".$myrow["id"]." and reference_table='content'");
while ($myrow2 = $this->connector->fetchArray($result2)) // Αν υπάρχει μετάφραση στην τρέχουσα γλώσσα
{
if ($myrow2["reference_field"]=='title')
$myrow["title"] = $myrow2["value"];
if ($myrow2["reference_field"]=='body')
$myrow["body"] = $myrow2["value"];
}
}
$result2 = $this->connector->query("SELECT * FROM categories WHERE id=".$myrow["category_id"]);
if ($myrow2 = $this->connector->fetchArray($result2))
$item_category = $myrow2["title"];
$output .= "\n\t\t<item>";
$output .= "\n\t\t\t<title><![CDATA[".$this->system->stripHTMLTags($myrow['title'],"")."]]></title>";
$output .= "\n\t\t\t<link>".$this->system->fullURL(false)."?id=".$myrow['id']."</link>";
$output .= "\n\t\t\t<description><![CDATA[".$this->makePreview($myrow['body'],$this->system->general_settings["rss_summary_length"],"<br>")."]]></description>";
$output .= "\n\t\t\t<category><![CDATA[".$item_category."]]></category>";
$output .= "\n\t\t\t<pubDate>".date("r", strtotime($myrow['created']))."</pubDate>";
$output .= "\n\t\t</item>";
}
$output .= "\n\t</channel>\n</rss>";
header("Content-Type: application/rss+xml");
echo $output;
}
public function makePDF($url)
{
if (ini_get('allow_url_fopen')) {
$html = file_get_contents($url);
}
else {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
$html = curl_exec($ch);
curl_close($ch);
}
// Εύρεση του head κώδικα της σελίδας
$matchcount = preg_match('/<head>.*<\/head>/si', $html, $matches);
$page_head = $matches[0];
// Regular expression για εύρεση div με συγκεκριμένη κλάση και οποιοδήποτε άλλο βάθος nested divs
$pattern = '{<div\s+class="article"\s*>((?:(?:(?!<div[^>]*>|</div>).)++|<div[^>]*>(?1)</div>)*)</div>}si';
$matchcount = preg_match($pattern, $html, $matches);
$article_content = $matches[0];
// Αφαίρεση του div με τα εικονίδια pdf, εκτύπωσης και email
$article_content = preg_replace('/<div class="article_actions">.*<\/div>/i', '', $article_content);
// Εύρεση του τίτλου του άρθρου
$matchcount = preg_match('/<div class="article_title"><h3>(.*)<\/h3><\/div>/i', $article_content, $matches);
$article_title = $matches[1];
$html = '<html>'.$page_head.'<body>'.$article_content.'</body></html>';
// Δημιουργία του PDF εγγράφου
$mpdf=new mPDF('utf-8');
$mpdf->SetTitle($article_title);
$stylesheet = file_get_contents('css/style.css');
$mpdf->WriteHTML($stylesheet,1);
$stylesheet = file_get_contents('css/print.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($article_content);
$mpdf->Output($article_title, 'I');
}
}