"Administrators", "moduleUrlName" => "admins", "moduleLangName" => "admins", "moduleIcon" => "fa-users", "moduleVersion" => "3.0", "modulePages" => array( array( "pageId" => 1, "urlName" => "admins-list", "url" => "admins-list", "parent" => 0, "inMenu" => 1, "headPage" => 1, "pagination" => true ), array( "pageId" => 2, "urlName" => "admins-detail", "url" => "admins-detail", "parent" => 1, "inMenu" => 0, "headPage" => 0, "pagination" => false ), array( "pageId" => 3, "urlName" => "admins-permission", "url" => "admins-permission", "parent" => 1, "inMenu" => 0, "headPage" => 0, "pagination" => true ) ) ); ?> "Contacts", "moduleUrlName" => "contactBoxes", "moduleLangName" => "contactBoxes", "moduleIcon" => "fa-wpforms", "moduleVersion" => "1.1", "mediaSettings" => array( "contactBox" => "contactBox" ), "modulePages" => array( array( "pageId" => 1, "urlName" => "boxes-list", "url" => "boxes-list", "parent" => 0, "inMenu" => 1, "headPage" => 1 ), array( "pageId" => 2, "urlName" => "box-detail", "url" => "box-detail", "parent" => 1, "inMenu" => 0, "headPage" => 0 ) ) ); ?>connect !== null){ return $this->connect; } $this->connect = $connect; $this->createGroup($templateData); } public function __toString(){ return get_class($this); } /* ================== Application functions === */ public function getTemplate(){ return $this->template; } private function createGroup($templateData){ $object = new entityGroup($templateData["id"], $templateData["title"], $templateData["url"], $templateData["templateName"], $templateData["langShort"]); // Default entity if( isset($templateData["metaKeywords"]) && !empty($templateData["metaKeywords"]) ){ $object->metaKeywords($templateData["metaKeywords"]); } if( isset($templateData["metaTitle"]) && !empty($templateData["metaTitle"]) ){ $object->metaTitle($templateData["metaTitle"]); } if( isset($templateData["metaDescription"]) && !empty($templateData["metaDescription"]) ){ $object->metaDescription($templateData["metaDescription"]); } if( isset($templateData["allowIndex"]) && !empty($templateData["allowIndex"]) ){ $object->allowIndex($templateData["allowIndex"]); } if( isset($templateData["createdDate"]) && !empty($templateData["createdDate"]) ){ $object->createdDate($templateData["createdDate"]); } if( isset($templateData["updatedDate"]) && !empty($templateData["updatedDate"]) ){ $object->updatedDate($templateData["updatedDate"]); } if( isset($templateData["visibility"]) && !empty($templateData["visibility"]) ){ $object->visibility($templateData["visibility"]); } if( isset($templateData["orderNum"]) && !empty($templateData["orderNum"]) ){ $object->orderNum($templateData["orderNum"]); } // Category entity (table cols) if( isset($templateData["shortDesc"]) && !empty($templateData["shortDesc"]) ){ $object->shortDesc($templateData["shortDesc"]); } if( isset($templateData["description"]) && !empty($templateData["description"]) ){ $object->description($templateData["description"]); } if( isset($templateData["parentId"]) && !empty($templateData["parentId"]) ){ $object->parentId($templateData["parentId"]); } if( isset($templateData["className"]) && !empty($templateData["className"]) ){ $object->className($templateData["className"]); } if( isset($templateData["shortTag"]) && !empty($templateData["shortTag"]) ){ $object->shortTag($templateData["shortTag"]); } // Category entity (method results) if( isset($templateData["path"]) && !empty($templateData["path"]) ){ $object->path($templateData["path"]); } if( isset($templateData["images"]) && !empty($templateData["images"]) ){ $object->images($templateData["images"]); } if( isset($templateData["moduleName"]) && !empty($templateData["moduleName"]) ){ $object->moduleName($templateData["moduleName"]); } $this->template = $object; } }title = $title; $this->templateName = $templateName; parent::__construct($id); $this->langShort = $langShort; $this->url = $url; } /* ================== Object functions === */ public function shortDesc($value = null){ if( empty($value) OR !empty($this->shortDesc) ){ return $this->shortDesc; }else{ $this->shortDesc = $value; return true; } } public function description($value = null){ if( empty($value) OR !empty($this->description) ){ return $this->description; }else{ $this->description = $value; return true; } } public function path($value){ if( empty($value) OR !empty($this->path) ){ return $this->path; }else{ $this->path = $value; return true; } } public function date($value){ if( empty($value) OR !empty($this->date) ){ return $this->date; }else{ $this->date = $value; return true; } } public function time($value){ if( empty($value) OR !empty($this->time) ){ return $this->time; }else{ $this->time = $value; return true; } } public function postType($value){ if( empty($value) OR !empty($this->postType) ){ return $this->postType; }else{ $this->postType = $value; return true; } } public function authorId($value){ if( empty($value) OR !empty($this->authorId) ){ return $this->authorId; }else{ $this->authorId = (object) $value; return true; } } public function autoEnable($value){ if( empty($value) OR !empty($this->autoEnable) ){ return $this->autoEnable; }else{ $this->autoEnable = $value; return true; } } public function className($value){ if( empty($value) OR !empty($this->className) ){ return $this->className; }else{ $this->className = $value; return true; } } public function pageSidebar($value){ if( empty($value) OR !empty($this->pageSidebar) ){ return $this->pageSidebar; }else{ $this->pageSidebar = $value; return true; } } public function moduleName($value){ if( empty($value) OR !empty($this->moduleName) ){ return $this->moduleName; }else{ $this->moduleName = $value; return true; } } public function groups($value){ if( empty($value) OR !empty($this->groups) ){ return $this->groups; }else{ $this->groups = (object) $value; return true; } } public function images($value){ if( empty($value) OR !empty($this->images) ){ return $this->images; }else{ $this->images = (array) $value; return true; } } }title = $title; $this->templateName = $templateName; parent::__construct($id); $this->langShort = $langShort; $this->url = $url; } /* ================== Object functions === */ public function shortDesc($value = null){ if( empty($value) OR !empty($this->shortDesc) ){ return $this->shortDesc; }else{ $this->shortDesc = $value; return true; } } public function description($value = null){ if( empty($value) OR !empty($this->description) ){ return $this->description; }else{ $this->description = $value; return true; } } public function path($value){ if( empty($value) OR !empty($this->path) ){ return $this->path; }else{ $this->path = $value; return true; } } public function className($value){ if( empty($value) OR !empty($this->className) ){ return $this->className; }else{ $this->className = $value; return true; } } public function moduleName($value){ if( empty($value) OR !empty($this->moduleName) ){ return $this->moduleName; }else{ $this->moduleName = $value; return true; } } public function images($value){ if( empty($value) OR !empty($this->images) ){ return $this->images; }else{ $this->images = (array) $value; return true; } } }title = $title; $this->templateName = $templateName; parent::__construct($id); $this->langShort = $langShort; $this->url = $url; } /* ================== Object functions === */ public function shortDesc($value = null){ if( empty($value) OR !empty($this->shortDesc) ){ return $this->shortDesc; }else{ $this->shortDesc = $value; return true; } } public function description($value = null){ if( empty($value) OR !empty($this->description) ){ return $this->description; }else{ $this->description = $value; return true; } } public function path($value){ if( empty($value) OR !empty($this->path) ){ return $this->path; }else{ $this->path = $value; return true; } } public function className($value){ if( empty($value) OR !empty($this->className) ){ return $this->className; }else{ $this->className = $value; return true; } } public function shortTag($value){ if( empty($value) OR !empty($this->shortTag) ){ return $this->shortTag; }else{ $this->shortTag = $value; return true; } } public function moduleName($value){ if( empty($value) OR !empty($this->moduleName) ){ return $this->moduleName; }else{ $this->moduleName = $value; return true; } } public function parentId($value){ if( empty($value) OR !empty($this->parentId) ){ return $this->parentId; }else{ $this->parentId = $value; return true; } } public function images($value){ if( empty($value) OR !empty($this->images) ){ return $this->images; }else{ $this->images = (array) $value; return true; } } }createBlogPost($templateData); }else{ $this->createPost($templateData); } }else{ $this->createCategory($templateData); } } public function __toString(){ return get_class($this); } /* ================== Application functions === */ public function getTemplate(){ return $this->template; } // POST ENTITY private function createPost($templateData){ $object = new entityPost($templateData["id"], $templateData["title"], $templateData["url"], $templateData["templateName"], $templateData["langShort"]); // Default entity if( isset($templateData["metaKeywords"]) && !empty($templateData["metaKeywords"]) ){ $object->metaKeywords($templateData["metaKeywords"]); } if( isset($templateData["metaTitle"]) && !empty($templateData["metaTitle"]) ){ $object->metaTitle($templateData["metaTitle"]); } if( isset($templateData["metaDescription"]) && !empty($templateData["metaDescription"]) ){ $object->metaDescription($templateData["metaDescription"]); } if( isset($templateData["allowIndex"]) && !empty($templateData["allowIndex"]) ){ $object->allowIndex($templateData["allowIndex"]); } if( isset($templateData["urlPrefix"]) && !empty($templateData["urlPrefix"]) ){ $object->urlPrefix($templateData["urlPrefix"]); } if( isset($templateData["createdDate"]) && !empty($templateData["createdDate"]) ){ $object->createdDate($templateData["createdDate"]); } if( isset($templateData["updatedDate"]) && !empty($templateData["updatedDate"]) ){ $object->updatedDate($templateData["updatedDate"]); } if( isset($templateData["visibility"]) && !empty($templateData["visibility"]) ){ $object->visibility($templateData["visibility"]); } if( isset($templateData["orderNum"]) && !empty($templateData["orderNum"]) ){ $object->orderNum($templateData["orderNum"]); } // Post entity (table cols) if( isset($templateData["shortDesc"]) && !empty($templateData["shortDesc"]) ){ $object->shortDesc($templateData["shortDesc"]); } if( isset($templateData["description"]) && !empty($templateData["description"]) ){ $object->description($templateData["description"]); } if( isset($templateData["postType"]) && !empty($templateData["postType"]) ){ $object->postType($templateData["postType"]); } if( isset($templateData["moduleName"]) && !empty($templateData["moduleName"]) ){ $object->moduleName($templateData["moduleName"]); } if( isset($templateData["pageSidebar"]) && !empty($templateData["pageSidebar"]) ){ $object->pageSidebar($templateData["pageSidebar"]); } if( isset($templateData["autoEnable"]) && !empty($templateData["autoEnable"]) ){ $object->autoEnable($templateData["autoEnable"]); } if( isset($templateData["className"]) && !empty($templateData["className"]) ){ $object->className($templateData["className"]); } if( isset($templateData["authorId"]) && !empty($templateData["authorId"]) ){ $object->authorId($templateData["authorId"]); } // Post entity (method results) if( isset($templateData["path"]) && !empty($templateData["path"]) ){ $object->path($templateData["path"]); } if( isset($templateData["date"]) && !empty($templateData["date"]) ){ $object->date($templateData["date"]); } if( isset($templateData["time"]) && !empty($templateData["time"]) ){ $object->time($templateData["time"]); } if( isset($templateData["groups"]) && !empty($templateData["groups"]) ){ $object->groups($templateData["groups"]); } if( isset($templateData["images"]) && !empty($templateData["images"]) ){ $object->images($templateData["images"]); } $this->template = $object; } // BLOG POST ENTITY private function createBlogPost($templateData){ $object = new entityBlog($templateData["id"], $templateData["title"], $templateData["url"], $templateData["templateName"], $templateData["langShort"]); // Default entity if( isset($templateData["metaKeywords"]) && !empty($templateData["metaKeywords"]) ){ $object->metaKeywords($templateData["metaKeywords"]); } if( isset($templateData["metaTitle"]) && !empty($templateData["metaTitle"]) ){ $object->metaTitle($templateData["metaTitle"]); } if( isset($templateData["metaDescription"]) && !empty($templateData["metaDescription"]) ){ $object->metaDescription($templateData["metaDescription"]); } if( isset($templateData["allowIndex"]) && !empty($templateData["allowIndex"]) ){ $object->allowIndex($templateData["allowIndex"]); } if( isset($templateData["urlPrefix"]) && !empty($templateData["urlPrefix"]) ){ $object->urlPrefix($templateData["urlPrefix"]); } if( isset($templateData["createdDate"]) && !empty($templateData["createdDate"]) ){ $object->createdDate($templateData["createdDate"]); } if( isset($templateData["updatedDate"]) && !empty($templateData["updatedDate"]) ){ $object->updatedDate($templateData["updatedDate"]); } if( isset($templateData["visibility"]) && !empty($templateData["visibility"]) ){ $object->visibility($templateData["visibility"]); } if( isset($templateData["orderNum"]) && !empty($templateData["orderNum"]) ){ $object->orderNum($templateData["orderNum"]); } // Post entity (table cols) if( isset($templateData["shortDesc"]) && !empty($templateData["shortDesc"]) ){ $object->shortDesc($templateData["shortDesc"]); } if( isset($templateData["description"]) && !empty($templateData["description"]) ){ $object->description($templateData["description"]); } if( isset($templateData["postType"]) && !empty($templateData["postType"]) ){ $object->postType($templateData["postType"]); } if( isset($templateData["moduleName"]) && !empty($templateData["moduleName"]) ){ $object->moduleName($templateData["moduleName"]); } if( isset($templateData["pageSidebar"]) && !empty($templateData["pageSidebar"]) ){ $object->pageSidebar($templateData["pageSidebar"]); } if( isset($templateData["autoEnable"]) && !empty($templateData["autoEnable"]) ){ $object->autoEnable($templateData["autoEnable"]); } if( isset($templateData["className"]) && !empty($templateData["className"]) ){ $object->className($templateData["className"]); } if( isset($templateData["authorId"]) && !empty($templateData["authorId"]) ){ $object->authorId($templateData["authorId"]); } // Post entity (method results) if( isset($templateData["path"]) && !empty($templateData["path"]) ){ $object->path($templateData["path"]); } if( isset($templateData["date"]) && !empty($templateData["date"]) ){ $object->date($templateData["date"]); } if( isset($templateData["time"]) && !empty($templateData["time"]) ){ $object->time($templateData["time"]); } if( isset($templateData["categories"]) && !empty($templateData["categories"]) ){ $object->categories($templateData["categories"]); } if( isset($templateData["images"]) && !empty($templateData["images"]) ){ $object->images($templateData["images"]); } $this->template = $object; } private function createCategory($templateData){ $object = new entityCategory($templateData["id"], $templateData["title"], $templateData["url"], $templateData["templateName"], $templateData["langShort"]); // Default entity if( isset($templateData["metaKeywords"]) && !empty($templateData["metaKeywords"]) ){ $object->metaKeywords($templateData["metaKeywords"]); } if( isset($templateData["metaTitle"]) && !empty($templateData["metaTitle"]) ){ $object->metaTitle($templateData["metaTitle"]); } if( isset($templateData["metaDescription"]) && !empty($templateData["metaDescription"]) ){ $object->metaDescription($templateData["metaDescription"]); } if( isset($templateData["allowIndex"]) && !empty($templateData["allowIndex"]) ){ $object->allowIndex($templateData["allowIndex"]); } if( isset($templateData["createdDate"]) && !empty($templateData["createdDate"]) ){ $object->createdDate($templateData["createdDate"]); } if( isset($templateData["updatedDate"]) && !empty($templateData["updatedDate"]) ){ $object->updatedDate($templateData["updatedDate"]); } if( isset($templateData["visibility"]) && !empty($templateData["visibility"]) ){ $object->visibility($templateData["visibility"]); } if( isset($templateData["orderNum"]) && !empty($templateData["orderNum"]) ){ $object->orderNum($templateData["orderNum"]); } // Category entity (table cols) if( isset($templateData["shortDesc"]) && !empty($templateData["shortDesc"]) ){ $object->shortDesc($templateData["shortDesc"]); } if( isset($templateData["description"]) && !empty($templateData["description"]) ){ $object->description($templateData["description"]); } if( isset($templateData["parentId"]) && !empty($templateData["parentId"]) ){ $object->parentId($templateData["parentId"]); } if( isset($templateData["className"]) && !empty($templateData["className"]) ){ $object->className($templateData["className"]); } // Category entity (method results) if( isset($templateData["path"]) && !empty($templateData["path"]) ){ $object->path($templateData["path"]); } if( isset($templateData["images"]) && !empty($templateData["images"]) ){ $object->images($templateData["images"]); } if( isset($templateData["moduleName"]) && !empty($templateData["moduleName"]) ){ $object->moduleName($templateData["moduleName"]); } $this->template = $object; } }title = $title; $this->templateName = $templateName; parent::__construct($id); $this->langShort = $langShort; $this->url = $url; } /* ================== Object functions === */ public function shortDesc($value = null){ if( empty($value) OR !empty($this->shortDesc) ){ return $this->shortDesc; }else{ $this->shortDesc = $value; return true; } } public function description($value = null){ if( empty($value) OR !empty($this->description) ){ return $this->description; }else{ $this->description = $value; return true; } } public function path($value){ if( empty($value) OR !empty($this->path) ){ return $this->path; }else{ $this->path = $value; return true; } } public function date($value){ if( empty($value) OR !empty($this->date) ){ return $this->date; }else{ $this->date = $value; return true; } } public function time($value){ if( empty($value) OR !empty($this->time) ){ return $this->time; }else{ $this->time = $value; return true; } } public function postType($value){ if( empty($value) OR !empty($this->postType) ){ return $this->postType; }else{ $this->postType = $value; return true; } } public function authorId($value){ if( empty($value) OR !empty($this->authorId) ){ return $this->authorId; }else{ $this->authorId = $value; return true; } } public function autoEnable($value){ if( empty($value) OR !empty($this->autoEnable) ){ return $this->autoEnable; }else{ $this->autoEnable = $value; return true; } } public function className($value){ if( empty($value) OR !empty($this->className) ){ return $this->className; }else{ $this->className = $value; return true; } } public function pageSidebar($value){ if( empty($value) OR !empty($this->pageSidebar) ){ return $this->pageSidebar; }else{ $this->pageSidebar = $value; return true; } } public function moduleName($value){ if( empty($value) OR !empty($this->moduleName) ){ return $this->moduleName; }else{ $this->moduleName = $value; return true; } } public function categories($value){ if( empty($value) OR !empty($this->categories) ){ return $this->categories; }else{ $this->categories = (object) $value; return true; } } public function images($value){ if( empty($value) OR !empty($this->images) ){ return $this->images; }else{ $this->images = (array) $value; return true; } } } "post", 2 => "blog"]; public $translateRows = ["title", "shortDesc", "description", "metaKeywords", "metaTitle", "metaDescription", "url", "langShort"]; // Only editable fields public $dataRows = ["urlPrefix", "postType", "autorId", "autoEnable", "allowIndex", "className", "createdDate", "updatedDate", "orderNum", "visibility"]; // Only editable fields public function __construct(CMS $CMS) { if($this->connect !== null){ return $this->connect; } $this->connect = $CMS->connect; $this->lang = $CMS->lang; $this->deleteText = $CMS->deleteText; $this->hooksTable = $CMS->hooksTable; $this->postsTable = $CMS->postsTable; $this->postsTranslateTable = $CMS->postsTranslateTable; $this->categoriesTable = $CMS->categoriesTable; $this->crossTable = $CMS->crossTable; $this->bondsTable = $CMS->bondsTable; $this->anchorsTable = $CMS->anchorsTable; $this->groupsTable = $CMS->groupsTable; $this->crossGroupTable = $CMS->crossGroupTable; $this->CMS = $CMS; } public function __toString(){ return get_class($this); } /* ================== Application functions === */ // Add URL PATH and CATEGORIES to post public function reCreatePosts($allPosts){ if( !empty($allPosts) ){ $newPostArray = []; foreach($allPosts as $key => $post){ $newPostArray[$key] = $this->optimalize($post); } return $newPostArray; }else{ return $allPosts; } } public function optimalize($postInfo){ $langType = $_SESSION["languages"]["appLang"]; $templateClass = new moduleTemplates($this->connect); $allAnchors = $templateClass->getAllTemplateAnchors($langType); // Add categories $cmsGroup = new cmsGroups($this->CMS); $allPostCategories = []; $allCategories = $cmsGroup->getAllGroupsCross($postInfo["id"], $langType); if($allCategories){ foreach($allCategories as $categoryKey => $category){ $allPostCategories[$categoryKey] = $cmsGroup->getOneGroupById($category["categoryId"], $langType); $allPostCategories[$categoryKey]["path"] = '/'.$allAnchors[$category["templateName"]].'/'.$allPostCategories[$categoryKey]["url"]; $allPostCategories[$categoryKey]["images"] = $this->CMS->mediaManager->getAllRelatedImagesSerialized($category["id"], $this->CMS->mediaNameGroup, $langType, ""); } } // Add url path $optimalisedPost = $postInfo; $optimalisedPost["path"] = '/'.$allAnchors["page"].'/'.$postInfo["urlPrefix"].'-'.$postInfo["url"]; $optimalisedPost["categories"] = $allPostCategories; // Edit date $optimalisedPost["date"] = date("d. m. Y", strtotime($optimalisedPost["createdDate"])); $optimalisedPost["time"] = date("H:i:s", strtotime($optimalisedPost["createdDate"])); // Add images $allImages = $this->CMS->mediaManager->getAllRelatedImagesSerialized($postInfo["id"], $this->CMS->mediaNamePost, $langType, ""); if($allImages){ foreach($allImages as $key => $image){ if($key == 0){ $optimalisedPost["images"]["head"] = (array) $image; }else{ $optimalisedPost["images"]["other"][] = (array) $image; } } } // Return return $optimalisedPost; } /* ================== POST functions === */ // Select all posts for aplication public function getAllPosts($lang){ $sql = "SELECT translations.*, data.* FROM `{$this->postsTable}` AS data INNER JOIN `{$this->postsTranslateTable}` AS translations ON data.id = translations.associatedId WHERE translations.langShort = :langShort ORDER BY orderNum;"; $returnData = $this->connect->getQuery($sql, array("langShort" => $lang), true); return $returnData; } // Select one post for aplication public function getOnePost($postId, $lang){ $sql = "SELECT translations.*, data.* FROM `{$this->postsTable}` AS data INNER JOIN `{$this->postsTranslateTable}` AS translations ON data.id = translations.associatedId WHERE translations.langShort = :langShort AND data.id = :id;"; $returnData = $this->connect->getQuery($sql, array("id" => $postId, "langShort" => $lang), false); return $returnData; } // Create selectbox with authors for posts public function getPostAuthorToSelectBox($authorId, $allAuthors){ $option = ""; foreach ($allAuthors as $admin){ $selected = ($authorId == $admin->id) ? "selected" : ""; $option .= ''; } return $option; } // Select all posts from category - with translation public function getAllCategoriesPosts($lang, $categoryId){ $sql = " SELECT translations.*, data.* FROM `{$this->postsTable}` AS data INNER JOIN `{$this->postsTranslateTable}` AS translations ON data.id = translations.associatedId INNER JOIN `{$this->crossTable}` AS postCategories ON translations.associatedId = postCategories.postId WHERE translations.langShort = :langShort AND postCategories.categoryId = :categoryId ORDER BY data.orderNum;"; $returnData = $this->connect->getQuery($sql, array("langShort" => $lang, "categoryId" => $categoryId), true); return $returnData; } // Select all posts from groups - with translation public function getAllGroupsPosts($lang, $groupId){ $sql = " SELECT translations.*, data.* FROM `{$this->postsTable}` AS data INNER JOIN `{$this->postsTranslateTable}` AS translations ON data.id = translations.associatedId INNER JOIN `{$this->crossGroupTable}` AS postGroups ON translations.associatedId = postGroups.postId WHERE translations.langShort = :langShort AND postGroups.groupId = :groupId ORDER BY data.orderNum;"; $returnData = $this->connect->getQuery($sql, array("langShort" => $lang, "groupId" => $groupId), true); return $returnData; } }template == "blogCategory"){ $this->activeCategory = (array) $breadCrumbs[0]; } } // Add all active template anchors public function setAnchors($allAnchors){ $this->allAnchors = $allAnchors; } // Add URL PATH and CATEGORIES to post public function reCreatePosts($allPosts){ if( !empty($allPosts) ){ $newPostArray = []; foreach($allPosts as $key => $post){ $newPostArray[$key] = $this->optimalize($post); } return $newPostArray; }else{ return $allPosts; } } public function optimalize($postInfo){ $langType = $_SESSION["languages"]["appLang"]; $templateClass = new moduleTemplates($this->connect); $allAnchors = $templateClass->getAllTemplateAnchors($langType); // Add categories $cmsCategory = new cmsCategories($this->CMS); $allPostCategories = []; $allCategories = $cmsCategory->getAllCategoriesCross($postInfo["id"], $langType); if($allCategories){ foreach($allCategories as $categoryKey => $category){ $allPostCategories[$categoryKey] = $cmsCategory->getOneCategoryById($category["categoryId"], $langType); $allPostCategories[$categoryKey]["path"] = '/'.$allAnchors["blog"].'/'.$allPostCategories[$categoryKey]["url"]; $allPostCategories[$categoryKey]["images"] = $this->CMS->mediaManager->getAllRelatedImagesSerialized($category["id"], $this->CMS->mediaNameCategory, $langType, ""); } } // Add url path $optimalisedPost = $postInfo; $path = ( $this->activeCategory !== null ) ? '/'.$allAnchors["blog"].'/'.$this->activeCategory["url"] : $allPostCategories[0]["path"]; $optimalisedPost["path"] = $path.'/'.$postInfo["urlPrefix"].'-'.$postInfo["url"]; $optimalisedPost["categories"] = $allPostCategories; // Edit date $optimalisedPost["date"] = date("d. m. Y", strtotime($optimalisedPost["createdDate"])); $optimalisedPost["time"] = date("H:i:s", strtotime($optimalisedPost["createdDate"])); // Add images $allImages = $this->CMS->mediaManager->getAllRelatedImagesSerialized($postInfo["id"], $this->CMS->mediaNamePost, $langType, ""); if($allImages){ foreach($allImages as $key => $image){ if($key == 0){ $optimalisedPost["images"]["head"] = (array) $image; }else{ $optimalisedPost["images"]["other"][] = (array) $image; } } } // Return return $optimalisedPost; } /* ================== BLOG POST functions === */ // Select all blog posts public function getAllPosts($lang){ $sql = " SELECT translations.*, data.* FROM `{$this->postsTable}` AS data INNER JOIN `{$this->postsTranslateTable}` AS translations ON data.id = translations.associatedId WHERE data.postType = 2 AND translations.langShort = :langShort ORDER BY orderNum;"; $result = $this->connect->getQuery($sql, array("langShort" => $lang), true); return $this->reCreatePosts($result); } // Select all visible blog posts public function getAllVisiblePosts($lang){ $sql = " SELECT translations.*, data.* FROM `{$this->postsTable}` AS data INNER JOIN `{$this->postsTranslateTable}` AS translations ON data.id = translations.associatedId WHERE data.postType = 2 AND translations.langShort = :langShort AND data.visibility = 1 ORDER BY orderNum;"; $result = $this->connect->getQuery($sql, array("langShort" => $lang), true); return $this->reCreatePosts($result); } // Select one post public function getOnePost($postId, $lang){ $sql = " SELECT translations.*, data.* FROM `{$this->postsTable}` AS data INNER JOIN `{$this->postsTranslateTable}` AS translations ON data.id = translations.associatedId WHERE data.postType = 2 AND translations.langShort = :langShort AND data.id = :id;"; $result = $this->connect->getQuery($sql, array("id" => $postId, "langShort" => $lang), true); return $this->reCreatePosts($result); } // Select one visible post public function getOneVisiblePost($postId, $lang){ $sql = " SELECT translations.*, data.* FROM `{$this->postsTable}` AS data INNER JOIN `{$this->postsTranslateTable}` AS translations ON data.id = translations.associatedId WHERE data.postType = 2 AND translations.langShort = :langShort AND data.id = :id AND data.visibility = 1;"; $result = $this->connect->getQuery($sql, array("id" => $postId, "langShort" => $lang), true); return $this->reCreatePosts($result); } // Select all posts from category - with translation public function getAllPostsFromCategory($lang, $categoryId){ $sql = " SELECT translations.*, data.* FROM `{$this->postsTable}` AS data INNER JOIN `{$this->postsTranslateTable}` AS translations ON data.id = translations.associatedId INNER JOIN `{$this->crossTable}` AS postCategories ON translations.associatedId = postCategories.postId WHERE translations.langShort = :langShort AND postCategories.categoryId = :categoryId ORDER BY data.orderNum;"; $result = $this->connect->getQuery($sql, array("langShort" => $lang, "categoryId" => $categoryId), true); return $this->reCreatePosts($result); } // Select all visible posts from category - with translation public function getAllVisiblePostsFromCategory($lang, $categoryId){ $sql = " SELECT translations.*, data.* FROM `{$this->postsTable}` AS data INNER JOIN `{$this->postsTranslateTable}` AS translations ON data.id = translations.associatedId INNER JOIN `{$this->crossTable}` AS postCategories ON translations.associatedId = postCategories.postId WHERE translations.langShort = :langShort AND postCategories.categoryId = :categoryId AND data.visibility = 1 ORDER BY data.orderNum;"; $result = $this->connect->getQuery($sql, array("langShort" => $lang, "categoryId" => $categoryId), true); return $this->reCreatePosts($result); } }connect !== null){ return $this->connect; } $this->connect = $CMS->connect; $this->lang = $CMS->lang; $this->deleteText = $CMS->deleteText; $this->hooksTable = $CMS->hooksTable; $this->postsTable = $CMS->postsTable; $this->postsTranslateTable = $CMS->postsTranslateTable; $this->categoriesTable = $CMS->categoriesTable; $this->crossTable = $CMS->crossTable; $this->bondsTable = $CMS->bondsTable; $this->anchorsTable = $CMS->anchorsTable; $this->groupsTable = $CMS->groupsTable; $this->crossGroupTable = $CMS->crossGroupTable; $this->CMS = $CMS; $this->langEngine = new languageModule($this->connect); $this->translateEngine = new translateClass($this->langEngine); } public function __toString(){ return get_class($this); } /* ================== Application functions === */ public function optimalize($groupInfo){ $langType = $_SESSION["languages"]["appLang"]; $templateClass = new moduleTemplates($this->connect); $allAnchors = $templateClass->getAllTemplateAnchors($langType); $optimalisedGroup = $groupInfo; // Add url path $optimalisedGroup["path"] = '/'.$allAnchors[$groupInfo["templateName"]].'/'.$groupInfo["url"]; // Add images $allImages = $this->CMS->mediaManager->getAllRelatedImagesSerialized($groupInfo["id"], $this->CMS->mediaNameGroup, $langType, ""); if($allImages){ foreach($allImages as $key => $image){ if($key == 0){ $optimalisedGroup["images"]["head"] = (array) $image; }else{ $optimalisedGroup["images"]["other"][] = (array) $image; } } } // Return return $optimalisedGroup; } /* ================== HOOK functions === */ // Select all groups public function getAllGroups($langShort){ $sql = "SELECT * FROM `{$this->groupsTable}`;"; $returnData = $this->connect->getQuery($sql, null, true); $returnData = $this->translateEngine->translateResult($langShort, $returnData, $this->translateType, true); return $returnData; } // Select all visible groups public function getAllVisibleGroups($langShort){ $sql = "SELECT * FROM `{$this->groupsTable}` WHERE visibility = 1 ORDER BY orderNum;"; $returnData = $this->connect->getQuery($sql, null, true); $returnData = $this->translateEngine->translateResult($langShort, $returnData, $this->translateType, true); return $returnData; } // Select all post groups public function getAllGroupsCross($postId, $langShort){ $sql = "SELECT * FROM `{$this->crossGroupTable}` WHERE postId = :postId ORDER BY groupId;"; $returnData = $this->connect->getQuery($sql, array("postId" => $postId), true); $returnData = $this->translateEngine->translateResult($langShort, $returnData, $this->translateType, true); return $returnData; } // Select all child groups public function getAllChildGroups($id, $langShort){ $sql = "SELECT * FROM `{$this->groupsTable}` WHERE parentId = :id ORDER BY orderNum;"; $returnData = $this->connect->getQuery($sql, array("id" => $id), true); $returnData = $this->translateEngine->translateResult($langShort, $returnData, $this->translateType, true); return $returnData; } // Select all child groups public function getAllVisibleChildGroups($id, $langShort){ $sql = "SELECT * FROM `{$this->groupsTable}` WHERE visibility = 1 AND parentId = :id ORDER BY orderNum;"; $returnData = $this->connect->getQuery($sql, array("id" => $id), true); $returnData = $this->translateEngine->translateResult($langShort, $returnData, $this->translateType, true); return $returnData; } // Select one group public function getOneGroupById($id, $langShort){ $sql = "SELECT * FROM `{$this->groupsTable}` WHERE id = :id;"; $returnData = $this->connect->getQuery($sql, array("id" => $id), false); $returnData = $this->translateEngine->translateResult($langShort, $returnData, $this->translateType, false); return $returnData; } // Add all post groups public function addSelectedGroups($postId, $crossArray){ foreach($crossArray as $key => $value){ $sql = "INSERT INTO `{$this->crossGroupTable}`"; (int) $insert = $this->connect->insertQuery($sql, array("postId" => $postId, "groupId" => $value)); if($insert == 0){return false;} } return true; } // Check if URL addres exist public function checkUrlExist($url){ $sql = "SELECT * FROM `{$this->groupsTable}` WHERE url = :url;"; $returnData = $this->connect->getQuery($sql, array("url" => $url), true); $returnData = $this->translateEngine->translateResult($langShort, $returnData, $this->translateType, true); return (empty($returnData)) ? false : true; } // Check if URL is not exits public function checkUrlDuplicity($urlForCheck){ $urlCheck = $urlForCheck; $urlExist = $this->checkUrlExist($urlCheck); if($urlExist === true){ $urlCount = 1; do{ $urlCheck = $urlForCheck.'-'.$urlCount; $urlExist = $this->checkUrlExist($urlCheck); $urlCount++; }while($urlExist === true); } return $urlCheck; } // Select all post groups public function getSelectedGroups($postId, $langShort){ $allPostCategories = $this->getAllGroupsCross($postId, $langShort); $allCategories = []; foreach($allPostCategories as $postCategory){ $allCategories[] = $postCategory["groupId"]; } return $allCategories; } // Delete all post groups public function deleteSelectedGroups($postId){ $sql = "DELETE FROM `{$this->crossGroupTable}`"; $whereSql = "WHERE postId = :id"; $returnData = $this->connect->deleteQuery($sql, array("id" => $postId), $whereSql); return true; } public function selectAllGroupsAsCheckboxTree($groupId, $postId, $repeat = 0, $langShort){ $allGroups = $this->getAllChildGroups($groupId, $langShort); if($allGroups){ $groupsIds = $this->getSelectedGroups($postId, $langShort); $i = count($allGroups); $count = $i; $checkBoxTree = null; foreach ($allGroups as $key => $group){ $groupId = $group["id"]; $subGroups = $this->getAllChildGroups($groupId, $langShort); $selected = (in_array($groupId, $groupsIds)) ? "checked" : ""; if ($repeat!=0 AND $i==$count) $checkBoxTree .= ''; } }else{ $checkBoxTree = $this->lang["mod-contentEditor-groups-detail-groups-no"]; } return $checkBoxTree; } public function selectAllGroupsAsSelectBoxTree($groupPosition, $activeGroupId, $repeat = 0, $langShort){ $allGroups = $this->getAllChildGroups($groupPosition, $langShort); $selectBoxTree = null; if($allGroups){ $oneGroup = $this->getOneGroupById($activeGroupId, $langShort); foreach ($allGroups as $group){ $i = $groupPosition; $selected = ($oneGroup["parentId"] == $group["id"]) ? "selected" : ""; $selectBoxTree .= ''; $selectBoxTree .= $this->selectAllGroupsAsSelectBoxTree($group["id"], $activeGroupId, $repeat+1, $langShort); $i++; } } return $selectBoxTree; } // Delete post groups public function deletePostGroupsCross($objectId){ $sql = "DELETE FROM `{$this->groupsTable}`"; $whereSql = "WHERE groupId = :id"; $returnData = $this->connect->deleteQuery($sql, array("id" => $objectId), $whereSql); return $returnData; } // Replace child groups by parentId = 0 public function replaceChildGroups($objectId){ $sqlQuery = "UPDATE `{$this->groupsTable}`"; $whereSql = "WHERE parentId = :id"; $done = $this->connect->updateQuery($sqlQuery, array("parentId" => 0), array("id" => $objectId), $whereSql); return ($done !== true) ? false : true; } // GET options for selectbox in HOOK MENU public function getTemplateForGroup($langTableName, $lang, $selectedName){ $allContent = $this->CMS->getAllContentFromOtherTable($this->connect->injectionProtect($langTableName), $lang); $return = null; if( !empty($allContent) ){ foreach($allContent as $content){ $selected = ($selectedName == $content["templateName"]) ? "selected" : ""; $return .= ''; } } return $return; } }connect !== null){ return $this->connect; } $this->connect = $CMS->connect; $this->lang = $CMS->lang; $this->deleteText = $CMS->deleteText; $this->hooksTable = $CMS->hooksTable; $this->postsTable = $CMS->postsTable; $this->postsTranslateTable = $CMS->postsTranslateTable; $this->categoriesTable = $CMS->categoriesTable; $this->crossTable = $CMS->crossTable; $this->bondsTable = $CMS->bondsTable; $this->anchorsTable = $CMS->anchorsTable; $this->groupsTable = $CMS->groupsTable; $this->crossGroupTable = $CMS->crossGroupTable; $this->CMS = $CMS; } public function __toString(){ return get_class($this); } /* ================== HOOK functions === */ // Select all hooks for aplication public function getAllHooks(){ $sql = "SELECT * FROM `{$this->hooksTable}` ORDER BY id;"; $returnData = $this->connect->getQuery($sql, null, true); return $returnData; } // Select one hook for aplication public function getOneHook($hookId){ $sql = "SELECT * FROM `{$this->hooksTable}` WHERE id = :id;"; $returnData = $this->connect->getQuery($sql, array("id" => $hookId), false); return $returnData; } // Select all content to hook public function getAllHookContent($hookId, $parentId = 0){ $sql = "SELECT * FROM `{$this->bondsTable}` WHERE hookId = :hookId AND parentId = :parentId ORDER BY orderNum;"; $returnData = $this->connect->getQuery($sql, array("hookId" => $hookId, "parentId" => $parentId), true); return $returnData; } // Select all content child public function getAllHookContentChild($parentId){ $sql = "SELECT * FROM `{$this->bondsTable}` WHERE parentId = :parentId ORDER BY orderNum;"; $returnData = $this->connect->getQuery($sql, array("parentId" => $parentId), true); return $returnData; } // Inster content to hook public function addContentToHook($data){ $sql = "INSERT INTO `{$this->bondsTable}`"; $returnData = $this->connect->insertQuery($sql, $data); return $returnData; } // Update HOOK MENU public function updateHookMenu($id, $parentId, $orderNum){ $sql = "UPDATE `{$this->bondsTable}`"; $whereSql = "WHERE id = :id"; $values = array("parentId" => $parentId, "orderNum" => $orderNum); $returnData = $this->connect->updateQuery($sql, $values, array("id" => $id), $whereSql); return $returnData; } // Update HOOK public function updateHook($title, $hookId){ $sql = "UPDATE `{$this->hooksTable}`"; $whereSql = "WHERE id = :id"; $returnData = $this->connect->updateQuery($sql, array("title" => $title), array("id" => $hookId), $whereSql); return $returnData; } // Update HOOK MENU CHILD public function updateChild($parentId){ $allChild = $this->getAllHookContentChild($parentId); if( !empty($allChild) ){ foreach($allChild as $child){ $sql = "UPDATE `{$this->bondsTable}`"; $whereSql = "WHERE id = :id"; $values = array("parentId" => 0, "orderNum" => 0); $returnData = $this->connect->updateQuery($sql, $values, array("id" => $child["id"]), $whereSql); } } } // GET options for selectbox in HOOK MENU public function getOptionsForMenu($langTableName, $lang){ $allContent = $this->CMS->getAllContentFromOtherTable($this->connect->injectionProtect($langTableName), $lang); if( !empty($allContent) ){ foreach($allContent as $content){ echo''; } } } // Select content to hook as sortable list public function getHookContentSortable($hookId, $parentId, $repeat = 0){ $lang = $this->lang; $content = $this->getAllHookContent($hookId, $parentId); $hook = null; if( !empty($content) ){ foreach ($content as $track){ $oneContent = $this->CMS->getContentFromOtherTableById($track["objectId"], $track["dataTable"], $_SESSION["languages"]["adminLang"]); $hookInfo = $this->createHookInfo($oneContent, $track["dataTable"], []); $hookText = ''.$hookInfo["title"].' ('.$lang["mod-contentEditor-hooks-edit-content-".$hookInfo["type"]].')'; $i = 0; if ($i == 0 AND $repeat != 0) $hook .= '
    '; $hook .= '
  1. '; $hook .= '
    '; $hook .= '
    '; $hook .= ''.$hookText.''; $hook .= ''; $hook .= 'deleteText.'>'; $hook .= ' '.$lang["delete"]; $hook .= ''; $hook .= ''; $hook .= '
    '; $hook .= $this->getHookContentSortable($hookId, $track["id"], $repeat+1); $hook .= '
  2. '; $i++; if ($i > 0 AND $repeat != 0) $hook .= '
'; } } return $hook; } // Create TREE for sorting MENU HOOK public function hookTree($id, $values, $repeat, $orderedList){ $space = ""; for($i=0; $i<$repeat; $i++){ $space .=" "; } foreach($values as $value) { if( isset($value["children"]) ){ $repeat++; $this->hookTree($value["id"], $value["children"], $repeat, $orderedList); } $this->updateHookMenu($value["id"], $id, $orderedList[$value["id"]]); } } // Select content to hook as TREE public function getHookContentTree($hookId, $parentId, $repeat = 0, $activeTemplate){ $lang = $this->lang; $contentTree = []; $activeTemplate = (array) $activeTemplate; $content = $this->getAllHookContent($hookId, $parentId); if( !empty($content) ){ foreach ($content as $track){ $oneContent = $this->CMS->getContentFromOtherTableById($track["objectId"], $track["dataTable"], $_SESSION["languages"]["appLang"]); $hookInfo = $this->createHookInfo($oneContent, $track["dataTable"], $activeTemplate); $contentTree[] = ["data" => $hookInfo, "child" => $this->getHookContentTree($hookId, $track["id"], $repeat+1, $activeTemplate)]; } } return $contentTree; } // Create hook info with new URL public function createHookInfo($objectInfo, $objectTable, $activeTemplate = []){ $templatesClass = new moduleTemplates($this->connect); $templateAnchors = $templatesClass->getAllTemplateAnchors($_SESSION["languages"]["adminLang"]); // TEMPLATE if($objectTable == "templates-lang"){ $newUrl = ($objectInfo["templateName"] == "home") ? "/" : "/".$objectInfo["url"]; $type = "template"; } // CMS GROUP if($objectTable == "contenteditor-groups"){ if( empty($objectInfo["templateName"]) OR $objectInfo["allowIndex"] != 1 ){ $newUrl = "#"; // If templateName is empty or index group is not allowed - disable URL and page content }else{ $newUrl = "/".$templateAnchors[$objectInfo["templateName"]]."/".$objectInfo["url"]; } $type = "group"; } // CMS POST if($objectTable == "contenteditor-posts-lang"){ $newUrl = "/".$templateAnchors["page"]."/".$objectInfo["urlPrefix"]."-".$objectInfo["url"]; $type = "post"; } // CMS POST if($objectTable == "contenteditor-categories"){ $newUrl = "/".$templateAnchors["blog"]."/".$objectInfo["url"]; $objectInfo["templateName"] = "blog"; $type = "blogCategory"; } $className = ($objectInfo["className"]) ? $objectInfo["className"] : ""; $className .= ($activeTemplate["id"] == $objectInfo["id"] && $activeTemplate["url"] == $objectInfo["url"] && $activeTemplate["templateName"] == $objectInfo["templateName"]) ? " active" : ""; $className .= ($newUrl == "#") ? "noClick" : ""; return [ "id" => $objectInfo["id"], "title" => $objectInfo["title"], "type" => $type, "className" => $className, "url" => $newUrl, ]; } }connect !== null){ return $this->connect; } $this->connect = $CMS->connect; $this->lang = $CMS->lang; $this->deleteText = $CMS->deleteText; $this->hooksTable = $CMS->hooksTable; $this->postsTable = $CMS->postsTable; $this->postsTranslateTable = $CMS->postsTranslateTable; $this->categoriesTable = $CMS->categoriesTable; $this->crossTable = $CMS->crossTable; $this->bondsTable = $CMS->bondsTable; $this->anchorsTable = $CMS->anchorsTable; $this->groupsTable = $CMS->groupsTable; $this->crossGroupTable = $CMS->crossGroupTable; $this->CMS = $CMS; $this->langEngine = new languageModule($this->connect); $this->translateEngine = new translateClass($this->langEngine); } public function __toString(){ return get_class($this); } /* ================== Application functions === */ public function optimalize($categoryInfo){ $langType = $_SESSION["languages"]["appLang"]; $templateClass = new moduleTemplates($this->connect); $allAnchors = $templateClass->getAllTemplateAnchors($langType); $optimalisedCategory = $categoryInfo; // Add url path $optimalisedCategory["path"] = '/'.$allAnchors["blog"].'/'.$categoryInfo["url"]; // Add images $allImages = $this->CMS->mediaManager->getAllRelatedImagesSerialized($categoryInfo["id"], $this->CMS->mediaNameCategory, $langType, ""); if($allImages){ foreach($allImages as $key => $image){ if($key == 0){ $optimalisedCategory["images"]["head"] = (array) $image; }else{ $optimalisedCategory["images"]["other"][] = (array) $image; } } } // Return return $optimalisedCategory; } /* ================== HOOK functions === */ // Select all categories public function getAllCategories($langShort){ $sql = "SELECT * FROM `{$this->categoriesTable}`;"; $returnData = $this->connect->getQuery($sql, null, true); $returnData = $this->translateEngine->translateResult($langShort, $returnData, $this->translateType, true); return $returnData; } // Select all categories public function getAllVisibleCategories($langShort){ $sql = "SELECT * FROM `{$this->categoriesTable}` WHERE visibility = 1 ORDER BY orderNum;"; $returnData = $this->connect->getQuery($sql, null, true); $returnData = $this->translateEngine->translateResult($langShort, $returnData, $this->translateType, true); return $returnData; } // Select all post categories public function getAllCategoriesCross($postId, $langShort){ $sql = "SELECT * FROM `{$this->crossTable}` WHERE postId = :postId ORDER BY categoryId;"; $returnData = $this->connect->getQuery($sql, array("postId" => $postId), true); $returnData = $this->translateEngine->translateResult($langShort, $returnData, $this->translateType, true); return $returnData; } // Select all child categories public function getAllChildCategories($id, $langShort){ $sql = "SELECT * FROM `{$this->categoriesTable}` WHERE parentId = :id ORDER BY orderNum;"; $returnData = $this->connect->getQuery($sql, array("id" => $id), true); $returnData = $this->translateEngine->translateResult($langShort, $returnData, $this->translateType, true); return $returnData; } // Select all child categories public function getAllVisibleChildCategories($id, $langShort){ $sql = "SELECT * FROM `{$this->categoriesTable}` WHERE visibility = 1 AND parentId = :id ORDER BY orderNum;"; $returnData = $this->connect->getQuery($sql, array("id" => $id), true); $returnData = $this->translateEngine->translateResult($langShort, $returnData, $this->translateType, true); return $returnData; } // Select one category public function getOneCategoryById($id, $langShort){ $sql = "SELECT * FROM `{$this->categoriesTable}` WHERE id = :id;"; $returnData = $this->connect->getQuery($sql, array("id" => $id), false); $returnData = $this->translateEngine->translateResult($langShort, $returnData, $this->translateType, false); return $returnData; } // Add all post categories public function addSelectedCategories($postId, $crossArray){ foreach($crossArray as $key => $value){ $sql = "INSERT INTO `{$this->crossTable}`"; (int) $insert = $this->connect->insertQuery($sql, array("postId" => $postId, "categoryId" => $value)); if($insert == 0){return false;} } return true; } // Check if URL addres exist public function checkUrlExist($url){ $sql = "SELECT * FROM `{$this->categoriesTable}` WHERE url = :url;"; $returnData = $this->connect->getQuery($sql, array("url" => $url), true); $returnData = $this->translateEngine->translateResult($langShort, $returnData, $this->translateType, true); return (empty($returnData)) ? false : true; } // Check if URL is not exits public function checkUrlDuplicity($urlForCheck){ $urlCheck = $urlForCheck; $urlExist = $this->checkUrlExist($urlCheck); if($urlExist === true){ $urlCount = 1; do{ $urlCheck = $urlForCheck.'-'.$urlCount; $urlExist = $this->checkUrlExist($urlCheck); $urlCount++; }while($urlExist === true); } return $urlCheck; } // Select all post categories public function getSelectedCategories($postId, $langShort){ $allPostCategories = $this->getAllCategoriesCross($postId, $langShort); $allCategories = []; foreach($allPostCategories as $postCategory){ $allCategories[] = $postCategory["categoryId"]; } return $allCategories; } // Delete all post categories public function deleteSelectedCategories($postId){ $sql = "DELETE FROM `{$this->crossTable}`"; $whereSql = "WHERE postId = :id"; $returnData = $this->connect->deleteQuery($sql, array("id" => $postId), $whereSql); return true; } public function selectAllCategoriesAsCheckboxTree($categoryId, $postId, $repeat = 0, $langShort){ $allCategories = $this->getAllChildCategories($categoryId, $langShort); if($allCategories){ $categoriesIds = $this->getSelectedCategories($postId, $langShort); $i = count($allCategories); $count = $i; $checkBoxTree = null; foreach ($allCategories as $key=>$category){ $categoryId = $category["id"]; $subCategories = $this->getAllChildCategories($categoryId, $langShort); $selected = (in_array($categoryId, $categoriesIds)) ? "checked" : ""; if ($repeat!=0 AND $i==$count) $checkBoxTree .= ''; } }else{ $checkBoxTree = $this->lang["mod-contentEditor-posts-detail-categories-no"]; } return $checkBoxTree; } public function selectAllCategoriesAsSelectBoxTree($categoryPosition, $activeCategoryId, $repeat = 0, $langShort){ $allCategories = $this->getAllChildCategories($categoryPosition, $langShort); $selectBoxTree = null; if($allCategories){ $oneCategory = $this->getOneCategoryById($activeCategoryId, $langShort); foreach ($allCategories as $category){ $i = $categoryPosition; $selected = ($oneCategory["parentId"] == $category["id"]) ? "selected" : ""; $selectBoxTree .= ''; $selectBoxTree .= $this->selectAllCategoriesAsSelectBoxTree($category["id"], $activeCategoryId, $repeat+1, $langShort); $i++; } } return $selectBoxTree; } // Delete post categories public function deletePostCategoriesCross($objectId){ $sql = "DELETE FROM `{$this->categoriesTable}`"; $whereSql = "WHERE categoryId = :id"; $returnData = $this->connect->deleteQuery($sql, array("id" => $objectId), $whereSql); return $returnData; } // Replace child categories by parentId = 0 public function replaceChildCategories($objectId){ $sqlQuery = "UPDATE `{$this->categoriesTable}`"; $whereSql = "WHERE parentId = :id"; $done = $this->connect->updateQuery($sqlQuery, array("parentId" => 0), array("id" => $objectId), $whereSql); return ($done !== true) ? false : true; } }connect !== null){ return $this->connect; } $this->connect = $connect; if($activeLang !== null){ $this->lang = $activeLang; $this->deleteText = "confirm-head='{$this->lang["confirm-delete-head"]}' confirm-text='{$this->lang["confirm-delete-text"]}' confirm-yes='{$this->lang["confirm-delete-yes"]}' confirm-no='{$this->lang["confirm-delete-no"]}'"; } $this->mediaManager = new mediaManager($this->connect); $this->mediaLoader = new mediaLoad($this->mediaManager); $this->postsTable = databaseTables::getTable("contentEditor", "postTable"); $this->postsTranslateTable = databaseTables::getTable("contentEditor", "postTableLang"); $this->categoriesTable = databaseTables::getTable("contentEditor", "categoryTable"); $this->crossTable = databaseTables::getTable("contentEditor", "crossCategoryTable"); $this->groupsTable = databaseTables::getTable("contentEditor", "groupTable"); $this->crossGroupTable = databaseTables::getTable("contentEditor", "crossGroupTable"); $this->hooksTable = databaseTables::getTable("contentEditor", "hookTable"); $this->bondsTable = databaseTables::getTable("contentEditor", "bondTable"); $this->anchorsTable = databaseTables::getTable("contentEditor", "anchorTable"); } public function __toString(){ return get_class($this); } /* ================== BASIC functions === */ // Delete content by AJAX from SOME TABLE public function deleteAjaxContent($objectId, $table){ $sql = "DELETE FROM `{$table}`"; $whereSql = "WHERE id = :id"; $returnData = $this->connect->deleteQuery($sql, array("id" => $objectId), $whereSql); return $returnData; } // Delete content by AJAX from SOME TABLE public function deleteAjaxContentTranslate($objectId, $table){ $sql = "DELETE FROM `{$table}`"; $whereSql = "WHERE associatedId = :id"; $returnData = $this->connect->deleteQuery($sql, array("id" => $objectId), $whereSql); return $returnData; } // Delete translations by AJAX from SOME TABLE public function deleteAjaxTranslate($objectId ,$objectType, $table){ $sql = "DELETE FROM `{$table}`"; $whereSql = "WHERE objectId = :id AND objectType = :type"; $returnData = $this->connect->deleteQuery($sql, array("id" => $objectId, "type" => $objectType), $whereSql); return $returnData; } // Visibility control by AJAX from SOME TABLE public function setVisibilityObject($objectId, $table){ $sql = "SELECT * FROM `{$table}` WHERE id = :id;"; $contentData = $this->connect->getQuery($sql, array("id" => $objectId), false); if( isset($contentData["visibility"]) ){ $setVisibility = ($contentData["visibility"] == 0) ? 1 : 0; }else{ return false; } $sqlQuery = "UPDATE `{$table}`"; $whereSql = "WHERE id = :id"; $done = $this->connect->updateQuery($sqlQuery, array("visibility" => $setVisibility), array("id" => $objectId), $whereSql); return ($done !== true) ? false : $setVisibility; } // OrderNums edit by AJAX from SOME TABLE public function setOrderNums($objectId, $table, $orderNum){ $sqlQuery = "UPDATE `{$table}`"; $whereSql = "WHERE id = :id"; $done = $this->connect->updateQuery($sqlQuery, array("orderNum" => $orderNum), array("id" => $objectId), $whereSql); return ($done !== true) ? false : $setVisibility; } // ONE RESULT from OTHER MODULE TABLE - support multilanguage public function getContentFromOtherTableById($objectId, $langTableName, $lang){ $dataTableName = ( strpos($langTableName, "-lang") !== false ) ? str_replace("-lang", "", $langTableName) : null; // Create two tables if -lang prefix exist (tableName and tableName-lang) if($dataTableName !== null){ $sql = "SELECT * FROM `{$dataTableName}` WHERE id = :id;"; $contentData = $this->connect->getQuery($sql, array("id" => $objectId), false); $sql = "SELECT * FROM `{$langTableName}` WHERE associatedId = :id AND langShort = :langShort;"; $langData = $this->connect->getQuery($sql, array("id" => $objectId, "langShort" => $lang), false); unset($langData["id"]); $returnData = array_merge($contentData, $langData); }else{ $sql = "SELECT * FROM `{$langTableName}` WHERE id = :id;"; $returnData = $this->connect->getQuery($sql, array("id" => $objectId), false); } return $returnData; } // ALL RESULTS from OTHER MODULE TABLE - support multilanguage public function getAllContentFromOtherTable($langTableName, $lang){ $dataTableName = ( strpos($langTableName, "-lang") !== false ) ? str_replace("-lang", "", $langTableName) : null; // Create two tables if -lang prefix exist (tableName and tableName-lang) if($dataTableName !== null){ $returnData = []; $sql = "SELECT * FROM `{$dataTableName}`;"; $contentData = $this->connect->getQuery($sql, null, true); if($contentData){ foreach($contentData as $key => $content){ $sql = "SELECT * FROM `{$langTableName}` WHERE associatedId = :id AND langShort = :langShort;"; $langData = $this->connect->getQuery($sql, array("id" => $content["id"], "langShort" => $lang), false); unset($langData["id"]); $returnData[$key] = array_merge($content, $langData); } } }else{ $sql = "SELECT * FROM `{$langTableName}`;"; $returnData = $this->connect->getQuery($sql, null, true); } return $returnData; } } "contentEditor", "moduleUrlName" => "contentEditor", "moduleLangName" => "contentEditor", "moduleIcon" => "fa-files-o", "moduleVersion" => "3.4", "requiredModules" => array( array("moduleName" => "templates") ), "mediaSettings" => array( "post" => "post", "postCategories" => "postCategories", "postGroup" => "postGroups" ), "modulePages" => array( array( "pageId" => 1, "urlName" => "content-hooks", "url" => "content-hooks", "parent" => 0, "inMenu" => 1, "headPage" => 1 ), array( "pageId" => 2, "urlName" => "edit-hook", "url" => "edit-hook", "parent" => 1, "inMenu" => 0, "headPage" => 0 ), array( "pageId" => 3, "urlName" => "posts", "url" => "posts", "parent" => 1, "inMenu" => 1, "headPage" => 0 ), array( "pageId" => 4, "urlName" => "post-detail", "url" => "post-detail", "parent" => 3, "inMenu" => 0, "headPage" => 0 ), array( "pageId" => 5, "urlName" => "categories", "url" => "categories", "parent" => 1, "inMenu" => 1, "headPage" => 0 ), array( "pageId" => 6, "urlName" => "category-detail", "url" => "category-detail", "parent" => 5, "inMenu" => 0, "headPage" => 0 ), array( "pageId" => 7, "urlName" => "groups", "url" => "groups", "parent" => 1, "inMenu" => 1, "headPage" => 0 ), array( "pageId" => 8, "urlName" => "group-detail", "url" => "group-detail", "parent" => 7, "inMenu" => 0, "headPage" => 0 ), array( "pageId" => 9, "urlName" => "content-settings", "url" => "content-settings", "parent" => 0, "inMenu" => 1, "headPage" => 0 ) ) ); ?>connect !== null){ return $this->connect; } $this->connect = $emailTemplates->connect; $this->table = $emailTemplates->headTableName; $this->lang = $emailTemplates->lang; $this->emailTemplates = $emailTemplates; } public function __toString(){ return get_class($this); } /* ================== EMAIL PARTS CREATOR === */ // Create discount info public function addDiscountInfo($orderInfo){ if($orderInfo["discount"] != 0){ $emailTemplate = ' '.$this->lang["mod-emailTemplates-emailTemplate-slevaZbozi"].' - '.$orderInfo["discount"].' '; }else{ $emailTemplate = ""; } return $emailTemplate; } // Create delivery mothod detail public function addDelivery($orderInfo){ $emailTemplate =' '.$this->lang["mod-emailTemplates-emailTemplate-dopravce"].' '.$orderInfo["deliveryTitle"].' '.$orderInfo["deliveryPrice"].' '.$this->lang["currency"].' '; return $emailTemplate; } // Create payment mothod detail public function addPayment($orderInfo){ $emailTemplate =' '.$this->lang["mod-emailTemplates-emailTemplate-platba"].' '.$orderInfo["paymentTitle"].' '.$orderInfo["paymentPrice"].' '.$this->lang["currency"].' '; return $emailTemplate; } // Wrapping row for details public function wrapAddressRow($placeholder, $value){ $wrap = ''; $wrap .= ''.$this->lang["mod-emailTemplates-emailTemplate-".$placeholder].':'; $wrap .= ''.$value.''; $wrap .= ''; return $wrap; } // Create user delivery info - MUST WORK ON IT! public function addUserInfo($orderInfo){ $emailUserInfo = array(); $emailTemplate = null; if($orderInfo["companyName"]){ $emailTemplate = $this->wrapAddressRow("company", $orderInfo["companyName"]); $emailTemplate .= ($orderInfo["companyIdentNum"]) ? $this->wrapAddressRow("ico", $orderInfo["companyIdentNum"]) : ""; $emailTemplate .= ($orderInfo["companyTax"]) ? $this->wrapAddressRow("dic", $orderInfo["companyTax"]) : ""; } $invoice .= $this->wrapAddressRow("name", $orderInfo["invoiceName"]); $invoice .= $this->wrapAddressRow("surname", $orderInfo["invoiceSurname"]); $invoice .= $this->wrapAddressRow("address", ($orderInfo["invoiceStreet"].", ".$orderInfo["invoiceCity"].", ".$orderInfo["invoiceZip"]) ); $invoice .= $this->wrapAddressRow("email", $orderInfo["invoiceEmail"]); $invoice .= $this->wrapAddressRow("phone", $orderInfo["invoicePhone"]); /* $deliveryName = ($orderInfo["deliveryName"]) ? $orderInfo["deliveryName"] : $orderInfo["invoiceName"]; $deliverySurname = ($orderInfo["deliverySurname"]) ? $orderInfo["deliverySurname"] : $orderInfo["invoiceSurname"]; $deliveryStreet = ($orderInfo["deliveryStreet"]) ? $orderInfo["deliveryStreet"] : $orderInfo["invoiceStreet"]; $deliveryCity = ($orderInfo["deliveryCity"]) ? $orderInfo["deliveryCity"] : $orderInfo["invoiceCity"]; $deliveryPSC = ($orderInfo["deliveryZip"]) ? $orderInfo["deliveryZip"] : $orderInfo["invoiceZip"]; $deliveryMethod = moduleDelivery::getOneDeliveryById($orderInfo["deliveryId"]); if( !empty($orderInfo["deliveryInfo"]) ){ $deliveryName = $orderInfo["deliveryTitle"]; $deliveryInfo = moduleDelivery::getOneBrancheById($orderInfo["deliveryInfo"]); $delivery = $this->wrapAddressRow("name", $deliveryName); $delivery .= $this->wrapAddressRow("address", ($deliveryInfo["title"]) ); }elseif( $deliveryMethod["pickUp"] == 1 && $deliveryMethod["pobocky"] == 0 ){ $delivery = $this->wrapAddressRow("address", $orderInfo["dopravce_nazev"]); }else{ $delivery = $this->wrapAddressRow("name", $deliveryName); $delivery .= $this->wrapAddressRow("surname", $deliverySurname); $delivery .= $this->wrapAddressRow("address", ($deliveryStreet.", ".$deliveryCity.", ".$deliveryPSC) ); } $invoiceTable = ''; $invoiceTable .= $invoice; $invoiceTable .= '
'; $deliveryTable = ''; $deliveryTable .= $delivery; $deliveryTable .= '
'; */ return array("invoiceDetail" => $invoiceTable, "deliveryDetail" => $deliveryTable); } // Create products - MUST WORK ON IT public function addProducts($allProducts){ $lang = $this->lang; foreach($allProducts as $product){ $atributy_vyrobku = ""; $atributy = explode("[",$product["atributy"]); unset($atributy[0]); $attr = count($atributy); $pom=1; foreach($atributy as $atribut){ $atribut = str_replace("]","",$atribut); $list = explode(",",$atribut); $atributy_vyrobku .= $list[0].": ".$list[1]; if($attr!=$pom){$atributy_vyrobku.=", ";} $pom++; } $allAnchors = moduleTemplates::getAllTemplateAnchors(); $productUrl = $lang["page_url"]."/".$allAnchors["produkt"]."/".$product["url"]; $emailTemplate .= ''; $emailTemplate .= ''; $emailTemplate .= ''.$product["nazev_zbozi"].''; $emailTemplate .= ''.$product["mnozstvi"].' '.$lang["emails_module-emailTemplate-kus"].''; if($atributy_vyrobku){ $emailTemplate .= ''.$atributy_vyrobku.''; } $emailTemplate .= ''.$product["cena_s_DPH"].' '.$lang["currency"].''; $emailTemplate .= ''; $emailTemplate .= ''; $emailTemplate .= ''.($product["mnozstvi"]*$product["cena_s_DPH"]).' '.$lang["currency"].''; $emailTemplate .= ''; $emailTemplate .= ''; /*$emailTemplate .= ''; $emailTemplate .= ''; $emailTemplate .= '';*/ } return $emailTemplate; } // Create campaigns detail - MUST WORK ON IT public function addCampaignDetailInfo($orderInfo){ $lang = $this->lang; if($orderInfo["slevaKampanTyp"] > 0){ $emailTemplate = ' '.$lang["module_campaign-front-cart-globalniSlevy"].' - '.$orderInfo["slevaKampanCena_s"].' '.$lang["currency"].' '; }else{ $emailTemplate = ""; } return $emailTemplate; } /* ================== EMAIL SENDING - classic === */ public function sendEmailTemplate($allSettings, $data, $FILES, $emailKey, $emailRecipient){ $emailTemplate = new PHPMailer(); $emailTemplate->IsHTML(true); $emailTemplate->From = $allSettings["primaryEmail"]; $emailTemplate->FromName = $this->emailSign; $emailTemplate->Subject = $this->emailTemplates->getEmailSubject($data, $emailKey); $emailTemplate->Body = $this->emailTemplates->getEmailTemplate($data, $emailKey); $emailToUser = $this->emailTemplates->getMultipleAdminEmails($emailRecipient); foreach($emailToUser as $addEmail){ $emailTemplate->AddAddress($addEmail); } if( !empty($FILES) ){ foreach($FILES as $file_to_send){ $emailTemplate->AddAttachment($file_to_send["tmp_name"], $file_to_send['name']); } } $emailTemplate->Send(); } /* ================== EMAIL SENDING - eshop === */ public function sendEshopEmailTemplate($allSettings, $orderInfo, $allProducts, $emailKey, $emailRecipient){ $orderCompleted = ''; $orderCompleted .= $this->addProducts($allProducts); $orderCompleted .= $this->addCampaignDetailInfo($orderInfo); $orderCompleted .= $this->addDiscountInfo($orderInfo); $orderCompleted .= $this->addDelivery($orderInfo); $orderCompleted .= $this->addPayment($orderInfo); $orderCompleted .= $this->addPlacing($orderInfo); $orderCompleted .= '
'; $orderInfoArray = array( "orderId" => $orderInfo["orderId"], "createdDate" => $orderInfo["createdDate"], "message" => $orderInfo["message"], "totalPrice" => $orderInfo["totalPriceTax"].' '.$this->lang["currency"], "orderSummary" => $orderCompleted ); $userInfo = $this->addUserInfo($orderInfo); $orderArray = array_merge($userInfo, $orderInfoArray); $emailTemplate = new PHPMailer(); $emailTemplate->IsHTML(true); $emailTemplate->From = $allSettings["primaryEmail"]; $emailTemplate->FromName = $this->emailSign; $emailTemplate->Subject = $this->emailTemplates->getEmailSubject($orderArray, $emailKey); $emailTemplate->Body = $this->emailTemplates->getEmailTemplate($orderArray, $emailKey); $emailToUser = $this->emailTemplates->getMultipleAdminEmails($emailRecipient); foreach($emailToUser as $addEmail){ $emailTemplate->AddAddress($addEmail); } $emailTemplate->Send(); } public function sendChangeOrderEmail($allSettings, $orderStatus, $orderInfo, $emailKey, $emailRecipient){ $orderCompleted = ''; $orderCompleted .= $this->addProducts($allProducts); $orderCompleted .= $this->addCampaignDetailInfo($orderInfo[0]); $orderCompleted .= $this->addDiscountInfo($orderInfo[0]); $orderCompleted .= $this->addDelivery($orderInfo[0]); $orderCompleted .= $this->addPayment($orderInfo[0]); $orderCompleted .= $this->addPlacing($orderInfo[0]); $orderCompleted .= '
'; $orderInfoArray = array( "orderId" => $orderInfo[0]["orderId"], "createdDate" => $orderInfo[0]["createdDate"], "message" => $orderInfo[0]["message"], "totalPrice" => $orderInfo[0]["totalPriceTax"].' '.$this->lang["currency"], "orderSummary" => $orderCompleted, "orderStatus" => $orderStatus["title"], "orderStatusTitle" => $orderStatus["emailTemplateTitle"], "orderStatusText" => $orderStatus["emailTemplateText"] ); $userInfo = $this->addUserInfo($orderInfo[0]); $orderArray = array_merge($userInfo, $orderInfoArray); $emailTemplate = new PHPMailer(); $emailTemplate->IsHTML(true); $emailTemplate->From = $allSettings["primaryEmail"]; $emailTemplate->FromName = $this->emailSign; $emailTemplate->Subject = $this->emailTemplates->getEmailSubject($orderArray, $emailKey); $emailTemplate->Body = $this->emailTemplates->getEmailTemplate($orderArray, $emailKey); $emailToUser = $this->emailTemplates->getMultipleAdminEmails($emailRecipient); foreach($emailToUser as $addEmail){ $emailTemplate->AddAddress($addEmail); } $emailTemplate->Send(); } /* ================== EMAIL SENDING - system === */ // Vybrání všeho z tabulky XXX public function sendForgotEmail($allSettings, $data, $allAnchors, $emailKey, $emailRecipient){ $forgotURL = 'http://'.$this->pageURL.'/'.$allAnchors["forgotten-password"].'?value='.$data["code"]; $forgotURLAnchor = ''.$forgotURL.''; $emailData = array( "email" => $data["invoiceName"], "code" => $forgotURL ); $emailTemplate = new PHPMailer(); $emailTemplate->IsHTML(true); $emailTemplate->From = $allSettings["primaryEmail"]; $emailTemplate->FromName = $this->emailSign; $emailTemplate->Subject = $this->emailTemplates->getEmailSubject($emailData, $emailKey); $emailTemplate->Body = $this->emailTemplates->getEmailTemplate($emailData, $emailKey); $emailToUser = $this->emailTemplates->getMultipleAdminEmails($emailRecipient); foreach($emailToUser as $addEmail){ $emailTemplate->AddAddress($addEmail); } $emailTemplate->Send(); } }connect !== null){ return $this->connect; } $this->connect = $connect; $this->lang = $lang; $this->headTableName = databaseTables::getTable("emailTemplates", "emailTable"); } public function __toString(){ return get_class($this); } /* ================== MODULE FUNCTIONS === */ // Vybrání jednoho z tabulky XXX public function selectOneFrom($id){ $sql = "SELECT * FROM `{$this->headTableName}` WHERE id = :id"; $data = $this->connect->getQuery($sql, array("id" => $id), false); return $data; } // Vybrání všeho z tabulky XXX public function selectAllFrom(){ $sql = "SELECT * FROM `{$this->headTableName}`"; $data = $this->connect->getQuery($sql, null, true); return $data; } // Vybrání všeho z tabulky XXX public function selectAllTemplates(){ $sql = "SELECT emailKey FROM `{$this->headTableName}`"; $data = $this->connect->getQuery($sql, null, true); return $data; } public function selectEmailTemplate($emailKey){ $sql = "SELECT * FROM `{$this->headTableName}` WHERE emailKey = :emailKey"; $data = $this->connect->getQuery($sql, array("emailKey" => $emailKey), false); return $data; } /* ============ FUNKCE ============== */ public function getEmailTemplate($variablesArr, $templateKey){ $template = $this->selectEmailTemplate($templateKey); $templateHTML = $this->decodeImagePaths($this->decodeTemplate($template["emailContent"], $variablesArr), $variablesArr); return $templateHTML; } public function getEmailSubject($variablesArr, $templateKey){ $template = $this->selectEmailTemplate($templateKey); $subjectHTML = $this->decodeTemplate($template["emailSubject"], $variablesArr); return $subjectHTML; } public function getMultipleAdminEmails($emailTo){ if (strpos($emailTo, ',') !== false) { $emails = explode(',', $emailTo); }else{ $emails = array($emailTo); } return $emails; } private function decodeTemplate($HTML, $variablesArr){ foreach($variablesArr as $key => $value) { $HTML = str_replace("{".$key."}", $value, $HTML); } // V případě, že některé proměnné nebyly nahrazeny $HTML = preg_replace('/' . preg_quote('{') .'.*?'.preg_quote('}') . '/', '', $HTML); return $HTML; } private function decodeImagePaths($HTML, $variablesArr){ $HTML = str_replace("/emailTemplates/images/", 'http://'.$_SERVER["SERVER_NAME"].'/emailTemplates/images/', $HTML); return $HTML; } public function editMailTemplate($id, $emailData){ $sql = "UPDATE `{$this->headTableName}`"; $whereSql = "WHERE id = :id"; $returnData = $this->connect->updateQuery($sql, $emailData, array("id" => $id), $whereSql); return true; } } "Emailové šablony", "moduleUrlName" => "emailTemplates", "moduleLangName" => "emailTemplates", "moduleIcon" => "fa-envelope-o", "moduleVersion" => "2.0", "modulePages" => array( array( "pageId" => 1, "urlName" => "emails-content", "url" => "emails-content", "parent" => 0, "inMenu" => 1, "headPage" => 1 ) ) ); ?>lang = $langFile; } // SETTINGS - For pagination public $pageLimit = 30; public $pageLimitFront = 12; // FILTER TYPES - Must have translation in language files and exist in frontend folder! public $filterTypes = array( "filterClassic" => "filter", "filterPrice" => "filterPrice", "filterSymptoms" => "filterSymptoms", "filterTags" => "filterTags", "filterParams" => "filterParams" // MUST BE LAST! ); // PARAMETER TYPES - Must be same as in database (paramsTableName)! public $paramStructure = array( "id" => 0, "filterId" => 0, "paramType" => 0, "paramName" => "", "paramIcon" => "", "paramHelp" => "" ); // PAGINATION - Front and Back public function getPagination($type, $pocetVysledku, $pagi, $ajax, $requestUrl){ if(is_numeric($type)){ if($type == 0){ $filterPageLimit = $this->pageLimit; }else{ $filterPageLimit = $type; } }else{ $filterPageLimit = $this->pageLimitFront; } if($pocetVysledku > $filterPageLimit){ if($pocetVysledku % $filterPageLimit == 0){ $paginace = ceil($pocetVysledku / $filterPageLimit); }elseif($pocetVysledku < $filterPageLimit){ $paginace = 1; }else{ $paginace = ceil($pocetVysledku / $filterPageLimit); } $aktiv_page = $pagi; if($ajax === true && $aktiv_page+1 < $paginace){ echo ''.$this->lang["mod-filter-frontFilter-loadMore"].''; } echo ''; if($aktiv_page > 0){ echo ''; } for($i=0;$i<$paginace;$i++){ $page_name = $i+1; $act = ($aktiv_page == $i) ? "active" : ""; $paginationTemplate = ''.$page_name.''; $last = round($paginace); if($paginace > 5){ if( $i==0 ){ echo $paginationTemplate; if( !(($aktiv_page - 2) <=0) ){ echo ". . ."; } }elseif( $i+1 == $last ){ if( !(($aktiv_page + 2) >=$last) ){ echo ". . ."; } echo $paginationTemplate; }elseif( $i==($aktiv_page - 1) OR $i==$aktiv_page OR $i==($aktiv_page + 1) ){ echo $paginationTemplate; }else{ continue; } }else{ echo $paginationTemplate; } } if($aktiv_page+1 < $paginace){ echo ''; } echo ''; } } // PAGINATION LINKS - Generate URL for anchor filtrations public function easyFiltrLink($actual_link,$filtr,$url_value){ // Vytvoření proměnných $parts = parse_url($actual_link); $skip = false; $queryParams = array(); if( isset($parts['query']) ){ parse_str($parts['query'], $queryParams); } // Odstranění aktivního parametru unset($queryParams[$filtr]); if($filtr != 'page'){ unset($queryParams['page']); } // Odstranění checkbox parametru if( strpos($filtr, '[') !== false ){ $arrayedFilter = explode("[",$filtr); $arrayedFilter = array("key" => $arrayedFilter[0],"name" => str_replace("]","",$arrayedFilter[1]),"value" => $url_value ); if( isset($queryParams[$arrayedFilter["key"]]) AND isset($queryParams[$arrayedFilter["key"]][$arrayedFilter["name"]]) ){ if( $queryParams[$arrayedFilter["key"]][$arrayedFilter["name"]] == "true" ){ unset($queryParams[$arrayedFilter["key"]][$arrayedFilter["name"]]); $skip = true; } if( empty($queryParams[$arrayedFilter["key"]]) ){ unset($queryParams[$arrayedFilter["key"]]); } } } // Seskupení pole parametrů $queryString = http_build_query($queryParams); // Vygenerování URL if($queryString){ $url = $parts['path'] . '?' . $queryString; if($url_value!="default" AND $skip === false){ $url .= "&".$filtr."=".$url_value; } }else{ $url = ""; if($url_value!="default" AND $skip === false){ $url .= "?".$filtr."=".$url_value; }else{ $url = $parts['path']; } } return $url; } // LIMITS - Price limit for price slider filter public static function getProductLimitsForPriceSlider($produktyKeKontrole){ $limity = array(); if($produktyKeKontrole){ // Nejnižší cena usort($produktyKeKontrole, function($a, $b) { return $a['cena_filtr'] > $b['cena_filtr']; }); $limity["limitMinimum"] = $produktyKeKontrole[0]['cena_filtr']; // Nejvyšší cena usort($produktyKeKontrole, function($a, $b) { return $a['cena_filtr'] < $b['cena_filtr']; }); $limity["limitMaximum"] = $produktyKeKontrole[0]['cena_filtr']; }else{ $limity["limitMinimum"] = 0; $limity["limitMaximum"] = 0; } return $limity; } // FILTRATION - Get filtered results public static function getFiltredResults($vsechnyProdukty, $GET, $pageStart, $pageLimit){ // Zachycení hodnot pro filtr if($GET){ $vyfiltrovaneVysledky = $filtry = array(); foreach ($GET as $key => $value) { if($key == "sort"){ $sort = $value; }elseif( (strpos($key, 'param') !== false) ){ $keyName = str_replace("param","",$key); $parameters[$keyName][] = $value; }else{ $filtry[$key] = $value; } } } $vyfiltrovaneVysledky = $vsechnyProdukty; // FILTER - Parametric if( isset($parameters) ){ $pomocnePole = array(); /* // RADIOBUTTON foreach( $vyfiltrovaneVysledky as $produkt ){ // If product have parametric values if( !empty($produkt["filterOptions"]) ){ foreach($produkt["filterOptions"] as $paramName => $paramValues){ // If parameter is active in filter if( isset($parameters[$paramName]) ){ // If value of parameter is active if( isset($parameters[$paramName][0][$paramValues]) ){ /$pomocnePole[] = $produkt; } } } } }*/ // CHECKBOX foreach( $vyfiltrovaneVysledky as $produkt ){ // If product have parametric values if( !empty($produkt["filterOptions"]) ){ foreach($produkt["filterOptions"] as $paramName => $paramValues){ // If parameter is active in filter ($paramName) if( isset($parameters[$paramName]) ){ // If value of parameter is active ($parameters[$paramName]) foreach($parameters[$paramName][0] as $searchedParamValue => $true){ // If parameter value is in product settings ($searchedParamValue) if( in_array($searchedParamValue,$produkt["filterOptions"][$paramName]) ){ $pomocnePole[] = $produkt; break; } } } } } } $vyfiltrovaneVysledky = $pomocnePole; } // FILTER - Symptoms if( isset($filtry["priznak"]) ){ $pomocnePole = array(); foreach( $filtry["priznak"] as $key => $true ){ $podminkaPriznaku = "priznak_".$key; foreach( $vyfiltrovaneVysledky as $produkt ){ if ( $produkt[$podminkaPriznaku] == 1 ){ $pomocnePole[] = $produkt; } } } $vyfiltrovaneVysledky = $pomocnePole; } // FILTER - Room tags - TOMR.cz if( isset($filtry["tag"]) ){ $pomocnePole = array(); foreach( $filtry["tag"] as $idStitku => $true ){ foreach( $vyfiltrovaneVysledky as $produkt ){ $poleStitku = explode(",",$produkt["stitky"]); if ( in_array($idStitku, $poleStitku) ){ $pomocnePole[] = $produkt; } } } $vyfiltrovaneVysledky = $pomocnePole; } // FILTER - Price if( isset($filtry["min"]) && isset($filtry["max"]) ){ $pomocnePole = array(); foreach( $vyfiltrovaneVysledky as $produkt ){ if ( $produkt["cena_filtr"] >= $filtry["min"] && $produkt["cena_filtr"] <= $filtry["max"] ){ $pomocnePole[] = $produkt; } } //$vyfiltrovaneVysledky = ( empty($pomocnePole) ) ? $vyfiltrovaneVysledky : $pomocnePole; $vyfiltrovaneVysledky = $pomocnePole; } // FILTER - Sorting if($sort){ if($sort=="name-desc"){ usort($vyfiltrovaneVysledky, function($a, $b) { return $a['titulek'] < $b['titulek']; }); }elseif($sort=="name-asc"){ usort($vyfiltrovaneVysledky, function($a, $b) { return $a['titulek'] > $b['titulek']; }); }elseif($sort=="price-desc"){ usort($vyfiltrovaneVysledky, function($a, $b) { return $a['cena_filtr'] < $b['cena_filtr']; }); }elseif($sort=="price-asc"){ usort($vyfiltrovaneVysledky, function($a, $b) { return $a['cena_filtr'] > $b['cena_filtr']; }); } } $pocetVysledku = count($vyfiltrovaneVysledky); $vyfiltrovaneVysledky = ($pocetVysledku > $pageLimit) ? array_slice($vyfiltrovaneVysledky,$pageStart,$pageLimit) : $vyfiltrovaneVysledky; return array("pocet" => $pocetVysledku, "data"=>$vyfiltrovaneVysledky); } } headTableName = databaseTables::getTable("filtration", "filtrationTable"); $this->paramsTableName = databaseTables::getTable("filtration", "paramTable"); } // FILTER TYPES - Must have translation in language files and exist in frontend folder! public $filterTypes = array( "filterClassic" => "filter", "filterPrice" => "filterPrice", "filterSymptoms" => "filterSymptoms", "filterTags" => "filterTags", "filterParams" => "filterParams" // MUST BE LAST! ); // PARAETERS TYPES - Must be same as in database (paramsTableName)! public $paramStructure = array( "id" => 0, "filterId" => 0, "paramType" => 0, "paramName" => "", "paramIcon" => "", "paramHelp" => "" ); // PARAMETRIC FILTER - Get options for category public function getFilterOptionsForCategory($categoryId){ $sql = "SELECT * from `$this->headTableName` WHERE categoryId = :categoryId"; $stmt = Connect::getInstance()->dbh->prepare($sql); $stmt->bindValue(":categoryId", $categoryId); $stmt->execute(); $data = $stmt->fetch(PDO::FETCH_ASSOC); return $data; } // PARAMETRIC FILTER - Get parameters by id of filter public function getParamFilterById($id){ $sql = "SELECT * from `$this->paramsTableName` WHERE id = :id"; $stmt = Connect::getInstance()->dbh->prepare($sql); $stmt->bindValue(":id", $id); $stmt->execute(); $data = $stmt->fetch(PDO::FETCH_ASSOC); return $data; } // PARAMETRIC FILTER - Get parameters for category public function getFilterParamsForCategory($filterId){ $sql = "SELECT * from `$this->paramsTableName` WHERE filterId = :filterId AND paramParent = 0 ORDER BY id ASC"; $stmt = Connect::getInstance()->dbh->prepare($sql); $stmt->bindValue(":filterId", $filterId); $stmt->execute(); $data = $stmt->fetchAll(PDO::FETCH_ASSOC); return $data; } // PARAMETRIC FILTER - Get parameters values public function getFilterParamsValues($paramId){ $sql = "SELECT * from `$this->paramsTableName` WHERE paramParent = :paramParent ORDER BY id ASC"; $stmt = Connect::getInstance()->dbh->prepare($sql); $stmt->bindValue(":paramParent", $paramId); $stmt->execute(); $data = $stmt->fetchAll(PDO::FETCH_ASSOC); return $data; } // PARAMETRIC FILTER - Get params from product as array public static function getParamsAsArray($params){ $selectedParams = explode(";",$params); $newParam = array(); if($params){ foreach($selectedParams as $param){ $paramValues = explode(":",$param); //$newParam[$paramValues[0]] = $paramValues[1]; // RADIOBUTTON $newParam[$paramValues[0]] = explode("-",$paramValues[1]); // CHECKBOX } } return $newParam; } // GET ROWS from table public static function tableStatus($table){ $sql = "SHOW TABLE STATUS WHERE Name = :table;"; $stmt = Connect::getInstance()->dbh->prepare($sql); $stmt->bindValue(":table", $table); $stmt->execute(); $data = $stmt->fetch(PDO::FETCH_ASSOC); return $data["Rows"]; } // PAGINATION - Front and Back public function getPagination($type, $pocetVysledku, $pagi, $ajax, $requestUrl){ global $lang; if(is_numeric($type)){ if($type == 0){ $filterPageLimit = $this->pageLimit; }else{ $filterPageLimit = $type; } }else{ $filterPageLimit = $this->pageLimitFront; } if($pocetVysledku>$filterPageLimit){ if($pocetVysledku % $filterPageLimit == 0){ $paginace = ceil($pocetVysledku / $filterPageLimit); }elseif($pocetVysledku < $filterPageLimit){ $paginace = 1; }else{ $paginace = ceil($pocetVysledku / $filterPageLimit); } $aktiv_page = $pagi; if($ajax === true && $aktiv_page+1 < $paginace){ echo ''.$lang["module_filtr-frontFilter-loadMore"].''; } echo ''; if($aktiv_page > 0){ echo ''; } for($i=0;$i<$paginace;$i++){ $page_name = $i+1; $act = ($aktiv_page == $i) ? "active" : ""; $paginationTemplate = ''.$page_name.''; $last = round($paginace); if($paginace > 5){ if( $i==0 ){ echo $paginationTemplate; if( !(($aktiv_page - 2) <=0) ){ echo ". . ."; } }elseif( $i+1 == $last ){ if( !(($aktiv_page + 2) >=$last) ){ echo ". . ."; } echo $paginationTemplate; }elseif( $i==($aktiv_page - 1) OR $i==$aktiv_page OR $i==($aktiv_page + 1) ){ echo $paginationTemplate; }else{ continue; } }else{ echo $paginationTemplate; } } if($aktiv_page+1 < $paginace){ echo ''; } echo ''; } } // PAGINATION LINKS - Generate URL for anchor filtrations public function easyFiltrLink($actual_link,$filtr,$url_value){ // Vytvoření proměnných $parts = parse_url($actual_link); $skip = false; $queryParams = array(); parse_str($parts['query'], $queryParams); // Odstranění aktivního parametru unset($queryParams[$filtr]); if($filtr!='stranka'){ unset($queryParams['stranka']); } // Odstranění checkbox parametru if( strpos($filtr, '[') !== false ){ $arrayedFilter = explode("[",$filtr); $arrayedFilter = array("key" => $arrayedFilter[0],"name" => str_replace("]","",$arrayedFilter[1]),"value" => $url_value ); if( isset($queryParams[$arrayedFilter["key"]]) AND isset($queryParams[$arrayedFilter["key"]][$arrayedFilter["name"]]) ){ if( $queryParams[$arrayedFilter["key"]][$arrayedFilter["name"]] == "true" ){ unset($queryParams[$arrayedFilter["key"]][$arrayedFilter["name"]]); $skip = true; } if( empty($queryParams[$arrayedFilter["key"]]) ){ unset($queryParams[$arrayedFilter["key"]]); } } } // Seskupení pole parametrů $queryString = http_build_query($queryParams); // Vygenerování URL if($queryString){ $url = $parts['path'] . '?' . $queryString; if($url_value!="default" AND $skip === false){ $url .= "&".$filtr."=".$url_value; } }else{ if($url_value!="default" AND $skip === false){ $url .= "?".$filtr."=".$url_value; }else{ $url = $parts['path']; } } return $url; } // LIMITS - Price limit for price slider filter public static function getProductLimitsForPriceSlider($produktyKeKontrole){ $limity = array(); if($produktyKeKontrole){ // Nejnižší cena usort($produktyKeKontrole, function($a, $b) { return $a['cena_filtr'] > $b['cena_filtr']; }); $limity["limitMinimum"] = $produktyKeKontrole[0]['cena_filtr']; // Nejvyšší cena usort($produktyKeKontrole, function($a, $b) { return $a['cena_filtr'] < $b['cena_filtr']; }); $limity["limitMaximum"] = $produktyKeKontrole[0]['cena_filtr']; }else{ $limity["limitMinimum"] = 0; $limity["limitMaximum"] = 0; } return $limity; } // FILTRATION - Get filtered results public static function getFiltredResults($vsechnyProdukty, $GET, $pageStart, $pageLimit){ // Zachycení hodnot pro filtr if($GET){ $vyfiltrovaneVysledky = $filtry = array(); foreach ($GET as $key => $value) { if($key == "sort"){ $sort = $value; }elseif( (strpos($key, 'param') !== false) ){ $keyName = str_replace("param","",$key); $parameters[$keyName][] = $value; }else{ $filtry[$key] = $value; } } } $vyfiltrovaneVysledky = $vsechnyProdukty; // FILTER - Parametric if( isset($parameters) ){ $pomocnePole = array(); /* // RADIOBUTTON foreach( $vyfiltrovaneVysledky as $produkt ){ // If product have parametric values if( !empty($produkt["filterOptions"]) ){ foreach($produkt["filterOptions"] as $paramName => $paramValues){ // If parameter is active in filter if( isset($parameters[$paramName]) ){ // If value of parameter is active if( isset($parameters[$paramName][0][$paramValues]) ){ /$pomocnePole[] = $produkt; } } } } }*/ // CHECKBOX foreach( $vyfiltrovaneVysledky as $produkt ){ // If product have parametric values if( !empty($produkt["filterOptions"]) ){ foreach($produkt["filterOptions"] as $paramName => $paramValues){ // If parameter is active in filter ($paramName) if( isset($parameters[$paramName]) ){ // If value of parameter is active ($parameters[$paramName]) foreach($parameters[$paramName][0] as $searchedParamValue => $true){ // If parameter value is in product settings ($searchedParamValue) if( in_array($searchedParamValue,$produkt["filterOptions"][$paramName]) ){ $pomocnePole[] = $produkt; break; } } } } } } $vyfiltrovaneVysledky = $pomocnePole; } // FILTER - Symptoms if( isset($filtry["priznak"]) ){ $pomocnePole = array(); foreach( $filtry["priznak"] as $key => $true ){ $podminkaPriznaku = "priznak_".$key; foreach( $vyfiltrovaneVysledky as $produkt ){ if ( $produkt[$podminkaPriznaku] == 1 ){ $pomocnePole[] = $produkt; } } } $vyfiltrovaneVysledky = $pomocnePole; } // FILTER - Room tags - TOMR.cz if( isset($filtry["tag"]) ){ $pomocnePole = array(); foreach( $filtry["tag"] as $idStitku => $true ){ foreach( $vyfiltrovaneVysledky as $produkt ){ $poleStitku = explode(",",$produkt["stitky"]); if ( in_array($idStitku, $poleStitku) ){ $pomocnePole[] = $produkt; } } } $vyfiltrovaneVysledky = $pomocnePole; } // FILTER - Price if( isset($filtry["min"]) && isset($filtry["max"]) ){ $pomocnePole = array(); foreach( $vyfiltrovaneVysledky as $produkt ){ if ( $produkt["cena_filtr"] >= $filtry["min"] && $produkt["cena_filtr"] <= $filtry["max"] ){ $pomocnePole[] = $produkt; } } //$vyfiltrovaneVysledky = ( empty($pomocnePole) ) ? $vyfiltrovaneVysledky : $pomocnePole; $vyfiltrovaneVysledky = $pomocnePole; } // FILTER - Sorting if($sort){ if($sort=="name-desc"){ usort($vyfiltrovaneVysledky, function($a, $b) { return $a['titulek'] < $b['titulek']; }); }elseif($sort=="name-asc"){ usort($vyfiltrovaneVysledky, function($a, $b) { return $a['titulek'] > $b['titulek']; }); }elseif($sort=="price-desc"){ usort($vyfiltrovaneVysledky, function($a, $b) { return $a['cena_filtr'] < $b['cena_filtr']; }); }elseif($sort=="price-asc"){ usort($vyfiltrovaneVysledky, function($a, $b) { return $a['cena_filtr'] > $b['cena_filtr']; }); } } $pocetVysledku = count($vyfiltrovaneVysledky); $vyfiltrovaneVysledky = ($pocetVysledku > $pageLimit) ? array_slice($vyfiltrovaneVysledky,$pageStart,$pageLimit) : $vyfiltrovaneVysledky; return array("pocet" => $pocetVysledku, "data"=>$vyfiltrovaneVysledky); } } "Filtration", "moduleUrlName" => "filtration", "moduleLangName" => "filtration", "moduleIcon" => "fa-filter", "moduleVersion" => "2.3", "modulePages" => array( array( "pageId" => 1, "urlName" => "filter-settings", "url" => "filter-settings", "parent" => 0, "inMenu" => 0, "headPage" => 0 ) ) ); ?>connect !== null){ return $this->connect; } $this->connect = $connect; $this->appLang = ($appLang !== null) ? $appLang : null; $this->adminLang = ($adminLang !== null) ? $adminLang : null; $this->moduleLangFolder = ($this->moduleLangFolder !== null) ? $this->moduleLangFolder : $moduleLangFolder; $this->activeModulesPaths = ($this->activeModulesPaths !== null) ? $this->activeModulesPaths : $activeModulesPaths; $this->languagesTable = databaseTables::getTable("localization", "languageTable"); $this->checkLanguage(); } public function __toString(){ return get_class($this); } /* ================== Application functions === */ // Store active language shortcode to session and call for create a language file public function checkLanguage(){ if( $this->appLang === null ){ if ( !isset($_SESSION["languages"]["appLang"]) OR empty($_SESSION["languages"]["appLang"]) ){ $_SESSION["languages"]["appLang"] = DEFAULT_LANG; $this->appLang = $_SESSION["languages"]["appLang"]; } }else{ $this->setLanguage("appLang", $this->appLang); } if( $this->adminLang === null ){ if ( !isset($_SESSION["languages"]["adminLang"]) OR empty($_SESSION["languages"]["adminLang"]) ){ $_SESSION["languages"]["adminLang"] = DEFAULT_LANG; $this->adminLang = $_SESSION["languages"]["adminLang"]; } }else{ $this->setLanguage("adminLang", $this->adminLang); } $this->createLangFile("appLang", $this->activeModulesPaths, $this->moduleLangFolder); $this->createLangFile("adminLang", $this->activeModulesPaths, $this->moduleLangFolder); } // Store active language shortcode to session and call for create a language file public function setLanguage($langType, $langShort){ $language = $this->visibleLanguage($langShort); $_SESSION["languages"][$langType] = ( !empty($language) && $language["visibility"] == 1 ) ? $langShort : DEFAULT_LANG; $this->$langType = $_SESSION["languages"][$langType]; } // Create a language file with variables public function createLangFile($langShort, $activeModulesPaths, $moduleLangFolder){ $langFile = []; $langDefault = $this->getLanguageFile($_SESSION["languages"][$langShort]); $langModules = $this->getModuleLangFiles($langShort, $activeModulesPaths, $moduleLangFolder); $this->langFile[$langShort] = array_merge($langDefault,$langModules); return true; } // Load a basic language file public function getLanguageFile($langShort){ if( file_exists(LANG_DIR.$langShort.".php") ){ include(LANG_DIR.$langShort.".php"); }else{ include(LANG_DIR.DEFAULT_LANG.".php"); } return $lang; } // Load a modules language file public function getModuleLangFiles($langShort, $activeModulesPaths, $moduleLangFolder){ $langFile = []; if($activeModulesPaths){ foreach($activeModulesPaths as $modules){ if( isset($modules[$moduleLangFolder][$langShort]) ){ include($modules[$moduleLangFolder][$langShort]); }else{ include($modules[$moduleLangFolder][DEFAULT_LANG]); } $langFile = array_merge($langFile,$lang); } } return $langFile; } /* ================== Functions for work with data === */ // Select all languages in database public function getAllLanguages(){ $sql = "SELECT * FROM `{$this->languagesTable}` ORDER BY orderNum;"; $returnData = $this->connect->getQuery($sql, null, true); return $returnData; } // Select all active languages in database public function getAllActiveLanguages(){ $sql = "SELECT * FROM `{$this->languagesTable}` WHERE visibility = 1 ORDER BY orderNum;"; $returnData = $this->connect->getQuery($sql, null, true); return $returnData; } // Check if language exist and is active public function visibleLanguage($langShort){ $sql = "SELECT visibility FROM `{$this->languagesTable}` WHERE langShort = :langShort;"; $returnData = $this->connect->getQuery($sql, array("langShort" => $langShort), false); return $returnData; } // Add new language into database public function addLanguage($langValues){ $sql = "INSERT INTO `{$this->languagesTable}`"; $returnData = $this->connect->insertQuery($sql, $langValues); return $returnData; } // Edit language in database public function editLanguage($langValues, $whereValues = null){ $sql = "UPDATE `{$this->languagesTable}`"; $whereSql = "WHERE id = :id"; $returnData = $this->connect->updateQuery($sql, $langValues, $whereValues, $whereSql); return $returnData; } // Delete language from database public function deleteLanguage($whereValues){ $sql = "DELETE FROM `{$this->languagesTable}`"; $whereSql = "WHERE id = :id"; $returnData = $this->connect->deleteQuery($sql, $whereValues, $whereSql); return $returnData; } // Get one language by currency public function getOneLangByCurrency($currency){ $sql = "SELECT visibility FROM `{$this->languagesTable}` WHERE currency = :currency;"; $returnData = $this->connect->getQuery($sql, array("currency" => $currency), false); return $returnData; } } connect !== null){ return $this->connect; } $this->connect = $languageModule->connect; $this->appLang = $languageModule->appLang; $this->adminLang = $languageModule->adminLang; $this->translationsTable = databaseTables::getTable("localization", "translateTable"); } public function __toString(){ return get_class($this); } /* ================== Application functions === */ public function getLang(){ return $this->activeLang; } public function checkReplacing(){ return $this->replacingContent; } public function checkExistingTranslation($url, $langShort){ $sql = "SELECT * FROM `{$this->translationsTable}` WHERE url = :url AND langShort = :langShort"; $bind = array("url" => $url, "langShort" => $langShort); $translateResult = $this->connect->getQuery($sql, $bind, false); if( !empty($translateResult) ){ return $this->createTranslate($translateResult, $langShort, array()); }else{ return false; } } public function checkExistingTranslationObject($objectId, $objectType, $langShort, $defaultData){ $sql = "SELECT * FROM `{$this->translationsTable}` WHERE objectId = :id AND objectType = :type AND langShort = :langShort"; $bind = array("id" => $objectId, "type" => $objectType, "langShort" => $langShort); $translateResult = $this->connect->getQuery($sql, $bind, false); if( !empty($translateResult) ){ return $this->createTranslate($translateResult, $langShort, $defaultData); }else{ return false; } } public function createTranslate($translateResult, $langShort, $defaultData){ if( empty($defaultData) ){ $objectTable = $translateResult["contentTable"]; $sql = "SELECT * FROM `{$objectTable}` WHERE id = :id"; // ALL tables which have translate angine enabled MUST HAVE primary key named as ID! $bind = array("id" => $translateResult["objectId"]); $defaultData = $this->connect->getQuery($sql, $bind, false); } $translatedArray = $translateBox = $returnArray = []; if( isset($translateResult["translate"]) && !empty($translateResult["translate"]) ){ $translateParts = explode(";;",$translateResult["translate"]); foreach($translateParts as $part){ if( !empty($part) ){ $languagePart = explode(":=",$part); $translateBox[$languagePart[0]] = $languagePart[1]; } } foreach($defaultData as $colName => $colValue){ $translatedArray[$colName] = ( isset($translateBox[$colName]) && !empty($translateBox[$colName]) ) ? $translateBox[$colName] : $colValue; } $translatedArray["url"] = $translateResult["url"]; } if( $this->showMismatchContent === false ){ // NULL - If translation not exist, return FALSE $returnArray = ( empty($translatedArray) ) ? false : $translatedArray; }else{ // TRUE - If translation not exist, show original content (TEXT data) $returnArray = ( empty($translatedArray) ) ? $defaultData : $translatedArray; } if( !empty($returnArray) ){ $returnArray = array_merge($returnArray, array("langShort" => $langShort)); } return $returnArray; } public function selectRightTranslate($multipleData, $activeLang){ $translatedObject = array_search($activeLang, array_column($multipleData, 'langShort')); if( !isset($translatedObject) && $this->showMismatchContent === true ){ $translatedObject = array_search(DEFAULT_LANG, array_column($returnData["data"], 'langShort')); } return $multipleData[$translatedObject]; } public function checkTranslateFile($langPath){ if( file_exists($langPath) ){ $lang = $this->loadTranslateFile($langPath); }else{ $lang = []; } return $lang; } public function loadTranslateFile($langPath){ include($langPath); return $lang; } public function createMultiTableQuery($postData, $translatableRows, $dataRows){ $data = $translate = $other = []; foreach($postData as $key => $value){ if( isset($translatableRows[$key]) OR in_array($key, $translatableRows) ){ $translate[$key] = $value; }elseif( isset($dataRows[$key]) OR in_array($key, $dataRows) ){ $data[$key] = $value; }else{ $other[$key] = $value; } } return ["data" => $data, "translate" => $translate, "other" => $other]; } public function updateQuery($postData, $dataTable, $translateTable, $objectId, $objectLang){ if( !empty($postData["data"]) && $dataTable !== null ){ $sqlQuery = "UPDATE `{$dataTable}`"; $whereSql = "WHERE id = :id"; $done = $this->connect->updateQuery($sqlQuery, $postData["data"], array("id" => $objectId), $whereSql); if($done !== true){return false;} } if( !empty($postData["translate"]) && $translateTable !== null ){ $sqlQuery = "UPDATE `{$translateTable}`"; $whereSql = "WHERE associatedId = :associatedId AND langShort = :langShort"; $done = $this->connect->updateQuery($sqlQuery, $postData["translate"], array("associatedId" => $objectId, "langShort" => $objectLang), $whereSql); if($done !== true){return false;} } return ( isset($done) ) ? true : false; } public function addQuery($postData, $dataTable, $translateTable){ if( !empty($postData["data"]) && $dataTable !== null ){ $sql = "INSERT INTO `{$dataTable}`"; (int) $doneHead = $this->connect->insertQuery($sql, $postData["data"]); if($doneHead === 0){return false;} } if( !empty($postData["translate"]) && $translateTable !== null ){ if($doneHead !== 0 AND $doneHead !== '0'){ $postData["translate"]["associatedId"] = $doneHead; } $sql = "INSERT INTO `{$translateTable}`"; (int) $doneTranslate = $this->connect->insertQuery($sql, $postData["translate"]); if($doneTranslate === 0){return false;} } $done = ($doneHead !== 0) ? $doneHead : $doneTranslate; return ($done === 0) ? false : $done; } public function updateQueryAndTranslate($postData, $dataTable, $objectId, $objectType, $langShort, $defaultUrl, $enableTranslate = true){ if( !empty($postData["data"]) && $dataTable !== null ){ $sqlQuery = "UPDATE `{$dataTable}`"; $whereSql = "WHERE id = :id"; $baseData = array_merge($postData["data"], $postData["translate"]); $done = $this->connect->updateQuery($sqlQuery, $baseData, array("id" => $objectId), $whereSql); if($done !== true){return false;} } if( !empty($postData["translate"]) && $enableTranslate === true ){ $translateSql = "SELECT * FROM `{$this->translationsTable}` WHERE objectId = :objectId AND langShort = :langShort AND objectType = :objectType"; $translateBind = array("objectId" => $objectId, "langShort" => $langShort, "objectType" => $objectType); $translateCheck = $this->connect->getQuery($translateSql, $translateBind, false); $translate = []; $translate["url"] = $postData["translate"]["url"]; unset($postData["translate"]["url"]); $translate["translate"] = $this->createTranslateString($postData["translate"]); $translate["urlDefault"] = $defaultUrl; if(isset($translate["url"])){unset($translate["url"]);unset($translate["urlDefault"]);} if( !empty($translateCheck) ){ $sqlQuery = "UPDATE `{$this->translationsTable}`"; $whereSql = "WHERE objectId = :objectId AND langShort = :langShort AND objectType = :objectType"; $done = $this->connect->updateQuery($sqlQuery, $translate, array("objectId" => $objectId, "langShort" => $langShort, "objectType" => $objectType), $whereSql); }else{ $translate["objectId"] = $objectId; $translate["objectType"] = $objectType; $translate["contentTable"] = $dataTable; $translate["langShort"] = $langShort; $sql = "INSERT INTO `{$this->translationsTable}`"; (int) $done = $this->connect->insertQuery($sql, $translate); if($done === 0){return false;} } } return ( isset($done) ) ? true : false; } public function addQueryAndTranslate($postData, $dataTable){ if( (!empty($postData["data"]) OR !empty($postData["translate"])) && $dataTable !== null ){ $sql = "INSERT INTO `{$dataTable}`"; $baseData = array_merge($postData["data"], $postData["translate"]); (int) $doneHead = $this->connect->insertQuery($sql, $baseData); if($doneHead === 0){return false;} } return ( isset($doneHead) ) ? $doneHead : false; } public function createTranslateString($postData){ $allTranslates = null; if($postData){ foreach($postData as $name => $value){ $allTranslates .= $name.":=".$value.";;"; } } return $allTranslates; } // Check possible translation public function translateResult($langShort, $defaultData, $translateType, $loop = true){ $returnData = []; if(!empty($defaultData)){ if( $loop === true){ $translateData = []; foreach($defaultData as $categoryData){ $translate = $this->checkExistingTranslationObject($categoryData["id"], $translateType, $langShort, $categoryData); $translateData[] = ( !empty($translate) ) ? $translate : $categoryData; } $returnData = $translateData; }else{ $translate = $this->checkExistingTranslationObject($defaultData["id"], $translateType, $langShort, $defaultData); $returnData = ( !empty($translate) ) ? $translate : $defaultData; } } return $returnData; } /* public function createTranslatedQuery($translatableRows, $keyId, $dataTable, $dataAlias, $langTable, $langAlias){ $rowConditions = ""; $keyNum = count($translatableRows); foreach($translatableRows as $key => $row){ $rowConditions .= "IFNULL({$langAlias}.{$row}, {$defaultAlias}.{$row}) AS {$row}"; $rowConditions .= ( ($key+1) == $keyNum) ? " ": ", "; } $sql .= "FROM `{$dataTable}` AS {$dataAlias} "; $sql .= "LEFT OUTER JOIN `{$langTable}` AS {$langAlias} "; $sql .= "ON {$dataAlias}.id = {$langAlias}.{$keyId} AND {$langAlias}.langShort = :langShort "; $sql .= "LEFT OUTER JOIN `{$langTable}` AS {$defaultAlias} "; $sql .= "ON {$dataAlias}.id = {$defaultAlias}.{$keyId} AND {$defaultAlias}.langShort = :langDefault "; } */ } "Localization", "moduleUrlName" => "localization", "moduleLangName" => "localization", "moduleIcon" => "fa-language", "moduleVersion" => "2.1", "modulePages" => array( array( "pageId" => 1, "urlName" => "language-settings", "url" => "language-settings", "parent" => 0, "inMenu" => 1, "headPage" => 1 ), array( "pageId" => 2, "urlName" => "language-assets", "url" => "language-assets", "parent" => 1, "inMenu" => 0, "headPage" => 0 ), array( "pageId" => 3, "urlName" => "language-edit", "url" => "language-edit", "parent" =>2, "inMenu" => 0, "headPage" => 0 ) ) ); ?>connect !== null){ return $this->connect; } $this->connect = $connect; $this->dataTable = databaseTables::getTable("maintenance", "maintenanceTable"); $this->translateTable = databaseTables::getTable("maintenance", "maintenanceTableLang"); } public function __toString(){ return get_class($this); } /* ================== Application function === */ private function getVisitorIp() { $ipaddress = ''; if (isset($_SERVER['HTTP_CLIENT_IP'])) $ipaddress = $_SERVER['HTTP_CLIENT_IP']; else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR']; else if(isset($_SERVER['HTTP_X_FORWARDED'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED']; else if(isset($_SERVER['HTTP_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_FORWARDED_FOR']; else if(isset($_SERVER['HTTP_FORWARDED'])) $ipaddress = $_SERVER['HTTP_FORWARDED']; else if(isset($_SERVER['REMOTE_ADDR'])) $ipaddress = $_SERVER['REMOTE_ADDR']; else $ipaddress = 'UNKNOWN'; return $ipaddress; } /* ================== Functions for work with data === */ // Get maintenance page by LANG public function getMaintenance($lang){ $sql = "SELECT translations.*, data.* FROM `{$this->dataTable}` AS data INNER JOIN `{$this->translateTable}` AS translations ON data.id = translations.associatedId WHERE translations.langShort = :langShort;"; $returnData = $this->connect->getQuery($sql, array("langShort" => $lang), false); if( empty($returnData) ){ $returnData = $this->createMainteanceTranslation($lang); } return $returnData; } // Create maintenance page for language if not exist private function createMainteanceTranslation($lang){ $returnData = []; $sql = "INSERT INTO `{$this->dataTable}`"; $newId = $this->connect->insertQuery($sql, ["enabled" => 0]); $done = ($newId != 0) ? true : false; $sql = "INSERT INTO `{$this->translateTable}`"; $newResult = $this->connect->insertQuery($sql, ["associatedId" => $newId, "langShort" => $lang]); $done = ($newResult != 0) ? true : false; if($done === true){ $returnData = $this->getMaintenance($lang); } return $returnData; } // Get maintenance page by LANG public function checkMaintenance($presenter){ $presenter->controller->maintenance = false; $presenter->controller->maintenanceData = []; $presenter->controller->maintenanceCss = null; if($presenter->controller->frontEnd === true){ $sql = "SELECT translations.*, data.* FROM `{$this->dataTable}` AS data INNER JOIN `{$this->translateTable}` AS translations ON data.id = translations.associatedId WHERE translations.langShort = :langShort;"; $maintenancePage = $this->connect->getQuery($sql, array("langShort" => $presenter->templateData->langShort), false); $visitorIp = $this->getVisitorIp(); $arrayIp = array_filter(explode(";", $maintenancePage["addresses"])); if( $maintenancePage["enabled"] == 1 AND !in_array($visitorIp, $arrayIp) ){ $presenter->controller->maintenance = true; $presenter->metaData->description = ( !empty($maintenancePage["metaDescription"]) ) ? $maintenancePage["metaDescription"] : $presenter->metaData->description; $presenter->metaData->keywords = ( !empty($maintenancePage["metaKeywords"]) ) ? $maintenancePage["metaKeywords"] : $presenter->metaData->keywords; $presenter->metaData->title = ( !empty($maintenancePage["metaTitle"]) ) ? $maintenancePage["metaTitle"] : $presenter->metaData->title; $presenter->controller->maintenanceData = $maintenancePage["description"]; $presenter->controller->maintenanceCss = (empty($maintenancePage["cssStyle"])) ? null : $maintenancePage["cssStyle"]; $presenter->activeContent->templatePath = 'systemPages/maintenance.php'; $presenter->activeContent->templateController = null; } } return $presenter; } } "Maintenance", "moduleUrlName" => "maintenance", "moduleLangName" => "maintenance", "moduleIcon" => "fa-wrench", "moduleVersion" => "1.0", "modulePages" => array( array( "pageId" => 1, "urlName" => "upkeep", "url" => "upkeep", "parent" => 0, "inMenu" => 1, "headPage" => 1 ) ) ); ?> [ "width" => 60, "height" => 60, "quality" => 50, "proportional" => true ], "120" => [ "width" => 120, "height" => 120, "quality" => 50, "proportional" => true ], "250" => [ "width" => 250, "height" => 250, "quality" => 70, "proportional" => true ], "500" => [ "width" => 500, "height" => 500, "quality" => 80, "proportional" => true ], "800" => [ "width" => 800, "height" => 800, "quality" => 80, "proportional" => true ], "ogTag" => [ "width" => 1200, "height" => 630, "quality" => 80, "proportional" => true ] ]; private $supportedFormats = [ "image" => [ "image/jpeg" => "jpg", "image/png" => "png", "image/gif" => "gif" ], "file" => [ "application/pdf" => "pdf", "application/msword" => "word", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" => "word", "application/vnd.ms-excel" => "excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" => "excel", "application/vnd.ms-powerpoint" => "powerpoint", "application/vnd.openxmlformats-officedocument.presentationml.presentation" => "powerpoint", "application/vnd.openxmlformats-officedocument.presentationml.slideshow" => "powerpoint", "application/xml" => "xml", "text/xml" => "xml", "text/plain" => "txt" ], "video" => [ "video/mp4" => "mp4", "video/webm" => "webm", "video/ogg" => "ogg", "video/quicktime" => "mov", "video/x-ms-wmv" => "x-ms-wmv" ], "audio" => [ "audio/mpeg" => "mp3", "audio/mp3" => "mp3", "audio/wav" => "wav", "audio/ogg" => "ogg" ] ]; public $totalResults = null; public function __construct(Connect $connect) { if($this->connect !== null){ return $this->connect; } $this->connect = $connect; $appImages = new appImageSizes(); $this->imageSizesArray = $this->imageSizesArray + $appImages->imageSizesArray; $this->dataTable = databaseTables::getTable("mediaManager", "mediaTable"); $this->translateTable = databaseTables::getTable("mediaManager", "mediaTableLang"); } public function __toString(){ return get_class($this); } /* ================== CACHE === */ public function cacheResults($activeFolder, $rewrite = false){ if( (isset($_SESSION["security"]["adminLogin"]["cache"]["mediaManager"][$activeFolder]["totalResults"]) && $rewrite === true) OR !isset($_SESSION["security"]["adminLogin"]["cache"]["mediaManager"][$activeFolder]["totalResults"]) ){ $sql = "SELECT count(*) AS num FROM `{$this->dataTable}` WHERE folder = {$activeFolder};"; $info = $this->connect->getQuery($sql, null, false); $_SESSION["security"]["adminLogin"]["cache"]["mediaManager"][$activeFolder]["totalResults"] = $info["num"]; $this->totalResults = $info["num"]; }else{ $this->totalResults = $_SESSION["security"]["adminLogin"]["cache"]["mediaManager"][$activeFolder]["totalResults"]; } } /* ================== Application functions === */ // Check supported files public function checkFile($fileType){ $supported = false; if( !empty($fileType) ){ foreach($this->supportedFormats as $type => $exts){ if( array_key_exists($fileType, $exts) ){ $supported = $type; break; } } } return $supported; } // Check supported files public function getFileType($fileType){ $returnType = (isset($this->supportedFormats["file"][$fileType])) ? $this->supportedFormats["file"][$fileType] : $fileType; return $returnType; } // Get group of fileType public function getFileGroup($fileType){ if(isset($this->supportedFormats["file"][$fileType])){ $returnType = "file"; }elseif(isset($this->supportedFormats["audio"][$fileType])){ $returnType = "audio"; }elseif(isset($this->supportedFormats["video"][$fileType])){ $returnType = "video"; }else{ $returnType = "image"; } return $returnType; } // Create title public function convertTitle($title) { static $convertTable = array ( 'á' => 'a', 'Á' => 'A', 'ä' => 'a', 'Ä' => 'A', 'č' => 'c', 'Č' => 'C', 'ď' => 'd', 'Ď' => 'D', 'é' => 'e', 'É' => 'E', 'ě' => 'e', 'Ě' => 'E', 'ë' => 'e', 'Ë' => 'E', 'í' => 'i', 'Í' => 'I', 'ï' => 'i', 'Ï' => 'I', 'ľ' => 'l', 'Ľ' => 'L', 'ĺ' => 'l', 'Ĺ' => 'L', 'ň' => 'n', 'Ň' => 'N', 'ń' => 'n', 'Ń' => 'N', 'ó' => 'o', 'Ó' => 'O', 'ö' => 'o', 'Ö' => 'O', 'ř' => 'r', 'Ř' => 'R', 'ŕ' => 'r', 'Ŕ' => 'R', 'š' => 's', 'Š' => 'S', 'ś' => 's', 'Ś' => 'S', 'ť' => 't', 'Ť' => 'T', 'ú' => 'u', 'Ú' => 'U', 'ů' => 'u', 'Ů' => 'U', 'ü' => 'u', 'Ü' => 'U', 'ý' => 'y', 'Ý' => 'Y', 'ÿ' => 'y', 'Ÿ' => 'Y', 'ž' => 'z', 'Ž' => 'Z', 'ź' => 'z', 'Ź' => 'Z', ); $title = strtolower(strtr($title, $convertTable)); $title = preg_replace('/[^a-zA-Z0-9]+/u', '-', $title); $title = str_replace('--', '-', $title); $title = trim($title, '-'); return $title; } // Check if name exist public function checkIfNameExist($filename, $extension, $rowFilename, $uploadFolder){ $nameExist = $this->findNameInTable($uploadFolder.$filename); if($nameExist === true){ $i = 1; do{ $filename = $rowFilename.$i.".".$extension; $nameExist = $this->findNameInTable($uploadFolder.$filename); $i++; }while($nameExist === true); } return $filename; } // Find name in table public function findNameInTable($imageName){ $sql = "SELECT * FROM `$this->dataTable` WHERE url = :url;"; $returnData = $this->connect->getQuery($sql, array("url" => $imageName), true); return ( empty($returnData) ) ? false : true; } // Create file params public function parseParams($name, $isUrl = false){ $filename = ($isUrl === false) ? stripslashes($name) : substr(strrchr(stripslashes($name), "/"), 1); $extension = substr(strrchr($name, "."), 1); $rowFilename = $this->convertTitle(str_replace(".".$extension,"",$filename)); $filename = $rowFilename.".".$extension; return ["fileName" => $filename, "extension" => $extension, "rowFilename" => $rowFilename]; } public function getHeadImage($objectId, $templateName, $lang, $size = null){ $allUrls = []; $image = $this->getHeadFile($objectId, $templateName, $lang); if( !empty($image) ){ $mediaLoad = new mediaLoad($this); $imageData = $image; $newUrl = $mediaLoad->getFileName($image["url"], $size); $fileInfo = $this->parseParams($image["url"], true); $imageData["fileName"] = $fileInfo["fileName"]; $imageData["url"] = $newUrl; $imageData["basicUrl"] = $image["url"]; $imageEntity = new mediaFactory($imageData); $object = $imageEntity->getMedia(); return (object) $object; }else{ return false; } } public function getAllRelatedImages($objectId, $templateName, $lang, $size = null){ $allUrls = []; $allFiles = $this->getAllObjectFiles($objectId, $templateName, $lang); if($allFiles){ $mediaLoad = new mediaLoad($this); usort($allFiles, function($a, $b) { return $a['orderNum'] > $b['orderNum']; }); foreach ($allFiles as $image){ $imageData = $image; $newUrl = $mediaLoad->getFileName($image["url"], $size); $fileInfo = $this->parseParams($image["url"], true); $imageData["fileName"] = $fileInfo["fileName"]; $imageData["url"] = $newUrl; $imageData["basicUrl"] = $image["url"]; $imageEntity = new mediaFactory($imageData); $object = $imageEntity->getMedia(); $allUrls[] = $object; } } return (empty($allUrls)) ? false : (object) $allUrls; } public function getAllRelatedImagesSerialized($objectId, $templateName, $lang, $size = null){ $allUrls = []; $allFiles = $this->getAllObjectFilesSerialized($objectId, $templateName, $lang); if($allFiles){ $mediaLoad = new mediaLoad($this); foreach ($allFiles as $image){ $imageData = $image; $newUrl = $mediaLoad->getFileName($image["url"], $size); $fileInfo = $this->parseParams($image["url"], true); $imageData["fileName"] = $fileInfo["fileName"]; $imageData["url"] = $newUrl; $imageData["basicUrl"] = $image["url"]; $imageEntity = new mediaFactory($imageData); $object = $imageEntity->getMedia(); $allUrls[] = $object; } } return (empty($allUrls)) ? false : (object) $allUrls; } /* ================== Functions for work with data === */ // Get all files public function getAllFiles($lang){ $sql = "SELECT data.*, translations.title, translations.alt, translations.langShort FROM `{$this->dataTable}` AS data INNER JOIN `{$this->translateTable}` AS translations ON data.id = translations.associatedId WHERE translations.langShort = :langShort;"; $returnData = $this->connect->getQuery($sql, array("langShort" => $lang), true); return $returnData; } // Get all files with same template public function getAllTemplateFiles($template, $lang){ $sql = "SELECT data.*, translations.title, translations.alt, translations.langShort FROM `{$this->dataTable}` AS data INNER JOIN `{$this->translateTable}` AS translations ON data.id = translations.associatedId WHERE data.template = :template AND translations.langShort = :langShort;"; $returnData = $this->connect->getQuery($sql, array("template" => $template, "langShort" => $lang), true); return $returnData; } // Get limited files public function getAllLimited($lang, $limit, $start){ $sql = "SELECT data.*, translations.title, translations.alt, translations.langShort FROM `{$this->dataTable}` AS data INNER JOIN `{$this->translateTable}` AS translations ON data.id = translations.associatedId WHERE translations.langShort = :langShort ORDER BY data.id DESC LIMIT $limit OFFSET $start;"; $returnData = $this->connect->getQuery($sql, array("langShort" => $lang), true); return $returnData; } // Get limited files public function getAllLimitedFoldered($lang, $folder, $limit, $start){ $sql = "SELECT data.*, translations.title, translations.alt, translations.langShort FROM `{$this->dataTable}` AS data INNER JOIN `{$this->translateTable}` AS translations ON data.id = translations.associatedId WHERE translations.langShort = :langShort AND data.folder = :folder AND data.duplicated = 0 ORDER BY data.id DESC LIMIT $limit OFFSET $start;"; $returnData = $this->connect->getQuery($sql, array("langShort" => $lang, "folder" => $folder), true); return $returnData; } // Get all files for object public function getAllObjectFiles($objectId, $template, $lang){ $sql = "SELECT data.*, translations.title, translations.alt, translations.langShort FROM `{$this->dataTable}` AS data INNER JOIN `{$this->translateTable}` AS translations ON data.id = translations.associatedId WHERE data.template = :template AND data.objectId = :id AND translations.langShort = :langShort;"; $returnData = $this->connect->getQuery($sql, array("id" => $objectId, "template" => $template, "langShort" => $lang), true); return $returnData; } // Get all files ordered by HEAD public function getAllObjectFilesByHead($objectId, $template, $lang){ $sql = "SELECT data.*, translations.title, translations.alt, translations.langShort FROM `{$this->dataTable}` AS data INNER JOIN `{$this->translateTable}` AS translations ON data.id = translations.associatedId WHERE data.template = :template AND data.objectId = :id AND translations.langShort = :langShort ORDER BY head DESC;"; $returnData = $this->connect->getQuery($sql, array("id" => $objectId, "template" => $template, "langShort" => $lang), true); return $returnData; } // Get all files ordered by HEAD and ORDER NUM public function getAllObjectFilesSerialized($objectId, $template, $lang){ $sql = "SELECT data.*, translations.title, translations.alt, translations.langShort FROM `{$this->dataTable}` AS data INNER JOIN `{$this->translateTable}` AS translations ON data.id = translations.associatedId WHERE data.template = :template AND data.objectId = :id AND translations.langShort = :langShort ORDER BY head DESC, orderNum ASC;"; $returnData = $this->connect->getQuery($sql, array("id" => $objectId, "template" => $template, "langShort" => $lang), true); return $returnData; } // Get one file by ID public function getOneFileById($objectId, $lang){ $sql = "SELECT data.*, translations.title, translations.alt, translations.langShort FROM `{$this->dataTable}` AS data INNER JOIN `{$this->translateTable}` AS translations ON data.id = translations.associatedId WHERE data.id = :id AND translations.langShort = :langShort;"; $returnData = $this->connect->getQuery($sql, array("id" => $objectId, "langShort" => $lang), false); return $returnData; } // Get one file by URL public function getOneFileByUrl($objectUrl, $lang){ $sql = "SELECT data.*, translations.title, translations.alt, translations.langShort FROM `{$this->dataTable}` AS data INNER JOIN `{$this->translateTable}` AS translations ON data.id = translations.associatedId WHERE data.url = :url AND translations.langShort = :langShort LIMIT 1;"; $returnData = $this->connect->getQuery($sql, array("url" => $objectUrl, "langShort" => $lang), false); return $returnData; } // Get all files for object with HEAD PREFIX public function getHeadFile($objectId, $template, $lang){ $sql = "SELECT data.*, translations.title, translations.alt, translations.langShort FROM `{$this->dataTable}` AS data INNER JOIN `{$this->translateTable}` AS translations ON data.id = translations.associatedId WHERE data.template = :template AND data.objectId = :id AND translations.langShort = :langShort ORDER BY head DESC LIMIT 1;"; $returnData = $this->connect->getQuery($sql, array("id" => $objectId, "template" => $template, "langShort" => $lang), false); return $returnData; } // Add new file into database public function addFile($fileValues){ $sql = "INSERT INTO `{$this->dataTable}`"; $returnData = $this->connect->insertQuery($sql, $fileValues); return $returnData; } // Add new file into database public function addTranslate($objectId){ if($objectId != 0){ $fileValues = ["associatedId" => $objectId, "langShort" => $_SESSION["languages"]["adminLang"]]; $sql = "INSERT INTO `{$this->translateTable}`"; $returnData = $this->connect->insertQuery($sql, $fileValues); return $returnData; } } // Delete file from database public function deleteFile($objectId){ $sql = "DELETE FROM `{$this->translateTable}`"; $whereSql = "WHERE associatedId = :id"; $returnData = $this->connect->deleteQuery($sql, array("id" => $objectId), $whereSql); $sql = "DELETE FROM `{$this->dataTable}`"; $whereSql = "WHERE id = :id"; $returnData = $this->connect->deleteQuery($sql, array("id" => $objectId), $whereSql); return true; } // Edit file in database public function editFile($langValues, $whereValues = null){ $sql = "UPDATE `{$this->languagesTable}`"; $whereSql = "WHERE id = :id"; $returnData = $this->connect->updateQuery($sql, $langValues, $whereValues, $whereSql); return $returnData; } }mediaManager !== null){ return $this->mediaManager; } $this->mediaManager = $mediaManager; } /* ================== UPLOAD FUNCTIONS === */ // UPLOAD IMAGE public function uploadImages($allFiles, $size = null){ $systemLogger = new systemLogger($this->mediaManager->connect); $uploadImage = new imageResizer(); // Create upload folder $uploadFolder = date('Y')."/".date('m')."/"; $uploadPathDone = UPLOAD_DIR.$uploadFolder; $counter = 0; foreach($allFiles as $file){ if(empty($file["name"]) OR empty($file["tmp_name"])){ continue; } // Create file params $fileInfo = $this->mediaManager->parseParams($file['name'], false); // Check possible name duplicity $imageName = $this->mediaManager->checkIfNameExist($fileInfo["fileName"], $fileInfo["extension"], $fileInfo["rowFilename"], $uploadFolder); // Create upload folder if not exist if (!file_exists($uploadPathDone)) { mkdir($uploadPathDone, 0777, true); } // Create object for database $imageData = ["url" => $uploadFolder.$imageName, "objectId" => 0, "fileType" => $file["type"], "fileSize" => $file["size"], "folder" => $file["folderId"], "createdDate" => date("Y-m-d H:i:s"), "updatedDate" => date("Y-m-d H:i:s")]; $uploadedId = $this->mediaManager->addFile($imageData); $translate = $this->mediaManager->addTranslate($uploadedId); if($uploadedId != 0){ //if($size === null){ $imageDetail = getimagesize($file["tmp_name"]); list($imageWidth, $imageHeight) = $imageDetail; $imageQuality = 100; $resizedFile = $uploadPathDone."/".$imageName; //} $upload = $uploadImage->smart_resize_image(null, file_get_contents($file["tmp_name"]), $imageWidth , $imageHeight , true , $resizedFile , false , false , $imageQuality); if( $upload !== true ){ $this->mediaManager->deleteFile($uploadedId); }else{ $systemLogger->createLog($_SESSION["languages"]["adminLang"], "mediaManager", "uploadFile", $uploadedId, $_SESSION["security"]["adminLogin"]["logIn"]); $counter++; $this->mediaManager->cacheResults($file["folderId"], true); } } } return $counter; } // UPLOAD IMAGE FROM URL ADDRESS public function uploadImageByUrl($uploadDir, $url, $size = null){ $systemLogger = new systemLogger($this->mediaManager->connect); $uploadImage = new imageResizer(); $urlAddress = $uploadDir.$url; $uploadFolder = date('Y')."/".date('m')."/"; $uploadPathDone = UPLOAD_DIR.$uploadFolder; $return = false; // Create file params $fileInfo = $this->mediaManager->parseParams($urlAddress, true); // Check possible name duplicity $imageName = ($size === null) ? $this->mediaManager->checkIfNameExist($fileInfo["fileName"], $fileInfo["extension"], $fileInfo["rowFilename"], $uploadFolder) : $fileInfo["fileName"]; // Create object for database if($size === null){ $imageData = ["url" => $uploadFolder.$imageName, "objectId" => 0, "fileType" => $file["type"], "fileSize" => $file["size"], "folder" => $file["folderId"], "createdDate" => date("Y-m-d H:i:s"), "updatedDate" => date("Y-m-d H:i:s")]; $uploadedId = $this->mediaManager->addFile($imageData); $translate = $this->mediaManager->addTranslate($uploadedId); }else{ $load = $this->mediaManager->getOneFileByUrl($url, $_SESSION["languages"]["adminLang"]); $uploadedId = $load["id"]; } if($uploadedId != 0){ if($size === null){ $imageDetail = getimagesize($urlAddress); list($imageWidth, $imageHeight) = $imageDetail; $imageQuality = 100; $proportionalUpload = false; if (!file_exists($uploadPathDone)) { mkdir($uploadPathDone, 0777, true); } $resizedFile = $uploadPathDone."/".$imageName; }else{ $imageWidth = $this->mediaManager->imageSizesArray[$size]["width"]; $imageHeight = $this->mediaManager->imageSizesArray[$size]["height"]; $imageQuality = $this->mediaManager->imageSizesArray[$size]["quality"]; $proportionalUpload = $this->mediaManager->imageSizesArray[$size]["proportional"]; $rowFilename = substr(strrchr(stripslashes($url), "/"), 1); $extension = substr(strrchr($url, "."), 1); $filePath = str_replace($rowFilename,"",$url); $fileUrl = $filePath.$size."/"; $resizedFile = $uploadDir.$fileUrl; if (!file_exists($resizedFile)) { mkdir($resizedFile, 0777, true); } $resizedFile = $resizedFile."/".$imageName; } $upload = $uploadImage->smart_resize_image($urlAddress, null, $imageWidth , $imageHeight , $proportionalUpload , $resizedFile , false , false , $imageQuality); if( $upload !== true ){ if($size === null){ $this->mediaManager->deleteFile($uploadedId); } }else{ if($size === null){ $systemLogger->createLog($_SESSION["languages"]["adminLang"], "mediaManager", "uploadFileUrl", $uploadedId, $_SESSION["security"]["adminLogin"]["logIn"]); }else{ $systemLogger->createLog($_SESSION["languages"]["adminLang"], "mediaManager", "regenerateFile", $uploadedId, $_SESSION["security"]["adminLogin"]["logIn"]); } $return = true; $this->mediaManager->cacheResults(true); } } return $return; } // UPLOAD FILE public function uploadFiles($allFiles){ $systemLogger = new systemLogger($this->mediaManager->connect); $uploadImage = new imageResizer(); // Create upload folder $uploadFolder = date('Y')."/".date('m')."/"; $uploadPathDone = UPLOAD_DIR.$uploadFolder; $counter = 0; foreach($allFiles as $file){ if(empty($file["name"]) OR empty($file["tmp_name"])){ continue; } // Create file params $fileInfo = $this->mediaManager->parseParams($file['name'], false); // Check possible name duplicity $imageName = $this->mediaManager->checkIfNameExist($fileInfo["fileName"], $fileInfo["extension"], $fileInfo["rowFilename"], $uploadFolder); // Create upload folder if not exist if (!file_exists($uploadPathDone)) { mkdir($uploadPathDone, 0777, true); } // Create object for database $imageData = ["url" => $uploadFolder.$imageName, "objectId" => 0, "fileType" => $file["type"], "fileSize" => $file["size"], "folder" => $file["folderId"], "createdDate" => date("Y-m-d H:i:s"), "updatedDate" => date("Y-m-d H:i:s")]; $uploadedId = $this->mediaManager->addFile($imageData); $translate = $this->mediaManager->addTranslate($uploadedId); if($uploadedId != 0){ $uploadFilePath = $uploadPathDone."/".$imageName; $upload = move_uploaded_file($file["tmp_name"], $uploadFilePath); if( $upload === false ){ $this->mediaManager->deleteFile($uploadedId); }else{ $systemLogger->createLog($_SESSION["languages"]["adminLang"], "mediaManager", "uploadFile", $uploadedId, $_SESSION["security"]["adminLogin"]["logIn"]); $counter++; $this->mediaManager->cacheResults($file["folderId"], true); } } } return $counter; } }connect !== null){ return $this->connect; } $this->connect = $mediaManager->connect; $this->mediaManager = $mediaManager; $this->uploadClass = new uploadClass($this->mediaManager); } public function __toString(){ return get_class($this); } /* ================== Application functions === */ public function recreateUrl($fileUrl, $size){ if( !empty($size) ){ $rowFilename = substr(strrchr(stripslashes($fileUrl), "/"), 1); $extension = substr(strrchr($fileUrl, "."), 1); $filePath = str_replace($rowFilename,"",$fileUrl); $fileUrl = $filePath.$size."/".$rowFilename; } return $fileUrl; } public function getFileName($url, $size){ if($url === null){ return false; } $fileUrl = $this->recreateUrl($url, $size); $filePathReturn = stripslashes($fileUrl); // Remove possible backslashes if( !file_exists(UPLOAD_DIR.$filePathReturn) ){ $regenerateFile = $this->uploadClass->uploadImageByUrl(UPLOAD_DIR, $url, $size); if($regenerateFile !== true){return false;} } if( !empty($filePathReturn) ){ $this->loadedImages[] = $url; return "/upload/".$filePathReturn; }else{ return false; } } public function removeFile($fileUrl){ $status = false; if( file_exists(UPLOAD_DIR.$fileUrl) ){ $status = unlink(UPLOAD_DIR.$fileUrl); } return $status; } public function createImage($file, $size = null, $id = null, $class = null, $attr = null, $responsiveSizes = []){ $file = (array) $file; $fileType = $this->mediaManager->checkFile($file["fileType"]); $class = ($fileType != "image") ? ($class === null) ? "svgIcon" : " svgIcon" : $class; $fileType = ($fileType == "file") ? $this->mediaManager->getFileType($file["fileType"]) : $fileType; $srcset = null; /*if( !empty($responsiveSizes) ){ $srcset = 'srcset="'; foreach($responsiveSizes as $imageSize => $layoutWidth){ $srcsetImage = $this->getFileName($file["basicUrl"], $imageSize); $srcset .= " ".$srcsetImage." ".$layoutWidth.","; } $srcset .= '"'; }*/ if( isset($file["basicUrl"]) ){ $file["url"] = $file["basicUrl"]; } $fileUrl = ($fileType != "image") ? "/adminFiles/imgs/mediaIcon-".$fileType.'.svg' : $this->getFileName($file["url"], $size); $fileAlt = ( !empty($file["alt"]) ) ? $file["alt"] : $file["title"]; $idTag = ($id !== null) ? 'id="'.$id.'"' : ''; $classTag = ($class !== null) ? 'class="'.$class.'"' : ''; $attrTag = ($attr !== null) ? $attr : ''; $imageTag = "{$fileAlt}"; return $imageTag; } public function adminThumbnail($file, $size = null, $id = null, $class = null, $attr = null, $responsiveSizes = []){ $file = (array) $file; $fileSubName = (!empty($file["title"])) ? $file["title"] : $file["alt"]; $fileSubName = (!empty($fileSubName)) ? $fileSubName : substr(strrchr(stripslashes($file["url"]), "/"), 1); if( isset($file["basicUrl"]) ){ $file["url"] = $file["basicUrl"]; } $fileSize = ( !empty($file["fileSize"]) ) ? $file["fileSize"] : filesize(UPLOAD_DIR.$file["url"]); // Size in bytes $checkSize = true; $sizeAttach = [0 => "B", 1 => "kB", 2 => "MB", 3 => "GB"]; $attach = 0; do{ $reducedSize = $fileSize / 1024; if($reducedSize > 1024){ $fileSize = $reducedSize; $attach++; }else{ $checkSize = false; $attach++; $fileSize = round($reducedSize, 2)." ".$sizeAttach[$attach]; } }while($checkSize === true); $returnThumbnail = $this->createImage($file, $size, $id, $class, $attr, $responsiveSizes); $returnThumbnail .= ''; $returnThumbnail .= $fileSubName; $returnThumbnail .= ''; return $returnThumbnail; } }imageEntity($data); } public function __toString(){ return get_class($this); } /* ================== Application functions === */ public function getMedia(){ return $this->mediaEntity; } private function imageEntity($data){ $object = new imageEntity($data["id"], $data["url"], $data["langShort"]); if( isset($data["objectId"]) && !empty($data["objectId"]) ){ $object->objectId($data["objectId"]); } if( isset($data["template"]) && !empty($data["template"]) ){ $object->template($data["template"]); } if( isset($data["head"]) && !empty($data["head"]) ){ $object->head($data["head"]); } if( isset($data["grouped"]) && !empty($data["grouped"]) ){ $object->grouped($data["grouped"]); } if( isset($data["duplicated"]) && !empty($data["duplicated"]) ){ $object->duplicated($data["duplicated"]); } if( isset($data["title"]) && !empty($data["title"]) ){ $object->title($data["title"]); } if( isset($data["alt"]) && !empty($data["alt"]) ){ $object->alt($data["alt"]); } if( isset($data["fileType"]) && !empty($data["fileType"]) ){ $object->fileType($data["fileType"]); } if( isset($data["folder"]) && !empty($data["folder"]) ){ $object->folder($data["folder"]); } if( isset($data["orderNum"]) && !empty($data["orderNum"]) ){ $object->orderNum($data["orderNum"]); } if( isset($data["createdDate"]) && !empty($data["createdDate"]) ){ $object->createdDate($data["createdDate"]); } if( isset($data["updatedDate"]) && !empty($data["updatedDate"]) ){ $object->updatedDate($data["updatedDate"]); } if( isset($data["fileName"]) && !empty($data["fileName"]) ){ $object->fileName($data["fileName"]); } if( isset($data["basicUrl"]) && !empty($data["basicUrl"]) ){ $object->basicUrl($data["basicUrl"]); } $this->mediaEntity = $object; } }= 0 && $transparency < $palletsize) { $transparent_color = imagecolorsforindex($image, $transparency); $transparency = imagecolorallocate($image_resized, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']); imagefill($image_resized, 0, 0, $transparency); imagecolortransparent($image_resized, $transparency); } elseif ($info[2] == IMAGETYPE_PNG) { imagealphablending($image_resized, false); $color = imagecolorallocatealpha($image_resized, 0, 0, 0, 127); imagefill($image_resized, 0, 0, $color); imagesavealpha($image_resized, true); } } imagecopyresampled($image_resized, $image, 0, 0, $cropWidth, $cropHeight, $final_width, $final_height, $width_old - 2 * $cropWidth, $height_old - 2 * $cropHeight); # Taking care of original, if needed if ( $delete_original ) { if ( $use_linux_commands ) exec('rm '.$file); else @unlink($file); } # Preparing a method of providing result switch ( strtolower($output) ) { case 'browser': $mime = image_type_to_mime_type($info[2]); header("Content-type: $mime"); $output = NULL; break; case 'file': $output = $file; break; case 'return': return $image_resized; break; default: break; } # Writing image according to type to the output destination and image quality switch ( $info[2] ) { case IMAGETYPE_GIF: imagegif($image_resized, $output); break; case IMAGETYPE_JPEG: imagejpeg($image_resized, $output, $quality); break; case IMAGETYPE_PNG: $quality = 9 - (int)((0.9*$quality)/10.0); imagepng($image_resized, $output, $quality); break; default: return false; } return true; } }id = $id; $this->url = $url; $this->langShort = $langShort; } /* ================== Object functions === */ public function objectId($value = null){ if( !empty($value) ){ $this->objectId = $value; } } public function template($value = null){ if( !empty($value) ){ $this->template = $value; } } public function head($value = null){ if( !empty($value) ){ $this->head = $value; } } public function grouped($value = null){ if( !empty($value) ){ $this->grouped = $value; } } public function title($value = null){ if( !empty($value) ){ $this->title = $value; } } public function alt($value = null){ if( !empty($value) ){ $this->alt = $value; } } public function createdDate($value = null){ if( !empty($value) ){ $this->createdDate = $value; } } public function updatedDate($value = null){ if( !empty($value) ){ $this->updatedDate = $value; } } public function fileName($value = null){ if( !empty($value) ){ $this->fileName = $value; } } public function basicUrl($value = null){ if( !empty($value) ){ $this->basicUrl = $value; } } public function duplicated($value = null){ if( !empty($value) ){ $this->duplicated = $value; } } public function orderNum($value = null){ if( !empty($value) ){ $this->orderNum = $value; } } public function fileType($value = null){ if( !empty($value) ){ $this->fileType = $value; } } public function folder($value = null){ if( !empty($value) ){ $this->folder = $value; } } }connect !== null){ return $this->connect; } $this->connect = $connect; $this->langEngine = new languageModule($this->connect); $this->translateEngine = new translateClass($this->langEngine); $this->dataTable = databaseTables::getTable("mediaManager", "folderTable"); } public function __toString(){ return get_class($this); } /* ================== Application functions === */ // Check possible translation public function translateResult($langShort, $defaultData, $loop = true){ $returnData = []; if(!empty($defaultData)){ if( $loop === true){ $translateData = []; foreach($defaultData as $categoryData){ $translate = $this->translateEngine->checkExistingTranslationObject($categoryData["id"], $this->translateType, $langShort, $categoryData); $translateData[] = ( !empty($translate) ) ? $translate : $categoryData; } $returnData = $translateData; }else{ $translate = $this->translateEngine->checkExistingTranslationObject($defaultData["id"], $this->translateType, $langShort, $defaultData); $returnData = ( !empty($translate) ) ? $translate : $defaultData; } } return $returnData; } // Check if name exist public function checkIfNameExist($filename, $extension, $rowFilename, $uploadFolder){ $nameExist = $this->findNameInTable($uploadFolder.$filename); if($nameExist === true){ $i = 1; do{ $filename = $rowFilename.$i.".".$extension; $nameExist = $this->findNameInTable($uploadFolder.$filename); $i++; }while($nameExist === true); } return $filename; } /* ================== Functions for work with data === */ // Select all folders public function getAllFolders($langShort){ $sql = "SELECT * FROM `{$this->dataTable}`;"; $returnData = $this->connect->getQuery($sql, null, true); $returnData = $this->translateResult($langShort, $returnData, true); return $returnData; } // Select one folder public function getOneFolderById($id, $langShort){ $sql = "SELECT * FROM `{$this->dataTable}` WHERE id = :id;"; $returnData = $this->connect->getQuery($sql, array("id" => $id), false); $returnData = $this->translateResult($langShort, $returnData, false); return $returnData; } // Select all folders by parent id public function getAllFoldersByParent($langShort, $parentId){ $sql = "SELECT * FROM `{$this->dataTable}` WHERE parentId = :parentId;"; $returnData = $this->connect->getQuery($sql, array("parentId" => $parentId), true); $returnData = $this->translateResult($langShort, $returnData, true); return $returnData; } // Select all folders and bredcrumbs for adminstration public function getAllFoldersInfo($langShort, $parentId){ $folderRoute = []; $allFolders = $this->getAllFoldersByParent($langShort, $parentId); $folderInfo = $this->getOneFolderById($parentId, $langShort); if(!empty($folderInfo)){ $folderRoute[] = $folderInfo; $lastFolder = $folderInfo; do{ $folderInfo = $this->getOneFolderById($folderInfo["parentId"], $langShort); if(!empty($folderInfo)){ $folderRoute[] = $folderInfo; } }while($folderInfo["parentId"] != 0 OR !empty($folderInfo)); } $lastFolder = (isset($lastFolder)) ? $lastFolder : $folderInfo; return ["allFolders" => $allFolders, "folderRoute" => array_reverse($folderRoute), "activeFolder" => $lastFolder]; } // Delete folder public function deleteFolder($folderId){ $sql = "DELETE FROM `{$this->dataTable}`"; $whereSql = "WHERE id = :id"; $removeFolder = $this->connect->deleteQuery($sql, array("id" => $folderId), $whereSql); $sql = "DELETE FROM `{$this->translateEngine->translationsTable}`"; $whereSql = "WHERE objectId = :id AND objectType = :type"; $removeTranslate = $this->connect->deleteQuery($sql, array("id" => $folderId, "type" => $this->translateType), $whereSql); return $removeFolder; } // Edit file in database public function editFile($langValues, $whereValues = null){ $sql = "UPDATE `{$this->languagesTable}`"; $whereSql = "WHERE id = :id"; $returnData = $this->connect->updateQuery($sql, $langValues, $whereValues, $whereSql); return $returnData; } } "Media manager", "moduleUrlName" => "mediaManager", "moduleLangName" => "mediaManager", "moduleIcon" => "fa-file-image-o", "moduleVersion" => "3.1", "modulePaginationLimit" => "30", "modulePages" => array( array( "pageId" => 1, "urlName" => "media-list", "url" => "media-list", "parent" => 0, "inMenu" => 1, "headPage" => 1 ), array( "pageId" => 2, "urlName" => "upload-media", "url" => "upload-media", "parent" => 1, "inMenu" => 0, "headPage" => 0 ) ) ); ?>connect !== null){ return $this->connect; } $this->connect = $connect; $this->basicSettings = $this->getModuleSettings("", true); $this->buildNum = $this->getBuild(); $this->settingsTable = databaseTables::getTable("settings", "settingTable"); } public function __toString(){ return get_class($this); } /* ================== Application functions === */ // Re-group settings as Array public function reGroupSettings($allData){ $allSettings = []; if($allData){ foreach ($allData as $eachSettings) { $allSettings[$eachSettings["settName"]] = $eachSettings["settValue"]; } } return $allSettings; } // Get app build (for cache assets) private function getBuild(){ $sql = "SELECT * FROM `{$this->settingsTable}` WHERE settName = 'buildNum';"; $buildNum = $this->connect->getQuery($sql, null, false); return $buildNum["settValue"]; } public function updateBuild(){ $updateBuild = $this->editSettings(["buildNum" => $this->buildNum+1], "settings"); return $updateBuild; } /* ================== Functions for work with data === */ // Load all settings public function getSettings($reGroup = true){ $sql = "SELECT * FROM `{$this->settingsTable}` ORDER BY moduleName;"; $returnData = $this->connect->getQuery($sql, null, true); $allSettings = ($reGroup === true) ? $this->reGroupSettings($returnData) : $returnData; return $allSettings; } // Load all settings by moduleName public function getModuleSettings($moduleName, $reGroup = true){ $sql = "SELECT * FROM `{$this->settingsTable}` WHERE moduleName = :moduleName;"; $returnData = $this->connect->getQuery($sql, array("moduleName" => $moduleName), true); $allSettings = ($reGroup === true) ? $this->reGroupSettings($returnData) : $returnData; return $allSettings; } // Load all settings by settGroup public function getGroupedSettings($settGroup, $reGroup = true){ $sql = "SELECT * FROM `{$this->settingsTable}` WHERE settGroup = :settGroup;"; $returnData = $this->connect->getQuery($sql, array("settGroup" => $settGroup), true); $allSettings = ($reGroup === true) ? $this->reGroupSettings($returnData) : $returnData; return $allSettings; } // Edit settings public function editSettings($settingsData, $moduleName = ""){ $sql = "UPDATE `{$this->settingsTable}`"; $whereSql = "WHERE settName = :settName AND moduleName = :moduleName"; foreach($settingsData as $settName => $settValue){ $returnData = $this->connect->updateQuery($sql, array("settValue" => $settValue, "updatedDate" => date("Y-m-d H:i:s")), array("settName" => $settName, "moduleName" => $moduleName), $whereSql); if($returnData !== true){ return false; } } return true; } }connect !== null){ return $this->connect; } $this->connect = $connect; $this->lastLog = $this->getLastLog(); $this->logsTable = databaseTables::getTable("settings", "logTable"); } public function __toString(){ return get_class($this); } /* ================== Functions for work with data === */ // Create log with action private function getLastLog(){ $sql = "SELECT * FROM `{$this->logsTable}` ORDER BY logTime DESC;"; $returnData = $this->connect->getQuery($sql, null, true); return $returnData; } // Create log with action public function createLog($langShort, $logType, $logAction, $objectId, $userId){ $logValues = [ "langShort" => $langShort, "logType" => $logType, "logAction" => $logAction, "objectId" => $objectId, "userId" => $userId, "logTime" => date("Y-m-d H:i:s") ]; $sql = "INSERT INTO `{$this->logsTable}`"; $returnData = $this->connect->insertQuery($sql, $logValues); if( $returnData > 0 ){ $this->lastLog = $returnData; return true; }else{ return false; } } } "Settings", "moduleUrlName" => "settings", "moduleLangName" => "settings", "moduleIcon" => "fa-cogs", "moduleVersion" => "3.0", "modulePages" => array( array( "pageId" => 1, "urlName" => "settings-edit", "url" => "settings-edit", "parent" => 0, "inMenu" => 1, "headPage" => 1 ), array( "pageId" => 2, "urlName" => "settings-config", "url" => "settings-config", "parent" => 0, "inMenu" => 1, "headPage" => 0 ) ) ); ?>connect !== null){ return $this->connect; } $this->connect = $connect; $this->langEngine = new languageModule($this->connect); $this->translateEngine = new translateClass($this->langEngine); $this->slidesTable = databaseTables::getTable("slideshow", "slideshowTable"); $this->slidesGroupsTable = databaseTables::getTable("slideshow", "groupTable"); } public function __toString(){ return get_class($this); } // Check possible translation public function translateResult($langShort, $defaultData, $loop = true){ $returnData = []; if(!empty($defaultData)){ if( $loop === true){ $translateData = []; foreach($defaultData as $categoryData){ $translate = $this->translateEngine->checkExistingTranslationObject($categoryData["id"], $this->translateType, $langShort, $categoryData); $translateData[] = ( !empty($translate) ) ? $translate : $categoryData; } $returnData = $translateData; }else{ $translate = $this->translateEngine->checkExistingTranslationObject($defaultData["id"], $this->translateType, $langShort, $defaultData); $returnData = ( !empty($translate) ) ? $translate : $defaultData; } } return $returnData; } /* ================== Application functions === */ // Add IMAGES public function reCreate($allData){ if( !empty($allData) ){ $newPostArray = []; foreach($allData as $key => $info){ $newPostArray[$key] = $this->optimalize($info); } return $newPostArray; }else{ return $allData; } } public function optimalize($info){ $langType = $_SESSION["languages"]["appLang"]; $mediaManager = new mediaManager($this->connect); $optimalised = $info; // Add images $allImages = $mediaManager->getAllRelatedImagesSerialized($info["id"], $this->mediaInfoName, $langType, ""); if($allImages){ foreach($allImages as $key => $image){ if($key == 0){ $optimalised["images"]["head"] = (array) $image; }else{ $optimalised["images"]["other"][] = (array) $image; } } } // Return return $optimalised; } /* ================== TRANSLATE functions === */ // Select all slides public function getAllSlides($langShort){ $sql = "SELECT * FROM `{$this->slidesTable}`;"; $returnData = $this->connect->getQuery($sql, null, true); $returnData = $this->translateResult($langShort, $returnData, true); return $returnData; } // Select one slide public function getOneSlideById($id, $langShort){ $sql = "SELECT * FROM `{$this->slidesTable}` WHERE id = :id;"; $returnData = $this->connect->getQuery($sql, array("id" => $id), false); $returnData = $this->translateResult($langShort, $returnData, false); return $returnData; } // Select all slides by group public function getAllSlidesByGroup($langShort, $groupId){ $sql = "SELECT * FROM `{$this->slidesTable}` WHERE groupId = :groupId ORDER BY orderNum ASC;"; $returnData = $this->connect->getQuery($sql, array("groupId" => $groupId), true); $returnData = $this->translateResult($langShort, $returnData, true); return $returnData; } // Select all visible slides by group public function getAllVisibleSlidesByGroup($langShort, $groupId){ $sql = "SELECT * FROM `{$this->slidesTable}` WHERE groupId = :groupId AND visibility = 1 ORDER BY orderNum ASC;"; $returnData = $this->connect->getQuery($sql, array("groupId" => $groupId), true); $returnData = $this->translateResult($langShort, $returnData, true); return $returnData; } // Select all visible slides by group public function getAllVisibleSlidesByClassName($langShort, $className){ $sql = "SELECT * FROM `{$this->slidesTable}` WHERE className = :className AND visibility = 1 ORDER BY orderNum ASC;"; $returnData = $this->connect->getQuery($sql, array("className" => $className), true); $returnData = $this->translateResult($langShort, $returnData, true); return $returnData; } // Select all slider GROUPED by group public function getAllSlidesGrouped($langShort){ $sql = "SELECT * FROM `{$this->slidesTable}` ORDER BY groupId, orderNum ASC;"; $returnData = $this->connect->getQuery($sql, null, true); $returnData = $this->translateResult($langShort, $returnData, true); return $returnData; } // Select all slider groups public function getAllSlidesGroups($langShort){ $sql = "SELECT * FROM `{$this->slidesGroupsTable}`;"; $returnData = $this->connect->getQuery($sql, null, true); $returnData = $this->translateResult($langShort, $returnData, true); return $returnData; } // Select all slider groups as SELECTBOX public function sliderGroupsAsSelectBox($langShort, $groupId){ $returnData = $this->getAllSlidesGroups($langShort); $slideSelect = null; foreach ($returnData as $group){ $selected = ($groupId == $group["groupId"]) ? "selected" : "" ; $slideSelect .= ''; } return $slideSelect; } // Select one slide public function getOneSlideGroup($id, $langShort){ $sql = "SELECT * FROM `{$this->slidesGroupsTable}` WHERE groupId = :groupId;"; $returnData = $this->connect->getQuery($sql, array("groupId" => $id), false); $returnData = $this->translateResult($langShort, $returnData, false); return $returnData; } } "Slideshow", "moduleUrlName" => "slideshow", "moduleLangName" => "slideshow", "moduleIcon" => "fa-picture-o", "moduleVersion" => "2.1", "mediaSettings" => array( "slideshow" => "slideshow" ), "modulePages" => array( array( "pageId" => 1, "urlName" => "slideshow", "url" => "slideshow", "parent" => 0, "inMenu" => 1, "headPage" => 1 ),array( "pageId" => 2, "urlName" => "edit-slideshow", "url" => "edit-slideshow", "parent" => 1, "inMenu" => 0, "headPage" => 0 ) ) ); ?>createTemplate($templateData); } public function __toString(){ return get_class($this); } /* ================== Application functions === */ public function getTemplate(){ return $this->template; } private function createTemplate($templateData){ $object = new templateEntity($templateData["id"], $templateData["title"], $templateData["url"], $templateData["templateName"], $templateData["langShort"]); if( isset($templateData["shortDesc"]) && !empty($templateData["shortDesc"]) ){ $object->shortDesc($templateData["shortDesc"]); } if( isset($templateData["description"]) && !empty($templateData["description"]) ){ $object->description($templateData["description"]); } if( isset($templateData["metaKeywords"]) && !empty($templateData["metaKeywords"]) ){ $object->metaKeywords($templateData["metaKeywords"]); } if( isset($templateData["metaTitle"]) && !empty($templateData["metaTitle"]) ){ $object->metaTitle($templateData["metaTitle"]); } if( isset($templateData["metaDescription"]) && !empty($templateData["metaDescription"]) ){ $object->metaDescription($templateData["metaDescription"]); } if( isset($templateData["allowIndex"]) && !empty($templateData["allowIndex"]) ){ $object->allowIndex($templateData["allowIndex"]); } if( isset($templateData["urlPrefix"]) && !empty($templateData["urlPrefix"]) ){ $object->urlPrefix($templateData["urlPrefix"]); } if( isset($templateData["pageType"]) && !empty($templateData["pageType"]) ){ $object->pageType($templateData["pageType"]); } if( isset($templateData["moduleName"]) && !empty($templateData["moduleName"]) ){ $object->moduleName($templateData["moduleName"]); } if( isset($templateData["pageSidebar"]) && !empty($templateData["pageSidebar"]) ){ $object->pageSidebar($templateData["pageSidebar"]); } if( isset($templateData["pageTopMenu"]) && !empty($templateData["pageTopMenu"]) ){ $object->pageTopMenu($templateData["pageTopMenu"]); } if( isset($templateData["youtubeUrl"]) && !empty($templateData["youtubeUrl"]) ){ $object->youtubeUrl($templateData["youtubeUrl"]); } if( isset($templateData["createdDate"]) && !empty($templateData["createdDate"]) ){ $object->createdDate($templateData["createdDate"]); } if( isset($templateData["updatedDate"]) && !empty($templateData["updatedDate"]) ){ $object->updatedDate($templateData["updatedDate"]); } if( isset($templateData["visibility"]) && !empty($templateData["visibility"]) ){ $object->visibility($templateData["visibility"]); } if( isset($templateData["className"]) && !empty($templateData["className"]) ){ $object->className($templateData["className"]); } if( isset($templateData["images"]) && !empty($templateData["images"]) ){ $object->images($templateData["images"]); } $this->template = $object; } }title = $title; $this->templateName = $templateName; parent::__construct($id); $this->langShort = $langShort; $this->url = $url; } /* ================== Object functions === */ public function title(){ return $this->title; } public function shortDesc($value = null){ if( empty($value) OR !empty($this->shortDesc) ){ return $this->shortDesc; }else{ $this->shortDesc = $value; return true; } } public function description($value = null){ if( empty($value) OR !empty($this->description) ){ return $this->description; }else{ $this->description = $value; return true; } } public function templateName(){ return $this->templateName; } public function pageType(){ return $this->pageType; } public function moduleName($value){ if( empty($value) OR !empty($this->moduleName) ){ return $this->moduleName; }else{ $this->moduleName = $value; return true; } } public function pageSidebar(){ return $this->pageSidebar; } public function pageTopMenu(){ return $this->pageTopMenu; } public function youtubeUrl($value = null){ if( empty($value) OR !empty($this->youtubeUrl) ){ return $this->youtubeUrl; }else{ $this->youtubeUrl = $value; return true; } } public function className($value = null){ if( empty($value) OR !empty($this->className) ){ return $this->className; }else{ $this->className = $value; return true; } } public function images($value = null){ if( empty($value) OR !empty($this->images) ){ return $this->images; }else{ $this->images = (array) $value; return true; } } }connect !== null){ return $this->connect; } $this->connect = $moduleLoader->connect; $this->prefixesTable = databaseTables::getTable("templates", "prefixTable"); } public function __toString(){ return get_class($this); } /* ================== Application functions === */ // Create URL public function title2pagename($title){ static $convertTable = array ( 'á' => 'a', 'Á' => 'A', 'ä' => 'a', 'Ä' => 'A', 'č' => 'c', 'Č' => 'C', 'ď' => 'd', 'Ď' => 'D', 'é' => 'e', 'É' => 'E', 'ě' => 'e', 'Ě' => 'E', 'ë' => 'e', 'Ë' => 'E', 'í' => 'i', 'Í' => 'I', 'ï' => 'i', 'Ï' => 'I', 'ľ' => 'l', 'Ľ' => 'L', 'ĺ' => 'l', 'Ĺ' => 'L', 'ň' => 'n', 'Ň' => 'N', 'ń' => 'n', 'Ń' => 'N', 'ó' => 'o', 'Ó' => 'O', 'ö' => 'o', 'Ö' => 'O', 'ř' => 'r', 'Ř' => 'R', 'ŕ' => 'r', 'Ŕ' => 'R', 'š' => 's', 'Š' => 'S', 'ś' => 's', 'Ś' => 'S', 'ť' => 't', 'Ť' => 'T', 'ú' => 'u', 'Ú' => 'U', 'ů' => 'u', 'Ů' => 'U', 'ü' => 'u', 'Ü' => 'U', 'ý' => 'y', 'Ý' => 'Y', 'ÿ' => 'y', 'Ÿ' => 'Y', 'ž' => 'z', 'Ž' => 'Z', 'ź' => 'z', 'Ź' => 'Z', ); $title = strtolower(strtr($title, $convertTable)); $title = preg_replace('/[^a-zA-Z0-9]+/u', '-', $title); $title = str_replace('--', '-', $title); $title = trim($title, '-'); return $title; } // Return unique prefix public function createPrefix() { do{ $prefixNum = $this->controlPrefix($this->generatePrefix()); }while($prefixNum === false ); return $prefixNum; } // Generate random prefix number public function generatePrefix() { $randNum = mt_rand($this->prefixMin, $this->prefixMax); return $randNum; } // Check if prefix exist public function controlPrefix($prefixNum) { $sql = "SELECT * FROM `{$this->prefixesTable}` WHERE urlPrefix = :urlPrefix;"; $returnData = $this->connect->getQuery($sql, array("urlPrefix" => $prefixNum), true); return ( empty($returnData) ) ? $prefixNum : false; } // Add new prefix into database public function addNewPrefix($objectTable){ $prefix = $this->createPrefix(); $sql = "INSERT INTO `{$this->prefixesTable}`"; $returnData = $this->connect->insertQuery($sql, array("urlPrefix" => $prefix, "contentTable" => $objectTable) ); $return = ($returnData === 0) ? false : $prefix; return $return; } // Delete prefix public function clearPrefixes(){ $sql = "SELECT * FROM `{$this->prefixesTable}`"; $prefixes = $this->connect->getQuery($sql, null, true); foreach($prefixes as $prefix){ $table = $prefix["contentTable"]; $sql = "SELECT * FROM `{$table}` WHERE urlPrefix = :urlPrefix;"; $returnData = $this->connect->getQuery($sql, array("urlPrefix" => $prefix["urlPrefix"]), true); if( empty($returnData) ){ $sql = "DELETE FROM `{$this->prefixesTable}`"; $whereSql = "WHERE urlPrefix = :urlPrefix"; $returnData = $this->connect->deleteQuery($sql, array("urlPrefix" => $prefix["urlPrefix"]), $whereSql); } } return true; } } false, 2 => true, 3 => null]; // URL CONTENT (www.XXX.xx/template/URL-CONTENT) > true = MUST; false = MUST NOT; null = BOTH (blog) public function __construct(Connect $connect) { if($this->connect !== null){ return $this->connect; } $this->connect = $connect; $this->templatesTable = databaseTables::getTable("templates", "templateTable"); $this->templatesLangTable = databaseTables::getTable("templates", "templateTableLang"); } public function __toString(){ return get_class($this); } /* ================== Application functions === */ // Get all URL addresses from templates public function getAllTemplateAnchors($lang){ $sql = "SELECT templates.*, translations.* FROM `{$this->templatesTable}` AS templates INNER JOIN `{$this->templatesLangTable}` AS translations ON templates.id = translations.associatedId WHERE langShort = :langShort;"; $allTemplates = $this->connect->getQuery($sql, array("langShort" => $lang), true); $allAnchors = []; if($allTemplates){ foreach($allTemplates as $template){ $allAnchors[$template["templateName"]] = $template["url"]; } } return $allAnchors; } public function optimalize($templateInfo){ $langType = $_SESSION["languages"]["appLang"]; $allAnchors = $this->getAllTemplateAnchors($langType); $newInfo = $templateInfo; $mediaManager = new mediaManager($this->connect); // Add images $allImages = $mediaManager->getAllRelatedImagesSerialized($templateInfo["id"], $this->mediaInfoName, $langType, ""); if($allImages){ foreach($allImages as $key => $image){ if($key == 0){ $newInfo["images"]["head"] = (array) $image; }else{ $newInfo["images"]["other"][] = (array) $image; } } } // Return return $newInfo; } /* ================== Functions for work with data === */ // Get all templates public function getAllTemplates($lang){ $sql = "SELECT translations.*, templates.* FROM `{$this->templatesTable}` AS templates INNER JOIN `{$this->templatesLangTable}` AS translations ON templates.id = translations.associatedId AND translations.langShort = :langShort;"; $queryData = $this->connect->getQuery($sql, array("langShort" => $lang), true); return $queryData; } // Get all visible templates public function getAllVisibleTemplates($lang){ $sql = "SELECT translations.*, templates.* FROM `{$this->templatesTable}` AS templates INNER JOIN `{$this->templatesLangTable}` AS translations ON templates.id = translations.associatedId WHERE templates.visibility = 1 AND translations.langShort = :langShort;"; $queryData = $this->connect->getQuery($sql, array("langShort" => $lang), true); return $queryData; } // Get one template by ID public function getTemplateInfoById($templateId, $lang, $checkVisibility = false){ $sql = "SELECT translations.*, templates.* FROM `{$this->templatesTable}` AS templates INNER JOIN `{$this->templatesLangTable}` AS translations ON templates.id = translations.associatedId WHERE templates.id = :id AND translations.langShort = :langShort;"; $returnData = $this->connect->getQuery($sql, array("id" => $templateId, "langShort" => $lang), false); $returnObject = ($checkVisibility !== true) ? $returnData : ( ($returnData["visibility"] == 1) ? $returnData : array() ); return $returnObject; } // Get one template by TEMPLATE NAME public function getTemplateInfoByName($templateName, $lang, $checkVisibility = false){ $sql = "SELECT translations.*, templates.* FROM `{$this->templatesTable}` AS templates INNER JOIN `{$this->templatesLangTable}` AS translations ON templates.id = translations.associatedId WHERE templates.templateName = :templateName AND translations.langShort = :langShort"; $returnData = $this->connect->getQuery($sql, array("templateName" => $templateName, "langShort" => $lang), false); $returnObject = ($checkVisibility !== true) ? $returnData : ( ($returnData["visibility"] == 1) ? $returnData : array() ); return $returnObject; } // Get one template by URL public function getTemplateInfoByUrl($templateUrl, $lang, $checkVisibility = false){ $sql = "SELECT translations.*, templates.* FROM `{$this->templatesTable}` AS templates INNER JOIN `{$this->templatesLangTable}` AS translations ON templates.id = translations.associatedId WHERE translations.url = :url AND translations.langShort = :langShort;"; $returnData = $this->connect->getQuery($sql, array("url" => $templateUrl, "langShort" => $lang), false); $returnObject = ($checkVisibility !== true) ? $returnData : ( ($returnData["visibility"] == 1) ? $returnData : array() ); return $returnObject; } }title) || empty($pageData->id) ){ return false; } $this->lastTitle = $pageData->title; $this->lastUrl = ( isset($pageData->url) ) ? $pageData->url : null; $this->lastPrefix = ( isset($pageData->urlPrefix) ) ? $pageData->urlPrefix : null; $this->lastId = $pageData->id; $this->lastTemplate = ( isset($template) ) ? $template : null; $this->breadCrumbs[] = (object) [ "id" => $this->lastId, "title" => $this->lastTitle, "urlPrefix" => $this->lastPrefix, "url" => $this->lastUrl, "urlComplete" => ($this->lastPrefix !== null) ? $this->lastPrefix."-".$this->lastUrl : $this->lastUrl, "template" => $this->lastTemplate ]; } public function get(){ return $this->breadCrumbs; } public function getReverse(){ return array_reverse($this->get()); } public function removeLastBread(){ $count = count($this->breadCrumbs); unset($this->breadCrumbs[$count-1]); } public function getLast(){ $count = count($this->breadCrumbs); return $this->breadCrumbs[$count-1]; } public function removeAll(){ $this->breadCrumbs = []; } } "Templates", "moduleUrlName" => "templates", "moduleLangName" => "templates", "moduleIcon" => "fa-file", "moduleVersion" => "3.2", "mediaSettings" => array( "template" => "template" ), "modulePages" => array( array( "pageId" => 1, "urlName" => "templates-list", "url" => "templates-list", "parent" => 0, "inMenu" => 1, "headPage" => 1 ), array( "pageId" => 2, "urlName" => "template-detail", "url" => "template-detail", "parent" => 1, "inMenu" => 0, "headPage" => 0 ) ) ); ?>