public static function changeTheAuthorLink($author) { $contributorId = self::getContributorAndId(); $user = $contributorId['user']; $url = CMA_BaseController::getContributorUrl($user); return $url; }
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; }
static function getOptOutUrl(CMA_Thread $thread, $type) { return CMA_BaseController::getUrl('newsletter', 'optout', array($type => $thread->getId(), 'token' => self::getOptOutToken($thread))); }
public static function displaySettingsPage() { $messages = array(); if (!empty($_POST['titles'])) { self::$_titles = array_map('stripslashes', $_POST['titles']); update_option(self::OPTION_TITLES, self::$_titles); $messages[] = __('Settings succesfully updated', 'cm-answers'); } $params = array(); $params = apply_filters('CMA_admin_settings', $params); extract($params); ob_start(); require CMA_PATH . '/views/backend/settings.phtml'; $content = ob_get_contents(); ob_end_clean(); self::displayAdminPage($content); }
protected static function createAuthorLink($user, $simple = false) { if (empty($user)) { return null; } if (CMA_Settings::getOption(CMA_Settings::OPTION_AUTHOR_LINK_ENABLED)) { $url = CMA_BaseController::getContributorUrl($user); if (!empty($url)) { $authorLink = sprintf('<a href="%s">%s</a>', esc_attr($url), esc_html($user->display_name)); } } if (empty($authorLink)) { $authorLink = '<span class="cma-author">' . esc_html($user->display_name) . '</span>'; } if (!$simple) { if (self::canSendPrivateQuestion($user->ID)) { $authorLink .= ' ' . self::createPrivateQuestionIcon($user->ID); } } return $authorLink; }
/** * Render widget * * @param array $args * @param WP_Widget $instance */ public function widget($args, $instance) { extract($args, EXTR_SKIP); if (empty($instance['title'])) { $instance['title'] = CMA::__(self::DEFAULT_TITLE); } if (empty($instance['limit'])) { $instance['limit'] = self::DEFAULT_LIMIT; } $title = apply_filters('widget_title', $instance['title']); $limit = $instance['limit']; $displayNumber = isset($instance['displayNumber']) ? $instance['displayNumber'] : self::DISPLAY_NUMBER_ANSWERS; echo $before_widget; if (!empty($title)) { echo $before_title . $title . $after_title; } ?> <div class="cma-tags-container"><?php $contributors = $this->getContributors($displayNumber, $limit); foreach ($contributors as $c) { echo '<div>'; if (empty($c->user_id)) { echo $c->display_name; } else { printf('<a href="%s">%s</a>', esc_attr(CMA_BaseController::getContributorUrl($c->user_id)), esc_html($c->display_name)); } if ($displayNumber != self::DISPLAY_NONE) { printf(' <span>%d %s</span>', intval($c->cnt), strtolower(CMA_Labels::getLocalized($displayNumber))); } echo '</div>'; } ?> </div> <?php echo $after_widget; }
public static function displaySettingsPage() { wp_enqueue_style('jquery-ui-tabs-css', CMA_URL . '/views/resources/jquery-ui-tabs.css'); wp_enqueue_script('jquery-ui-tabs', false, array(), false, true); wp_enqueue_script('cma-suggest-user', CMA_URL . '/views/resources/js/suggest-user.js', array('suggest', 'jquery')); $messages = array(); if (!empty($_POST['titles'])) { self::$_titles = array_map('stripslashes', $_POST['titles']); update_option(self::OPTION_TITLES, self::$_titles); $messages[] = CMA_Settings::__('Settings succesfully updated'); } if (!get_option('permalink_structure')) { // rewrite notice $messages[] = sprintf(CMA_Settings::__('Plugin pages will appear correctly if you choose non-default <a href="%s">permalink structure</a> in your Wordpress settings and enable URL rewrite rules.'), esc_attr(admin_url('options-permalink.php'))); } $params = apply_filters('CMA_admin_settings', array()); extract($params); ob_start(); require CMA_PATH . '/views/backend/settings.phtml'; self::displayAdminPage(ob_get_clean()); }
public static function displaySettingsPage() { // CSRF protection if (!empty($_POST) and (empty($_POST['nonce']) or !wp_verify_nonce($_POST['nonce'], self::ADMIN_SETTINGS))) { die('Invalid nonce'); } $messages = array(); if (!empty($_POST['titles'])) { self::$_titles = array_map('stripslashes', $_POST['titles']); update_option(self::OPTION_TITLES, self::$_titles); $messages[] = __('Settings succesfully updated', 'cm-answers'); } wp_enqueue_style('cma-settings', CMA_URL . '/views/resources/settings.css'); wp_enqueue_script('cma-backend', CMA_URL . '/views/resources/backend.js'); $params = array(); $params = apply_filters('CMA_admin_settings', $params); extract($params); ob_start(); require CMA_PATH . '/views/backend/settings.phtml'; $content = ob_get_contents(); ob_end_clean(); self::displayAdminPage($content); }
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; }