first commit
This commit is contained in:
308
wp-content/plugins/revslider/inc_php/framework/base.class.php
Normal file
308
wp-content/plugins/revslider/inc_php/framework/base.class.php
Normal file
@ -0,0 +1,308 @@
|
||||
<?php
|
||||
|
||||
class UniteBaseClassRev{
|
||||
|
||||
protected static $wpdb;
|
||||
protected static $table_prefix;
|
||||
protected static $mainFile;
|
||||
protected static $t;
|
||||
|
||||
protected static $dir_plugin;
|
||||
protected static $dir_languages;
|
||||
public static $url_plugin;
|
||||
protected static $url_ajax;
|
||||
public static $url_ajax_actions;
|
||||
protected static $url_ajax_showimage;
|
||||
protected static $path_settings;
|
||||
protected static $path_plugin;
|
||||
protected static $path_languages;
|
||||
protected static $path_temp;
|
||||
protected static $path_views;
|
||||
protected static $path_templates;
|
||||
protected static $path_cache;
|
||||
protected static $path_base;
|
||||
protected static $is_multisite;
|
||||
protected static $debugMode = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* the constructor
|
||||
*/
|
||||
public function __construct($mainFile,$t){
|
||||
global $wpdb;
|
||||
|
||||
self::$is_multisite = UniteFunctionsWPRev::isMultisite();
|
||||
|
||||
self::$wpdb = $wpdb;
|
||||
self::$table_prefix = self::$wpdb->base_prefix;
|
||||
if(UniteFunctionsWPRev::isMultisite()){
|
||||
$blogID = UniteFunctionsWPRev::getBlogID();
|
||||
if($blogID != 1){
|
||||
self::$table_prefix .= $blogID."_";
|
||||
}
|
||||
}
|
||||
|
||||
self::$mainFile = $mainFile;
|
||||
self::$t = $t;
|
||||
|
||||
//set plugin dirname (as the main filename)
|
||||
$info = pathinfo($mainFile);
|
||||
$baseName = $info["basename"];
|
||||
$filename = str_replace(".php","",$baseName);
|
||||
|
||||
self::$dir_plugin = $filename;
|
||||
|
||||
self::$url_plugin = plugins_url(self::$dir_plugin)."/";
|
||||
self::$url_ajax = admin_url("admin-ajax.php");
|
||||
self::$url_ajax_actions = self::$url_ajax . "?action=".self::$dir_plugin."_ajax_action";
|
||||
self::$url_ajax_showimage = self::$url_ajax . "?action=".self::$dir_plugin."_show_image";
|
||||
self::$path_plugin = dirname(self::$mainFile)."/";
|
||||
self::$path_settings = self::$path_plugin."settings/";
|
||||
self::$path_temp = self::$path_plugin."temp/";
|
||||
|
||||
//set cache path:
|
||||
self::setPathCache();
|
||||
|
||||
self::$path_views = self::$path_plugin."views/";
|
||||
self::$path_templates = self::$path_views."/templates/";
|
||||
self::$path_base = ABSPATH;
|
||||
self::$path_languages = self::$path_plugin."languages/";
|
||||
self::$dir_languages = self::$dir_plugin."/languages/";
|
||||
|
||||
load_plugin_textdomain(self::$dir_plugin,false,self::$dir_languages);
|
||||
|
||||
//update globals oldversion flag
|
||||
GlobalsRevSlider::$isNewVersion = false;
|
||||
$version = get_bloginfo("version");
|
||||
$version = (double)$version;
|
||||
if($version >= 3.5)
|
||||
GlobalsRevSlider::$isNewVersion = true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* set cache path for images. for multisite it will be current blog content folder
|
||||
*/
|
||||
private static function setPathCache(){
|
||||
|
||||
self::$path_cache = self::$path_plugin."cache/";
|
||||
if(self::$is_multisite){
|
||||
|
||||
if(!defined("BLOGUPLOADDIR") || !is_dir(BLOGUPLOADDIR))
|
||||
return(false);
|
||||
|
||||
$path = BLOGUPLOADDIR.self::$dir_plugin."-cache/";
|
||||
|
||||
if(!is_dir($path))
|
||||
mkdir($path);
|
||||
if(is_dir($path))
|
||||
self::$path_cache = $path;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* set debug mode.
|
||||
*/
|
||||
public static function setDebugMode(){
|
||||
self::$debugMode = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* add some wordpress action
|
||||
*/
|
||||
protected static function addAction($action,$eventFunction){
|
||||
|
||||
add_action( $action, array(self::$t, $eventFunction) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* register script helper function
|
||||
* @param $scriptFilename
|
||||
*/
|
||||
protected static function addScriptAbsoluteUrl($scriptPath,$handle){
|
||||
|
||||
wp_register_script($handle , $scriptPath);
|
||||
wp_enqueue_script($handle);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* register script helper function
|
||||
* @param $scriptFilename
|
||||
*/
|
||||
protected static function addScript($scriptName,$folder="js",$handle=null){
|
||||
if($handle == null)
|
||||
$handle = self::$dir_plugin."-".$scriptName;
|
||||
|
||||
wp_register_script($handle , self::$url_plugin .$folder."/".$scriptName.".js" );
|
||||
wp_enqueue_script($handle);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* register common script helper function
|
||||
* the handle for the common script is coming without plugin name
|
||||
*/
|
||||
protected static function addScriptCommon($scriptName,$handle=null, $folder="js"){
|
||||
if($handle == null)
|
||||
$handle = $scriptName;
|
||||
|
||||
self::addScript($scriptName,$folder,$handle);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* simple enqueue script
|
||||
*/
|
||||
protected static function addWPScript($scriptName){
|
||||
wp_enqueue_script($scriptName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* register style helper function
|
||||
* @param $styleFilename
|
||||
*/
|
||||
protected static function addStyle($styleName,$handle=null,$folder="css"){
|
||||
if($handle == null)
|
||||
$handle = self::$dir_plugin."-".$styleName;
|
||||
|
||||
wp_register_style($handle , self::$url_plugin .$folder."/".$styleName.".css" );
|
||||
wp_enqueue_style($handle);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* register common script helper function
|
||||
* the handle for the common script is coming without plugin name
|
||||
*/
|
||||
protected static function addStyleCommon($styleName,$handle=null,$folder="css"){
|
||||
if($handle == null)
|
||||
$handle = $styleName;
|
||||
self::addStyle($styleName,$handle,$folder);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* register style absolute url helper function
|
||||
*/
|
||||
protected static function addStyleAbsoluteUrl($styleUrl,$handle){
|
||||
|
||||
wp_register_style($handle , $styleUrl);
|
||||
wp_enqueue_style($handle);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* simple enqueue style
|
||||
*/
|
||||
protected static function addWPStyle($styleName){
|
||||
wp_enqueue_style($styleName);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get image url to be shown via thumb making script.
|
||||
*/
|
||||
public static function getImageUrl($filepath, $width=null,$height=null,$exact=false,$effect=null,$effect_param=null){
|
||||
|
||||
$urlImage = UniteImageViewRev::getUrlThumb(self::$url_ajax_showimage, $filepath,$width ,$height ,$exact ,$effect ,$effect_param);
|
||||
|
||||
return($urlImage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* on show image ajax event. outputs image with parameters
|
||||
*/
|
||||
public static function onShowImage(){
|
||||
|
||||
$pathImages = UniteFunctionsWPRev::getPathContent();
|
||||
$urlImages = UniteFunctionsWPRev::getUrlContent();
|
||||
|
||||
try{
|
||||
|
||||
$imageView = new UniteImageViewRev(self::$path_cache,$pathImages,$urlImages);
|
||||
$imageView->showImageFromGet();
|
||||
|
||||
}catch (Exception $e){
|
||||
header("status: 500");
|
||||
echo $e->getMessage();
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get POST var
|
||||
*/
|
||||
protected static function getPostVar($key,$defaultValue = ""){
|
||||
$val = self::getVar($_POST, $key, $defaultValue);
|
||||
return($val);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get GET var
|
||||
*/
|
||||
protected static function getGetVar($key,$defaultValue = ""){
|
||||
$val = self::getVar($_GET, $key, $defaultValue);
|
||||
return($val);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get post or get variable
|
||||
*/
|
||||
protected static function getPostGetVar($key,$defaultValue = ""){
|
||||
|
||||
if(array_key_exists($key, $_POST))
|
||||
$val = self::getVar($_POST, $key, $defaultValue);
|
||||
else
|
||||
$val = self::getVar($_GET, $key, $defaultValue);
|
||||
|
||||
return($val);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get some var from array
|
||||
*/
|
||||
protected static function getVar($arr,$key,$defaultValue = ""){
|
||||
$val = $defaultValue;
|
||||
if(isset($arr[$key])) $val = $arr[$key];
|
||||
return($val);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* make config file of all the text in the settings for the .mo and .po creation
|
||||
*/
|
||||
protected static function updateSettingsText(){
|
||||
|
||||
$filelist = UniteFunctionsRev::getFileList(self::$path_settings,"xml");
|
||||
foreach($filelist as $file){
|
||||
$filepath = self::$path_settings.$file;
|
||||
UniteFunctionsWPRev::writeSettingLanguageFile($filepath);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,526 @@
|
||||
<?php
|
||||
|
||||
class UniteBaseAdminClassRev extends UniteBaseClassRev{
|
||||
|
||||
const ACTION_ADMIN_MENU = "admin_menu";
|
||||
const ACTION_ADMIN_INIT = "admin_init";
|
||||
const ACTION_ADD_SCRIPTS = "admin_enqueue_scripts";
|
||||
|
||||
const ROLE_ADMIN = "admin";
|
||||
const ROLE_EDITOR = "editor";
|
||||
const ROLE_AUTHOR = "author";
|
||||
|
||||
protected static $master_view;
|
||||
protected static $view;
|
||||
|
||||
private static $arrSettings = array();
|
||||
private static $arrMenuPages = array();
|
||||
private static $tempVars = array();
|
||||
private static $startupError = "";
|
||||
private static $menuRole = self::ROLE_ADMIN;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* main constructor
|
||||
*/
|
||||
public function __construct($mainFile,$t,$defaultView){
|
||||
|
||||
parent::__construct($mainFile,$t);
|
||||
|
||||
//set view
|
||||
self::$view = self::getGetVar("view");
|
||||
if(empty(self::$view))
|
||||
self::$view = $defaultView;
|
||||
|
||||
//add internal hook for adding a menu in arrMenus
|
||||
self::addAction(self::ACTION_ADMIN_MENU, "addAdminMenu");
|
||||
|
||||
//if not inside plugin don't continue
|
||||
if($this->isInsidePlugin() == true){
|
||||
self::addAction(self::ACTION_ADD_SCRIPTS, "addCommonScripts");
|
||||
self::addAction(self::ACTION_ADD_SCRIPTS, "onAddScripts");
|
||||
}
|
||||
|
||||
//a must event for any admin. call onActivate function.
|
||||
$this->addEvent_onActivate();
|
||||
self::addActionAjax("show_image", "onShowImage");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* set the menu role - for viewing menus
|
||||
*/
|
||||
public static function setMenuRole($menuRole){
|
||||
self::$menuRole = $menuRole;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* set startup error to be shown in master view
|
||||
*/
|
||||
public static function setStartupError($errorMessage){
|
||||
self::$startupError = $errorMessage;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* tells if the the current plugin opened is this plugin or not
|
||||
* in the admin side.
|
||||
*/
|
||||
private function isInsidePlugin(){
|
||||
$page = self::getGetVar("page");
|
||||
if($page == self::$dir_plugin)
|
||||
return(true);
|
||||
return(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* add common used scripts
|
||||
*/
|
||||
public static function addCommonScripts(){
|
||||
|
||||
//include jquery ui
|
||||
if(GlobalsRevSlider::$isNewVersion){ //load new jquery ui library
|
||||
|
||||
$urlJqueryUI = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js";
|
||||
self::addScriptAbsoluteUrl($urlJqueryUI,"jquery-ui");
|
||||
self::addStyle("jquery-ui-1.9.2.custom.min","jui-smoothness","css/jui/new");
|
||||
|
||||
if(function_exists("wp_enqueue_media"))
|
||||
wp_enqueue_media();
|
||||
|
||||
}else{ //load old jquery ui library
|
||||
|
||||
$urlJqueryUI = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js";
|
||||
self::addScriptAbsoluteUrl($urlJqueryUI,"jquery-ui");
|
||||
self::addStyle("jquery-ui-1.8.18.custom","jui-smoothness","css/jui/old");
|
||||
|
||||
}
|
||||
|
||||
self::addScriptCommon("settings","unite_settings");
|
||||
self::addScriptCommon("admin","unite_admin");
|
||||
self::addScriptCommon("jquery.tipsy","tipsy");
|
||||
|
||||
//--- add styles
|
||||
|
||||
self::addStyleCommon("admin","unite_admin");
|
||||
|
||||
//add tipsy
|
||||
self::addStyleCommon("tipsy","tipsy");
|
||||
|
||||
//include farbtastic
|
||||
self::addScriptCommon("my-farbtastic","my-farbtastic","js/farbtastic");
|
||||
self::addStyleCommon("farbtastic","farbtastic","js/farbtastic");
|
||||
|
||||
//include codemirror
|
||||
self::addScriptCommon("codemirror","codemirror_js","js/codemirror");
|
||||
self::addScriptCommon("css","codemirror_js_css","js/codemirror");
|
||||
self::addStyleCommon("codemirror","codemirror_css","js/codemirror");
|
||||
|
||||
//include dropdown checklist
|
||||
self::addScriptCommon("ui.dropdownchecklist-1.4-min","dropdownchecklist_js","js/dropdownchecklist");
|
||||
//self::addScriptCommon("ui.dropdownchecklist","dropdownchecklist_js","js/dropdownchecklist");
|
||||
//self::addStyleCommon("ui.dropdownchecklist.standalone","dropdownchecklist_css","js/dropdownchecklist");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* admin pages parent, includes all the admin files by default
|
||||
*/
|
||||
public static function adminPages(){
|
||||
self::validateAdminPermissions();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* validate permission that the user is admin, and can manage options.
|
||||
*/
|
||||
protected static function isAdminPermissions(){
|
||||
|
||||
if( is_admin() && current_user_can("manage_options") )
|
||||
return(true);
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* validate admin permissions, if no pemissions - exit
|
||||
*/
|
||||
protected static function validateAdminPermissions(){
|
||||
if(!self::isAdminPermissions()){
|
||||
echo "access denied";
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* set view that will be the master
|
||||
*/
|
||||
protected static function setMasterView($masterView){
|
||||
self::$master_view = $masterView;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* inlcude some view file
|
||||
*/
|
||||
protected static function requireView($view){
|
||||
try{
|
||||
//require master view file, and
|
||||
if(!empty(self::$master_view) && !isset(self::$tempVars["is_masterView"]) ){
|
||||
$masterViewFilepath = self::$path_views.self::$master_view.".php";
|
||||
UniteFunctionsRev::validateFilepath($masterViewFilepath,"Master View");
|
||||
|
||||
self::$tempVars["is_masterView"] = true;
|
||||
require $masterViewFilepath;
|
||||
}
|
||||
else{ //simple require the view file.
|
||||
$viewFilepath = self::$path_views.$view.".php";
|
||||
|
||||
UniteFunctionsRev::validateFilepath($viewFilepath,"View");
|
||||
require $viewFilepath;
|
||||
}
|
||||
|
||||
}catch (Exception $e){
|
||||
echo "<br><br>View ($view) Error: <b>".$e->getMessage()."</b>";
|
||||
|
||||
if(self::$debugMode == true)
|
||||
dmp($e->getTraceAsString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* require some template from "templates" folder
|
||||
*/
|
||||
protected static function getPathTemplate($templateName){
|
||||
|
||||
$pathTemplate = self::$path_templates.$templateName.".php";
|
||||
UniteFunctionsRev::validateFilepath($pathTemplate,"Template");
|
||||
|
||||
return($pathTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* require settings file, the filename without .php
|
||||
*/
|
||||
protected static function requireSettings($settingsFile){
|
||||
|
||||
try{
|
||||
require self::$path_plugin."settings/$settingsFile.php";
|
||||
}catch (Exception $e){
|
||||
echo "<br><br>Settings ($settingsFile) Error: <b>".$e->getMessage()."</b>";
|
||||
dmp($e->getTraceAsString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get path to settings file
|
||||
* @param $settingsFile
|
||||
*/
|
||||
protected static function getSettingsFilePath($settingsFile){
|
||||
|
||||
$filepath = self::$path_plugin."settings/$settingsFile.php";
|
||||
return($filepath);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* add all js and css needed for media upload
|
||||
*/
|
||||
protected static function addMediaUploadIncludes(){
|
||||
|
||||
self::addWPScript("thickbox");
|
||||
self::addWPStyle("thickbox");
|
||||
self::addWPScript("media-upload");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add admin menus from the list.
|
||||
*/
|
||||
public static function addAdminMenu(){
|
||||
|
||||
$role = "manage_options";
|
||||
|
||||
switch(self::$menuRole){
|
||||
case self::ROLE_AUTHOR:
|
||||
$role = "edit_published_posts";
|
||||
break;
|
||||
case self::ROLE_EDITOR:
|
||||
$role = "edit_pages";
|
||||
break;
|
||||
default:
|
||||
case self::ROLE_ADMIN:
|
||||
$role = "manage_options";
|
||||
break;
|
||||
}
|
||||
|
||||
foreach(self::$arrMenuPages as $menu){
|
||||
$title = $menu["title"];
|
||||
$pageFunctionName = $menu["pageFunction"];
|
||||
add_menu_page( $title, $title, $role, self::$dir_plugin, array(self::$t, $pageFunctionName) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* add menu page
|
||||
*/
|
||||
protected static function addMenuPage($title,$pageFunctionName){
|
||||
|
||||
self::$arrMenuPages[] = array("title"=>$title,"pageFunction"=>$pageFunctionName);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get url to some view.
|
||||
*/
|
||||
public static function getViewUrl($viewName,$urlParams=""){
|
||||
$params = "&view=".$viewName;
|
||||
if(!empty($urlParams))
|
||||
$params .= "&".$urlParams;
|
||||
|
||||
$link = admin_url( "admin.php?page=".self::$dir_plugin.$params);
|
||||
return($link);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* register the "onActivate" event
|
||||
*/
|
||||
protected function addEvent_onActivate($eventFunc = "onActivate"){
|
||||
register_activation_hook( self::$mainFile, array(self::$t, $eventFunc) );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* store settings in the object
|
||||
*/
|
||||
protected static function storeSettings($key,$settings){
|
||||
self::$arrSettings[$key] = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get settings object
|
||||
*/
|
||||
protected static function getSettings($key){
|
||||
if(!isset(self::$arrSettings[$key]))
|
||||
UniteFunctionsRev::throwError("Settings $key not found");
|
||||
$settings = self::$arrSettings[$key];
|
||||
return($settings);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* add ajax back end callback, on some action to some function.
|
||||
*/
|
||||
protected static function addActionAjax($ajaxAction,$eventFunction){
|
||||
self::addAction('wp_ajax_'.self::$dir_plugin."_".$ajaxAction, $eventFunction);
|
||||
self::addAction('wp_ajax_nopriv_'.self::$dir_plugin."_".$ajaxAction, $eventFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* echo json ajax response
|
||||
*/
|
||||
private static function ajaxResponse($success,$message,$arrData = null){
|
||||
|
||||
$response = array();
|
||||
$response["success"] = $success;
|
||||
$response["message"] = $message;
|
||||
|
||||
if(!empty($arrData)){
|
||||
|
||||
if(gettype($arrData) == "string")
|
||||
$arrData = array("data"=>$arrData);
|
||||
|
||||
$response = array_merge($response,$arrData);
|
||||
}
|
||||
|
||||
$json = json_encode($response);
|
||||
|
||||
echo $json;
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* echo json ajax response, without message, only data
|
||||
*/
|
||||
protected static function ajaxResponseData($arrData){
|
||||
if(gettype($arrData) == "string")
|
||||
$arrData = array("data"=>$arrData);
|
||||
|
||||
self::ajaxResponse(true,"",$arrData);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* echo json ajax response
|
||||
*/
|
||||
protected static function ajaxResponseError($message,$arrData = null){
|
||||
|
||||
self::ajaxResponse(false,$message,$arrData,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* echo ajax success response
|
||||
*/
|
||||
protected static function ajaxResponseSuccess($message,$arrData = null){
|
||||
|
||||
self::ajaxResponse(true,$message,$arrData,true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* echo ajax success response
|
||||
*/
|
||||
protected static function ajaxResponseSuccessRedirect($message,$url){
|
||||
$arrData = array("is_redirect"=>true,"redirect_url"=>$url);
|
||||
|
||||
self::ajaxResponse(true,$message,$arrData,true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*/
|
||||
protected static function updatePlugin($viewBack = false){
|
||||
$linkBack = self::getViewUrl($viewBack);
|
||||
$htmlLinkBack = UniteFunctionsRev::getHtmlLink($linkBack, "Go Back");
|
||||
|
||||
$zip = new UniteZipRev();
|
||||
|
||||
try{
|
||||
|
||||
if(function_exists("unzip_file") == false){
|
||||
if( UniteZipRev::isZipExists() == false)
|
||||
UniteFunctionsRev::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 = UniteFunctionsRev::getVal($_FILES, "update_file");
|
||||
if(empty($arrFiles))
|
||||
UniteFunctionsRev::throwError("Update file don't found.");
|
||||
|
||||
$filename = UniteFunctionsRev::getVal($arrFiles, "name");
|
||||
|
||||
if(empty($filename))
|
||||
UniteFunctionsRev::throwError("Update filename not found.");
|
||||
|
||||
$fileType = UniteFunctionsRev::getVal($arrFiles, "type");
|
||||
|
||||
/*
|
||||
$fileType = strtolower($fileType);
|
||||
|
||||
if($fileType != "application/zip")
|
||||
UniteFunctionsRev::throwError("The file uploaded is not zip.");
|
||||
*/
|
||||
|
||||
$filepathTemp = UniteFunctionsRev::getVal($arrFiles, "tmp_name");
|
||||
if(file_exists($filepathTemp) == false)
|
||||
UniteFunctionsRev::throwError("Can't find the uploaded file.");
|
||||
|
||||
//crate temp folder
|
||||
UniteFunctionsRev::checkCreateDir(self::$path_temp);
|
||||
|
||||
//create the update folder
|
||||
$pathUpdate = self::$path_temp."update_extract/";
|
||||
UniteFunctionsRev::checkCreateDir($pathUpdate);
|
||||
|
||||
//remove all files in the update folder
|
||||
if(is_dir($pathUpdate)){
|
||||
$arrNotDeleted = UniteFunctionsRev::deleteDir($pathUpdate,false);
|
||||
if(!empty($arrNotDeleted)){
|
||||
$strNotDeleted = print_r($arrNotDeleted,true);
|
||||
UniteFunctionsRev::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)
|
||||
UniteFunctionsRev::throwError("Can't move the uploaded file here: {$filepathZip}.");
|
||||
|
||||
if(function_exists("unzip_file") == true){
|
||||
WP_Filesystem();
|
||||
$response = unzip_file($filepathZip, $pathUpdate);
|
||||
}
|
||||
else
|
||||
$zip->extract($filepathZip, $pathUpdate);
|
||||
|
||||
//get extracted folder
|
||||
$arrFolders = UniteFunctionsRev::getFoldersList($pathUpdate);
|
||||
if(empty($arrFolders))
|
||||
UniteFunctionsRev::throwError("The update folder is not extracted");
|
||||
|
||||
if(count($arrFolders) > 1)
|
||||
UniteFunctionsRev::throwError("Extracted folders are more then 1. Please check the update file.");
|
||||
|
||||
//get product folder
|
||||
$productFolder = $arrFolders[0];
|
||||
if(empty($productFolder))
|
||||
UniteFunctionsRev::throwError("Wrong product folder.");
|
||||
|
||||
if($productFolder != self::$dir_plugin)
|
||||
UniteFunctionsRev::throwError("The update folder don't match the product folder, please check the update file.");
|
||||
|
||||
$pathUpdateProduct = $pathUpdate.$productFolder."/";
|
||||
|
||||
//check some file in folder to validate it's the real one:
|
||||
$checkFilepath = $pathUpdateProduct.$productFolder.".php";
|
||||
if(file_exists($checkFilepath) == false)
|
||||
UniteFunctionsRev::throwError("Wrong update extracted folder. The file: {$checkFilepath} not found.");
|
||||
|
||||
//copy the plugin without the captions file.
|
||||
//$pathOriginalPlugin = $pathUpdate."copy/";
|
||||
$pathOriginalPlugin = self::$path_plugin;
|
||||
|
||||
$arrBlackList = array();
|
||||
$arrBlackList[] = "rs-plugin/css/captions.css";
|
||||
|
||||
UniteFunctionsRev::copyDir($pathUpdateProduct, $pathOriginalPlugin,"",$arrBlackList);
|
||||
|
||||
//delete the update
|
||||
UniteFunctionsRev::deleteDir($pathUpdate);
|
||||
|
||||
dmp("Updated Successfully, redirecting...");
|
||||
echo "<script>location.href='$linkBack'</script>";
|
||||
|
||||
}catch(Exception $e){
|
||||
$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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
class UniteBaseFrontClassRev extends UniteBaseClassRev{
|
||||
|
||||
const ACTION_ENQUEUE_SCRIPTS = "wp_enqueue_scripts";
|
||||
|
||||
/**
|
||||
*
|
||||
* main constructor
|
||||
*/
|
||||
public function __construct($mainFile,$t){
|
||||
|
||||
parent::__construct($mainFile,$t);
|
||||
|
||||
self::addAction(self::ACTION_ENQUEUE_SCRIPTS, "onAddScripts");
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
class UniteCssParserRev{
|
||||
|
||||
private $cssContent;
|
||||
|
||||
public function __construct(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* init the parser, set css content
|
||||
*/
|
||||
public function initContent($cssContent){
|
||||
$this->cssContent = $cssContent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get array of slide classes, between two sections.
|
||||
*/
|
||||
public function getArrClasses($startText = "",$endText=""){
|
||||
|
||||
$content = $this->cssContent;
|
||||
|
||||
//trim from top
|
||||
if(!empty($startText)){
|
||||
$posStart = strpos($content, $startText);
|
||||
if($posStart !== false)
|
||||
$content = substr($content, $posStart,strlen($content)-$posStart);
|
||||
}
|
||||
|
||||
//trim from bottom
|
||||
if(!empty($endText)){
|
||||
$posEnd = strpos($content, $endText);
|
||||
if($posEnd !== false)
|
||||
$content = substr($content,0,$posEnd);
|
||||
}
|
||||
|
||||
//get styles
|
||||
$lines = explode("\n",$content);
|
||||
$arrClasses = array();
|
||||
foreach($lines as $key=>$line){
|
||||
$line = trim($line);
|
||||
|
||||
if(strpos($line, "{") === false)
|
||||
continue;
|
||||
|
||||
//skip unnessasary links
|
||||
if(strpos($line, ".caption a") !== false)
|
||||
continue;
|
||||
|
||||
if(strpos($line, ".tp-caption a") !== false)
|
||||
continue;
|
||||
|
||||
//get style out of the line
|
||||
$class = str_replace("{", "", $line);
|
||||
$class = trim($class);
|
||||
|
||||
//skip captions like this: .tp-caption.imageclass img
|
||||
if(strpos($class," ") !== false)
|
||||
continue;
|
||||
|
||||
$class = str_replace(".caption.", ".", $class);
|
||||
$class = str_replace(".tp-caption.", ".", $class);
|
||||
|
||||
$class = str_replace(".", "", $class);
|
||||
$class = trim($class);
|
||||
$arrWords = explode(" ", $class);
|
||||
$class = $arrWords[count($arrWords)-1];
|
||||
$class = trim($class);
|
||||
|
||||
$arrClasses[] = $class;
|
||||
}
|
||||
|
||||
return($arrClasses);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
151
wp-content/plugins/revslider/inc_php/framework/db.class.php
Normal file
151
wp-content/plugins/revslider/inc_php/framework/db.class.php
Normal file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
class UniteDBRev{
|
||||
|
||||
private $wpdb;
|
||||
private $lastRowID;
|
||||
|
||||
/**
|
||||
*
|
||||
* constructor - set database object
|
||||
*/
|
||||
public function __construct(){
|
||||
global $wpdb;
|
||||
$this->wpdb = $wpdb;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* throw error
|
||||
*/
|
||||
private function throwError($message,$code=-1){
|
||||
UniteFunctionsRev::throwError($message,$code);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
// validate for errors
|
||||
private function checkForErrors($prefix = ""){
|
||||
|
||||
if(mysql_error()){
|
||||
$query = $this->wpdb->last_query;
|
||||
$message = $this->wpdb->last_error;
|
||||
|
||||
if($prefix) $message = $prefix.' - <b>'.$message.'</b>';
|
||||
if($query) $message .= '<br>---<br> Query: ' . $query;
|
||||
|
||||
$this->throwError($message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* insert variables to some table
|
||||
*/
|
||||
public function insert($table,$arrItems){
|
||||
|
||||
$this->wpdb->insert($table, $arrItems);
|
||||
$this->checkForErrors("Insert query error");
|
||||
|
||||
$this->lastRowID = mysql_insert_id();
|
||||
|
||||
return($this->lastRowID);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get last insert id
|
||||
*/
|
||||
public function getLastInsertID(){
|
||||
$this->lastRowID = mysql_insert_id();
|
||||
return($this->lastRowID);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* delete rows
|
||||
*/
|
||||
public function delete($table,$where){
|
||||
|
||||
UniteFunctionsRev::validateNotEmpty($table,"table name");
|
||||
UniteFunctionsRev::validateNotEmpty($where,"where");
|
||||
|
||||
$query = "delete from $table where $where";
|
||||
|
||||
$this->wpdb->query($query);
|
||||
|
||||
$this->checkForErrors("Delete query error");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* run some sql query
|
||||
*/
|
||||
public function runSql($query){
|
||||
|
||||
$this->wpdb->query($query);
|
||||
$this->checkForErrors("Regular query error");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* insert variables to some table
|
||||
*/
|
||||
public function update($table,$arrItems,$where){
|
||||
|
||||
$response = $this->wpdb->update($table, $arrItems, $where);
|
||||
if($response === false)
|
||||
UniteFunctionsRev::throwError("no update action taken!");
|
||||
|
||||
$this->checkForErrors("Update query error");
|
||||
|
||||
return($this->wpdb->num_rows);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get data array from the database
|
||||
*
|
||||
*/
|
||||
public function fetch($tableName,$where="",$orderField="",$groupByField="",$sqlAddon=""){
|
||||
|
||||
$query = "select * from $tableName";
|
||||
if($where) $query .= " where $where";
|
||||
if($orderField) $query .= " order by $orderField";
|
||||
if($groupByField) $query .= " group by $groupByField";
|
||||
if($sqlAddon) $query .= " ".$sqlAddon;
|
||||
|
||||
$response = $this->wpdb->get_results($query,ARRAY_A);
|
||||
|
||||
$this->checkForErrors("fetch");
|
||||
|
||||
return($response);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* fetch only one item. if not found - throw error
|
||||
*/
|
||||
public function fetchSingle($tableName,$where="",$orderField="",$groupByField="",$sqlAddon=""){
|
||||
$response = $this->fetch($tableName, $where, $orderField, $groupByField, $sqlAddon);
|
||||
if(empty($response))
|
||||
$this->throwError("Record not found");
|
||||
$record = $response[0];
|
||||
return($record);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* escape data to avoid sql errors and injections.
|
||||
*/
|
||||
public function escape($string){
|
||||
return($this->wpdb->escape($string));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
class UniteElementsBaseRev{
|
||||
|
||||
protected $db;
|
||||
|
||||
public function __construct(){
|
||||
|
||||
$this->db = new UniteDBRev();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,770 @@
|
||||
<?php
|
||||
|
||||
class UniteFunctionsRev{
|
||||
|
||||
public static function throwError($message,$code=null){
|
||||
if(!empty($code))
|
||||
throw new Exception($message,$code);
|
||||
else
|
||||
throw new Exception($message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* set output for download
|
||||
*/
|
||||
public static function downloadFile($str,$filename="output.txt"){
|
||||
|
||||
//output for download
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
header("Content-Disposition: attachment; filename=".$filename.";");
|
||||
header("Content-Transfer-Encoding: binary");
|
||||
header("Content-Length: ".strlen($str));
|
||||
echo $str;
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* turn boolean to string
|
||||
*/
|
||||
public static function boolToStr($bool){
|
||||
if(gettype($bool) == "string")
|
||||
return($bool);
|
||||
if($bool == true)
|
||||
return("true");
|
||||
else
|
||||
return("false");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* convert string to boolean
|
||||
*/
|
||||
public static function strToBool($str){
|
||||
if(is_bool($str))
|
||||
return($str);
|
||||
|
||||
if(empty($str))
|
||||
return(false);
|
||||
|
||||
if(is_numeric($str))
|
||||
return($str != 0);
|
||||
|
||||
$str = strtolower($str);
|
||||
if($str == "true")
|
||||
return(true);
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------
|
||||
// get black value from rgb value
|
||||
public static function yiq($r,$g,$b){
|
||||
return (($r*0.299)+($g*0.587)+($b*0.114));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
// convert colors to rgb
|
||||
public static function html2rgb($color){
|
||||
if ($color[0] == '#')
|
||||
$color = substr($color, 1);
|
||||
if (strlen($color) == 6)
|
||||
list($r, $g, $b) = array($color[0].$color[1],
|
||||
$color[2].$color[3],
|
||||
$color[4].$color[5]);
|
||||
elseif (strlen($color) == 3)
|
||||
list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
|
||||
else
|
||||
return false;
|
||||
$r = hexdec($r); $g = hexdec($g); $b = hexdec($b);
|
||||
return array($r, $g, $b);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// convert timestamp to time string
|
||||
public static function timestamp2Time($stamp){
|
||||
$strTime = date("H:i",$stamp);
|
||||
return($strTime);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// convert timestamp to date and time string
|
||||
public static function timestamp2DateTime($stamp){
|
||||
$strDateTime = date("d M Y, H:i",$stamp);
|
||||
return($strDateTime);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// convert timestamp to date string
|
||||
public static function timestamp2Date($stamp){
|
||||
$strDate = date("d M Y",$stamp); //27 Jun 2009
|
||||
return($strDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* get value from array. if not - return alternative
|
||||
*/
|
||||
public static function getVal($arr,$key,$altVal=""){
|
||||
if(isset($arr[$key])) return($arr[$key]);
|
||||
return($altVal);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* convert object to string.
|
||||
*/
|
||||
public static function toString($obj){
|
||||
return(trim((string)$obj));
|
||||
}
|
||||
|
||||
/**
|
||||
* remove utf8 bom sign
|
||||
*/
|
||||
public static function remove_utf8_bom($content){
|
||||
$content = str_replace(chr(239),"",$content);
|
||||
$content = str_replace(chr(187),"",$content);
|
||||
$content = str_replace(chr(191),"",$content);
|
||||
$content = trim($content);
|
||||
return($content);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
// get variable from post or from get. get wins.
|
||||
public static function getPostGetVariable($name,$initVar = ""){
|
||||
$var = $initVar;
|
||||
if(isset($_POST[$name])) $var = $_POST[$name];
|
||||
else if(isset($_GET[$name])) $var = $_GET[$name];
|
||||
return($var);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
public static function getPostVariable($name,$initVar = ""){
|
||||
$var = $initVar;
|
||||
if(isset($_POST[$name])) $var = $_POST[$name];
|
||||
return($var);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
|
||||
public static function getGetVar($name,$initVar = ""){
|
||||
$var = $initVar;
|
||||
if(isset($_GET[$name])) $var = $_GET[$name];
|
||||
return($var);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* validate that some file exists, if not - throw error
|
||||
*/
|
||||
public static function validateFilepath($filepath,$errorPrefix=null){
|
||||
if(file_exists($filepath) == true)
|
||||
return(false);
|
||||
if($errorPrefix == null)
|
||||
$errorPrefix = "File";
|
||||
$message = $errorPrefix." $filepath not exists!";
|
||||
self::throwError($message);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* validate that some value is numeric
|
||||
*/
|
||||
public static function validateNumeric($val,$fieldName=""){
|
||||
self::validateNotEmpty($val,$fieldName);
|
||||
|
||||
if(empty($fieldName))
|
||||
$fieldName = "Field";
|
||||
|
||||
if(!is_numeric($val))
|
||||
self::throwError("$fieldName should be numeric ");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* validate that some variable not empty
|
||||
*/
|
||||
public static function validateNotEmpty($val,$fieldName=""){
|
||||
|
||||
if(empty($fieldName))
|
||||
$fieldName = "Field";
|
||||
|
||||
if(empty($val) && is_numeric($val) == false)
|
||||
self::throwError("Field <b>$fieldName</b> should not be empty");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* if directory not exists - create it
|
||||
* @param $dir
|
||||
*/
|
||||
public static function checkCreateDir($dir){
|
||||
if(!is_dir($dir))
|
||||
mkdir($dir);
|
||||
|
||||
if(!is_dir($dir))
|
||||
self::throwError("Could not create directory: $dir");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* delete file, validate if deleted
|
||||
*/
|
||||
public static function checkDeleteFile($filepath){
|
||||
if(file_exists($filepath) == false)
|
||||
return(false);
|
||||
|
||||
$success = @unlink($filepath);
|
||||
if($success == false)
|
||||
self::throwError("Failed to delete the file: $filepath");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
//filter array, leaving only needed fields - also array
|
||||
public static function filterArrFields($arr,$fields){
|
||||
$arrNew = array();
|
||||
foreach($fields as $field){
|
||||
if(isset($arr[$field]))
|
||||
$arrNew[$field] = $arr[$field];
|
||||
}
|
||||
return($arrNew);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
//get path info of certain path with all needed fields
|
||||
public static function getPathInfo($filepath){
|
||||
$info = pathinfo($filepath);
|
||||
|
||||
//fix the filename problem
|
||||
if(!isset($info["filename"])){
|
||||
$filename = $info["basename"];
|
||||
if(isset($info["extension"]))
|
||||
$filename = substr($info["basename"],0,(-strlen($info["extension"])-1));
|
||||
$info["filename"] = $filename;
|
||||
}
|
||||
|
||||
return($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert std class to array, with all sons
|
||||
* @param unknown_type $arr
|
||||
*/
|
||||
public static function convertStdClassToArray($arr){
|
||||
$arr = (array)$arr;
|
||||
|
||||
$arrNew = array();
|
||||
|
||||
foreach($arr as $key=>$item){
|
||||
$item = (array)$item;
|
||||
$arrNew[$key] = $item;
|
||||
}
|
||||
|
||||
return($arrNew);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
//save some file to the filesystem with some text
|
||||
public static function writeFile($str,$filepath){
|
||||
$fp = fopen($filepath,"w+");
|
||||
fwrite($fp,$str);
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
//save some file to the filesystem with some text
|
||||
public static function writeDebug($str,$filepath="debug.txt",$showInputs = true){
|
||||
$post = print_r($_POST,true);
|
||||
$server = print_r($_SERVER,true);
|
||||
|
||||
if(getType($str) == "array")
|
||||
$str = print_r($str,true);
|
||||
|
||||
if($showInputs == true){
|
||||
$output = "--------------------"."\n";
|
||||
$output .= $str."\n";
|
||||
$output .= "Post: ".$post."\n";
|
||||
}else{
|
||||
$output = "---"."\n";
|
||||
$output .= $str . "\n";
|
||||
}
|
||||
|
||||
if(!empty($_GET)){
|
||||
$get = print_r($_GET,true);
|
||||
$output .= "Get: ".$get."\n";
|
||||
}
|
||||
|
||||
//$output .= "Server: ".$server."\n";
|
||||
|
||||
$fp = fopen($filepath,"a+");
|
||||
fwrite($fp,$output);
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* clear debug file
|
||||
*/
|
||||
public static function clearDebug($filepath = "debug.txt"){
|
||||
|
||||
if(file_exists($filepath))
|
||||
unlink($filepath);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* save to filesystem the error
|
||||
*/
|
||||
public static function writeDebugError(Exception $e,$filepath = "debug.txt"){
|
||||
$message = $e->getMessage();
|
||||
$trace = $e->getTraceAsString();
|
||||
|
||||
$output = $message."\n";
|
||||
$output .= $trace."\n";
|
||||
|
||||
$fp = fopen($filepath,"a+");
|
||||
fwrite($fp,$output);
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------
|
||||
//save some file to the filesystem with some text
|
||||
public static function addToFile($str,$filepath){
|
||||
$fp = fopen($filepath,"a+");
|
||||
fwrite($fp,"---------------------\n");
|
||||
fwrite($fp,$str."\n");
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
//check the php version. throw exception if the version beneath 5
|
||||
private static function checkPHPVersion(){
|
||||
$strVersion = phpversion();
|
||||
$version = (float)$strVersion;
|
||||
if($version < 5) throw new Exception("You must have php5 and higher in order to run the application. Your php version is: $version");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// valiadte if gd exists. if not - throw exception
|
||||
private static function validateGD(){
|
||||
if(function_exists('gd_info') == false)
|
||||
throw new Exception("You need GD library to be available in order to run this application. Please turn it on in php.ini");
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
//return if the json library is activated
|
||||
public static function isJsonActivated(){
|
||||
return(function_exists('json_encode'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* encode array into json for client side
|
||||
*/
|
||||
public static function jsonEncodeForClientSide($arr){
|
||||
$json = "";
|
||||
if(!empty($arr)){
|
||||
$json = json_encode($arr);
|
||||
$json = addslashes($json);
|
||||
}
|
||||
|
||||
$json = "'".$json."'";
|
||||
|
||||
return($json);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* decode json from the client side
|
||||
*/
|
||||
public static function jsonDecodeFromClientSide($data){
|
||||
|
||||
$data = stripslashes($data);
|
||||
$data = str_replace('\"','\"',$data);
|
||||
$data = json_decode($data);
|
||||
$data = (array)$data;
|
||||
|
||||
return($data);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
//validate if some directory is writable, if not - throw a exception
|
||||
private static function validateWritable($name,$path,$strList,$validateExists = true){
|
||||
|
||||
if($validateExists == true){
|
||||
//if the file/directory doesn't exists - throw an error.
|
||||
if(file_exists($path) == false)
|
||||
throw new Exception("$name doesn't exists");
|
||||
}
|
||||
else{
|
||||
//if the file not exists - don't check. it will be created.
|
||||
if(file_exists($path) == false) return(false);
|
||||
}
|
||||
|
||||
if(is_writable($path) == false){
|
||||
chmod($path,0755); //try to change the permissions
|
||||
if(is_writable($path) == false){
|
||||
$strType = "Folder";
|
||||
if(is_file($path)) $strType = "File";
|
||||
$message = "$strType $name is doesn't have a write permissions. Those folders/files must have a write permissions in order that this application will work properly: $strList";
|
||||
throw new Exception($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
//validate presets for identical keys
|
||||
public static function validatePresets(){
|
||||
global $g_presets;
|
||||
if(empty($g_presets)) return(false);
|
||||
//check for duplicates
|
||||
$assoc = array();
|
||||
foreach($g_presets as $preset){
|
||||
$id = $preset["id"];
|
||||
if(isset($assoc[$id]))
|
||||
throw new Exception("Double preset ID detected: $id");
|
||||
$assoc[$id] = true;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
//Get url of image for output
|
||||
public static function getImageOutputUrl($filename,$width=0,$height=0,$exact=false){
|
||||
//exact validation:
|
||||
if($exact == "true" && (empty($width) || empty($height) ))
|
||||
self::throwError("Exact must have both - width and height");
|
||||
|
||||
$url = CMGlobals::$URL_GALLERY."?img=".$filename;
|
||||
if(!empty($width))
|
||||
$url .= "&w=".$width;
|
||||
|
||||
if(!empty($height))
|
||||
$url .= "&h=".$height;
|
||||
|
||||
if($exact == true)
|
||||
$url .= "&t=exact";
|
||||
|
||||
return($url);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get list of all files in the directory
|
||||
* ext - filter by his extension only
|
||||
*/
|
||||
public static function getFileList($path,$ext=""){
|
||||
$dir = scandir($path);
|
||||
$arrFiles = array();
|
||||
foreach($dir as $file){
|
||||
if($file == "." || $file == "..") continue;
|
||||
if(!empty($ext)){
|
||||
$info = pathinfo($file);
|
||||
$extension = UniteFunctionsRev::getVal($info, "extension");
|
||||
if($ext != strtolower($extension))
|
||||
continue;
|
||||
}
|
||||
$filepath = $path . "/" . $file;
|
||||
if(is_file($filepath)) $arrFiles[] = $file;
|
||||
}
|
||||
return($arrFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get list of all files in the directory
|
||||
*/
|
||||
public static function getFoldersList($path){
|
||||
$dir = scandir($path);
|
||||
$arrFiles = array();
|
||||
foreach($dir as $file){
|
||||
if($file == "." || $file == "..") continue;
|
||||
$filepath = $path . "/" . $file;
|
||||
if(is_dir($filepath)) $arrFiles[] = $file;
|
||||
}
|
||||
return($arrFiles);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* do "trim" operation on all array items.
|
||||
*/
|
||||
public static function trimArrayItems($arr){
|
||||
if(gettype($arr) != "array")
|
||||
UniteFunctionsRev::throwError("trimArrayItems error: The type must be array");
|
||||
|
||||
foreach ($arr as $key=>$item)
|
||||
$arr[$key] = trim($item);
|
||||
|
||||
return($arr);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get url contents
|
||||
*/
|
||||
public static function getUrlContents($url,$arrPost=array(),$method = "post",$debug=false){
|
||||
$ch = curl_init();
|
||||
$timeout = 0;
|
||||
|
||||
$strPost = '';
|
||||
foreach($arrPost as $key=>$value){
|
||||
if(!empty($strPost))
|
||||
$strPost .= "&";
|
||||
$value = urlencode($value);
|
||||
$strPost .= "$key=$value";
|
||||
}
|
||||
|
||||
|
||||
//set curl options
|
||||
if(strtolower($method) == "post"){
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS,$strPost);
|
||||
}
|
||||
else //get
|
||||
$url .= "?".$strPost;
|
||||
|
||||
//remove me
|
||||
//Functions::addToLogFile(SERVICE_LOG_SERVICE, "url", $url);
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
||||
|
||||
$headers = array();
|
||||
$headers[] = "User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8";
|
||||
$headers[] = "Accept-Charset:utf-8;q=0.7,*;q=0.7";
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
if($debug == true){
|
||||
dmp($url);
|
||||
dmp($response);
|
||||
exit();
|
||||
}
|
||||
|
||||
if($response == false)
|
||||
throw new Exception("getUrlContents Request failed");
|
||||
|
||||
curl_close($ch);
|
||||
return($response);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get link html
|
||||
*/
|
||||
public static function getHtmlLink($link,$text,$id="",$class=""){
|
||||
|
||||
if(!empty($class))
|
||||
$class = " class='$class'";
|
||||
|
||||
if(!empty($id))
|
||||
$id = " id='$id'";
|
||||
|
||||
$html = "<a href=\"$link\"".$id.$class.">$text</a>";
|
||||
return($html);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get select from array
|
||||
*/
|
||||
public static function getHTMLSelect($arr,$default="",$htmlParams="",$assoc = false){
|
||||
|
||||
$html = "<select $htmlParams>";
|
||||
foreach($arr as $key=>$item){
|
||||
$selected = "";
|
||||
|
||||
if($assoc == false){
|
||||
if($item == $default) $selected = " selected ";
|
||||
}
|
||||
else{
|
||||
if(trim($key) == trim($default))
|
||||
$selected = " selected ";
|
||||
}
|
||||
|
||||
|
||||
if($assoc == true)
|
||||
$html .= "<option $selected value='$key'>$item</option>";
|
||||
else
|
||||
$html .= "<option $selected value='$item'>$item</option>";
|
||||
}
|
||||
$html.= "</select>";
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Convert array to assoc array by some field
|
||||
*/
|
||||
public static function arrayToAssoc($arr,$field=null){
|
||||
$arrAssoc = array();
|
||||
|
||||
foreach($arr as $item){
|
||||
if(empty($field))
|
||||
$arrAssoc[$item] = $item;
|
||||
else
|
||||
$arrAssoc[$item[$field]] = $item;
|
||||
}
|
||||
|
||||
return($arrAssoc);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* convert assoc array to array
|
||||
*/
|
||||
public static function assocToArray($assoc){
|
||||
$arr = array();
|
||||
foreach($assoc as $item)
|
||||
$arr[] = $item;
|
||||
|
||||
return($arr);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* strip slashes from textarea content after ajax request to server
|
||||
*/
|
||||
public static function normalizeTextareaContent($content){
|
||||
if(empty($content))
|
||||
return($content);
|
||||
$content = stripslashes($content);
|
||||
$content = trim($content);
|
||||
return($content);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get random array item
|
||||
*/
|
||||
public static function getRandomArrayItem($arr){
|
||||
$numItems = count($arr);
|
||||
$rand = rand(0, $numItems-1);
|
||||
$item = $arr[$rand];
|
||||
return($item);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* recursive delete directory or file
|
||||
*/
|
||||
public static function deleteDir($path,$deleteOriginal = true, $arrNotDeleted = array(),$originalPath = ""){
|
||||
|
||||
if(empty($originalPath))
|
||||
$originalPath = $path;
|
||||
|
||||
//in case of paths array
|
||||
if(getType($path) == "array"){
|
||||
$arrPaths = $path;
|
||||
foreach($path as $singlePath)
|
||||
$arrNotDeleted = self::deleteDir($singlePath,$deleteOriginal,$arrNotDeleted,$originalPath);
|
||||
return($arrNotDeleted);
|
||||
}
|
||||
|
||||
if(!file_exists($path))
|
||||
return($arrNotDeleted);
|
||||
|
||||
if(is_file($path)){ // delete file
|
||||
$deleted = unlink($path);
|
||||
if(!$deleted)
|
||||
$arrNotDeleted[] = $path;
|
||||
}
|
||||
else{ //delete directory
|
||||
$arrPaths = scandir($path);
|
||||
foreach($arrPaths as $file){
|
||||
if($file == "." || $file == "..")
|
||||
continue;
|
||||
$filepath = realpath($path."/".$file);
|
||||
$arrNotDeleted = self::deleteDir($filepath,$deleteOriginal,$arrNotDeleted,$originalPath);
|
||||
}
|
||||
|
||||
if($deleteOriginal == true || $originalPath != $path){
|
||||
$deleted = @rmdir($path);
|
||||
if(!$deleted)
|
||||
$arrNotDeleted[] = $path;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return($arrNotDeleted);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* copy folder to another location.
|
||||
*
|
||||
*/
|
||||
public static function copyDir($source,$dest,$rel_path = "",$blackList = null){
|
||||
|
||||
$full_source = $source;
|
||||
if(!empty($rel_path))
|
||||
$full_source = $source."/".$rel_path;
|
||||
|
||||
$full_dest = $dest;
|
||||
if(!empty($full_dest))
|
||||
$full_dest = $dest."/".$rel_path;
|
||||
|
||||
if(!is_dir($full_source))
|
||||
self::throwError("The source directroy: '$full_source' not exists.");
|
||||
|
||||
if(!is_dir($full_dest))
|
||||
mkdir($full_dest);
|
||||
|
||||
$files = scandir($full_source);
|
||||
foreach($files as $file){
|
||||
if($file == "." || $file == "..")
|
||||
continue;
|
||||
|
||||
$path_source = $full_source."/".$file;
|
||||
$path_dest = $full_dest."/".$file;
|
||||
|
||||
//validate black list
|
||||
$rel_path_file = $file;
|
||||
if(!empty($rel_path))
|
||||
$rel_path_file = $rel_path."/".$file;
|
||||
|
||||
//if the file or folder is in black list - pass it
|
||||
if(array_search($rel_path_file, $blackList) !== false)
|
||||
continue;
|
||||
|
||||
//if file - copy file
|
||||
if(is_file($path_source)){
|
||||
copy($path_source,$path_dest);
|
||||
}
|
||||
else{ //if directory - recursive copy directory
|
||||
if(empty($rel_path))
|
||||
$rel_path_new = $file;
|
||||
else
|
||||
$rel_path_new = $rel_path."/".$file;
|
||||
|
||||
self::copyDir($source,$dest,$rel_path_new,$blackList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
17
wp-content/plugins/revslider/inc_php/framework/functions.php
Normal file
17
wp-content/plugins/revslider/inc_php/framework/functions.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
if(!function_exists("dmp")){
|
||||
function dmp($str){
|
||||
echo "<div align='left'>";
|
||||
echo "<pre>";
|
||||
print_r($str);
|
||||
echo "</pre>";
|
||||
echo "</div>";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
@ -0,0 +1,256 @@
|
||||
<?php
|
||||
|
||||
class UniteFunctionsWPRev{
|
||||
|
||||
const THUMB_SMALL = "thumbnail";
|
||||
const THUMB_MEDIUM = "medium";
|
||||
const THUMB_LARGE = "large";
|
||||
const THUMB_FULL = "full";
|
||||
|
||||
|
||||
/**
|
||||
* get blog id
|
||||
*/
|
||||
public static function getBlogID(){
|
||||
global $blog_id;
|
||||
return($blog_id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get blog id
|
||||
*/
|
||||
public static function isMultisite(){
|
||||
$isMultisite = is_multisite();
|
||||
return($isMultisite);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* check if some db table exists
|
||||
*/
|
||||
public static function isDBTableExists($tableName){
|
||||
global $wpdb;
|
||||
|
||||
if(empty($tableName))
|
||||
UniteFunctionsRev::throwError("Empty table name!!!");
|
||||
|
||||
$sql = "show tables like '$tableName'";
|
||||
|
||||
$table = $wpdb->get_var($sql);
|
||||
|
||||
if($table == $tableName)
|
||||
return(true);
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get wordpress base path
|
||||
*/
|
||||
public static function getPathBase(){
|
||||
return ABSPATH;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get wp-content path
|
||||
*/
|
||||
public static function getPathContent(){
|
||||
if(self::isMultisite()){
|
||||
if(!defined("BLOGUPLOADDIR")){
|
||||
$pathBase = self::getPathBase();
|
||||
$pathContent = $pathBase."wp-content/";
|
||||
}else
|
||||
$pathContent = BLOGUPLOADDIR;
|
||||
}else{
|
||||
$pathContent = WP_CONTENT_DIR;
|
||||
if(!empty($pathContent)){
|
||||
$pathContent .= "/";
|
||||
}
|
||||
else{
|
||||
$pathBase = self::getPathBase();
|
||||
$pathContent = $pathBase."wp-content/";
|
||||
}
|
||||
}
|
||||
|
||||
return($pathContent);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get content url
|
||||
*/
|
||||
public static function getUrlContent(){
|
||||
|
||||
if(self::isMultisite() == false){ //without multisite
|
||||
$baseUrl = content_url()."/";
|
||||
}
|
||||
else{ //for multisite
|
||||
$arrUploadData = wp_upload_dir();
|
||||
$baseUrl = $arrUploadData["baseurl"]."/";
|
||||
}
|
||||
|
||||
return($baseUrl);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* register widget (must be class)
|
||||
*/
|
||||
public static function registerWidget($widgetName){
|
||||
add_action('widgets_init', create_function('', 'return register_widget("'.$widgetName.'");'));
|
||||
}
|
||||
|
||||
/**
|
||||
* get image relative path from image url (from upload)
|
||||
*/
|
||||
public static function getImagePathFromURL($urlImage){
|
||||
|
||||
$baseUrl = self::getUrlContent();
|
||||
$pathImage = str_replace($baseUrl, "", $urlImage);
|
||||
|
||||
return($pathImage);
|
||||
}
|
||||
|
||||
/**
|
||||
* get image real path phisical on disk from url
|
||||
*/
|
||||
public static function getImageRealPathFromUrl($urlImage){
|
||||
$filepath = self::getImagePathFromURL($urlImage);
|
||||
$realPath = UniteFunctionsWPRev::getPathContent().$filepath;
|
||||
return($realPath);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get image url from image path.
|
||||
*/
|
||||
public static function getImageUrlFromPath($pathImage){
|
||||
//protect from absolute url
|
||||
$pathLower = strtolower($pathImage);
|
||||
if(strpos($pathLower, "http://") !== false || strpos($pathLower, "www.") === 0)
|
||||
return($pathImage);
|
||||
|
||||
$urlImage = self::getUrlContent().$pathImage;
|
||||
return($urlImage);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* write settings language file for wp automatic scanning
|
||||
*/
|
||||
public static function writeSettingLanguageFile($filepath){
|
||||
$info = pathinfo($filepath);
|
||||
$path = UniteFunctionsRev::getVal($info, "dirname")."/";
|
||||
$filename = UniteFunctionsRev::getVal($info, "filename");
|
||||
$ext = UniteFunctionsRev::getVal($info, "extension");
|
||||
$filenameOutput = "{$filename}_{$ext}_lang.php";
|
||||
$filepathOutput = $path.$filenameOutput;
|
||||
|
||||
//load settings
|
||||
$settings = new UniteSettingsAdvancedRev();
|
||||
$settings->loadXMLFile($filepath);
|
||||
$arrText = $settings->getArrTextFromAllSettings();
|
||||
|
||||
$str = "";
|
||||
$str .= "<?php \n";
|
||||
foreach($arrText as $text){
|
||||
$text = str_replace('"', '\\"', $text);
|
||||
$str .= "_e(\"$text\",\"".REVSLIDER_TEXTDOMAIN."\"); \n";
|
||||
}
|
||||
$str .= "?>";
|
||||
|
||||
UniteFunctionsRev::writeFile($str, $filepathOutput);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* check the current post for the existence of a short code
|
||||
*/
|
||||
public static function hasShortcode($shortcode = '') {
|
||||
|
||||
$post = get_post(get_the_ID());
|
||||
|
||||
if (empty($shortcode))
|
||||
return $found;
|
||||
|
||||
$found = false;
|
||||
|
||||
if (stripos($post->post_content, '[' . $shortcode) !== false )
|
||||
$found = true;
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get attachment image url
|
||||
*/
|
||||
public static function getUrlAttachmentImage($thumbID,$size = self::THUMB_FULL){
|
||||
$arrImage = wp_get_attachment_image_src($thumbID,$size);
|
||||
if(empty($arrImage))
|
||||
return(false);
|
||||
$url = UniteFunctionsRev::getVal($arrImage, 0);
|
||||
return($url);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get attachment image array by id and size
|
||||
*/
|
||||
public static function getAttachmentImage($thumbID,$size = self::THUMB_FULL){
|
||||
|
||||
$arrImage = wp_get_attachment_image_src($thumbID,$size);
|
||||
if(empty($arrImage))
|
||||
return(false);
|
||||
|
||||
$output = array();
|
||||
$output["url"] = UniteFunctionsRev::getVal($arrImage, 0);
|
||||
$output["width"] = UniteFunctionsRev::getVal($arrImage, 1);
|
||||
$output["height"] = UniteFunctionsRev::getVal($arrImage, 2);
|
||||
|
||||
return($output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get post thumb id from post id
|
||||
*/
|
||||
public static function getPostThumbID($postID){
|
||||
$thumbID = get_post_thumbnail_id( $postID );
|
||||
return($thumbID);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get url of post thumbnail
|
||||
*/
|
||||
public static function getUrlPostImage($postID,$size = self::THUMB_FULL){
|
||||
|
||||
$post_thumbnail_id = get_post_thumbnail_id( $postID );
|
||||
if(empty($post_thumbnail_id))
|
||||
return("");
|
||||
|
||||
$arrImage = wp_get_attachment_image_src($post_thumbnail_id,$size);
|
||||
if(empty($arrImage))
|
||||
return("");
|
||||
|
||||
$urlImage = $arrImage[0];
|
||||
return($urlImage);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,610 @@
|
||||
<?php
|
||||
|
||||
class UniteImageViewRev{
|
||||
|
||||
private $pathCache;
|
||||
private $pathImages;
|
||||
private $urlImages;
|
||||
|
||||
private $filename = null;
|
||||
private $maxWidth = null;
|
||||
private $maxHeight = null;
|
||||
private $type = null;
|
||||
private $effect = null;
|
||||
private $effect_arg1 = null;
|
||||
private $effect_arg2 = null;
|
||||
|
||||
const EFFECT_BW = "bw";
|
||||
const EFFECT_BRIGHTNESS = "bright";
|
||||
const EFFECT_CONTRAST = "contrast";
|
||||
const EFFECT_EDGE = "edge";
|
||||
const EFFECT_EMBOSS = "emboss";
|
||||
const EFFECT_BLUR = "blur";
|
||||
const EFFECT_BLUR3 = "blur3";
|
||||
const EFFECT_MEAN = "mean";
|
||||
const EFFECT_SMOOTH = "smooth";
|
||||
const EFFECT_DARK = "dark";
|
||||
|
||||
const TYPE_EXACT = "exact";
|
||||
const TYPE_EXACT_TOP = "exacttop";
|
||||
|
||||
private $jpg_quality = 81;
|
||||
|
||||
public function __construct($pathCache,$pathImages,$urlImages){
|
||||
|
||||
$this->pathCache = $pathCache;
|
||||
$this->pathImages = $pathImages;
|
||||
$this->urlImages = $urlImages;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* set jpg quality output
|
||||
*/
|
||||
public function setJPGQuality($quality){
|
||||
$this->jpg_quality = $quality;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get thumb url
|
||||
*/
|
||||
public static function getUrlThumb($urlBase, $filename,$width=null,$height=null,$exact=false,$effect=null,$effect_param=null){
|
||||
|
||||
$filename = urlencode($filename);
|
||||
|
||||
$url = $urlBase."&img=$filename";
|
||||
if(!empty($width))
|
||||
$url .= "&w=".$width;
|
||||
if(!empty($height))
|
||||
$url .= "&h=".$height;
|
||||
|
||||
if($exact == true){
|
||||
$url .= "&t=".self::TYPE_EXACT;
|
||||
}
|
||||
|
||||
if(!empty($effect)){
|
||||
$url .= "&e=".$effect;
|
||||
if(!empty($effect_param))
|
||||
$url .= "&ea1=".$effect_param;
|
||||
}
|
||||
|
||||
return($url);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* throw error
|
||||
*/
|
||||
private function throwError($message,$code=null){
|
||||
UniteFunctionsRev::throwError($message,$code);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get filename for thumbnail save / retrieve
|
||||
* TODO: do input validations - security measures
|
||||
*/
|
||||
private function getThumbFilename(){
|
||||
$info = pathInfo($this->filename);
|
||||
|
||||
//add dirname as postfix (if exists)
|
||||
$postfix = "";
|
||||
|
||||
$dirname = UniteFunctionsRev::getVal($info, "dirname");
|
||||
if(!empty($dirname)){
|
||||
$postfix = str_replace("/", "-", $dirname);
|
||||
}
|
||||
|
||||
|
||||
$ext = $info["extension"];
|
||||
$name = $info["filename"];
|
||||
$width = ceil($this->maxWidth);
|
||||
$height = ceil($this->maxHeight);
|
||||
$thumbFilename = $name."_".$width."x".$height;
|
||||
|
||||
if(!empty($this->type))
|
||||
$thumbFilename .= "_" . $this->type;
|
||||
|
||||
if(!empty($this->effect)){
|
||||
$thumbFilename .= "_e" . $this->effect;
|
||||
if(!empty($this->effect_arg1)){
|
||||
$thumbFilename .= "x" . $this->effect_arg1;
|
||||
}
|
||||
}
|
||||
|
||||
//add postfix
|
||||
if(!empty($postfix))
|
||||
$thumbFilename .= "_".$postfix;
|
||||
|
||||
$thumbFilename .= ".".$ext;
|
||||
|
||||
return($thumbFilename);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// get thumbnail fielpath by parameters.
|
||||
private function getThumbFilepath(){
|
||||
$filename = $this->getThumbFilename();
|
||||
$filepath = $this->pathCache .$filename;
|
||||
return($filepath);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// ouptput emtpy image code.
|
||||
private function outputEmptyImageCode(){
|
||||
echo "empty image";
|
||||
exit();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// outputs image and exit.
|
||||
private function outputImage($filepath){
|
||||
|
||||
$info = UniteFunctionsRev::getPathInfo($filepath);
|
||||
$ext = $info["extension"];
|
||||
$filetime = filemtime($filepath);
|
||||
|
||||
$ext = strtolower($ext);
|
||||
if($ext == "jpg")
|
||||
$ext = "jpeg";
|
||||
|
||||
$numExpires = 31536000; //one year
|
||||
$strExpires = @date('D, d M Y H:i:s',time()+$numExpires);
|
||||
$strModified = @date('D, d M Y H:i:s',$filetime);
|
||||
|
||||
$contents = file_get_contents($filepath);
|
||||
$filesize = strlen($contents);
|
||||
header("Last-Modified: $strModified GMT");
|
||||
header("Expires: $strExpires GMT");
|
||||
header("Cache-Control: public");
|
||||
header("Content-Type: image/$ext");
|
||||
header("Content-Length: $filesize");
|
||||
|
||||
echo $contents;
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// get src image from filepath according the image type
|
||||
private function getGdSrcImage($filepath,$type){
|
||||
// create the image
|
||||
$src_img = false;
|
||||
switch($type){
|
||||
case IMAGETYPE_JPEG:
|
||||
$src_img = @imagecreatefromjpeg($filepath);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
$src_img = @imagecreatefrompng($filepath);
|
||||
break;
|
||||
case IMAGETYPE_GIF:
|
||||
$src_img = @imagecreatefromgif($filepath);
|
||||
break;
|
||||
case IMAGETYPE_BMP:
|
||||
$src_img = @imagecreatefromwbmp($filepath);
|
||||
break;
|
||||
default:
|
||||
$this->throwError("wrong image format, can't resize");
|
||||
break;
|
||||
}
|
||||
|
||||
if($src_img == false){
|
||||
$this->throwError("Can't resize image");
|
||||
}
|
||||
|
||||
return($src_img);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// save gd image to some filepath. return if success or not
|
||||
private function saveGdImage($dst_img,$filepath,$type){
|
||||
$successSaving = false;
|
||||
switch($type){
|
||||
case IMAGETYPE_JPEG:
|
||||
$successSaving = imagejpeg($dst_img,$filepath,$this->jpg_quality);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
$successSaving = imagepng($dst_img,$filepath);
|
||||
break;
|
||||
case IMAGETYPE_GIF:
|
||||
$successSaving = imagegif($dst_img,$filepath);
|
||||
break;
|
||||
case IMAGETYPE_BMP:
|
||||
$successSaving = imagewbmp($dst_img,$filepath);
|
||||
break;
|
||||
}
|
||||
|
||||
return($successSaving);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// crop image to specifix height and width , and save it to new path
|
||||
private function cropImageSaveNew($filepath,$filepathNew){
|
||||
|
||||
$imgInfo = getimagesize($filepath);
|
||||
$imgType = $imgInfo[2];
|
||||
|
||||
$src_img = $this->getGdSrcImage($filepath,$imgType);
|
||||
|
||||
$width = imageSX($src_img);
|
||||
$height = imageSY($src_img);
|
||||
|
||||
//crop the image from the top
|
||||
$startx = 0;
|
||||
$starty = 0;
|
||||
|
||||
//find precrop width and height:
|
||||
$percent = $this->maxWidth / $width;
|
||||
$newWidth = $this->maxWidth;
|
||||
$newHeight = ceil($percent * $height);
|
||||
|
||||
if($this->type == "exact"){ //crop the image from the middle
|
||||
$startx = 0;
|
||||
$starty = ($newHeight-$this->maxHeight)/2 / $percent;
|
||||
}
|
||||
|
||||
if($newHeight < $this->maxHeight){ //by width
|
||||
$percent = $this->maxHeight / $height;
|
||||
$newHeight = $this->maxHeight;
|
||||
$newWidth = ceil($percent * $width);
|
||||
|
||||
if($this->type == "exact"){ //crop the image from the middle
|
||||
$startx = ($newWidth - $this->maxWidth) /2 / $percent; //the startx is related to big image
|
||||
$starty = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//resize the picture:
|
||||
$tmp_img = ImageCreateTrueColor($newWidth,$newHeight);
|
||||
|
||||
$this->handleTransparency($tmp_img,$imgType,$newWidth,$newHeight);
|
||||
|
||||
imagecopyresampled($tmp_img,$src_img,0,0,$startx,$starty,$newWidth,$newHeight,$width,$height);
|
||||
|
||||
$this->handleImageEffects($tmp_img);
|
||||
|
||||
//crop the picture:
|
||||
$dst_img = ImageCreateTrueColor($this->maxWidth,$this->maxHeight);
|
||||
|
||||
$this->handleTransparency($dst_img,$imgType,$this->maxWidth,$this->maxHeight);
|
||||
|
||||
imagecopy($dst_img, $tmp_img, 0, 0, 0, 0, $newWidth, $newHeight);
|
||||
|
||||
//save the picture
|
||||
$is_saved = $this->saveGdImage($dst_img,$filepathNew,$imgType);
|
||||
|
||||
imagedestroy($dst_img);
|
||||
imagedestroy($src_img);
|
||||
imagedestroy($tmp_img);
|
||||
|
||||
return($is_saved);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// if the images are png or gif - handle image transparency
|
||||
private function handleTransparency(&$dst_img,$imgType,$newWidth,$newHeight){
|
||||
//handle transparency:
|
||||
if($imgType == IMAGETYPE_PNG || $imgType == IMAGETYPE_GIF){
|
||||
imagealphablending($dst_img, false);
|
||||
imagesavealpha($dst_img,true);
|
||||
$transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127);
|
||||
imagefilledrectangle($dst_img, 0, 0, $newWidth, $newHeight, $transparent);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// handle image effects
|
||||
private function handleImageEffects(&$imgHandle){
|
||||
if(empty($this->effect))
|
||||
return(false);
|
||||
|
||||
switch($this->effect){
|
||||
case self::EFFECT_BW:
|
||||
if(defined("IMG_FILTER_GRAYSCALE"))
|
||||
imagefilter($imgHandle,IMG_FILTER_GRAYSCALE);
|
||||
break;
|
||||
case self::EFFECT_BRIGHTNESS:
|
||||
if(defined("IMG_FILTER_BRIGHTNESS")){
|
||||
if(!is_numeric($this->effect_arg1))
|
||||
$this->effect_arg1 = 50; //set default value
|
||||
UniteFunctionsRev::validateNumeric($this->effect_arg1,"'ea1' argument");
|
||||
imagefilter($imgHandle,IMG_FILTER_BRIGHTNESS,$this->effect_arg1);
|
||||
}
|
||||
break;
|
||||
case self::EFFECT_DARK:
|
||||
if(defined("IMG_FILTER_BRIGHTNESS")){
|
||||
if(!is_numeric($this->effect_arg1))
|
||||
$this->effect_arg1 = -50; //set default value
|
||||
UniteFunctionsRev::validateNumeric($this->effect_arg1,"'ea1' argument");
|
||||
imagefilter($imgHandle,IMG_FILTER_BRIGHTNESS,$this->effect_arg1);
|
||||
}
|
||||
break;
|
||||
case self::EFFECT_CONTRAST:
|
||||
if(defined("IMG_FILTER_CONTRAST")){
|
||||
if(!is_numeric($this->effect_arg1))
|
||||
$this->effect_arg1 = -5; //set default value
|
||||
imagefilter($imgHandle,IMG_FILTER_CONTRAST,$this->effect_arg1);
|
||||
}
|
||||
break;
|
||||
case self::EFFECT_EDGE:
|
||||
if(defined("IMG_FILTER_EDGEDETECT"))
|
||||
imagefilter($imgHandle,IMG_FILTER_EDGEDETECT);
|
||||
break;
|
||||
case self::EFFECT_EMBOSS:
|
||||
if(defined("IMG_FILTER_EMBOSS"))
|
||||
imagefilter($imgHandle,IMG_FILTER_EMBOSS);
|
||||
break;
|
||||
case self::EFFECT_BLUR:
|
||||
$this->effect_Blur($imgHandle,5);
|
||||
/*
|
||||
if(defined("IMG_FILTER_GAUSSIAN_BLUR"))
|
||||
imagefilter($imgHandle,IMG_FILTER_GAUSSIAN_BLUR);
|
||||
*/
|
||||
break;
|
||||
case self::EFFECT_MEAN:
|
||||
if(defined("IMG_FILTER_MEAN_REMOVAL"))
|
||||
imagefilter($imgHandle,IMG_FILTER_MEAN_REMOVAL);
|
||||
break;
|
||||
case self::EFFECT_SMOOTH:
|
||||
if(defined("IMG_FILTER_SMOOTH")){
|
||||
if(!is_numeric($this->effect_arg1))
|
||||
$this->effect_arg1 = 15; //set default value
|
||||
imagefilter($imgHandle,IMG_FILTER_SMOOTH,$this->effect_arg1);
|
||||
}
|
||||
break;
|
||||
case self::EFFECT_BLUR3:
|
||||
$this->effect_Blur($imgHandle,5);
|
||||
break;
|
||||
default:
|
||||
$this->throwError("Effect not supported: <b>{$this->effect}</b>");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function effect_Blur(&$gdimg, $radius=0.5) {
|
||||
// Taken from Torstein Hרnsi's phpUnsharpMask (see phpthumb.unsharp.php)
|
||||
|
||||
$radius = round(max(0, min($radius, 50)) * 2);
|
||||
if (!$radius) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$w = ImageSX($gdimg);
|
||||
$h = ImageSY($gdimg);
|
||||
if ($imgBlur = ImageCreateTrueColor($w, $h)) {
|
||||
// Gaussian blur matrix:
|
||||
// 1 2 1
|
||||
// 2 4 2
|
||||
// 1 2 1
|
||||
|
||||
// Move copies of the image around one pixel at the time and merge them with weight
|
||||
// according to the matrix. The same matrix is simply repeated for higher radii.
|
||||
for ($i = 0; $i < $radius; $i++) {
|
||||
ImageCopy ($imgBlur, $gdimg, 0, 0, 1, 1, $w - 1, $h - 1); // up left
|
||||
ImageCopyMerge($imgBlur, $gdimg, 1, 1, 0, 0, $w, $h, 50.00000); // down right
|
||||
ImageCopyMerge($imgBlur, $gdimg, 0, 1, 1, 0, $w - 1, $h, 33.33333); // down left
|
||||
ImageCopyMerge($imgBlur, $gdimg, 1, 0, 0, 1, $w, $h - 1, 25.00000); // up right
|
||||
ImageCopyMerge($imgBlur, $gdimg, 0, 0, 1, 0, $w - 1, $h, 33.33333); // left
|
||||
ImageCopyMerge($imgBlur, $gdimg, 1, 0, 0, 0, $w, $h, 25.00000); // right
|
||||
ImageCopyMerge($imgBlur, $gdimg, 0, 0, 0, 1, $w, $h - 1, 20.00000); // up
|
||||
ImageCopyMerge($imgBlur, $gdimg, 0, 1, 0, 0, $w, $h, 16.666667); // down
|
||||
ImageCopyMerge($imgBlur, $gdimg, 0, 0, 0, 0, $w, $h, 50.000000); // center
|
||||
ImageCopy ($gdimg, $imgBlur, 0, 0, 0, 0, $w, $h);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// resize image and save it to new path
|
||||
private function resizeImageSaveNew($filepath,$filepathNew){
|
||||
|
||||
$imgInfo = getimagesize($filepath);
|
||||
$imgType = $imgInfo[2];
|
||||
|
||||
$src_img = $this->getGdSrcImage($filepath,$imgType);
|
||||
|
||||
$width = imageSX($src_img);
|
||||
$height = imageSY($src_img);
|
||||
|
||||
$newWidth = $width;
|
||||
$newHeight = $height;
|
||||
|
||||
//find new width
|
||||
if($height > $this->maxHeight){
|
||||
$procent = $this->maxHeight / $height;
|
||||
$newWidth = ceil($width * $procent);
|
||||
$newHeight = $this->maxHeight;
|
||||
}
|
||||
|
||||
//if the new width is grater than max width, find new height, and remain the width.
|
||||
if($newWidth > $this->maxWidth){
|
||||
$procent = $this->maxWidth / $newWidth;
|
||||
$newHeight = ceil($newHeight * $procent);
|
||||
$newWidth = $this->maxWidth;
|
||||
}
|
||||
|
||||
//if the image don't need to be resized, just copy it from source to destanation.
|
||||
if($newWidth == $width && $newHeight == $height && empty($this->effect)){
|
||||
$success = copy($filepath,$filepathNew);
|
||||
if($success == false)
|
||||
$this->throwError("can't copy the image from one path to another");
|
||||
}
|
||||
else{ //else create the resized image, and save it to new path:
|
||||
$dst_img = ImageCreateTrueColor($newWidth,$newHeight);
|
||||
|
||||
$this->handleTransparency($dst_img,$imgType,$newWidth,$newHeight);
|
||||
|
||||
//copy the new resampled image:
|
||||
imagecopyresampled($dst_img,$src_img,0,0,0,0,$newWidth,$newHeight,$width,$height);
|
||||
|
||||
$this->handleImageEffects($dst_img);
|
||||
|
||||
$is_saved = $this->saveGdImage($dst_img,$filepathNew,$imgType);
|
||||
imagedestroy($dst_img);
|
||||
}
|
||||
|
||||
imagedestroy($src_img);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* set image effect
|
||||
*/
|
||||
public function setEffect($effect,$arg1 = ""){
|
||||
$this->effect = $effect;
|
||||
$this->effect_arg1 = $arg1;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
//return image
|
||||
private function showImage($filename,$maxWidth=-1,$maxHeight=-1,$type=""){
|
||||
|
||||
if(empty($filename))
|
||||
$this->throwError("image filename not found");
|
||||
|
||||
//validate input
|
||||
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!");
|
||||
}
|
||||
|
||||
$filepath = $this->pathImages.$filename;
|
||||
|
||||
|
||||
if(!is_file($filepath)) $this->outputEmptyImageCode();
|
||||
|
||||
//if gd library doesn't exists - output normal image without resizing.
|
||||
if(function_exists("gd_info") == false)
|
||||
$this->throwError("php must support GD Library");
|
||||
|
||||
//check conditions for output original image
|
||||
if(empty($this->effect)){
|
||||
if((is_numeric($maxWidth) == false || is_numeric($maxHeight) == false)) outputImage($filepath);
|
||||
|
||||
if($maxWidth == -1 && $maxHeight == -1)
|
||||
$this->outputImage($filepath);
|
||||
}
|
||||
|
||||
if($maxWidth == -1) $maxWidth = 1000000;
|
||||
if($maxHeight == -1) $maxHeight = 100000;
|
||||
|
||||
//init variables
|
||||
$this->filename = $filename;
|
||||
$this->maxWidth = $maxWidth;
|
||||
$this->maxHeight = $maxHeight;
|
||||
$this->type = $type;
|
||||
|
||||
$filepathNew = $this->getThumbFilepath();
|
||||
|
||||
if(is_file($filepathNew)){
|
||||
$this->outputImage($filepathNew);
|
||||
exit();
|
||||
}
|
||||
|
||||
try{
|
||||
if($type == self::TYPE_EXACT || $type == self::TYPE_EXACT_TOP){
|
||||
$isSaved = $this->cropImageSaveNew($filepath,$filepathNew);
|
||||
}
|
||||
else
|
||||
$isSaved = $this->resizeImageSaveNew($filepath,$filepathNew);
|
||||
|
||||
if($isSaved == false){
|
||||
$this->outputImage($filepath);
|
||||
exit();
|
||||
}
|
||||
|
||||
}catch(Exception $e){
|
||||
$this->outputImage($filepath);
|
||||
}
|
||||
|
||||
if(is_file($filepathNew))
|
||||
$this->outputImage($filepathNew);
|
||||
else
|
||||
$this->outputImage($filepath);
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* show image from get params
|
||||
*/
|
||||
public function showImageFromGet(){
|
||||
|
||||
$imageFilename = UniteFunctionsRev::getGetVar("img");
|
||||
$maxWidth = UniteFunctionsRev::getGetVar("w",-1);
|
||||
$maxHeight = UniteFunctionsRev::getGetVar("h",-1);
|
||||
$type = UniteFunctionsRev::getGetVar("t","");
|
||||
|
||||
//set effect
|
||||
$effect = UniteFunctionsRev::getGetVar("e");
|
||||
$effectArgument1 = UniteFunctionsRev::getGetVar("ea1");
|
||||
|
||||
if(!empty($effect))
|
||||
$this->setEffect($effect,$effectArgument1);
|
||||
|
||||
$this->showImage($imageFilename,$maxWidth,$maxHeight,$type);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// download image, change size and name if needed.
|
||||
public function downloadImage($filename){
|
||||
$filepath = $this->urlImages."/".$filename;
|
||||
if(!is_file($filepath)) {
|
||||
echo "file doesn't exists";
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->outputImageForDownload($filepath,$filename);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// output image for downloading
|
||||
private function outputImageForDownload($filepath,$filename,$mimeType=""){
|
||||
$contents = file_get_contents($filepath);
|
||||
$filesize = strlen($contents);
|
||||
|
||||
if($mimeType == ""){
|
||||
$info = UniteFunctionsRev::getPathInfo($filepath);
|
||||
$ext = $info["extension"];
|
||||
$mimeType = "image/$ext";
|
||||
}
|
||||
|
||||
header("Content-Type: $mimeType");
|
||||
header("Content-Disposition: attachment; filename=\"$filename\"");
|
||||
header("Content-Length: $filesize");
|
||||
echo $contents;
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* validate type
|
||||
* @param unknown_type $type
|
||||
*/
|
||||
public function validateType($type){
|
||||
switch($type){
|
||||
case self::TYPE_EXACT:
|
||||
case self::TYPE_EXACT_TOP:
|
||||
break;
|
||||
default:
|
||||
$this->throwError("Wrong image type: ".$type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
$folderIncludes = dirname(__FILE__)."/";
|
||||
|
||||
require_once $folderIncludes . 'functions.php';
|
||||
require_once $folderIncludes . 'functions.class.php';
|
||||
require_once $folderIncludes . 'functions_wordpress.class.php';
|
||||
require_once $folderIncludes . 'db.class.php';
|
||||
require_once $folderIncludes . 'settings.class.php';
|
||||
require_once $folderIncludes . 'cssparser.class.php';
|
||||
require_once $folderIncludes . 'settings_advances.class.php';
|
||||
require_once $folderIncludes . 'settings_output.class.php';
|
||||
require_once $folderIncludes . 'settings_product.class.php';
|
||||
require_once $folderIncludes . 'settings_product_sidebar.class.php';
|
||||
require_once $folderIncludes . 'image_view.class.php';
|
||||
require_once $folderIncludes . 'zip.class.php';
|
||||
|
||||
?>
|
@ -0,0 +1,961 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* unite settings class.
|
||||
* @version 1.1
|
||||
*
|
||||
*/
|
||||
|
||||
class UniteSettingsRev{
|
||||
|
||||
const COLOR_OUTPUT_FLASH = "flash";
|
||||
const COLOR_OUTPUT_HTML = "html";
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
const RELATED_NONE = "";
|
||||
const TYPE_TEXT = "text";
|
||||
const TYPE_COLOR = "color";
|
||||
const TYPE_SELECT = "list";
|
||||
const TYPE_CHECKBOX = "checkbox";
|
||||
const TYPE_RADIO = "radio";
|
||||
const TYPE_TEXTAREA = "textarea";
|
||||
const TYPE_STATIC_TEXT = "statictext";
|
||||
const TYPE_HR = "hr";
|
||||
const TYPE_CUSTOM = "custom";
|
||||
const ID_PREFIX = "";
|
||||
const TYPE_CONTROL = "control";
|
||||
const TYPE_BUTTON = "button";
|
||||
const TYPE_IMAGE = "image";
|
||||
const TYPE_CHECKLIST = "checklist";
|
||||
|
||||
//------------------------------------------------------------
|
||||
//set data types
|
||||
const DATATYPE_NUMBER = "number";
|
||||
const DATATYPE_STRING = "string";
|
||||
const DATATYPE_BOOLEAN = "boolean";
|
||||
|
||||
const CONTROL_TYPE_ENABLE = "enable";
|
||||
const CONTROL_TYPE_DISABLE = "disable";
|
||||
const CONTROL_TYPE_SHOW = "show";
|
||||
const CONTROL_TYPE_HIDE = "hide";
|
||||
|
||||
//additional parameters that can be added to settings.
|
||||
const PARAM_TEXTSTYLE = "textStyle";
|
||||
const PARAM_ADDPARAMS = "addparams"; //additional text after the field
|
||||
const PARAM_ADDTEXT = "addtext"; //additional text after the field
|
||||
const PARAM_ADDTEXT_BEFORE_ELEMENT = "addtext_before_element"; //additional text after the field
|
||||
const PARAM_CELLSTYLE = "cellStyle"; //additional text after the field
|
||||
|
||||
//view defaults:
|
||||
protected $defaultText = "Enter value";
|
||||
protected $sap_size = 5;
|
||||
|
||||
//other variables:
|
||||
protected $HRIdCounter = 0; //counter of hr id
|
||||
|
||||
protected $arrSettings = array();
|
||||
protected $arrSections = array();
|
||||
protected $arrIndex = array(); //index of name->index of the settings.
|
||||
protected $arrSaps = array();
|
||||
|
||||
//controls:
|
||||
protected $arrControls = array(); //array of items that controlling others (hide/show or enabled/disabled)
|
||||
protected $arrBulkControl = array(); //bulk cotnrol array. if not empty, every settings will be connected with control.
|
||||
|
||||
//custom functions:
|
||||
protected $customFunction_afterSections = null;
|
||||
protected $colorOutputType = self::COLOR_OUTPUT_HTML;
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// constructor
|
||||
public function __construct(){
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// get where query according relatedTo and relatedID.
|
||||
private function getWhereQuery(){
|
||||
$where = "relatedTo='".$this->relatedTo."' and relatedID='".$this->relatedID."'";
|
||||
return($where);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//set type of color output
|
||||
public function setColorOutputType($type){
|
||||
$this->colorOutputType = $type;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//set the related to/id for saving/restoring settings.
|
||||
public function setRelated($relatedTo,$relatedID){
|
||||
$this->relatedTo = $relatedTo;
|
||||
$this->relatedID = $relatedID;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//modify the data before save
|
||||
private function modifySettingsData($arrSettings){
|
||||
|
||||
foreach($arrSettings as $key=>$content){
|
||||
switch(getType($content)){
|
||||
case "string":
|
||||
//replace the unicode line break (sometimes left after json)
|
||||
$content = str_replace("u000a","\n",$content);
|
||||
$content = str_replace("u000d","",$content);
|
||||
break;
|
||||
case "object":
|
||||
case "array":
|
||||
$content = UniteFunctionsRev::convertStdClassToArray($content);
|
||||
break;
|
||||
}
|
||||
|
||||
$arrSettings[$key] = $content;
|
||||
}
|
||||
|
||||
return($arrSettings);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// add the section value to the setting
|
||||
private function checkAndAddSectionAndSap($setting){
|
||||
//add section
|
||||
if(!empty($this->arrSections)){
|
||||
$sectionKey = count($this->arrSections)-1;
|
||||
$setting["section"] = $sectionKey;
|
||||
$section = $this->arrSections[$sectionKey];
|
||||
$sapKey = count($section["arrSaps"])-1;
|
||||
$setting["sap"] = $sapKey;
|
||||
}
|
||||
else{
|
||||
//please impliment add sap normal!!! - without sections
|
||||
}
|
||||
return($setting);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// validate items parameter. throw exception on error
|
||||
private function validateParamItems($arrParams){
|
||||
if(!isset($arrParams["items"])) throw new Exception("no select items presented");
|
||||
if(!is_array($arrParams["items"])) throw new Exception("the items parameter should be array");
|
||||
if(empty($arrParams["items"])) throw new Exception("the items array should not be empty");
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//add this setting to index
|
||||
private function addSettingToIndex($name){
|
||||
$this->arrIndex[$name] = count($this->arrSettings)-1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//get types array from all the settings:
|
||||
protected function getArrTypes(){
|
||||
$arrTypesAssoc = array();
|
||||
$arrTypes = array();
|
||||
foreach($this->arrSettings as $setting){
|
||||
$type = $setting["type"];
|
||||
if(!isset($arrTypesAssoc[$type])) $arrTypes[] = $type;
|
||||
$arrTypesAssoc[$type] = "";
|
||||
}
|
||||
return($arrTypes);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// get json client object for javascript
|
||||
public function getJsonClientString(){
|
||||
$arrSettingTypes = array();
|
||||
foreach($this->arrSettings as $setting){
|
||||
if(isset($setting["name"]))
|
||||
$arrSettingTypes[$setting["name"]] = $setting["datatype"];
|
||||
}
|
||||
$strJson = json_encode($arrSettingTypes);
|
||||
return($strJson);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get settings array
|
||||
*/
|
||||
public function getArrSettings(){
|
||||
return($this->arrSettings);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get sections
|
||||
*/
|
||||
public function getArrSections(){
|
||||
return($this->arrSections);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get controls
|
||||
*/
|
||||
public function getArrControls(){
|
||||
return($this->arrControls);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* set settings array
|
||||
*/
|
||||
public function setArrSettings($arrSettings){
|
||||
$this->arrSettings = $arrSettings;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//get number of settings
|
||||
public function getNumSettings(){
|
||||
$counter = 0;
|
||||
foreach($this->arrSettings as $setting){
|
||||
switch($setting["type"]){
|
||||
case self::TYPE_HR:
|
||||
case self::TYPE_STATIC_TEXT:
|
||||
break;
|
||||
default:
|
||||
$counter++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return($counter);
|
||||
}
|
||||
|
||||
//private function
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// add radio group
|
||||
public function addRadio($name,$arrItems,$text = "",$defaultItem="",$arrParams = array()){
|
||||
$params = array("items"=>$arrItems);
|
||||
$params = array_merge($params,$arrParams);
|
||||
$this->add($name,$defaultItem,$text,self::TYPE_RADIO,$params);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//add text area control
|
||||
public function addTextArea($name,$defaultValue,$text,$arrParams = array()){
|
||||
$this->add($name,$defaultValue,$text,self::TYPE_TEXTAREA,$arrParams);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//add button control
|
||||
public function addButton($name,$value,$arrParams = array()){
|
||||
$this->add($name,$value,"",self::TYPE_BUTTON,$arrParams);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// add checkbox element
|
||||
public function addCheckbox($name,$defaultValue = false,$text = "",$arrParams = array()){
|
||||
$this->add($name,$defaultValue,$text,self::TYPE_CHECKBOX,$arrParams);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//add text box element
|
||||
public function addTextBox($name,$defaultValue = "",$text = "",$arrParams = array()){
|
||||
$this->add($name,$defaultValue,$text,self::TYPE_TEXT,$arrParams);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//add image selector
|
||||
public function addImage($name,$defaultValue = "",$text = "",$arrParams = array()){
|
||||
$this->add($name,$defaultValue,$text,self::TYPE_IMAGE,$arrParams);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//add color picker setting
|
||||
public function addColorPicker($name,$defaultValue = "",$text = "",$arrParams = array()){
|
||||
$this->add($name,$defaultValue,$text,self::TYPE_COLOR,$arrParams);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* add custom setting
|
||||
*/
|
||||
public function addCustom($customType,$name,$defaultValue = "",$text = "",$arrParams = array()){
|
||||
$params = array();
|
||||
$params["custom_type"] = $customType;
|
||||
$params = array_merge($params,$arrParams);
|
||||
|
||||
$this->add($name,$defaultValue,$text,self::TYPE_CUSTOM,$params);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//add horezontal sap
|
||||
public function addHr($name="",$params=array()){
|
||||
$setting = array();
|
||||
$setting["type"] = self::TYPE_HR;
|
||||
|
||||
//set item name
|
||||
$itemName = "";
|
||||
if($name != "") $itemName = $name;
|
||||
else{ //generate hr id
|
||||
$this->HRIdCounter++;
|
||||
$itemName = "hr".$this->HRIdCounter;
|
||||
}
|
||||
|
||||
$setting["id"] = self::ID_PREFIX.$itemName;
|
||||
$setting["id_row"] = $setting["id"]."_row";
|
||||
|
||||
//addsection and sap keys
|
||||
$setting = $this->checkAndAddSectionAndSap($setting);
|
||||
|
||||
$this->checkAddBulkControl($itemName);
|
||||
|
||||
$setting = array_merge($params,$setting);
|
||||
$this->arrSettings[] = $setting;
|
||||
|
||||
//add to settings index
|
||||
$this->addSettingToIndex($itemName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//add static text
|
||||
public function addStaticText($text,$name="",$params=array()){
|
||||
$setting = array();
|
||||
$setting["type"] = self::TYPE_STATIC_TEXT;
|
||||
|
||||
//set item name
|
||||
$itemName = "";
|
||||
if($name != "") $itemName = $name;
|
||||
else{ //generate hr id
|
||||
$this->HRIdCounter++;
|
||||
$itemName = "textitem".$this->HRIdCounter;
|
||||
}
|
||||
|
||||
$setting["id"] = self::ID_PREFIX.$itemName;
|
||||
$setting["id_row"] = $setting["id"]."_row";
|
||||
$setting["text"] = $text;
|
||||
|
||||
$this->checkAddBulkControl($itemName);
|
||||
|
||||
$params = array_merge($params,$setting);
|
||||
|
||||
//addsection and sap keys
|
||||
$setting = $this->checkAndAddSectionAndSap($setting);
|
||||
|
||||
$this->arrSettings[] = $setting;
|
||||
|
||||
//add to settings index
|
||||
$this->addSettingToIndex($itemName);
|
||||
}
|
||||
|
||||
/**
|
||||
* add select setting
|
||||
*/
|
||||
public function addSelect($name,$arrItems,$text,$defaultItem="",$arrParams=array()){
|
||||
$params = array("items"=>$arrItems);
|
||||
$params = array_merge($params,$arrParams);
|
||||
$this->add($name,$defaultItem,$text,self::TYPE_SELECT,$params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add select setting
|
||||
*/
|
||||
public function addChecklist($name,$arrItems,$text,$defaultItem="",$arrParams=array()){
|
||||
$params = array("items"=>$arrItems);
|
||||
$params = array_merge($params,$arrParams);
|
||||
$this->add($name,$defaultItem,$text,self::TYPE_CHECKLIST,$params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* add saporator
|
||||
*/
|
||||
public function addSap($text, $name="", $opened = false){
|
||||
|
||||
if(empty($text))
|
||||
UniteFunctionsRev::throwError("sap $name must have a text");
|
||||
|
||||
//create sap array
|
||||
$sap = array();
|
||||
$sap["name"] = $name;
|
||||
$sap["text"] = $text;
|
||||
|
||||
if($opened == true) $sap["opened"] = true;
|
||||
|
||||
//add sap to current section
|
||||
if(!empty($this->arrSections)){
|
||||
$lastSection = end($this->arrSections);
|
||||
$section_keys = array_keys($this->arrSections);
|
||||
$lastSectionKey = end($section_keys);
|
||||
$arrSaps = $lastSection["arrSaps"];
|
||||
$arrSaps[] = $sap;
|
||||
$this->arrSections[$lastSectionKey]["arrSaps"] = $arrSaps;
|
||||
$sap_keys = array_keys($arrSaps);
|
||||
$sapKey = end($sap_keys);
|
||||
}
|
||||
else{
|
||||
$this->arrSaps[] = $sap;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//get sap data:
|
||||
public function getSap($sapKey,$sectionKey=-1){
|
||||
//get sap without sections:
|
||||
if($sectionKey == -1) return($this->arrSaps[$sapKey]);
|
||||
if(!isset($this->arrSections[$sectionKey])) throw new Exception("Sap on section:".$sectionKey." doesn't exists");
|
||||
$arrSaps = $this->arrSections[$sectionKey]["arrSaps"];
|
||||
if(!isset($arrSaps[$sapKey])) throw new Exception("Sap with key:".$sapKey." doesn't exists");
|
||||
$sap = $arrSaps[$sapKey];
|
||||
return($sap);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// add a new section. Every settings from now on will be related to this section
|
||||
public function addSection($label,$name=""){
|
||||
|
||||
if(!empty($this->arrSettings) && empty($this->arrSections))
|
||||
UniteFunctionsRev::throwError("You should add first section before begin to add settings. (section: $text)");
|
||||
|
||||
if(empty($label))
|
||||
UniteFunctionsRev::throwError("You have some section without text");
|
||||
|
||||
$arrSection = array(
|
||||
"text"=>$label,
|
||||
"arrSaps"=>array(),
|
||||
"name"=>$name
|
||||
);
|
||||
|
||||
$this->arrSections[] = $arrSection;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//add setting, may be in different type, of values
|
||||
protected function add($name,$defaultValue = "",$text = "",$type = self::TYPE_TEXT,$arrParams = array()){
|
||||
|
||||
//validation:
|
||||
if(empty($name)) throw new Exception("Every setting should have a name!");
|
||||
|
||||
switch($type){
|
||||
case self::TYPE_RADIO:
|
||||
case self::TYPE_SELECT:
|
||||
$this->validateParamItems($arrParams);
|
||||
break;
|
||||
case self::TYPE_CHECKBOX:
|
||||
if(!is_bool($defaultValue)) throw new Exception("The checkbox value should be boolean");
|
||||
break;
|
||||
}
|
||||
|
||||
//validate name:
|
||||
if(isset($this->arrIndex[$name])) throw new Exception("Duplicate setting name:".$name);
|
||||
|
||||
$this->checkAddBulkControl($name);
|
||||
|
||||
//set defaults:
|
||||
if($text == "") $text = $this->defaultText;
|
||||
|
||||
$setting = array();
|
||||
$setting["name"] = $name;
|
||||
$setting["id"] = self::ID_PREFIX.$name;
|
||||
$setting["id_service"] = $setting["id"]."_service";
|
||||
$setting["id_row"] = $setting["id"]."_row";
|
||||
$setting["type"] = $type;
|
||||
$setting["text"] = $text;
|
||||
$setting["value"] = $defaultValue;
|
||||
|
||||
//set data type:
|
||||
switch($setting["type"]){
|
||||
case self::TYPE_COLOR:
|
||||
$dataType = self::DATATYPE_STRING;
|
||||
break;
|
||||
default:
|
||||
switch(getType($defaultValue)){
|
||||
case "integer":
|
||||
case "double":
|
||||
$dataType = self::DATATYPE_NUMBER;
|
||||
break;
|
||||
case "boolean":
|
||||
$dataType = self::DATATYPE_BOOLEAN;
|
||||
break;
|
||||
case "string":
|
||||
default:
|
||||
$dataType = self::DATATYPE_STRING;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$setting["datatype"] = $dataType;
|
||||
|
||||
$setting = array_merge($setting,$arrParams);
|
||||
|
||||
//addsection and sap keys
|
||||
$setting = $this->checkAndAddSectionAndSap($setting);
|
||||
|
||||
$this->arrSettings[] = $setting;
|
||||
|
||||
//add to settings index
|
||||
$this->addSettingToIndex($name);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//add a item that controlling visibility of enabled/disabled of other.
|
||||
public function addControl($control_item_name,$controlled_item_name,$control_type,$value){
|
||||
|
||||
UniteFunctionsRev::validateNotEmpty($control_item_name,"control parent");
|
||||
UniteFunctionsRev::validateNotEmpty($controlled_item_name,"control child");
|
||||
UniteFunctionsRev::validateNotEmpty($control_type,"control type");
|
||||
UniteFunctionsRev::validateNotEmpty($value,"control value");
|
||||
|
||||
$arrControl = array();
|
||||
if(isset($this->arrControls[$control_item_name]))
|
||||
$arrControl = $this->arrControls[$control_item_name];
|
||||
$arrControl[] = array("name"=>$controlled_item_name,"type"=>$control_type,"value"=>$value);
|
||||
$this->arrControls[$control_item_name] = $arrControl;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//start control of all settings that comes after this function (between startBulkControl and endBulkControl)
|
||||
public function startBulkControl($control_item_name,$control_type,$value){
|
||||
$this->arrBulkControl = array("control_name"=>$control_item_name,"type"=>$control_type,"value"=>$value);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//end bulk control
|
||||
public function endBulkControl(){
|
||||
$this->arrBulkControl = array();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//build name->(array index) of the settings.
|
||||
private function buildArrSettingsIndex(){
|
||||
$this->arrIndex = array();
|
||||
foreach($this->arrSettings as $key=>$value)
|
||||
if(isset($value["name"])) $this->arrIndex[$value["name"]] = $key;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// set sattes of the settings (enabled/disabled, visible/invisible) by controls
|
||||
public function setSettingsStateByControls(){
|
||||
|
||||
foreach($this->arrControls as $control_name => $arrControlled){
|
||||
//take the control value
|
||||
if(!isset($this->arrIndex[$control_name])) throw new Exception("There is not sutch control setting: '$control_name'");
|
||||
$index = $this->arrIndex[$control_name];
|
||||
$parentValue = strtolower($this->arrSettings[$index]["value"]);
|
||||
|
||||
//set child (controlled) attributes
|
||||
foreach($arrControlled as $controlled){
|
||||
if(!isset($this->arrIndex[$controlled["name"]])) throw new Exception("There is not sutch controlled setting: '".$controlled["name"]."'");
|
||||
$indexChild = $this->arrIndex[$controlled["name"]];
|
||||
$child = $this->arrSettings[$indexChild];
|
||||
$value = strtolower($controlled["value"]);
|
||||
switch($controlled["type"]){
|
||||
case self::CONTROL_TYPE_ENABLE:
|
||||
if($value != $parentValue) $child["disabled"] = true;
|
||||
break;
|
||||
case self::CONTROL_TYPE_DISABLE:
|
||||
if($value == $parentValue) $child["disabled"] = true;
|
||||
break;
|
||||
case self::CONTROL_TYPE_SHOW:
|
||||
if($value != $parentValue) $child["hidden"] = true;
|
||||
break;
|
||||
case self::CONTROL_TYPE_HIDE:
|
||||
if($value == $parentValue) $child["hidden"] = true;
|
||||
break;
|
||||
}
|
||||
$this->arrSettings[$indexChild] = $child;
|
||||
}
|
||||
}//end foreach
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//check that bulk control is available , and add some element to it.
|
||||
private function checkAddBulkControl($name){
|
||||
//add control
|
||||
if(!empty($this->arrBulkControl))
|
||||
$this->addControl($this->arrBulkControl["control_name"],$name,$this->arrBulkControl["type"],$this->arrBulkControl["value"]);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//set custom function that will be run after sections will be drawen
|
||||
public function setCustomDrawFunction_afterSections($func){
|
||||
$this->customFunction_afterSections = $func;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* parse options from xml field
|
||||
* @param $field
|
||||
*/
|
||||
private function getOptionsFromXMLField($field,$fieldName){
|
||||
$arrOptions = array();
|
||||
|
||||
$arrField = (array)$field;
|
||||
$options = UniteFunctionsRev::getVal($arrField, "option");
|
||||
|
||||
if(empty($options))
|
||||
return($arrOptions);
|
||||
|
||||
foreach($options as $option){
|
||||
|
||||
if(gettype($option) == "string")
|
||||
UniteFunctionsRev::throwError("Wrong options type: ".$option." in field: $fieldName");
|
||||
|
||||
$attribs = $option->attributes();
|
||||
|
||||
$optionValue = (string)UniteFunctionsRev::getVal($attribs, "value");
|
||||
$optionText = (string)UniteFunctionsRev::getVal($attribs, "text");
|
||||
|
||||
//validate options:
|
||||
UniteFunctionsRev::validateNotEmpty($optionValue,"option value");
|
||||
UniteFunctionsRev::validateNotEmpty($optionText,"option text");
|
||||
|
||||
$arrOptions[$optionValue] = $optionText;
|
||||
}
|
||||
|
||||
return($arrOptions);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* load settings from xml file
|
||||
*/
|
||||
public function loadXMLFile($filepath){
|
||||
|
||||
if(!file_exists($filepath))
|
||||
UniteFunctionsRev::throwError("File: '$filepath' not exists!!!");
|
||||
|
||||
$obj = simplexml_load_file($filepath);
|
||||
|
||||
if(empty($obj))
|
||||
UniteFunctionsRev::throwError("Wrong xml file format: $filepath");
|
||||
|
||||
$fieldsets = $obj->fieldset;
|
||||
if(!@count($obj->fieldset)){
|
||||
$fieldsets = array($fieldsets);
|
||||
}
|
||||
|
||||
$this->addSection("Xml Settings");
|
||||
|
||||
foreach($fieldsets as $fieldset){
|
||||
|
||||
//Add Section
|
||||
$attribs = $fieldset->attributes();
|
||||
|
||||
$sapName = (string)UniteFunctionsRev::getVal($attribs, "name");
|
||||
$sapLabel = (string)UniteFunctionsRev::getVal($attribs, "label");
|
||||
|
||||
UniteFunctionsRev::validateNotEmpty($sapName,"sapName");
|
||||
UniteFunctionsRev::validateNotEmpty($sapLabel,"sapLabel");
|
||||
|
||||
$this->addSap($sapLabel,$sapName);
|
||||
|
||||
//--- add fields
|
||||
$fieldset = (array)$fieldset;
|
||||
$fields = $fieldset["field"];
|
||||
|
||||
if(is_array($fields) == false)
|
||||
$fields = array($fields);
|
||||
|
||||
foreach($fields as $field){
|
||||
$attribs = $field->attributes();
|
||||
$fieldType = (string)UniteFunctionsRev::getVal($attribs, "type");
|
||||
$fieldName = (string)UniteFunctionsRev::getVal($attribs, "name");
|
||||
$fieldLabel = (string)UniteFunctionsRev::getVal($attribs, "label");
|
||||
$fieldDefaultValue = (string)UniteFunctionsRev::getVal($attribs, "default");
|
||||
|
||||
//all other params will be added to "params array".
|
||||
$arrMustParams = array("type","name","label","default");
|
||||
|
||||
$arrParams = array();
|
||||
|
||||
foreach($attribs as $key=>$value){
|
||||
$key = (string)$key;
|
||||
$value = (string)$value;
|
||||
|
||||
//skip must params:
|
||||
if(in_array($key, $arrMustParams))
|
||||
continue;
|
||||
|
||||
$arrParams[$key] = $value;
|
||||
}
|
||||
|
||||
$options = $this->getOptionsFromXMLField($field,$fieldName);
|
||||
|
||||
//validate must fields:
|
||||
UniteFunctionsRev::validateNotEmpty($fieldType,"type");
|
||||
|
||||
//validate name
|
||||
if($fieldType != self::TYPE_HR && $fieldType != self::TYPE_CONTROL &&
|
||||
$fieldType != "bulk_control_start" && $fieldType != "bulk_control_end")
|
||||
UniteFunctionsRev::validateNotEmpty($fieldName,"name");
|
||||
switch ($fieldType){
|
||||
case self::TYPE_CHECKBOX:
|
||||
$fieldDefaultValue = UniteFunctionsRev::strToBool($fieldDefaultValue);
|
||||
$this->addCheckbox($fieldName,$fieldDefaultValue,$fieldLabel,$arrParams);
|
||||
break;
|
||||
case self::TYPE_COLOR:
|
||||
$this->addColorPicker($fieldName,$fieldDefaultValue,$fieldLabel,$arrParams);
|
||||
break;
|
||||
case self::TYPE_HR:
|
||||
$this->addHr();
|
||||
break;
|
||||
case self::TYPE_TEXT:
|
||||
$this->addTextBox($fieldName,$fieldDefaultValue,$fieldLabel,$arrParams);
|
||||
break;
|
||||
case self::TYPE_STATIC_TEXT:
|
||||
$this->addStaticText($fieldLabel, $fieldName, $arrParams);
|
||||
break;
|
||||
case self::TYPE_IMAGE:
|
||||
$this->addImage($fieldName,$fieldDefaultValue,$fieldLabel,$arrParams);
|
||||
break;
|
||||
case self::TYPE_SELECT:
|
||||
$this->addSelect($fieldName, $options, $fieldLabel,$fieldDefaultValue,$arrParams);
|
||||
break;
|
||||
case self::TYPE_CHECKBOX:
|
||||
$this->addChecklist($fieldName, $options, $fieldLabel,$fieldDefaultValue,$arrParams);
|
||||
break;
|
||||
case self::TYPE_RADIO:
|
||||
$this->addRadio($fieldName, $options, $fieldLabel,$fieldDefaultValue,$arrParams);
|
||||
break;
|
||||
case self::TYPE_TEXTAREA:
|
||||
$this->addTextArea($fieldName, $fieldDefaultValue, $fieldLabel, $arrParams);
|
||||
break;
|
||||
case self::TYPE_CUSTOM:
|
||||
$this->add($fieldName, $fieldDefaultValue, $fieldLabel, self::TYPE_CUSTOM, $arrParams);
|
||||
break;
|
||||
case self::TYPE_CONTROL:
|
||||
$parent = UniteFunctionsRev::getVal($arrParams, "parent");
|
||||
$child = UniteFunctionsRev::getVal($arrParams, "child");
|
||||
$ctype = UniteFunctionsRev::getVal($arrParams, "ctype");
|
||||
$value = UniteFunctionsRev::getVal($arrParams, "value");
|
||||
$this->addControl($parent, $child, $ctype, $value);
|
||||
break;
|
||||
case "bulk_control_start":
|
||||
$parent = UniteFunctionsRev::getVal($arrParams, "parent");
|
||||
$ctype = UniteFunctionsRev::getVal($arrParams, "ctype");
|
||||
$value = UniteFunctionsRev::getVal($arrParams, "value");
|
||||
|
||||
$this->startBulkControl($parent, $ctype, $value);
|
||||
break;
|
||||
case "bulk_control_end":
|
||||
$this->endBulkControl();
|
||||
break;
|
||||
default:
|
||||
UniteFunctionsRev::throwError("wrong type: $fieldType");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get titles and descriptions array
|
||||
*/
|
||||
public function getArrTextFromAllSettings(){
|
||||
$arr = array();
|
||||
$arrUnits = array();
|
||||
|
||||
//get saps array:
|
||||
foreach($this->arrSections as $section){
|
||||
$arrSaps = UniteFunctionsRev::getVal($section, "arrSaps");
|
||||
if(empty($arrSaps))
|
||||
continue;
|
||||
foreach($arrSaps as $sap){
|
||||
$text = $sap["text"];
|
||||
if(!empty($text))
|
||||
$arr[] = $text;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->arrSettings as $setting){
|
||||
|
||||
$text = UniteFunctionsRev::getVal($setting, "text");
|
||||
$desc = UniteFunctionsRev::getVal($setting, "description");
|
||||
$unit = UniteFunctionsRev::getVal($setting, "unit");
|
||||
|
||||
if(!empty($text))
|
||||
$arr[] = $text;
|
||||
|
||||
if(!empty($desc))
|
||||
$arr[] = $desc;
|
||||
|
||||
if(!empty($unit)){
|
||||
if(!isset($arrUnits[$unit]))
|
||||
$arr[] = $unit;
|
||||
$arrUnits[$unit] = true;
|
||||
}
|
||||
|
||||
$items = UniteFunctionsRev::getVal($setting, "items");
|
||||
if(!empty($items)){
|
||||
foreach($items as $item){
|
||||
if(!isset($arrUnits[$item]))
|
||||
$arr[] = $item;
|
||||
$arrUnits[$item] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return($arr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get setting array by name
|
||||
*/
|
||||
public function getSettingByName($name){
|
||||
|
||||
//if index present
|
||||
if(!empty($this->arrIndex)){
|
||||
if(array_key_exists($name, $this->arrIndex) == false)
|
||||
UniteFunctionsRev::throwError("setting $name not found");
|
||||
$index = $this->arrIndex[$name];
|
||||
$setting = $this->arrSettings[$index];
|
||||
return($setting);
|
||||
}
|
||||
|
||||
//if no index
|
||||
foreach($this->arrSettings as $setting){
|
||||
$settingName = UniteFunctionsRev::getVal($setting, "name");
|
||||
if($settingName == $name)
|
||||
return($setting);
|
||||
}
|
||||
|
||||
UniteFunctionsRev::throwError("Setting with name: $name don't exists");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get value of some setting
|
||||
* @param $name
|
||||
*/
|
||||
public function getSettingValue($name,$default=""){
|
||||
$setting = $this->getSettingByName($name);
|
||||
$value = UniteFunctionsRev::getVal($setting, "value",$default);
|
||||
|
||||
return($value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* update setting array by name
|
||||
*/
|
||||
public function updateArrSettingByName($name,$setting){
|
||||
|
||||
foreach($this->arrSettings as $key => $settingExisting){
|
||||
$settingName = UniteFunctionsRev::getVal($settingExisting,"name");
|
||||
if($settingName == $name){
|
||||
$this->arrSettings[$key] = $setting;
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
UniteFunctionsRev::throwError("Setting with name: $name don't exists");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* update default value in the setting
|
||||
*/
|
||||
public function updateSettingValue($name,$value){
|
||||
$setting = $this->getSettingByName($name);
|
||||
$setting["value"] = $value;
|
||||
|
||||
$this->updateArrSettingByName($name, $setting);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* set values from array of stored settings elsewhere.
|
||||
*/
|
||||
public function setStoredValues($arrValues){
|
||||
|
||||
foreach($this->arrSettings as $key=>$setting){
|
||||
$name = UniteFunctionsRev::getVal($setting, "name");
|
||||
|
||||
//type consolidation
|
||||
$type = UniteFunctionsRev::getVal($setting, "type");
|
||||
|
||||
$customType = UniteFunctionsRev::getVal($setting, "custom_type");
|
||||
if(!empty($customType))
|
||||
$type .= ".".$customType;
|
||||
|
||||
switch($type){
|
||||
case "custom.kenburns_position":
|
||||
$name = $setting["name"];
|
||||
if(array_key_exists($name."_hor", $arrValues)){
|
||||
$value_vert = UniteFunctionsRev::getVal($arrValues, $name."_vert","random");
|
||||
$value_hor = UniteFunctionsRev::getVal($arrValues, $name."_hor","random");
|
||||
$this->arrSettings[$key]["value"] = "$value_vert,$value_hor";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if(array_key_exists($name, $arrValues)){
|
||||
$this->arrSettings[$key]["value"] = $arrValues[$name];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get setting values. replace from stored ones if given
|
||||
*/
|
||||
public function getArrValues(){
|
||||
|
||||
$arrSettingsOutput = array();
|
||||
|
||||
//modify settings by type
|
||||
foreach($this->arrSettings as $setting){
|
||||
if($setting["type"] == self::TYPE_HR
|
||||
||$setting["type"] == self::TYPE_STATIC_TEXT)
|
||||
continue;
|
||||
|
||||
$value = $setting["value"];
|
||||
|
||||
//modify value by type
|
||||
switch($setting["type"]){
|
||||
case self::TYPE_COLOR:
|
||||
$value = strtolower($value);
|
||||
//set color output type
|
||||
if($this->colorOutputType == self::COLOR_OUTPUT_FLASH)
|
||||
$value = str_replace("#","0x",$value);
|
||||
break;
|
||||
case self::TYPE_CHECKBOX:
|
||||
if($value == true) $value = "true";
|
||||
else $value = "false";
|
||||
break;
|
||||
}
|
||||
|
||||
//remove lf
|
||||
if(isset($setting["remove_lf"])){
|
||||
$value = str_replace("\n","",$value);
|
||||
$value = str_replace("\r\n","",$value);
|
||||
}
|
||||
|
||||
$arrSettingsOutput[$setting["name"]] = $value;
|
||||
}
|
||||
|
||||
return($arrSettingsOutput);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
// advanced settings class. adds some advanced features
|
||||
class UniteSettingsAdvancedRev extends UniteSettingsRev{
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//add boolean true/false select with custom names
|
||||
public function addSelect_boolean($name,$text,$bValue=true,$firstItem="Enable",$secondItem="Disable",$arrParams=array()){
|
||||
$arrItems = array("true"=>$firstItem,"false"=>$secondItem);
|
||||
$defaultText = "true";
|
||||
if($bValue == false) $defaultText = "false";
|
||||
$this->addSelect($name,$arrItems,$text,$defaultText,$arrParams);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//add float select
|
||||
public function addSelect_float($name,$defaultValue,$text,$arrParams=array()){
|
||||
$this->addSelect($name,array("left"=>"Left","right"=>"Right"),$text,$defaultValue,$arrParams);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//add align select
|
||||
public function addSelect_alignX($name,$defaultValue,$text,$arrParams=array()){
|
||||
$this->addSelect($name,array("left"=>"Left","center"=>"Center","right"=>"Right"),$text,$defaultValue,$arrParams);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//add align select
|
||||
public function addSelect_alignY($name,$defaultValue,$text,$arrParams=array()){
|
||||
$this->addSelect($name,array("top"=>"Top","middle"=>"Middle","bottom"=>"Bottom"),$text,$defaultValue,$arrParams);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//add transitions select
|
||||
public function addSelect_border($name,$defaultValue,$text,$arrParams=array()){
|
||||
$arrItems = array();
|
||||
$arrItems["solid"] = "Solid";
|
||||
$arrItems["dashed"] = "Dashed";
|
||||
$arrItems["dotted"] = "Dotted";
|
||||
$arrItems["double"] = "Double";
|
||||
$arrItems["groove"] = "Groove";
|
||||
$arrItems["ridge"] = "Ridge";
|
||||
$arrItems["inset"] = "Inset";
|
||||
$arrItems["outset"] = "Outset";
|
||||
$this->addSelect($name,$arrItems,$text,$defaultValue,$arrParams);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//add transitions select
|
||||
public function addSelect_textDecoration($name,$defaultValue,$text,$arrParams=array()){
|
||||
$arrItems = array();
|
||||
$arrItems["none"] = "None";
|
||||
$arrItems["underline"] = "Underline";
|
||||
$arrItems["overline"] = "Overline";
|
||||
$arrItems["line-through"] = "Line-through";
|
||||
$this->addSelect($name,$arrItems,$text,$defaultValue,$arrParams);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//add transitions select - arrExtensions may be string, and lower case
|
||||
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 = UniteFunctionsRev::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);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//add transitions select
|
||||
public function addSelect_transitions($name,$defaultValue,$text,$arrParams=array()){
|
||||
$arrItems = array();
|
||||
$arrItems["linear"] = "Linear";
|
||||
$arrItems["easeOutQuint"] = "EaseOut";
|
||||
$arrItems["easeInQuint"] = "EaseIn";
|
||||
$arrItems["easeInOutQuad"] = "EaseInOut";
|
||||
|
||||
$arrItems["easeOutElastic"] = "EaseIn - Elastic";
|
||||
$arrItems["easeOutBounce"] = "EaseIn - Bounce";
|
||||
$arrItems["easeOutBack"] = "EaseIn - Back";
|
||||
$arrItems["easeOutQuart"] = "EaseIn - Quart";
|
||||
$arrItems["easeOutExpo"] = "EaseIn - Expo";
|
||||
|
||||
$arrItems["easeInElastic"] = "EaseOut - Elastic";
|
||||
$arrItems["easeInBounce"] = "EaseOut - Bounce";
|
||||
$arrItems["easeInBack"] = "EaseOut - Back";
|
||||
$arrItems["easeInQuart"] = "EaseOut - Quart";
|
||||
$arrItems["easeInExpo"] = "EaseOut - Expo";
|
||||
|
||||
$arrItems["easeInOutElastic"] = "EaseInOut - Elastic";
|
||||
$arrItems["easeInOutBounce"] = "EaseInOut - Bounce";
|
||||
$arrItems["easeInOutBack"] = "EaseInOut - Back";
|
||||
$arrItems["easeInOutQuart"] = "EaseInOut - Quart";
|
||||
$arrItems["easeInOutExpo"] = "EaseInOut - Expo";
|
||||
|
||||
$this->addSelect($name,$arrItems,$text,$defaultValue,$arrParams);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,248 @@
|
||||
<?php
|
||||
|
||||
class UniteSettingsOutputRev{
|
||||
|
||||
protected $arrSettings = array();
|
||||
protected $settings;
|
||||
protected $formID;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* init the output settings
|
||||
*/
|
||||
public function init(UniteSettingsRev $settings){
|
||||
$this->settings = new UniteSettingsRev();
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* draw order box
|
||||
* @param $setting
|
||||
*/
|
||||
protected function drawOrderbox($setting){
|
||||
|
||||
$items = $setting["items"];
|
||||
|
||||
//get arrItems by saved value
|
||||
$arrItems = array();
|
||||
|
||||
if(!empty($setting["value"]) &&
|
||||
getType($setting["value"]) == "array" &&
|
||||
count($setting["value"]) == count($items)){
|
||||
|
||||
$savedItems = $setting["value"];
|
||||
|
||||
foreach($savedItems as $value){
|
||||
$text = $value;
|
||||
if(isset($items[$value]))
|
||||
$text = $items[$value];
|
||||
$arrItems[] = array("value"=>$value,"text"=>$text);
|
||||
}
|
||||
} //get arrItems only from original items
|
||||
else{
|
||||
foreach($items as $value=>$text)
|
||||
$arrItems[] = array("value"=>$value,"text"=>$text);
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<ul class="orderbox" id="<?php echo $setting["id"]?>">
|
||||
<?php
|
||||
foreach($arrItems as $item){
|
||||
$itemKey = $item["value"];
|
||||
$itemText = $item["text"];
|
||||
|
||||
$value = (getType($itemKey) == "string")?$itemKey:$itemText;
|
||||
?>
|
||||
<li>
|
||||
<div class="div_value"><?php echo $value?></div>
|
||||
<div class="div_text"><?php echo $itemText?></div>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//draw advanced order box
|
||||
protected function drawOrderbox_advanced($setting){
|
||||
|
||||
$items = $setting["items"];
|
||||
if(!is_array($items))
|
||||
$this->throwError("Orderbox error - the items option must be array (items)");
|
||||
|
||||
//get arrItems modify items by saved value
|
||||
|
||||
if(!empty($setting["value"]) &&
|
||||
getType($setting["value"]) == "array" &&
|
||||
count($setting["value"]) == count($items)):
|
||||
|
||||
$savedItems = $setting["value"];
|
||||
|
||||
//make assoc array by id:
|
||||
$arrAssoc = array();
|
||||
foreach($items as $item)
|
||||
$arrAssoc[$item[0]] = $item[1];
|
||||
|
||||
foreach($savedItems as $item){
|
||||
$value = $item["id"];
|
||||
$text = $value;
|
||||
if(isset($arrAssoc[$value]))
|
||||
$text = $arrAssoc[$value];
|
||||
$arrItems[] = array($value,$text,$item["enabled"]);
|
||||
}
|
||||
else:
|
||||
$arrItems = $items;
|
||||
endif;
|
||||
|
||||
?>
|
||||
<ul class="orderbox_advanced" id="<?php echo $setting["id"]?>">
|
||||
<?php
|
||||
foreach($arrItems as $arrItem){
|
||||
switch(getType($arrItem)){
|
||||
case "string":
|
||||
$value = $arrItem;
|
||||
$text = $arrItem;
|
||||
$enabled = true;
|
||||
break;
|
||||
case "array":
|
||||
$value = $arrItem[0];
|
||||
$text = (count($arrItem)>1)?$arrItem[1]:$arrItem[0];
|
||||
$enabled = (count($arrItem)>2)?$arrItem[2]:true;
|
||||
break;
|
||||
default:
|
||||
$this->throwError("Error in setting:".$setting.". unknown item type.");
|
||||
break;
|
||||
}
|
||||
|
||||
$checkboxClass = $enabled ? "div_checkbox_on" : "div_checkbox_off";
|
||||
|
||||
?>
|
||||
<li>
|
||||
<div class="div_value"><?php echo $value?></div>
|
||||
<div class="div_checkbox <?php echo $checkboxClass?>"></div>
|
||||
<div class="div_text"><?php echo $text?></div>
|
||||
<div class="div_handle"></div>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* draw includes of the settings.
|
||||
*/
|
||||
public function drawHeaderIncludes(){
|
||||
|
||||
$arrSections = $this->settings->getArrSections();
|
||||
$arrControls = $this->settings->getArrControls();
|
||||
|
||||
$formID = $this->formID;
|
||||
|
||||
$arrOnReady = array();
|
||||
$arrJs = array();
|
||||
|
||||
//put json string types
|
||||
$jsonString = $this->settings->getJsonClientString();
|
||||
|
||||
//$arrJs[] = "obj.jsonSettingTypes = '$jsonString'";
|
||||
//$arrJs[] = "obj.objSettingTypes = JSON.parse(obj.jsonSettingTypes);";
|
||||
|
||||
//put sections vars
|
||||
/*
|
||||
if(!empty($arrSections)){
|
||||
$arrJs[] = "obj.sectionsEnabled = true;";
|
||||
$arrJs[] = "obj.numSections = ".count($arrSections).";";
|
||||
}
|
||||
else
|
||||
$arrJs[] = "obj.sectionsEnabled = false;";
|
||||
*/
|
||||
|
||||
//put the settings into form id
|
||||
|
||||
$arrJs[] = "g_settingsObj['$formID'] = {}";
|
||||
|
||||
//put controls json object:
|
||||
if(!empty($arrControls)){
|
||||
$strControls = json_encode($arrControls);
|
||||
$arrJs[] = "g_settingsObj['$formID'].jsonControls = '".$strControls."'";
|
||||
$arrJs[] = "g_settingsObj['$formID'].controls = JSON.parse(g_settingsObj['$formID'].jsonControls);";
|
||||
}
|
||||
|
||||
/*
|
||||
//put types onready function
|
||||
$arrTypes = $this->getArrTypes();
|
||||
//put script includes:
|
||||
foreach($arrTypes as $type){
|
||||
switch($type){
|
||||
case UniteSettingsRev::TYPE_ORDERBOX:
|
||||
$arrOnReady[] = "$(function() { $( '.orderbox' ).sortable();}); ";
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_ORDERBOX_ADVANCED:
|
||||
$arrOnReady[] = "init_advanced_orderbox();";
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
//put js vars and onready func.
|
||||
|
||||
echo "<script type='text/javascript'>\n";
|
||||
|
||||
//put js
|
||||
foreach($arrJs as $line){
|
||||
echo $line."\n";
|
||||
}
|
||||
|
||||
if(!empty($arrOnReady)):
|
||||
//put onready
|
||||
echo "$(document).ready(function(){\n";
|
||||
foreach($arrOnReady as $line){
|
||||
echo $line."\n";
|
||||
}
|
||||
echo "});";
|
||||
endif;
|
||||
echo "\n</script>\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// draw after body additional settings accesories
|
||||
public function drawAfterBody(){
|
||||
$arrTypes = $this->settings->getArrTypes();
|
||||
foreach($arrTypes as $type){
|
||||
switch($type){
|
||||
case self::TYPE_COLOR:
|
||||
?>
|
||||
<div id='divPickerWrapper' style='position:absolute;display:none;'><div id='divColorPicker'></div></div>
|
||||
<?php
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* do some operation before drawing the settings.
|
||||
*/
|
||||
protected function prepareToDraw(){
|
||||
|
||||
$this->settings->setSettingsStateByControls();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,618 @@
|
||||
<?php
|
||||
|
||||
class UniteSettingsRevProductRev extends UniteSettingsOutputRev{
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//draw text as input
|
||||
protected function drawTextInput($setting) {
|
||||
$disabled = "";
|
||||
$style="";
|
||||
$readonly = "";
|
||||
|
||||
if(isset($setting["style"]))
|
||||
$style = "style='".$setting["style"]."'";
|
||||
if(isset($setting["disabled"]))
|
||||
$disabled = 'disabled="disabled"';
|
||||
|
||||
if(isset($setting["readonly"])){
|
||||
$readonly = "readonly='readonly'";
|
||||
}
|
||||
|
||||
$class = "regular-text";
|
||||
|
||||
if(isset($setting["class"]) && !empty($setting["class"])){
|
||||
$class = $setting["class"];
|
||||
|
||||
//convert short classes:
|
||||
switch($class){
|
||||
case "small":
|
||||
$class = "small-text";
|
||||
break;
|
||||
case "code":
|
||||
$class = "regular-text code";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($class))
|
||||
$class = "class='$class'";
|
||||
|
||||
?>
|
||||
<input type="text" <?php echo $class?> <?php echo $style?> <?php echo $disabled?><?php echo $readonly?> id="<?php echo $setting["id"]?>" name="<?php echo $setting["name"]?>" value="<?php echo $setting["value"]?>" />
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* draw imaeg input:
|
||||
* @param $setting
|
||||
*/
|
||||
protected function drawImageInput($setting){
|
||||
|
||||
$class = UniteFunctionsRev::getVal($setting, "class");
|
||||
|
||||
if(!empty($class))
|
||||
$class = "class='$class'";
|
||||
|
||||
$settingsID = $setting["id"];
|
||||
|
||||
$buttonID = $settingsID."_button";
|
||||
|
||||
$spanPreviewID = $buttonID."_preview";
|
||||
|
||||
$img = "";
|
||||
$value = UniteFunctionsRev::getVal($setting, "value");
|
||||
|
||||
if(!empty($value)){
|
||||
$urlImage = $value;
|
||||
$imagePath = UniteFunctionsWPRev::getImageRealPathFromUrl($urlImage);
|
||||
if(file_exists($realPath)){
|
||||
$filepath = UniteFunctionsWPRev::getImagePathFromURL($urlImage);
|
||||
$urlImage = UniteBaseClassRev::getImageUrl($filepath,100,70,true);
|
||||
}
|
||||
|
||||
$img = "<img width='100' height='70' src='$urlImage'></img>";
|
||||
}
|
||||
|
||||
?>
|
||||
<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?>" class='button-image-select <?php echo $class?>' value="Choose Image"></input>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//draw a color picker
|
||||
protected function drawColorPickerInput($setting){
|
||||
$bgcolor = $setting["value"];
|
||||
$bgcolor = str_replace("0x","#",$bgcolor);
|
||||
// set the forent color (by black and white value)
|
||||
$rgb = UniteFunctionsRev::html2rgb($bgcolor);
|
||||
$bw = UniteFunctionsRev::yiq($rgb[0],$rgb[1],$rgb[2]);
|
||||
$color = "#000000";
|
||||
if($bw<128) $color = "#ffffff";
|
||||
|
||||
|
||||
$disabled = "";
|
||||
if(isset($setting["disabled"])){
|
||||
$color = "";
|
||||
$disabled = 'disabled="disabled"';
|
||||
}
|
||||
|
||||
$style="style='background-color:$bgcolor;color:$color'";
|
||||
|
||||
?>
|
||||
<input type="text" class="inputColorPicker" id="<?php echo $setting["id"]?>" <?php echo $style?> name="<?php echo $setting["name"]?>" value="<?php echo $bgcolor?>" <?php echo $disabled?>></input>
|
||||
<?php
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// draw setting input by type
|
||||
protected function drawInputs($setting){
|
||||
switch($setting["type"]){
|
||||
case UniteSettingsRev::TYPE_TEXT:
|
||||
$this->drawTextInput($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_COLOR:
|
||||
$this->drawColorPickerInput($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_SELECT:
|
||||
$this->drawSelectInput($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_CHECKLIST:
|
||||
$this->drawChecklistInput($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_CHECKBOX:
|
||||
$this->drawCheckboxInput($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_RADIO:
|
||||
$this->drawRadioInput($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_TEXTAREA:
|
||||
$this->drawTextAreaInput($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_IMAGE:
|
||||
$this->drawImageInput($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_CUSTOM:
|
||||
if(method_exists($this,"drawCustomInputs") == false){
|
||||
UniteFunctionsRev::throwError("Method don't exists: drawCustomInputs, please override the class");
|
||||
}
|
||||
$this->drawCustomInputs($setting);
|
||||
break;
|
||||
default:
|
||||
throw new Exception("wrong setting type - ".$setting["type"]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// draw text area input
|
||||
|
||||
protected function drawTextAreaInput($setting){
|
||||
|
||||
$disabled = "";
|
||||
if (isset($setting["disabled"])) $disabled = 'disabled="disabled"';
|
||||
|
||||
$style = "";
|
||||
if(isset($setting["style"]))
|
||||
$style = "style='".$setting["style"]."'";
|
||||
|
||||
$rows = UniteFunctionsRev::getVal($setting, "rows");
|
||||
if(!empty($rows))
|
||||
$rows = "rows='$rows'";
|
||||
|
||||
$cols = UniteFunctionsRev::getVal($setting, "cols");
|
||||
if(!empty($cols))
|
||||
$cols = "cols='$cols'";
|
||||
|
||||
?>
|
||||
<textarea id="<?php echo $setting["id"]?>" name="<?php echo $setting["name"]?>" <?php echo $style?> <?php echo $disabled?> <?php echo $rows?> <?php echo $cols?> ><?php echo $setting["value"]?></textarea>
|
||||
<?php
|
||||
if(!empty($cols))
|
||||
echo "<br>"; //break line on big textareas.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* draw radio input
|
||||
*/
|
||||
protected function drawRadioInput($setting){
|
||||
$items = $setting["items"];
|
||||
$settingID = UniteFunctionsRev::getVal($setting, "id");
|
||||
$wrapperID = $settingID."_wrapper";
|
||||
|
||||
$addParams = UniteFunctionsRev::getVal($setting, "addparams");
|
||||
|
||||
$counter = 0;
|
||||
?>
|
||||
<span id="<?php echo $wrapperID?>" class="radio_settings_wrapper" <?php echo $addParams?>>
|
||||
<?php
|
||||
foreach($items as $value=>$text):
|
||||
$counter++;
|
||||
$radioID = $setting["id"]."_".$counter;
|
||||
$checked = "";
|
||||
if($value == $setting["value"]) $checked = " checked";
|
||||
?>
|
||||
<input type="radio" id="<?php echo $radioID?>" value="<?php echo $value?>" name="<?php echo $setting["name"]?>" <?php echo $checked?>/>
|
||||
<label for="<?php echo $radioID?>" style="cursor:pointer;"><?php echo $text?></label>
|
||||
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</span>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* draw checkbox
|
||||
*/
|
||||
protected function drawCheckboxInput($setting){
|
||||
$checked = "";
|
||||
if($setting["value"] == true) $checked = 'checked="checked"';
|
||||
?>
|
||||
<input type="checkbox" id="<?php echo $setting["id"]?>" class="inputCheckbox" name="<?php echo $setting["name"]?>" <?php echo $checked?>/>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* draw select input
|
||||
*/
|
||||
protected function drawSelectInput($setting){
|
||||
|
||||
$className = "";
|
||||
if(isset($this->arrControls[$setting["name"]])) $className = "control";
|
||||
$class = "";
|
||||
if($className != "") $class = "class='".$className."'";
|
||||
|
||||
$disabled = "";
|
||||
if(isset($setting["disabled"])) $disabled = 'disabled="disabled"';
|
||||
|
||||
?>
|
||||
<select id="<?php echo $setting["id"]?>" name="<?php echo $setting["name"]?>" <?php echo $disabled?> <?php echo $class?>>
|
||||
<?php
|
||||
foreach($setting["items"] as $value=>$text):
|
||||
$text = __($text,REVSLIDER_TEXTDOMAIN);
|
||||
$selected = "";
|
||||
if($value == $setting["value"]) $selected = 'selected="selected"';
|
||||
?>
|
||||
<option value="<?php echo $value?>" <?php echo $selected?>><?php echo $text?></option>
|
||||
<?php
|
||||
endforeach
|
||||
?>
|
||||
</select>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* draw checklist input
|
||||
* @param unknown_type $setting
|
||||
*/
|
||||
protected function drawChecklistInput($setting){
|
||||
|
||||
$className = "input_checklist";
|
||||
if(isset($this->arrControls[$setting["name"]]))
|
||||
$className .= " control";
|
||||
|
||||
$class = "";
|
||||
if($className != "") $class = "class='".$className."'";
|
||||
|
||||
$disabled = "";
|
||||
if(isset($setting["disabled"])) $disabled = 'disabled="disabled"';
|
||||
|
||||
$args = UniteFunctionsRev::getVal($setting, "args");
|
||||
|
||||
$settingValue = $setting["value"];
|
||||
|
||||
if(strpos($settingValue,",") !== false)
|
||||
$settingValue = explode(",", $settingValue);
|
||||
|
||||
$style = "z-index:1000;";
|
||||
$minWidth = UniteFunctionsRev::getVal($setting, "minwidth");
|
||||
|
||||
if(!empty($minWidth)){
|
||||
$style .= "min-width:{$minWidth}px;";
|
||||
$args .= " data-minwidth='{$minWidth}'";
|
||||
}
|
||||
|
||||
?>
|
||||
<select id="<?php echo $setting["id"]?>" name="<?php echo $setting["name"]?>" <?php echo $disabled?> multiple <?php echo $class?> <?php echo $args?> size="1" style="<?php echo $style?>">
|
||||
<?php
|
||||
foreach($setting["items"] as $value=>$text):
|
||||
//set selected
|
||||
$selected = "";
|
||||
$addition = "";
|
||||
if(strpos($value,"option_disabled") === 0){
|
||||
$addition = "disabled";
|
||||
}else{
|
||||
if(is_array($settingValue)){
|
||||
if(array_search($value, $settingValue) !== false)
|
||||
$selected = 'selected="selected"';
|
||||
}else{
|
||||
if($value == $settingValue)
|
||||
$selected = 'selected="selected"';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<option <?php echo $addition?> value="<?php echo $value?>" <?php echo $selected?>><?php echo $text?></option>
|
||||
<?php
|
||||
endforeach
|
||||
?>
|
||||
</select>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//draw hr row
|
||||
protected function drawTextRow($setting){
|
||||
|
||||
//set cell style
|
||||
$cellStyle = "";
|
||||
if(isset($setting["padding"]))
|
||||
$cellStyle .= "padding-left:".$setting["padding"].";";
|
||||
|
||||
if(!empty($cellStyle))
|
||||
$cellStyle="style='$cellStyle'";
|
||||
|
||||
//set style
|
||||
$rowStyle = "";
|
||||
if(isset($setting["hidden"]))
|
||||
$rowStyle .= "display:none;";
|
||||
|
||||
if(!empty($rowStyle))
|
||||
$rowStyle = "style='$rowStyle'";
|
||||
|
||||
?>
|
||||
<tr id="<?php echo $setting["id_row"]?>" <?php echo $rowStyle ?> valign="top">
|
||||
<td colspan="4" align="right" <?php echo $cellStyle?>>
|
||||
<span class="spanSettingsStaticText"><?php echo $setting["text"]?></span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//draw hr row
|
||||
protected function drawHrRow($setting){
|
||||
//set hidden
|
||||
$rowStyle = "";
|
||||
if(isset($setting["hidden"])) $rowStyle = "style='display:none;'";
|
||||
|
||||
$class = UniteFunctionsRev::getVal($setting, "class");
|
||||
if(!empty($class))
|
||||
$class = "class='$class'";
|
||||
|
||||
?>
|
||||
<tr id="<?php echo $setting["id_row"]?>" <?php echo $rowStyle ?>>
|
||||
<td colspan="4" align="left" style="text-align:left;">
|
||||
<hr <?php echo $class; ?> />
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//draw settings row
|
||||
protected function drawSettingRow($setting){
|
||||
|
||||
//set cellstyle:
|
||||
$cellStyle = "";
|
||||
if(isset($setting[UniteSettingsRev::PARAM_CELLSTYLE])){
|
||||
$cellStyle .= $setting[UniteSettingsRev::PARAM_CELLSTYLE];
|
||||
}
|
||||
|
||||
//set text style:
|
||||
$textStyle = $cellStyle;
|
||||
if(isset($setting[UniteSettingsRev::PARAM_TEXTSTYLE])){
|
||||
$textStyle .= $setting[UniteSettingsRev::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='disabled'";
|
||||
|
||||
//modify text:
|
||||
$text = UniteFunctionsRev::getVal($setting,"text","");
|
||||
// prevent line break (convert spaces to nbsp)
|
||||
$text = str_replace(" "," ",$text);
|
||||
switch($setting["type"]){
|
||||
case UniteSettingsRev::TYPE_CHECKBOX:
|
||||
$text = "<label for='".$setting["id"]."' style='cursor:pointer;'>$text</label>";
|
||||
break;
|
||||
}
|
||||
|
||||
//set settings text width:
|
||||
$textWidth = "";
|
||||
if(isset($setting["textWidth"])) $textWidth = 'width="'.$setting["textWidth"].'"';
|
||||
|
||||
$description = UniteFunctionsRev::getVal($setting, "description");
|
||||
$required = UniteFunctionsRev::getVal($setting, "required");
|
||||
|
||||
?>
|
||||
<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 echo $text?>:
|
||||
</th>
|
||||
<td <?php echo $cellStyle?>>
|
||||
<?php
|
||||
$this->drawInputs($setting);
|
||||
?>
|
||||
<?php if(!empty($required)):?>
|
||||
<span class='setting_required'>*</span>
|
||||
<?php endif?>
|
||||
<?php if(!empty($description)):?>
|
||||
<span class="description"><?php echo $description?></span>
|
||||
<?php endif?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//draw all settings
|
||||
public function drawSettings(){
|
||||
$this->drawHeaderIncludes();
|
||||
$this->prepareToDraw();
|
||||
|
||||
//draw main div
|
||||
$lastSectionKey = -1;
|
||||
$visibleSectionKey = 0;
|
||||
$lastSapKey = -1;
|
||||
|
||||
$arrSections = $this->settings->getArrSections();
|
||||
$arrSettings = $this->settings->getArrSettings();
|
||||
|
||||
//draw settings - simple
|
||||
if(empty($arrSections)):
|
||||
?><table class='form-table'><?php
|
||||
foreach($arrSettings as $key=>$setting){
|
||||
switch($setting["type"]){
|
||||
case UniteSettingsRev::TYPE_HR:
|
||||
$this->drawHrRow($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_STATIC_TEXT:
|
||||
$this->drawTextRow($setting);
|
||||
break;
|
||||
default:
|
||||
$this->drawSettingRow($setting);
|
||||
break;
|
||||
}
|
||||
}
|
||||
?></table><?php
|
||||
else:
|
||||
|
||||
//draw settings - advanced - with sections
|
||||
foreach($arrSettings as $key=>$setting):
|
||||
|
||||
//operate sections:
|
||||
if(!empty($arrSections) && isset($setting["section"])){
|
||||
$sectionKey = $setting["section"];
|
||||
|
||||
if($sectionKey != $lastSectionKey): //new section
|
||||
$arrSaps = $arrSections[$sectionKey]["arrSaps"];
|
||||
|
||||
if(!empty($arrSaps)){
|
||||
//close sap
|
||||
if($lastSapKey != -1):
|
||||
?>
|
||||
</table>
|
||||
</div>
|
||||
<?php
|
||||
endif;
|
||||
$lastSapKey = -1;
|
||||
}
|
||||
|
||||
$style = ($visibleSectionKey == $sectionKey)?"":"style='display:none'";
|
||||
|
||||
//close section
|
||||
if($sectionKey != 0):
|
||||
if(empty($arrSaps))
|
||||
echo "</table>";
|
||||
echo "</div>\n";
|
||||
endif;
|
||||
|
||||
//if no saps - add table
|
||||
if(empty($arrSaps)):
|
||||
?><table class="form-table"><?php
|
||||
endif;
|
||||
endif;
|
||||
$lastSectionKey = $sectionKey;
|
||||
}//end section manage
|
||||
|
||||
//operate saps
|
||||
if(!empty($arrSaps) && isset($setting["sap"])){
|
||||
$sapKey = $setting["sap"];
|
||||
if($sapKey != $lastSapKey){
|
||||
$sap = $this->settings->getSap($sapKey,$sectionKey);
|
||||
|
||||
//draw sap end
|
||||
if($sapKey != 0): ?>
|
||||
</table>
|
||||
<?php endif;
|
||||
|
||||
//set opened/closed states:
|
||||
//$style = "style='display:none;'";
|
||||
$style = "";
|
||||
|
||||
$class = "divSapControl";
|
||||
|
||||
if($sapKey == 0 || isset($sap["opened"]) && $sap["opened"] == true){
|
||||
$style = "";
|
||||
$class = "divSapControl opened";
|
||||
}
|
||||
|
||||
?>
|
||||
<div id="divSapControl_<?php echo $sectionKey."_".$sapKey?>" class="<?php echo $class?>">
|
||||
|
||||
<h3><?php echo $sap["text"]?></h3>
|
||||
</div>
|
||||
<div id="divSap_<?php echo $sectionKey."_".$sapKey?>" class="divSap" <?php echo $style ?>>
|
||||
<table class="form-table">
|
||||
<?php
|
||||
$lastSapKey = $sapKey;
|
||||
}
|
||||
}//saps manage
|
||||
|
||||
//draw row:
|
||||
switch($setting["type"]){
|
||||
case UniteSettingsRev::TYPE_HR:
|
||||
$this->drawHrRow($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_STATIC_TEXT:
|
||||
$this->drawTextRow($setting);
|
||||
break;
|
||||
default:
|
||||
$this->drawSettingRow($setting);
|
||||
break;
|
||||
}
|
||||
endforeach;
|
||||
endif;
|
||||
?>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
if(!empty($arrSections)):
|
||||
if(empty($arrSaps)) //close table settings if no saps
|
||||
echo "</table>";
|
||||
echo "</div>\n"; //close last section div
|
||||
endif;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// draw sections menu
|
||||
public function drawSections($activeSection=0){
|
||||
if(!empty($this->arrSections)):
|
||||
echo "<ul class='listSections' >";
|
||||
for($i=0;$i<count($this->arrSections);$i++):
|
||||
$class = "";
|
||||
if($activeSection == $i) $class="class='selected'";
|
||||
$text = $this->arrSections[$i]["text"];
|
||||
echo '<li '.$class.'><a onfocus="this.blur()" href="#'.($i+1).'"><div>'.$text.'</div></a></li>';
|
||||
endfor;
|
||||
echo "</ul>";
|
||||
endif;
|
||||
|
||||
//call custom draw function:
|
||||
if($this->customFunction_afterSections) call_user_func($this->customFunction_afterSections);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* draw settings function
|
||||
* @param $drawForm draw the form yes / no
|
||||
*/
|
||||
public function draw($formID=null,$drawForm = false){
|
||||
if(empty($formID))
|
||||
UniteFunctionsRev::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
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
@ -0,0 +1,711 @@
|
||||
<?php
|
||||
class UniteSettingsProductSidebarRev extends UniteSettingsOutputRev{
|
||||
|
||||
private $addClass = ""; //add class to the main div
|
||||
private $arrButtons = array();
|
||||
private $isAccordion = true;
|
||||
|
||||
/**
|
||||
*
|
||||
* add buggon
|
||||
*/
|
||||
public function addButton($title,$id,$class = "button-secondary"){
|
||||
|
||||
$button = array(
|
||||
"title"=>$title,
|
||||
"id"=>$id,
|
||||
"class"=>$class
|
||||
);
|
||||
|
||||
$this->arrButtons[] = $button;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* set add class for the main div
|
||||
*/
|
||||
public function setAddClass($addClass){
|
||||
$this->addClass = $addClass;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//draw text as input
|
||||
protected function drawTextInput($setting) {
|
||||
$disabled = "";
|
||||
$style="";
|
||||
if(isset($setting["style"]))
|
||||
$style = "style='".$setting["style"]."'";
|
||||
if(isset($setting["disabled"]))
|
||||
$disabled = 'disabled="disabled"';
|
||||
|
||||
$class = UniteFunctionsRev::getVal($setting, "class","text-sidebar");
|
||||
|
||||
//modify class:
|
||||
switch($class){
|
||||
case "normal":
|
||||
case "regular":
|
||||
$class = "text-sidebar-normal";
|
||||
break;
|
||||
}
|
||||
|
||||
if(!empty($class))
|
||||
$class = "class='$class'";
|
||||
|
||||
$attribs = UniteFunctionsRev::getVal($setting, "attribs");
|
||||
|
||||
?>
|
||||
<input type="text" <?php echo $attribs?> <?php echo $class?> <?php echo $style?> <?php echo $disabled?> id="<?php echo $setting["id"]?>" name="<?php echo $setting["name"]?>" value="<?php echo $setting["value"]?>" />
|
||||
<?php
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//draw a color picker
|
||||
protected function drawColorPickerInput($setting){
|
||||
$bgcolor = $setting["value"];
|
||||
$bgcolor = str_replace("0x","#",$bgcolor);
|
||||
// set the forent color (by black and white value)
|
||||
$rgb = UniteFunctionsRev::html2rgb($bgcolor);
|
||||
$bw = UniteFunctionsRev::yiq($rgb[0],$rgb[1],$rgb[2]);
|
||||
$color = "#000000";
|
||||
if($bw<128) $color = "#ffffff";
|
||||
|
||||
|
||||
$disabled = "";
|
||||
if(isset($setting["disabled"])){
|
||||
$color = "";
|
||||
$disabled = 'disabled="disabled"';
|
||||
}
|
||||
|
||||
$style="style='background-color:$bgcolor;color:$color'";
|
||||
|
||||
?>
|
||||
<input type="text" class="inputColorPicker" id="<?php echo $setting["id"]?>" <?php echo $style?> name="<?php echo $setting["name"]?>" value="<?php echo $bgcolor?>" <?php echo $disabled?>></input>
|
||||
<?php
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// draw setting input by type
|
||||
protected function drawInputs($setting){
|
||||
switch($setting["type"]){
|
||||
case UniteSettingsRev::TYPE_TEXT:
|
||||
$this->drawTextInput($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_COLOR:
|
||||
$this->drawColorPickerInput($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_SELECT:
|
||||
$this->drawSelectInput($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_CHECKBOX:
|
||||
$this->drawCheckboxInput($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_RADIO:
|
||||
$this->drawRadioInput($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_TEXTAREA:
|
||||
$this->drawTextAreaInput($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_CUSTOM:
|
||||
$this->drawCustom($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_BUTTON:
|
||||
$this->drawButtonSetting($setting);
|
||||
break;
|
||||
default:
|
||||
throw new Exception("wrong setting type - ".$setting["type"]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//draw advanced order box
|
||||
protected function drawOrderbox_advanced($setting){
|
||||
|
||||
$items = $setting["items"];
|
||||
if(!is_array($items))
|
||||
$this->throwError("Orderbox error - the items option must be array (items)");
|
||||
|
||||
//get arrItems modify items by saved value
|
||||
|
||||
if(!empty($setting["value"]) &&
|
||||
getType($setting["value"]) == "array" &&
|
||||
count($setting["value"]) == count($items)):
|
||||
|
||||
$savedItems = $setting["value"];
|
||||
|
||||
//make assoc array by id:
|
||||
$arrAssoc = array();
|
||||
foreach($items as $item)
|
||||
$arrAssoc[$item[0]] = $item[1];
|
||||
|
||||
foreach($savedItems as $item){
|
||||
$value = $item["id"];
|
||||
$text = $value;
|
||||
if(isset($arrAssoc[$value]))
|
||||
$text = $arrAssoc[$value];
|
||||
$arrItems[] = array($value,$text,$item["enabled"]);
|
||||
}
|
||||
else:
|
||||
$arrItems = $items;
|
||||
endif;
|
||||
|
||||
?>
|
||||
<ul class="orderbox_advanced" id="<?php echo $setting["id"]?>">
|
||||
<?php
|
||||
foreach($arrItems as $arrItem){
|
||||
switch(getType($arrItem)){
|
||||
case "string":
|
||||
$value = $arrItem;
|
||||
$text = $arrItem;
|
||||
$enabled = true;
|
||||
break;
|
||||
case "array":
|
||||
$value = $arrItem[0];
|
||||
$text = (count($arrItem)>1)?$arrItem[1]:$arrItem[0];
|
||||
$enabled = (count($arrItem)>2)?$arrItem[2]:true;
|
||||
break;
|
||||
default:
|
||||
$this->throwError("Error in setting:".$setting.". unknown item type.");
|
||||
break;
|
||||
}
|
||||
$checkboxClass = $enabled ? "div_checkbox_on" : "div_checkbox_off";
|
||||
|
||||
?>
|
||||
<li>
|
||||
<div class="div_value"><?php echo $value?></div>
|
||||
<div class="div_checkbox <?php echo $checkboxClass?>"></div>
|
||||
<div class="div_text"><?php echo $text?></div>
|
||||
<div class="div_handle"></div>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//draw order box
|
||||
protected function drawOrderbox($setting){
|
||||
|
||||
$items = $setting["items"];
|
||||
|
||||
//get arrItems by saved value
|
||||
$arrItems = array();
|
||||
|
||||
if(!empty($setting["value"]) &&
|
||||
getType($setting["value"]) == "array" &&
|
||||
count($setting["value"]) == count($items)){
|
||||
|
||||
$savedItems = $setting["value"];
|
||||
|
||||
foreach($savedItems as $value){
|
||||
$text = $value;
|
||||
if(isset($items[$value]))
|
||||
$text = $items[$value];
|
||||
$arrItems[] = array("value"=>$value,"text"=>$text);
|
||||
}
|
||||
} //get arrItems only from original items
|
||||
else{
|
||||
foreach($items as $value=>$text)
|
||||
$arrItems[] = array("value"=>$value,"text"=>$text);
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<ul class="orderbox" id="<?php echo $setting["id"]?>">
|
||||
<?php
|
||||
foreach($arrItems as $item){
|
||||
$itemKey = $item["value"];
|
||||
$itemText = $item["text"];
|
||||
|
||||
$value = (getType($itemKey) == "string")?$itemKey:$itemText;
|
||||
?>
|
||||
<li>
|
||||
<div class="div_value"><?php echo $value?></div>
|
||||
<div class="div_text"><?php echo $itemText?></div>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* draw button
|
||||
*/
|
||||
function drawButtonSetting($setting){
|
||||
//set class
|
||||
$class = UniteFunctionsRev::getVal($setting, "class");
|
||||
if(!empty($class))
|
||||
$class = "class='$class'";
|
||||
|
||||
?>
|
||||
<input type="button" id="<?php echo $setting["id"]?>" value="<?php echo $setting["value"]?>" <?php echo $class?>>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// draw text area input
|
||||
protected function drawTextAreaInput($setting){
|
||||
$disabled = "";
|
||||
if (isset($setting["disabled"])) $disabled = 'disabled="disabled"';
|
||||
|
||||
//set style
|
||||
$style = UniteFunctionsRev::getVal($setting, "style");
|
||||
if(!empty($style))
|
||||
$style = "style='".$style."'";
|
||||
|
||||
//set class
|
||||
$class = UniteFunctionsRev::getVal($setting, "class");
|
||||
if(!empty($class))
|
||||
$class = "class='$class'";
|
||||
|
||||
?>
|
||||
<textarea id="<?php echo $setting["id"]?>" <?php echo $class?> name="<?php echo $setting["name"]?>" <?php echo $style?> <?php echo $disabled?>><?php echo $setting["value"]?></textarea>
|
||||
<?php
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// draw radio input
|
||||
protected function drawRadioInput($setting){
|
||||
$items = $setting["items"];
|
||||
$counter = 0;
|
||||
$id = $setting["id"];
|
||||
$isDisabled = UniteFunctionsRev::getVal($setting, "disabled",false);
|
||||
|
||||
?>
|
||||
<span id="<?php echo $id?>" class="radio_wrapper">
|
||||
<?php
|
||||
foreach($items as $value=>$text):
|
||||
$counter++;
|
||||
$radioID = $id."_".$counter;
|
||||
$checked = "";
|
||||
if($value == $setting["value"]) $checked = " checked";
|
||||
|
||||
$disabled = "";
|
||||
if($isDisabled == true)
|
||||
$disabled = 'disabled="disabled"';
|
||||
|
||||
?>
|
||||
<input type="radio" id="<?php echo $radioID?>" value="<?php echo $value?>" name="<?php echo $setting["name"]?>" <?php echo $disabled?> <?php echo $checked?>/>
|
||||
<label for="<?php echo $radioID?>" style="cursor:pointer;"><?php _e($text)?></label>
|
||||
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</span>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// draw checkbox
|
||||
protected function drawCheckboxInput($setting){
|
||||
$checked = "";
|
||||
if($setting["value"] == true) $checked = 'checked="checked"';
|
||||
?>
|
||||
<input type="checkbox" id="<?php echo $setting["id"]?>" class="inputCheckbox" name="<?php echo $setting["name"]?>" <?php echo $checked?>/>
|
||||
<?php
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//draw select input
|
||||
protected function drawSelectInput($setting){
|
||||
|
||||
$className = "";
|
||||
if(isset($this->arrControls[$setting["name"]])) $className = "control";
|
||||
$class = "";
|
||||
if($className != "") $class = "class='".$className."'";
|
||||
|
||||
$disabled = "";
|
||||
if(isset($setting["disabled"]))
|
||||
$disabled = 'disabled="disabled"';
|
||||
|
||||
?>
|
||||
<select id="<?php echo $setting["id"]?>" name="<?php echo $setting["name"]?>" <?php echo $disabled?> <?php echo $class?>>
|
||||
<?php
|
||||
foreach($setting["items"] as $value=>$text):
|
||||
$text = __($text,REVSLIDER_TEXTDOMAIN);
|
||||
$selected = "";
|
||||
if($value == $setting["value"]) $selected = 'selected="selected"';
|
||||
?>
|
||||
<option value="<?php echo $value?>" <?php echo $selected?>><?php echo $text?></option>
|
||||
<?php
|
||||
endforeach
|
||||
?>
|
||||
</select>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* draw custom setting
|
||||
*/
|
||||
protected function drawCustom($setting){
|
||||
dmp($setting);
|
||||
exit();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//draw hr row
|
||||
protected function drawTextRow($setting){
|
||||
|
||||
//set cell style
|
||||
$cellStyle = "";
|
||||
if(isset($setting["padding"]))
|
||||
$cellStyle .= "padding-left:".$setting["padding"].";";
|
||||
|
||||
if(!empty($cellStyle))
|
||||
$cellStyle="style='$cellStyle'";
|
||||
|
||||
//set style
|
||||
$rowStyle = "";
|
||||
if(isset($setting["hidden"]) && $setting["hidden"] == true)
|
||||
$rowStyle .= "display:none;";
|
||||
|
||||
if(!empty($rowStyle))
|
||||
$rowStyle = "style='$rowStyle'";
|
||||
|
||||
?>
|
||||
<span class="spanSettingsStaticText"><?php echo __($setting["text"],REVSLIDER_TEXTDOMAIN)?></span>
|
||||
<?php
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//draw hr row
|
||||
protected function drawHrRow($setting){
|
||||
//set hidden
|
||||
$rowStyle = "";
|
||||
if(isset($setting["hidden"]) && $setting["hidden"] == true) $rowStyle = "style='display:none;'";
|
||||
|
||||
?>
|
||||
<li id="<?php echo $setting["id"]?>_row">
|
||||
<hr />
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
//draw settings row
|
||||
protected function drawSettingRow($setting){
|
||||
|
||||
//set cellstyle:
|
||||
$cellStyle = "";
|
||||
if(isset($setting[UniteSettingsRev::PARAM_CELLSTYLE])){
|
||||
$cellStyle .= $setting[UniteSettingsRev::PARAM_CELLSTYLE];
|
||||
}
|
||||
|
||||
//set text style:
|
||||
$textStyle = $cellStyle;
|
||||
if(isset($setting[UniteSettingsRev::PARAM_TEXTSTYLE])){
|
||||
$textStyle .= $setting[UniteSettingsRev::PARAM_TEXTSTYLE];
|
||||
}
|
||||
|
||||
if($textStyle != "") $textStyle = "style='".$textStyle."'";
|
||||
if($cellStyle != "") $cellStyle = "style='".$cellStyle."'";
|
||||
|
||||
//set hidden
|
||||
$rowStyle = "";
|
||||
if(isset($setting["hidden"]) && $setting["hidden"] == true) $rowStyle = "display:none;";
|
||||
if(!empty($rowStyle)) $rowStyle = "style='$rowStyle'";
|
||||
|
||||
//set row class:
|
||||
$rowClass = "";
|
||||
if(isset($setting["disabled"])) $rowClass = "class='disabled'";
|
||||
|
||||
//modify text:
|
||||
$text = UniteFunctionsRev::getVal($setting,"text","");
|
||||
$text = __($text,REVSLIDER_TEXTDOMAIN);
|
||||
|
||||
// prevent line break (convert spaces to nbsp)
|
||||
$text = str_replace(" "," ",$text);
|
||||
|
||||
if($setting["type"] == UniteSettingsRev::TYPE_CHECKBOX)
|
||||
$text = "<label for='{$setting["id"]}'>{$text}</label>";
|
||||
|
||||
//set settings text width:
|
||||
$textWidth = "";
|
||||
if(isset($setting["textWidth"])) $textWidth = 'width="'.$setting["textWidth"].'"';
|
||||
|
||||
$description = UniteFunctionsRev::getVal($setting, "description");
|
||||
$description = __($description,REVSLIDER_TEXTDOMAIN);
|
||||
|
||||
$unit = UniteFunctionsRev::getVal($setting, "unit");
|
||||
$unit = __($unit,REVSLIDER_TEXTDOMAIN);
|
||||
|
||||
$required = UniteFunctionsRev::getVal($setting, "required");
|
||||
|
||||
$addHtml = UniteFunctionsRev::getVal($setting, UniteSettingsRev::PARAM_ADDTEXT);
|
||||
$addHtmlBefore = UniteFunctionsRev::getVal($setting, UniteSettingsRev::PARAM_ADDTEXT_BEFORE_ELEMENT);
|
||||
|
||||
|
||||
//set if draw text or not.
|
||||
$toDrawText = true;
|
||||
if($setting["type"] == UniteSettingsRev::TYPE_BUTTON)
|
||||
$toDrawText = false;
|
||||
|
||||
$settingID = $setting["id"];
|
||||
|
||||
$attribsText = UniteFunctionsRev::getVal($setting, "attrib_text");
|
||||
|
||||
?>
|
||||
<li id="<?php echo $settingID?>_row" <?php echo $rowStyle." ".$rowClass?>>
|
||||
|
||||
<?php if($toDrawText == true):?>
|
||||
<span id="<?php echo $settingID?>_text" class='setting_text' title="<?php echo $description?>" <?php echo $attribsText?>><?php echo $text ?></span>
|
||||
<?php endif?>
|
||||
|
||||
<?php if(!empty($addHtmlBefore)):?>
|
||||
<span class="settings_addhtmlbefore"><?php echo $addHtmlBefore?></span>
|
||||
<?php endif?>
|
||||
|
||||
<span class='setting_input'>
|
||||
<?php $this->drawInputs($setting);?>
|
||||
</span>
|
||||
<?php if(!empty($unit)):?>
|
||||
<span class='setting_unit'><?php echo $unit?></span>
|
||||
<?php endif?>
|
||||
<?php if(!empty($required)):?>
|
||||
<span class='setting_required'>*</span>
|
||||
<?php endif?>
|
||||
<?php if(!empty($addHtml)):?>
|
||||
<span class="settings_addhtml"><?php echo $addHtml?></span>
|
||||
<?php endif?>
|
||||
<div class="clear"></div>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* insert settings into saps array
|
||||
*/
|
||||
private function groupSettingsIntoSaps(){
|
||||
$arrSections = $this->settings->getArrSections();
|
||||
$arrSaps = $arrSections[0]["arrSaps"];
|
||||
$arrSettings = $this->settings->getArrSettings();
|
||||
|
||||
//group settings by saps
|
||||
foreach($arrSettings as $key=>$setting){
|
||||
|
||||
$sapID = $setting["sap"];
|
||||
|
||||
if(isset($arrSaps[$sapID]["settings"]))
|
||||
$arrSaps[$sapID]["settings"][] = $setting;
|
||||
else
|
||||
$arrSaps[$sapID]["settings"] = array($setting);
|
||||
}
|
||||
return($arrSaps);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* draw buttons that defined earlier
|
||||
*/
|
||||
private function drawButtons(){
|
||||
foreach($this->arrButtons as $key=>$button){
|
||||
if($key>0)
|
||||
echo "<span class='hor_sap'></span>";
|
||||
echo UniteFunctionsRev::getHtmlLink("#", $button["title"],$button["id"],$button["class"]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* draw some setting, can be setting array or name
|
||||
*/
|
||||
public function drawSetting($setting,$state = null){
|
||||
if(gettype($setting) == "string")
|
||||
$setting = $this->settings->getSettingByName($setting);
|
||||
|
||||
switch($state){
|
||||
case "hidden":
|
||||
$setting["hidden"] = true;
|
||||
break;
|
||||
}
|
||||
|
||||
switch($setting["type"]){
|
||||
case UniteSettingsRev::TYPE_HR:
|
||||
$this->drawHrRow($setting);
|
||||
break;
|
||||
case UniteSettingsRev::TYPE_STATIC_TEXT:
|
||||
$this->drawTextRow($setting);
|
||||
break;
|
||||
default:
|
||||
$this->drawSettingRow($setting);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* draw setting by bulk names
|
||||
*/
|
||||
public function drawSettingsByNames($arrSettingNames,$state=null){
|
||||
if(gettype($arrSettingNames) == "string")
|
||||
$arrSettingNames = explode(",",$arrSettingNames);
|
||||
|
||||
foreach($arrSettingNames as $name)
|
||||
$this->drawSetting($name,$state);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* draw all settings
|
||||
*/
|
||||
public function drawSettings(){
|
||||
$this->prepareToDraw();
|
||||
$this->drawHeaderIncludes();
|
||||
|
||||
|
||||
$arrSaps = $this->groupSettingsIntoSaps();
|
||||
|
||||
$class = "postbox 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 = "class='no-accordion'";
|
||||
}else{
|
||||
$h3Class = "";
|
||||
if($key>0){
|
||||
$style = "style='display:none;'";
|
||||
$h3Class = "class='box_closed'";
|
||||
}
|
||||
}
|
||||
|
||||
$text = $sap["text"];
|
||||
$text = __($text,REVSLIDER_TEXTDOMAIN);
|
||||
|
||||
?>
|
||||
<div class="<?php echo $class?>">
|
||||
<h3 <?php echo $h3Class?>>
|
||||
|
||||
<?php if($this->isAccordion == true):?>
|
||||
<div class="postbox-arrow"></div>
|
||||
<?php endif?>
|
||||
|
||||
<span><?php echo $text ?></span>
|
||||
</h3>
|
||||
|
||||
<div class="inside" <?php echo $style?> >
|
||||
<ul class="list_settings">
|
||||
<?php
|
||||
|
||||
foreach($sap["settings"] as $setting){
|
||||
$this->drawSetting($setting);
|
||||
}
|
||||
|
||||
?>
|
||||
</ul>
|
||||
|
||||
<?php
|
||||
if(!empty($this->arrButtons)){
|
||||
?>
|
||||
<div class="clear"></div>
|
||||
<div class="settings_buttons">
|
||||
<?php
|
||||
$this->drawButtons();
|
||||
?>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
endforeach;
|
||||
|
||||
echo "</div>"; //wrapper close
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// draw sections menu
|
||||
public function drawSections($activeSection=0){
|
||||
if(!empty($this->arrSections)):
|
||||
echo "<ul class='listSections' >";
|
||||
for($i=0;$i<count($this->arrSections);$i++):
|
||||
$class = "";
|
||||
if($activeSection == $i) $class="class='selected'";
|
||||
$text = $this->arrSections[$i]["text"];
|
||||
echo '<li '.$class.'><a onfocus="this.blur()" href="#'.($i+1).'"><div>'.$text.'</div></a></li>';
|
||||
endfor;
|
||||
echo "</ul>";
|
||||
endif;
|
||||
|
||||
//call custom draw function:
|
||||
if($this->customFunction_afterSections) call_user_func($this->customFunction_afterSections);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* init accordion
|
||||
*/
|
||||
private function putAccordionInit(){
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function(){
|
||||
UniteSettingsRev.initAccordion("<?php echo $this->formID?>");
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* activate the accordion
|
||||
*/
|
||||
public function isAccordion($activate){
|
||||
$this->isAccordion = $activate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* draw settings function
|
||||
*/
|
||||
public function draw($formID=null){
|
||||
if(empty($formID))
|
||||
UniteFunctionsRev::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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
97
wp-content/plugins/revslider/inc_php/framework/zip.class.php
Normal file
97
wp-content/plugins/revslider/inc_php/framework/zip.class.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
class UniteZipRev{
|
||||
|
||||
private $zip;
|
||||
|
||||
/**
|
||||
*
|
||||
* get true / false if the zip archive exists.
|
||||
*/
|
||||
public static function isZipExists(){
|
||||
$exists = class_exists("ZipArchive");
|
||||
return $exists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* add zip file
|
||||
*/
|
||||
private function addItem($basePath,$path){
|
||||
|
||||
$rel_path = str_replace($basePath."/", "", $path);
|
||||
|
||||
if(is_dir($path)){ //directory
|
||||
|
||||
//add dir to zip
|
||||
if($basePath != $path)
|
||||
$this->zip->addEmptyDir($rel_path);
|
||||
|
||||
$files = scandir($path);
|
||||
foreach($files as $file){
|
||||
if($file == "." || $file == ".." || $file == ".svn")
|
||||
continue;
|
||||
$filepath = $path."/".$file;
|
||||
$this->addItem($basePath, $filepath);
|
||||
}
|
||||
}
|
||||
else{ //file
|
||||
if(!file_exists($path))
|
||||
throwError("filepath: '$path' don't exists, can't zip");
|
||||
|
||||
$this->zip->addFile($path,$rel_path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* make zip archive
|
||||
* if exists additional paths, add additional items to the zip
|
||||
*/
|
||||
public function makeZip($srcPath, $zipFilepath,$additionPaths = array()){
|
||||
|
||||
if(!is_dir($srcPath))
|
||||
throwError("The path: '$srcPath' don't exists, can't zip");
|
||||
|
||||
$this->zip = new ZipArchive;
|
||||
$success = $this->zip->open($zipFilepath, ZipArchive::CREATE);
|
||||
|
||||
if($success == false)
|
||||
throwError("Can't create zip file: $zipFilepath");
|
||||
|
||||
$this->addItem($srcPath,$srcPath);
|
||||
|
||||
if(gettype($additionPaths) != "array")
|
||||
throwError("Wrong additional paths variable.");
|
||||
|
||||
|
||||
//add additional paths
|
||||
if(!empty($additionPaths))
|
||||
foreach($additionPaths as $path){
|
||||
if(!is_dir($path))
|
||||
throwError("Path: $path not found, can't zip");
|
||||
$this->addItem($path, $path);
|
||||
}
|
||||
|
||||
$this->zip->close();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Extract zip archive
|
||||
*/
|
||||
public function extract($src, $dest){
|
||||
$zip = new ZipArchive;
|
||||
if ($zip->open($src)===true){
|
||||
$zip->extractTo($dest);
|
||||
$zip->close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
define("REVSLIDER_TEXTDOMAIN","revslider");
|
||||
|
||||
class GlobalsRevSlider{
|
||||
|
||||
const SHOW_DEBUG = false;
|
||||
const TABLE_SLIDERS_NAME = "revslider_sliders";
|
||||
const TABLE_SLIDES_NAME = "revslider_slides";
|
||||
const TABLE_SETTINGS_NAME = "revslider_settings";
|
||||
|
||||
const FIELDS_SLIDE = "slider_id,slide_order,params,layers";
|
||||
const FIELDS_SLIDER = "title,alias,params";
|
||||
|
||||
const YOUTUBE_EXAMPLE_ID = "cXwQjHRZieI";
|
||||
const DEFAULT_YOUTUBE_ARGUMENTS = "hd=1&wmode=opaque&controls=1&showinfo=0;rel=0;";
|
||||
const DEFAULT_VIMEO_ARGUMENTS = "title=0&byline=0&portrait=0;api=1";
|
||||
const LINK_HELP_SLIDERS = "http://themepunch.com/codecanyon/revolution_wp/documentation/";
|
||||
const LINK_HELP_SLIDER = "http://themepunch.com/codecanyon/revolution_wp/documentation/#!/main_settings";
|
||||
const LINK_HELP_SLIDE_LIST = "http://themepunch.com/codecanyon/revolution_wp/documentation/#!/slides_editor";
|
||||
const LINK_HELP_SLIDE = "http://themepunch.com/codecanyon/revolution_wp/documentation/#!/slide_general_settings";
|
||||
|
||||
public static $table_sliders;
|
||||
public static $table_slides;
|
||||
public static $table_settings;
|
||||
public static $filepath_captions;
|
||||
public static $filepath_captions_original;
|
||||
public static $urlCaptionsCSS;
|
||||
public static $isNewVersion;
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,342 @@
|
||||
<?php
|
||||
|
||||
class RevOperations extends UniteElementsBaseRev{
|
||||
|
||||
/**
|
||||
*
|
||||
* get button classes
|
||||
*/
|
||||
public function getButtonClasses(){
|
||||
|
||||
$arrButtons = array(
|
||||
"red"=>"Red Button",
|
||||
"green"=>"Green Button",
|
||||
"blue"=>"Blue Button",
|
||||
"orange"=>"Orange Button",
|
||||
"darkgrey"=>"Darkgrey Button",
|
||||
"lightgrey"=>"Lightgrey Button",
|
||||
);
|
||||
|
||||
return($arrButtons);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get easing functions array
|
||||
*/
|
||||
public function getArrEasing($toAssoc = true){
|
||||
|
||||
$arrEasing = array(
|
||||
"easeOutBack",
|
||||
"easeInQuad",
|
||||
"easeOutQuad",
|
||||
"easeInOutQuad",
|
||||
"easeInCubic",
|
||||
"easeOutCubic",
|
||||
"easeInOutCubic",
|
||||
"easeInQuart",
|
||||
"easeOutQuart",
|
||||
"easeInOutQuart",
|
||||
"easeInQuint",
|
||||
"easeOutQuint",
|
||||
"easeInOutQuint",
|
||||
"easeInSine",
|
||||
"easeOutSine",
|
||||
"easeInOutSine",
|
||||
"easeInExpo",
|
||||
"easeOutExpo",
|
||||
"easeInOutExpo",
|
||||
"easeInCirc",
|
||||
"easeOutCirc",
|
||||
"easeInOutCirc",
|
||||
"easeInElastic",
|
||||
"easeOutElastic",
|
||||
"easeInOutElastic",
|
||||
"easeInBack",
|
||||
"easeOutBack",
|
||||
"easeInOutBack",
|
||||
"easeInBounce",
|
||||
"easeOutBounce",
|
||||
"easeInOutBounce"
|
||||
);
|
||||
|
||||
if($toAssoc)
|
||||
$arrEasing = UniteFunctionsRev::arrayToAssoc($arrEasing);
|
||||
|
||||
return($arrEasing);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get arr end easing
|
||||
*/
|
||||
public function getArrEndEasing(){
|
||||
$arrEasing = $this->getArrEasing(false);
|
||||
$arrEasing = array_merge(array("nothing"),$arrEasing);
|
||||
$arrEasing = UniteFunctionsRev::arrayToAssoc($arrEasing);
|
||||
$arrEasing["nothing"] = "No Change";
|
||||
|
||||
return($arrEasing);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get transition array
|
||||
*/
|
||||
public function getArrTransition(){
|
||||
|
||||
$arrTransition = array(
|
||||
"random"=>"Random",
|
||||
"fade"=>"Fade",
|
||||
"slidehorizontal"=>"Slide Horizontal",
|
||||
"slidevertical"=>"Slide Vertical",
|
||||
"boxslide"=>"Box Slide",
|
||||
"boxfade"=>"Box Fade",
|
||||
"slotzoom-horizontal"=>"SlotZoom Horizontal",
|
||||
"slotslide-horizontal"=>"SlotSlide Horizontal",
|
||||
"slotfade-horizontal"=>"SlotFade Horizontal",
|
||||
"slotzoom-vertical"=>"SlotZoom Vertical",
|
||||
"slotslide-vertical"=>"SlotSlide Vertical",
|
||||
"slotfade-vertical"=>"SlotFade Vertical",
|
||||
"curtain-1"=>"Curtain 1",
|
||||
"curtain-2"=>"Curtain 2",
|
||||
"curtain-3"=>"Curtain 3",
|
||||
"slideleft"=>"Slide Left",
|
||||
"slideright"=>"Slide Right",
|
||||
"slideup"=>"Slide Up",
|
||||
"slidedown"=>"Slide Down",
|
||||
"papercut"=>"Premium - Paper Cut",
|
||||
"3dcurtain-horizontal"=>"Premium - 3D Curtain Horizontal",
|
||||
"3dcurtain-vertical"=>"Premium - 3D Curtain Vertical",
|
||||
"flyin"=>"Premium - Fly In",
|
||||
"turnoff"=>"Premium - Turn Off",
|
||||
"cubic"=>"Premium - Cubic"
|
||||
);
|
||||
|
||||
return($arrTransition);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get random transition
|
||||
*/
|
||||
public static function getRandomTransition(){
|
||||
$arrTrans = self::getArrTransition();
|
||||
unset($arrTrans["random"]);
|
||||
$trans = array_rand($arrTrans);
|
||||
|
||||
return($trans);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get animations array
|
||||
*/
|
||||
public function getArrAnimations(){
|
||||
|
||||
$arrAnimations = array(
|
||||
"fade"=>"Fade",
|
||||
"sft"=>"Short from Top",
|
||||
"sfb"=>"Short from Bottom",
|
||||
"sfr"=>"Short from Right",
|
||||
"sfl"=>"Short from Left",
|
||||
"lft"=>"Long from Top",
|
||||
"lfb"=>"Long from Bottom",
|
||||
"lfr"=>"Long from Right",
|
||||
"lfl"=>"Long from Left",
|
||||
"randomrotate"=>"Random Rotate"
|
||||
);
|
||||
|
||||
return($arrAnimations);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get "end" animations array
|
||||
*/
|
||||
public function getArrEndAnimations(){
|
||||
$arrAnimations = array(
|
||||
"auto"=>"Choose Automatic",
|
||||
"fadeout"=>"Fade Out",
|
||||
"stt"=>"Short to Top",
|
||||
"stb"=>"Short to Bottom",
|
||||
"stl"=>"Short to Left",
|
||||
"str"=>"Short to Right",
|
||||
"ltt"=>"Long to Top",
|
||||
"ltb"=>"Long to Bottom",
|
||||
"ltl"=>"Long to Left",
|
||||
"ltr"=>"Long to Right",
|
||||
"randomrotateout"=>"Random Rotate Out"
|
||||
);
|
||||
|
||||
return($arrAnimations);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* parse css file and get the classes from there.
|
||||
*/
|
||||
public function getArrCaptionClasses($contentCSS){
|
||||
//parse css captions file
|
||||
$parser = new UniteCssParserRev();
|
||||
$parser->initContent($contentCSS);
|
||||
$arrCaptionClasses = $parser->getArrClasses();
|
||||
return($arrCaptionClasses);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get the select classes html for putting in the html by ajax
|
||||
*/
|
||||
private function getHtmlSelectCaptionClasses($contentCSS){
|
||||
$arrCaptions = $this->getArrCaptionClasses($contentCSS);
|
||||
$htmlSelect = UniteFunctionsRev::getHTMLSelect($arrCaptions,"","id='layer_caption' name='layer_caption'",true);
|
||||
return($htmlSelect);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get contents of the css file
|
||||
*/
|
||||
public function getCaptionsContent(){
|
||||
$contentCSS = file_get_contents(GlobalsRevSlider::$filepath_captions);
|
||||
return($contentCSS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* update captions css file content
|
||||
* @return new captions html select
|
||||
*/
|
||||
public function updateCaptionsContentData($content){
|
||||
$content = stripslashes($content);
|
||||
$content = trim($content);
|
||||
UniteFunctionsRev::writeFile($content, GlobalsRevSlider::$filepath_captions);
|
||||
|
||||
//output captions array
|
||||
$arrCaptions = $this->getArrCaptionClasses($content);
|
||||
return($arrCaptions);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* copy from original css file to the captions css.
|
||||
*/
|
||||
public function restoreCaptionsCss(){
|
||||
|
||||
if(!file_exists(GlobalsRevSlider::$filepath_captions_original))
|
||||
UniteFunctionsRev::throwError("The original css file: captions_original.css doesn't exists.");
|
||||
|
||||
$success = @copy(GlobalsRevSlider::$filepath_captions_original, GlobalsRevSlider::$filepath_captions);
|
||||
if($success == false)
|
||||
UniteFunctionsRev::throwError("Failed to restore from the original captions file.");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* preview slider output
|
||||
* if output object is null - create object
|
||||
*/
|
||||
public function previewOutput($sliderID,$output = null){
|
||||
|
||||
if($sliderID == "empty_output"){
|
||||
$this->loadingMessageOutput();
|
||||
exit();
|
||||
}
|
||||
|
||||
if($output == null)
|
||||
$output = new RevSliderOutput();
|
||||
|
||||
$output->setPreviewMode();
|
||||
|
||||
//put the output html
|
||||
$urlPlugin = RevSliderAdmin::$url_plugin."rs-plugin/";
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<link rel='stylesheet' href='<?php echo $urlPlugin?>css/settings.css' type='text/css' media='all' />
|
||||
<link rel='stylesheet' href='<?php echo $urlPlugin?>css/captions.css' type='text/css' media='all' />
|
||||
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js'></script>
|
||||
<script type='text/javascript' src='<?php echo $urlPlugin?>js/jquery.themepunch.revolution.min.js'></script>
|
||||
</head>
|
||||
<body style="padding:0px;margin:0px;">
|
||||
<?php
|
||||
$output->putSliderBase($sliderID);
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* output loading message
|
||||
*/
|
||||
public function loadingMessageOutput(){
|
||||
?>
|
||||
<div class="message_loading_preview">Loading Preview...</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* put slide preview by data
|
||||
*/
|
||||
public function putSlidePreviewByData($data){
|
||||
|
||||
if($data == "empty_output"){
|
||||
$this->loadingMessageOutput();
|
||||
exit();
|
||||
}
|
||||
|
||||
$data = UniteFunctionsRev::jsonDecodeFromClientSide($data);
|
||||
|
||||
$slideID = $data["slideid"];
|
||||
$slide = new RevSlide();
|
||||
$slide->initByID($slideID);
|
||||
$sliderID = $slide->getSliderID();
|
||||
|
||||
$output = new RevSliderOutput();
|
||||
$output->setOneSlideMode($data);
|
||||
|
||||
$this->previewOutput($sliderID,$output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* update general settings
|
||||
*/
|
||||
public function updateGeneralSettings($data){
|
||||
|
||||
$strSettings = serialize($data);
|
||||
$params = new RevSliderParams();
|
||||
$params->updateFieldInDB("general", $strSettings);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get general settigns values.
|
||||
*/
|
||||
public function getGeneralSettingsValues(){
|
||||
|
||||
$params = new RevSliderParams();
|
||||
$strSettings = $params->getFieldFromDB("general");
|
||||
|
||||
$arrValues = array();
|
||||
if(!empty($strSettings))
|
||||
$arrValues = unserialize($strSettings);
|
||||
|
||||
return($arrValues);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
1239
wp-content/plugins/revslider/inc_php/revslider_output.class.php
Normal file
1239
wp-content/plugins/revslider/inc_php/revslider_output.class.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* get / update params in db
|
||||
*
|
||||
*/
|
||||
|
||||
class RevSliderParams extends UniteElementsBaseRev{
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* update settign in db
|
||||
*/
|
||||
public function updateFieldInDB($name,$value){
|
||||
|
||||
$arrUpdate = array();
|
||||
$arrUpdate[$name] = $value;
|
||||
|
||||
$arr = $this->db->fetch(GlobalsRevSlider::$table_settings);
|
||||
if(empty($arr)){ //insert to db
|
||||
$this->db->insert(GlobalsRevSlider::$table_settings,$arrUpdate);
|
||||
}else{ //update db
|
||||
$id = $arr[0]["id"];
|
||||
$this->db->update(GlobalsRevSlider::$table_settings,$arrUpdate,array("id"=>$id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get field from db
|
||||
*/
|
||||
public function getFieldFromDB($name){
|
||||
|
||||
$arr = $this->db->fetch(GlobalsRevSlider::$table_settings);
|
||||
|
||||
if(empty($arr))
|
||||
return("");
|
||||
|
||||
|
||||
$arr = $arr[0];
|
||||
|
||||
if(array_key_exists($name, $arr) == false)
|
||||
UniteFunctionsRev::throwError("The settings db should cotnain field: $name");
|
||||
|
||||
$value = $arr[$name];
|
||||
return($value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,273 @@
|
||||
<?php
|
||||
|
||||
class RevSliderSettingsProduct extends UniteSettingsRevProductRev{
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* set custom values to settings
|
||||
*/
|
||||
public static function setSettingsCustomValues(UniteSettingsRev $settings,$arrValues){
|
||||
$arrSettings = $settings->getArrSettings();
|
||||
|
||||
foreach($arrSettings as $key=>$setting){
|
||||
$type = UniteFunctionsRev::getVal($setting, "type");
|
||||
if($type != UniteSettingsRev::TYPE_CUSTOM)
|
||||
continue;
|
||||
$customType = UniteFunctionsRev::getVal($setting, "custom_type");
|
||||
|
||||
switch($customType){
|
||||
case "slider_size":
|
||||
$setting["width"] = UniteFunctionsRev::getVal($arrValues, "width",UniteFunctionsRev::getVal($setting,"width"));
|
||||
$setting["height"] = UniteFunctionsRev::getVal($arrValues, "height",UniteFunctionsRev::getVal($setting,"height"));
|
||||
$arrSettings[$key] = $setting;
|
||||
break;
|
||||
case "responsitive_settings":
|
||||
$id = $setting["id"];
|
||||
$setting["w1"] = UniteFunctionsRev::getVal($arrValues, $id."_w1",UniteFunctionsRev::getVal($setting,"w1"));
|
||||
$setting["w2"] = UniteFunctionsRev::getVal($arrValues, $id."_w2",UniteFunctionsRev::getVal($setting,"w2"));
|
||||
$setting["w3"] = UniteFunctionsRev::getVal($arrValues, $id."_w3",UniteFunctionsRev::getVal($setting,"w3"));
|
||||
$setting["w4"] = UniteFunctionsRev::getVal($arrValues, $id."_w4",UniteFunctionsRev::getVal($setting,"w4"));
|
||||
$setting["w5"] = UniteFunctionsRev::getVal($arrValues, $id."_w5",UniteFunctionsRev::getVal($setting,"w5"));
|
||||
$setting["w6"] = UniteFunctionsRev::getVal($arrValues, $id."_w6",UniteFunctionsRev::getVal($setting,"w6"));
|
||||
|
||||
$setting["sw1"] = UniteFunctionsRev::getVal($arrValues, $id."_sw1",UniteFunctionsRev::getVal($setting,"sw1"));
|
||||
$setting["sw2"] = UniteFunctionsRev::getVal($arrValues, $id."_sw2",UniteFunctionsRev::getVal($setting,"sw2"));
|
||||
$setting["sw3"] = UniteFunctionsRev::getVal($arrValues, $id."_sw3",UniteFunctionsRev::getVal($setting,"sw3"));
|
||||
$setting["sw4"] = UniteFunctionsRev::getVal($arrValues, $id."_sw4",UniteFunctionsRev::getVal($setting,"sw4"));
|
||||
$setting["sw5"] = UniteFunctionsRev::getVal($arrValues, $id."_sw5",UniteFunctionsRev::getVal($setting,"sw5"));
|
||||
$setting["sw6"] = UniteFunctionsRev::getVal($arrValues, $id."_sw6",UniteFunctionsRev::getVal($setting,"sw6"));
|
||||
$arrSettings[$key] = $setting;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$settings->setArrSettings($arrSettings);
|
||||
|
||||
//disable settings by slider type:
|
||||
$sliderType = $settings->getSettingValue("slider_type");
|
||||
|
||||
switch($sliderType){
|
||||
case "fixed":
|
||||
case "fullwidth":
|
||||
case "fullscreen":
|
||||
//hide responsive
|
||||
$settingRes = $settings->getSettingByName("responsitive");
|
||||
$settingRes["disabled"] = true;
|
||||
$settings->updateArrSettingByName("responsitive", $settingRes);
|
||||
break;
|
||||
}
|
||||
|
||||
//change height to max height
|
||||
$settingSize = $settings->getSettingByName("slider_size");
|
||||
$settingSize["slider_type"] = $sliderType;
|
||||
$settings->updateArrSettingByName("slider_size", $settingSize);
|
||||
|
||||
return($settings);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* draw responsitive settings value
|
||||
*/
|
||||
protected function drawResponsitiveSettings($setting){
|
||||
$id = $setting["id"];
|
||||
|
||||
$w1 = UniteFunctionsRev::getVal($setting, "w1");
|
||||
$w2 = UniteFunctionsRev::getVal($setting, "w2");
|
||||
$w3 = UniteFunctionsRev::getVal($setting, "w3");
|
||||
$w4 = UniteFunctionsRev::getVal($setting, "w4");
|
||||
$w5 = UniteFunctionsRev::getVal($setting, "w5");
|
||||
$w6 = UniteFunctionsRev::getVal($setting, "w6");
|
||||
|
||||
$sw1 = UniteFunctionsRev::getVal($setting, "sw1");
|
||||
$sw2 = UniteFunctionsRev::getVal($setting, "sw2");
|
||||
$sw3 = UniteFunctionsRev::getVal($setting, "sw3");
|
||||
$sw4 = UniteFunctionsRev::getVal($setting, "sw4");
|
||||
$sw5 = UniteFunctionsRev::getVal($setting, "sw5");
|
||||
$sw6 = UniteFunctionsRev::getVal($setting, "sw6");
|
||||
|
||||
$disabled = (UniteFunctionsRev::getVal($setting, "disabled") == true);
|
||||
|
||||
$strDisabled = "";
|
||||
if($disabled == true)
|
||||
$strDisabled = "disabled='disabled'";
|
||||
|
||||
?>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<?php _e("Screen Width",REVSLIDER_TEXTDOMAIN)?>1:
|
||||
</td>
|
||||
<td>
|
||||
<input id="<?php echo $id?>_w1" name="<?php echo $id?>_w1" type="text" class="textbox-small" <?php echo $strDisabled?> value="<?php echo $w1?>">
|
||||
</td>
|
||||
<td>
|
||||
<?php _e("Slider Width",REVSLIDER_TEXTDOMAIN)?>1:
|
||||
</td>
|
||||
<td>
|
||||
<input id="<?php echo $id?>_sw1" name="<?php echo $id?>_sw1" type="text" class="textbox-small" <?php echo $strDisabled?> value="<?php echo $sw1?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<?php _e("Screen Width",REVSLIDER_TEXTDOMAIN)?>2:
|
||||
</td>
|
||||
<td>
|
||||
<input id="<?php echo $id?>_w2" name="<?php echo $id?>_w2" type="text" class="textbox-small" <?php echo $strDisabled?> value="<?php echo $w2?>">
|
||||
</td>
|
||||
<td>
|
||||
<?php _e("Slider Width",REVSLIDER_TEXTDOMAIN)?>2:
|
||||
</td>
|
||||
<td>
|
||||
<input id="<?php echo $id?>_sw2" name="<?php echo $id?>_sw2" type="text" class="textbox-small" <?php echo $strDisabled?> value="<?php echo $sw2?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<?php _e("Screen Width",REVSLIDER_TEXTDOMAIN)?>3:
|
||||
</td>
|
||||
<td>
|
||||
<input id="<?php echo $id?>_w3" name="<?php echo $id?>_w3" type="text" class="textbox-small" <?php echo $strDisabled?> value="<?php echo $w3?>">
|
||||
</td>
|
||||
<td>
|
||||
<?php _e("Slider Width",REVSLIDER_TEXTDOMAIN)?>3:
|
||||
</td>
|
||||
<td>
|
||||
<input id="<?php echo $id?>_sw3" name="<?php echo $id?>_sw3" type="text" class="textbox-small" <?php echo $strDisabled?> value="<?php echo $sw3?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<?php _e("Screen Width",REVSLIDER_TEXTDOMAIN)?>4:
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="<?php echo $id?>_w4" name="<?php echo $id?>_w4" class="textbox-small" <?php echo $strDisabled?> value="<?php echo $w4?>">
|
||||
</td>
|
||||
<td>
|
||||
<?php _e("Slider Width",REVSLIDER_TEXTDOMAIN)?>4:
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="<?php echo $id?>_sw4" name="<?php echo $id?>_sw4" class="textbox-small" <?php echo $strDisabled?> value="<?php echo $sw4?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<?php _e("Screen Width",REVSLIDER_TEXTDOMAIN)?>5:
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="<?php echo $id?>_w5" name="<?php echo $id?>_w5" class="textbox-small" <?php echo $strDisabled?> value="<?php echo $w5?>">
|
||||
</td>
|
||||
<td>
|
||||
<?php _e("Slider Width",REVSLIDER_TEXTDOMAIN)?>5:
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="<?php echo $id?>_sw5" name="<?php echo $id?>_sw5" class="textbox-small" <?php echo $strDisabled?> value="<?php echo $sw5?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<?php _e("Screen Width",REVSLIDER_TEXTDOMAIN)?>6:
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="<?php echo $id?>_w6" name="<?php echo $id?>_w6" class="textbox-small" <?php echo $strDisabled?> value="<?php echo $w6?>">
|
||||
</td>
|
||||
<td>
|
||||
<?php _e("Slider Width",REVSLIDER_TEXTDOMAIN)?>6:
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="<?php echo $id?>_sw6" name="<?php echo $id?>_sw6" class="textbox-small" <?php echo $strDisabled?> value="<?php echo $sw6?>">
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* draw slider size
|
||||
*/
|
||||
protected function drawSliderSize($setting){
|
||||
|
||||
$width = UniteFunctionsRev::getVal($setting, "width");
|
||||
$height = UniteFunctionsRev::getVal($setting, "height");
|
||||
|
||||
$sliderType = UniteFunctionsRev::getVal($setting, "slider_type");
|
||||
|
||||
$textNormalW = __("Grid Width:",REVSLIDER_TEXTDOMAIN);
|
||||
$textNormalH = __("Grid Height:",REVSLIDER_TEXTDOMAIN);
|
||||
|
||||
$textFullWidthW = __("Grid Width:",REVSLIDER_TEXTDOMAIN);
|
||||
$textFullWidthH = __("Grid Height:",REVSLIDER_TEXTDOMAIN);
|
||||
|
||||
$textFullScreenW = __("Grid Width:",REVSLIDER_TEXTDOMAIN);
|
||||
$textFullScreenH = __("Grid Height:",REVSLIDER_TEXTDOMAIN);
|
||||
|
||||
//set default text (fixed, responsive)
|
||||
switch($sliderType){
|
||||
default:
|
||||
$textDefaultW = $textNormalW;
|
||||
$textDefaultH = $textNormalH;
|
||||
break;
|
||||
case "fullwidth":
|
||||
$textDefaultW = $textFullWidthW;
|
||||
$textDefaultH = $textFullWidthH;
|
||||
break;
|
||||
case "fullscreen":
|
||||
$textDefaultW = $textFullScreenW;
|
||||
$textDefaultH = $textFullScreenH;
|
||||
break;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td id="cellWidth" data-textnormal="<?php echo $textNormalW?>" data-textfull="<?php echo $textFullWidthW?>" data-textscreen="<?php echo $textFullScreenW?>">
|
||||
<?php echo $textDefaultW ?>
|
||||
</td>
|
||||
<td id="cellWidthInput">
|
||||
<input id="width" name="width" type="text" class="textbox-small" value="<?php echo $width?>">
|
||||
</td>
|
||||
<td id="cellHeight" data-textnormal="<?php echo $textNormalH?>" data-textfull="<?php echo $textFullWidthH?>" data-textscreen="<?php echo $textFullScreenH?>">
|
||||
<?php echo $textDefaultH ?>
|
||||
</td>
|
||||
<td>
|
||||
<input id="height" name="height" type="text" class="textbox-small" value="<?php echo $height?>">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* draw custom inputs for rev slider
|
||||
* @param $setting
|
||||
*/
|
||||
protected function drawCustomInputs($setting){
|
||||
|
||||
$customType = UniteFunctionsRev::getVal($setting, "custom_type");
|
||||
switch($customType){
|
||||
case "slider_size":
|
||||
$this->drawSliderSize($setting);
|
||||
break;
|
||||
case "responsitive_settings":
|
||||
$this->drawResponsitiveSettings($setting);
|
||||
break;
|
||||
default:
|
||||
UniteFunctionsRev::throwError("No handler function for type: $customType");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
503
wp-content/plugins/revslider/inc_php/revslider_slide.class.php
Normal file
503
wp-content/plugins/revslider/inc_php/revslider_slide.class.php
Normal file
@ -0,0 +1,503 @@
|
||||
<?php
|
||||
|
||||
class RevSlide extends UniteElementsBaseRev{
|
||||
|
||||
private $id;
|
||||
private $sliderID;
|
||||
private $slideOrder;
|
||||
|
||||
private $imageUrl;
|
||||
private $imageID;
|
||||
private $imageThumb;
|
||||
private $imageFilepath;
|
||||
private $imageFilename;
|
||||
|
||||
private $params;
|
||||
private $arrLayers;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* init slide by db record
|
||||
*/
|
||||
public function initByData($record){
|
||||
|
||||
$this->id = $record["id"];
|
||||
$this->sliderID = $record["slider_id"];
|
||||
$this->slideOrder = $record["slide_order"];
|
||||
|
||||
$params = $record["params"];
|
||||
$params = (array)json_decode($params);
|
||||
|
||||
$layers = $record["layers"];
|
||||
$layers = (array)json_decode($layers);
|
||||
$layers = UniteFunctionsRev::convertStdClassToArray($layers);
|
||||
|
||||
$imageID = UniteFunctionsRev::getVal($params, "image_id");
|
||||
|
||||
//get image url and thumb url
|
||||
if(!empty($imageID)){
|
||||
$this->imageID = $imageID;
|
||||
|
||||
$imageUrl = UniteFunctionsWPRev::getUrlAttachmentImage($imageID);
|
||||
if(empty($imageUrl))
|
||||
$imageUrl = UniteFunctionsRev::getVal($params, "image");
|
||||
|
||||
$this->imageThumb = UniteFunctionsWPRev::getUrlAttachmentImage($imageID,UniteFunctionsWPRev::THUMB_MEDIUM);
|
||||
|
||||
}else{
|
||||
$imageUrl = UniteFunctionsRev::getVal($params, "image");
|
||||
}
|
||||
|
||||
//set image path, file and url
|
||||
$this->imageUrl = $imageUrl;
|
||||
|
||||
$this->imageFilepath = UniteFunctionsWPRev::getImagePathFromURL($this->imageUrl);
|
||||
$realPath = UniteFunctionsWPRev::getPathContent().$this->imageFilepath;
|
||||
|
||||
if(file_exists($realPath) == false || is_file($realPath) == false)
|
||||
$this->imageFilepath = "";
|
||||
|
||||
$this->imageFilename = basename($this->imageUrl);
|
||||
|
||||
$this->params = $params;
|
||||
$this->arrLayers = $layers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* init the slider by id
|
||||
*/
|
||||
public function initByID($slideid){
|
||||
UniteFunctionsRev::validateNumeric($slideid,"Slide ID");
|
||||
$slideid = $this->db->escape($slideid);
|
||||
$record = $this->db->fetchSingle(GlobalsRevSlider::$table_slides,"id=$slideid");
|
||||
|
||||
$this->initByData($record);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get slide ID
|
||||
*/
|
||||
public function getID(){
|
||||
return($this->id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get slide order
|
||||
*/
|
||||
public function getOrder(){
|
||||
$this->validateInited();
|
||||
return($this->slideOrder);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get layers in json format
|
||||
*/
|
||||
public function getLayers(){
|
||||
$this->validateInited();
|
||||
return($this->arrLayers);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* modify layer links for export
|
||||
*/
|
||||
public function getLayersForExport(){
|
||||
$this->validateInited();
|
||||
$arrLayersNew = array();
|
||||
foreach($this->arrLayers as $key=>$layer){
|
||||
$imageUrl = UniteFunctionsRev::getVal($layer, "image_url");
|
||||
if(!empty($imageUrl))
|
||||
$layer["image_url"] = UniteFunctionsWPRev::getImagePathFromURL($layer["image_url"]);
|
||||
|
||||
$arrLayersNew[] = $layer;
|
||||
}
|
||||
|
||||
return($arrLayersNew);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get params for export
|
||||
*/
|
||||
public function getParamsForExport(){
|
||||
$arrParams = $this->getParams();
|
||||
$urlImage = UniteFunctionsRev::getVal($arrParams, "image");
|
||||
if(!empty($urlImage))
|
||||
$arrParams["image"] = UniteFunctionsWPRev::getImagePathFromURL($urlImage);
|
||||
|
||||
return($arrParams);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* normalize layers text, and get layers
|
||||
*
|
||||
*/
|
||||
public function getLayersNormalizeText(){
|
||||
$arrLayersNew = array();
|
||||
foreach ($this->arrLayers as $key=>$layer){
|
||||
$text = $layer["text"];
|
||||
$text = addslashes($text);
|
||||
$layer["text"] = $text;
|
||||
$arrLayersNew[] = $layer;
|
||||
}
|
||||
|
||||
return($arrLayersNew);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get slide params
|
||||
*/
|
||||
public function getParams(){
|
||||
$this->validateInited();
|
||||
return($this->params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get parameter from params array. if no default, then the param is a must!
|
||||
*/
|
||||
function getParam($name,$default=null){
|
||||
|
||||
if($default === null){
|
||||
if(!array_key_exists($name, $this->params))
|
||||
UniteFunctionsRev::throwError("The param <b>$name</b> not found in slide params.");
|
||||
$default = "";
|
||||
}
|
||||
|
||||
return UniteFunctionsRev::getVal($this->params, $name,$default);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get image filename
|
||||
*/
|
||||
public function getImageFilename(){
|
||||
return($this->imageFilename);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get image filepath
|
||||
*/
|
||||
public function getImageFilepath(){
|
||||
return($this->imageFilepath);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get image url
|
||||
*/
|
||||
public function getImageUrl(){
|
||||
return($this->imageUrl);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get image id
|
||||
*/
|
||||
public function getImageID(){
|
||||
return($this->imageID);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get thumb url
|
||||
*/
|
||||
public function getThumbUrl(){
|
||||
$thumbUrl = $this->imageUrl;
|
||||
if(!empty($this->imageThumb))
|
||||
$thumbUrl = $this->imageThumb;
|
||||
|
||||
return($thumbUrl);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get the slider id
|
||||
*/
|
||||
public function getSliderID(){
|
||||
return($this->sliderID);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* validate that the slider exists
|
||||
*/
|
||||
private function validateSliderExists($sliderID){
|
||||
$slider = new RevSlider();
|
||||
$slider->initByID($sliderID);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* validate that the slide is inited and the id exists.
|
||||
*/
|
||||
private function validateInited(){
|
||||
if(empty($this->id))
|
||||
UniteFunctionsRev::throwError("The slide is not inited!!!");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* create the slide (from image)
|
||||
*/
|
||||
public function createSlide($sliderID,$obj=""){
|
||||
|
||||
$imageID = null;
|
||||
|
||||
if(is_array($obj)){
|
||||
$urlImage = UniteFunctionsRev::getVal($obj, "url");
|
||||
$imageID = UniteFunctionsRev::getVal($obj, "id");
|
||||
}else{
|
||||
$urlImage = $obj;
|
||||
}
|
||||
|
||||
//get max order
|
||||
$slider = new RevSlider();
|
||||
$slider->initByID($sliderID);
|
||||
$maxOrder = $slider->getMaxOrder();
|
||||
$order = $maxOrder+1;
|
||||
|
||||
$params = array();
|
||||
if(!empty($urlImage)){
|
||||
$params["background_type"] = "image";
|
||||
$params["image"] = $urlImage;
|
||||
if(!empty($imageID))
|
||||
$params["image_id"] = $imageID;
|
||||
|
||||
}else{ //create transparent slide
|
||||
|
||||
$params["background_type"] = "trans";
|
||||
}
|
||||
|
||||
$jsonParams = json_encode($params);
|
||||
|
||||
$arrInsert = array("params"=>$jsonParams,
|
||||
"slider_id"=>$sliderID,
|
||||
"slide_order"=>$order,
|
||||
"layers"=>""
|
||||
);
|
||||
|
||||
$slideID = $this->db->insert(GlobalsRevSlider::$table_slides, $arrInsert);
|
||||
|
||||
return($slideID);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* update slide image from data
|
||||
*/
|
||||
public function updateSlideImageFromData($data){
|
||||
|
||||
$slideID = UniteFunctionsRev::getVal($data, "slide_id");
|
||||
$this->initByID($slideID);
|
||||
|
||||
$urlImage = UniteFunctionsRev::getVal($data, "url_image");
|
||||
UniteFunctionsRev::validateNotEmpty($urlImage);
|
||||
$imageID = UniteFunctionsRev::getVal($data, "image_id");
|
||||
|
||||
$arrUpdate = array();
|
||||
$arrUpdate["image"] = $urlImage;
|
||||
$arrUpdate["image_id"] = $imageID;
|
||||
|
||||
$this->updateParamsInDB($arrUpdate);
|
||||
|
||||
return($urlImage);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* update slide parameters in db
|
||||
*/
|
||||
private function updateParamsInDB($arrUpdate){
|
||||
|
||||
$this->params = array_merge($this->params,$arrUpdate);
|
||||
$jsonParams = json_encode($this->params);
|
||||
|
||||
$arrDBUpdate = array("params"=>$jsonParams);
|
||||
|
||||
$this->db->update(GlobalsRevSlider::$table_slides,$arrDBUpdate,array("id"=>$this->id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* sort layers by order
|
||||
*/
|
||||
private function sortLayersByOrder($layer1,$layer2){
|
||||
$layer1 = (array)$layer1;
|
||||
$layer2 = (array)$layer2;
|
||||
|
||||
$order1 = UniteFunctionsRev::getVal($layer1, "order",1);
|
||||
$order2 = UniteFunctionsRev::getVal($layer2, "order",2);
|
||||
if($order1 == $order2)
|
||||
return(0);
|
||||
|
||||
return($order1 > $order2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* go through the layers and fix small bugs if exists
|
||||
*/
|
||||
private function normalizeLayers($arrLayers){
|
||||
|
||||
usort($arrLayers,array($this,"sortLayersByOrder"));
|
||||
|
||||
$arrLayersNew = array();
|
||||
foreach ($arrLayers as $key=>$layer){
|
||||
|
||||
$layer = (array)$layer;
|
||||
|
||||
//set type
|
||||
$type = UniteFunctionsRev::getVal($layer, "type","text");
|
||||
$layer["type"] = $type;
|
||||
|
||||
//normalize position:
|
||||
$layer["left"] = round($layer["left"]);
|
||||
$layer["top"] = round($layer["top"]);
|
||||
|
||||
//unset order
|
||||
unset($layer["order"]);
|
||||
|
||||
//modify text
|
||||
$layer["text"] = stripcslashes($layer["text"]);
|
||||
|
||||
$arrLayersNew[] = $layer;
|
||||
}
|
||||
|
||||
return($arrLayersNew);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* normalize params
|
||||
*/
|
||||
private function normalizeParams($params){
|
||||
|
||||
$urlImage = UniteFunctionsRev::getVal($params, "image_url");
|
||||
|
||||
//init the id if absent
|
||||
$params["image_id"] = UniteFunctionsRev::getVal($params, "image_id");
|
||||
|
||||
$params["image"] = $urlImage;
|
||||
unset($params["image_url"]);
|
||||
|
||||
if(isset($params["video_description"]))
|
||||
$params["video_description"] = UniteFunctionsRev::normalizeTextareaContent($params["video_description"]);
|
||||
|
||||
return($params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* update slide from data
|
||||
* @param $data
|
||||
*/
|
||||
public function updateSlideFromData($data){
|
||||
|
||||
$slideID = UniteFunctionsRev::getVal($data, "slideid");
|
||||
$this->initByID($slideID);
|
||||
|
||||
//treat params
|
||||
$params = UniteFunctionsRev::getVal($data, "params");
|
||||
$params = $this->normalizeParams($params);
|
||||
|
||||
//treat layers
|
||||
$layers = UniteFunctionsRev::getVal($data, "layers");
|
||||
if(gettype($layers) == "string"){
|
||||
$layers = stripslashes($layers);
|
||||
$layers = json_decode($layers);
|
||||
$layers = UniteFunctionsRev::convertStdClassToArray($layers);
|
||||
}
|
||||
|
||||
if(empty($layers) || gettype($layers) != "array")
|
||||
$layers = array();
|
||||
|
||||
$layers = $this->normalizeLayers($layers);
|
||||
|
||||
$arrUpdate = array();
|
||||
$arrUpdate["layers"] = json_encode($layers);
|
||||
$arrUpdate["params"] = json_encode($params);
|
||||
|
||||
$this->db->update(GlobalsRevSlider::$table_slides,$arrUpdate,array("id"=>$this->id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* delete slide from data
|
||||
*/
|
||||
public function deleteSlideFromData($data){
|
||||
$slideID = UniteFunctionsRev::getVal($data, "slideID");
|
||||
$this->initByID($slideID);
|
||||
$this->db->delete(GlobalsRevSlider::$table_slides,"id='$slideID'");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* set params from client
|
||||
*/
|
||||
public function setParams($params){
|
||||
$params = $this->normalizeParams($params);
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* set layers from client
|
||||
*/
|
||||
public function setLayers($layers){
|
||||
$layers = $this->normalizeLayers($layers);
|
||||
$this->arrLayers = $layers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/* toggle slide state from data
|
||||
*/
|
||||
public function toggleSlideStatFromData($data){
|
||||
|
||||
$slideID = UniteFunctionsRev::getVal($data, "slide_id");
|
||||
$this->initByID($slideID);
|
||||
|
||||
$state = $this->getParam("state","published");
|
||||
$newState = ($state == "published")?"unpublished":"published";
|
||||
|
||||
$arrUpdate = array();
|
||||
$arrUpdate["state"] = $newState;
|
||||
|
||||
$this->updateParamsInDB($arrUpdate);
|
||||
|
||||
return($newState);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
896
wp-content/plugins/revslider/inc_php/revslider_slider.class.php
Normal file
896
wp-content/plugins/revslider/inc_php/revslider_slider.class.php
Normal file
@ -0,0 +1,896 @@
|
||||
<?php
|
||||
|
||||
class RevSlider extends UniteElementsBaseRev{
|
||||
|
||||
const VALIDATE_NUMERIC = "numeric";
|
||||
const VALIDATE_EMPTY = "empty";
|
||||
const FORCE_NUMERIC = "force_numeric";
|
||||
|
||||
private $id;
|
||||
private $title;
|
||||
private $alias;
|
||||
private $arrParams;
|
||||
private $arrSlides = null;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* validate that the slider is inited. if not - throw error
|
||||
*/
|
||||
private function validateInited(){
|
||||
if(empty($this->id))
|
||||
UniteFunctionsRev::throwError("The slider is not inited!");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* init slider by db data
|
||||
*
|
||||
*/
|
||||
public function initByDBData($arrData){
|
||||
|
||||
$this->id = $arrData["id"];
|
||||
$this->title = $arrData["title"];
|
||||
$this->alias = $arrData["alias"];
|
||||
|
||||
$params = $arrData["params"];
|
||||
$params = (array)json_decode($params);
|
||||
|
||||
$this->arrParams = $params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* init the slider object by database id
|
||||
*/
|
||||
public function initByID($sliderID){
|
||||
UniteFunctionsRev::validateNumeric($sliderID,"Slider ID");
|
||||
$sliderID = $this->db->escape($sliderID);
|
||||
|
||||
try{
|
||||
$sliderData = $this->db->fetchSingle(GlobalsRevSlider::$table_sliders,"id=$sliderID");
|
||||
}catch(Exception $e){
|
||||
UniteFunctionsRev::throwError("Slider with ID: $sliderID Not Found");
|
||||
}
|
||||
|
||||
$this->initByDBData($sliderData);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* init slider by alias
|
||||
*/
|
||||
public function initByAlias($alias){
|
||||
$alias = $this->db->escape($alias);
|
||||
|
||||
try{
|
||||
$where = "alias='$alias'";
|
||||
|
||||
$sliderData = $this->db->fetchSingle(GlobalsRevSlider::$table_sliders,$where);
|
||||
|
||||
}catch(Exception $e){
|
||||
$arrAliases = $this->getAllSliderAliases();
|
||||
$strAliases = "";
|
||||
if(!empty($arrAliases))
|
||||
$strAliases = "'".implode("' or '", $arrAliases)."'";
|
||||
|
||||
$errorMessage = "Slider with alias <strong>$alias</strong> not found.";
|
||||
if(!empty($strAliases))
|
||||
$errorMessage .= " <br><br>Maybe you mean: ".$strAliases;
|
||||
|
||||
UniteFunctionsRev::throwError($errorMessage);
|
||||
}
|
||||
|
||||
$this->initByDBData($sliderData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* init by id or alias
|
||||
*/
|
||||
public function initByMixed($mixed){
|
||||
if(is_numeric($mixed))
|
||||
$this->initByID($mixed);
|
||||
else
|
||||
$this->initByAlias($mixed);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get data functions
|
||||
*/
|
||||
public function getTitle(){
|
||||
return($this->title);
|
||||
}
|
||||
|
||||
public function getID(){
|
||||
return($this->id);
|
||||
}
|
||||
|
||||
public function getParams(){
|
||||
return($this->arrParams);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* set slider params
|
||||
*/
|
||||
public function setParams($arrParams){
|
||||
$this->arrParams = $arrParams;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get parameter from params array. if no default, then the param is a must!
|
||||
*/
|
||||
function getParam($name,$default=null,$validateType = null,$title=""){
|
||||
|
||||
if($default === null){
|
||||
if(!array_key_exists($name, $this->arrParams))
|
||||
UniteFunctionsRev::throwError("The param <b>$name</b> not found in slider params.");
|
||||
|
||||
$default = "";
|
||||
}
|
||||
|
||||
$value = UniteFunctionsRev::getVal($this->arrParams, $name,$default);
|
||||
|
||||
//validation:
|
||||
switch($validateType){
|
||||
case self::VALIDATE_NUMERIC:
|
||||
case self::VALIDATE_EMPTY:
|
||||
$paramTitle = !empty($title)?$title:$name;
|
||||
if($value !== "0" && $value !== 0 && empty($value))
|
||||
UniteFunctionsRev::throwError("The param <strong>$paramTitle</strong> should not be empty.");
|
||||
break;
|
||||
case self::VALIDATE_NUMERIC:
|
||||
$paramTitle = !empty($title)?$title:$name;
|
||||
if(!is_numeric($value))
|
||||
UniteFunctionsRev::throwError("The param <strong>$paramTitle</strong> should be numeric. Now it's: $value");
|
||||
break;
|
||||
case self::FORCE_NUMERIC:
|
||||
if(!is_numeric($value)){
|
||||
$value = 0;
|
||||
if(!empty($default))
|
||||
$value = $default;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getAlias(){
|
||||
return($this->alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* get combination of title (alias)
|
||||
*/
|
||||
public function getShowTitle(){
|
||||
$showTitle = $this->title." ($this->alias)";
|
||||
return($showTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get slider shortcode
|
||||
*/
|
||||
public function getShortcode(){
|
||||
$shortCode = "[rev_slider {$this->alias}]";
|
||||
return($shortCode);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* check if alias exists in DB
|
||||
*/
|
||||
private function isAliasExistsInDB($alias){
|
||||
$alias = $this->db->escape($alias);
|
||||
|
||||
$where = "alias='$alias'";
|
||||
if(!empty($this->id))
|
||||
$where .= " and id != '{$this->id}'";
|
||||
|
||||
$response = $this->db->fetch(GlobalsRevSlider::$table_sliders,$where);
|
||||
return(!empty($response));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* validate settings for add
|
||||
*/
|
||||
private function validateInputSettings($title,$alias,$params){
|
||||
UniteFunctionsRev::validateNotEmpty($title,"title");
|
||||
UniteFunctionsRev::validateNotEmpty($alias,"alias");
|
||||
|
||||
if($this->isAliasExistsInDB($alias))
|
||||
UniteFunctionsRev::throwError("Some other slider with alias '$alias' already exists");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* create / update slider from options
|
||||
*/
|
||||
private function createUpdateSliderFromOptions($options,$sliderID = null){
|
||||
|
||||
$arrMain = UniteFunctionsRev::getVal($options, "main");
|
||||
$params = UniteFunctionsRev::getVal($options, "params");
|
||||
|
||||
//trim all input data
|
||||
$arrMain = UniteFunctionsRev::trimArrayItems($arrMain);
|
||||
$params = UniteFunctionsRev::trimArrayItems($params);
|
||||
|
||||
$params = array_merge($arrMain,$params);
|
||||
|
||||
$title = UniteFunctionsRev::getVal($arrMain, "title");
|
||||
$alias = UniteFunctionsRev::getVal($arrMain, "alias");
|
||||
|
||||
if(!empty($sliderID))
|
||||
$this->initByID($sliderID);
|
||||
|
||||
$this->validateInputSettings($title, $alias, $params);
|
||||
|
||||
$jsonParams = json_encode($params);
|
||||
|
||||
//insert slider to database
|
||||
$arrData = array();
|
||||
$arrData["title"] = $title;
|
||||
$arrData["alias"] = $alias;
|
||||
$arrData["params"] = $jsonParams;
|
||||
|
||||
if(empty($sliderID)){ //create slider
|
||||
$sliderID = $this->db->insert(GlobalsRevSlider::$table_sliders,$arrData);
|
||||
return($sliderID);
|
||||
|
||||
}else{ //update slider
|
||||
$this->initByID($sliderID);
|
||||
|
||||
$sliderID = $this->db->update(GlobalsRevSlider::$table_sliders,$arrData,array("id"=>$sliderID));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* delete slider from datatase
|
||||
*/
|
||||
private function deleteSlider(){
|
||||
|
||||
$this->validateInited();
|
||||
|
||||
//delete slider
|
||||
$this->db->delete(GlobalsRevSlider::$table_sliders,"id=".$this->id);
|
||||
|
||||
//delete slides
|
||||
$this->deleteAllSlides();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* delete all slides
|
||||
*/
|
||||
private function deleteAllSlides(){
|
||||
$this->validateInited();
|
||||
|
||||
$this->db->delete(GlobalsRevSlider::$table_slides,"slider_id=".$this->id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* duplicate slider in datatase
|
||||
*/
|
||||
private function duplicateSlider(){
|
||||
|
||||
$this->validateInited();
|
||||
|
||||
//get slider number:
|
||||
$response = $this->db->fetch(GlobalsRevSlider::$table_sliders);
|
||||
$numSliders = count($response);
|
||||
$newSliderSerial = $numSliders+1;
|
||||
|
||||
$newSliderTitle = "Slider".$newSliderSerial;
|
||||
$newSliderAlias = "slider".$newSliderSerial;
|
||||
|
||||
//insert a new slider
|
||||
$sqlSelect = "select ".GlobalsRevSlider::FIELDS_SLIDER." from ".GlobalsRevSlider::$table_sliders." where id={$this->id}";
|
||||
$sqlInsert = "insert into ".GlobalsRevSlider::$table_sliders." (".GlobalsRevSlider::FIELDS_SLIDER.") ($sqlSelect)";
|
||||
|
||||
$this->db->runSql($sqlInsert);
|
||||
$lastID = $this->db->getLastInsertID();
|
||||
UniteFunctionsRev::validateNotEmpty($lastID);
|
||||
|
||||
//update the new slider with the title and the alias values
|
||||
$arrUpdate = array();
|
||||
$arrUpdate["title"] = $newSliderTitle;
|
||||
$arrUpdate["alias"] = $newSliderAlias;
|
||||
$this->db->update(GlobalsRevSlider::$table_sliders, $arrUpdate, array("id"=>$lastID));
|
||||
|
||||
//duplicate slides
|
||||
$fields_slide = GlobalsRevSlider::FIELDS_SLIDE;
|
||||
$fields_slide = str_replace("slider_id", $lastID, $fields_slide);
|
||||
|
||||
$sqlSelect = "select ".$fields_slide." from ".GlobalsRevSlider::$table_slides." where slider_id={$this->id}";
|
||||
$sqlInsert = "insert into ".GlobalsRevSlider::$table_slides." (".GlobalsRevSlider::FIELDS_SLIDE.") ($sqlSelect)";
|
||||
|
||||
$this->db->runSql($sqlInsert);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* duplicate slide
|
||||
*/
|
||||
private function duplicateSlide($slideID){
|
||||
$slide = new RevSlide();
|
||||
$slide->initByID($slideID);
|
||||
$order = $slide->getOrder();
|
||||
$slides = $this->getSlides();
|
||||
$newOrder = $order+1;
|
||||
$this->shiftOrder($newOrder);
|
||||
|
||||
//do duplication
|
||||
$sqlSelect = "select ".GlobalsRevSlider::FIELDS_SLIDE." from ".GlobalsRevSlider::$table_slides." where id={$slideID}";
|
||||
$sqlInsert = "insert into ".GlobalsRevSlider::$table_slides." (".GlobalsRevSlider::FIELDS_SLIDE.") ($sqlSelect)";
|
||||
|
||||
$this->db->runSql($sqlInsert);
|
||||
$lastID = $this->db->getLastInsertID();
|
||||
UniteFunctionsRev::validateNotEmpty($lastID);
|
||||
|
||||
//update order
|
||||
$arrUpdate = array("slide_order"=>$newOrder);
|
||||
|
||||
$this->db->update(GlobalsRevSlider::$table_slides,$arrUpdate, array("id"=>$lastID));
|
||||
|
||||
return($lastID);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* copy / move slide
|
||||
*/
|
||||
private function copyMoveSlide($slideID,$targetSliderID,$operation){
|
||||
|
||||
if($operation == "move"){
|
||||
|
||||
$targetSlider = new RevSlider();
|
||||
$targetSlider->initByID($targetSliderID);
|
||||
$maxOrder = $targetSlider->getMaxOrder();
|
||||
$newOrder = $maxOrder+1;
|
||||
$arrUpdate = array("slider_id"=>$targetSliderID,"slide_order"=>$newOrder);
|
||||
|
||||
$this->db->update(GlobalsRevSlider::$table_slides,$arrUpdate,array("id"=>$slideID));
|
||||
|
||||
}else{ //in place of copy
|
||||
$this->duplicateSlide($slideID);
|
||||
$this->copyMoveSlide($slideID,$targetSliderID,"move");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* shift order of the slides from specific order
|
||||
*/
|
||||
private function shiftOrder($fromOrder){
|
||||
|
||||
$where = " slider_id={$this->id} and slide_order >= $fromOrder";
|
||||
$sql = "update ".GlobalsRevSlider::$table_slides." set slide_order=(slide_order+1) where $where";
|
||||
$this->db->runSql($sql);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* create slider in database from options
|
||||
*/
|
||||
public function createSliderFromOptions($options){
|
||||
$sliderID = $this->createUpdateSliderFromOptions($options);
|
||||
return($sliderID);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* export slider from data, output a file for download
|
||||
*/
|
||||
public function exportSlider(){
|
||||
$this->validateInited();
|
||||
|
||||
$sliderParams = $this->getParamsForExport();
|
||||
$arrSlides = $this->getSlidesForExport();
|
||||
|
||||
$arrSliderExport = array("params"=>$sliderParams,"slides"=>$arrSlides);
|
||||
|
||||
$strExport = serialize($arrSliderExport);
|
||||
|
||||
if(!empty($this->alias))
|
||||
$filename = $this->alias.".txt";
|
||||
else
|
||||
$filename = "slider_export.txt";
|
||||
|
||||
UniteFunctionsRev::downloadFile($strExport,$filename);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* import slider from multipart form
|
||||
*/
|
||||
public function importSliderFromPost(){
|
||||
|
||||
try{
|
||||
|
||||
$sliderID = UniteFunctionsRev::getPostVariable("sliderid");
|
||||
$sliderExists = !empty($sliderID);
|
||||
|
||||
if($sliderExists)
|
||||
$this->initByID($sliderID);
|
||||
|
||||
$filepath = $_FILES["import_file"]["tmp_name"];
|
||||
|
||||
if(file_exists($filepath) == false)
|
||||
UniteFunctionsRev::throwError("Import file not found!!!");
|
||||
|
||||
//get content array
|
||||
$content = @file_get_contents($filepath);
|
||||
$arrSlider = @unserialize($content);
|
||||
if(empty($arrSlider))
|
||||
UniteFunctionsRev::throwError("Wrong export slider file format!");
|
||||
|
||||
|
||||
//update slider params
|
||||
|
||||
$sliderParams = $arrSlider["params"];
|
||||
|
||||
if($sliderExists){
|
||||
$sliderParams["title"] = $this->arrParams["title"];
|
||||
$sliderParams["alias"] = $this->arrParams["alias"];
|
||||
$sliderParams["shortcode"] = $this->arrParams["shortcode"];
|
||||
}
|
||||
|
||||
if(isset($sliderParams["background_image"]))
|
||||
$sliderParams["background_image"] = UniteFunctionsWPRev::getImageUrlFromPath($sliderParams["background_image"]);
|
||||
|
||||
$json_params = json_encode($sliderParams);
|
||||
|
||||
//update slider or craete new
|
||||
if($sliderExists){
|
||||
$arrUpdate = array("params"=>$json_params);
|
||||
$this->db->update(GlobalsRevSlider::$table_sliders,$arrUpdate,array("id"=>$sliderID));
|
||||
}
|
||||
else{ //new slider
|
||||
$arrInsert = array();
|
||||
$arrInsert["params"] = $json_params;
|
||||
$arrInsert["title"] = UniteFunctionsRev::getVal($sliderParams, "title","Slider1");
|
||||
$arrInsert["alias"] = UniteFunctionsRev::getVal($sliderParams, "alias","slider1");
|
||||
$sliderID = $this->db->insert(GlobalsRevSlider::$table_sliders,$arrInsert);
|
||||
}
|
||||
|
||||
//-------- Slides Handle -----------
|
||||
|
||||
//delete current slides
|
||||
if($sliderExists)
|
||||
$this->deleteAllSlides();
|
||||
|
||||
//create all slides
|
||||
$arrSlides = $arrSlider["slides"];
|
||||
foreach($arrSlides as $slide){
|
||||
|
||||
$params = $slide["params"];
|
||||
$layers = $slide["layers"];
|
||||
|
||||
//convert params images:
|
||||
if(isset($params["image"]))
|
||||
$params["image"] = UniteFunctionsWPRev::getImageUrlFromPath($params["image"]);
|
||||
|
||||
//convert layers images:
|
||||
foreach($layers as $key=>$layer){
|
||||
if(isset($layer["image_url"])){
|
||||
$layer["image_url"] = UniteFunctionsWPRev::getImageUrlFromPath($layer["image_url"]);
|
||||
$layers[$key] = $layer;
|
||||
}
|
||||
}
|
||||
|
||||
//create new slide
|
||||
$arrCreate = array();
|
||||
$arrCreate["slider_id"] = $sliderID;
|
||||
$arrCreate["slide_order"] = $slide["slide_order"];
|
||||
$arrCreate["layers"] = json_encode($layers);
|
||||
$arrCreate["params"] = json_encode($params);
|
||||
|
||||
$this->db->insert(GlobalsRevSlider::$table_slides,$arrCreate);
|
||||
}
|
||||
|
||||
}catch(Exception $e){
|
||||
$errorMessage = $e->getMessage();
|
||||
return(array("success"=>false,"error"=>$errorMessage,"sliderID"=>$sliderID));
|
||||
}
|
||||
|
||||
return(array("success"=>true,"sliderID"=>$sliderID));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* update slider from options
|
||||
*/
|
||||
public function updateSliderFromOptions($options){
|
||||
|
||||
$sliderID = UniteFunctionsRev::getVal($options, "sliderid");
|
||||
UniteFunctionsRev::validateNotEmpty($sliderID,"Slider ID");
|
||||
|
||||
$this->createUpdateSliderFromOptions($options,$sliderID);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* delete slider from input data
|
||||
*/
|
||||
public function deleteSliderFromData($data){
|
||||
$sliderID = UniteFunctionsRev::getVal($data, "sliderid");
|
||||
UniteFunctionsRev::validateNotEmpty($sliderID,"Slider ID");
|
||||
$this->initByID($sliderID);
|
||||
$this->deleteSlider();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* delete slider from input data
|
||||
*/
|
||||
public function duplicateSliderFromData($data){
|
||||
$sliderID = UniteFunctionsRev::getVal($data, "sliderid");
|
||||
UniteFunctionsRev::validateNotEmpty($sliderID,"Slider ID");
|
||||
$this->initByID($sliderID);
|
||||
$this->duplicateSlider();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* duplicate slide from input data
|
||||
*/
|
||||
public function duplicateSlideFromData($data){
|
||||
|
||||
//init the slider
|
||||
$sliderID = UniteFunctionsRev::getVal($data, "sliderID");
|
||||
UniteFunctionsRev::validateNotEmpty($sliderID,"Slider ID");
|
||||
$this->initByID($sliderID);
|
||||
|
||||
//get the slide id
|
||||
$slideID = UniteFunctionsRev::getVal($data, "slideID");
|
||||
UniteFunctionsRev::validateNotEmpty($slideID,"Slide ID");
|
||||
$this->duplicateSlide($slideID);
|
||||
|
||||
return($sliderID);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* copy / move slide from data
|
||||
*/
|
||||
public function copyMoveSlideFromData($data){
|
||||
|
||||
$sliderID = UniteFunctionsRev::getVal($data, "sliderID");
|
||||
UniteFunctionsRev::validateNotEmpty($sliderID,"Slider ID");
|
||||
$this->initByID($sliderID);
|
||||
|
||||
$targetSliderID = UniteFunctionsRev::getVal($data, "targetSliderID");
|
||||
UniteFunctionsRev::validateNotEmpty($sliderID,"Target Slider ID");
|
||||
$this->initByID($sliderID);
|
||||
|
||||
if($targetSliderID == $sliderID)
|
||||
UniteFunctionsRev::throwError("The target slider can't be equal to the source slider");
|
||||
|
||||
$slideID = UniteFunctionsRev::getVal($data, "slideID");
|
||||
UniteFunctionsRev::validateNotEmpty($slideID,"Slide ID");
|
||||
|
||||
$operation = UniteFunctionsRev::getVal($data, "operation");
|
||||
|
||||
$this->copyMoveSlide($slideID,$targetSliderID,$operation);
|
||||
|
||||
return($sliderID);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* create a slide from input data
|
||||
*/
|
||||
public function createSlideFromData($data,$returnSlideID = false){
|
||||
|
||||
$sliderID = UniteFunctionsRev::getVal($data, "sliderid");
|
||||
$obj = UniteFunctionsRev::getVal($data, "obj");
|
||||
|
||||
UniteFunctionsRev::validateNotEmpty($sliderID,"Slider ID");
|
||||
$this->initByID($sliderID);
|
||||
|
||||
if(is_array($obj)){ //multiple
|
||||
foreach($obj as $item){
|
||||
$slide = new RevSlide();
|
||||
$slideID = $slide->createSlide($sliderID, $item);
|
||||
}
|
||||
|
||||
return(count($obj));
|
||||
|
||||
}else{ //signle
|
||||
$urlImage = $obj;
|
||||
$slide = new RevSlide();
|
||||
$slideID = $slide->createSlide($sliderID, $urlImage);
|
||||
if($returnSlideID == true)
|
||||
return($slideID);
|
||||
else
|
||||
return(1); //num slides -1 slide created
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* update slides order from data
|
||||
*/
|
||||
public function updateSlidesOrderFromData($data){
|
||||
$sliderID = UniteFunctionsRev::getVal($data, "sliderID");
|
||||
$arrIDs = UniteFunctionsRev::getVal($data, "arrIDs");
|
||||
UniteFunctionsRev::validateNotEmpty($arrIDs,"slides");
|
||||
|
||||
$this->initByID($sliderID);
|
||||
|
||||
foreach($arrIDs as $index=>$slideID){
|
||||
$order = $index+1;
|
||||
$arrUpdate = array("slide_order"=>$order);
|
||||
$where = array("id"=>$slideID);
|
||||
$this->db->update(GlobalsRevSlider::$table_slides,$arrUpdate,$where);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get the "main" and "settings" arrays, for dealing with the settings.
|
||||
*/
|
||||
public function getSettingsFields(){
|
||||
$this->validateInited();
|
||||
|
||||
$arrMain = array();
|
||||
$arrMain["title"] = $this->title;
|
||||
$arrMain["alias"] = $this->alias;
|
||||
|
||||
$arrRespose = array("main"=>$arrMain,
|
||||
"params"=>$this->arrParams);
|
||||
|
||||
return($arrRespose);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get slides of the current slider
|
||||
*/
|
||||
public function getSlides($publishedOnly = false){
|
||||
$this->validateInited();
|
||||
|
||||
$arrSlides = array();
|
||||
$arrSlideRecords = $this->db->fetch(GlobalsRevSlider::$table_slides,"slider_id=".$this->id,"slide_order");
|
||||
|
||||
foreach ($arrSlideRecords as $record){
|
||||
$slide = new RevSlide();
|
||||
$slide->initByData($record);
|
||||
|
||||
if($publishedOnly == true){
|
||||
$state = $slide->getParam("state","published");
|
||||
if($state == "unpublished")
|
||||
continue;
|
||||
}
|
||||
|
||||
$arrSlides[] = $slide;
|
||||
}
|
||||
|
||||
$this->arrSlides = $arrSlides;
|
||||
|
||||
return($arrSlides);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get array of slide names
|
||||
*/
|
||||
public function getArrSlideNames(){
|
||||
if(empty($this->arrSlides))
|
||||
$this->getSlides();
|
||||
|
||||
$arrSlideNames = array();
|
||||
|
||||
foreach($this->arrSlides as $number=>$slide){
|
||||
$slideID = $slide->getID();
|
||||
$filename = $slide->getImageFilename();
|
||||
$slideName = "Slide ".($number+1);
|
||||
if(!empty($filename))
|
||||
$slideName .= " ($filename)";
|
||||
|
||||
$arrSlideNames[$slideID] = $slideName;
|
||||
}
|
||||
return($arrSlideNames);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get array of slides numbers by id's
|
||||
*/
|
||||
public function getSlidesNumbersByIDs($publishedOnly = false){
|
||||
|
||||
if(empty($this->arrSlides))
|
||||
$this->getSlides($publishedOnly);
|
||||
|
||||
$arrSlideNumbers = array();
|
||||
|
||||
foreach($this->arrSlides as $number=>$slide){
|
||||
$slideID = $slide->getID();
|
||||
$arrSlideNumbers[$slideID] = ($number+1);
|
||||
}
|
||||
return($arrSlideNumbers);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get slider params for export slider
|
||||
*/
|
||||
private function getParamsForExport(){
|
||||
$exportParams = $this->arrParams;
|
||||
|
||||
//modify background image
|
||||
$urlImage = UniteFunctionsRev::getVal($exportParams, "background_image");
|
||||
if(!empty($urlImage))
|
||||
$exportParams["background_image"] = $urlImage;
|
||||
|
||||
return($exportParams);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get slides for export
|
||||
*/
|
||||
private function getSlidesForExport(){
|
||||
$arrSlides = $this->getSlides();
|
||||
$arrSlidesExport = array();
|
||||
foreach($arrSlides as $slide){
|
||||
$slideNew = array();
|
||||
$slideNew["params"] = $slide->getParamsForExport();
|
||||
$slideNew["slide_order"] = $slide->getOrder();
|
||||
$slideNew["layers"] = $slide->getLayersForExport();
|
||||
$arrSlidesExport[] = $slideNew;
|
||||
}
|
||||
|
||||
return($arrSlidesExport);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get slides number
|
||||
*/
|
||||
public function getNumSlides($publishedOnly = false){
|
||||
if($this->arrSlides == null)
|
||||
$this->getSlides($publishedOnly);
|
||||
|
||||
$numSlides = count($this->arrSlides);
|
||||
return($numSlides);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get sliders array - function don't belong to the object!
|
||||
*/
|
||||
public function getArrSliders(){
|
||||
$where = "";
|
||||
|
||||
$response = $this->db->fetch(GlobalsRevSlider::$table_sliders,$where,"id");
|
||||
|
||||
$arrSliders = array();
|
||||
foreach($response as $arrData){
|
||||
$slider = new RevSlider();
|
||||
$slider->initByDBData($arrData);
|
||||
$arrSliders[] = $slider;
|
||||
}
|
||||
|
||||
return($arrSliders);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get aliasees array
|
||||
*/
|
||||
public function getAllSliderAliases(){
|
||||
$where = "";
|
||||
|
||||
$response = $this->db->fetch(GlobalsRevSlider::$table_sliders,$where,"id");
|
||||
|
||||
$arrAliases = array();
|
||||
foreach($response as $arrSlider){
|
||||
$arrAliases[] = $arrSlider["alias"];
|
||||
}
|
||||
|
||||
return($arrAliases);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get array of slider id -> title
|
||||
*/
|
||||
public function getArrSlidersShort($exceptID = null){
|
||||
$arrSliders = $this->getArrSliders();
|
||||
$arrShort = array();
|
||||
foreach($arrSliders as $slider){
|
||||
$id = $slider->getID();
|
||||
if(!empty($exceptID) && $exceptID == $id)
|
||||
continue;
|
||||
|
||||
$title = $slider->getTitle();
|
||||
$arrShort[$id] = $title;
|
||||
}
|
||||
return($arrShort);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get max order
|
||||
*/
|
||||
public function getMaxOrder(){
|
||||
$this->validateInited();
|
||||
$maxOrder = 0;
|
||||
$arrSlideRecords = $this->db->fetch(GlobalsRevSlider::$table_slides,"slider_id=".$this->id,"slide_order desc","","limit 1");
|
||||
if(empty($arrSlideRecords))
|
||||
return($maxOrder);
|
||||
$maxOrder = $arrSlideRecords[0]["slide_order"];
|
||||
|
||||
return($maxOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get setting - start with slide
|
||||
*/
|
||||
public function getStartWithSlideSetting(){
|
||||
|
||||
$numSlides = $this->getNumSlides();
|
||||
|
||||
$startWithSlide = $this->getParam("start_with_slide","1");
|
||||
if(is_numeric($startWithSlide)){
|
||||
$startWithSlide = (int)$startWithSlide - 1;
|
||||
if($startWithSlide < 0)
|
||||
$startWithSlide = 0;
|
||||
|
||||
if($startWithSlide >= $numSlides)
|
||||
$startWithSlide = 0;
|
||||
|
||||
}else
|
||||
$startWithSlide = 0;
|
||||
|
||||
return($startWithSlide);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
102
wp-content/plugins/revslider/inc_php/revslider_widget.class.php
Normal file
102
wp-content/plugins/revslider/inc_php/revslider_widget.class.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
class RevSlider_Widget extends WP_Widget {
|
||||
|
||||
public function __construct(){
|
||||
|
||||
// widget actual processes
|
||||
$widget_ops = array('classname' => 'widget_revslider', 'description' => __('Displays a revolution slider on the page') );
|
||||
parent::__construct('rev-slider-widget', __('Revolution Slider'), $widget_ops);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* the form
|
||||
*/
|
||||
public function form($instance) {
|
||||
|
||||
$slider = new RevSlider();
|
||||
$arrSliders = $slider->getArrSlidersShort();
|
||||
|
||||
if(empty($arrSliders))
|
||||
echo __("No sliders found, Please create a slider");
|
||||
else{
|
||||
|
||||
$field = "rev_slider";
|
||||
$fieldPages = "rev_slider_pages";
|
||||
$fieldCheck = "rev_slider_homepage";
|
||||
|
||||
$sliderID = UniteFunctionsRev::getVal($instance, $field);
|
||||
$homepage = UniteFunctionsRev::getVal($instance, $fieldCheck);
|
||||
$pagesValue = UniteFunctionsRev::getVal($instance, $fieldPages);
|
||||
|
||||
$fieldID = $this->get_field_id( $field );
|
||||
$fieldName = $this->get_field_name( $field );
|
||||
|
||||
$select = UniteFunctionsRev::getHTMLSelect($arrSliders,$sliderID,'name="'.$fieldName.'" id="'.$fieldID.'"',true);
|
||||
|
||||
$fieldID_check = $this->get_field_id( $fieldCheck );
|
||||
$fieldName_check = $this->get_field_name( $fieldCheck );
|
||||
$checked = "";
|
||||
if($homepage == "on")
|
||||
$checked = "checked='checked'";
|
||||
|
||||
$fieldPages_ID = $this->get_field_id( $fieldPages );
|
||||
$fieldPages_Name = $this->get_field_name( $fieldPages );
|
||||
|
||||
?>
|
||||
Choose Slider: <?php echo $select?>
|
||||
<div style="padding-top:10px;"></div>
|
||||
|
||||
<label for="<?php echo $fieldID_check?>">Home Page Only:</label>
|
||||
<input type="checkbox" name="<?php echo $fieldName_check?>" id="<?php echo $fieldID_check?>" <?php echo $checked?> >
|
||||
<br><br>
|
||||
<label for="<?php echo $fieldPages_ID?>">Pages: (example: 2,10) </label>
|
||||
<input type="text" name="<?php echo $fieldPages_Name?>" id="<?php echo $fieldPages_ID?>" value="<?php echo $pagesValue?>">
|
||||
|
||||
<div style="padding-top:10px;"></div>
|
||||
<?php
|
||||
} //else
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* update
|
||||
*/
|
||||
public function update($new_instance, $old_instance) {
|
||||
|
||||
return($new_instance);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* widget output
|
||||
*/
|
||||
public function widget($args, $instance) {
|
||||
|
||||
$sliderID = UniteFunctionsRev::getVal($instance, "rev_slider");
|
||||
|
||||
$homepageCheck = UniteFunctionsRev::getVal($instance, "rev_slider_homepage");
|
||||
$homepage = "";
|
||||
if($homepageCheck == "on")
|
||||
$homepage = "homepage";
|
||||
|
||||
$pages = UniteFunctionsRev::getVal($instance, "rev_slider_pages");
|
||||
if(!empty($pages)){
|
||||
if(!empty($homepage))
|
||||
$homepage .= ",";
|
||||
$homepage .= $pages;
|
||||
}
|
||||
|
||||
if(empty($sliderID))
|
||||
return(false);
|
||||
|
||||
RevSliderOutput::putSlider($sliderID,$homepage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
Reference in New Issue
Block a user