revslider-front.class.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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 RevSliderFront extends RevSliderBaseFront{
  9. /**
  10. *
  11. * the constructor
  12. */
  13. public function __construct(){
  14. parent::__construct($this);
  15. //set table names
  16. RevSliderGlobals::$table_sliders = self::$table_prefix.RevSliderGlobals::TABLE_SLIDERS_NAME;
  17. RevSliderGlobals::$table_slides = self::$table_prefix.RevSliderGlobals::TABLE_SLIDES_NAME;
  18. RevSliderGlobals::$table_static_slides = self::$table_prefix.RevSliderGlobals::TABLE_STATIC_SLIDES_NAME;
  19. RevSliderGlobals::$table_settings = self::$table_prefix.RevSliderGlobals::TABLE_SETTINGS_NAME;
  20. RevSliderGlobals::$table_css = self::$table_prefix.RevSliderGlobals::TABLE_CSS_NAME;
  21. RevSliderGlobals::$table_layer_anims = self::$table_prefix.RevSliderGlobals::TABLE_LAYER_ANIMS_NAME;
  22. RevSliderGlobals::$table_navigation = self::$table_prefix.RevSliderGlobals::TABLE_NAVIGATION_NAME;
  23. add_filter('punchfonts_modify_url', array('RevSliderFront', 'modify_punch_url'));
  24. add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
  25. }
  26. /**
  27. *
  28. * a must function. you can not use it, but the function must stay there!
  29. */
  30. public static function onAddScripts(){
  31. global $wp_version;
  32. $slver = apply_filters('revslider_remove_version', RevSliderGlobals::SLIDER_REVISION);
  33. $style_pre = '';
  34. $style_post = '';
  35. if($wp_version < 3.7){
  36. $style_pre = '<style type="text/css">';
  37. $style_post = '</style>';
  38. }
  39. $operations = new RevSliderOperations();
  40. $arrValues = $operations->getGeneralSettingsValues();
  41. $includesGlobally = RevSliderFunctions::getVal($arrValues, "includes_globally","on");
  42. $includesFooter = RevSliderFunctions::getVal($arrValues, "js_to_footer","off");
  43. $load_all_javascript = RevSliderFunctions::getVal($arrValues, "load_all_javascript","off");
  44. $strPutIn = RevSliderFunctions::getVal($arrValues, "pages_for_includes");
  45. $isPutIn = RevSliderOutput::isPutIn($strPutIn,true);
  46. $do_inclusion = apply_filters('revslider_include_libraries', false);
  47. //put the includes only on pages with active widget or shortcode
  48. // if the put in match, then include them always (ignore this if)
  49. if($isPutIn == false && $includesGlobally == "off" && $do_inclusion == false){
  50. $isWidgetActive = is_active_widget( false, false, "rev-slider-widget", true );
  51. $hasShortcode = RevSliderFunctionsWP::hasShortcode("rev_slider");
  52. if($isWidgetActive == false && $hasShortcode == false)
  53. return(false);
  54. }
  55. wp_enqueue_style('rs-plugin-settings', RS_PLUGIN_URL .'public/assets/css/settings.css', array(), $slver);
  56. $custom_css = RevSliderOperations::getStaticCss();
  57. $custom_css = RevSliderCssParser::compress_css($custom_css);
  58. if(trim($custom_css) == '') $custom_css = '#rs-demo-id {}';
  59. wp_add_inline_style( 'rs-plugin-settings', $style_pre.$custom_css.$style_post );
  60. $setBase = (is_ssl()) ? "https://" : "http://";
  61. wp_enqueue_script(array('jquery'));
  62. $waitfor = array('jquery');
  63. $enable_logs = RevSliderFunctions::getVal($arrValues, "enable_logs",'off');
  64. if($enable_logs == 'on'){
  65. wp_enqueue_script('enable-logs', RS_PLUGIN_URL .'public/assets/js/jquery.themepunch.enablelog.js', $waitfor, $slver);
  66. $waitfor[] = 'enable-logs';
  67. }
  68. $ft = ($includesFooter == "on") ? true : false;
  69. wp_enqueue_script('tp-tools', RS_PLUGIN_URL .'public/assets/js/jquery.themepunch.tools.min.js', $waitfor, $slver, $ft);
  70. wp_enqueue_script('revmin', RS_PLUGIN_URL .'public/assets/js/jquery.themepunch.revolution.min.js', 'tp-tools', $slver, $ft);
  71. if($load_all_javascript !== 'off'){ //if on, load all libraries instead of dynamically loading them
  72. wp_enqueue_script('revmin-actions', RS_PLUGIN_URL .'public/assets/js/extensions/revolution.extension.actions.min.js', 'tp-tools', $slver, $ft);
  73. wp_enqueue_script('revmin-carousel', RS_PLUGIN_URL .'public/assets/js/extensions/revolution.extension.carousel.min.js', 'tp-tools', $slver, $ft);
  74. wp_enqueue_script('revmin-kenburn', RS_PLUGIN_URL .'public/assets/js/extensions/revolution.extension.kenburn.min.js', 'tp-tools', $slver, $ft);
  75. wp_enqueue_script('revmin-layeranimation', RS_PLUGIN_URL .'public/assets/js/extensions/revolution.extension.layeranimation.min.js', 'tp-tools', $slver, $ft);
  76. wp_enqueue_script('revmin-migration', RS_PLUGIN_URL .'public/assets/js/extensions/revolution.extension.migration.min.js', 'tp-tools', $slver, $ft);
  77. wp_enqueue_script('revmin-navigation', RS_PLUGIN_URL .'public/assets/js/extensions/revolution.extension.navigation.min.js', 'tp-tools', $slver, $ft);
  78. wp_enqueue_script('revmin-parallax', RS_PLUGIN_URL .'public/assets/js/extensions/revolution.extension.parallax.min.js', 'tp-tools', $slver, $ft);
  79. wp_enqueue_script('revmin-slideanims', RS_PLUGIN_URL .'public/assets/js/extensions/revolution.extension.slideanims.min.js', 'tp-tools', $slver, $ft);
  80. wp_enqueue_script('revmin-video', RS_PLUGIN_URL .'public/assets/js/extensions/revolution.extension.video.min.js', 'tp-tools', $slver, $ft);
  81. }
  82. add_action('wp_head', array('RevSliderFront', 'add_meta_generator'));
  83. add_action('wp_head', array('RevSliderFront', 'add_setREVStartSize'), 99);
  84. add_action('admin_head', array('RevSliderFront', 'add_setREVStartSize'), 99);
  85. add_action("wp_footer", array('RevSliderFront',"load_icon_fonts") );
  86. // Async JS Loading
  87. $js_defer = RevSliderBase::getVar($arrValues, 'js_defer', 'off');
  88. if($js_defer!='off') add_filter('clean_url', array('RevSliderFront', 'add_defer_forscript'), 11, 1);
  89. add_action('wp_before_admin_bar_render', array('RevSliderFront', 'add_admin_menu_nodes'));
  90. add_action('wp_footer', array('RevSliderFront', 'putAdminBarMenus'), 99);
  91. }
  92. /**
  93. * add admin menu points in ToolBar Top
  94. * @since: 5.0.5
  95. */
  96. public static function putAdminBarMenus () {
  97. if(!is_super_admin() || !is_admin_bar_showing()) return;
  98. ?>
  99. <script>
  100. jQuery(document).ready(function() {
  101. if (jQuery('#wp-admin-bar-revslider-default').length>0 && jQuery('.rev_slider_wrapper').length>0) {
  102. var aliases = new Array();
  103. jQuery('.rev_slider_wrapper').each(function() {
  104. aliases.push(jQuery(this).data('alias'));
  105. });
  106. if(aliases.length>0)
  107. jQuery('#wp-admin-bar-revslider-default li').each(function() {
  108. var li = jQuery(this),
  109. t = jQuery.trim(li.find('.ab-item .rs-label').data('alias')); //text()
  110. if (jQuery.inArray(t,aliases)!=-1) {
  111. } else {
  112. li.remove();
  113. }
  114. });
  115. } else {
  116. jQuery('#wp-admin-bar-revslider').remove();
  117. }
  118. });
  119. </script>
  120. <?php
  121. }
  122. /**
  123. * add admin nodes
  124. * @since: 5.0.5
  125. */
  126. public static function add_admin_menu_nodes(){
  127. if(!is_super_admin() || !is_admin_bar_showing()) return;
  128. self::_add_node('<span class="rs-label">Slider Revolution</span>', false, admin_url('admin.php?page=revslider'), array('class' => 'revslider-menu' ), 'revslider'); //<span class="wp-menu-image dashicons-before dashicons-update"></span>
  129. //add all nodes of all Slider
  130. $sl = new RevSliderSlider();
  131. $sliders = $sl->getAllSliderForAdminMenu();
  132. if(!empty($sliders)){
  133. foreach($sliders as $id => $slider){
  134. self::_add_node('<span class="rs-label" data-alias="'.esc_attr($slider['alias']).'">'.esc_html($slider['title']).'</span>', 'revslider', admin_url('admin.php?page=revslider&view=slide&id=new&slider='.intval($id)), array('class' => 'revslider-sub-menu' ), esc_attr($slider['alias'])); //<span class="wp-menu-image dashicons-before dashicons-update"></span>
  135. }
  136. }
  137. }
  138. /**
  139. * add admin node
  140. * @since: 5.0.5
  141. */
  142. public static function _add_node($title, $parent = false, $href = '', $custom_meta = array(), $id = ''){
  143. global $wp_admin_bar;
  144. if(!is_super_admin() || !is_admin_bar_showing()) return;
  145. if($id == '') $id = strtolower(str_replace(' ', '-', $title));
  146. // links from the current host will open in the current window
  147. $meta = strpos( $href, site_url() ) !== false ? array() : array( 'target' => '_blank' ); // external links open in new tab/window
  148. $meta = array_merge( $meta, $custom_meta );
  149. $wp_admin_bar->add_node(array(
  150. 'parent' => $parent,
  151. 'id' => $id,
  152. 'title' => $title,
  153. 'href' => $href,
  154. 'meta' => $meta,
  155. ));
  156. }
  157. /**
  158. *
  159. * create db tables
  160. */
  161. public static function createDBTables(){
  162. if(get_option('revslider_change_database', false) || get_option('rs_tables_created', false) === false){
  163. self::createTable(RevSliderGlobals::TABLE_SLIDERS_NAME);
  164. self::createTable(RevSliderGlobals::TABLE_SLIDES_NAME);
  165. self::createTable(RevSliderGlobals::TABLE_STATIC_SLIDES_NAME);
  166. self::createTable(RevSliderGlobals::TABLE_CSS_NAME);
  167. self::createTable(RevSliderGlobals::TABLE_LAYER_ANIMS_NAME);
  168. self::createTable(RevSliderGlobals::TABLE_NAVIGATION_NAME);
  169. }
  170. update_option('rs_tables_created', true);
  171. update_option('revslider_change_database', false);
  172. self::updateTables();
  173. }
  174. public static function load_icon_fonts(){
  175. global $fa_icon_var,$pe_7s_var;
  176. if($fa_icon_var) echo "<link rel='stylesheet' property='stylesheet' id='rs-icon-set-fa-icon-css' href='" . RS_PLUGIN_URL . "public/assets/fonts/font-awesome/css/font-awesome.css' type='text/css' media='all' />";
  177. if($pe_7s_var) echo "<link rel='stylesheet' property='stylesheet' id='rs-icon-set-pe-7s-css' href='" . RS_PLUGIN_URL . "public/assets/fonts/pe-icon-7-stroke/css/pe-icon-7-stroke.css' type='text/css' media='all' />";
  178. }
  179. public static function updateTables(){
  180. $cur_ver = get_option('revslider_table_version', '1.0.0');
  181. if(get_option('revslider_change_database', false)){
  182. $cur_ver = '1.0.0';
  183. }
  184. if(version_compare($cur_ver, '1.0.6', '<')){
  185. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  186. $tableName = RevSliderGlobals::TABLE_SLIDERS_NAME;
  187. $sql = "CREATE TABLE " .self::$table_prefix.$tableName ." (
  188. id int(9) NOT NULL AUTO_INCREMENT,
  189. title tinytext NOT NULL,
  190. alias tinytext,
  191. params LONGTEXT NOT NULL,
  192. settings TEXT NULL,
  193. type VARCHAR(191) NOT NULL DEFAULT '',
  194. UNIQUE KEY id (id)
  195. );";
  196. dbDelta($sql);
  197. $tableName = RevSliderGlobals::TABLE_SLIDES_NAME;
  198. $sql = "CREATE TABLE " .self::$table_prefix.$tableName ." (
  199. id int(9) NOT NULL AUTO_INCREMENT,
  200. slider_id int(9) NOT NULL,
  201. slide_order int not NULL,
  202. params LONGTEXT NOT NULL,
  203. layers LONGTEXT NOT NULL,
  204. settings TEXT NOT NULL DEFAULT '',
  205. UNIQUE KEY id (id)
  206. );";
  207. dbDelta($sql);
  208. $tableName = RevSliderGlobals::TABLE_STATIC_SLIDES_NAME;
  209. $sql = "CREATE TABLE " .self::$table_prefix.$tableName ." (
  210. id int(9) NOT NULL AUTO_INCREMENT,
  211. slider_id int(9) NOT NULL,
  212. params LONGTEXT NOT NULL,
  213. layers LONGTEXT NOT NULL,
  214. settings TEXT NOT NULL,
  215. UNIQUE KEY id (id)
  216. );";
  217. dbDelta($sql);
  218. $tableName = RevSliderGlobals::TABLE_CSS_NAME;
  219. $sql = "CREATE TABLE " .self::$table_prefix.$tableName ." (
  220. id int(9) NOT NULL AUTO_INCREMENT,
  221. handle TEXT NOT NULL,
  222. settings LONGTEXT,
  223. hover LONGTEXT,
  224. advanced LONGTEXT,
  225. params LONGTEXT NOT NULL,
  226. UNIQUE KEY id (id)
  227. );";
  228. dbDelta($sql);
  229. $tableName = RevSliderGlobals::TABLE_LAYER_ANIMS_NAME;
  230. $sql = "CREATE TABLE " .self::$table_prefix.$tableName ." (
  231. id int(9) NOT NULL AUTO_INCREMENT,
  232. settings text NULL,
  233. UNIQUE KEY id (id)
  234. );";
  235. dbDelta($sql);
  236. update_option('revslider_table_version', '1.0.6');
  237. }
  238. }
  239. /**
  240. * create tables
  241. */
  242. public static function createTable($tableName){
  243. global $wpdb;
  244. $parseCssToDb = false;
  245. $checkForTablesOneTime = get_option('revslider_checktables', '0');
  246. if($checkForTablesOneTime == '0'){
  247. update_option('revslider_checktables', '1');
  248. if(RevSliderFunctionsWP::isDBTableExists(self::$table_prefix.RevSliderGlobals::TABLE_CSS_NAME)){ //$wpdb->tables( 'global' )
  249. //check if database is empty
  250. $result = $wpdb->get_row("SELECT COUNT( DISTINCT id ) AS NumberOfEntrys FROM ".self::$table_prefix.RevSliderGlobals::TABLE_CSS_NAME);
  251. if($result->NumberOfEntrys == 0) $parseCssToDb = true;
  252. }
  253. }
  254. if($parseCssToDb){
  255. $RevSliderOperations = new RevSliderOperations();
  256. $RevSliderOperations->importCaptionsCssContentArray();
  257. $RevSliderOperations->moveOldCaptionsCss();
  258. }
  259. if(!get_option('revslider_change_database', false)){
  260. //if table exists - don't create it.
  261. $tableRealName = self::$table_prefix.$tableName;
  262. if(RevSliderFunctionsWP::isDBTableExists($tableRealName))
  263. return(false);
  264. }
  265. switch($tableName){
  266. case RevSliderGlobals::TABLE_SLIDERS_NAME:
  267. $sql = "CREATE TABLE " .self::$table_prefix.$tableName ." (
  268. id int(9) NOT NULL AUTO_INCREMENT,
  269. title tinytext NOT NULL,
  270. alias tinytext,
  271. params LONGTEXT NOT NULL,
  272. settings TEXT NULL,
  273. type VARCHAR(191) NOT NULL DEFAULT '',
  274. UNIQUE KEY id (id)
  275. );";
  276. break;
  277. case RevSliderGlobals::TABLE_SLIDES_NAME:
  278. $sql = "CREATE TABLE " .self::$table_prefix.$tableName ." (
  279. id int(9) NOT NULL AUTO_INCREMENT,
  280. slider_id int(9) NOT NULL,
  281. slide_order int not NULL,
  282. params LONGTEXT NOT NULL,
  283. layers LONGTEXT NOT NULL,
  284. settings TEXT NOT NULL DEFAULT '',
  285. UNIQUE KEY id (id)
  286. );";
  287. break;
  288. case RevSliderGlobals::TABLE_STATIC_SLIDES_NAME:
  289. $sql = "CREATE TABLE " .self::$table_prefix.$tableName ." (
  290. id int(9) NOT NULL AUTO_INCREMENT,
  291. slider_id int(9) NOT NULL,
  292. params LONGTEXT NOT NULL,
  293. layers LONGTEXT NOT NULL,
  294. settings TEXT NOT NULL,
  295. UNIQUE KEY id (id)
  296. );";
  297. break;
  298. case RevSliderGlobals::TABLE_CSS_NAME:
  299. $sql = "CREATE TABLE " .self::$table_prefix.$tableName ." (
  300. id int(9) NOT NULL AUTO_INCREMENT,
  301. handle TEXT NOT NULL,
  302. settings LONGTEXT,
  303. hover LONGTEXT,
  304. advanced LONGTEXT,
  305. params LONGTEXT NOT NULL,
  306. UNIQUE KEY id (id)
  307. );";
  308. $parseCssToDb = true;
  309. break;
  310. case RevSliderGlobals::TABLE_LAYER_ANIMS_NAME:
  311. $sql = "CREATE TABLE " .self::$table_prefix.$tableName ." (
  312. id int(9) NOT NULL AUTO_INCREMENT,
  313. handle TEXT NOT NULL,
  314. params TEXT NOT NULL,
  315. settings TEXT NULL,
  316. UNIQUE KEY id (id)
  317. );";
  318. break;
  319. case RevSliderGlobals::TABLE_NAVIGATION_NAME:
  320. $sql = "CREATE TABLE " .self::$table_prefix.$tableName ." (
  321. id int(9) NOT NULL AUTO_INCREMENT,
  322. name VARCHAR(191) NOT NULL,
  323. handle VARCHAR(191) NOT NULL,
  324. css LONGTEXT NOT NULL,
  325. markup LONGTEXT NOT NULL,
  326. settings LONGTEXT NULL,
  327. UNIQUE KEY id (id)
  328. );";
  329. break;
  330. default:
  331. RevSliderFunctions::throwError("table: $tableName not found");
  332. break;
  333. }
  334. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  335. dbDelta($sql);
  336. if(!get_option('revslider_change_database', false)){
  337. if($parseCssToDb){
  338. $RevSliderOperations = new RevSliderOperations();
  339. $RevSliderOperations->importCaptionsCssContentArray();
  340. $RevSliderOperations->moveOldCaptionsCss();
  341. }
  342. }
  343. }
  344. public function enqueue_styles(){
  345. }
  346. /**
  347. * Change FontURL to new URL (added for chinese support since google is blocked there)
  348. * @since: 5.0
  349. */
  350. public static function modify_punch_url($url){
  351. $operations = new RevSliderOperations();
  352. $arrValues = $operations->getGeneralSettingsValues();
  353. $set_diff_font = RevSliderFunctions::getVal($arrValues, "change_font_loading",'');
  354. if($set_diff_font !== ''){
  355. return $set_diff_font;
  356. }else{
  357. return $url;
  358. }
  359. }
  360. /**
  361. * Add Meta Generator Tag in FrontEnd
  362. * @since: 5.0
  363. */
  364. public static function add_meta_generator(){
  365. global $revSliderVersion;
  366. echo apply_filters('revslider_meta_generator', '<meta name="generator" content="Powered by Slider Revolution '.$revSliderVersion.' - responsive, Mobile-Friendly Slider Plugin for WordPress with comfortable drag and drop interface." />'."\n");
  367. }
  368. /**
  369. * Add Meta Generator Tag in FrontEnd
  370. * @since: 5.4.3
  371. */
  372. public static function add_setREVStartSize(){
  373. $script = '<script type="text/javascript">';
  374. $script .= 'function setREVStartSize(e){
  375. try{ e.c=jQuery(e.c);var i=jQuery(window).width(),t=9999,r=0,n=0,l=0,f=0,s=0,h=0;
  376. if(e.responsiveLevels&&(jQuery.each(e.responsiveLevels,function(e,f){f>i&&(t=r=f,l=e),i>f&&f>r&&(r=f,n=e)}),t>r&&(l=n)),f=e.gridheight[l]||e.gridheight[0]||e.gridheight,s=e.gridwidth[l]||e.gridwidth[0]||e.gridwidth,h=i/s,h=h>1?1:h,f=Math.round(h*f),"fullscreen"==e.sliderLayout){var u=(e.c.width(),jQuery(window).height());if(void 0!=e.fullScreenOffsetContainer){var c=e.fullScreenOffsetContainer.split(",");if (c) jQuery.each(c,function(e,i){u=jQuery(i).length>0?u-jQuery(i).outerHeight(!0):u}),e.fullScreenOffset.split("%").length>1&&void 0!=e.fullScreenOffset&&e.fullScreenOffset.length>0?u-=jQuery(window).height()*parseInt(e.fullScreenOffset,0)/100:void 0!=e.fullScreenOffset&&e.fullScreenOffset.length>0&&(u-=parseInt(e.fullScreenOffset,0))}f=u}else void 0!=e.minHeight&&f<e.minHeight&&(f=e.minHeight);e.c.closest(".rev_slider_wrapper").css({height:f})
  377. }catch(d){console.log("Failure at Presize of Slider:"+d)}
  378. };';
  379. $script .= '</script>'."\n";
  380. echo apply_filters('revslider_add_setREVStartSize', $script);
  381. }
  382. /**
  383. *
  384. * adds async loading
  385. * @since: 5.0
  386. */
  387. public static function add_defer_forscript($url){
  388. if ( strpos($url, 'themepunch.enablelog.js' )===false && strpos($url, 'themepunch.revolution.min.js' )===false && strpos($url, 'themepunch.tools.min.js' )===false )
  389. return $url;
  390. else if (is_admin())
  391. return $url;
  392. else
  393. return $url."' defer='defer";
  394. }
  395. }
  396. ?>