pixedelic

pixgridder.functions.3.2.9.php

Feb 17th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 57.47 KB | None | 0 0
  1. <?php
  2.  
  3. class PixGridder{
  4.  
  5.     /**
  6.      * @since   3.2.8
  7.      *
  8.      * @var     string
  9.      */
  10.     protected $version = '3.2.8';
  11.  
  12.     /**
  13.      * @since    1.0.0
  14.      *
  15.      * @var      string
  16.      */
  17.     protected $plugin_slug = 'pixgridder';
  18.  
  19.     /**
  20.      * @since    1.0.0
  21.      *
  22.      * @var      string
  23.      */
  24.     protected $plugin_name = 'PixGridder Pro';
  25.  
  26.     /**
  27.      * @since    1.0.0
  28.      *
  29.      * @var      object
  30.      */
  31.     protected static $instance = null;
  32.  
  33.     /**
  34.      * @since    3.2.0
  35.      */
  36.     public function __construct() {
  37.         add_action( 'init', array( &$this, 'load_plugin_textdomain' ) );
  38.         add_action( 'loop_start', array( &$this, 'move_nextpage' ) );
  39.         add_action( 'admin_footer', array( &$this, 'check_version' ) );
  40.         add_action( 'wp_head', array( &$this, 'filter_content' ) );
  41.         add_action( 'wp_head', array( &$this, 'css_inline' ) );
  42.         add_action( 'admin_menu', array( &$this, 'add_menu' ) );
  43.         add_action( 'admin_enqueue_scripts', array( &$this, 'admin_styles' ) );
  44.         add_action( 'admin_enqueue_scripts', array( &$this, 'admin_scripts' ) );
  45.         add_action( 'add_meta_boxes', array( &$this, 'add_meta' ) );
  46.         add_action( 'save_post', array( &$this, 'content_save' ) );
  47.         add_action( 'save_post', array( &$this, 'disable_save' ) );
  48.         add_action( 'wp_ajax_pixgridder_height_preview', array( &$this, 'save_height_preview' ) );
  49.         add_action( 'wp_ajax_pixgridder_data_save', array( &$this, 'save_via_ajax' ) );
  50.         add_action( 'wp_ajax_css_pixgridder_ajax', array( &$this, 'compile_css_ajax' ) );
  51.         add_action( 'admin_head', array( &$this, 'remove_subpages' ) );
  52.         add_action( 'admin_head', array( &$this, 'js_vars' ) );
  53.         add_action( 'admin_head', array( &$this, 'add_tinyMCE' ) );
  54.         add_filter( 'mce_css', array( &$this, 'add_tinymce_css' ) );
  55.         add_action( 'admin_head', array( &$this, 'default_editor' ) );
  56.         add_filter( 'admin_body_class', array( &$this, 'admin_class_by_editor' ) );
  57.  
  58.         add_action( 'wp_enqueue_scripts', array( &$this, 'front_styles' ) );
  59.         add_action( 'wp_enqueue_scripts', array( &$this, 'front_scripts' ) );
  60.         add_action( 'wp_head', array( &$this, 'fx_vars' ) );
  61.         add_filter( 'body_class', array( &$this, 'body_class' ) );
  62.         add_filter( 'the_content', array( &$this, 'filter_content' ), 10 );
  63.         add_filter( 'the_content', array( &$this, 'filter_content' ), 100 );
  64.         add_filter( 'pre_set_site_transient_update_plugins', array( &$this, 'check_for_plugin_update' ));
  65.         add_filter( 'plugins_api', array( &$this, 'plugin_api_call' ), 10, 3);
  66.  
  67.     }
  68.  
  69.     /**
  70.      * Return an instance of this class.
  71.      *
  72.      * @since     1.0.0
  73.      *
  74.      * @return    object    A single instance of this class.
  75.      */
  76.     public static function get_instance() {
  77.  
  78.         // If the single instance hasn't been set, set it now.
  79.         if ( null == self::$instance ) {
  80.             self::$instance = new self;
  81.         }
  82.  
  83.         return self::$instance;
  84.     }
  85.  
  86.     /**
  87.      * Fired when the plugin is activated.
  88.      *
  89.      * @since    1.0.0
  90.      *
  91.      * @param    boolean    $network_wide    True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog.
  92.      */
  93.     public static function activate( $network_wide ) {
  94.         self::add_general();
  95.         self::compile_css();
  96.     }
  97.  
  98.     /**
  99.      * Check last version and add new options and styles if necessary.
  100.      *
  101.      * @since    3.0.0
  102.      */
  103.     public function check_version() {
  104.         if ( get_option('pixgridder_info_update')!=$this->version ) {
  105.             update_option('pixgridder_info_update',$this->version);
  106.             self::add_general();
  107.             self::compile_css();
  108.         }
  109.     }
  110.  
  111.     /**
  112.      * Fired when the plugin is uninstall.
  113.      *
  114.      * @since    1.0.0
  115.      *
  116.      * @param    boolean    $network_wide    True if WPMU superadmin uses "Network Deactivate" action, false if WPMU is disabled or plugin is deactivated on an individual blog.
  117.      */
  118.     public static function uninstall( $network_wide ) {
  119.  
  120.         global $wpdb;
  121.         $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '%pixgridder_%'");
  122.  
  123.         $results = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_content LIKE '%pixgridder%' AND post_name NOT LIKE '%autosave%' AND post_name NOT LIKE '%revision%'");
  124.         foreach ( $results as $result )
  125.         {
  126.             $id = $result->ID;
  127.             $content = $result->post_content;
  128.             $content = preg_replace('/<!--pixgridder(.+?)-->/', '', $content);
  129.             $content = preg_replace('/<!--\/pixgridder(.+?)-->/', '', $content);
  130.             $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_content = %s WHERE ID = $id", $content ) );
  131.         }
  132.     }
  133.  
  134.     /**
  135.      * Load text domain for translation.
  136.      *
  137.      * @since    3.2.2
  138.      */
  139.     public function load_plugin_textdomain() {
  140.  
  141.         $domain = $this->plugin_slug;
  142.         $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
  143.  
  144.         load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $locale . '.mo' );
  145.         load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
  146.     }
  147.  
  148.     /**
  149.      * Load tinyMCE custom functions.
  150.      *
  151.      * @since    1.0.0
  152.      */
  153.     public function add_tinyMCE() {
  154.         global $post, $pagenow;
  155.  
  156.         if ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) {
  157.             $typenow = get_post_type();
  158.             $templatenow = get_post_meta($post->ID,'_wp_page_template', true) == '' ? 'default' : get_post_meta($post->ID,'_wp_page_template', true);
  159.             $editor = get_post_meta( $post->ID, 'pixBuilderDisable', true );
  160.             $post_types_selected = get_option( 'pixgridder_post_type' ) != '' ? get_option( 'pixgridder_post_type' ) : array();
  161.             $page_template = get_option( 'pixgridder_page_template' ) != '' ? get_option( 'pixgridder_page_template' ) : array();
  162.  
  163.             $pixgridder_array_rules_ = get_option('pixgridder_array_rules_');
  164.  
  165.             if ( ($typenow != 'page' && in_array($typenow,$post_types_selected)) || ($typenow == 'page' && (in_array($templatenow,$page_template) || empty($page_template))) ) {
  166.                 $display = true;
  167.             } else {
  168.                 $display = false;          
  169.             }          
  170.             $i = 0;
  171.  
  172.             if ( isset($pixgridder_array_rules_[$i]) && $pixgridder_array_rules_[$i]!='' ) {
  173.                 while($i<count($pixgridder_array_rules_)) {
  174.                     $post_type = $pixgridder_array_rules_[$i]['post_type'];
  175.                     $meta_name = $pixgridder_array_rules_[$i]['meta_name'];
  176.                     $meta_value = $pixgridder_array_rules_[$i]['meta_value'];
  177.                     $enabled = $pixgridder_array_rules_[$i]['enabled'];
  178.                     if ( $typenow == $post_type && $enabled != 'disabled' && ( get_post_meta( $post->ID, $meta_name, true ) == $meta_value || $meta_name=='' ) ) {
  179.                         $display = true;
  180.                     } elseif  ( $typenow == $post_type && $enabled == 'disabled' && ( get_post_meta( $post->ID, $meta_name, true ) == $meta_value || $meta_name=='' ) ) {
  181.                         $display = false;
  182.                     }
  183.                     $i++;
  184.                 }
  185.             }
  186.  
  187.             if ( $editor == 'on' ) {
  188.                 $display = false;
  189.             }
  190.            
  191.             if ( ! current_user_can('edit_posts', $post->ID) && ! current_user_can('edit_pages', $post->ID) )
  192.                 return;
  193.             if ( get_user_option('rich_editing') == 'true' && ( $display == true ) ) {
  194.                 add_filter('mce_external_plugins', 'add_pixgridder_js' );
  195.             }
  196.  
  197.             function add_pixgridder_js($plugin_array) {
  198.                 $plugin_array['pixgridder'] = PIXGRIDDER_URL.'scripts/pixgridder_tinyMCE.js';
  199.                 return $plugin_array;
  200.             }      
  201.  
  202.             function tinymce_settings($settings) {
  203.                 //$settings['extended_valid_elements'] = "span[!class]";
  204.                 $settings['theme_advanced_resizing'] = false;
  205.                 return $settings;
  206.             }
  207.             add_filter('tiny_mce_before_init','tinymce_settings');
  208.            
  209.             function tinymce_autoresize($settings) {
  210.                 $settings['wp_autoresize_on'] = false;
  211.                 return $settings;
  212.             }
  213.             if ( $display )
  214.                 add_filter('tiny_mce_before_init','tinymce_autoresize');
  215.         }
  216.     }
  217.  
  218.     /**
  219.      * Register and enqueue front-end scripts.
  220.      *
  221.      * @since    1.0.0
  222.      */
  223.     public function front_scripts() {
  224.         wp_register_script( 'pix-modernizr', PIXGRIDDER_URL.'scripts/modernizr.pix.js', array(), '2.6.2' );
  225.         //wp_register_script( 'pix-stellar', PIXGRIDDER_URL.'scripts/jquery.stellar.min.js', array('jquery'), '0.6.2' );
  226.         wp_enqueue_script( $this->plugin_slug . '-fx', PIXGRIDDER_URL.'scripts/fx.js', array('pix-modernizr','jquery'/*,'pix-stellar'*/));
  227.     }
  228.  
  229.     /**
  230.      * Register and enqueue front-end style sheets.
  231.      *
  232.      * @since    3.1.0
  233.      */
  234.     public function front_styles() {
  235.         global $blog_id;
  236.  
  237.         if ( get_option('pixgridder_load_css_inline')=='true' )
  238.             return;
  239.  
  240.         if ( is_multisite() && $blog_id > 1 ) {
  241.             $blog_ID = '-'.$blog_id;
  242.         } else {
  243.             $blog_ID = '';
  244.         }
  245.         $theme_style = get_stylesheet_directory().'/front-gridder'.$blog_ID.'.css';
  246.         if (file_exists($theme_style)) {
  247.             wp_enqueue_style( $this->plugin_slug, get_stylesheet_directory_uri().'/front-gridder'.$blog_ID.'.css', array(), $this->version );
  248.         } else {
  249.             if ( is_multisite() && $blog_id > 1 ) {
  250.                 $upload_dir = wp_upload_dir();
  251.                 $dir = $upload_dir['baseurl'] .'/pixgridder/';
  252.                 $css_file = $dir . '/front-gridder.css';
  253.             } else {
  254.                 $css_file = PIXGRIDDER_URL.'css/front-gridder.css';
  255.             }
  256.             wp_enqueue_style( $this->plugin_slug, $css_file, array(), $this->version );
  257.         }
  258.     }
  259.  
  260.     /**
  261.      * Register and enqueue admin-specific style sheet.
  262.      *
  263.      * @since    1.0.0
  264.      */
  265.     public function admin_styles() {
  266.         global $pagenow;
  267.         if ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) {
  268.             wp_enqueue_style( 'wp-jquery-ui-dialog' );
  269.             wp_enqueue_style( 'farbtastic' );
  270.             wp_enqueue_style( $this->plugin_slug .'-fontello', PIXGRIDDER_URL.'css/fontello.css', array(), $this->version );
  271.             wp_enqueue_style( $this->plugin_slug .'-open-sans', PIXGRIDDER_URL.'css/open_sans.css', array(), $this->version );
  272.             wp_enqueue_style( $this->plugin_slug, PIXGRIDDER_URL.'css/gridder.css', array(), $this->version );
  273.         } else if ('admin.php' == $pagenow && isset($_GET['page']) && $_GET['page']=='pixgridder_admin') {
  274.             wp_enqueue_style ( 'wp-jquery-ui-dialog' );
  275.             wp_enqueue_style( $this->plugin_slug .'-codemirror', PIXGRIDDER_URL.'css/codemirror.css', array(), $this->version );
  276.             wp_enqueue_style( $this->plugin_slug .'-codemirror-skin', PIXGRIDDER_URL.'css/codemirror-skin.css', array(), $this->version );
  277.             wp_enqueue_style( $this->plugin_slug .'-fontello', PIXGRIDDER_URL.'css/fontello.css', array(), $this->version );
  278.             wp_enqueue_style( $this->plugin_slug .'-open-sans', PIXGRIDDER_URL.'css/open_sans.css', array(), $this->version );
  279.             wp_enqueue_style( $this->plugin_slug .'-admin', PIXGRIDDER_URL.'css/admin.css', array(), $this->version );
  280.         }
  281.     }
  282.  
  283.     /**
  284.      * Register and enqueue admin-specific scripts.
  285.      *
  286.      * @since    3.2.5
  287.      */
  288.     public function admin_scripts() {
  289.         global $pagenow;
  290.         if ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) {
  291.             wp_enqueue_script( 'farbtastic' );
  292.             wp_enqueue_script( $this->plugin_slug . '-modernizr', PIXGRIDDER_URL.'scripts/modernizr.pix.js', array(), '2.6.2' );
  293.             wp_enqueue_script( $this->plugin_slug . '-ui-touch-punch', PIXGRIDDER_URL.'scripts/jquery.ui.touch-punch.min.js', array('jquery-ui-mouse'), '0.2.2', false );
  294.             wp_enqueue_script( $this->plugin_slug . '-livequery', PIXGRIDDER_URL.'scripts/jquery.livequery.js', array('jquery'), '1.1.1', false );
  295.             wp_enqueue_script( $this->plugin_slug, PIXGRIDDER_URL.'scripts/gridder.js', array($this->plugin_slug.'-modernizr','jquery','farbtastic','jquery-ui-core',$this->plugin_slug.'-ui-touch-punch','jquery-ui-sortable',$this->plugin_slug.'-livequery','jquery-ui-resizable','jquery-ui-dialog','jquery-ui-autocomplete') );
  296.         } else if ('admin.php' == $pagenow && isset($_GET['page']) && $_GET['page']=='pixgridder_admin') {
  297.             wp_enqueue_script( $this->plugin_slug . '-modernizr', PIXGRIDDER_URL.'scripts/modernizr.pix.js', array(), '2.6.2' );
  298.             wp_enqueue_script( $this->plugin_slug . '-ui-touch-punch', PIXGRIDDER_URL.'scripts/jquery.ui.touch-punch.min.js', array('jquery-ui-mouse'), '0.2.2', false );
  299.             //wp_enqueue_script( $this->plugin_slug . '-ui-slider', PIXGRIDDER_URL.'scripts/jquery.ui.slider.js', array('jquery-ui-core','jquery-ui-mouse','jquery-ui-widget'), '1.11.2', false );
  300.             wp_enqueue_script( $this->plugin_slug . '-codemirror', PIXGRIDDER_URL.'scripts/codemirror.js', array('jquery'), '3.14', false );
  301.             wp_enqueue_script( $this->plugin_slug . '-css-mode', PIXGRIDDER_URL.'scripts/css.js', array($this->plugin_slug.'-codemirror'), '3.14', false );
  302.             wp_enqueue_script( $this->plugin_slug . '-livequery', PIXGRIDDER_URL.'scripts/jquery.livequery.js', array('jquery'), '1.1.1', false );
  303.             wp_enqueue_script( $this->plugin_slug . '-easing', PIXGRIDDER_URL.'scripts/jquery.easing.min.js', array('jquery'), '1.3', false );
  304.             wp_enqueue_script( $this->plugin_slug . '-admin', PIXGRIDDER_URL.'scripts/admin.js', array($this->plugin_slug.'-modernizr','jquery','jquery-ui-core',$this->plugin_slug.'-ui-touch-punch','jquery-ui-sortable','jquery-ui-draggable','jquery-ui-droppable','jquery-ui-slider',$this->plugin_slug.'-css-mode',$this->plugin_slug.'-livequery',$this->plugin_slug.'-easing','jquery-ui-dialog'));
  305.         }
  306.     }
  307.  
  308.     /**
  309.      * Set the defalt tinyMCE editor.
  310.      *
  311.      * @since    1.0.0
  312.      */
  313.     public function default_editor() {
  314.         global $post, $pagenow;
  315.  
  316.         if ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) {
  317.             $typenow = get_post_type();
  318.             $templatenow = get_post_meta($post->ID,'_wp_page_template', true) == '' ? 'default' : get_post_meta($post->ID,'_wp_page_template', true);
  319.             $editor = get_post_meta( $post->ID, 'pixBuilderDisable', true );
  320.             $post_types_selected = get_option( 'pixgridder_post_type' ) != '' ? get_option( 'pixgridder_post_type' ) : array();
  321.             $page_template = get_option( 'pixgridder_page_template' ) != '' ? get_option( 'pixgridder_page_template' ) : array();
  322.  
  323.             $pixgridder_array_rules_ = get_option('pixgridder_array_rules_');
  324.  
  325.             if ( ($typenow != 'page' && in_array($typenow,$post_types_selected)) || ($typenow == 'page' && (in_array($templatenow,$page_template) || empty($page_template))) ) {
  326.                 $display = true;
  327.             } else {
  328.                 $display = false;          
  329.             }          
  330.             $i = 0;
  331.  
  332.             if ( isset($pixgridder_array_rules_[$i]) && $pixgridder_array_rules_[$i]!='' ) {
  333.                 while($i<count($pixgridder_array_rules_)) {
  334.                     $post_type = $pixgridder_array_rules_[$i]['post_type'];
  335.                     $meta_name = $pixgridder_array_rules_[$i]['meta_name'];
  336.                     $meta_value = $pixgridder_array_rules_[$i]['meta_value'];
  337.                     $enabled = $pixgridder_array_rules_[$i]['enabled'];
  338.                     if ( $typenow == $post_type && $enabled != 'disabled' && ( get_post_meta( $post->ID, $meta_name, true ) == $meta_value || $meta_name=='' ) ) {
  339.                         $display = true;
  340.                     } elseif  ( $typenow == $post_type && $enabled == 'disabled' && ( get_post_meta( $post->ID, $meta_name, true ) == $meta_value || $meta_name=='' ) ) {
  341.                         $display = false;
  342.                     }
  343.                     $i++;
  344.                 }
  345.             }
  346.            
  347.             if ( $editor == 'on' ) {
  348.                 $display = false;
  349.             }
  350.  
  351.             if ( $display == true ) {
  352.                 add_filter( 'wp_default_editor', create_function('', 'return "tinymce";') );
  353.             }
  354.         }
  355.     }
  356.  
  357.  
  358.     /**
  359.      * Add the class "pixgridder" to the front-end body
  360.      *
  361.      * @since    1.0.0
  362.      */
  363.     public function body_class($classes) {
  364.         $classes[] = 'pixgridder';
  365.         if ( get_option('pixgridder_fx')!='none' && get_option('pixgridder_fx')!='' ) {
  366.             $classes[] = 'pix-scroll-load';
  367.         }
  368.         if ( get_option('pixgridder_fx')=='available' ) {
  369.             $classes[] = 'available';
  370.         }
  371.         return $classes;
  372.     }
  373.  
  374.  
  375.     /**
  376.      * Change the admin body class if the grid builder is activated for that particular post/page.
  377.      *
  378.      * @since    3.2.5
  379.      *
  380.      */
  381.     public function admin_class_by_editor($classes) {
  382.         global $pagenow, $post;
  383.  
  384.         if ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) {
  385.  
  386.             $typenow = get_post_type();
  387.             $templatenow = get_post_meta($post->ID,'_wp_page_template', true) == '' ? 'default' : get_post_meta($post->ID,'_wp_page_template', true);
  388.             $editor = get_post_meta( $post->ID, 'pixBuilderDisable', true );
  389.             $post_types_selected = get_option( 'pixgridder_post_type' );
  390.             $page_template = get_option( 'pixgridder_page_template' );
  391.  
  392.             $pixgridder_array_rules_ = get_option('pixgridder_array_rules_');
  393.  
  394.             if ( ($typenow != 'page' && in_array($typenow,$post_types_selected)) || ($typenow == 'page' && (empty($page_template) || in_array($templatenow,$page_template))) ) {
  395.                 $display = true;
  396.             } else {
  397.                 $display = false;          
  398.             }          
  399.             $i = 0;
  400.  
  401.             if ( isset($pixgridder_array_rules_[$i]) && $pixgridder_array_rules_[$i]!='' ) {
  402.                 while($i<count($pixgridder_array_rules_)) {
  403.                     $post_type = $pixgridder_array_rules_[$i]['post_type'];
  404.                     $meta_name = $pixgridder_array_rules_[$i]['meta_name'];
  405.                     $meta_value = $pixgridder_array_rules_[$i]['meta_value'];
  406.                     $enabled = $pixgridder_array_rules_[$i]['enabled'];
  407.                     if ( $typenow == $post_type && $enabled != 'disabled' && ( get_post_meta( $post->ID, $meta_name, true ) == $meta_value || $meta_name=='' ) ) {
  408.                         $display = true;
  409.                     } elseif  ( $typenow == $post_type && $enabled == 'disabled' && ( get_post_meta( $post->ID, $meta_name, true ) == $meta_value || $meta_name=='' ) ) {
  410.                         $display = false;
  411.                     }
  412.                     $i++;
  413.                 }
  414.             }
  415.            
  416.             if ( $editor == 'on' ) {
  417.                 $display = false;
  418.             }
  419.  
  420.             if ( $display==true ) {
  421.                 $classes .= ' pix_body_builder';
  422.             }
  423.  
  424.             return $classes;
  425.         }
  426.     }
  427.  
  428.     /**
  429.      * Add the metaboxes: the grid builder and its tabs to switch between builder and preview.
  430.      *
  431.      * @since    1.0.0
  432.      */
  433.     public function add_meta() {
  434.         global $post;
  435.  
  436.         if ( !$post )
  437.             return;
  438.  
  439.         $typenow = get_post_type();
  440.         $templatenow = get_post_meta($post->ID,'_wp_page_template', true) == '' ? 'default' : get_post_meta($post->ID,'_wp_page_template', true);
  441.         $editor = get_post_meta( $post->ID, 'pixBuilderDisable', true );
  442.         $post_types_selected = get_option( 'pixgridder_post_type' ) != '' ? get_option( 'pixgridder_post_type' ) : array();
  443.         $page_template = get_option( 'pixgridder_page_template' ) != '' ? get_option( 'pixgridder_page_template' ) : array();
  444.  
  445.         $pixgridder_array_rules_ = get_option('pixgridder_array_rules_');
  446.  
  447.         if ( ($typenow != 'page' && in_array($typenow,$post_types_selected)) || ($typenow == 'page' && (in_array($templatenow,$page_template) || empty($page_template))) ) {
  448.             $display = true;
  449.         } else {
  450.             $display = false;          
  451.         }          
  452.         $i = 0;
  453.  
  454.         if ( isset($pixgridder_array_rules_[$i]) && $pixgridder_array_rules_[$i]!='' ) {
  455.             while($i<count($pixgridder_array_rules_)) {
  456.                 $post_type = $pixgridder_array_rules_[$i]['post_type'];
  457.                 $meta_name = $pixgridder_array_rules_[$i]['meta_name'];
  458.                 $meta_value = $pixgridder_array_rules_[$i]['meta_value'];
  459.                 $enabled = $pixgridder_array_rules_[$i]['enabled'];
  460.                 if ( $typenow == $post_type && $enabled != 'disabled' && ( get_post_meta( $post->ID, $meta_name, true ) == $meta_value || $meta_name=='' ) ) {
  461.                     $display = true;
  462.                 } elseif  ( $typenow == $post_type && $enabled == 'disabled' && ( get_post_meta( $post->ID, $meta_name, true ) == $meta_value || $meta_name=='' ) ) {
  463.                     $display = false;
  464.                 }
  465.                 $i++;
  466.             }
  467.         }
  468.  
  469.         $post_types = get_post_types();
  470.         foreach ( $post_types as $post_type ) {
  471.             if ( $display == true ) {
  472.                 add_meta_box( 'pixgridder_disable', 'PixGridder options', 'pixgridder_disable', $post_type, 'normal', 'high' );
  473.             }
  474.         }
  475.  
  476.         if ( $editor == 'on' ) {
  477.             $display = false;
  478.         }
  479.  
  480.         $post_types = get_post_types();
  481.         foreach ( $post_types as $post_type ) {
  482.             if ( $display == true ) {
  483.                 add_meta_box( 'pixgridder_builder', 'PixGridder', 'pixgridder_builder', $post_type, 'normal', 'low' );
  484.                 add_meta_box( 'pixgridder_content', 'PixGridder Content', 'pixgridder_content', $post_type, 'normal' );
  485.             }
  486.         }
  487.  
  488.         function pixgridder_content( $post, $display ) {
  489.             $values = get_post_custom( $post->ID );
  490.             $pixgridder_content = isset( $values['pixgridder_content'] ) ? esc_attr( $values['pixgridder_content'][0] ) : '';
  491.             wp_nonce_field( 'pixgridder_content_nonce', 'pixgridder_content_nonce' );
  492.             ?>
  493.             <div class="pix_meta_boxes">
  494.                 <p>
  495.                     <label for="pixBuilderTxtArea"><?php _e('Content','pixgridder'); ?></label><br>
  496.                     <div class="field_wrap"><textarea name="pixgridder_content" id="pixBuilderTxtArea" ><?php echo $pixgridder_content; ?></textarea></div>
  497.                 </p>
  498.                 <div class="clear"></div>
  499.                
  500.          
  501.             </div><!-- .pix_meta_boxes -->
  502.             <?php  
  503.         }
  504.  
  505.         function pixgridder_builder( $post, $display ) {
  506.             require_once( PIXGRIDDER_PATH.'lib/pixgridder-builder.php' );
  507.         }
  508.  
  509.         function pixgridder_disable( $post, $display ) {
  510.             $values = get_post_custom( $post->ID );
  511.             $pixBuilderWasHere = isset( $values['pixBuilderWasHere'] ) ? esc_attr( $values['pixBuilderWasHere'][0] ) : 'off';
  512.             $pixBuilderDisable = isset( $values['pixBuilderDisable'] ) ? esc_attr( $values['pixBuilderDisable'][0] ) : 'off';
  513.             $pixBuilderRemove = isset( $values['pixBuilderRemove'] ) ? esc_attr( $values['pixBuilderRemove'][0] ) : 'off';
  514.             wp_nonce_field( 'pixgridder_disable_nonce', 'pixgridder_disable_nonce' );
  515.             ?>
  516.             <div class="pix_meta_boxes">
  517.                 <input type="hidden" name="pixBuilderWasHere" id="pixBuilderWasHere" value="true"></label>
  518.                 <p>
  519.                     <label for="pixBuilderDisable"><?php _e('Disable the grid builder','pixgridder'); ?>
  520.                     <input type="checkbox" name="pixBuilderDisable" id="pixBuilderDisable" <?php checked( $pixBuilderDisable, 'on' ); ?>></label>
  521.                 </p>
  522.                 <p>
  523.                     <label for="pixBuilderRemove"><?php _e('Remove any trace of PixGridder from this page','pixgridder'); ?>
  524.                     <input type="checkbox" name="pixBuilderRemove" id="pixBuilderRemove"></label>
  525.                 </p>
  526.                 <p>
  527.                     <small>Icons are from <a href="http://fontello.com/" target="_blank">Fontello.com</a> (licenses available there for all the sets)</small>
  528.                 </p>
  529.             </div><!-- .pix_meta_boxes -->
  530.             <?php
  531.         }
  532.  
  533.     }
  534.  
  535.     /**
  536.      * Save the data sent thorugh metaboxes.
  537.      *
  538.      * @since    1.0.0
  539.      */
  540.     public function content_save( $post_id ) {
  541.         if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
  542.  
  543.         if( !isset( $_POST['pixgridder_content_nonce'] ) || !wp_verify_nonce( $_POST['pixgridder_content_nonce'], 'pixgridder_content_nonce' ) ) return;
  544.  
  545.         if( !current_user_can( 'edit_post', $post_id ) ) return;
  546.        
  547.         if( isset( $_POST['pixgridder_content'] ) )
  548.             update_post_meta( $post_id, 'pixgridder_content', esc_attr( $_POST['pixgridder_content'] ) );
  549.            
  550.     }
  551.     public function disable_save( $post_id ) {
  552.         if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
  553.  
  554.         if( !isset( $_POST['pixgridder_disable_nonce'] ) || !wp_verify_nonce( $_POST['pixgridder_disable_nonce'], 'pixgridder_disable_nonce' ) ) return;
  555.  
  556.         if( !current_user_can( 'edit_post', $post_id ) ) return;
  557.        
  558.         if( isset( $_POST['pixBuilderWasHere'] ) )
  559.             update_post_meta( $post_id, 'pixBuilderWasHere', esc_attr( $_POST['pixBuilderWasHere'] ) );
  560.  
  561.         $chkedit = ( isset( $_POST['pixBuilderDisable'] ) && $_POST['pixBuilderDisable'] ) ? 'on' : 'off';
  562.         update_post_meta( $post_id, 'pixBuilderDisable', $chkedit );
  563.        
  564.         if ( isset( $_POST['pixBuilderRemove'] ) && $_POST['pixBuilderRemove'] ) {
  565.             global $wpdb;
  566.             $results = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE ID = $post_id");
  567.             foreach ( $results as $result ) {
  568.                 $content = $result->post_content;
  569.                 $content = preg_replace('/<!--pixgridder(.+?)-->/', '', $content);
  570.                 $content = preg_replace('/<!--\/pixgridder(.+?)-->/', '', $content);
  571.                 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_content = %s WHERE ID = $post_id", $content ) );
  572.             }
  573.         }
  574.     }
  575.  
  576.     /**
  577.      * Save via AJAX the height of the preview wrap.
  578.      *
  579.      * @since    1.0.0
  580.      */
  581.     public function save_height_preview() {
  582.         update_option('pixgridder_height_preview',$_POST['height']);
  583.         die();
  584.     }
  585.  
  586.     /**
  587.      * Check if PixGridder is active inside the loop
  588.      *
  589.      * @since    3.0.0
  590.      *
  591.      */
  592.     public function check_active($id) {
  593.  
  594.         $typenow = get_post_type($id);
  595.         $templatenow = get_post_meta($id,'_wp_page_template', true) == '' ? 'default' : get_post_meta($id,'_wp_page_template', true);
  596.         $editor = get_post_meta($id, 'pixBuilderDisable', true );
  597.         $washere = get_post_meta($id, 'pixBuilderWasHere', true );
  598.         $post_types_selected = get_option( 'pixgridder_post_type' );
  599.         $page_template = get_option( 'pixgridder_page_template' );
  600.  
  601.         $pixgridder_array_rules_ = get_option('pixgridder_array_rules_');
  602.  
  603.         if ( ($typenow != 'page' && in_array($typenow,$post_types_selected)) || ($typenow == 'page' && (empty($page_template) || in_array($templatenow,$page_template))) ) {
  604.             $display = true;
  605.         } else {
  606.             $display = false;          
  607.         }
  608.  
  609.         $i = 0;
  610.  
  611.         if ( isset($pixgridder_array_rules_[$i]) && $pixgridder_array_rules_[$i]!='' ) {
  612.             while($i<count($pixgridder_array_rules_)) {
  613.                 $post_type = $pixgridder_array_rules_[$i]['post_type'];
  614.                 $meta_name = $pixgridder_array_rules_[$i]['meta_name'];
  615.                 $meta_value = $pixgridder_array_rules_[$i]['meta_value'];
  616.                 $enabled = $pixgridder_array_rules_[$i]['enabled'];
  617.                 if ( $typenow == $post_type && $enabled != 'disabled' && ( get_post_meta( $id, $meta_name, true ) == $meta_value || $meta_name == '') ) {
  618.                     $display = true;
  619.                 }
  620.                 $i++;
  621.             }
  622.         }
  623.  
  624.         if ( !isset($washere) || $washere=='' || $washere==false ) $display = false;
  625.  
  626.         if ( $display == true ) {
  627.  
  628.             $active_gridder = true;
  629.  
  630.         } else {
  631.  
  632.             $active_gridder = false;
  633.  
  634.         }
  635.  
  636.         return $active_gridder;
  637.     }
  638.  
  639.     /**
  640.      * Replace the html comments in the post content to create the grid
  641.      *
  642.      * @since    3.2.9
  643.      *
  644.      */
  645.     public function filter_content($content) {
  646.  
  647.         global $post, $active_gridder;
  648.  
  649.         if ( !$post )
  650.             return $content;
  651.  
  652.         if (strpos($content,'<!--pixgridder:') === false)
  653.             return $content;
  654.  
  655.         $typenow = apply_filters('pixgridder_filter_content_post_type', get_post_type());
  656.         $post_id = apply_filters('pixgridder_filter_content_post_id', $post->ID);
  657.  
  658.         $templatenow = get_post_meta($post_id,'_wp_page_template', true) == '' ? 'default' : get_post_meta($post_id,'_wp_page_template', true);
  659.         $editor = get_post_meta( $post_id, 'pixBuilderDisable', true );
  660.         $washere = get_post_meta( $post_id, 'pixBuilderWasHere', true );
  661.         $post_types_selected = get_option( 'pixgridder_post_type' );
  662.         $page_template = get_option( 'pixgridder_page_template' );
  663.  
  664.         $pixgridder_array_rules_ = get_option('pixgridder_array_rules_');
  665.         $row_close = stripslashes(get_option('pixgridder_row_close'));
  666.         $column_close = stripslashes(get_option('pixgridder_column_close'));
  667.  
  668.         if ( ($typenow != 'page' && in_array($typenow,$post_types_selected)) || ($typenow == 'page' && (empty($page_template) || in_array($templatenow,$page_template))) ) {
  669.             $display = true;
  670.         } else {
  671.             $display = false;          
  672.         }
  673.  
  674.         $i = 0;
  675.  
  676.         if ( isset($pixgridder_array_rules_[$i]) && $pixgridder_array_rules_[$i]!='' ) {
  677.             while($i<count($pixgridder_array_rules_)) {
  678.                 $post_type = $pixgridder_array_rules_[$i]['post_type'];
  679.                 $meta_name = $pixgridder_array_rules_[$i]['meta_name'];
  680.                 $meta_value = $pixgridder_array_rules_[$i]['meta_value'];
  681.                 $enabled = $pixgridder_array_rules_[$i]['enabled'];
  682.                 $start_row = stripslashes($pixgridder_array_rules_[$i]['start_row']);
  683.                 $end_row = stripslashes($pixgridder_array_rules_[$i]['end_row']);
  684.                 $start_column = stripslashes($pixgridder_array_rules_[$i]['start_column']);
  685.                 $end_column = stripslashes($pixgridder_array_rules_[$i]['end_column']);
  686.                 if ( $typenow == $post_type && $enabled != 'disabled' && ( get_post_meta( $post_id, $meta_name, true ) == $meta_value || $meta_name == '') && $start_row != 'default' ) {
  687.                     $display = true;
  688.                 }
  689.                 if ( $typenow == $post_type && $enabled != 'disabled' && ( get_post_meta( $post_id, $meta_name, true ) == $meta_value || $meta_name == '') && $end_row != 'default' ) {
  690.                     $display = true;
  691.                     $row_close = $end_row;
  692.                     }
  693.                 if ( $typenow == $post_type && $enabled != 'disabled' && ( get_post_meta( $post_id, $meta_name, true ) == $meta_value || $meta_name == '') && $start_column != 'default' ) {
  694.                     $display = true;
  695.                 }
  696.                 if ( $typenow == $post_type && $enabled != 'disabled' && ( get_post_meta( $post_id, $meta_name, true ) == $meta_value || $meta_name == '') && $end_column != 'default' ) {
  697.                     $display = true;
  698.                 }
  699.                 $i++;
  700.             }
  701.         }
  702.  
  703.         if ( !isset($washere) ) $display = false;
  704.  
  705.         if ( $display == true ) {
  706.  
  707.             $active_gridder = true;
  708.  
  709.             require_once( ABSPATH . WPINC . '/class-oembed.php' );
  710.             $oembed = _wp_oembed_get_object();
  711.             $providers = $oembed->providers;
  712.  
  713.             if ( !function_exists('pixgridder_match_oembed') ) {
  714.                 function pixgridder_match_oembed($matches) {
  715.                     $var = preg_replace('/<p>/', '', $matches[0]);
  716.                     $var = preg_replace('/<\/p>/', '', $var);
  717.                     global $wp_embed;
  718.                     return $wp_embed->autoembed($var);
  719.                 }
  720.             }
  721.  
  722.             foreach ($providers as $key => $value) {
  723.                 if(substr($key,0,1) == '#') {
  724.                     $content = preg_replace_callback(
  725.                         "$key",
  726.                         'pixgridder_match_oembed',
  727.                         $content
  728.                     );
  729.                 }
  730.             }
  731.  
  732.             if ( !function_exists('pixgridder_json_to_css') ) {
  733.                 function pixgridder_json_to_css($matches) {
  734.                     $string = preg_replace('/\{/', '', $matches[1]);
  735.                     $string = preg_replace('/\}/', ';', $string);
  736.                     $string = preg_replace('/\',/', ';', $string);
  737.                     $string = preg_replace('/\'/', '', $string);
  738.                     $string = preg_replace('/border-bottom-color:\#(.+?);/','border-bottom:1px solid #$1;',$string);
  739.                     $string = preg_replace('/border-top-color:\#(.+?);/','border-top:1px solid #$1;',$string);
  740.                     return 'style="'.$string.'"';
  741.                 }
  742.             }
  743.  
  744.             if ( !function_exists('pixgridder_data_children') ) {
  745.                 function pixgridder_data_children($matches) {
  746.                     $string = preg_replace('/<!--pixgridder:column\[(.?[^\]\s]+)\]-->/', '<!--pixgridder:column[$1] data-extrachild['.$matches[1].']-->', $matches[2]);
  747.                     return 'data-extra['.$matches[1].']'.$string.'<!--/pixgridder:row';
  748.                 }
  749.             }
  750.  
  751.             $blocks = preg_split('/<(|\/)pre/', $content);
  752.             $content = ""; //reuse as our buffer
  753.             foreach($blocks as $i => $block) {
  754.                 if($i % 2 == 1) {
  755.                     $content .= "\n<pre$block</pre\n";
  756.                 } else {
  757.                     $utf_filter = apply_filters('pixgridder_utf_filter', false);
  758.                     if ( isset($utf_filter) && $utf_filter===true) {
  759.                         $block = utf8_decode($block);
  760.                     }
  761.                     $block = preg_replace('/\s+/', ' ', $block);
  762.                     if ( isset($utf_filter) && $utf_filter===true) {
  763.                         $block = utf8_encode($block);
  764.                     }
  765.                     $content .= $block;
  766.                 }
  767.             }
  768.  
  769.             $content = preg_replace('/<!--pixgridder-nextpage-->/', '', $content);
  770.             $content = preg_replace('/<!--pixgridder:column\[(.?[^\]\s]+)\]--><br\W*?\/>/', '<!--pixgridder:column[$1]-->', $content);
  771.             $content = preg_replace('/<!--pixgridder:column\[(.?[^\]\s]+)\]-->[\n\r]/', '<!--pixgridder:column[$1]-->', $content);
  772.             $content = preg_replace('/<!--pixgridder:column\[(.?[^\]\s]+)\]--><!--\/pixgridder:column\[(.?[^\]\s]+)\]-->/', '', $content);
  773.             $content = preg_replace('/<!--pixgridder:row\[(.?[^\]\s]+)\]--><!--\/pixgridder:row\[(.?[^\]\s]+)\]-->/', '', $content);
  774.             $content = preg_replace('/<!--pixgridder:column\[(.?[^\]\s]+)\]--><!--\/pixgridder:column(.+?)-->/', '', $content);
  775.             $content = preg_replace('/<!--pixgridder:column\[(.?[^\]\s]+)\]--><!--\/pixgridder:column(.+?)-->/', '', $content);
  776.             $content = preg_replace('/<!--pixgridder:row\[(.?[^\]\s]+)\]--><!--\/pixgridder:row(.+?)-->/', '', $content);
  777.             $content = preg_replace('/<p><!--pixgridder:(.+?)-->(?!<!--)/', '<!--pixgridder:$1--><p>', $content);
  778.             $content = preg_replace('/<p><!--\/pixgridder:(.+?)-->(?!<!--)/', '<!--/pixgridder:$1--><p>', $content);
  779.             $content = preg_replace('/<p><!--pixgridder:(.+?)--><\/p>/', '<!--pixgridder:$1-->', $content);
  780.             $content = preg_replace('/<p><!--\/pixgridder:(.+?)--><\/p>/', '<!--/pixgridder:$1-->', $content);
  781.             $content = preg_replace('/<!--\/pixgridder:(.+?)--><p><\/p>/', '<!--/pixgridder:$1-->', $content);
  782.             $content = preg_replace_callback('/data-extra\[(.+?)\](.*?)<!--\/pixgridder:row/s', 'pixgridder_data_children', $content);
  783.             $content = preg_replace_callback('/<!--pixgridder:row\[cols=(.*?)\](.*?)-->/', array($this, 'pixgridder_preg_rows'), $content);
  784.             $content = preg_replace_callback('/<!--pixgridder:column\[col=(.*?)\](.*?)-->/', array($this, 'pixgridder_preg_cols'), $content);
  785.             $content = preg_replace('/data-id\[(.+?)\]/', 'id="$1"', $content);
  786.             $content = preg_replace('/data-class\[(.+?)\]/', 'class="$1"', $content);
  787.             $content = preg_replace_callback('/data-style\[(.+?)\]/', 'pixgridder_json_to_css', $content);
  788.             $content = preg_replace('/data-extra\[(.+?)\]/', 'data-extra="$1"', $content);
  789.             $content = preg_replace('/data-extrachild\[(.+?)\]/', 'data-extrachild="$1"', $content);
  790.             //$content = preg_replace('/data-stellar-background-ratio\[(.+?)\]/', 'data-stellar-background-ratio="$1"', $content);
  791.             $content = preg_replace('/data-stellar-background-ratio\[(.+?)\]/', 'data-pix-ratio="$1"', $content);
  792.             $content = preg_replace('/data-small\[(.+?)\]/', 'data-small="$1"', $content);
  793.             $content = preg_replace('/data-medium\[(.+?)\]/', 'data-medium="$1"', $content);
  794.             $content = preg_replace('/<!--\/pixgridder:row\[cols=(.+?)\]-->/', $row_close, $content);
  795.             $content = preg_replace('/<!--\/pixgridder:column\[col=(.+?)\]-->/', $column_close, $content);
  796.             $content = preg_replace('/<p><\/p>/', '', $content);
  797.  
  798.         } else {
  799.  
  800.             $active_gridder = false;
  801.  
  802.             $content = preg_replace('/<!--pixgridder(.+?)-->/', '', $content);
  803.             $content = preg_replace('/<!--\/pixgridder(.+?)-->/', '', $content);
  804.  
  805.         }
  806.  
  807.         return $content;
  808.     }
  809.  
  810.     /**
  811.      * Fix for <!--nextpage--> position
  812.      *
  813.      * @since    3.1.0
  814.      *
  815.      */
  816.     function move_nextpage(){
  817.  
  818.         global $post;
  819.  
  820.         if ( !$post )
  821.             return;
  822.  
  823.         $content = $post->post_content;
  824.  
  825.         if ( false !== strpos( $content, '<!--nextpage-->' ) && false === strpos( $content, '<!--pixgridder-nextpage-->' ) ) {
  826.             $content = '<!--pixgridder-nextpage-->'.$content;
  827.             $content = preg_replace( '/[\n\r]<!--nextpage-->[\n\r]/', '<!--nextpage-->', $content );
  828.             $content = preg_replace( '/[\n\r]<!--nextpage-->/', '<!--nextpage-->', $content );
  829.             $content = preg_replace( '/<!--nextpage-->[\n\r]/', '<!--nextpage-->', $content );
  830.             $content = preg_replace('/<!--pixgridder:column\[(.?[^\]\s]+)\]-->(.+?)<!--nextpage-->/s', "<!--pixgridder:column[$1]-->$2<!--nextpage[$1]-->", $content);
  831.             $content = preg_replace('/<!--pixgridder:column\[(.?[^\]\s]+)\]--><!--nextpage-->/s', "<!--pixgridder:column[$1]--><!--nextpage[$1]-->", $content);
  832.             $content = preg_replace('/<!--pixgridder:row\[(.?[^\]\s]+)\]-->(.+?)<!--nextpage\[col=(.+?)\]-->/s', "<!--pixgridder:row[$1]-->$2<!--nextpage[$1][col=$3]-->", $content);
  833.             $content = preg_replace('/<!--pixgridder:row\[(.?[^\]\s]+)\]--><!--nextpage\[col=(.+?)\]-->/s', "<!--pixgridder:row[$1]--><!--nextpage[$1][col=$3]-->", $content);
  834.             $content = preg_replace('/<!--nextpage\[cols=(.+?)\]\[col=(.+?)\]-->/s', "<!--/pixgridder:column[col=$2]--><!--/pixgridder:row[cols=$1]--><!--nextpage--><!--pixgridder:row[cols=$1]--><!--pixgridder:column[col=$2]-->", $content);
  835.             $post->post_content = $content;
  836.         }
  837.  
  838.         setup_postdata($post);
  839.  
  840.     }
  841.  
  842.     /**
  843.      * Replace callbacks for PHP 5.3.0<
  844.      *
  845.      * @since    3.1.0
  846.      *
  847.      */
  848.     public function pixgridder_preg_rows($matches) {
  849.         global $post;
  850.  
  851.         if ( !$post )
  852.             return;
  853.  
  854.         $typenow = apply_filters('pixgridder_filter_content_post_type', get_post_type());
  855.         $post_id = apply_filters('pixgridder_filter_content_post_id', $post->ID);
  856.  
  857.         $pixgridder_array_rules_ = get_option('pixgridder_array_rules_');
  858.  
  859.         $row_open = stripslashes(get_option('pixgridder_row_open'));
  860.  
  861.         $i = 0;
  862.  
  863.         if ( isset($pixgridder_array_rules_[$i]) && $pixgridder_array_rules_[$i]!='' ) {
  864.             while($i<count($pixgridder_array_rules_)) {
  865.                 $post_type = $pixgridder_array_rules_[$i]['post_type'];
  866.                 $meta_name = $pixgridder_array_rules_[$i]['meta_name'];
  867.                 $meta_value = $pixgridder_array_rules_[$i]['meta_value'];
  868.                 $enabled = $pixgridder_array_rules_[$i]['enabled'];
  869.                 $start_row = stripslashes($pixgridder_array_rules_[$i]['start_row']);
  870.                 $end_row = stripslashes($pixgridder_array_rules_[$i]['end_row']);
  871.                 $start_column = stripslashes($pixgridder_array_rules_[$i]['start_column']);
  872.                 $end_column = stripslashes($pixgridder_array_rules_[$i]['end_column']);
  873.                 if ( $typenow == $post_type && $enabled != 'disabled' && ( get_post_meta( $post_id, $meta_name, true ) == $meta_value || $meta_name == '') && $start_row != 'default' ) {
  874.                     $row_open = $start_row;
  875.                 }
  876.                 $i++;
  877.             }
  878.         }
  879.         $string = $matches[2];
  880.         if ( strpos($row_open,' class=') !== false && strpos($string,'data-class') !== false ) {
  881.             preg_match('/ class=[\'"](.+?)[\'"]/',$row_open,$class);
  882.             $string = preg_replace('/data-class\[(.+?)\]/','data-class['.$class[1].' $1]',$matches[2]);
  883.             $row_open = preg_replace('/ class=[\'"](.+?)[\'"]/','',$row_open, 1);
  884.         }
  885.         $row_open = preg_replace('/>/',' '.$string.'>',$row_open, 1);
  886.         $result = preg_replace('/\$1/',$matches[1],$row_open);
  887.         return $result;
  888.     }
  889.     public function pixgridder_preg_cols($matches) {
  890.         global $post;
  891.  
  892.         if ( !$post )
  893.             return;
  894.  
  895.         $typenow = apply_filters('pixgridder_filter_content_post_type', get_post_type());
  896.         $post_id = apply_filters('pixgridder_filter_content_post_id', $post->ID);
  897.  
  898.         $pixgridder_array_rules_ = get_option('pixgridder_array_rules_');
  899.  
  900.         $column_open = stripslashes(get_option('pixgridder_column_open'));
  901.  
  902.         $i = 0;
  903.  
  904.         if ( isset($pixgridder_array_rules_[$i]) && $pixgridder_array_rules_[$i]!='' ) {
  905.             while($i<count($pixgridder_array_rules_)) {
  906.                 $post_type = $pixgridder_array_rules_[$i]['post_type'];
  907.                 $meta_name = $pixgridder_array_rules_[$i]['meta_name'];
  908.                 $meta_value = $pixgridder_array_rules_[$i]['meta_value'];
  909.                 $enabled = $pixgridder_array_rules_[$i]['enabled'];
  910.                 $start_row = stripslashes($pixgridder_array_rules_[$i]['start_row']);
  911.                 $end_row = stripslashes($pixgridder_array_rules_[$i]['end_row']);
  912.                 $start_column = stripslashes($pixgridder_array_rules_[$i]['start_column']);
  913.                 $end_column = stripslashes($pixgridder_array_rules_[$i]['end_column']);
  914.                 if ( $typenow == $post_type && $enabled != 'disabled' && ( get_post_meta( $post_id, $meta_name, true ) == $meta_value || $meta_name == '') && $start_column != 'default' ) {
  915.                     $column_open = $start_column;
  916.                 }
  917.                 if ( $typenow == $post_type && $enabled != 'disabled' && ( get_post_meta( $post_id, $meta_name, true ) == $meta_value || $meta_name == '') && $end_column != 'default' ) {
  918.                     $column_close = $end_column;
  919.                 }
  920.                 $i++;
  921.             }
  922.         }
  923.         $string = $matches[2];
  924.         if ( strpos($column_open,' class=') !== false && strpos($string,'data-class') !== false ) {
  925.             preg_match('/ class=[\'"](.+?)[\'"]/',$column_open,$class);
  926.             $string = preg_replace('/data-class\[(.+?)\]/','data-class['.$class[1].' $1]',$matches[2]);
  927.             $column_open = preg_replace('/ class=[\'"](.+?)[\'"]/','',$column_open, 1);
  928.         }
  929.         $column_open = preg_replace('/>/',' '.$string.'>',$column_open, 1);
  930.         $result = preg_replace('/\$1/',$matches[1],$column_open);
  931.         return $result;
  932.     }
  933.  
  934.     /**
  935.      * Add plugin menu.
  936.      *
  937.      * @since    1.0.0
  938.      */
  939.     public function add_menu() {
  940.         if (function_exists('add_options_page')) {
  941.             add_menu_page($this->plugin_name, $this->plugin_name, 'activate_plugins', 'pixgridder_admin', array( $this, 'register_options' ));
  942.             add_submenu_page('pixgridder_admin', 'Very general', 'Very general', 'activate_plugins', 'pixgridder_verygeneral', array( $this, 'register_options' ));
  943.             add_submenu_page('pixgridder_admin', 'Register', 'Register', 'activate_plugins', 'pixgridder_register', array( $this, 'register_options' ));
  944.             add_submenu_page('pixgridder_admin', 'Settings', 'Settings', 'activate_plugins', 'pixgridder_settings', array( $this, 'register_options' ));
  945.             add_submenu_page('pixgridder_admin', 'Compile CSS file', 'Compile CSS file', 'activate_plugins', 'pixgridder_css', array( $this, 'register_options' ));
  946.             add_submenu_page('pixgridder_admin', 'Add rules', 'Add rules', 'activate_plugins', 'pixgridder_rules', array( $this, 'register_options' ));
  947.             add_submenu_page('pixgridder_admin', 'Installation', 'Installation', 'activate_plugins', 'pixgridder_descdoc', array( $this, 'register_options' ));
  948.             add_submenu_page('pixgridder_admin', 'Installation', 'Installation', 'activate_plugins', 'pixgridder_startdoc', array( $this, 'register_options' ));
  949.             add_submenu_page('pixgridder_admin', 'Admin panel', 'Admin panel', 'activate_plugins', 'pixgridder_admindoc', array( $this, 'register_options' ));
  950.             add_submenu_page('pixgridder_admin', 'Grid builder', 'Grid builder', 'activate_plugins', 'pixgridder_builderdoc', array( $this, 'register_options' ));
  951.         }
  952.     }
  953.  
  954.     /**
  955.      * Options.
  956.      *
  957.      * @since    1.1.0
  958.      *
  959.      */
  960.     public static function register_options() {
  961.         global $options;
  962.  
  963.         $pixGridder = new PixGridder();
  964.         $version = $pixGridder->version;
  965.  
  966.         $page_template = locate_template( array( 'page.php' ) );
  967.         $pixgridder_post_type = (!empty($page_template)) ? array("page" => "page") : '';
  968.  
  969.         if (!empty($page_template)) {
  970.             $pixgridder_page_template['default'] = 'default';
  971.         }
  972.         $templates = get_page_templates();
  973.         $pixgridder_page_template = array();
  974.         foreach ( $templates as $template_name => $template_filename ) {
  975.             $pixgridder_page_template[$template_filename] = $template_filename;
  976.         }
  977.  
  978.         $options = array (
  979.             array( "id" => "pixgridder_info_update",
  980.                 "std" => $version),
  981.             array( "id" => "pixgridder_info_addon",
  982.                 "std" => ""),
  983.             array( "id" => "pixgridder_height_preview",
  984.                 "std" => "550"),
  985.             array( "id" => "pixgridder_allow_ajax",
  986.                 "std" => "true"),
  987.             array( "id" => "pixgridder_no_trace",
  988.                 "std" => "0"),
  989.             array( "id" => "pixgridder_user_name",
  990.                 "std" => ""),
  991.             array( "id" => "pixgridder_license_key",
  992.                 "std" => ""),
  993.             array( "id" => "pixgridder_fx",
  994.                 "std" => 'pix-fadeIn'),
  995.             array( "id" => "pixgridder_disable_preview",
  996.                 "std" => '0'),
  997.             array( "id" => "pixgridder_row_open",
  998.                 "std" => "<div class=\"row\" data-cols=\"$1\">"),
  999.             array( "id" => "pixgridder_row_close",
  1000.                 "std" => "</div><!--.row[data-cols=\"$1\"]-->"),
  1001.             array( "id" => "pixgridder_column_open",
  1002.                 "std" => "<div class=\"column\" data-col=\"$1\">"),
  1003.             array( "id" => "pixgridder_column_close",
  1004.                 "std" => "</div><!--.column[data-col=\"$1\"]-->"),
  1005.             array( "id" => "pixgridder_min_cols",
  1006.                 "std" => "3"),
  1007.             array( "id" => "pixgridder_max_cols",
  1008.                 "std" => "12"),
  1009.             array( "id" => "pixgridder_exclude_cols",
  1010.                 "std" => ""),
  1011.             array( "id" => "pixgridder_post_type",
  1012.                 "std" => $pixgridder_post_type),
  1013.             array( "id" => "pixgridder_page_template",
  1014.                 "std" => $pixgridder_page_template),
  1015.             array( "id" => "pixgridder_css_selector",
  1016.                 "std" => '.row .column'),
  1017.             array( "id" => "pixgridder_css_gutter",
  1018.                 "std" => '3'),
  1019.             array( "id" => "pixgridder_css_gutter_h",
  1020.                 "std" => '3'),
  1021.             array( "id" => "pixgridder_opacity_ms",
  1022.                 "std" => '500'),
  1023.             array( "id" => "pixgridder_animation_ms",
  1024.                 "std" => '350'),
  1025.             array( "id" => "pixgridder_remove_animation_break",
  1026.                 "std" => '1024'),
  1027.             array( "id" => "pixgridder_css_padding",
  1028.                 "std" => '0'),
  1029.             array( "id" => "pixgridder_css_break",
  1030.                 "std" => '800'),
  1031.             array( "id" => "pixgridder_medium_break",
  1032.                 "std" => '1024'),
  1033.             array( "id" => "pixgridder_css_code",
  1034.                 "std" => '\/* PixGridder custom stylesheet *\/'),
  1035.             array( "id" => "pixgridder_include_generated_css",
  1036.                 "std" => 'true'),
  1037.             array( "id" => "pixgridder_load_css_inline",
  1038.                 "std" => 'true')
  1039.         );
  1040.        
  1041.         self::pixgridder_admin( array( &$this, 'register_options' ) );
  1042.         self::pixgridder_verygeneral( array( &$this, 'register_options' ) );
  1043.         self::pixgridder_register( array( &$this, 'register_options' ) );
  1044.         self::pixgridder_settings( array( &$this, 'register_options' ) );
  1045.         self::pixgridder_css( array( &$this, 'register_options' ) );
  1046.         self::pixgridder_rules( array( &$this, 'register_options' ) );
  1047.         self::pixgridder_descdoc( array( &$this, 'register_options' ) );
  1048.         self::pixgridder_startdoc( array( &$this, 'register_options' ) );
  1049.         self::pixgridder_admindoc( array( &$this, 'register_options' ) );
  1050.         self::pixgridder_builderdoc( array( &$this, 'register_options' ) );
  1051.  
  1052.         return $options;
  1053.     }
  1054.  
  1055.     /**
  1056.      * Display the menu for admin panel.
  1057.      *
  1058.      * @since    1.0.0
  1059.      */
  1060.     public static function pixgridder_admin() {
  1061.         require_once( PIXGRIDDER_PATH . 'lib/admin/panel.php' );
  1062.     }
  1063.  
  1064.     /**
  1065.      * Display the general admin page.
  1066.      *
  1067.      * @since    1.0.0
  1068.      */
  1069.     public static function pixgridder_verygeneral() {
  1070.         require_once( PIXGRIDDER_PATH . 'lib/admin/general.php' );
  1071.     }
  1072.  
  1073.     /**
  1074.      * Display the register page.
  1075.      *
  1076.      * @since    1.0.0
  1077.      */
  1078.     public static function pixgridder_register() {
  1079.         require_once( PIXGRIDDER_PATH . 'lib/admin/register.php' );
  1080.     }
  1081.  
  1082.     /**
  1083.      * Display the general settings.
  1084.      *
  1085.      * @since    1.0.0
  1086.      */
  1087.     public static function pixgridder_settings() {
  1088.         require_once( PIXGRIDDER_PATH . 'lib/admin/settings.php' );
  1089.     }
  1090.  
  1091.     /**
  1092.      * Display the css compiler.
  1093.      *
  1094.      * @since    1.0.0
  1095.      */
  1096.     public static function pixgridder_css() {
  1097.         require_once( PIXGRIDDER_PATH . 'lib/admin/css.php' );
  1098.     }
  1099.  
  1100.     /**
  1101.      * Display the "add rules" page.
  1102.      *
  1103.      * @since    1.0.0
  1104.      */
  1105.     public static function pixgridder_rules() {
  1106.         require_once( PIXGRIDDER_PATH . 'lib/admin/rules.php' );
  1107.     }
  1108.  
  1109.     /**
  1110.      * Display the documentation pages.
  1111.      *
  1112.      * @since    1.0.0
  1113.      */
  1114.     public static function pixgridder_descdoc() {
  1115.         require_once( PIXGRIDDER_PATH . 'lib/admin/documentation.php' );
  1116.     }
  1117.     public static function pixgridder_startdoc() {
  1118.         require_once( PIXGRIDDER_PATH . 'lib/admin/documentation.php' );
  1119.     }
  1120.     public static function pixgridder_admindoc() {
  1121.         require_once( PIXGRIDDER_PATH . 'lib/admin/documentation.php' );
  1122.     }
  1123.     public static function pixgridder_builderdoc() {
  1124.         require_once( PIXGRIDDER_PATH . 'lib/admin/documentation.php' );
  1125.     }
  1126.  
  1127.     /**
  1128.      * Register options in the database.
  1129.      *
  1130.      * @since    1.0.0
  1131.      */
  1132.     public static function add_general() {
  1133.         global $options;
  1134.         self::register_options();
  1135.        
  1136.         foreach ($options as $value) :
  1137.             if(!get_option($value['id'])){
  1138.                 add_option($value['id'], $value['std']);
  1139.             }
  1140.         endforeach;
  1141.     }
  1142.  
  1143.     /**
  1144.      * Save the options on the admin panel via AJAX.
  1145.      *
  1146.      * @since    1.0.0
  1147.      */
  1148.     public function save_via_ajax() {
  1149.         global $options;
  1150.         check_ajax_referer('pixgridder_data', 'pixgridder_security');
  1151.  
  1152.         $data = $_POST;
  1153.         unset($data['pixgridder_security'], $data['action']);
  1154.  
  1155.         foreach ($_REQUEST as $key => $value) {
  1156.             if ( preg_match("/pixgridder_array/", $key) ) {
  1157.                 delete_option($key);
  1158.                 if(!get_option($key)) {
  1159.                     add_option($key, $value);
  1160.                 } else {
  1161.                     update_option($key, $value);
  1162.                 }
  1163.             }
  1164.         }
  1165.        
  1166.         foreach ($_REQUEST as $key => $value) {
  1167.             if( isset($_REQUEST[$key]) ) {
  1168.                 update_option($key, $value);
  1169.             }
  1170.         }      
  1171.     }
  1172.  
  1173.     /**
  1174.      * Remove the subpages via CSS.
  1175.      *
  1176.      * @since    1.0.0
  1177.      */
  1178.     public function remove_subpages() { ?>
  1179.         <style type="text/css" media="screen">
  1180.             #toplevel_page_pixgridder_admin ul, #toplevel_page_pixgridder_admin .wp-menu-toggle, #toplevel_page_pixgridder_admin .wp-submenu, #toplevel_page_pixgridder_admin.wp-not-current-submenu .wp-menu-arrow {
  1181.                 display: none!important;
  1182.             }
  1183.         </style>
  1184.     <?php }
  1185.  
  1186.     /**
  1187.      * Set the animation on the frontend as JS var.
  1188.      *
  1189.      * @since    1.0.0
  1190.      */
  1191.     public function fx_vars() {
  1192.         ?>
  1193.         <script type="text/javascript">
  1194.         //<![CDATA[
  1195.             var pixgridder_blank_gif = "<?php echo PIXGRIDDER_URL.'images/blank.gif'; ?>",pixgridder_fx = "<?php echo get_option('pixgridder_fx'); ?>", pixgridder_css_selector = "<?php echo get_option('pixgridder_css_selector'); ?>";
  1196.         //]]>
  1197.         </script>
  1198.     <?php }
  1199.  
  1200.     /**
  1201.      * Set the content width as JS var.
  1202.      *
  1203.      * @since    1.1.0
  1204.      */
  1205.     public function js_vars() {
  1206.         global $content_width, $post, $pagenow;
  1207.  
  1208.         if ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) {
  1209.  
  1210.             $typenow = get_post_type();
  1211.             $templatenow = get_post_meta($post->ID,'_wp_page_template', true) == '' ? 'default' : get_post_meta($post->ID,'_wp_page_template', true);
  1212.             $editor = get_post_meta( $post->ID, 'pixBuilderDisable', true );
  1213.             $post_types_selected = get_option( 'pixgridder_post_type' ) != '' ? get_option( 'pixgridder_post_type' ) : array();
  1214.             $page_template = get_option( 'pixgridder_page_template' ) != '' ? get_option( 'pixgridder_page_template' ) : array();
  1215.  
  1216.             $pixgridder_array_rules_ = get_option('pixgridder_array_rules_');
  1217.  
  1218.             if ( ($typenow != 'page' && in_array($typenow,$post_types_selected)) || ($typenow == 'page' && (in_array($templatenow,$page_template) || empty($page_template))) ) {
  1219.                 $display = 'true';
  1220.             } else {
  1221.                 $display = 'false';        
  1222.             }          
  1223.             $i = 0;
  1224.  
  1225.             if ( isset($pixgridder_array_rules_[$i]) && $pixgridder_array_rules_[$i]!='' ) {
  1226.                 while($i<count($pixgridder_array_rules_)) {
  1227.                     $post_type = $pixgridder_array_rules_[$i]['post_type'];
  1228.                     $meta_name = $pixgridder_array_rules_[$i]['meta_name'];
  1229.                     $meta_value = $pixgridder_array_rules_[$i]['meta_value'];
  1230.                     $enabled = $pixgridder_array_rules_[$i]['enabled'];
  1231.                     if ( $typenow == $post_type && $enabled != 'disabled' && ( get_post_meta( $post->ID, $meta_name, true ) == $meta_value || $meta_name=='' ) ) {
  1232.                         $display = 'true';
  1233.                     } elseif  ( $typenow == $post_type && $enabled == 'disabled' && ( get_post_meta( $post->ID, $meta_name, true ) == $meta_value || $meta_name=='' ) ) {
  1234.                         $display = 'false';
  1235.                     }
  1236.                     $i++;
  1237.                 }
  1238.             }
  1239.            
  1240.             if ( $editor == 'on' ) {
  1241.                 $display = 'false';
  1242.             }
  1243.  
  1244.             if ( isset( $content_width ) ) {
  1245.                 $pix_content_width = $content_width;
  1246.             } else {
  1247.                 $pix_content_width = 980;
  1248.             }
  1249.  
  1250.             ?>
  1251.             <script type="text/javascript">
  1252.             //<![CDATA[
  1253.                 var pixgridder_content_width = <?php echo $pix_content_width; ?>, pixgridder_url = "<?php echo PIXGRIDDER_URL; ?>", pixgridder_display = <?php echo $display; ?>, pixgridder_preview_text = "<?php _e('Preview','pixgridder'); ?>", pixgridder_builder_text = "<?php _e('Builder','pixgridder'); ?>", pixgridder_disable_preview = "<?php echo get_option('pixgridder_disable_preview'); ?>",
  1254.                     pixgridder_rowClassArr = <?php echo apply_filters('pixgridder_rowClassArr','[]'); ?>;
  1255.                     pixgridder_colClassArr = <?php echo apply_filters('pixgridder_colClassArr','[]'); ?>;
  1256.                     pixgridder_featuredColors = <?php echo apply_filters('pixgridder_featuredColors','[]'); ?>;
  1257.             //]]>
  1258.             </script>
  1259.         <?php }
  1260.  
  1261.     }
  1262.  
  1263.  
  1264.     /**
  1265.      * The inline css compiler.
  1266.      *
  1267.      * @since    3.2.0
  1268.      */
  1269.     public static function css_inline() {
  1270.  
  1271.         $target_file = PIXGRIDDER_PATH.'lib/push.php';
  1272.  
  1273.         ob_start();
  1274.         require($target_file);
  1275.         $css = ob_get_clean();
  1276.  
  1277.         if ( get_option('pixgridder_load_css_inline')=='true' )
  1278.             echo '<style>'.$css.'</style>';
  1279.  
  1280.     }
  1281.  
  1282.  
  1283.     /**
  1284.      * The css compiler.
  1285.      *
  1286.      * @since    3.0.0
  1287.      */
  1288.     public static function compile_css() {
  1289.  
  1290.         do_action('pixgridder_css_compiling');
  1291.  
  1292.         WP_Filesystem();
  1293.         global $wp_filesystem, $blog_id;
  1294.  
  1295.         if ( is_multisite() && $blog_id > 1 ) {
  1296.             $upload_dir = wp_upload_dir();
  1297.             $dir = $upload_dir['basedir'] .'/pixgridder/';
  1298.             if (!is_dir($dir))
  1299.                 @mkdir($dir);
  1300.            
  1301.             $css_file = $dir . '/front-gridder.css';
  1302.         } else {
  1303.             $css_file = PIXGRIDDER_PATH . 'css/front-gridder.css';
  1304.         }
  1305.  
  1306.         $target_file = PIXGRIDDER_PATH.'lib/push.php';
  1307.  
  1308.         ob_start();
  1309.         require($target_file);
  1310.         $css = ob_get_clean();
  1311.  
  1312.         $wp_filesystem->put_contents( $css_file, $css, FS_CHMOD_FILE );
  1313.  
  1314.     }
  1315.  
  1316.  
  1317.     /**
  1318.      * The css compiler via AJAX.
  1319.      *
  1320.      * @since    3.0.0
  1321.      */
  1322.     public function compile_css_ajax() {
  1323.  
  1324.         do_action('pixgridder_css_ajax_compiling');
  1325.  
  1326.         WP_Filesystem();
  1327.         global $wp_filesystem, $blog_id;
  1328.  
  1329.         if ( is_multisite() && $blog_id > 1 ) {
  1330.             $upload_dir = wp_upload_dir();
  1331.             $dir = $upload_dir['basedir'] .'/pixgridder/';
  1332.             if (!is_dir($dir))
  1333.                 @mkdir($dir);
  1334.            
  1335.             $css_file = $dir . '/front-gridder.css';
  1336.         } else {
  1337.             $css_file = PIXGRIDDER_PATH . 'css/front-gridder.css';
  1338.         }
  1339.  
  1340.         $target_file = PIXGRIDDER_PATH.'lib/push.php';
  1341.  
  1342.         ob_start();
  1343.         require($target_file);
  1344.         $css = ob_get_clean();
  1345.  
  1346.         $wp_filesystem->put_contents( $css_file, $css, FS_CHMOD_FILE );
  1347.  
  1348.         die();
  1349.     }
  1350.  
  1351.     /**
  1352.      * Add custom stylesheet to tinyMCE.
  1353.      *
  1354.      * @since    2.0.0
  1355.      */
  1356.     public static function add_tinymce_css($wp) {
  1357.         $wp .= ',' . PIXGRIDDER_URL . 'css/tinymce_frame.css';
  1358.         return $wp;
  1359.     }
  1360.  
  1361.     /**
  1362.      * Check if a plugin is active.
  1363.      *
  1364.      * @since    3.1.0
  1365.      */
  1366.     public static function is_plugin_active($plugin) {
  1367.         include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
  1368.         if (is_plugin_active($plugin)) {
  1369.             return true;
  1370.         } else {
  1371.             return false;
  1372.         }
  1373.     }
  1374.  
  1375.     /**
  1376.      * License checker.
  1377.      *
  1378.      * @since    1.0.1
  1379.      */
  1380.     public function check_license($context) {
  1381.  
  1382.         $request_url = 'http://www.pixedelic.com/api/products/pixgridder.php';
  1383.        
  1384.         $request_string = array(
  1385.                 'body' => array(
  1386.                     'action' => 'check_pixgridder_license',
  1387.                     'id' => '5251972',
  1388.                     'username' => $_REQUEST['pixgridder_user_name'],
  1389.                     'license' => $_REQUEST['pixgridder_license_key']
  1390.                 )
  1391.             );
  1392.        
  1393.         $raw_response = wp_remote_post($request_url, $request_string);
  1394.  
  1395.         if (!is_wp_error($raw_response) && ($raw_response['response']['code'] == 200)) {
  1396.             $body = addslashes($raw_response['body']);
  1397.             if( stripos($body,'perfect')!=false ) { ?>
  1398. <script type="text/javascript">
  1399. /* <![CDATA[ */
  1400. var pixgridder_check_license = 'true',
  1401.     pixgridder_check_message = '<?php echo $body; ?>';
  1402. /* ]]> */
  1403. </script>
  1404.             <?php } else { ?>
  1405. <script type="text/javascript">
  1406. /* <![CDATA[ */
  1407. var pixgridder_check_license = 'false',
  1408.     pixgridder_check_message = '<?php echo $body; ?>';
  1409. /* ]]> */
  1410. </script>
  1411.             <?php }
  1412.         }
  1413.        
  1414.     }
  1415.  
  1416.     /**
  1417.      * Check for update.
  1418.      *
  1419.      * @since    1.0.1
  1420.      */
  1421.     public function check_for_plugin_update($checked_data) {
  1422.         global $wp_version;
  1423.  
  1424.         $api_url = 'http://www.pixedelic.com/api/';
  1425.  
  1426.         if (empty($checked_data->checked))
  1427.             return $checked_data;
  1428.        
  1429.         $args = array(
  1430.             'dir' => sanitize_title( $this->plugin_name ),
  1431.             'slug' => $this->plugin_slug,
  1432.             'version' => $checked_data->checked[ PIXGRIDDER_NAME ],
  1433.             'id' => '5251972',
  1434.             'user' => get_option('pixgridder_user_name'),
  1435.             'license' => get_option('pixgridder_license_key')
  1436.         );
  1437.  
  1438.         $request_string = array(
  1439.                 'body' => array(
  1440.                     'action' => 'basic_check',
  1441.                     'request' => serialize($args),
  1442.                     'api-key' => md5(get_bloginfo('url'))
  1443.                 ),
  1444.                 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
  1445.             );
  1446.        
  1447.         $raw_response = wp_remote_post($api_url, $request_string);
  1448.  
  1449.         if (!is_wp_error($raw_response) && ($raw_response['response']['code'] == 200))
  1450.             $response = unserialize($raw_response['body']);
  1451.  
  1452.         if (is_object($response) && !empty($response)) // Feed the update data into WP updater
  1453.             $checked_data->response[ PIXGRIDDER_NAME ] = $response;
  1454.        
  1455.         return $checked_data;
  1456.     }
  1457.  
  1458.     /**
  1459.      * Call for update.
  1460.      *
  1461.      * @since    2.1.0
  1462.      */
  1463.     public function plugin_api_call($def, $action, $args) {
  1464.         global $wp_version;
  1465.        
  1466.         $api_url = 'http://www.pixedelic.com/api/';
  1467.        
  1468.         if (!isset($args->slug) || ($args->slug != $this->plugin_slug))
  1469.             return false;
  1470.        
  1471.         $plugin_info = get_site_transient('update_plugins');
  1472.         $current_version = $plugin_info->checked[ PIXGRIDDER_NAME ];
  1473.         $args->version = $current_version;
  1474.        
  1475.         $request_string = array(
  1476.                 'body' => array(
  1477.                     'action' => $action,
  1478.                     'request' => serialize($args),
  1479.                     'api-key' => md5(get_bloginfo('url'))
  1480.                 ),
  1481.                 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
  1482.             );
  1483.        
  1484.         $request = wp_remote_post($api_url, $request_string);
  1485.  
  1486.         if (is_wp_error($request)) {
  1487.             $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>'), $request->get_error_message());
  1488.         } else {
  1489.             $res = unserialize($request['body']);
  1490.  
  1491.             if ($res === false)
  1492.                 $res = new WP_Error('plugins_api_failed', __('An unknown error occurred'), $request['body']);
  1493.         }
  1494.        
  1495.         return $res;
  1496.     }
  1497. }
Advertisement
Add Comment
Please, Sign In to add comment