/** * * init gallery by it's folder */ public function initByFolder($folderName) { $pathGallery = GlobalsUG::$pathGalleries . $folderName . "/"; if (is_dir($pathGallery) == false) { UniteFunctionsUG::throwError("Gallery {$folderName} not exists in gallery folder"); } $this->pathGallery = $pathGallery; $filepathConfig = $pathGallery . "config.xml"; if (file_exists($filepathConfig) == false) { UniteFunctionsUG::throwError("{$folderName} gallery config file not exists. "); } $this->folderName = $folderName; $this->filepathXmlFile = $filepathConfig; $this->initDataFromXml(); }
/** * get settings defaults by thumbs panel position */ public static function getDefautlsByPosition($pos) { $pos = strtolower($pos); if ($pos == "") { $pos = "bottom"; } switch ($pos) { case "top": return self::getDefaultsTop(); break; case "bottom": return self::getDefaultsBottom(); break; case "left": return self::getDefautsLeft(); break; case "right": return self::getDefaultsRight(); break; default: UniteFunctionsUG::throwError("Wrong position: {$pos}"); break; } }
/** * create thumbs from image by url * the image must be relative path to the platform base */ public function createThumbs($urlImage, $thumbWidth = null) { if ($thumbWidth === null) { $thumbWidth = GlobalsUG::THUMB_WIDTH; } $urlImage = HelperUG::URLtoRelative($urlImage); $info = HelperUG::getImageDetails($urlImage); //check thumbs path $pathThumbs = $info["path_thumbs"]; if (!is_dir($pathThumbs)) { @mkdir($pathThumbs); } if (!is_dir($pathThumbs)) { UniteFunctionsUG::throwError("Can't make thumb folder: {$pathThumbs}. Please check php and folder permissions"); } $filepathImage = $info["filepath"]; $filenameThumb = $this->imageView->makeThumb($filepathImage, $pathThumbs, $thumbWidth); $urlThumb = ""; if (!empty($filenameThumb)) { $urlThumbs = $info["url_dir_thumbs"]; $urlThumb = $urlThumbs . $filenameThumb; } return $urlThumb; }
/** * build javascript param */ protected function buildJsParam($paramName, $validate = null, $type = null) { if (array_key_exists($paramName, $this->arrJsParamsAssoc)) { UniteFunctionsUG::throwError("Unable to biuld js param: <b>{$paramName}</b> already exists"); } $output = array("name" => $paramName, "validate" => $validate, "type" => $type); $this->arrJsParamsAssoc[$paramName] = true; return $output; }
/** * * validate that the current gallery inited */ private static function validateInited() { if (empty(GlobalsUGGallery::$objGalleryType)) { UniteFunctionsUG::throwError("Gallery type not inited!"); } }
/** * * Update Plugin */ public static function updatePlugin() { try { //verify nonce: $nonce = UniteFunctionsUG::getPostVariable("nonce"); $isVerified = wp_verify_nonce($nonce, "unitegallery_actions"); if ($isVerified == false) { UniteFunctionsUG::throwError("Security error"); } $linkBack = HelperUG::getGalleriesView(); $htmlLinkBack = UniteFunctionsUG::getHtmlLink($linkBack, "Go Back"); //check if zip exists $zip = new UniteZipUG(); if (function_exists("unzip_file") == false) { if (UniteZipUG::isZipExists() == false) { UniteFunctionsUG::throwError("The ZipArchive php extension not exists, can't extract the update file. Please turn it on in php ini."); } } dmp("Update in progress..."); $arrFiles = UniteFunctionsUG::getVal($_FILES, "update_file"); if (empty($arrFiles)) { UniteFunctionsUG::throwError("Update file don't found."); } $filename = UniteFunctionsUG::getVal($arrFiles, "name"); if (empty($filename)) { UniteFunctionsIG::throwError("Update filename not found."); } $fileType = UniteFunctionsUG::getVal($arrFiles, "type"); $fileType = strtolower($fileType); $arrMimeTypes = array(); $arrMimeTypes[] = "application/zip"; $arrMimeTypes[] = "application/x-zip"; $arrMimeTypes[] = "application/x-zip-compressed"; $arrMimeTypes[] = "application/octet-stream"; $arrMimeTypes[] = "application/x-compress"; $arrMimeTypes[] = "application/x-compressed"; $arrMimeTypes[] = "multipart/x-zip"; if (in_array($fileType, $arrMimeTypes) == false) { UniteFunctionsUG::throwError("The file uploaded is not zip."); } $filepathTemp = UniteFunctionsUG::getVal($arrFiles, "tmp_name"); if (file_exists($filepathTemp) == false) { UniteFunctionsUG::throwError("Can't find the uploaded file."); } //crate temp folder $pathTemp = GlobalsUG::$pathPlugin . "temp/"; UniteFunctionsUG::checkCreateDir($pathTemp); //create the update folder $pathUpdate = $pathTemp . "update_extract/"; UniteFunctionsUG::checkCreateDir($pathUpdate); if (!is_dir($pathUpdate)) { UniteFunctionsUG::throwError("Could not create temp extract path"); } //remove all files in the update folder $arrNotDeleted = UniteFunctionsUG::deleteDir($pathUpdate, false); if (!empty($arrNotDeleted)) { $strNotDeleted = print_r($arrNotDeleted, true); UniteFunctionsUG::throwError("Could not delete those files from the update folder: {$strNotDeleted}"); } //copy the zip file. $filepathZip = $pathUpdate . $filename; $success = move_uploaded_file($filepathTemp, $filepathZip); if ($success == false) { UniteFunctionsUG::throwError("Can't move the uploaded file here: " . $filepathZip . "."); } //extract files: if (function_exists("unzip_file") == true) { WP_Filesystem(); $response = unzip_file($filepathZip, $pathUpdate); } else { $zip->extract($filepathZip, $pathUpdate); } //check for internal zip in case that cocecanyon original zip was uploaded self::updatePlugin_checkUnpackInnerZip($pathUpdate, $filename); //get extracted folder $arrFolders = UniteFunctionsUG::getDirList($pathUpdate); if (empty($arrFolders)) { UniteFunctionsUG::throwError("The update folder is not extracted"); } //get product folder $productFolder = null; if (count($arrFolders) == 1) { $productFolder = $arrFolders[0]; } else { foreach ($arrFolders as $folder) { if ($folder != "documentation") { $productFolder = $folder; } } } if (empty($productFolder)) { UniteFunctionsUG::throwError("Wrong product folder."); } $pathUpdateProduct = $pathUpdate . $productFolder . "/"; //check some file in folder to validate it's the real one: $checkFilepath = $pathUpdateProduct . "unitegallery.php"; if (file_exists($checkFilepath) == false) { UniteFunctionsUG::throwError("Wrong update extracted folder. The file: " . $checkFilepath . " not found."); } //copy the plugin without the captions file. $pathOriginalPlugin = GlobalsUG::$pathPlugin; $arrBlackList = array(); UniteFunctionsUG::copyDir($pathUpdateProduct, $pathOriginalPlugin, "", $arrBlackList); //delete the update UniteFunctionsUG::deleteDir($pathUpdate); //change folder to original (if updated to full version) if ($productFolder == "unitegallery") { $pathRename = str_replace("unite-gallery-lite", "unitegallery", $pathOriginalPlugin); if ($pathRename != $pathOriginalPlugin) { $success = @rename($pathOriginalPlugin, $pathRename); if ($success == true) { //activate plugin $pluginFile = $pathRename . "unitegallery.php"; if (file_exists($pluginFile)) { $activateSuccess = UniteFunctionsWPUG::activatePlugin($pluginFile); if ($activateSuccess == false) { $linkBack = admin_url("plugins.php"); } //link to plugin activate } } } } dmp("Updated Successfully, redirecting..."); echo "<script>location.href='{$linkBack}'</script>"; } catch (Exception $e) { //remove all files in the update folder UniteFunctionsUG::deleteDir($pathUpdate); $message = $e->getMessage(); $message .= " <br> Please update the plugin manually via the ftp"; echo "<div style='color:#B80A0A;font-size:18px;'><b>Update Error: </b> {$message}</div><br>"; echo $htmlLinkBack; exit; } }
/** * export gallery settings to downloadable file */ public function exportSettings() { $this->validateInited(); $galleryID = $this->id; $record = $this->db->fetchSingle(GlobalsUG::$table_galleries, "id={$galleryID}"); UniteFunctionsUG::validateNotEmpty($record, "Gallery Record"); unset($record["id"]); $strRecord = serialize($record); $filename = "unitegallery_" . $record["alias"] . ".txt"; UniteFunctionsUG::downloadFileFromContent($strRecord, $filename); //the download content should exit UniteFunctionsUG::throwError("Something wrong witht the export, please try again"); exit; }
/** * get additional item insert data from media items */ private function getAddDataFromMedia($data, $arrInsert) { $params = array(); $contentID = ""; $type = UniteFunctionsUG::getVal($data, "type"); $content = UniteFunctionsUG::getVal($data, "description"); switch ($type) { case self::TYPE_YOUTUBE: case self::TYPE_VIMEO: case self::TYPE_WISTIA: $contentID = UniteFunctionsUG::getVal($data, "videoid"); break; case self::TYPE_HTML5VIDEO: $params["video_mp4"] = UniteFunctionsUG::getVal($data, "urlVideo_mp4"); $params["video_webm"] = UniteFunctionsUG::getVal($data, "urlVideo_webm"); $params["video_ogv"] = UniteFunctionsUG::getVal($data, "urlVideo_ogv"); break; default: UniteFunctionsUG::throwError("Wrong media type: " . $type); break; } $arrInsert["contentid"] = trim($contentID); $arrInsert["content"] = trim($content); if (!empty($params)) { $arrInsert["params"] = $params; } return $arrInsert; }
/** * * throw error */ private function throwError($message, $code = -1) { UniteFunctionsUG::throwError($message, $code); }
/** * call gallery action, include gallery framework first */ public static function onGalleryAjaxAction($typeName, $action, $data, $galleryID) { if (empty($data)) { $data = array(); } self::initGalleryFramework($typeName, $galleryID); $filepathAjax = GlobalsUGGallery::$pathBase . "ajax_actions.php"; UniteFunctionsUG::validateFilepath($filepathAjax, "Ajax request error: "); require $filepathAjax; UniteFunctionsUG::throwError("No ajax response from gallery: <b>{$typeName} </b> to action <b>{$action}</b>"); }
/** * output some gallery by alias * mixed - alias or id * outputType - can be alias or ID * arrItems - alternative items */ public static function outputGallery($mixed, $catID = null, $outputType = "alias", $arrItems = null) { try { if ($mixed instanceof UniteGalleryGallery) { $objGallery = $mixed; } else { //init the gallery enviropment $objGallery = new UniteGalleryGallery(); if ($outputType == "alias") { $objGallery->initByAlias($mixed); } else { $objGallery->initByID($mixed); } } $galleryID = $objGallery->getID(); $objType = $objGallery->getObjType(); GlobalsUGGallery::init($objType, $objGallery, $galleryID); $filepathOutput = GlobalsUGGallery::$pathBase . "client_output.php"; UniteFunctionsUG::validateFilepath($filepathOutput); //require the gallery includes $filepathIncludes = GlobalsUGGallery::$pathBase . "includes.php"; if (file_exists($filepathIncludes)) { require_once $filepathIncludes; } $arrOptions = array(); $arrOptions["categoryid"] = ""; if ($catID && is_numeric($catID) && $catID > 0) { $arrOptions["categoryid"] = $catID; } if ($arrItems !== null) { $arrOptions["items"] = $arrItems; } //run the output require $filepathOutput; if (!isset($uniteGalleryOutput)) { UniteFunctionsUG::throwError("uniteGalleryOutput variable not found"); } return $uniteGalleryOutput; } catch (Exception $e) { $message = "<b>Unite Gallery Error:</b><br><br> " . $e->getMessage(); $operations = new UGOperations(); $operations->putModuleErrorMessage($message); } }
/** * * update setting array by name */ public function updateArrSettingByName($name, $setting) { foreach ($this->arrSettings as $key => $settingExisting) { $settingName = UniteFunctionsUG::getVal($settingExisting, "name"); if ($settingName == $name) { $this->arrSettings[$key] = $setting; return false; } } UniteFunctionsUG::throwError("Setting with name: {$name} don't exists"); }
/** * * draw settings function * @param $drawForm draw the form yes / no */ public function draw($formID = null, $drawForm = false) { if (empty($formID)) { UniteFunctionsUG::throwError("The form ID can't be empty. you must provide it"); } $this->formID = $formID; ?> <div class="settings_wrapper unite_settings_wide"> <?php if ($drawForm == true) { ?> <form name="<?php echo $formID; ?> " id="<?php echo $formID; ?> "> <?php $this->drawSettings(); ?> </form> <?php } else { $this->drawSettings(); } ?> </div> <?php }
/** * import gallery settings from upload file */ public function importGallerySettingsFromUploadFile($galleryID) { $gallery = $this->getGalleryByID($galleryID); $arrFile = UniteFunctionsUG::getVal($_FILES, "export_file"); try { $linkBack = HelperUG::getAdvancedView($galleryID); $htmlLinkBack = UniteFunctionsUG::getHtmlLink($linkBack, "Go Back"); if (empty($arrFile)) { UniteFunctionsUG::throwError("Import file not found"); } //get content $filepath = UniteFunctionsUG::getVal($arrFile, "tmp_name"); $content = file_get_contents($filepath); //remove temp path @unlink($filepath); if (empty($content)) { UniteFunctionsUG::throwError("No content found"); } $arrContent = @unserialize($content); if (empty($arrContent)) { UniteFunctionsUG::throwError("No content format"); } $gallery->importSettings($arrContent); //redirect back to settings dmp("gallery settings imported, redirecting..."); UniteFunctionsUG::putRedirectJS($linkBack); exit; } catch (Exception $e) { $message = $e->getMessage(); echo "<div style='color:#B80A0A;font-size:18px;'><b>Import Settings Error: </b> {$message}</div><br>"; echo $htmlLinkBack; exit; } }
/** * * get cats and taxanomies data from the category id's */ public static function getCatAndTaxData($catIDs) { if (is_string($catIDs)) { $catIDs = trim($catIDs); if (empty($catIDs)) { return array("tax" => "", "cats" => ""); } $catIDs = explode(",", $catIDs); } $strCats = ""; $arrTax = array(); foreach ($catIDs as $cat) { if (strpos($cat, "option_disabled") === 0) { continue; } $pos = strrpos($cat, "_"); if ($pos === false) { UniteFunctionsUG::throwError("The category is in wrong format"); } $taxName = substr($cat, 0, $pos); $catID = substr($cat, $pos + 1, strlen($cat) - $pos - 1); $arrTax[$taxName] = $taxName; if (!empty($strCats)) { $strCats .= ","; } $strCats .= $catID; } $strTax = ""; foreach ($arrTax as $taxName) { if (!empty($strTax)) { $strTax .= ","; } $strTax .= $taxName; } $output = array("tax" => $strTax, "cats" => $strCats); return $output; }
/** * * draw settings function */ public function draw($formID = null) { if (empty($formID)) { UniteFunctionsUG::throwError("You must provide formID to side settings."); } $this->formID = $formID; if (!empty($formID)) { ?> <form name="<?php echo $formID; ?> " id="<?php echo $formID; ?> "> <?php $this->drawSettings(); ?> </form> <?php } else { $this->drawSettings(); } if ($this->isAccordion == true) { $this->putAccordionInit(); } }
/** * * copy / move items to some category * @param $data */ public function copyMoveItemsFromData($data) { $targetCatID = UniteFunctionsUG::getVal($data, "targetCatID"); $selectedCatID = UniteFunctionsUG::getVal($data, "selectedCatID"); $arrItemIDs = UniteFunctionsUG::getVal($data, "arrItemIDs"); UniteFunctionsUG::validateNotEmpty($targetCatID, "category id"); UniteFunctionsUG::validateNotEmpty($arrItemIDs, "item id's"); $operation = UniteFunctionsUG::getVal($data, "operation"); switch ($operation) { case "copy": $this->copyItems($arrItemIDs, $targetCatID); break; case "move": $this->moveItems($arrItemIDs, $targetCatID); break; default: UniteFunctionsUG::throwError("Wrong operation: {$operation}"); break; } $repsonse = $this->getCatsAndItemsHtml($selectedCatID); return $repsonse; }
<?php /** * @package Unite Gallery * @author UniteCMS.net / Valiano * @copyright (C) 2012 Unite CMS, All Rights Reserved. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html * */ defined('_JEXEC') or die('Restricted access'); if (!isset($headerTitle)) { UniteFunctionsUG::throwError("header template error: \$headerTitle variable not defined"); } ?> <div class="unite_header_wrapper"> <div class="title_line"> <div class="title_line_text"> <?php echo GlobalsUG::PLUGIN_TITLE . " - " . $headerTitle; ?> </div> </div> <?php HelperUG::$operations->putTopMenu(GlobalsUG::VIEW_GALLERIES); ?> <div class="unite-clear"></div> </div> <div class="vert_sap10"></div>
/** * * put the gallery */ public function putGallery($galleryID, $arrOptions = array(), $initType = "id") { try { $objCategories = new UniteGalleryCategories(); $this->initGallery($galleryID); $this->setOutputOptions(); $this->putScripts(); $enableCatTabs = $this->getParam('enable_category_tabs', self::FORCE_BOOLEAN); //custom items pass if (is_array($arrOptions) && array_key_exists("items", $arrOptions)) { $arrItems = $arrOptions["items"]; $enableCatTabs = false; } else { //set gallery category $optCatID = UniteFunctionsUG::getVal($arrOptions, "categoryid"); if (!empty($optCatID) && $objCategories->isCatExists($optCatID)) { $categoryID = $optCatID; } else { if ($enableCatTabs == true) { $categoryID = $this->getParam("tabs_init_catid"); if ($categoryID == "first") { //get first category from tabs $strCatIDs = $this->getParam("categorytabs_ids"); $arrIDs = explode(",", $strCatIDs); if (!empty($arrIDs)) { $categoryID = $arrIDs[0]; } } if (empty($categoryID) || is_numeric($categoryID) == false) { $categoryID = $this->getParam("category"); } } else { $categoryID = $this->getParam("category"); } } if (empty($categoryID)) { UniteFunctionsUG::throwError(__("No items category selected", UNITEGALLERY_TEXTDOMAIN)); } $items = new UniteGalleryItems(); $arrItems = $items->getCatItems($categoryID); } if (empty($arrItems)) { UniteFunctionsUG::throwError("No gallery items found", UNITEGALLERY_TEXTDOMAIN); } //set wrapper style //size validation $this->getParam("gallery_width", self::FORCE_SIZE); if ($this->isTilesType == false) { $this->getParam("gallery_height", self::VALIDATE_NUMERIC); } $fullWidth = $this->getParam("full_width", self::FORCE_BOOLEAN); if ($fullWidth == true) { $this->arrParams["gallery_width"] = "100%"; } $wrapperStyle = $this->getPositionString(); //set position $htmlTabs = ""; if ($enableCatTabs == true) { $htmlTabs = $this->getCategoryTabsHtml($this->galleryHtmlID, $objCategories); $this->arrParams["gallery_initial_catid"] = $categoryID; } //get output related variables $addStyles = $this->getAdditionalStyles(); $position = $this->getParam("position"); $isRtlWrapper = $position == "right"; if ($isRtlWrapper == true) { $rtlWrapperStyle = $wrapperStyle; if (!empty($rtlWrapperStyle)) { $rtlWrapperStyle = " style='{$rtlWrapperStyle}'"; } $wrapperStyle = ""; //move the wrapper style to rtl wrapper } if (!empty($wrapperStyle)) { $wrapperStyle = " style='{$wrapperStyle}'"; } global $uniteGalleryVersion; $output = "\n\t\t\t\t\t\n\n\t\t\t\t\t<!-- START UNITE GALLERY LITE {$uniteGalleryVersion} -->\n\t\t\t\t\t\n\t\t\t\t"; if (!empty($addStyles)) { $output = $this->putInlineStyle($addStyles, $output); } if ($this->putJsToBody == true) { $output .= $this->putJsIncludesToBody(); } if ($enableCatTabs == true) { $output .= $htmlTabs; } //add rtl prefix to get the gallery to right if needed if ($isRtlWrapper == true) { $output .= self::LINE_PREFIX1 . "<div class='ug-rtl'{$rtlWrapperStyle}>"; } $output .= self::LINE_PREFIX1 . "<div id='{$this->galleryHtmlID}' class='unite-gallery'{$wrapperStyle}>"; $output .= self::LINE_PREFIX2 . $this->putItems($arrItems); $output .= self::LINE_PREFIX1 . "</div>"; if ($isRtlWrapper == true) { $output .= self::LINE_PREFIX1 . "</div>"; } $output .= self::BR; $output = $this->putGalleryScripts($output); $output .= self::BR; $output .= self::LINE_PREFIX1 . "<!-- END UNITEGALLERY LITE-->"; $compressOutput = $this->getParam("compress_output", self::FORCE_BOOLEAN); if ($compressOutput == true) { $output = str_replace("\r", "", $output); $output = str_replace("\n", "", $output); $output = trim($output); } return $output; ?> <?php } catch (Exception $e) { $prefix = __("Unite Gallery Error", UNITEGALLERY_TEXTDOMAIN); $output = $this->getErrorMessage($e, $prefix); return $output; } }
/** * * do "trim" operation on all array items. */ public static function trimArrayItems($arr) { if (gettype($arr) != "array") { UniteFunctionsUG::throwError("trimArrayItems error: The type must be array"); } foreach ($arr as $key => $item) { $arr[$key] = trim($item); } return $arr; }
/** * * update order from data */ public function updateOrderFromData($data) { $arrCatIDs = UniteFunctionsUG::getVal($data, "cat_order"); if (is_array($arrCatIDs) == false) { UniteFunctionsUG::throwError("Wrong categories array"); } $this->updateOrder($arrCatIDs); }