Advertisement
Guest User

ModuleOptionAbstract

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