Advertisement
Guest User

ModuleOptionAbstract.php

a guest
Sep 20th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.54 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @author : Jegtheme
  4.  */
  5. namespace EPIC\Module;
  6.  
  7. abstract Class ModuleOptionAbstract
  8. {
  9.     protected static $instance;
  10.  
  11.     protected $options = array();
  12.  
  13.     public static function getInstance()
  14.     {
  15.         $class = get_called_class();
  16.  
  17.         if (!isset(self::$instance[$class]))
  18.         {
  19.             self::$instance[$class] = new $class();
  20.         }
  21.  
  22.         return self::$instance[$class];
  23.     }
  24.  
  25.     protected function __construct()
  26.     {
  27.         $this->setup_hook();
  28.     }
  29.  
  30.     public function get_options()
  31.     {
  32.         if ( empty( $this->options ) ) {
  33.             $this->set_options();
  34.         }
  35.  
  36.         return $this->options;
  37.     }
  38.  
  39.     public function setup_hook()
  40.     {
  41.         add_action('init', array($this, 'map_vc'));
  42.     }
  43.  
  44.     public function remove_description()
  45.     {
  46.         $options = array();
  47.  
  48.         foreach($this->options as $key => $option)
  49.         {
  50.             unset($option['description']);
  51.             $options[] = $option;
  52.         }
  53.  
  54.         return $options;
  55.     }
  56.  
  57.     public function map_vc()
  58.     {
  59.         if (class_exists('WPBakeryVisualComposerAbstract'))
  60.         {
  61.             $this->set_options();
  62.             $this->show_compatible_column();
  63.  
  64.             $vc_options['base']         = epic_get_shortcode_name_from_option(get_class($this));
  65.             $vc_options['params']       = $this->options;
  66.             $vc_options['name']         = $this->get_module_name();
  67.             $vc_options['category']     = $this->get_category();
  68.             $vc_options['icon']         = strtolower($vc_options['base']);
  69.             $vc_options['description']  = $this->get_module_name();
  70.             $vc_options['as_parent']    = $this->get_module_parent();
  71.             $vc_options['as_child']     = $this->get_module_child();
  72.  
  73.             if ( ! empty( $vc_options['as_parent'] ) )
  74.             {
  75.                 include_once 'modules-container.php';
  76.  
  77.                 $vc_options['js_view'] = 'VcColumnView';
  78.             }
  79.  
  80.             vc_map($vc_options);
  81.         }
  82.     }
  83.  
  84.     public function get_module_parent()
  85.     {
  86.         return '';
  87.     }
  88.  
  89.     public function get_module_child()
  90.     {
  91.         return '';
  92.     }
  93.  
  94.     public function show_compatible_column()
  95.     {
  96.         $option_group = isset($this->options[0]['group']) ? $this->options[0]['group'] : "";
  97.  
  98.  
  99.         $compatible_column = array(
  100.             'type'          => 'alert',
  101.             'param_name'    => 'compatible_column_notice',
  102.             'heading'       => esc_html__('Compatible Column: ', 'epic-ne') . implode($this->compatible_column(), ', '),
  103.             'description'   => esc_html__('Please check style / design tab to change Module / Block width and make it fit with your current column width', 'epic-ne'),
  104.             'group'         => $option_group,
  105.             'std'           => 'info'
  106.         );
  107.  
  108.         array_unshift($this->options, $compatible_column);
  109.     }
  110.  
  111.     public function set_content_filter_option($number = 10, $hide_number_post = false)
  112.     {
  113.         $dependency = array('element' => "sort_by", 'value' => array('post_type', 'latest','oldest','alphabet_asc','alphabet_desc','random','random_week','random_month','most_comment','most_comment_day','most_comment_week','most_comment_month','popular_post_day','popular_post_week','popular_post_month','popular_post','rate','like','share'));
  114.  
  115.         $this->options[] = array(
  116.             'type'          => 'dropdown',
  117.             'param_name'    => 'post_type',
  118.             'heading'       => esc_html__('Include Post Type', 'epic-ne'),
  119.             'description'   => esc_html__('Choose post type for this content.', 'epic-ne'),
  120.             'group'         => esc_html__('Content Filter', 'epic-ne'),
  121.             'std'           => 'post',
  122.             'value'         => epic_get_all_post_type(),
  123.             'dependency'    => $dependency
  124.         );
  125.  
  126.         if(!$hide_number_post)
  127.         {
  128.             $this->options[] = array(
  129.                 'type'          => 'slider',
  130.                 'param_name'    => 'number_post',
  131.                 'heading'       => esc_html__('Number of Post', 'epic-ne'),
  132.                 'description'   => esc_html__('Show number of post on this module.', 'epic-ne'),
  133.                 'group'         => esc_html__('Content Filter', 'epic-ne'),
  134.                 'min'           => 1,
  135.                 'max'           => 30,
  136.                 'step'          => 1,
  137.                 'std'           => $number,
  138.             );
  139.         }
  140.  
  141.         if($hide_number_post && $number > 0)
  142.         {
  143.             $this->options[] = array(
  144.                 'type'          => 'alert',
  145.                 'param_name'    => 'content_filter_number_alert',
  146.                 'heading'       => esc_html__('Number of post', 'epic-ne'),
  147.                 'description'   => sprintf(esc_html__('This module will require you to choose %s number of post.', 'epic-ne'), $number),
  148.                 'group'         => esc_html__('Content Filter', 'epic-ne'),
  149.                 'std'           => 'info',
  150.             );
  151.         }
  152.  
  153.         $this->options[] = array(
  154.             'type'          => 'number',
  155.             'param_name'    => 'post_offset',
  156.             'heading'       => esc_html__('Post Offset', 'epic-ne'),
  157.             'description'   => esc_html__('Number of post offset (start of content).', 'epic-ne'),
  158.             'group'         => esc_html__('Content Filter', 'epic-ne'),
  159.             'min'           => 0,
  160.             'max'           => 9999,
  161.             'step'          => 1,
  162.             'std'           => 0,
  163.             'dependency'    => $dependency
  164.         );
  165.  
  166.         $this->options[] = array(
  167.             'type'          => 'dropdown',
  168.             'param_name'    => 'unique_content',
  169.             'heading'       => esc_html__('Include into Unique Content Group', 'epic-ne'),
  170.             'description'   => esc_html__('Choose unique content option, and this module will be included into unique content group. It won\'t duplicate content across the group. Ajax loaded content won\'t affect this unique content feature.', 'epic-ne'),
  171.             'group'         => esc_html__('Content Filter', 'epic-ne'),
  172.             'std'           => 'disable',
  173.             'value'         => array(
  174.                 esc_html__('Disable', 'epic-ne')                       => 'disable',
  175.                 esc_html__('Unique Content - Group 1', 'epic-ne')      => 'unique1',
  176.                 esc_html__('Unique Content - Group 2', 'epic-ne')      => 'unique2',
  177.                 esc_html__('Unique Content - Group 3', 'epic-ne')      => 'unique3',
  178.                 esc_html__('Unique Content - Group 4', 'epic-ne')      => 'unique4',
  179.                 esc_html__('Unique Content - Group 5', 'epic-ne')      => 'unique5',
  180.             ),
  181.             'dependency'    => $dependency
  182.         );
  183.  
  184.         $this->options[] = array(
  185.             'type'          => 'multipost',
  186.             'param_name'    => 'include_post',
  187.             'heading'       => esc_html__('Include Post ID', 'epic-ne'),
  188.             'description'   => wp_kses(__("Tips :<br/> - You can search post id by inputing title, clicking search title, and you will have your post id.<br/>- You can also directly insert your post id, and click enter to add it on the list.", 'epic-ne'), wp_kses_allowed_html()),
  189.             'group'         => esc_html__('Content Filter', 'epic-ne'),
  190.             'std'           => '',
  191.             'dependency'    => $dependency
  192.         );
  193.  
  194.         $this->options[] = array(
  195.             'type'          => 'multipost',
  196.             'param_name'    => 'exclude_post',
  197.             'heading'       => esc_html__('Exclude Post ID', 'epic-ne'),
  198.             'description'   => wp_kses(__("Tips :<br/> - You can search post id by inputing title, clicking search title, and you will have your post id.<br/>- You can also directly insert your post id, and click enter to add it on the list.", 'epic-ne'), wp_kses_allowed_html()),
  199.             'group'         => esc_html__('Content Filter', 'epic-ne'),
  200.             'std'           => '',
  201.             'dependency'    => $dependency
  202.         );
  203.  
  204.         $this->options[] = array(
  205.             'type'          => 'multicategory',
  206.             'param_name'    => 'include_category',
  207.             'heading'       => esc_html__('Include Category', 'epic-ne'),
  208.             'description'   => esc_html__('Choose which category you want to show on this module.', 'epic-ne'),
  209.             'group'         => esc_html__('Content Filter', 'epic-ne'),
  210.             'std'           => '',
  211.         );
  212.  
  213.         $this->options[] = array(
  214.             'type'          => 'multicategory',
  215.             'param_name'    => 'exclude_category',
  216.             'heading'       => esc_html__('Exclude Category', 'epic-ne'),
  217.             'description'   => esc_html__('Choose excluded category for this module.', 'epic-ne'),
  218.             'group'         => esc_html__('Content Filter', 'epic-ne'),
  219.             'std'           => '',
  220.         );
  221.  
  222.         $this->options[] = array(
  223.             'type'          => 'multiauthor',
  224.             'param_name'    => 'include_author',
  225.             'heading'       => esc_html__('Author', 'epic-ne'),
  226.             'description'   => esc_html__('Write to search post author.', 'epic-ne'),
  227.             'group'         => esc_html__('Content Filter', 'epic-ne'),
  228.             'std'           => '',
  229.             'dependency'    => $dependency
  230.         );
  231.  
  232.         $this->options[] = array(
  233.             'type'          => 'multitag',
  234.             'param_name'    => 'include_tag',
  235.             'heading'       => esc_html__('Include Tags', 'epic-ne'),
  236.             'description'   => esc_html__('Write to search post tag.', 'epic-ne'),
  237.             'group'         => esc_html__('Content Filter', 'epic-ne'),
  238.             'std'           => '',
  239.         );
  240.  
  241.         $this->options[] = array(
  242.             'type'          => 'multitag',
  243.             'param_name'    => 'exclude_tag',
  244.             'heading'       => esc_html__('Exclude Tags', 'epic-ne'),
  245.             'description'   => esc_html__('Write to search post tag.', 'epic-ne'),
  246.             'group'         => esc_html__('Content Filter', 'epic-ne'),
  247.             'std'           => '',
  248.         );
  249.  
  250.         $this->options[] = array(
  251.             'type'          => 'dropdown',
  252.             'param_name'    => 'sort_by',
  253.             'heading'       => esc_html__('Sort by', 'epic-ne'),
  254.             'description'   =>
  255.                 wp_kses(__("Sort post by this option<br/>* <strong>Jetpack :</strong> Need <strong>Jetpack</strong> plugin & Stat module enabled.<br/>", 'epic-ne'), wp_kses_allowed_html()),
  256.             'group'         => esc_html__('Content Filter', 'epic-ne'),
  257.             'std'           => 'latest',
  258.             'value'         => array(
  259.                 esc_html__('Latest Post', 'epic-ne')                                      => 'latest',
  260.                 esc_html__('Oldest Post', 'epic-ne')                                      => 'oldest',
  261.                 esc_html__('Alphabet Asc', 'epic-ne')                                     => 'alphabet_asc',
  262.                 esc_html__('Alphabet Desc', 'epic-ne')                                    => 'alphabet_desc',
  263.                 esc_html__('Random Post', 'epic-ne')                                      => 'random',
  264.                 esc_html__('Random Post (7 Days)', 'epic-ne')                             => 'random_week',
  265.                 esc_html__('Random Post (30 Days)', 'epic-ne')                            => 'random_month',
  266.                 esc_html__('Most Comment', 'epic-ne')                                     => 'most_comment',
  267.                 esc_html__('Popular Post (1 Day - Jetpack)', 'epic-ne')                   => 'popular_post_jetpack_day',
  268.                 esc_html__('Popular Post (7 Days - Jetpack)', 'epic-ne')                  => 'popular_post_jetpack_week',
  269.                 esc_html__('Popular Post (30 Days - Jetpack)', 'epic-ne')                 => 'popular_post_jetpack_month',
  270.                 esc_html__('Popular Post (All Time - Jetpack)', 'epic-ne')                => 'popular_post_jetpack_all',
  271.             )
  272.         );
  273.     }
  274.  
  275.     public function set_style_option()
  276.     {
  277.         $width = array(
  278.             esc_html__('Auto', 'epic-ne')  => 'auto'
  279.         );
  280.  
  281.         if(in_array(4, $this->compatible_column())) {
  282.             $width = array_merge($width, array(
  283.                 esc_html__('4 Column Design ( 1 Block )', 'epic-ne')  => 4
  284.             ));
  285.         }
  286.  
  287.         if(in_array(8, $this->compatible_column())) {
  288.             $width = array_merge($width, array(
  289.                 esc_html__('8 Column Design ( 2 Block )', 'epic-ne')  => 8
  290.             ));
  291.         }
  292.  
  293.         if(in_array(12, $this->compatible_column())) {
  294.             $width = array_merge($width, array(
  295.                 esc_html__('12 Column Design ( 3 Block )', 'epic-ne')  => 12
  296.             ));
  297.         }
  298.  
  299.         $this->options[] = array(
  300.             'type'          => 'textfield',
  301.             'param_name'    => 'el_id',
  302.             'heading'       => esc_html__('Element ID','epic-ne'),
  303.             'description'   => wp_kses(sprintf(__('Enter element ID (Note: make sure it is unique and valid according to <a href="%s">w3c specification</a>).', 'epic-ne'), 'http://www.w3schools.com/tags/att_global_id.asp'), wp_kses_allowed_html()),
  304.             'group'         => esc_html__('Design', 'epic-ne'),
  305.         );
  306.  
  307.         $this->options[] = array(
  308.             'type'          => 'textfield',
  309.             'param_name'    => 'el_class',
  310.             'heading'       => esc_html__('Extra class name','epic-ne'),
  311.             'description'   => esc_html__('Style particular content element differently - add a class name and refer to it in custom CSS.', 'epic-ne'),
  312.             'group'         => esc_html__('Design', 'epic-ne'),
  313.         );
  314.  
  315.         if($this->show_color_scheme())
  316.         {
  317.             $this->options[] = array(
  318.                 'type'          => 'dropdown',
  319.                 'param_name'    => 'scheme',
  320.                 'heading'       => esc_html__('Element Color Scheme', 'epic-ne'),
  321.                 'description'   => esc_html__('choose element color scheme for your element ', 'epic-ne'),
  322.                 'group'         => esc_html__('Design', 'epic-ne'),
  323.                 'default'       => 'normal',
  324.                 'value'         => array(
  325.                     esc_html__('Light', 'epic-ne') => 'normal',
  326.                     esc_html__('Dark', 'epic-ne')  => 'alt'
  327.                 )
  328.             );
  329.         }
  330.  
  331.         $this->options[] = array(
  332.             'type'          => 'dropdown',
  333.             'param_name'    => 'column_width',
  334.             'heading'       => esc_html__('Block / Column Width', 'epic-ne'),
  335.             'description'   => esc_html__('Please choose width of column you want to use on this block. 1 Block represents 4 columns.', 'epic-ne'),
  336.             'group'         => esc_html__('Design', 'epic-ne'),
  337.             'std'           => 'auto',
  338.             'value'         => $width,
  339.         );
  340.  
  341.         $this->additional_style();
  342.  
  343.         $this->options[] = array(
  344.             'type'          => 'css_editor',
  345.             'param_name'    => 'css',
  346.             'heading'       => esc_html__('CSS Box', 'epic-ne'),
  347.             'group'         => esc_html__('Design', 'epic-ne'),
  348.         );
  349.     }
  350.  
  351.     public function additional_style() {}
  352.  
  353.     public function show_color_scheme()
  354.     {
  355.         return true;
  356.     }
  357.  
  358.     public function get_category()
  359.     {
  360.         return esc_html__('EPIC - Module', 'epic-ne');
  361.     }
  362.  
  363.     abstract public function set_options();
  364.     abstract public function get_module_name();
  365.     abstract public function compatible_column();
  366. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement