static function indexQuestionForm($catId, $place) { if (CMA_Settings::getOption(CMA_Settings::OPTION_QUESTION_FORM_BUTTON)) { $url = home_url('question/add/'); echo CMA_BaseController::_loadView('answer/widget/question-form-button', compact('url')); } else { echo CMA_BaseController::_loadView('answer/widget/question-form', compact('catId')); } }
function getWidgetContent($instance) { global $wpdb; $atts = shortcode_atts(array('title' => self::getDefaultTitle(), 'show_questions' => 1, 'show_answers' => 1, 'show_comments' => 1, 'show_users' => 1), $instance); $questionsNumber = number_format($wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s", CMA_Thread::POST_TYPE, 'publish')), 0); $answersNumber = number_format($wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->comments} WHERE comment_type = %s AND comment_approved = 1", CMA_Answer::COMMENT_TYPE)), 0); $commentsNumber = number_format($wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->comments} WHERE comment_type = %s AND comment_approved = 1", CMA_Comment::COMMENT_TYPE)), 0); $usersNumber = number_format($wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->users} WHERE user_status = 0"), 0); return CMA_BaseController::_loadView('answer/widget/counters', compact('atts', 'questionsNumber', 'answersNumber', 'commentsNumber', 'usersNumber')); }
static function shortcode($atts = array()) { $atts = shortcode_atts(array('title' => 0, 'backlink' => 1, 'cat' => null), $atts); CMA_BaseController::loadScripts(); if (CMA_Thread::canPostQuestions()) { $post = $thread = null; $catId = $atts['cat']; $redirectAfterPost = '_thread'; $displayOptions = array('hideTitle' => empty($atts['title']), 'showBacklink' => !empty($atts['backlink'])); return CMA_BaseController::_loadView('answer/widget/question-form', compact('post', 'thread', 'catId', 'displayOptions', 'redirectAfterPost')); } }
/** * User's questions list loop. */ static function profile_questions_loop() { // global $dwqa_options; // $submit_question_link = get_post_type_archive_link(CMA_Thread::POST_TYPE); // $questions = get_posts( array( // 'posts_per_page' => -1, // 'author' => bp_displayed_user_id(), // 'post_type' => CMA_Thread::POST_TYPE // )); $userId = bp_displayed_user_id(); // include CMA_PATH . '/views/frontend/buddypress/user-questions-loop.phtml'; echo CMA_BaseController::_loadView('buddypress/user-questions-loop', compact('userId')); }
static function _loadView($name, $options = array()) { return CMA_BaseController::_loadView('../backend/meta-box/' . $name, $options); }
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; }
protected static function replaceCommentSystem() { $currentPostId = null; $category = null; add_filter('comments_array', function ($comments, $postId) use(&$category) { $category = CMA_Category::getPostCommentsCategory($postId); if (is_main_query() and get_post_type() != CMA_Thread::POST_TYPE and !empty($category) and !empty($category->term_id)) { $posts = get_posts(array('category' => $category->term_id, 'post_type' => CMA_Thread::POST_TYPE)); return $posts; } else { return $comments; } }, 10, 2); add_filter('comments_template', function ($theme_template) use(&$category) { if (is_main_query() and get_post_type() != CMA_Thread::POST_TYPE and !empty($category) and !empty($category->term_id)) { return CMA_PATH . '/views/frontend/comment/comments.phtml'; } else { return $theme_template; } }); add_action('post_comment_status_meta_box-options', function ($post) { // Add select box with CMA categories $categories = CMA_Category::getCategoriesTree(null, 0, $onlyVisible = false); $currentCategory = CMA_Category::getPostCommentsCategory($post->ID); echo CMA_BaseController::_loadView('../backend/hooks/post_comment_status_meta_box', compact('categories', 'post', 'currentCategory')); }); add_action('save_post', function ($postId) { // Save CMA category ID for post/page if (isset($_POST['cma_category'])) { if (empty($_POST['cma_category'])) { wp_set_post_terms($postId, array(), CMA_Category::TAXONOMY); } else { if ($_POST['cma_category'] == 'new') { if (!empty($_POST['cma_category_name'])) { $category = (object) wp_insert_term($_POST['cma_category_name'], CMA_Category::TAXONOMY); clean_term_cache(array(), CMA_Category::TAXONOMY); } } else { $category = get_term($_POST['cma_category'], CMA_Category::TAXONOMY, OBJECT); } } if (!empty($category) and !empty($category->term_id)) { CMA_Category::setPostCommentsCategoryId($postId, $category->term_id); } } }, 10); add_action('save_page', function ($postId) { // Save CMA category ID for post/page if (isset($_POST['cma_category'])) { if (empty($_POST['cma_category'])) { wp_set_post_terms($postId, array(), CMA_Category::TAXONOMY); } else { if ($_POST['cma_category'] == 'new') { if (!empty($_POST['cma_category_name'])) { $category = (object) wp_insert_term($_POST['cma_category_name'], CMA_Category::TAXONOMY); clean_term_cache(array(), CMA_Category::TAXONOMY); } } else { $category = get_term($_POST['cma_category'], CMA_Category::TAXONOMY, ARRAY_A); } } if (!empty($category) and !empty($category->term_id)) { CMA_Category::setPostCommentsCategoryId($postId, $category->term_id); } } }, 10); }
function getWidgetContent($args) { $questions = $this->questions; return CMA_BaseController::_loadView('answer/widget/related-questions', compact('questions')); }
public static function showPagination($arguments = array(), $base = null) { if (empty($base)) { $base = get_post_type_archive_link(CMA_Thread::POST_TYPE); } if (strpos($base, '?') !== false) { $base = str_replace('?', 'page/%#%/?', $base); } else { $base .= 'page/%#%/'; } $params = array('maxNumPages' => isset($arguments['maxNumPages']) ? $arguments['maxNumPages'] : self::$query->max_num_pages, 'paged' => isset($arguments['paged']) ? $arguments['paged'] : self::$query->get('paged'), 'base' => $base); unset($arguments['maxNumPages']); $params['add_args'] = array_filter($arguments); // var_dump($params); $pagination = CMA_BaseController::_loadView('answer/widget/pagination', $params); return $pagination; }