/** * * init the static variables */ public static function initStaticVars() { //UniteFunctionsUG::printDefinedConstants(); self::$urlSite = site_url(); if (substr(self::$urlSite, -1) != "/") { self::$urlSite .= "/"; } self::$urlAdmin = admin_url(); if (substr(self::$urlAdmin, -1) != "/") { self::$urlAdmin .= "/"; } }
/** * 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 imaeg input: * @param $setting */ protected function drawImageInput($setting) { $class = UniteFunctionsUG::getVal($setting, "class"); if (!empty($class)) { $class = "class='{$class}'"; } $settingsID = $setting["id"]; $buttonID = $settingsID . "_button"; $buttonRemoveID = $settingsID . "_button_remove"; $spanPreviewID = $buttonID . "_preview"; $img = ""; $value = UniteFunctionsUG::getVal($setting, "value"); if (!empty($value)) { $urlImage = $value; $imagePath = UniteFunctionsWPUG::getImageRealPathFromUrl($urlImage); $img = '<div style="width:100px;height:70px;background:url(' . $urlImage . '); background-position:center center; background-size:contain;background-repeat:no-repeat;"></div>'; } ?> <span id='<?php echo $spanPreviewID; ?> ' class='setting-image-preview'><?php echo $img; ?> </span> <input type="hidden" id="<?php echo $setting["id"]; ?> " name="<?php echo $setting["name"]; ?> " value="<?php echo $setting["value"]; ?> " /> <input type="button" id="<?php echo $buttonID; ?> " style="width: 110px !important; float: left;" class='button-image-select button-primary revblue<?php echo $class; ?> ' value="<?php _e('Choose Image', UNITEGALLERY_TEXTDOMAIN); ?> "></input> <input type="button" class="button-image-remove button-primary revred" style="width: 110px !important;" id="<?php echo $buttonRemoveID; ?> " value="<?php _e('Remove', UNITEGALLERY_TEXTDOMAIN); ?> " /> <div class="unite-clear"></div> <?php }
/** * * validate admin permissions, if no pemissions - exit */ protected static function validateAdminPermissions() { if (UniteFunctionsWPUG::isAdminPermissions(self::$capability) == false) { echo "access denied, no " . GlobalsUG::PERMISSION . " permissions"; return false; } }