base.class.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. <?php
  2. /**
  3. * @author ThemePunch <info@themepunch.com>
  4. * @link http://www.themepunch.com/
  5. * @copyright 2015 ThemePunch
  6. */
  7. if( !defined( 'ABSPATH') ) exit();
  8. class RevSliderBase {
  9. protected static $wpdb;
  10. protected static $table_prefix;
  11. protected static $t;
  12. protected static $url_ajax;
  13. protected static $url_ajax_showimage;
  14. protected static $path_views;
  15. protected static $path_templates;
  16. protected static $is_multisite;
  17. public static $url_ajax_actions;
  18. /**
  19. *
  20. * the constructor
  21. */
  22. public function __construct($t){
  23. global $wpdb;
  24. self::$is_multisite = RevSliderFunctionsWP::isMultisite();
  25. self::$wpdb = $wpdb;
  26. self::$table_prefix = self::$wpdb->base_prefix;
  27. if(self::$is_multisite){
  28. $blogID = RevSliderFunctionsWP::getBlogID();
  29. if($blogID != 1){
  30. self::$table_prefix .= $blogID."_";
  31. }
  32. }
  33. self::$t = $t;
  34. self::$url_ajax = admin_url("admin-ajax.php");
  35. self::$url_ajax_actions = self::$url_ajax . "?action=revslider_ajax_action";
  36. self::$url_ajax_showimage = self::$url_ajax . "?action=revslider_show_image";
  37. self::$path_views = RS_PLUGIN_PATH."admin/views/";
  38. self::$path_templates = self::$path_views."/templates/";
  39. load_plugin_textdomain('revslider',false,'revslider/languages/');
  40. //update globals oldversion flag
  41. RevSliderGlobals::$isNewVersion = false;
  42. $version = get_bloginfo("version");
  43. $version = (double)$version;
  44. if($version >= 3.5)
  45. RevSliderGlobals::$isNewVersion = true;
  46. }
  47. /**
  48. *
  49. * add some wordpress action
  50. */
  51. protected static function addAction($action,$eventFunction){
  52. add_action( $action, array(self::$t, $eventFunction) );
  53. }
  54. /**
  55. *
  56. * get image url to be shown via thumb making script.
  57. */
  58. public static function getImageUrl($filepath, $width=null,$height=null,$exact=false,$effect=null,$effect_param=null){
  59. $urlImage = self::getUrlThumb(self::$url_ajax_showimage, $filepath,$width ,$height ,$exact ,$effect ,$effect_param);
  60. return($urlImage);
  61. }
  62. /**
  63. * get thumb url
  64. * @since: 5.0
  65. * @moved from image_view.class.php
  66. */
  67. public static function getUrlThumb($urlBase, $filename,$width=null,$height=null,$exact=false,$effect=null,$effect_param=null){
  68. $filename = urlencode($filename);
  69. $url = $urlBase."&img=$filename";
  70. if(!empty($width))
  71. $url .= "&w=".$width;
  72. if(!empty($height))
  73. $url .= "&h=".$height;
  74. if($exact == true){
  75. $url .= "&t=".self::TYPE_EXACT;
  76. }
  77. if(!empty($effect)){
  78. $url .= "&e=".$effect;
  79. if(!empty($effect_param))
  80. $url .= "&ea1=".$effect_param;
  81. }
  82. return($url);
  83. }
  84. /**
  85. *
  86. * on show image ajax event. outputs image with parameters
  87. */
  88. public static function onShowImage(){
  89. $pathImages = RevSliderFunctionsWP::getPathContent();
  90. $urlImages = RevSliderFunctionsWP::getUrlContent();
  91. try{
  92. $imageID = intval(RevSliderFunctions::getGetVar("img"));
  93. $img = wp_get_attachment_image_src( $imageID, 'thumb' );
  94. if(empty($img)) exit;
  95. self::outputImage($img[0]);
  96. }catch (Exception $e){
  97. header("status: 500");
  98. echo __('Image not Found', 'revslider');
  99. exit();
  100. }
  101. }
  102. /**
  103. * show Image to client
  104. * @since: 5.0
  105. * @moved from image_view.class.php
  106. */
  107. private static function outputImage($filepath){
  108. $info = RevSliderFunctions::getPathInfo($filepath);
  109. $ext = $info["extension"];
  110. $ext = strtolower($ext);
  111. if($ext == "jpg")
  112. $ext = "jpeg";
  113. $numExpires = 31536000; //one year
  114. $strExpires = @date('D, d M Y H:i:s',time()+$numExpires);
  115. $contents = file_get_contents($filepath);
  116. $filesize = strlen($contents);
  117. header("Expires: $strExpires GMT");
  118. header("Cache-Control: public");
  119. header("Content-Type: image/$ext");
  120. header("Content-Length: $filesize");
  121. echo $contents;
  122. exit();
  123. }
  124. /**
  125. *
  126. * get POST var
  127. */
  128. protected static function getPostVar($key,$defaultValue = ""){
  129. $val = self::getVar($_POST, $key, $defaultValue);
  130. return($val);
  131. }
  132. /**
  133. *
  134. * get GET var
  135. */
  136. protected static function getGetVar($key,$defaultValue = ""){
  137. $val = self::getVar($_GET, $key, $defaultValue);
  138. return($val);
  139. }
  140. /**
  141. *
  142. * get post or get variable
  143. */
  144. protected static function getPostGetVar($key,$defaultValue = ""){
  145. if(array_key_exists($key, $_POST))
  146. $val = self::getVar($_POST, $key, $defaultValue);
  147. else
  148. $val = self::getVar($_GET, $key, $defaultValue);
  149. return($val);
  150. }
  151. /**
  152. *
  153. * get some var from array
  154. */
  155. public static function getVar($arr,$key,$defaultValue = ""){
  156. $val = $defaultValue;
  157. if(isset($arr[$key])) $val = $arr[$key];
  158. return($val);
  159. }
  160. /**
  161. * Get all images sizes + custom added sizes
  162. */
  163. public static function get_all_image_sizes($type = 'gallery'){
  164. $custom_sizes = array();
  165. switch($type){
  166. case 'flickr':
  167. $custom_sizes = array(
  168. 'original' => __('Original', 'revslider'),
  169. 'large' => __('Large', 'revslider'),
  170. 'large-square' => __('Large Square', 'revslider'),
  171. 'medium' => __('Medium', 'revslider'),
  172. 'medium-800' => __('Medium 800', 'revslider'),
  173. 'medium-640' => __('Medium 640', 'revslider'),
  174. 'small' => __('Small', 'revslider'),
  175. 'small-320' => __('Small 320', 'revslider'),
  176. 'thumbnail'=> __('Thumbnail', 'revslider'),
  177. 'square' => __('Square', 'revslider')
  178. );
  179. break;
  180. case 'instagram':
  181. $custom_sizes = array(
  182. 'standard_resolution' => __('Standard Resolution', 'revslider'),
  183. 'thumbnail' => __('Thumbnail', 'revslider'),
  184. 'low_resolution' => __('Low Resolution', 'revslider')
  185. );
  186. break;
  187. case 'twitter':
  188. $custom_sizes = array(
  189. 'large' => __('Standard Resolution', 'revslider')
  190. );
  191. break;
  192. case 'facebook':
  193. $custom_sizes = array(
  194. 'full' => __('Original Size', 'revslider'),
  195. 'thumbnail' => __('Thumbnail', 'revslider')
  196. );
  197. break;
  198. case 'youtube':
  199. $custom_sizes = array(
  200. 'default' => __('Default', 'revslider'),
  201. 'medium' => __('Medium', 'revslider'),
  202. 'high' => __('High', 'revslider'),
  203. 'standard' => __('Standard', 'revslider'),
  204. 'maxres' => __('Max. Res.', 'revslider')
  205. );
  206. break;
  207. case 'vimeo':
  208. $custom_sizes = array(
  209. 'thumbnail_small' => __('Small', 'revslider'),
  210. 'thumbnail_medium' => __('Medium', 'revslider'),
  211. 'thumbnail_large' => __('Large', 'revslider'),
  212. );
  213. break;
  214. case 'gallery':
  215. default:
  216. $added_image_sizes = get_intermediate_image_sizes();
  217. if(!empty($added_image_sizes) && is_array($added_image_sizes)){
  218. foreach($added_image_sizes as $key => $img_size_handle){
  219. $custom_sizes[$img_size_handle] = ucwords(str_replace('_', ' ', $img_size_handle));
  220. }
  221. }
  222. $img_orig_sources = array(
  223. 'full' => __('Original Size', 'revslider'),
  224. 'thumbnail' => __('Thumbnail', 'revslider'),
  225. 'medium' => __('Medium', 'revslider'),
  226. 'large' => __('Large', 'revslider')
  227. );
  228. $custom_sizes = array_merge($img_orig_sources, $custom_sizes);
  229. break;
  230. }
  231. return $custom_sizes;
  232. }
  233. /**
  234. * retrieve the image id from the given image url
  235. */
  236. public static function get_image_id_by_url($image_url) {
  237. global $wpdb;
  238. $attachment_id = 0;
  239. if(function_exists('attachment_url_to_postid')){
  240. $attachment_id = attachment_url_to_postid($image_url); //0 if failed
  241. }
  242. if ( 0 == $attachment_id ){ //try to get it old school way
  243. //for WP < 4.0.0
  244. $attachment_id = false;
  245. // If there is no url, return.
  246. if ( '' == $image_url )
  247. return;
  248. // Get the upload directory paths
  249. $upload_dir_paths = wp_upload_dir();
  250. // Make sure the upload path base directory exists in the attachment URL, to verify that we're working with a media library image
  251. if ( false !== strpos( $image_url, $upload_dir_paths['baseurl'] ) ) {
  252. // If this is the URL of an auto-generated thumbnail, get the URL of the original image
  253. $image_url = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $image_url );
  254. // Remove the upload path base directory from the attachment URL
  255. $image_url = str_replace( $upload_dir_paths['baseurl'] . '/', '', $image_url );
  256. // Finally, run a custom database query to get the attachment ID from the modified attachment URL
  257. $attachment_id = $wpdb->get_var( $wpdb->prepare( "SELECT wposts.ID FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '_wp_attached_file' AND wpostmeta.meta_value = '%s' AND wposts.post_type = 'attachment'", $image_url ) );
  258. }
  259. }
  260. return $attachment_id;
  261. }
  262. /**
  263. * get all the svg url sets used in Slider Revolution
  264. * @since: 5.1.7
  265. **/
  266. public static function get_svg_sets_url(){
  267. $svg_sets = array();
  268. $path = RS_PLUGIN_PATH . 'public/assets/assets/svg/';
  269. $url = RS_PLUGIN_URL . 'public/assets/assets/svg/';
  270. if(!file_exists($path.'action/ic_3d_rotation_24px.svg')){ //the path needs to be changed to the uploads folder then
  271. $upload_dir = wp_upload_dir();
  272. $path = $upload_dir['basedir'].'/revslider/assets/svg/';
  273. $url = $upload_dir['baseurl'].'/revslider/assets/svg/';
  274. }
  275. $svg_sets['Actions'] = array('path' => $path.'action/', 'url' => $url.'action/');
  276. $svg_sets['Alerts'] = array('path' => $path.'alert/', 'url' => $url.'alert/');
  277. $svg_sets['AV'] = array('path' => $path.'av/', 'url' => $url.'av/');
  278. $svg_sets['Communication'] = array('path' => $path.'communication/', 'url' => $url.'communication/');
  279. $svg_sets['Content'] = array('path' => $path.'content/', 'url' => $url.'content/');
  280. $svg_sets['Device'] = array('path' => $path.'device/', 'url' => $url.'device/');
  281. $svg_sets['Editor'] = array('path' => $path.'editor/', 'url' => $url.'editor/');
  282. $svg_sets['File'] = array('path' => $path.'file/', 'url' => $url.'file/');
  283. $svg_sets['Hardware'] = array('path' => $path.'hardware/', 'url' => $url.'hardware/');
  284. $svg_sets['Images'] = array('path' => $path.'image/', 'url' => $url.'image/');
  285. $svg_sets['Maps'] = array('path' => $path.'maps/', 'url' => $url.'maps/');
  286. $svg_sets['Navigation'] = array('path' => $path.'navigation/', 'url' => $url.'navigation/');
  287. $svg_sets['Notifications'] = array('path' => $path.'notification/', 'url' => $url.'notification/');
  288. $svg_sets['Places'] = array('path' => $path.'places/', 'url' => $url.'places/');
  289. $svg_sets['Social'] = array('path' => $path.'social/', 'url' => $url.'social/');
  290. $svg_sets['Toggle'] = array('path' => $path.'toggle/', 'url' => $url.'toggle/');
  291. $svg_sets = apply_filters('revslider_get_svg_sets', $svg_sets);
  292. return $svg_sets;
  293. }
  294. /**
  295. * get all the svg files for given sets used in Slider Revolution
  296. * @since: 5.1.7
  297. **/
  298. public static function get_svg_sets_full(){
  299. $svg_sets = self::get_svg_sets_url();
  300. $svg = array();
  301. if(!empty($svg_sets)){
  302. foreach($svg_sets as $handle => $values){
  303. $svg[$handle] = array();
  304. if($dir = opendir($values['path'])) {
  305. while(false !== ($file = readdir($dir))){
  306. if ($file != "." && $file != "..") {
  307. $filetype = pathinfo($file);
  308. if(isset($filetype['extension']) && $filetype['extension'] == 'svg'){
  309. $svg[$handle][$file] = $values['url'].$file;
  310. }
  311. }
  312. }
  313. }
  314. }
  315. }
  316. $svg = apply_filters('revslider_get_svg_sets_full', $svg);
  317. return $svg;
  318. }
  319. /**
  320. * get all the icon sets used in Slider Revolution
  321. * @since: 5.0
  322. **/
  323. public static function get_icon_sets(){
  324. $icon_sets = array();
  325. $icon_sets = apply_filters('revslider_mod_icon_sets', $icon_sets);
  326. return $icon_sets;
  327. }
  328. /**
  329. * add default icon sets of Slider Revolution
  330. * @since: 5.0
  331. **/
  332. public static function set_icon_sets($icon_sets){
  333. $icon_sets[] = 'fa-icon-';
  334. $icon_sets[] = 'pe-7s-';
  335. return $icon_sets;
  336. }
  337. /**
  338. * translates removed settings from Slider Settings from version <= 4.x to 5.0
  339. * @since: 5.0
  340. **/
  341. public static function translate_settings_to_v5($settings){
  342. if(isset($settings['navigaion_type'])){
  343. switch($settings['navigaion_type']){
  344. case 'none': // all is off, so leave the defaults
  345. break;
  346. case 'bullet':
  347. $settings['enable_bullets'] = 'on';
  348. $settings['enable_thumbnails'] = 'off';
  349. $settings['enable_tabs'] = 'off';
  350. break;
  351. case 'thumb':
  352. $settings['enable_bullets'] = 'off';
  353. $settings['enable_thumbnails'] = 'on';
  354. $settings['enable_tabs'] = 'off';
  355. break;
  356. }
  357. unset($settings['navigaion_type']);
  358. }
  359. if(isset($settings['navigation_arrows'])){
  360. $settings['enable_arrows'] = ($settings['navigation_arrows'] == 'solo' || $settings['navigation_arrows'] == 'nexttobullets') ? 'on' : 'off';
  361. unset($settings['navigation_arrows']);
  362. }
  363. if(isset($settings['navigation_style'])){
  364. $settings['navigation_arrow_style'] = $settings['navigation_style'];
  365. $settings['navigation_bullets_style'] = $settings['navigation_style'];
  366. unset($settings['navigation_style']);
  367. }
  368. if(isset($settings['navigaion_always_on'])){
  369. $settings['arrows_always_on'] = $settings['navigaion_always_on'];
  370. $settings['bullets_always_on'] = $settings['navigaion_always_on'];
  371. $settings['thumbs_always_on'] = $settings['navigaion_always_on'];
  372. unset($settings['navigaion_always_on']);
  373. }
  374. if(isset($settings['hide_thumbs']) && !isset($settings['hide_arrows']) && !isset($settings['hide_bullets'])){ //as hide_thumbs is still existing, we need to check if the other two were already set and only translate this if they are not set yet
  375. $settings['hide_arrows'] = $settings['hide_thumbs'];
  376. $settings['hide_bullets'] = $settings['hide_thumbs'];
  377. }
  378. if(isset($settings['navigaion_align_vert'])){
  379. $settings['bullets_align_vert'] = $settings['navigaion_align_vert'];
  380. $settings['thumbnails_align_vert'] = $settings['navigaion_align_vert'];
  381. unset($settings['navigaion_align_vert']);
  382. }
  383. if(isset($settings['navigaion_align_hor'])){
  384. $settings['bullets_align_hor'] = $settings['navigaion_align_hor'];
  385. $settings['thumbnails_align_hor'] = $settings['navigaion_align_hor'];
  386. unset($settings['navigaion_align_hor']);
  387. }
  388. if(isset($settings['navigaion_offset_hor'])){
  389. $settings['bullets_offset_hor'] = $settings['navigaion_offset_hor'];
  390. $settings['thumbnails_offset_hor'] = $settings['navigaion_offset_hor'];
  391. unset($settings['navigaion_offset_hor']);
  392. }
  393. if(isset($settings['navigaion_offset_hor'])){
  394. $settings['bullets_offset_hor'] = $settings['navigaion_offset_hor'];
  395. $settings['thumbnails_offset_hor'] = $settings['navigaion_offset_hor'];
  396. unset($settings['navigaion_offset_hor']);
  397. }
  398. if(isset($settings['navigaion_offset_vert'])){
  399. $settings['bullets_offset_vert'] = $settings['navigaion_offset_vert'];
  400. $settings['thumbnails_offset_vert'] = $settings['navigaion_offset_vert'];
  401. unset($settings['navigaion_offset_vert']);
  402. }
  403. if(isset($settings['show_timerbar']) && !isset($settings['enable_progressbar'])){
  404. if($settings['show_timerbar'] == 'hide'){
  405. $settings['enable_progressbar'] = 'off';
  406. $settings['show_timerbar'] = 'top';
  407. }else{
  408. $settings['enable_progressbar'] = 'on';
  409. }
  410. }
  411. return $settings;
  412. }
  413. /**
  414. * explodes google fonts and returns the number of font weights of all fonts
  415. * @since: 5.0
  416. **/
  417. public static function get_font_weight_count($string){
  418. $string = explode(':', $string);
  419. $nums = 0;
  420. if(count($string) >= 2){
  421. $string = $string[1];
  422. if(strpos($string, '&') !== false){
  423. $string = explode('&', $string);
  424. $string = $string[0];
  425. }
  426. $nums = count(explode(',', $string));
  427. }
  428. return $nums;
  429. }
  430. /**
  431. * strip slashes recursive
  432. * @since: 5.0
  433. */
  434. public static function stripslashes_deep($value){
  435. $value = is_array($value) ?
  436. array_map( array('RevSliderBase', 'stripslashes_deep'), $value) :
  437. stripslashes($value);
  438. return $value;
  439. }
  440. /**
  441. * check if file is in zip
  442. * @since: 5.0
  443. */
  444. public static function check_file_in_zip($d_path, $image, $alias, &$alreadyImported, $add_path = false){
  445. global $wp_filesystem;
  446. if(trim($image) !== ''){
  447. if(strpos($image, 'http') !== false){
  448. }else{
  449. $strip = false;
  450. $zimage = $wp_filesystem->exists( $d_path.'images/'.$image );
  451. if(!$zimage){
  452. $zimage = $wp_filesystem->exists( str_replace('//', '/', $d_path.'images/'.$image) );
  453. $strip = true;
  454. }
  455. if(!$zimage){
  456. //echo $image.__(' not found!<br>', 'revslider');
  457. }else{
  458. if(!isset($alreadyImported['images/'.$image])){
  459. //check if we are object folder, if yes, do not import into media library but add it to the object folder
  460. $uimg = ($strip == true) ? str_replace('//', '/', 'images/'.$image) : $image; //pclzip
  461. $object_library = (strpos($uimg, 'revslider/objects/') === 0) ? true : false;
  462. if($object_library === true){ //copy the image to the objects folder if false
  463. $objlib = new RevSliderObjectLibrary();
  464. $importImage = $objlib->_import_object($d_path.'images/'.$uimg);
  465. }else{
  466. $importImage = RevSliderFunctionsWP::import_media($d_path.'images/'.$uimg, $alias.'/');
  467. }
  468. if($importImage !== false){
  469. $alreadyImported['images/'.$image] = $importImage['path'];
  470. $image = $importImage['path'];
  471. }
  472. }else{
  473. $image = $alreadyImported['images/'.$image];
  474. }
  475. }
  476. if($add_path){
  477. $upload_dir = wp_upload_dir();
  478. $cont_url = $upload_dir['baseurl'];
  479. $image = str_replace('uploads/uploads/', 'uploads/', $cont_url . '/' . $image);
  480. }
  481. }
  482. }
  483. return $image;
  484. }
  485. /**
  486. * add "a" tags to links within a text
  487. * @since: 5.0
  488. */
  489. public static function add_wrap_around_url($text){
  490. $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
  491. // Check if there is a url in the text
  492. if(preg_match($reg_exUrl, $text, $url)){
  493. // make the urls hyper links
  494. return preg_replace($reg_exUrl, '<a href="'.$url[0].'" rel="nofollow" target="_blank">'.$url[0].'</a>', $text);
  495. }else{
  496. // if no urls in the text just return the text
  497. return $text;
  498. }
  499. }
  500. /**
  501. * prints out debug text if constant TP_DEBUG is defined and true
  502. * @since: 5.2.4
  503. */
  504. public static function debug($value , $message, $where = "console"){
  505. if( defined('TP_DEBUG') && TP_DEBUG ){
  506. if($where=="console"){
  507. echo '<script>
  508. jQuery(document).ready(function(){
  509. if(window.console) {
  510. console.log("'.$message.'");
  511. console.log('.json_encode($value).');
  512. }
  513. });
  514. </script>
  515. ';
  516. }
  517. else{
  518. var_dump($value);
  519. }
  520. }
  521. else {
  522. return false;
  523. }
  524. }
  525. }
  526. /**
  527. * old classname extends new one (old classnames will be obsolete soon)
  528. * @since: 5.0
  529. **/
  530. class UniteBaseClassRev extends RevSliderBase {}
  531. ?>