public static function general_shortcode($atts, $widget = true)
 {
     $atts = is_array($atts) ? $atts : array();
     $displayOptionsDefaults = CMA_Settings::getDisplayOptionsDefaults();
     $atts = CMA_Thread::sanitize_array($atts, array('limit' => array('int', 5), 'cat' => array('*', null), 'tag' => array('*', null), 'author' => array('string', null), 'contributor' => array('string', null), 'answered' => array('bool', null), 'resolved' => array('bool', null), 'sort' => array('string', CMA_Settings::getOption(CMA_Settings::OPTION_INDEX_ORDER_BY)), 'order' => array('string', 'desc'), 'tiny' => array('bool', false), 'form' => array('bool', $displayOptionsDefaults['form']), 'displaycategories' => array('bool', (bool) $displayOptionsDefaults['categories']), 'resolvedprefix' => array('bool', $displayOptionsDefaults['resolvedPrefix']), 'icons' => array('bool', $displayOptionsDefaults['icons']), 'pagination' => array('bool', $displayOptionsDefaults['pagination']), 'hidequestions' => array('bool', $displayOptionsDefaults['hideQuestions']), 'search' => array('bool', $displayOptionsDefaults['search']), 'votes' => array('bool', $displayOptionsDefaults['votes']), 'views' => array('bool', $displayOptionsDefaults['views']), 'answers' => array('bool', $displayOptionsDefaults['answers']), 'updated' => array('bool', $displayOptionsDefaults['updated']), 'authorinfo' => array('bool', $displayOptionsDefaults['authorinfo']), 'statusinfo' => array('bool', $displayOptionsDefaults['statusinfo']), 'tags' => array('bool', $displayOptionsDefaults['tags']), 'wrapperclass' => array('string', $displayOptionsDefaults['wrapperclass']), 'navbar' => array('bool', false), 'sortbar' => array('bool', false), 'ajax' => array('bool', true), 'showid' => array('bool', false), 'dateposted' => array('bool', false), 'showcontent' => array('bool', false), 'formontop' => array('bool', $displayOptionsDefaults['formontop']), 'subtree' => array('bool', $displayOptionsDefaults['subtree'])));
     if ($atts['tiny']) {
         $atts['pagination'] = false;
     }
     $search = esc_attr(CMA_AnswerController::$query->get('search'));
     $paged = esc_attr(CMA_AnswerController::$query->get('paged'));
     $questionsArgs = array('post_type' => CMA_Thread::POST_TYPE, 'post_status' => 'publish', 'posts_per_page' => $atts['limit'], 'paged' => $paged, 'orderby' => $atts['sort'], 'order' => $atts['order'], 'fields' => 'ids', 'widget' => true, 'tag' => empty($atts['tag']) ? isset($_GET["cmatag"]) ? $_GET["cmatag"] : '' : $atts['tag'], 'search' => $search);
     if (!is_null($atts['resolved'])) {
         $questionsArgs['meta_query'] = array(array('key' => CMA_Thread::$_meta['resolved'], 'value' => intval($atts['resolved'])));
     }
     if (!empty($atts['user_questions'])) {
         $questionsArgs['user_questions'] = $atts['user_questions'];
     }
     if (!empty($atts['author'])) {
         if (!is_numeric($atts['author'])) {
             if ($user = get_user_by('slug', $atts['author'])) {
                 $atts['author'] = $user->ID;
             } else {
                 $atts['author'] = null;
             }
         }
         $questionsArgs['author'] = $atts['author'];
     }
     if (!empty($atts['contributor']) and !is_numeric($atts['contributor'])) {
         if ($user = get_user_by('slug', $atts['contributor'])) {
             $atts['contributor'] = $user->ID;
         } else {
             $atts['contributor'] = null;
         }
     }
     $category = null;
     if (!empty($atts['cat'])) {
         // there may be multiple categories separated by commas
         if (!is_array($atts['cat'])) {
             $categories = explode(',', $atts['cat']);
         } else {
             $categories = $atts['cat'];
         }
         $categories = array_filter($categories);
         $categoriesSlugs = array();
         foreach ($categories as $i => $cat) {
             if (!is_scalar($cat)) {
                 continue;
             }
             if (preg_match('/^[0-9]+$/', $cat)) {
                 $category = get_term($cat, CMA_Category::TAXONOMY);
                 $categoriesSlugs[] = $category->slug;
                 $catId = $cat;
             } else {
                 if ($category = get_term_by('slug', trim($cat), CMA_Category::TAXONOMY)) {
                     $catId = $category->term_id;
                     $categoriesSlugs[] = $category->slug;
                 } else {
                     $catId = false;
                 }
             }
             if ($catId) {
                 if (empty($questionsArgs['tax_query'][0])) {
                     $questionsArgs['tax_query'][0] = array('taxonomy' => CMA_Category::TAXONOMY, 'field' => 'term_id', 'terms' => array($catId));
                 } else {
                     $questionsArgs['tax_query'][0]['terms'][] = $catId;
                 }
             }
         }
         $atts['cat'] = implode(',', $categoriesSlugs);
     }
     $customWhereCallback = function ($val) use($atts) {
         global $wpdb;
         if (!is_null($atts['answered'])) {
             $val .= CMA_AnswerController::registerCommentsFiltering($val, $atts['answered'] ? 'ans' : 'unans');
         }
         if (!empty($atts['contributor'])) {
             $val .= $wpdb->prepare(" AND (post_author = %d OR ID IN (\n        \t\t\tSELECT wc.comment_post_ID FROM {$wpdb->comments} wc\n        \t\t\t\tWHERE wc.user_id = %d\n        \t\t\t\tAND wc.comment_approved = 1\n        \t\t\t))", $atts['contributor'], $atts['contributor']);
         }
         $val .= " AND {$wpdb->posts}.ID IS NOT NULL";
         return $val;
     };
     $questionsArgs = apply_filters('cma_questions_shortcode_query_args', $questionsArgs, $atts);
     add_filter('posts_where_request', $customWhereCallback);
     add_filter('posts_where_request', array('CMA_AnswerController', 'categoryAccessFilter'));
     $q = CMA_Thread::customOrder(new WP_Query(), $atts['sort']);
     foreach ($questionsArgs as $key => $val) {
         $q->set($key, $val);
     }
     $questions = array_map(array('CMA_Thread', 'getInstance'), $q->get_posts());
     $maxNumPages = $atts['maxNumPages'] = $q->max_num_pages;
     $paged = $q->query_vars['paged'];
     remove_filter('posts_where_request', $customWhereCallback);
     remove_filter('posts_where_request', array('CMA_AnswerController', 'categoryAccessFilter'));
     $displayOptions = array('hideQuestions' => $atts['hidequestions'], 'tags' => !$atts['tiny'], 'pagination' => !$atts['tiny'] && $atts['pagination'], 'form' => $atts['form'], 'categories' => $atts['displaycategories'], 'search' => $atts['search'], 'votes' => $atts['votes'], 'views' => $atts['views'], 'answers' => $atts['answers'], 'updated' => $atts['updated'], 'authorinfo' => $atts['authorinfo'], 'tags' => $atts['tags'], 'statusinfo' => $atts['statusinfo'], 'wrapperclass' => $atts['wrapperclass'], 'navbar' => $atts['navbar'], 'sortbar' => $atts['sortbar'], 'formontop' => $atts['formontop'], 'resolvedPrefix' => $atts['resolvedprefix'], 'icons' => $atts['icons'], 'showid' => $atts['showid'], 'dateposted' => $atts['dateposted'], 'showcontent' => $atts['showcontent'], 'subtree' => $atts['subtree']);
     $checkPermissions = true;
     $widget = true;
     $category = CMA_Category::getInstance($category);
     $options = array_merge($atts, compact('displayOptions', 'catId', 'maxNumPages', 'paged', 'widget', 'search', 'checkPermissions'));
     $options['checkPermissions'] = false;
     $options = apply_filters('cma_questions_shortcode_widget_options', $options);
     $widgetCacheId = $options['widgetCacheId'] = CMA_AnswerController::saveWidgetOptions($options);
     $options['questions'] = $questions;
     CMA_BaseController::loadScripts();
     $result = CMA_BaseController::_loadView('answer/widget/questions', $options);
     if ($atts['ajax']) {
         $result = '<div class="cma-widget-ajax" data-widget-cache-id="' . $widgetCacheId . '">' . $result . '</div>';
     }
     return $result;
 }
 /**
  * Get the thread's permalink.
  * 
  * @param array $query Query args.
  * @param string $append Append a string to the URL path.
  * @return string
  */
 public function getPermalink(array $query = array(), $backlink = false, $append = '')
 {
     $result = get_permalink($this->getId());
     if (strlen($append) > 0) {
         $result .= $append;
     }
     $query = CMA_Thread::sanitize_array($query, array('ajax' => array('int', null), 'post_id' => array('int', null), 'sort' => array('string', null), CMA_AnswerController::PARAM_EDIT_ANSWER_ID => array('int', null), CMA_AnswerController::PARAM_EDIT_QUESTION_ID => array('int', null), CMA_AnswerController::PARAM_RESOLVE_QUESTION_ID => array('int', null)));
     if ($backlink === true and CMA_Settings::getOption(CMA_Settings::OPTION_BACKLINK_PARAM_ENABLED)) {
         $query['backlink'] = base64_encode($_SERVER['REQUEST_URI']);
     }
     $query = array_filter($query);
     if (!empty($query)) {
         $result = add_query_arg(urlencode_deep($query), $result);
     }
     return $result;
 }