| 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: Modules
// Purpose: Κλάση ενθεμάτων (modules)
///////////////////////////////////////////////////////////////////////////////////////
class Modules
{
private $connector;
private $system;
private $translator;
public function __construct($db, $system, $translator)
{
$this->connector = $db;
$this->system = $system;
$this->translator = $translator;
}
// Επιστρέφει τα στοιχεία του Module με το δεδομένο id
public function getModuleById($id)
{
$result = $this->connector->query("SELECT * FROM modules WHERE id=".$id);
return $this->connector->fetchArray($result);
}
// Επιστρέφει πίνακα με όλα τα Modules
public function getAllModules($state=-1)
{
$modules_array = array();
if ($state==0 or $state==1)
$where = "WHERE state=".$state;
else
$where = "";
$result = $this->connector->query("SELECT * FROM modules ".$where);
while ($myrow=$this->connector->fetchArray($result))
$modules_array[] = $myrow;
return $modules_array;
}
// Επιστρέφει πίνακα με τις ενεργές θέσεις των Modules
public function getModulePositionsArray()
{
$module_positions = array();
$result = $this->connector->query("SELECT * FROM module_positions WHERE state=1 ORDER BY position");
while ($myrow = $this->connector->fetchArray($result))
{
$module_positions[$myrow["id"]] = $myrow;
}
return $module_positions;
}
// Επιστρέφει πίνακα με τα ενεργά Modules της συγκεκριμένης δοσμένης θέσης και δοσμένης κατηγορίας
public function getModulesPerPositionArray($mod_position_id, $category_id)
{
$modules_per_position_array = array();
if ($_SESSION["perm_frontend_view_registered_content"]==0)
$access_level = "and access=0";
$sql = "SELECT * FROM modules, modules_categories WHERE modules.position=".$mod_position_id." and modules.state=1 and modules.id=modules_categories.moduleid and (modules_categories.categoryid=".$category_id." or modules_categories.categoryid=0) $access_level ORDER BY modules.sort_order ASC";
$result = $this->connector->query($this->translator->fixSqlStatement($sql, $this->translator->current_lang["id"], "modules", $this->system->general_settings["untranslated_modules_policy"]));
$i=0;
while ($myrow = $this->connector->fetchArray($result))
{
foreach ($myrow as $key=>$value)
{
$modules_per_position_array[$i][$key] = $value;
}
$modules_per_position_array[$i] = $this->translateModule($modules_per_position_array[$i]);
++$i;
}
return $modules_per_position_array;
}
// Επιστρέφει τα στοιχεία του τύπου ενθέματος με το δεδομένο id
public function getModuleTypeById($id)
{
$result = $this->connector->query("SELECT * FROM module_types WHERE id=".$id);
return $this->connector->fetchArray($result);
}
// Επιστρέφει πίνακα με τους υπάρχοντες τύπους (module types) ενθεμάτων
public function getModuleTypesArray()
{
$mod_types_array = array();
$result = $this->connector->query("SELECT * FROM module_types");
while ($myrow = $this->connector->fetchArray($result))
{
$mod_types_array[$myrow["id"]] = $myrow;
}
return $mod_types_array;
}
// Επιστρέφει τα στοιχεία της τοποθεσίας (position) με το δεδομένο id
public function getModulePositionById($id)
{
$result = $this->connector->query("SELECT * FROM module_positions WHERE id=".$id);
return $this->connector->fetchArray($result);
}
// Επιστρέφει πίνακα με όλα τα Modules ταξινομημένα με βάση τις θέσεις τους
public function getModulesOrderedByPosition()
{
$modules_array = array();
$result = $this->connector->query("SELECT * FROM modules ORDER BY position ASC, sort_order ASC");
while ($myrow = $this->connector->fetchArray($result))
{
$modules_array[] = $myrow;
}
return $modules_array;
}
// Επιστρέφει τον αριθμό σειράς του πρώτου στην σειρά ενθέματος της δοσμένης τοποθεσίας
public function minSortOrderModule($position)
{
$result = $this->connector->query("SELECT MIN(sort_order) FROM modules WHERE position=".$position);
$myrow = $this->connector->fetchArray($result);
return $myrow["MIN(sort_order)"];
}
// Επιστρέφει τον αριθμό σειράς του τελευταίου στην σειρά ενθέματος της δοσμένης τοποθεσίας
public function maxSortOrderModule($position)
{
$result = $this->connector->query("SELECT MAX(sort_order) FROM modules WHERE position=".$position);
$myrow = $this->connector->fetchArray($result);
return $myrow["MAX(sort_order)"];
}
// Επιστρέφει πίνακα με τα ids των κατηγοριών στις οποίες εμφανίζεται το ένθεμα με το δεδομένο id
public function getCategoriesWhereModuleShows($id)
{
$categories_array = array();
$result = $this->connector->query("SELECT * FROM modules_categories WHERE moduleid=".$id);
while ($myrow = $this->connector->fetchArray($result))
{
$categories_array[] = $myrow["categoryid"];
}
return $categories_array;
}
// Επιστρέφει τις μεταφρασμένες εκδοχές του title και body του δοσμένου Module αν υπάρχουν και αν δεν είμαστε στην default γλώσσα
public function translateModule($module)
{
if ($this->translator->current_lang["id"] != $this->translator->default_lang["id"]) // Αν δεν έχουμε Default γλώσσα
{
$translated_fields = $this->translator->fetchTranslatedContent($this->translator->current_lang["id"], $module["id"], "modules");
foreach ($translated_fields as $field_name=>$value)
{
$module[$field_name] = $value;
}
}
return $module;
}
// Εισάγει ένα νέο ένθεμα στη τοποθεσία $position και στη σειρά εμφάνισης $sort_order. Τα ενθέματα που ακολουθούν μετατοπίζονται μια θέση παρακάτω.
public function insertModule($title, $body, $mod_type, $show_title, $state, $sort_order, $position, $params, $access, $classname)
{
// Μετατόπιση προς τα κάτω ενθεμάτων αν είναι απαραίτητο για την εισαγωγή του νέου ενθέματος στη θέση του
$result = $this->connector->query("SELECT * FROM modules WHERE sort_order>=".$sort_order." and position=".$position." ORDER BY sort_order, id");
$pos = $sort_order;
while ($myrow = $this->connector->fetchArray($result))
{
++$pos;
$this->connector->query("UPDATE modules SET sort_order=".$pos." WHERE id=".$myrow["id"]);
}
// Εισαγωγή του νέου ενθέματος
$result = $this->connector->query("INSERT INTO modules (mod_type, title, show_title, body, state, sort_order, position, params, access, classname) VALUES ('$mod_type','$title','$show_title','$body','$state','$sort_order','$position','$params', '$access','$classname')");
return $result;
}
// Ενημέρωση του ενθέματος με το δεδομένο id
public function updateModule($id, $title, $body, $show_title, $state, $sort_order, $position, $params, $access, $classname)
{
// Εύρεση των παλιών sort_order και position
$myrow = $this->getModuleById($id);
$old_sort_order = $myrow["sort_order"];
$old_position = $myrow["position"];
// Μετατόπιση προς τα κάτω ενθεμάτων αν είναι απαραίτητο για την τοποθέτηση του ενθέματος στη νέα του θέση
if ($sort_order!=$old_sort_order or $position!=$old_position)
{
$result = $this->connector->query("SELECT * FROM modules WHERE sort_order>=".$sort_order." and position=".$position." ORDER BY sort_order, id");
$pos = $sort_order;
while ($myrow = $this->connector->fetchArray($result))
{
++$pos;
$this->connector->query("UPDATE modules SET sort_order=".$pos." WHERE id=".$myrow["id"]);
}
}
$result = $this->connector->query("UPDATE modules SET title='$title', show_title='$show_title', body='$body', state=$state, sort_order=$sort_order, position=$position, params='$params', access='$access', classname='$classname' WHERE id=$id");
return $result;
}
// Διαγραφή ενθέματος με το συγκεκριμένο id
public function deleteModule($id)
{
$result = $this->connector->query("DELETE FROM modules WHERE id=$id");
if ($result==true)
{
$this->connector->query("DELETE FROM modules_categories WHERE moduleid=$id"); // Διαγραφή αντιστοιχίσεων σε κατηγορίες
$this->translator->deleteAllTranslations("modules", $id); // Διαγραφή μεταφράσεων
}
return $result;
}
// Καταχώρηση των αντιστοιχίσεων του module με το δεδομένο id ($mod_id) στις κατηγορίες όπου θα εμφανίζεται (πίνακας $categories_array με τα ids των κατηγοριών)
public function assignModuleToCategories($mod_id, $categories_array)
{
$this->connector->query("DELETE FROM modules_categories WHERE moduleid=$mod_id"); // Διαγραφή των προηγούμενων αντιστοιχίσεων
if (count($categories_array)>0)
{
foreach ($categories_array as $category_id)
{
$this->connector->query("INSERT INTO modules_categories (moduleid, categoryid) VALUES ($mod_id, $category_id)");
}
}
}
// Επαναταξινομεί με συνεχόμενο αύξοντα αριθμό τα ενθέματα που βρίσκονται στη θέση $position
public function reorderModules($position)
{
$result = $this->connector->query("SELECT * FROM modules WHERE position=".$position." ORDER BY sort_order, id");
$pos=0;
while ($myrow = $this->connector->fetchArray($result))
{
++$pos;
$this->connector->query("UPDATE modules SET sort_order=".$pos." WHERE id=".$myrow["id"]);
}
}
// Εναλλάσει τη κατάσταση (ενεργό/ανενεργό) του ένθετου με το συγκεκριμένο id
public function toggleModuleState($id)
{
$myrow = $this->getModuleById($id);
if ($myrow["state"]==1)
$new_state = 0;
else
$new_state = 1;
$result = $this->connector->query("UPDATE modules SET state='$new_state' WHERE id=".$myrow["id"]);
return $result;
}
// Εναλλάσει το επίπεδο πρόσβασης (0=Δημόσιο, 1=Μέλη) του ενθέματος με το συγκεκριμένο id
public function toggleModuleAccess($id)
{
$myrow = $this->getModuleById($id);
if ($myrow["access"]==1)
$new_access_level = 0;
else
$new_access_level = 1;
$result = $this->connector->query("UPDATE modules SET access='$new_access_level' WHERE id=".$myrow["id"]);
return $result;
}
// Μετακινεί το ένθεμα με το συγκεκριμένο id μια θέση πάνω ($direction="up") ή κάτω ($direction="down") σε σχέση με τα υπόλοιπα ενθέματα στο ίδιο position
public function moveModule($id, $direction)
{
if ($myrow = $this->getModuleById($id))
{
if ($direction=="up")
$result2 = $this->connector->query("SELECT * FROM modules WHERE sort_order<".$myrow["sort_order"]." and position=".$myrow["position"]." ORDER BY sort_order DESC LIMIT 0,1");
else
$result2 = $this->connector->query("SELECT * FROM modules WHERE sort_order>".$myrow["sort_order"]." and position=".$myrow["position"]." ORDER BY sort_order ASC LIMIT 0,1");
if ($myrow2 = $this->connector->fetchArray($result2))
{
$tmp_order = $myrow2["sort_order"];
$this->connector->query("UPDATE modules SET sort_order=".$myrow["sort_order"]." WHERE id=".$myrow2["id"]);
$this->connector->query("UPDATE modules SET sort_order=".$tmp_order." WHERE id=".$id);
}
$this->reorderModules($myrow["position"]);
}
}
// Επιστρέφει πίνακα με τις παραμέτρους του συγκεκριμένου Module
public function getModuleParametersArray($module)
{
$module_parameters_array = array();
if ($module['params']!="")
{
$lines_array = explode("\n",$module['params']);
foreach($lines_array as $line)
{
$parameter_array = explode("=",$line);
$module_parameters_array[$parameter_array[0]] = $parameter_array[1];
}
}
return $module_parameters_array;
}
// Επιστρέφει πίνακα με τα τελευταία ή δημοφιλέστερα ή μόνιμα νέα
public function getLatestPopularNews($module_type, $module_parameters_array)
{
$news_array = array();
$sql = "SELECT * FROM content WHERE";
$creteria = "";
if ($module_parameters_array["param_category_ids"]!="" and $module_parameters_array["param_category_ids"]!=0)
{
$cat_ids = explode(",",$module_parameters_array["param_category_ids"]);
$c=0;
foreach($cat_ids as $catid)
{
if ($c==0)
$creteria .= " (category_id=$catid";
else
$creteria .= " or category_id=$catid";
++$c;
}
}
if ($module_parameters_array["param_frontpage_articles"]==1)
{
if ($creteria=="")
$creteria = "(frontpage=1";
else
$creteria .= " or frontpage=1";
}
if ($creteria!="")
$creteria .= ") and ";
if ($module_parameters_array["param_frontpage_articles"]==2) // Πρόβαλε μόνο άρθρα που είναι πρωτοσέλιδα
{
$creteria .= "frontpage=1 and ";
}
if ($module_type==3 or $module_type==12)
$sort_order = "created DESC, id DESC";
else
$sort_order = "hits DESC, created DESC, id DESC";
if ($_SESSION["perm_frontend_view_registered_content"]==0)
$access_level = "and access=0";
$sql .= $creteria." state=1 and article_type=0 $access_level and publish_up<=NOW() and (publish_down > NOW() or publish_down='0000-00-00 00:00:00') ORDER BY $sort_order LIMIT 0,".$module_parameters_array["param_count"];
$result = $this->connector->query($this->translator->fixSqlStatement($sql, $this->translator->current_lang["id"], "content", $this->system->general_settings["untranslated_articles_policy"]));
$i=0;
while ($myrow = $this->connector->fetchArray($result))
{
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", "title");
if (count($translated_fields)>0)
{
$myrow["title"] = $translated_fields["title"];
}
}
$news_array[$i] = $myrow;
++$i;
}
return $news_array;
}
// Επιστρέφει πίνακα με τις κατηγορίες ενός δευτερεύοντος μενού Module
public function getSecontaryMenuCategoriesArray($module_parameters_array)
{
$categories_array = array();
$creteria = "";
if ($module_parameters_array["param_secondarymenu_items"]!="")
{
$cat_ids = explode(",",$module_parameters_array["param_secondarymenu_items"]);
$i=0;
foreach($cat_ids as $catid)
{
if ($i==0)
$creteria .= "categories.id=$catid";
else
$creteria .= " or categories.id=$catid";
++$i;
}
}
if ($i>=2)
$creteria = "($creteria)";
$sql = "SELECT * FROM categories WHERE $creteria ORDER BY sort_order ASC";
$result = $this->connector->query($this->translator->fixSqlStatement($sql, $this->translator->current_lang["id"], "categories", $this->system->general_settings["untranslated_categories_policy"]));
$i=0;
while ($myrow = $this->connector->fetchArray($result))
{
if ($myrow['access']==1 and $_SESSION["perm_frontend_view_registered_content"]==0) // Δεν εμφανίζει το μενού αν είναι Ιδιωτικό και ο χρήστης δεν έχει εξουσιοδότηση
continue;
if ($this->translator->current_lang["id"] != $this->translator->default_lang["id"]) // Αν δεν έχουμε Default γλώσσα
{
$translated_fields = $this->translator->fetchTranslatedContent($this->translator->current_lang["id"], $myrow["id"], "categories", "title");
if (count($translated_fields)>0)
{
$myrow["title"] = $translated_fields["title"];
}
}
$categories_array[$i] = $myrow;
++$i;
}
$properly_ordered_categories_array = array();
foreach ($cat_ids as $catid)
{
for ($i=0; $i<count($categories_array); ++$i)
{
if ($catid==$categories_array[$i]["id"])
$properly_ordered_categories_array[$catid] = $categories_array[$i];
}
}
return $properly_ordered_categories_array;
}
// Επιστρέφει πίνακα με τις τιμές του πεδίου contact_parameters του Module
public function getContactParametersArray($module_parameters_array)
{
if ($module_parameters_array["param_contact"]!="")
$param_contact_array = explode(",",$module_parameters_array["param_contact"]);
else
$param_contact_array = array(1,1,1,1,1,1,1);
return $param_contact_array;
}
// CMS: Δημιουργεί και επιστρέφει σε μορφή HTML options list όλα τα ενθέματα που έχει δημιουργήσει ο χρήστης
public function buildModulesList($selected_modules_array)
{
$html = '';
$modules_array = $this->getAllModules(); // Πάρε όλα τα modules ενεργά και ανενεργά
foreach ($modules_array as $module)
{
if (in_array($module["id"], $selected_modules_array))
$selected = " selected";
else
$selected = "";
$html .= '<option value="'.$module["id"].'"'.$selected.'>'.$module["title"].'</option>';
}
return $html;
}
}