/**
  * The flexipages() template function
  */
 function flexipages($args = array())
 {
     $options = array();
     if (is_string($args)) {
         $key_value = explode('&', $args);
         foreach ($key_value as $value) {
             $x = explode('=', $value);
             $options[$x[0]] = $x[1];
             // $options['key'] = 'value';
         }
     } else {
         if (is_array($args)) {
             $options = $args;
         }
     }
     $flexipages = new Flexi_Pages($options);
     if (isset($options['dropdown']) && $options['dropdown']) {
         $display = $flexipages->get_dropdown();
     } else {
         $display = $flexipages->get_list();
     }
     if (isset($options['echo']) && !$options['echo']) {
         return $display;
     } else {
         echo $display;
     }
 }
 /**
  * Front end output
  *
  * @see WP_Widget::widget()
  *
  * @param array $args     Widget arguments.
  * @param array $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     if ($instance) {
         $options = $instance;
     } else {
         // Default options
         $options = $this->default_widget_options();
     }
     $flexi_pages_args = array('sort_column' => $options['sort_column'], 'sort_order' => $options['sort_order'], 'show_date' => $options['show_date'], 'date_format' => $options['date_format']);
     if ($options['exinclude_values']) {
         if ('include' == $options['exinclude']) {
             $flexi_pages_args['include'] = $options['exinclude_values'];
         } else {
             $flexi_pages_args['exclude'] = $options['exinclude_values'];
         }
     }
     if ($options['show_subpages_check']) {
         if (2 == intval($options['show_subpages']) || -2 == intval($options['show_subpages']) || -2 == intval($options['depth'])) {
             $flexi_pages_args['show_subpages'] = 2;
         } else {
             if (3 == intval($options['show_subpages']) || -3 == intval($options['show_subpages']) || -3 == intval($options['depth'])) {
                 $flexi_pages_args['show_subpages'] = 3;
             } else {
                 $flexi_pages_args['show_subpages'] = 1;
             }
         }
     } else {
         $flexi_pages_args['show_subpages'] = 0;
     }
     if ($options['hierarchy']) {
         $flexi_pages_args['hierarchy'] = 1;
         $flexi_pages_args['depth'] = intval($options['depth']);
     } else {
         $flexi_pages_args['hierarchy'] = 0;
         $flexi_pages_args['depth'] = 0;
     }
     if ($options['show_home_check']) {
         $flexi_pages_args['show_home'] = $options['show_home'] ? $options['show_home'] : __('Home', 'flexipages');
     }
     // To-do frame the options to be passed to the Flexi_Pages constructor
     // echo "<pre>"; print_r($flexi_pages_args); echo "</pre>";
     $flexipages = new Flexi_Pages($flexi_pages_args);
     if ($options['dropdown'] == 'on') {
         $flexipages_display = $flexipages->get_dropdown();
     } else {
         $flexipages_display = $flexipages->get_list();
     }
     if ($flexipages_display) {
         extract($args);
         echo $before_widget;
         if ($options['title']) {
             echo $before_title . apply_filters('the_title', $options['title']) . $after_title . "\n";
         }
         echo $flexipages_display;
         echo $after_widget;
     }
 }