/**
  * Render widget
  *
  * @param array $args
  * @param WP_Widget $instance
  */
 public function widget($args, $instance)
 {
     extract($args, EXTR_SKIP);
     echo $before_widget;
     $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
     if (!empty($title)) {
         echo $before_title . $title . $after_title;
     }
     foreach ($instance as $instanceKey => $intanceValue) {
         if (preg_match('/(display)(\\w+)/', $instanceKey, $matches) == 1) {
             $newKey = strtolower($matches[2]);
             $instance[$newKey] = $intanceValue;
             $instance['display' . $newKey] = $intanceValue;
             unset($instance[$instanceKey]);
         }
         if (strlen($intanceValue) == 0) {
             unset($instance[$instanceKey]);
         }
     }
     $instance['tiny'] = true;
     // WIDGET CODE GOES HERE
     echo CMA_Shortcodes::shortcode_questions($instance, true);
     echo $after_widget;
 }
 public static function bootstrap()
 {
     global $wp_query;
     // Create local reference to the main query:
     if (empty(self::$query)) {
         self::$query = $wp_query;
     }
     CMA_Thread::initAnonymousVotingCookie();
     self::initSessions();
     add_filter('preprocess_comment', function ($commentdata) {
         // Resolve conflict with Responsible Shop Theme
         $types = array(CMA_Answer::COMMENT_TYPE, CMA_Comment::COMMENT_TYPE, CMA_Thread::POST_TYPE);
         if (!empty($commentdata['comment_type']) and in_array($commentdata['comment_type'], $types)) {
             $className = 'white_label_themes';
             if (class_exists($className) and isset($GLOBALS['CORE']) and is_object($GLOBALS['CORE']) and get_class($GLOBALS['CORE']) == $className) {
                 remove_filter('preprocess_comment', array($GLOBALS['CORE'], '_preprocess_comment'));
             }
         }
         return $commentdata;
     }, 1);
     add_filter('comment_row_actions', array(__CLASS__, 'adminCommentRowActionsFilter'), 10, 2);
     // Initialize CMA fake page
     self::initFakePage();
     // Initialize custom Questions Index page
     CMA_Shortcodes::initCustomQuestionsIndexPage();
     CMA_RelatedQuestionsMetaBox::bootstrap();
     self::_addAdminPages();
     self::$_titles = get_option(self::OPTION_TITLES, array());
     $controllersDir = dirname(__FILE__);
     /*
      * Loop the controllers
      */
     foreach (scandir($controllersDir) as $name) {
         if ($name != '.' && $name != '..' && $name != basename(__FILE__) && strpos($name, 'Controller.php') !== false) {
             $controllerName = substr($name, 0, strpos($name, 'Controller.php'));
             $controllerClassName = CMA_PREFIX . $controllerName . 'Controller';
             $controller = strtolower($controllerName);
             include_once $controllersDir . DIRECTORY_SEPARATOR . $name;
             $controllerClassName::initialize();
             $args = array();
             /*
              * Loop the methods in each controller
              */
             foreach (get_class_methods($controllerClassName) as $methodName) {
                 if (strpos($methodName, 'Action') !== false && substr($methodName, 0, 1) != '_') {
                     $action = substr($methodName, 0, strpos($methodName, 'Action'));
                     $query_arg = self::_getQueryArg($controller, $action);
                     $newArgs = array('query_arg' => self::_getQueryArg($controller, $action), 'slug' => self::_getSlug($controller, $action), 'title' => self::_getTitle($controller, $action, true), 'viewPath' => self::_getViewPath($controller, $action), 'contentCallback' => array($controllerClassName, $methodName), 'controller' => $controller, 'action' => $action);
                     if (!isset($args[$query_arg])) {
                         $args[$query_arg] = array();
                     }
                     $args[$query_arg] = array_merge($args[$query_arg], $newArgs);
                 } elseif (strpos($methodName, 'Header') !== false && substr($methodName, 0, 1) != '_') {
                     $action = substr($methodName, 0, strpos($methodName, 'Header'));
                     $query_arg = self::_getQueryArg($controller, $action);
                     $newArgs = array('query_arg' => self::_getQueryArg($controller, $action), 'slug' => self::_getSlug($controller, $action), 'title' => self::_getTitle($controller, $action), 'viewPath' => self::_getViewPath($controller, $action), 'headerCallback' => array($controllerClassName, $methodName), 'controller' => $controller, 'action' => $action);
                     if (!isset($args[$query_arg])) {
                         $args[$query_arg] = array();
                     }
                     $args[$query_arg] = array_merge($args[$query_arg], $newArgs);
                 } elseif (strpos($methodName, 'Title') !== false && substr($methodName, 0, 1) != '_') {
                     $action = substr($methodName, 0, strpos($methodName, 'Title'));
                     $query_arg = self::_getQueryArg($controller, $action);
                     $newArgs = array('query_arg' => self::_getQueryArg($controller, $action), 'slug' => self::_getSlug($controller, $action), 'title' => self::_getTitle($controller, $action), 'viewPath' => self::_getViewPath($controller, $action), 'titleCallback' => array($controllerClassName, $methodName), 'controller' => $controller, 'action' => $action);
                     if (!isset($args[$query_arg])) {
                         $args[$query_arg] = array();
                     }
                     $args[$query_arg] = array_merge($args[$query_arg], $newArgs);
                 }
             }
             foreach ($args as $query_arg => $data) {
                 self::_registerAction($query_arg, $data);
             }
         }
     }
     if (is_admin() and basename($_SERVER['REQUEST_URI']) == 'edit-comments.php') {
         // Filter answers from wp comments list
         add_filter('comments_clauses', array(__CLASS__, 'filterWPCommentsList'));
     }
     self::registerPages();
     self::replaceCommentSystem();
 }
 /**
  * Initialize model
  */
 public static function init()
 {
     $post_type_args = array('has_archive' => TRUE, 'show_in_menu' => self::ADMIN_MENU, 'rewrite' => array('slug' => CMA_Settings::getOption(CMA_Settings::OPTION_ANSWERS_PERMALINK), 'with_front' => FALSE), 'supports' => array('title', 'editor', 'author'), 'hierarchical' => FALSE, 'taxonomies' => array('post_tag', CMA_Category::TAXONOMY));
     $plural = CMA_Labels::getLocalized('index_page_title');
     if (empty($plural)) {
         $plural = CMA_Labels::getLocalized('Questions');
     }
     self::registerPostType(self::POST_TYPE, 'Question', $plural, $plural, $post_type_args);
     add_filter('CMA_admin_parent_menu', create_function('$q', 'return "' . self::ADMIN_MENU . '";'));
     add_action('admin_menu', array(get_class(), 'registerAdminMenu'));
     $taxonomy_args = array('rewrite' => array('slug' => CMA_Settings::getOption(CMA_Settings::OPTION_ANSWERS_PERMALINK) . '/' . CMA_Settings::getOption(CMA_Settings::OPTION_CATEGORIES_URL_PART), 'with_front' => TRUE, 'show_ui' => TRUE, 'hierarchical' => false));
     self::registerTaxonomy(CMA_Category::TAXONOMY, array(self::POST_TYPE), 'CMA Category', 'CMA Categories', $taxonomy_args);
     add_action('generate_rewrite_rules', array(get_class(), 'fixCategorySlugs'));
     require_once CMA_PATH . '/lib/helpers/Shortcodes.php';
     CMA_Shortcodes::init();
 }
 protected static function _displayWidget()
 {
     if ($widgetOptions = self::restoreWidgetOptions()) {
         echo CMA_Shortcodes::general_shortcode($widgetOptions, true);
         exit;
     }
 }