/**
  * 
  * get gallery data from xml file
  */
 private function initDataFromXml()
 {
     $errorPrefix = $this->filepathXmlFile . " parsing error:";
     if (!file_exists($this->filepathXmlFile)) {
         UniteFunctionsUG::throwError("File: '{$filepath}' not exists!!!");
     }
     $obj = simplexml_load_file($this->filepathXmlFile);
     if (empty($obj)) {
         UniteFunctionsUG::throwError("Wrong xml file format: {$this->filepathXmlFile}");
     }
     $objGeneral = $obj->general;
     if (empty($objGeneral)) {
         UniteFunctionsUG::throwError($errorPrefix . "General section not found.");
     }
     //get general data
     $arrData = (array) $objGeneral;
     $this->name = UniteFunctionsUG::getVal($arrData, "name");
     $this->typeTitle = UniteFunctionsUG::getVal($arrData, "title");
     $this->isPublished = UniteFunctionsUG::getVal($arrData, "published");
     $this->isPublished = UniteFunctionsUG::strToBool($this->isPublished);
     $this->itemsType = UniteFunctionsUG::getVal($arrData, "items_type", "all");
     //validatopm
     UniteFunctionsUG::validateNotEmpty($this->name, $errorPrefix);
     UniteFunctionsUG::validateNotEmpty($this->typeTitle, $errorPrefix);
 }
 /**
  * update thumb panel defaults of some gallery settings
  * should be inited gallery inside the framework
  */
 public static function updateThumbPanelDefaults($data)
 {
     UniteFunctionsUG::validateNotEmpty(GlobalsUGGallery::$gallery, "The gallery shouold be inited");
     //$valuesParams["theme_panel_position"] = $position;
     //include settings
     $panelPos = UniteFunctionsUG::getVal($data, "position");
     require HelperGalleryUG::getFilepathSettings("gallery_settings");
     $posRelatedFields = self::getPositionRelatedSettings();
     $valuesParams = UniteFunctionsUG::filterArrFields($valuesParams, $posRelatedFields);
     $valuesParams["theme_panel_position"] = $panelPos;
     GlobalsUGGallery::$gallery->updateParams($valuesParams);
 }
 /**
  * replace the post gallery with unite gallery
  */
 function unitegallery_postgallery($output = '', $atts, $content = false, $tag = false)
 {
     $alias = UniteFunctionsUG::getVal($atts, "unitegallery");
     if (empty($alias)) {
         return $output;
     }
     $ids = UniteFunctionsUG::getVal($atts, "ids");
     if (empty($ids)) {
         return $output;
     }
     //get items
     $arrIDs = explode(",", $ids);
     $arrItems = UniteFunctionsWPUG::getArrItemsFromAttachments($arrIDs);
     //output gallery
     $objItems = new UniteGalleryItems();
     $arrUniteItems = $objItems->getItemsFromArray($arrItems);
     $content = HelperUG::outputGallery($alias, null, "alias", $arrUniteItems);
     return $content;
 }
 /**
  *
  * 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;
     }
 }
    /**
     * draw settings row
     * @param $setting
     */
    protected function drawSettingRow($setting)
    {
        //set cellstyle:
        $cellStyle = "";
        if (isset($setting[UniteSettingsUG::PARAM_CELLSTYLE])) {
            $cellStyle .= $setting[UniteSettingsUG::PARAM_CELLSTYLE];
        }
        //set text style:
        $textStyle = $cellStyle;
        if (isset($setting[UniteSettingsUG::PARAM_TEXTSTYLE])) {
            $textStyle .= $setting[UniteSettingsUG::PARAM_TEXTSTYLE];
        }
        if ($textStyle != "") {
            $textStyle = "style='" . $textStyle . "'";
        }
        if ($cellStyle != "") {
            $cellStyle = "style='" . $cellStyle . "'";
        }
        //set hidden
        $rowStyle = "";
        if (isset($setting["hidden"])) {
            $rowStyle = "display:none;";
        }
        if (!empty($rowStyle)) {
            $rowStyle = "style='{$rowStyle}'";
        }
        //set text class:
        $class = "";
        if (isset($setting["disabled"])) {
            $class = "class='setting-disabled'";
        }
        //modify text:
        $text = UniteFunctionsUG::getVal($setting, "text", "");
        // prevent line break (convert spaces to nbsp)
        $text = str_replace(" ", "&nbsp;", $text);
        switch ($setting["type"]) {
            case UniteSettingsUG::TYPE_CHECKBOX:
                $text = "<label for='" . $setting["id"] . "' style='cursor:pointer;'>{$text}</label>";
                break;
        }
        $description = UniteFunctionsUG::getVal($setting, "description");
        //set settings text width:
        $textWidth = "";
        if (isset($setting["textWidth"])) {
            $textWidth = 'width="' . $setting["textWidth"] . '"';
        }
        $addField = UniteFunctionsUG::getVal($setting, UniteSettingsUG::PARAM_ADDFIELD);
        ?>
						
			<?php 
        if (!empty($addField)) {
            $addSetting = $this->settings->getSettingByName($addField);
            UniteFunctionsUG::validateNotEmpty($addSetting, "AddSetting {$addField}");
            //set hidden
            $rowStyleAdd = "";
            if (isset($addSetting["hidden"])) {
                $rowStyleAdd = "display:none;";
            }
            if (!empty($rowStyleAdd)) {
                $rowStyleAdd = "style='{$rowStyleAdd}'";
            }
            $addSettingText = UniteFunctionsUG::getVal($addSetting, "text", "");
            $addSettingText = str_replace(" ", "&nbsp;", $addSettingText);
            ?>
				<tr <?php 
            echo $class;
            ?>
 valign="top">
				
				<td <?php 
            echo $cellStyle;
            ?>
 class="unite-settings-onecell" colspan="2">
					<span id="<?php 
            echo $setting["id_row"];
            ?>
" <?php 
            echo $rowStyle;
            ?>
>
						<span class='setting_onecell_text'><?php 
            echo $text;
            ?>
</span>				
							<?php 
            $this->drawInputs($setting);
            $this->drawInputAdditions($setting);
            ?>
						<span class="setting_onecell_horsap"></span>
					</span>
					
					<span id="<?php 
            echo $addSetting["id_row"];
            ?>
" <?php 
            echo $rowStyleAdd;
            ?>
>
						<span class='setting_onecell_text'><?php 
            echo $addSettingText;
            ?>
</span>				
						<?php 
            $this->drawInputs($addSetting);
            $this->drawInputAdditions($addSetting);
            ?>
					</span>
				</td>
				</tr>
				<?php 
            ?>
			<?php 
        } else {
            ?>
				<tr id="<?php 
            echo $setting["id_row"];
            ?>
" <?php 
            echo $rowStyle;
            ?>
 <?php 
            echo $class;
            ?>
 valign="top">
			
					<th <?php 
            echo $textStyle;
            ?>
 scope="row" <?php 
            echo $textWidth;
            ?>
>
						<?php 
            if ($this->showDescAsTips == true) {
                ?>
					    	<span class='setting_text' title="<?php 
                echo $description;
                ?>
"><?php 
                echo $text;
                ?>
</span>
					    <?php 
            } else {
                ?>
					    	<?php 
                echo $text;
                ?>
					    <?php 
            }
            ?>
					</th>
					<td <?php 
            echo $cellStyle;
            ?>
>
						<?php 
            $this->drawInputs($setting);
            $this->drawInputAdditions($setting);
            ?>
					</td>
				</tr>
			<?php 
        }
    }
 /**
  * import settings
  */
 public function importSettings($arrContent)
 {
     $this->validateInited();
     $jsonParams = UniteFunctionsUG::getVal($arrContent, "params");
     $paramsNew = (array) json_decode($jsonParams);
     if (empty($paramsNew)) {
         return false;
     }
     //unset variables
     $arrUnset = array("title", "alias", "category", "gallery_width", "gallery_height", "full_width", "enable_categories", "shortcode", "gallery_min_width", "include_jquery", "js_to_body", "compress_output", "gallery_debug_errors", "categories", "enable_category_tabs", "gallery_min_width", "gallery_min_height");
     foreach ($arrUnset as $key) {
         if (array_key_exists($key, $paramsNew)) {
             unset($paramsNew[$key]);
         }
     }
     $this->updateParams($paramsNew);
 }
 /**
  * update item data - media in db
  */
 private function updateItemData_media($data)
 {
     $title = UniteFunctionsUG::getVal($data, "title");
     UniteFunctionsUG::validateNotEmpty($title, "Item Title");
     $type = UniteFunctionsUG::getVal($data, "type");
     $urlImage = UniteFunctionsUG::getVal($data, "urlImage");
     $urlThumb = UniteFunctionsUG::getVal($data, "urlThumb");
     $arrUpdate = array();
     $arrUpdate["type"] = $type;
     $arrUpdate["url_image"] = HelperUG::URLtoRelative($urlImage);
     $arrUpdate["url_thumb"] = HelperUG::URLtoRelative($urlThumb);
     $arrUpdate["title"] = trim($title);
     $arrUpdate = $this->getAddDataFromMedia($data, $arrUpdate);
     $arrParams = UniteFunctionsUG::getVal($arrUpdate, "params");
     if (is_array($arrParams)) {
         $arrUpdate["params"] = json_encode($arrParams);
     }
     $this->db->update(GlobalsUG::$table_items, $arrUpdate, array("id" => $this->id));
     //init the item again from the new record
     $this->data = array_merge($this->data, $arrUpdate);
     $this->initByDBRecord($this->data);
 }
 /**
  *
  * set values from array of stored settings elsewhere.
  */
 public function setStoredValues($arrValues)
 {
     foreach ($this->arrSettings as $key => $setting) {
         $name = UniteFunctionsUG::getVal($setting, "name");
         //type consolidation
         $type = UniteFunctionsUG::getVal($setting, "type");
         $datatype = UniteFunctionsUG::getVal($setting, "datatype");
         //skip custom type
         $customType = UniteFunctionsUG::getVal($setting, "custom_type");
         if (!empty($customType)) {
             continue;
         }
         if (array_key_exists($name, $arrValues)) {
             $value = $arrValues[$name];
             $value = $this->modifyValueByDatatype($value, $datatype);
             $this->arrSettings[$key]["value"] = $value;
             $arrValues[$name] = $value;
         }
     }
     //end foreach
     return $arrValues;
 }
        }
        $content = file_get_contents($filepath);
        $data = array();
        $data["content"] = $content;
        $relativePath = HelperUG::pathToRelative($filepath);
        $data["filepath"] = $relativePath;
        HelperUG::ajaxResponseData($data);
        break;
    case "update_skin_css":
        $skin = UniteFunctionsUG::getVal($data, "skin");
        $filepath_modified = GlobalsUG::$path_media_ug . "themes/video/skin-{$skin}-modified.css";
        $content = UniteFunctionsUG::getVal($data, "css");
        UniteFunctionsUG::writeFile($content, $filepath_modified);
        HelperUG::ajaxResponseSuccess("Content Updated");
        break;
    case "get_original_skin_css":
        $skin = UniteFunctionsUG::getVal($data, "skin");
        $filepath = GlobalsUG::$path_media_ug . "themes/video/skin-{$skin}.css";
        $filepath_modified = GlobalsUG::$path_media_ug . "themes/video/skin-{$skin}-modified.css";
        if (file_exists($filepath_modified) == false) {
            HelperUG::ajaxResponseSuccess("The file is original");
        }
        $content = file_get_contents($filepath);
        $data = array();
        $data["content"] = $content;
        HelperUG::ajaxResponseData($data);
        break;
    default:
        HelperUG::ajaxResponseError("wrong ajax action (Video Theme): <b>{$action}</b> ");
        break;
}
    /**
     * 
     * 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;
        }
    }
 /**
  * 
  * update item data
  * get html item for admin response
  */
 public function updateItemData($data)
 {
     $itemID = UniteFunctionsUG::getVal($data, "itemID");
     UniteFunctionsUG::validateNotEmpty($itemID, "item params");
     $item = new UniteGalleryItem();
     $item->initByID($itemID);
     $item->updateItemData($data);
     $htmlItem = $item->getHtmlForAdmin();
     $response = array("html_item" => $htmlItem);
     return $response;
 }
 public function addSelect_filescan($name, $path, $arrExtensions, $defaultValue, $text, $arrParams = array())
 {
     if (getType($arrExtensions) == "string") {
         $arrExtensions = array($arrExtensions);
     } elseif (getType($arrExtensions) != "array") {
         $this->throwError("The extensions array is not array and not string in setting: {$name}, please check.");
     }
     //make items array
     if (!is_dir($path)) {
         $this->throwError("path: {$path} not found");
     }
     $arrItems = array();
     $files = scandir($path);
     foreach ($files as $file) {
         //general filter
         if ($file == ".." || $file == "." || $file == ".svn") {
             continue;
         }
         $info = pathinfo($file);
         $ext = UniteFunctionsUG::getVal($info, "extension");
         $ext = strtolower($ext);
         if (array_search($ext, $arrExtensions) === FALSE) {
             continue;
         }
         $arrItems[$file] = $file;
     }
     //handle add data array
     if (isset($arrParams["addData"])) {
         foreach ($arrParams["addData"] as $key => $value) {
             $arrItems[$key] = $value;
         }
     }
     if (empty($defaultValue) && !empty($arrItems)) {
         $defaultValue = current($arrItems);
     }
     $this->addSelect($name, $arrItems, $text, $defaultValue, $arrParams);
 }
 /**
  *
  * get some param
  */
 protected function getParam($name, $validateMode = null)
 {
     if (is_array($this->arrParams) == false) {
         $this->arrParams = array();
     }
     if (array_key_exists($name, $this->arrParams)) {
         $arrParams = $this->arrParams;
         $value = $this->arrParams[$name];
     } else {
         if (is_array($this->arrOriginalParams) == false) {
             $this->arrOriginalParams = array();
         }
         $arrParams = $this->arrOriginalParams;
         $value = UniteFunctionsUG::getVal($this->arrOriginalParams, $name);
     }
     switch ($validateMode) {
         case self::VALIDATE_EXISTS:
             if (array_key_exists($name, $arrParams) == false) {
                 UniteFunctionsUG::throwError("The param: {$name} don't exists");
             }
             break;
         case self::VALIDATE_NUMERIC:
             if (is_numeric($value) == false) {
                 UniteFunctionsUG::throwError("The param: {$name} is not numeric");
             }
             break;
         case self::VALIDATE_SIZE:
             if (strpos($value, "%") === false && is_numeric($value) == false) {
                 UniteFunctionsUG::throwError("The param: {$name} is not size");
             }
             break;
         case self::FORCE_SIZE:
             $isPercent = strpos($value, "%") !== false;
             if ($isPercent == false && is_numeric($value) == false) {
                 UniteFunctionsUG::throwError("The param: {$name} is not size");
             }
             if ($isPercent == false) {
                 $value .= "px";
             }
             break;
         case self::FORCE_NUMERIC:
             $value = floatval($value);
             $value = (double) $value;
             break;
         case self::FORCE_BOOLEAN:
             $value = UniteFunctionsUG::strToBool($value);
             break;
         case self::TRIM:
             $value = trim($value);
             break;
     }
     return $value;
 }
 /**
  * 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 thumbnail sizes array
  * mode: null, "small_only", "big_only"
  */
 public static function getArrThumbSizes($mode = null)
 {
     global $_wp_additional_image_sizes;
     $arrWPSizes = get_intermediate_image_sizes();
     $arrSizes = array();
     if ($mode != "big_only") {
         $arrSizes[self::THUMB_SMALL] = "Thumbnail (150x150)";
         $arrSizes[self::THUMB_MEDIUM] = "Medium (max width 300)";
     }
     if ($mode == "small_only") {
         return $arrSizes;
     }
     foreach ($arrWPSizes as $size) {
         $title = ucfirst($size);
         switch ($size) {
             case self::THUMB_LARGE:
             case self::THUMB_MEDIUM:
             case self::THUMB_FULL:
             case self::THUMB_SMALL:
                 continue 2;
                 break;
             case "ug_big":
                 $title = __("Big", UNITEGALLERY_TEXTDOMAIN);
                 break;
         }
         $arrSize = UniteFunctionsUG::getVal($_wp_additional_image_sizes, $size);
         $maxWidth = UniteFunctionsUG::getVal($arrSize, "width");
         if (!empty($maxWidth)) {
             $title .= " (max width {$maxWidth})";
         }
         $arrSizes[$size] = $title;
     }
     $arrSizes[self::THUMB_LARGE] = __("Large (max width 1024)", UNITEGALLERY_TEXTDOMAIN);
     $arrSizes[self::THUMB_FULL] = __("Full", UNITEGALLERY_TEXTDOMAIN);
     return $arrSizes;
 }
示例#16
0
}
?>
	
	
	
	
	<div id="dialog_new" class="dialog_new_gallery" title="<?php 
_e("Choose a gallery", UNITEGALLERY_TEXTDOMAIN);
?>
" style="display:none">
		<div class="unite-admin unite-dialog-inside">
			<ul id="listGalleries" class="list_galleries">
				<?php 
foreach ($arrGalleryTypes as $gallery) {
    $galleryName = UniteFunctionsUG::getVal($gallery, "name");
    $galleryTitle = UniteFunctionsUG::getVal($gallery, "title");
    $link = HelperUG::getViewUrl(GlobalsUG::VIEW_GALLERY, "type={$galleryName}");
    ?>
				<li><a class="unite-button-secondary" href="<?php 
    echo $link;
    ?>
" data-name="<?php 
    echo $galleryName;
    ?>
"><?php 
    echo $galleryTitle;
    ?>
</a></li>
				<?php 
}
?>
 /**
  * 
  * onAjax action handler
  */
 public static function onAjaxAction()
 {
     $actionType = UniteFunctionsUG::getPostGetVariable("action");
     if ($actionType != "unitegallery_ajax_action") {
         return false;
     }
     $gallery = new UniteGalleryGallery();
     $galleries = new UniteGalleryGalleries();
     $categories = new UniteGalleryCategories();
     $items = new UniteGalleryItems();
     $operations = new UGOperations();
     $action = UniteFunctionsUG::getPostGetVariable("client_action");
     $data = UniteFunctionsUG::getPostVariable("data");
     $data = UniteProviderFunctionsUG::normalizeAjaxInputData($data);
     $galleryType = UniteFunctionsUG::getPostVariable("gallery_type");
     $urlGalleriesView = HelperUG::getGalleriesView();
     try {
         switch ($action) {
             case "gallery_actions":
                 $galleryID = UniteFunctionsUG::getVal($data, "galleryID");
                 $galleryAction = UniteFunctionsUG::getVal($data, "gallery_action");
                 $galleryData = UniteFunctionsUG::getVal($data, "gallery_data", array());
                 self::onGalleryAjaxAction($galleryType, $galleryAction, $galleryData, $galleryID);
                 break;
             case "get_thumb_url":
                 $urlImage = UniteFunctionsUG::getVal($data, "urlImage");
                 $imageID = UniteFunctionsUG::getVal($data, "imageID");
                 $urlThumb = $operations->getThumbURLFromImageUrl($urlImage, $imageID);
                 $arrData = array("urlThumb" => $urlThumb);
                 HelperUG::ajaxResponseData($arrData);
                 break;
             case "add_category":
                 $catData = $categories->addFromData();
                 HelperUG::ajaxResponseData($catData);
                 break;
             case "remove_category":
                 $response = $categories->removeFromData($data);
                 HelperUG::ajaxResponseSuccess(__("The category deleted successfully.", UNITEGALLERY_TEXTDOMAIN), $response);
                 break;
             case "update_category":
                 $categories->updateFromData($data);
                 HelperUG::ajaxResponseSuccess(__("Category updated.", UNITEGALLERY_TEXTDOMAIN));
                 break;
             case "update_cat_order":
                 $categories->updateOrderFromData($data);
                 HelperUG::ajaxResponseSuccess(__("Order updated.", UNITEGALLERY_TEXTDOMAIN));
                 break;
             case "add_item":
                 $itemData = $items->addFromData($data);
                 HelperUG::ajaxResponseData($itemData);
                 break;
             case "get_item_data":
                 $response = $items->getItemData($data);
                 HelperUG::ajaxResponseData($response);
                 break;
             case "update_item_data":
                 $response = $items->updateItemData($data);
                 HelperUG::ajaxResponseSuccess(__("Item data updated!", UNITEGALLERY_TEXTDOMAIN), $response);
                 break;
             case "remove_items":
                 $response = $items->removeItemsFromData($data);
                 HelperUG::ajaxResponseSuccess(__("Items Removed", UNITEGALLERY_TEXTDOMAIN), $response);
                 break;
             case "get_cat_items":
                 $responeData = $items->getCatItemsHtmlFromData($data);
                 //update category param if inside gallery
                 $gallery->updateItemsCategoryFromData($data);
                 HelperUG::ajaxResponseData($responeData);
                 break;
             case "update_item_title":
                 $items->updateItemTitleFromData($data);
                 HelperUG::ajaxResponseSuccess(__("Item Title Updated", UNITEGALLERY_TEXTDOMAIN));
                 break;
             case "duplicate_items":
                 $response = $items->duplicateItemsFromData($data);
                 HelperUG::ajaxResponseSuccess(__("Items Duplicated", UNITEGALLERY_TEXTDOMAIN), $response);
                 break;
             case "update_items_order":
                 $items->saveOrderFromData($data);
                 HelperUG::ajaxResponseSuccess(__("Order Saved", UNITEGALLERY_TEXTDOMAIN));
                 break;
             case "copy_move_items":
                 $response = $items->copyMoveItemsFromData($data);
                 HelperUG::ajaxResponseSuccess(__("Done Operation", UNITEGALLERY_TEXTDOMAIN), $response);
                 break;
             case "create_gallery":
                 $galleryID = $galleries->addGaleryFromData($galleryType, $data);
                 $urlView = HelperUG::getGalleryView($galleryID);
                 HelperUG::ajaxResponseSuccessRedirect(__("Gallery Created", UNITEGALLERY_TEXTDOMAIN), $urlView);
                 break;
             case "delete_gallery":
                 $galleries->deleteGalleryFromData($data);
                 HelperUG::ajaxResponseSuccessRedirect(__("Gallery deleted", UNITEGALLERY_TEXTDOMAIN), $urlGalleriesView);
                 break;
             case "update_gallery":
                 $galleries->updateGalleryFromData($data);
                 HelperUG::ajaxResponseSuccess(__("Gallery Updated"));
                 break;
             case "duplicate_gallery":
                 $galleries->duplicateGalleryFromData($data);
                 HelperUG::ajaxResponseSuccessRedirect(__("Gallery duplicated", UNITEGALLERY_TEXTDOMAIN), $urlGalleriesView);
                 break;
             case "update_plugin":
                 if (method_exists("UniteProviderFunctionsUG", "updatePlugin")) {
                     UniteProviderFunctionsUG::updatePlugin();
                 } else {
                     echo "Functionality Don't Exists";
                 }
                 break;
             case "export_gallery_settings":
                 $galleryID = UniteFunctionsUG::getPostGetVariable("galleryid");
                 $galleries->exportGallerySettings($galleryID);
                 break;
             case "import_gallery_settings":
                 $galleryID = UniteFunctionsUG::getPostGetVariable("galleryid");
                 $galleries->importGallerySettingsFromUploadFile($galleryID);
                 break;
             default:
                 HelperUG::ajaxResponseError("wrong ajax action: <b>{$action}</b> ");
                 break;
         }
     } catch (Exception $e) {
         $message = $e->getMessage();
         $errorMessage = $message;
         if (GlobalsUG::SHOW_TRACE == true) {
             $trace = $e->getTraceAsString();
             $errorMessage = $message . "<pre>" . $trace . "</pre>";
         }
         HelperUG::ajaxResponseError($errorMessage);
     }
     //it's an ajax action, so exit
     HelperUG::ajaxResponseError("No response output on <b> {$action} </b> action. please check with the developer.");
     exit;
 }
 /**
  * 
  * widget output
  */
 public function widget($args, $instance)
 {
     $title = UniteFunctionsUG::getVal($instance, "title");
     $galleryID = UniteFunctionsUG::getVal($instance, "unitegallery");
     $categoryID = UniteFunctionsUG::getVal($instance, "unitegallery_cat");
     if (empty($galleryID)) {
         return false;
     }
     //widget output
     $beforeWidget = UniteFunctionsUG::getVal($args, "before_widget");
     $afterWidget = UniteFunctionsUG::getVal($args, "after_widget");
     $beforeTitle = UniteFunctionsUG::getVal($args, "before_title");
     $afterTitle = UniteFunctionsUG::getVal($args, "after_title");
     echo $beforeWidget;
     if (!empty($title)) {
         echo $beforeTitle . $title . $afterTitle;
     }
     $content = HelperUG::outputGallery($galleryID, $categoryID, "id");
     echo $content;
     echo $afterWidget;
 }
    /**
     * 
     * draw all settings
     */
    public function drawSettings()
    {
        $this->prepareToDraw();
        $this->drawHeaderIncludes();
        $arrSaps = $this->groupSettingsIntoSaps();
        $class = "unite-postbox";
        if (!empty($this->addClass)) {
            $class .= " " . $this->addClass;
        }
        //draw wrapper
        echo "<div class='settings_wrapper'>";
        //draw settings - advanced - with sections
        foreach ($arrSaps as $key => $sap) {
            //set accordion closed
            $style = "";
            if ($this->isAccordion == false) {
                $h3Class = " no-accordion";
            } else {
                $h3Class = "";
                if ($key > 0) {
                    $style = "style='display:none;'";
                    $h3Class = " box_closed";
                }
            }
            $text = $sap["text"];
            $classIcon = UniteFunctionsUG::getVal($sap, "icon");
            $text = __($text, UNITEGALLERY_TEXTDOMAIN);
            ?>
					<div class="<?php 
            echo $class;
            ?>
">
						<div class="unite-postbox-title<?php 
            echo $h3Class;
            ?>
">
						
						<?php 
            if (!empty($classIcon)) {
                ?>
						<i style="float:left;margin-top:4px;font-size:14px;" class="<?php 
                echo $classIcon;
                ?>
"></i>
						<?php 
            }
            ?>
						
						<?php 
            if ($this->isAccordion == true) {
                ?>
							<div class="unite-postbox-arrow"></div>
						<?php 
            }
            ?>
						
							<span><?php 
            echo $text;
            ?>
</span>
						</div>			
												
						<div class="inside" <?php 
            echo $style;
            ?>
 >
							<ul class="list_settings">
						<?php 
            $settings = UniteFunctionsUG::getVal($sap, "settings", array());
            foreach ($settings as $setting) {
                $this->drawSetting($setting);
            }
            ?>
							</ul>
							
							<?php 
            if (!empty($this->arrButtons)) {
                ?>
								<div class="unite-clear"></div>
								<div class="settings_buttons">
								<?php 
                $this->drawButtons();
                ?>
								</div>	
								<div class="unite-clear"></div>
								<?php 
            }
            ?>
						
							<div class="unite-clear"></div>
						</div>
					</div>
				<?php 
        }
        echo "</div>";
        //wrapper close
    }
 /**
  * get filename title from some url
  * used to get item title from image url
  */
 public static function getTitleFromUrl($url, $defaultTitle = "item")
 {
     $info = pathinfo($url);
     $filename = UniteFunctionsUG::getVal($info, "filename");
     $filename = urldecode($filename);
     $title = $defaultTitle;
     if (!empty($filename)) {
         $title = $filename;
     }
     return $title;
 }
 /**
  * make thumbnail from the image, and save to some path
  * return new path
  */
 public function makeThumb($filepathImage, $pathThumbs, $maxWidth = -1, $maxHeight = -1, $type = "")
 {
     //validate input
     UniteFunctionsUG::validateFilepath($filepathImage, "image not found");
     UniteFunctionsUG::validateDir($pathThumbs, "Thumbs folder don't exists.");
     if ($type == self::TYPE_EXACT || $type == self::TYPE_EXACT_TOP) {
         if ($maxHeight == -1) {
             $this->throwError("image with exact type must have height!");
         }
         if ($maxWidth == -1) {
             $this->throwError("image with exact type must have width!");
         }
     }
     //get filename
     $info = UniteFunctionsUG::getPathInfo($filepathImage);
     $filename = UniteFunctionsUG::getVal($info, "basename");
     UniteFunctionsUG::validateNotEmpty($filename, "image filename not given");
     //if gd library doesn't exists - output normal image without resizing.
     if (function_exists("gd_info") == false) {
         $this->throwError("php must support GD Library");
     }
     if ($maxWidth == -1 && $maxHeight == -1) {
         $this->throwError("Wrong thumb size");
     }
     if ($maxWidth == -1) {
         $maxWidth = 1000000;
     }
     if ($maxHeight == -1) {
         $maxHeight = 100000;
     }
     $this->filename = $filename;
     $this->maxWidth = $maxWidth;
     $this->maxHeight = $maxHeight;
     $this->type = $type;
     $this->pathCache = $pathThumbs;
     $filenameThumb = $this->getThumbFilename();
     $filepathNew = $this->pathCache . $filenameThumb;
     if (file_exists($filepathNew)) {
         return $filenameThumb;
     }
     if ($type == self::TYPE_EXACT || $type == self::TYPE_EXACT_TOP) {
         $isSaved = $this->cropImageSaveNew($filepathImage, $filepathNew);
     } else {
         $isSaved = $this->resizeImageSaveNew($filepathImage, $filepathNew);
     }
     if ($isSaved) {
         return $filenameThumb;
     } else {
         return "";
     }
 }
 /**
  * 
  * 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);
 }