Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 34.07 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  * AcmeeFramework
  5.  * @author   AcmeeDesign
  6.  * @url     http://acmeedesign.com
  7. */
  8.  
  9. defined('ABSPATH') || die;
  10.  
  11. if (!class_exists('AcmeeFramework')) {
  12.  
  13.     class AcmeeFramework {
  14.         public $config;
  15.         protected $options_slug;
  16.         private $aof_purchase_data = 'aof_purchase_data';
  17.         private $product_code = '17567303';
  18.         public $page_title;
  19.         public $fields_array;
  20.         public $do_not_save;
  21.  
  22.         function __construct() {
  23.             $this->config = aof_config();
  24.             $this->do_not_save = array('title', 'openTab', 'import', 'export');
  25.  
  26.             add_action('after_setup_theme', array($this, 'aofLoaddefault' ));
  27.             add_action('aof_tab_start', array($this, 'formwrapStart'));
  28.             add_action('aof_tab_start', array($this, 'saveBtn'));
  29.             add_action('aof_tab_close', array($this, 'formwrapEnd'));
  30.             add_action('aof_tab_close', array($this, 'saveBtn'));
  31.             add_action('aof_the_form',array($this, 'licenseValidate'), 9);
  32.             add_action('aof_after_heading', array($this, 'adminNotices'));
  33.             add_action('aof_before_heading', array($this, 'licenseUpdated'));
  34.         }
  35.  
  36.         /**
  37.         * Function to generate form fields
  38.         */
  39.         function generateFields($fields_array) {
  40.             //build form
  41.             echo '<div class="wrap clearfix">';
  42.             do_action('aof_before_heading');
  43.             echo '<h2>';
  44.             printf( __( '%s Settings', 'alter' ), 'Alter' );
  45.             echo '</h2>';
  46.             do_action('aof_after_heading');
  47.             do_action('aof_before_form');
  48.             do_action('aof_the_form');
  49.             $this->fieldLoop($fields_array);
  50.             do_action('aof_after_form');
  51.  
  52.             echo '</div>'; //close div wrap
  53.         }
  54.  
  55.         public function fieldLoop($config) {
  56.  
  57.             //get options data
  58.             $getoption = $this->aofgetOptions( ALTER_OPTIONS_SLUG );
  59.  
  60.             echo '<div class="loading_form_text">' . __('Loading...', 'alter') . '</div>';
  61.  
  62.             do_action('aof_tab_start');
  63.  
  64.             $fields_array['tabs'] = $config['aof_fields']['aof_tabs'];
  65.             $fields_array['fields'] = $config['aof_fields']['aof_fields'];
  66.             echo '<div id="aof_options_tab" class="clearfix">
  67.            <ul class="resp-tabs-list hor_1">';
  68.             if(is_array($fields_array['tabs']) && !empty($fields_array['tabs'])) {
  69.                 foreach($fields_array['tabs'] as $tabkey =>$tabvalue) {
  70.                     echo '<li class="' . $tabkey . '">' . $tabvalue . '</li>';
  71.                 }
  72.             }
  73.             echo '</ul>
  74.            <div class="resp-tabs-container hor_1">';
  75.  
  76.             foreach($fields_array['fields'] as $field_key => $field_array) {
  77.                 if(isset($field_array['id']) && !empty($field_array['id'])) {
  78.                     unset($field_meta);
  79.                     $field_meta = array();
  80.                     $field_meta['meta'] = (!empty($getoption[$field_array['id']])) ? $getoption[$field_array['id']] : "";
  81.                     $field_array = array_merge($field_array, $field_meta);
  82.                 }
  83.                 switch ($field_array['type']) {
  84.                     case 'openTab' :
  85.                         $tab_first = ($field_key == 0) ? true : false;
  86.                         $this->openTab($field_array, $tab_first);
  87.                         break;
  88.                     case 'title' :
  89.                         $this->addTitle($field_array);
  90.                         break;
  91.                     case 'note':
  92.                         $this->addNote($field_array);
  93.                         break;
  94.                     case 'text':
  95.                         $this->addText($field_array);
  96.                         break;
  97.                     case 'textarea':
  98.                         $this->addTextarea($field_array);
  99.                         break;
  100.                     case 'checkbox':
  101.                         $this->addCheckbox($field_array);
  102.                         break;
  103.                     case 'multicheck':
  104.                         $this->addMultiCheckbox($field_array);
  105.                         break;
  106.                     case 'radio':
  107.                         $this->addradio($field_array);
  108.                         break;
  109.                     case 'select':
  110.                         $this->addSelect($field_array);
  111.                         break;
  112.                     case 'number':
  113.                         $this->addNumber($field_array);
  114.                         break;
  115.                     case 'typography':
  116.                         $this->addTypography($field_array);
  117.                         break;
  118.                     case 'wpcolor':
  119.                         $this->addwpColor($field_array);
  120.                         break;
  121.                     case 'upload':
  122.                         $this->addUpload($field_array);
  123.                         break;
  124.                     case 'wpeditor':
  125.                         $this->addwpEditor($field_array);
  126.                         break;
  127.                     case 'export':
  128.                         $this->addExport($field_array);
  129.                         break;
  130.                     case 'import':
  131.                         $this->addImport($field_array);
  132.                         break;
  133.                         }
  134.  
  135.  
  136.  
  137.             } // foreach
  138.  
  139.  
  140.             echo '</div>
  141.        </div>'; //close div aof_options_tab
  142.  
  143.             do_action('aof_tab_close');
  144.  
  145.         }
  146.  
  147.         function licenseValidate() {//NULLED
  148.               return;
  149.             //verify purchase code
  150.             $valid_license = $this->validatePurchase();
  151.             if(!empty($valid_license) && count($valid_license[3]) == 5 && $valid_license[1] == $this->product_code)
  152.                 return;
  153.             else {
  154.                 $this->enterPurchaseCode();
  155.                 exit();
  156.             }
  157.         }
  158.  
  159.         function validatePurchase() {
  160.             $purchase_data = get_option($this->aof_purchase_data);
  161.             return $purchase_data;
  162.         }
  163.  
  164.         function getLicense() {
  165.               return "null.ed";
  166.             $code = $this->validatePurchase();
  167.             if(!empty($code)) {
  168.                 return $code[3][0];
  169.             }
  170.             else
  171.                 return null;
  172.         }
  173.  
  174.         function enterPurchaseCode() {
  175.             ?>
  176. <div id="enter_license">
  177.     <?php
  178.     if(function_exists('curl_init')) {
  179.       if(isset($_GET['status']) && $_GET['status'] == 'license_fail') {
  180.           echo '<div class="notice error">';
  181.           echo __('Invalid Purchase code! Or the envato server may be down. ', 'alter');
  182.           echo __('Or your server may not support wordpress remote get method. Please open a support ticket at ', 'alter');
  183.           echo '<a href="http://acmeedesign.com/support">http://acmeedesign.com/support</a>';
  184.           echo '</div>';
  185.       }
  186.      ?>
  187.         <h2><?php echo __('Enter Purchase Code', 'alter'); ?></h2>
  188.         <form name="enter_license" method="post" action="<?php echo admin_url( 'admin.php?page=' . ALTER_MENU_SLUG ); ?>">
  189.             <input type="text" class="purchase_code" name="purchase_code" value="" size="50" /><br /><br />
  190.             <input type="hidden" name="action" value="license_data" />
  191.             <input type="submit" name="submit" value="Submit" class="button button-primary button-large" />
  192.         </form>
  193.         <br />
  194.         <a href="https://help.market.envato.com/hc/en-us/articles/202822600-Where-Is-My-Purchase-Code-" target="_blank">How to find your purchase code?</a>
  195.         <?php
  196.       }
  197.       else {
  198.         echo '<div class="notice error" style="padding:10px"><strong>';
  199.         echo __('Notice: cURL module is not installed on your server. In order to activate your license, you need to install and activate cURL module on your
  200.        server. For more information please visit', 'alter');
  201.         echo' <a href="http://php.net/manual/en/curl.requirements.php">';
  202.         echo __('How to Install cURL?', 'alter');
  203.         echo '</a>';
  204.         echo '</strong></div>';
  205.       }
  206.         ?>
  207. </div>
  208.     <?php
  209.         }
  210.  
  211.         function licenseUpdated() {
  212.             if(isset($_GET['status']) && $_GET['status'] == 'license_success') {
  213.                 echo '<div class="license-updated">';
  214.                 echo __('Your Purchase code is accepted. Happy customizing WordPress!', 'alter');
  215.                 echo ' <a class="alter-kb" target="_blank" href="http://kb.acmeedesign.com/kbase_categories/alter-white-label-wordpress-plugin/">';
  216.                 echo __('Need help?', 'alter');
  217.                 echo '</a>';
  218.                 echo '</div>';
  219.             }
  220.         }
  221.  
  222.         function SaveSettings($post) {
  223.             if(isset($post['action']) && $post['action'] == 'license_data') {
  224.                 $purchase_code = trim($post['purchase_code']);
  225.                 $validate = EnvatoApi2::verifyPurchase( $purchase_code );
  226.                 if ( is_object($validate) ) {
  227.                     $buyer = $validate->buyer;
  228.                     $item_id = $validate->item_id;
  229.                     $license_type = $validate->licence;
  230.                     $code = explode('-', $purchase_code);
  231.                     if($item_id == $this->product_code) {
  232.                       $purchase_data = array($buyer, $item_id, $license_type, $code);
  233.                       update_option( $this->aof_purchase_data, $purchase_data );
  234.                       wp_safe_redirect( admin_url( 'admin.php?page=' . ALTER_ABOUT_SLUG . '&status=license_success' ) );
  235.                       exit();
  236.                     }
  237.                     else {
  238.                       wp_safe_redirect( admin_url( 'admin.php?page=' . ALTER_MENU_SLUG . '&status=license_fail' ) );
  239.                       exit();
  240.                     }
  241.                 }
  242.                 else {
  243.                     wp_safe_redirect( admin_url( 'admin.php?page=' . ALTER_MENU_SLUG . '&status=license_fail' ) );
  244.                     exit();
  245.                 }
  246.  
  247.             }
  248.              if(isset($post) && isset($post['aof_options_save'])) {
  249.  
  250.                 if ( isset($post['aof_options_nonce']) && !wp_verify_nonce($post['aof_options_nonce'], 'aof_options_form') )
  251.                    return;
  252.  
  253.                     if( isset($post['aof_import_settings']) && !empty($post['aof_import_settings']) ) {
  254.                         $settings = $post['aof_import_settings'];
  255.                         if(!empty($settings) && is_serialized($settings)) {
  256.                             $settings = unserialize($settings);
  257.                             update_option( ALTER_OPTIONS_SLUG, $settings );
  258.                             wp_safe_redirect( admin_url( 'admin.php?page=' . ALTER_MENU_SLUG . '&status=success' ) );
  259.                             exit();
  260.                         }
  261.                     }
  262.                     else {
  263.                       $save_data = array();
  264.                       $config = aof_config();
  265.                       $fields_array['fields'] = $config['aof_fields']['aof_fields'];
  266.                       if( is_array($fields_array['fields']) && !empty($fields_array['fields']) ) {
  267.                         //loop through the fields array and initialize $save_data variable
  268.                         foreach($fields_array['fields'] as $field) {
  269.                           if(isset($field['id']) && !in_array($field['type'], $this->do_not_save)) {
  270.                               $post_name = $field['id'];
  271.                               $post_value = (!empty($post[$post_name])) ? $post[$post_name] : "";
  272.                               if($field['type'] == "multicheck") {
  273.                                   $multicheck = array();
  274.                                   if(is_array($post_value)) {
  275.                                       foreach($post_value as $options) {
  276.                                           $multicheck[] = $options;
  277.                                       }
  278.                                   }
  279.                                   $save_data[$field['id']] = $multicheck;
  280.                               }
  281.                               elseif($field['type'] == "typography") {
  282.                                   $typography = array();
  283.                                   if(is_array($post_value)) {
  284.                                       foreach($post_value as $typo_name => $typo_value) {
  285.                                           $typography[$typo_name] = $typo_value;
  286.                                       }
  287.                                       $save_data[$field['id']] = $typography;
  288.                                   }
  289.                               }
  290.                               else {
  291.                                   $save_data[$field['id']] = (isset($post_value)) ? $this->validateInputs($post_value) : "";
  292.                               }
  293.                             }
  294.                           }
  295.                         }
  296.                         $saved_data = $this->aofgetOptions(ALTER_OPTIONS_SLUG);
  297.                         $data = array_merge($saved_data, $save_data);
  298.                         $saved = $this->aofsaveOptions($data);
  299.  
  300.                         //action processed after data saved.
  301.                         do_action('alter_data_saved');
  302.  
  303.                         if($saved) {
  304.                             wp_safe_redirect( admin_url( 'admin.php?page=' . ALTER_MENU_SLUG . '&status=updated' ) );
  305.                             exit();
  306.                         }
  307.                         else {
  308.                             wp_safe_redirect( admin_url( 'admin.php?page=' . ALTER_MENU_SLUG . '&status=error' ) );
  309.                             exit();
  310.                         }
  311.  
  312.                     }
  313.                 }
  314.  
  315.             //aof options save
  316.         }
  317.  
  318.         function aofgetOptions($option_id) {
  319.             if($this->config['multi'] === true) {
  320.                 if(is_serialized(get_site_option( $option_id ))) {
  321.                     $get_options = unserialize(get_site_option( $option_id ));
  322.                 }
  323.                 else {
  324.                     $get_options = get_site_option( $option_id );
  325.                 }
  326.             }
  327.             else {
  328.                 if(is_serialized(get_option( $option_id ))) {
  329.                     $get_options = unserialize(get_option( $option_id ));
  330.                 }
  331.                 else {
  332.                     $get_options = get_option( $option_id );
  333.                 }
  334.             }
  335.             return $get_options;
  336.         }
  337.  
  338.         function aofsaveOptions($save_options) {
  339.             if($this->config['multi'] === true) {
  340.                 update_site_option( ALTER_OPTIONS_SLUG, $save_options );
  341.                 return true;
  342.             }
  343.             else {
  344.                 update_option( ALTER_OPTIONS_SLUG, $save_options );
  345.                 return true;
  346.             }
  347.         }
  348.  
  349.         function openTab($fields, $tab_first) {
  350.             if($tab_first) {
  351.                 $output = '<div>';
  352.                 if(!empty($fields['name'])) $output .= '<h2>' . $fields['name'] . '</h2>';
  353.             }
  354.             else {
  355.                 $output = '</div><div>';
  356.                 if(!empty($fields['name'])) $output .= '<h2>' . $fields['name'] . '</h2>';
  357.             }
  358.             echo $output;
  359.         }
  360.  
  361.         function addTitle($fields) {
  362.             echo '<h3>' . $fields['name'] . '</h3>';
  363.         }
  364.  
  365.         function addNote($fields) {
  366.             $output = '<p class="description">' . $fields['desc'] . '</p>';
  367.             echo $output;
  368.         }
  369.  
  370.         function addText($fields) {
  371.             $meta = (isset($fields['meta'])) ? $fields['meta'] : "";
  372.             $form_field = '<input id="' . $fields['id'] . '" class="regular-text ' . $fields['id'] . '" type="text" name="' . $fields['id'] . '" value="' . $meta . '"  />';
  373.             $output = $this->fieldWrap($fields, $form_field);
  374.             echo $output;
  375.         }
  376.  
  377.         function addTextarea($fields) {
  378.             $meta = (isset($fields['meta'])) ? $fields['meta'] : "";
  379.             $form_field = '<textarea id="' . $fields['id'] . '" class="regular-text ' . $fields['id'] . '" name="' . $fields['id'] . '" rows="10">' . $meta . '</textarea>';
  380.             $output = $this->fieldWrap($fields, $form_field);
  381.             echo $output;
  382.         }
  383.  
  384.         //single checkbox
  385.         function addCheckbox($fields) {
  386.             $meta = (isset($fields['meta'])) ? $fields['meta'] : "";
  387.             $form_field = '<label for="' . $fields['id'] . '"><input id="' . $fields['id'] . '" class="' . $fields['id'] . '" type="checkbox" name="' . $fields['id'] . '" value="1"';
  388.             $form_field .= ($meta == 1) ? ' checked="checked"' : '';
  389.             $form_field .= '/></label>';
  390.             $output = $this->fieldWrap($fields, $form_field);
  391.             echo $output;
  392.         }
  393.  
  394.         //multi checkboxes
  395.         function addMultiCheckbox($fields) {
  396.             $meta = (isset($fields['meta'])) ? $fields['meta'] : "";
  397.             if(isset($fields['options'])) {
  398.                 $form_field = "";
  399.                 foreach($fields['options'] as $field_key => $field_value) {
  400.                     $form_field .= '<label for="' . $fields['id'] . '"><input class="' . $fields['id'] . '" type="checkbox" name="' . $fields['id'] . '[]" value="' . $field_key . '"  ';
  401.                     if(is_array($meta) && in_array($field_key, $meta)) {
  402.                         $form_field .= 'checked="checked"';
  403.                     }
  404.                     $form_field .= '/>';
  405.                     $form_field .= $field_value .  '</label>';
  406.                 }
  407.                 $output = $this->fieldWrap($fields, $form_field);
  408.                 echo $output;
  409.             }
  410.         }
  411.  
  412.         function addradio($fields) {
  413.             $meta = (isset($fields['meta'])) ? $fields['meta'] : "";
  414.             if(isset($fields['options'])) {
  415.                 $form_field = "";
  416.                 foreach($fields['options'] as $field_key => $field_value) {
  417.                     $form_field .= '<label for="' . $fields['id'] . '"><input class="' . $fields['id'] . '" type="radio" name="' . $fields['id'] . '" value="' . $field_key . '" ';
  418.                     $form_field .= ($meta == $field_key) ? 'checked="checked"' : '';
  419.                     $form_field .= '/>';
  420.                     $form_field .= $field_value .  '</label>';
  421.                 }
  422.             }
  423.             $output = $this->fieldWrap($fields, $form_field);
  424.             echo $output;
  425.         }
  426.  
  427.         function addSelect($fields) {
  428.             $meta = (isset($fields['meta'])) ? $fields['meta'] : "";
  429.             if(isset($fields['options'])) {
  430.                 $form_field = '<label for="' . $fields['id'] . '"><select id="' . $fields['id'] . '" class="' . $fields['id'] . '" name="' . $fields['id'] . '">';
  431.                 foreach($fields['options'] as $field_key => $field_value) {
  432.                     $form_field .= '<option value="' . $field_key . '"';
  433.                     $form_field .= ($meta == $field_key) ? ' selected="selected"' : '';
  434.                     $form_field .= '>' . $field_value .  '</option>';
  435.                 }
  436.                 $form_field .= '</select></label>';
  437.             }
  438.             $output = $this->fieldWrap($fields, $form_field);
  439.             echo $output;
  440.         }
  441.  
  442.         function addNumber($fields) {
  443.             $default = array(
  444.                 'default' => '1',
  445.                 'min' => '0',
  446.                 'max' => '50',
  447.                 'step' => '1',
  448.                 );
  449.             if(isset($fields['meta']) && !empty($fields['meta'])) {
  450.                 $meta = $fields['meta'];
  451.             }
  452.             else if($fields['default']) {
  453.                 $meta = $fields['default'];
  454.             }
  455.             else {
  456.                 $meta = "";
  457.             }
  458.             $fields = array_merge($default, $fields);
  459.             $form_field = '<div class="aof-number-slider"></div>';
  460.             $form_field .= '<input id="' . $fields['id'] . '" class="aof-number small-text ' . $fields['id'] . '" name="' . $fields['id'] . '" type="number" value="' . $meta . '" min="' . $fields['min'] . '" max="' . $fields['max'] . '" step="' . $fields['step'] . '">';
  461.             $output = $this->fieldWrap($fields, $form_field);
  462.             echo $output;
  463.         }
  464.  
  465.         function addTypography($fields) {
  466.             $meta = (isset($fields['meta'])) ? $fields['meta'] : "";
  467.             $font_type = isset($meta['font-type']) ? $meta['font-type'] : "";
  468.             $color = isset($meta['color']) ? $meta['color'] : "";
  469.             $gfonts = new AOFgfonts();
  470.             $gfonts_lists = $gfonts->get_gfonts();
  471.             $safe_fonts = array('Arial' => 'Arial, Helvetica, sans-serif', 'Arial Black' => '&quot;Arial Black&quot;, Gadget, sans-serif', 'Comic Sans' => '&quot;Comic Sans MS&quot;, cursive, sans-serif', 'Courier New' => '&quot;Courier New&quot;, Courier, monospace', 'Georgia' => 'Georgia, serif', 'Lucida Sans Unicode' => '&quot;Lucida Sans Unicode&quot;, &quot;Lucida Grande&quot;, sans-serif');
  472.             $font_weights = array( 'normal', 'lighter', 'bold', 'bolder', '100', '200', '300', '400', '500', '600', '700', '800', '900' );
  473.             $font_styles = array('normal', 'italic');
  474.  
  475.             //print_r($gfonts_lists);
  476.             $form_field = '<div class="aof_typography">';
  477.             if(isset($fields['show_font_family']) && $fields['show_font_family'] !== false) {
  478.                 $form_field .='<label>' . __( 'Font Family', 'alter' ) . '<select class="aof_font_family" name="' . $fields['id'] . '[font-family]">';
  479.                 $form_field .='<optgroup label="Web Safe Fonts" class="safe">';
  480.                 foreach ($safe_fonts as $sfontname => $sfontvalue) {
  481.                     $selected = ( htmlentities($meta['font-family']) == $sfontvalue ) ? " selected=selected" : "";
  482.                     $form_field .='<option value="' . $sfontvalue . '"' . $selected . '>' . $sfontname . '</option>';
  483.                 }
  484.                 //<option value="Arial, Helvetica, sans-serif">Arial</option><option value="&quot;Arial Black&quot;, Gadget, sans-serif">Arial Black</option><option value="&quot;Comic Sans MS&quot;, cursive, sans-serif">Comic Sans</option><option value="&quot;Courier New&quot;, Courier, monospace">Courier New</option><option value="Georgia, serif">Geogia</option><option value="Impact, Charcoal, sans-serif">Impact</option><option value="&quot;Lucida Console&quot;, Monaco, monospace">Lucida Console</option><option value="&quot;Lucida Sans Unicode&quot;, &quot;Lucida Grande&quot;, sans-serif">Lucida Sans</option><option value="&quot;Palatino Linotype&quot;, &quot;Book Antiqua&quot;, Palatino, serif">Palatino</option><option value="Tahoma, Geneva, sans-serif">Tahoma</option><option value="&quot;Times New Roman&quot;, Times, serif">Times New Roman</option><option value="&quot;Trebuchet MS&quot;, Helvetica, sans-serif">Trebuchet</option><option value="Verdana, Geneva, sans-serif">Verdana</option></optgroup>';
  485.                 $form_field .='<optgroup label="Google WebFonts" class="google">';
  486.                 foreach ($gfonts_lists as $fontname => $fontvalue) {
  487.                     $selected = ( $meta['font-family'] == $fontvalue['name'] ) ? " selected=selected" : "";
  488.                     $form_field .='<option value="' . $fontvalue['name'] . '"' . $selected . '>' . $fontvalue['name'] . '</option>';
  489.                 }
  490.                 $form_field .='</optgroup>';
  491.                 $form_field .='</select><input type="hidden" class="aof-font-type" name="' . $fields['id'] . '[font-type]" value="' . $font_type . '" /></label>';
  492.             }
  493.  
  494.             if(isset($fields['show_color']) && $fields['show_color'] !== false) {
  495.                 //wpcolor
  496.                 $form_field .= __( 'Color', 'alter' ) . '<label><input class="aof-wpcolor ' . $fields['id'] . '" type="text" name="' . $fields['id'] . '[color]" value="' . $color . '"  /></label>';
  497.             }
  498.  
  499.             if(isset($fields['show_font_weight']) && $fields['show_font_weight'] !== false) {
  500.                 //font weight
  501.                 $form_field .= __( 'Font Weight', 'alter' ) . '<label><select class="aof_font_weight" name="' . $fields['id'] . '[font-weight]">';
  502.                 foreach ($font_weights as $font_weight) {
  503.                     $selected = ( $meta['font-weight'] == $font_weight ) ? " selected=selected" : "";
  504.                     $form_field .='<option value="' . $font_weight . '"' . $selected . '>' . $font_weight . '</option>';
  505.                 }
  506.                 $form_field .='</select></label>';
  507.             }
  508.  
  509.             if(isset($fields['show_font_style']) && $fields['show_font_style'] !== false) {
  510.                 //font style
  511.                 $form_field .= __( 'Font Style', 'alter' ) . '<label><select class="aof_font_style" name="' . $fields['id'] . '[font-style]">';
  512.                 foreach ($font_styles as $font_style) {
  513.                     $selected = ( $meta['font-style'] == $font_style ) ? " selected=selected" : "";
  514.                     $form_field .='<option value="' . $font_style . '"' . $selected .'>' . $font_style . '</option>';
  515.                 }
  516.                 $form_field .='</select></label>';
  517.             }
  518.  
  519.             if(isset($fields['show_font_size']) && $fields['show_font_size'] !== false) {
  520.                 //font size
  521.                 $form_field .= __( 'Font Size', 'alter' ) . '<label><select class="aof_font_size" name="' . $fields['id'] . '[font-size]">';
  522.                 for($i = 9; $i <= 65; $i++) {
  523.                     $selected = ( $meta['font-size'] == $i ) ? " selected=selected" : "";
  524.                     $form_field .='<option value="' . $i . '"' . $selected . '>' . $i . 'px</option>';
  525.                 }
  526.                 $form_field .='</select></label>';
  527.             }
  528.             $form_field .='</div>';
  529.             $output = $this->fieldWrap($fields, $form_field);
  530.             echo $output;
  531.         }
  532.  
  533.         function addwpColor($fields) {
  534.             $meta = (isset($fields['meta'])) ? $fields['meta'] : "";
  535.             $form_field = '<input id="' . $fields['id'] . '" class="aof-wpcolor ' . $fields['id'] . '" type="text" name="' . $fields['id'] . '" value="' . $meta . '"  />';
  536.             $output = $this->fieldWrap($fields, $form_field);
  537.             echo $output;
  538.         }
  539.  
  540.         function addwpEditor($fields) {
  541.             $meta = (isset($fields['meta'])) ? $fields['meta'] : "";
  542.             echo '<div class="field_wrap">';
  543.             echo '<div class="label"><label for="' . $fields['id'] . '">' . $fields['name'] . '</label></div>';
  544.             echo '<div class="field_content">';
  545.             $settings = array('textarea_name' => $fields['id'], 'textarea_rows' => 10);
  546.             wp_editor(stripslashes(stripslashes(html_entity_decode($meta))), $fields['id'], $settings);
  547.             if(isset($fields['desc']) && !empty($fields['desc'])) {
  548.                 echo '<div class="field_desc">' . $fields['desc'] . '</div>';
  549.             }
  550.             echo '</div></div>';
  551.  
  552.         }
  553.  
  554.         function addUpload($fields) {
  555.             $meta = (isset($fields['meta'])) ? $fields['meta'] : "";
  556.             $attachment_url = (is_numeric($meta)) ? $this->getAttachmenturl($meta) : $meta;
  557.             $form_field = '
  558.                <div id ="' . $fields['id'] . '" class="thumbnail aof-image-preview">';
  559.             if((!empty($meta))) {
  560.                 $form_field .=  '<i class="dashicons dashicons-no-alt img-remove"></i>';
  561.                 $form_field .=  '<image class="imgpreview_' . $fields['id'] .'" src="' . $attachment_url . '" />';
  562.             }
  563.             $form_field .= '<input class="aof_image_url" name="' . $fields['id'] . '" type="hidden" value="' . $attachment_url . '" /></div>';
  564.             $output = $this->fieldWrap($fields, $form_field);
  565.             echo $output;
  566.         }
  567.  
  568.         function addExport($fields) {
  569.             $getoption = $this->aofgetOptions( ALTER_OPTIONS_SLUG );
  570.             if(is_serialized($getoption) === false && is_array($getoption)) {
  571.                 $meta = serialize($getoption);
  572.             }
  573.             elseif(is_serialized($getoption)) {
  574.                 $meta = $getoption;
  575.             }
  576.             else {
  577.                 $meta = "";
  578.             }
  579.             $export_options = array();
  580.             $export_options['name'] = $fields['name'];
  581.             $export_options['id'] = $fields['id'];
  582.             $export_options['meta'] = $meta;
  583.             $this->addTextarea($export_options);
  584.         }
  585.  
  586.         function addImport($fields) {
  587.             $import_options = array();
  588.             $import_options['name'] = $fields['name'];
  589.             $import_options['id'] = "aof_import_settings";
  590.             $this->addTextarea($import_options);
  591.         }
  592.  
  593.         function saveBtn() {
  594.           ?>
  595.             <div class="save_options">
  596.               <input type="submit" name="alter_submit" value="<?php _e('Save Changes', 'alter'); ?>" class="button button-primary button-large" />
  597.               <!-- <input type="submit" name="aof_reset_options" value="Reset to Defaults" class="button button-secondary button-large" /> -->
  598.             </div>
  599.           <?php
  600.         }
  601.  
  602.         function fieldWrap($args, $field) {
  603.             if(isset($args['id']) && !empty($args['id'])) {
  604.                 $label = $args['id'];
  605.             }
  606.             else {
  607.                 $label = $this->createSlug($args['name']);
  608.             }
  609.             $output = '<div class="field_wrap">';
  610.             $output .= '<div class="label"><label for="' . $label . '">' . $args['name'] . '</label></div>';
  611.             $output .= '<div class="field_content">';
  612.             $output .= $field;
  613.             if(isset($args['desc']) && !empty($args['desc'])) {
  614.                 $output .= '<div class="field_desc">' . $args['desc'] . '</div>';
  615.             }
  616.             $output .= '</div></div>';
  617.             return $output;
  618.         }
  619.  
  620.         function formwrapStart() {
  621.             echo '<form method="post" name="aof_options_framework" class="aof_options_framework clearfix" id="aof_options_framework" action="" enctype="multipart/form-data">';
  622.         }
  623.  
  624.         function formwrapEnd() {
  625.             echo '<input type="hidden" name="aof_options_save" value="saveoptions" />';
  626.             wp_nonce_field( 'aof_options_form', 'aof_options_nonce' );
  627.             echo '</form>';
  628.         }
  629.  
  630.         function validateInputs($data, $type = NULL) {
  631.             if($type == "text") {
  632.                $output = sanitize_text_field( $data );
  633.             }
  634.             elseif($type == "textarea") {
  635.                 $output = esc_textarea( $data );
  636.             }
  637.             else {
  638.                 $output = stripslashes( trim($data) );
  639.             }
  640.             return $output;
  641.         }
  642.  
  643.         function createSlug($arg) {
  644.             $slug = trim(strtolower($arg));
  645.             $slug = str_replace(' ', '_', $slug);
  646.             $slug = preg_replace('/[^a-zA-Z0-9]/', '_', $slug);
  647.             return $slug;
  648.         }
  649.  
  650.         function getAttachmenturl($attc_id, $size='full') {
  651.             global $switched, $wpdb;
  652.             $imageAttachment = "";
  653.             if ( is_numeric( $attc_id ) ) {
  654.                 if($this->config['multi'] === true) {
  655.                     switch_to_blog(1);
  656.                     $imageAttachment = wp_get_attachment_image_src( $attc_id, $size );
  657.                     restore_current_blog();
  658.                 }
  659.                 else $imageAttachment = wp_get_attachment_image_src( $attc_id, $size );
  660.                 return $imageAttachment[0];
  661.             }
  662.         }
  663.  
  664.         /**
  665.         * Function to get default options
  666.         */
  667.        function getDefaultOptions() {
  668.          $fields_array = $this->config['aof_fields']['aof_fields'];
  669.          if( is_array($fields_array) && !empty($fields_array) ) {
  670.            foreach($fields_array as $field) {
  671.               if(isset($field['id']) && !in_array($field['type'], $this->do_not_save)) {
  672.                   $default_value = ( isset($field['default']) && !empty($field['default']) ) ? $field['default'] : "";
  673.                   if($field['type'] == "multicheck") {
  674.                       $multicheck = array();
  675.                       if(is_array($default_value)) {
  676.                           foreach($default_value as $options) {
  677.                               $multicheck[] = $options;
  678.                           }
  679.                           $save_data[$field['id']] = $multicheck;
  680.                       }
  681.                     }
  682.                     elseif($field['type'] == "typography") {
  683.                       $typography = array();
  684.                       if(is_array($default_value)) {
  685.                           foreach($default_value as $typo_name => $typo_value) {
  686.                               $typography[$typo_name] = $typo_value;
  687.                           }
  688.                           $save_data[$field['id']] = $typography;
  689.                       }
  690.                     }
  691.                     else {
  692.                       $save_data[$field['id']] = $default_value;
  693.                     }
  694.               }
  695.            }
  696.            return $save_data;
  697.          }
  698.          else return false;
  699.        }
  700.  
  701.         /**
  702.         * Function to insert default values
  703.         */
  704.         function aofLoaddefault($reset=false) {
  705.             $default_options = $this->aofgetOptions( ALTER_OPTIONS_SLUG );
  706.             if ( false === $default_options || empty($default_options) || $reset === true) {
  707.                 $default_options = $this->getDefaultOptions();
  708.                 if(!empty($default_options)) {
  709.                     if($this->config['multi'] === true) {
  710.                         update_site_option( ALTER_OPTIONS_SLUG, $default_options );
  711.                     }
  712.                     else {
  713.                         update_option( ALTER_OPTIONS_SLUG, $default_options );
  714.                     }
  715.                 }
  716.             }
  717.  
  718.         }
  719.  
  720.         /**
  721.         * Function to show notices for plugin actions
  722.         */
  723.         function adminNotices() {
  724.             if( isset($_GET['status']) && $_GET['status'] == "updated") {
  725.                 $message = __( 'Settings saved.', 'alter');
  726.                 echo "<div class='updated'><p>{$message}</p></div>";
  727.             }
  728.             if( isset($_GET['status']) && $_GET['status'] == "error") {
  729.                 $message = __( 'Error: Settings not saved.', 'alter');
  730.                 echo "<div class='error'><p>{$message}</p></div>";
  731.             }
  732.         }
  733.  
  734.  
  735.     }
  736. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement