| 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: Photogalleries
// Purpose: Κλάση φωτογραφικών άλμπουμς
///////////////////////////////////////////////////////////////////////////////////////
class Photogalleries
{
public $photogalleries_path;
public $photogalleries_settings;
private $connector;
private $system;
private $translator;
private $temp;
public function __construct($db, $system, $translator)
{
$this->connector = $db;
$this->system = $system;
$this->translator = $translator;
$this->photogalleries_path = "userfiles/photogalleries";
$this->photogalleries_settings = $this->getPhotogalleriesSettings();
}
// Αντλεί τις ρυθμίσεις για τις photogalleries από τη βάση
public function getPhotogalleriesSettings()
{
$result = $this->connector->query("SELECT * FROM photogalleries_settings");
$photogalleries_settings = $this->connector->fetchArray($result);
return $photogalleries_settings;
}
// Ενημερώνει τις ρυθμίσεις για τις photogalleries
public function updatePhotogalleriesSettings($maxwidth, $maxheight, $resizeby, $photoquality, $originalphotoresize, $thumbwidth, $thumbheight, $thumbresizeby, $categoriesordering, $categoriesperpage, $categoriescolumns, $showcatthumbnail, $photosordering, $photosperpage, $photoscolumns, $fancybox, $id=1)
{
$result = $this->connector->query("UPDATE photogalleries_settings SET maxwidth=$maxwidth, maxheight=$maxheight, resizeby=$resizeby, photoquality=$photoquality, originalphotoresize=$originalphotoresize, thumbwidth=$thumbwidth, thumbheight=$thumbheight, thumbresizeby=$thumbresizeby, categoriesordering=$categoriesordering, categoriesperpage=$categoriesperpage, categoriescolumns=$categoriescolumns, showcatthumbnail=$showcatthumbnail, photosordering=$photosordering, photosperpage=$photosperpage, photoscolumns=$photoscolumns, fancybox='$fancybox' WHERE id=".$id);
// Ενημέρωσε τον πίνακα $photogalleries_settings με τα νέα δεδομένα
$result = $this->connector->query("SELECT * FROM photogalleries_settings");
$this->photogalleries_settings = $this->connector->fetchArray($result);
return $result;
}
// Επιστρέφει πίνακα με τα στοιχεία των πεδίων της κατηγορίας με το δοσμένο id
public function getCategoryById($id)
{
$result = $this->connector->query("SELECT * FROM photogalleries_cats WHERE id=$id");
$myrow = $this->connector->fetchArray($result);
return $myrow;
}
// Εισάγει μια νέα κατηγορία με γονέα $parent_id και στη σειρά εμφάνισης $sort_order. Οι υποκατηγορίες που ακολουθούν μετατοπίζονται μια θέση παρακάτω.
public function insertCategory($title, $description, $parent_id, $state, $sort_order, $access)
{
// Μετατόπιση προς τα κάτω κατηγοριών αν είναι απαραίτητο για την εισαγωγή του νέου ενθέματος στη θέση του
$result = $this->connector->query("SELECT * FROM photogalleries_cats WHERE sort_order>=".$sort_order." and parent_id=".$parent_id." ORDER BY sort_order, id");
$pos = $sort_order;
while ($myrow = $this->connector->fetchArray($result))
{
++$pos;
$this->connector->query("UPDATE photogalleries_cats SET sort_order=".$pos." WHERE id=".$myrow["id"]);
}
// Εισαγωγή του νέας κατηγορίας
$result = $this->connector->query("INSERT INTO photogalleries_cats (title, description, parent_id, state, sort_order, access) VALUES ('$title', '$description', $parent_id, $state, $sort_order, $access)");
$id = $this->connector->getLastInsertedId();
$catpath = $this->system->generateSlug($title, "_")."_".$id;
$this->connector->query("UPDATE photogalleries_cats SET catpath='$catpath' WHERE id=$id");
if ($result==true)
$this->createGalleryFolder($id, $catpath);
return $result;
}
// Ενημέρωση της κατηγορίας με το δεδομένο id
public function updateCategory($id, $title, $description, $parent_id, $state, $sort_order, $access, $catimage)
{
// Εύρεση των παλιών sort_order και position
$myrow = $this->getCategoryById($id);
$old_sort_order = $myrow["sort_order"];
$old_parent_id = $myrow["parent_id"];
// Μετατόπιση προς τα κάτω κατηγοριών αν είναι απαραίτητο για την τοποθέτηση της κατηγορίας στη νέα της θέση
$result = $this->connector->query("SELECT * FROM photogalleries_cats WHERE sort_order>=".$sort_order." and parent_id=".$parent_id." ORDER BY sort_order, id");
$pos = $sort_order;
while ($myrow = $this->connector->fetchArray($result))
{
++$pos;
$this->connector->query("UPDATE photogalleries_cats SET sort_order=".$pos." WHERE id=".$myrow["id"]);
}
$result = $this->connector->query("UPDATE photogalleries_cats SET title='$title', description='$description', parent_id=$parent_id, state=$state, sort_order=$sort_order, access=$access, catimage='$catimage' WHERE id=$id");
return $result;
}
// Διαγραφή κατηγορίας με το συγκεκριμένο id
public function deleteCategory($id)
{
$myrow = $this->getCategoryById($id);
$catpath = $myrow["catpath"];
$result = $this->connector->query("DELETE FROM photogalleries_cats WHERE id=$id");
if ($result==true)
{
$this->translator->deleteAllTranslations("photogalleries_cats", $id); // Διαγραφή μεταφράσεων
}
if ($result==true)
$this->deleteGalleryFolder($id, $catpath);
return $result;
}
// Επιστρέφει πίνακα με τις υποκατηγορές που ανοίκουν στη δοσμένη κατηγορία. Αν $exclude_empty=true δεν επιστρέφονται οι άδειες, χωρίς φωτογραφίες κατηγορίες
// Αν $order_by=0 οι υποκακατηγορίες ταξινομούνται βάση του αριθμού ταξινόμησης, ενώ αν $order_by=1 βάση του τίτλου
public function getSubCategories($category_id, $order_by=0, $exclude_empty=false)
{
if ($order_by==0)
$order_by = "sort_order ASC, title ASC";
else
$order_by = "title ASC, sort_order ASC";
$subcategories_array = array();
$result = $this->connector->query("SELECT * FROM photogalleries_cats WHERE parent_id=$category_id ORDER BY $order_by");
while ($myrow = $this->connector->fetchArray($result))
{
if ($exclude_empty==false or ($exclude_empty==true and $this->getCategoryTotalNumOfPhotos($myrow["id"], true)>0))
$subcategories_array[] = $myrow;
}
return $subcategories_array;
}
// CMS: Δημιουργεί και επιστρέφει σε μορφή HTML options list όλη τη δομή κατηγοριών ξεκινώντας από τον γονέα $parent_id. To option με id κατηγορίας $disabled_category γίνεται disabled (μη επιλέξιμο)
public function buildCategoriesOptionList($parent_id, $selected_categories_array=array(), $disabled_category=0, $depth=0)
{
$html = '';
++$depth;
$result = $this->connector->query("SELECT * FROM photogalleries_cats WHERE parent_id=$parent_id ORDER BY sort_order ASC");
while ($myrow = $this->connector->fetchArray($result))
{
if ($myrow['id']==$disabled_category)
continue;
$spaces="";
for ($i=1; $i<$depth; ++$i)
{
$spaces.=" ";
}
$new_option = '<option value='.$myrow['id'];
if ($depth>1)
$new_option .= ' style="background: url(images/categories_tree_line.png) no-repeat '.(($depth-1)*15-9).'px 1px;"';
if (in_array($myrow['id'], $selected_categories_array))
$new_option .= ' selected';
if ($myrow['id']==$disabled_category)
$new_option .= ' disabled';
$new_option .='>'.$spaces.$myrow['title'].'</option>';
$html .= $new_option;
$html .= $this->buildCategoriesOptionList($myrow['id'], $selected_categories_array, $disabled_category, $depth); // find childitems recursively
}
return $html;
}
// Επιστρέφει array με τα δεδομένα των εγγραφών που θα προβληθούν στον html πίνακα δεδομένων. Υποκατηγορίες υποκατηγοριών αντλούνται αναδρομικά
// έτσι ώστε αμέσως μετά μια κατηγορία να ακολουθούν όλες οι υποκατηγορίες και οι υποκατηγορίες των υποκατηγοριών κ.ο.κ.
public function buildCategoriesDataTableArray($state, $table_ordering, $order_type, $parent_id=0, $depth=0)
{
$data_array = array();
$children_array = array();
$where = "WHERE parent_id=$parent_id";
if ($state!=-1)
$where .= " and state=$state";
$result = $this->connector->query("SELECT * FROM photogalleries_cats $where ORDER BY $table_ordering $order_type");
while ($myrow = $this->connector->fetchArray($result))
{
$myrow["depth"] = $depth;
$data_array[] = $myrow;
$children_array = $this->buildCategoriesDataTableArray($state, $table_ordering, $order_type, $myrow["id"], ($depth+1));
if (count($children_array)>0)
$data_array = array_merge($data_array, $children_array);
}
return $data_array;
}
// Επιστρέφει τον αριθμό σειράς της πρώτης στην σειρά κατηγορίας που έχουν κοινό το δεδομένο γονέα (parent_id)
public function minSortOrderCategory($parent_id)
{
$result = $this->connector->query("SELECT MIN(sort_order) FROM photogalleries_cats WHERE parent_id=".$parent_id);
$myrow = $this->connector->fetchArray($result);
return $myrow["MIN(sort_order)"];
}
// Επιστρέφει τον αριθμό σειράς της τελευταίας στην σειρά κατηγορίας που έχουν κοινό το δεδομένο γονέα (parent_id)
public function maxSortOrderCategory($parent_id)
{
$result = $this->connector->query("SELECT MAX(sort_order) FROM photogalleries_cats WHERE parent_id=".$parent_id);
$myrow = $this->connector->fetchArray($result);
return $myrow["MAX(sort_order)"];
}
// Επαναταξινομεί με συνεχόμενο αύξοντα αριθμό τις κατηγορίες με τον ίδιο γονέα ($parent_id)
public function reorderCategories($parent_id)
{
$result = $this->connector->query("SELECT * FROM photogalleries_cats WHERE parent_id=".$parent_id." ORDER BY sort_order, id");
$pos=0;
while ($myrow = $this->connector->fetchArray($result))
{
++$pos;
$this->connector->query("UPDATE photogalleries_cats SET sort_order=".$pos." WHERE id=".$myrow["id"]);
}
}
// Μετακινεί την κατηγορία με το συγκεκριμένο id μια θέση πάνω ($direction="up") ή κάτω ($direction="down") σε σχέση με τα υπόλοιπες κατηγορίες με τον ίδιο γονέα
public function moveCategory($id, $direction)
{
if ($myrow = $this->getCategoryById($id))
{
if ($direction=="up")
$result2 = $this->connector->query("SELECT * FROM photogalleries_cats WHERE sort_order<".$myrow["sort_order"]." and parent_id=".$myrow["parent_id"]." ORDER BY sort_order DESC LIMIT 0,1");
else
$result2 = $this->connector->query("SELECT * FROM photogalleries_cats WHERE sort_order>".$myrow["sort_order"]." and parent_id=".$myrow["parent_id"]." ORDER BY sort_order ASC LIMIT 0,1");
if ($myrow2 = $this->connector->fetchArray($result2))
{
$tmp_order = $myrow2["sort_order"];
$this->connector->query("UPDATE photogalleries_cats SET sort_order=".$myrow["sort_order"]." WHERE id=".$myrow2["id"]);
$this->connector->query("UPDATE photogalleries_cats SET sort_order=".$tmp_order." WHERE id=".$id);
}
$this->reorderCategories($myrow["parent_id"]);
}
}
// Εναλλάσει τη κατάσταση (ενεργή/ανενεργή) της κατηγορίαςμε το συγκεκριμένο id
public function toggleCategoryState($id)
{
$myrow = $this->getCategoryById($id);
if ($myrow["state"]==1)
$new_state = 0;
else
$new_state = 1;
$result = $this->connector->query("UPDATE photogalleries_cats SET state='$new_state' WHERE id=".$myrow["id"]);
return $result;
}
// Εναλλάσει το επίπεδο πρόσβασης (0=Δημόσιο, 1=Μέλη) της κατηγορίας με το συγκεκριμένο id
public function toggleCategoryAccess($id)
{
$myrow = $this->getCategoryById($id);
if ($myrow["access"]==1)
$new_access_level = 0;
else
$new_access_level = 1;
$result = $this->connector->query("UPDATE photogalleries_cats SET access='$new_access_level' WHERE id=".$myrow["id"]);
return $result;
}
// Ελέγχει αν μια κατηγορία είναι γονέας άλλων υποκατηγοριών
public function hasSubCategories($id)
{
$result = $this->connector->query("SELECT * FROM photogalleries_cats WHERE parent_id=".$id);
if ($this->connector->getNumRows($result)>0)
return true;
else
return false;
}
// Αποθηκεύει στον πίνακα $cat_path = array('id' => array(), 'title' => array()); το πλήρες path (από το παιδί μέχρι τον αρχικό πατέρα) της δοσμένης κατηγορίας
public function buildCategoryPath($cat_id, $current_lang_id=0)
{
global $current_lang;
$cat_path = array();
$next_cat_id = "";
$next_cat_title = "";
$cur_cat_id = $cat_id;
$result = $this->connector->query("SELECT * FROM photogalleries_cats WHERE id=$cur_cat_id");
$loop = 0;
while ($myrow = $this->connector->fetchArray($result))
{
if ($current_lang_id!=0 and $current_lang_id != $this->translator->default_lang["id"]) // Αν δεν έχουμε Default γλώσσα
{
$translated_fields = $this->translator->fetchTranslatedContent($current_lang_id, $myrow["id"], "photogalleries_cats","title");
if (count($translated_fields)>0 and $translated_fields["title"]!="") // Αν υπάρχει μετάφραση στην τρέχουσα γλώσσα
{
$myrow["title"] = $translated_fields["title"];
}
}
$cat_path[] = array('id'=>$myrow["id"], 'title'=>$myrow["title"]);
if (($cur_cat_id=$myrow["parent_id"])==0)
break;
$result = $this->connector->query("SELECT * FROM photogalleries_cats WHERE id=$cur_cat_id");
}
$cat_path = array_reverse($cat_path);
return $cat_path;
}
// Δημιουργεί το φάκελο στο σκληρό δίσκο για το άλμπουμ της κατηγορίας με το δεδομένο id
public function createGalleryFolder($id, $catpath="")
{
if (!is_dir("../".$this->photogalleries_path))
mkdir("../".$this->photogalleries_path, 0777);
if (!is_dir("../".$this->photogalleries_path."/photos"))
mkdir("../".$this->photogalleries_path."/photos", 0777);
if (!is_dir("../".$this->photogalleries_path."/thumbnails"))
mkdir("../".$this->photogalleries_path."/thumbnails", 0777);
if ($catpath=="")
{
$myrow = $this->getCategoryById($id);
$catpath = $myrow["catpath"];
}
mkdir("../".$this->photogalleries_path."/photos/".$catpath, 0777);
mkdir("../".$this->photogalleries_path."/thumbnails/".$catpath, 0777);
}
// Διαγράφει το φάκελο στο σκληρό δίσκο για το άλμπουμ της κατηγορίας με το δεδομένο id
public function deleteGalleryFolder($id, $catpath="")
{
if ($catpath=="")
{
$myrow = $this->getCategoryById($id);
$catpath = $myrow["catpath"];
}
if ($catpath!="")
{
rmdir("../".$this->photogalleries_path."/photos/".$catpath);
rmdir("../".$this->photogalleries_path."/thumbnails/".$catpath);
}
}
// Επιστρέφει το συνολικό αριθμό φωτογραφιών που ανέβηκαν στην κατηγορία. Αν το $subcats είναι True προσμετράει και τις φωτογραφίες των υποκατηγοριών της
public function getCategoryTotalNumOfPhotos($category_id, $subcats=true, $total_photos=0)
{
$result = $this->connector->query("SELECT * FROM photogalleries WHERE category_id=$category_id");
$total_photos = $this->connector->getNumRows($result);
if ($subcats==true)
{
$result = $this->connector->query("SELECT * FROM photogalleries_cats WHERE parent_id=$category_id");
while ($myrow = $this->connector->fetchArray($result))
{
$total_photos = $total_photos + $this->getCategoryTotalNumOfPhotos($myrow["id"], $subcats, $total_photos);
}
}
return $total_photos;
}
// Επιστρέφει το μερικό path (catpath/filename) ενός τυχαίου thumbnail της κατηγορίας. Αν η κατηγορία δεν έχει δικά της άμεσα thumbnails επιλέγεται ένα thumbnail από τις υποκατηγορίες της, αν έχει.
public function getCategoryRandomThumbnail($category_id)
{
$filename = "";
$range_result = $this->connector->query("SELECT MAX(id) AS max_id , MIN(id) AS min_id FROM photogalleries WHERE category_id=$category_id");
$range_row = $this->connector->fetchArray($range_result);
$random = mt_rand($range_row["min_id"] , $range_row["max_id"]);
$result = $this->connector->query("SELECT * FROM photogalleries WHERE category_id=$category_id and id>=$random LIMIT 0,1");
if ($myrow = $this->connector->fetchArray($result))
{
$parent_category = $this->getCategoryById($category_id);
$filename = $parent_category["catpath"]."/".$myrow["filename"];
}
else
{
$result = $this->connector->query("SELECT * FROM photogalleries_cats WHERE parent_id=$category_id ORDER BY RAND()");
while ($myrow = $this->connector->fetchArray($result))
{
$filename = $this->getCategoryRandomThumbnail($myrow["id"]);
if ($filename!="")
break;
}
}
return $filename;
}
// Επιστρέφει το μερικό path (catpath/filename) $num_of_photos τυχαίων thumbnailς των επιλεγμένων κατηγοριών. Δεν ανατρέχονται αναδρομικά υποκατηγορίες.
public function getCategoriesRandomThumbnails($category_ids_array, $num_of_photos=1)
{
$criteria = "";
if (count($category_ids_array)>0)
{
foreach ($category_ids_array as $category_id)
{
if ($criteria=="")
$criteria = "WHERE category_id=".$category_id;
else
$criteria .= " or category_id=".$category_id;
}
}
$result = $this->connector->query("SELECT * FROM photogalleries ".$criteria);
// Βάλε τα αποτελέσματα σε έναν πίνακα
while ($myrow = $this->connector->fetchArray($result))
{
$photos_array[] = $myrow;
}
if ($this->connector->getNumRows($result)>0)
{
// Ανεκάτεψε τυχαία τον πίνακα και πάρε τα $num_of_photos πρώτα αποτελεσματα
shuffle($photos_array);
$final_photos_array = array_slice($photos_array, 0, $num_of_photos);
}
else
{
$final_photos_array = array();
}
return $final_photos_array;
}
// Επιστρέφει πίνακα με τα στοιχεία των πεδίων της φωτογραφίας με το δοσμένο id
public function getPhotoById($id)
{
$result = $this->connector->query("SELECT * FROM photogalleries WHERE id=$id");
$myrow = $this->connector->fetchArray($result);
return $myrow;
}
// Εισάγει μια νέα κατηγορία φωτογραφία στην κατηγορία με id $parent_id
public function insertPhoto($title, $description, $parent_id, $filename, $state, $userid)
{
$result = $this->connector->query("INSERT INTO photogalleries (title, description, category_id, filename, state, userid, created) VALUES ('$title', '$description', $parent_id, '$filename', $state, $userid, NOW())");
return $result;
}
// Ενημέρωση της κατηγορίας με το δεδομένο id
public function updatePhoto($id, $title, $description, $category_id, $state)
{
$result = $this->connector->query("UPDATE photogalleries SET title='$title', description='$description', category_id=$category_id, state=$state WHERE id=$id");
return $result;
}
// Διαγραφή φωτογραφίας με το συγκεκριμένο id
public function deletePhoto($id)
{
$myrow = $this->getPhotoById($id);
$filename = $myrow["filename"];
$myrow = $this->getCategoryById($myrow["category_id"]);
$galleryfolder = $myrow["catpath"];
$result = $this->connector->query("DELETE FROM photogalleries WHERE id=$id");
if ($result==true)
{
$this->translator->deleteAllTranslations("photogalleries", $id); // Διαγραφή μεταφράσεων
$this->deletePhotoFile($id, $galleryfolder, $filename); // Διαγραφή του αρχείου της φωτογραφίας
}
return $result;
}
// Επιστρέφει τις μεταφρασμένες εκδοχές του title και body της φωτογραφίας ή της κατηγορίας (ανάλογα με το $table) με το δοσμένο id αν υπάρχουν και αν δεν είμαστε στην default γλώσσα
public function translatedFields($id, $table=0)
{
$fields = array();
if ($table==0)
$reference_table = "photogalleries";
else
$reference_table = "photogalleries_cats";
if ($this->translator->current_lang["id"] != $this->translator->default_lang["id"]) // Αν δεν έχουμε Default γλώσσα
{
$translated_fields = $this->translator->fetchTranslatedContent($this->translator->current_lang["id"], $id, $reference_table);
foreach ($translated_fields as $field_name=>$value)
{
$fields[$field_name] = $value;
}
}
return $fields;
}
// Εναλλάσει τη κατάσταση (ενεργή/ανενεργή) της φωτογραφίας με το συγκεκριμένο id
public function togglePhotoState($id)
{
$myrow = $this->getPhotoById($id);
if ($myrow["state"]==1)
$new_state = 0;
else
$new_state = 1;
$result = $this->connector->query("UPDATE photogalleries SET state='$new_state' WHERE id=".$myrow["id"]);
return $result;
}
// Διαγράφει τα αρχεία (thumbnail και original) της φωτογραφίας στο σκληρό δίσκο με το δεδομένο id
public function deletePhotoFile($id, $galleryfolder="", $filename="")
{
if ($galleryfolder=="" or $filename=="")
{
$myrow = $this->getPhotoById($id);
$filename = $myrow["filename"];
$myrow = $this->getCategoryById($myrow["category_id"]);
$galleryfolder = $myrow["catpath"];
}
if ($filename!="" and $galleryfolder!="")
{
@unlink("../".$this->photogalleries_path."/photos/".$galleryfolder."/".$filename);
@unlink("../".$this->photogalleries_path."/thumbnails/".$galleryfolder."/".$filename);
}
}
// Μεταφέρει τα αρχεία (thumbnail και original) της φωτογραφίας με το δεδομένο id στους φάκελο της νέας κατηγορίας $new_category_id
public function movePhotoFile($id, $old_category_id, $new_category_id)
{
$photo = $this->getPhotoById($id);
$old_parent_category = $this->getCategoryById($old_category_id);
$new_parent_category = $this->getCategoryById($new_category_id);
copy("../".$this->photogalleries_path."/photos/".$old_parent_category["catpath"]."/".$photo["filename"], "../".$this->photogalleries_path."/photos/".$new_parent_category["catpath"]."/".$photo["filename"]);
copy("../".$this->photogalleries_path."/thumbnails/".$old_parent_category["catpath"]."/".$photo["filename"], "../".$this->photogalleries_path."/thumbnails/".$new_parent_category["catpath"]."/".$photo["filename"]);
unlink("../".$this->photogalleries_path."/photos/".$old_parent_category["catpath"]."/".$photo["filename"]);
unlink("../".$this->photogalleries_path."/thumbnails/".$old_parent_category["catpath"]."/".$photo["filename"]);
}
// Υπολογίζει τις νέες διαστάσεις μιας φωτογραφίας με βάση τις πρωτότυπες διαστάσεις, και τη μέθοδο προσαρμογής $resizeby (0=πλάτος και ύψος, 1=μόνο πλάτος, 2=μόνο ύψος, 3=περικοπή (crop))
public function resizedPhotoDimensions($originalwidth, $originalheight, $maxwidth, $maxheight, $resizeby)
{
if ($resizeby==0) // Προσαρμογή διαστάσεων με βάση και το πλάτος και το ύψος
{
if (($originalwidth/$originalheight)>($maxwidth/$maxheight))
{
$newwidth = $maxwidth;
$newheight = (int) ($newwidth*($originalheight/$originalwidth));
}
else
{
$newheight = $maxheight;
$newwidth = (int) ($newheight*($originalwidth/$originalheight));
}
}
else if ($resizeby==1) // Προσαρμογή διαστάσεων με βάση το πλάτος (προκείπτουν φωτογραφίες ίδιου πλάτους)
{
$newwidth = $maxwidth;
$newheight = (int) ($newwidth*($originalheight/$originalwidth));
}
else if ($resizeby==2) // Προσαρμογή διαστάσεων με βάση το ύψος (προκείπτουν φωτογραφίες ίδιου ύψους)
{
$newheight = $maxheight;
$newwidth = (int) ($newheight*($originalwidth/$originalheight));
}
else if ($resizeby==3) // Γίνετε resize αλλά και περικοπή (crop) στις δεδομένες διαστάσεις
{
$newwidth = $maxwidth;
$newheight = $maxheight;
}
return array($newwidth, $newheight);
}
// Επιστρέφει πίνακα με τα στοιχεία των φωτογραφιών με την δοσμένη γονική κατηγορία
// Αν $order_by=0 οι φωτογραφίες ταξινομούνται βάση ημερομηνίας καταχώρησης, ενώ αν $order_by=1 βάση του τίτλου
public function getPhotosByParentCategory($category_id, $order_by=0)
{
if ($order_by==0)
$order_by = "created DESC, title ASC";
else
$order_by = "title ASC, created ASC";
$photos_array = array();
$result = $this->connector->query("SELECT * FROM photogalleries WHERE category_id=$category_id ORDER BY $order_by");
while ($myrow = $this->connector->fetchArray($result))
$photos_array[] = $myrow;
return $photos_array;
}
// Δημιουργεί τον HTML κώδικα του μενού της σελιδοποίησης για τις υπεράριθμες ανά σελίδα φωτογραφίες ($reference=2) ή υποκατηγορίες ($reference=1) μιας κατηγορίας
public function buildGalleriesPagination($category_id, $gallery_id, $total_items, $start1, $start2, $reference=1)
{
if ($reference==1) // Σελιδοποίηση υποκατηγοριών
{
$items_per_page = $this->photogalleries_settings["categoriesperpage"];
$i1 = 1;
$i2 = 2;
}
else // Σελιδοποίηση φωτογραφιών
{
$items_per_page = $this->photogalleries_settings["photosperpage"];
$i1 = 2;
$i2 = 1;
}
$html = "";
if ($total_items>$items_per_page)
{
$html .= "<ul>";
if (${"start".$i1}==0)
{
$html .= '<li class="pagination_first"><span class="pagenav">« '._FIRST_PAGE.'</span></li>';
$html .= '<li class="pagination_prev"><span class="pagenav">‹ '._PREV_PAGE.'</span></li>';
}
else
{
$html .= '<li class="pagination_first"><a href="index.php?cat_id='.$category_id.'&gallery_id='.$gallery_id.'&start'.$i1.'=0&start'.$i2.'='.${"start".$i2}.'" class="pagenav" title="'._FIRST_PAGE.'">« '._FIRST_PAGE.'</a></li>';
$html .= '<li class="pagination_prev"><a href="index.php?cat_id='.$category_id.'&gallery_id='.$gallery_id.'&start'.$i1.'='.(${"start".$i1}-$items_per_page).'&start'.$i2.'='.${"start".$i2}.'" class="pagenav" title="'._PREV_PAGE.'">‹ '._PREV_PAGE.'</a></li>';
}
$displayed_pagenumbers = 8; // Το μέγιστο πλήθος των αριθμών σελίδων (pagenumbers) που θα εμφανίζονται στο μενού της σελιδοποίησης
$total_pagenumbers = ceil($total_items/$items_per_page); // Ο συνολικός αριθμός σελίδων
$current_pagenumber =${"start".$i1}/$items_per_page + 1; // Το τρέχον pagenumber
$start_pagenumber = $current_pagenumber - floor($displayed_pagenumbers/2); // Το πρώτο εμφανιζόμενο pagenumber
if ($start_pagenumber<1)
{
$start_pagenumber = 1;
}
if (($start_pagenumber + $displayed_pagenumbers) > $total_pagenumbers)
{
$stop_pagenumber = $total_pagenumbers;
if ($total_pagenumbers < $displayed_pagenumbers)
{
$start_pagenumber = 1;
}
else
{
$start_pagenumber = $total_pagenumbers - $displayed_pagenumbers + 1;
}
}
else
{
$stop_pagenumber = $start_pagenumber + $displayed_pagenumbers - 1;
}
for ($i=$start_pagenumber; $i<=$stop_pagenumber; ++$i)
{
if ((($i-1)*$items_per_page)==${"start".$i1})
$html .= '<li><span class="pagenav">'.$i.'</span></li>';
else
$html .= '<li><a href="index.php?cat_id='.$category_id.'&gallery_id='.$gallery_id.'&start'.$i1.'='.(($i-1)*$items_per_page).'&start'.$i2.'='.${"start".$i2}.'" class="pagenav" title="'.$i.'">'.$i.'</a></li>';
}
$last_page_photos_num = $total_items%$items_per_page;
if ($last_page_photos_num==0)
$last_page_photos_num = $items_per_page;
if ((${"start".$i1}+ $last_page_photos_num) == $total_items)
{
$html .= '<li class="pagination_next"><span class="pagenav">'._NEXT_PAGE.' ›</span></li>';
$html .= '<li class="pagination_last"><span class="pagenav">'._LAST_PAGE.' »</span></li>';
}
else
{
$html .= '<li class="pagination_next"><a href="index.php?cat_id='.$category_id.'&gallery_id='.$gallery_id.'&start'.$i1.'='.(${"start".$i1}+$items_per_page).'&start'.$i2.'='.${"start".$i2}.'" class="pagenav" title="'._NEXT_PAGE.'">'._NEXT_PAGE.' ›</a></li>';
$html .= '<li class="pagination_last"><a href="index.php?cat_id='.$category_id.'&gallery_id='.$gallery_id.'&start'.$i1.'='.($total_items-$last_page_photos_num).'&start'.$i2.'='.${"start".$i2}.'" class="pagenav" title="'._LAST_PAGE.'">'._LAST_PAGE.' »</a></li>';
}
$html .= "</ul>";
$html .= '<p class="counter">'._PAGE.' '.(${"start".$i1}/$items_per_page+1).' '._OF.' '.ceil($total_items/$items_per_page).'</p>';
}
return $html;
}
// Αυξάνει τα Hits της συγκεκριμένης φωτογραφίας κατά ένα
public function updatePhotoHits($id)
{
$this->connector->query("UPDATE photogalleries SET hits=hits+1 WHERE id=".$id);
}
// Συνάρτηση για resize εικόνων
// $filenamepath = το full path της αρχικής εικόνας που θα γίνει resized.
// $newprefix = πρόθεμα που προστείθεται στο αρχικό όνομα αρχείου για να αποφευχθούν διενέξεις με τα προτότυπα αρχεία, π.χ. thumbnail_$filename.
// $path = εκεί όπου θα αποθηκευτεί η νέα εικόνα.
// $newwidth = το νέο πλάτος
// $newheight = το νέο ύψος
// $quality = Η ποιότητα της νέας εικόνας
// Παράδειγμα: makeimage('images/image.jpg', 'fullimage_', 'imgs/', 250, 250, 80)
public function makeimage($filenamepath, $newprefix, $path, $newwidth, $newheight, $quality=100, $crop=false)
{
$patharr=explode("/",$filenamepath);
$num=count($patharr);
$filename=$patharr[$num-1];
// Searches image name string to select extension (everything after . )
$image_type = strstr($filename, '.');
// Switches the image create function based on file extension
switch(strtolower($image_type))
{
case '.jpg':
$source = imagecreatefromjpeg($filenamepath);
break;
case '.png':
$source = imagecreatefrompng($filenamepath);
break;
case '.gif':
$source = imagecreatefromgif($filenamepath);
break;
default:
echo("Error Invalid Image Type");
die;
break;
}
// Creates the name of the saved file
$file = $newprefix . $filename;
// Creates the path to the saved file
$fullpath = $path . $file;
// Finds size of the old file
list($width, $height) = getimagesize($filenamepath);
// Creates image with new sizes
$thumb = imagecreatetruecolor($newwidth, $newheight);
if ($crop==true) // // Resizes old image to new sizes and crop
{
if (($width/$height)>($newwidth/$newheight))
{
$cropheight = $height;
$cropwidth = $cropheight*($newwidth/$newheight);
$cropx = ($width-$cropwidth)/2;
$cropy = 0;
}
else
{
$cropwidth = $width;
$cropheight = $cropwidth*($newheight/$newwidth);
$cropx = 0;
$cropy = ($height-$cropheight)/2;
}
imagecopyresampled($thumb, $source, 0, 0, $cropx, $cropy, $newwidth, $newheight, $cropwidth, $cropheight);
}
else // Resizes old image to new sizes
{
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
// Saves image and sets quality || numerical value = quality on scale of 1-100
imagejpeg($thumb, $fullpath, $quality);
imagedestroy($source);
// Returns full filepath of image
return $fullpath;
}
}