static function overrideTemplate($template) { if (get_query_var('CMA-question-add')) { $tempalte = self::prepareSinglePage($title = CMA_Labels::getLocalized('ask_a_question'), $content = '', $newQuery = true); } return $template; }
static function ajaxHandler() { $response = array('success' => 0, 'message' => 'An error occurred.'); if (CMA_Settings::getOption(CMA_Settings::OPTION_NEW_QUESTION_NOTIFY_EVERYBODY_OPTINOUT)) { if (isset($_POST['nonce']) and wp_verify_nonce($_POST['nonce'], 'cma_follow')) { if (CMA_ThreadNewsletter::isNewsletterFollower()) { if (CMA_Settings::getOption(CMA_Settings::OPTION_NEW_QUESTION_NOTIFY_EVERYBODY_ENABLED)) { CMA_ThreadNewsletter::addUserToNewsletterBlacklist(); } CMA_ThreadNewsletter::removeUserFromNewsletterWhitelist(); $response = array('success' => 1, 'message' => CMA_Labels::getLocalized('newsletter_new_therads_disabled_success')); } else { CMA_ThreadNewsletter::removeUserFromNewsletterBlacklist(); CMA_ThreadNewsletter::addUserToNewsletterWhitelist(); $response = array('success' => 1, 'message' => CMA_Labels::getLocalized('newsletter_new_therads_enabled_success')); } } } header('content-type: application/json'); echo json_encode($response); exit; }
/** * Create new comment. * * @param string $content * @param int $userId * @param int $threadId * @param int $answerId (optional) * @throws Exception * @return CMA_Comment */ public static function create($content, $userId, $threadId, $answerId = null) { $user = get_userdata($userId); if (empty($userId) or empty($user)) { throw new Exception(CMA::__('Invalid user.')); } $thread = CMA_Thread::getInstance($threadId); if (!$thread or !$thread->isVisible()) { throw new Exception(CMA::__('You have no permission to post this comment.')); } if ($answerId) { $answer = CMA_Answer::getById($answerId); if (!$answer or !$answer->isVisible()) { throw new Exception(CMA::__('You have no permission to post this comment.')); } } $content = str_replace(';)', ':)', strip_tags($content)); if (empty($content)) { throw new Exception(CMA::__('Content cannot be empty')); } if (($badWord = CMA_BadWords::filterIfEnabled($content)) !== false) { throw new Exception(sprintf(CMA_Labels::getLocalized('msg_content_includes_bad_word'), $badWord)); } $approved = CMA_Settings::getOption(CMA_Settings::OPTION_COMMENTS_AUTO_APPROVE) || CMA_Thread::isAuthorAutoApproved($userId) ? 1 : 0; $comment = new self(array('comment_post_ID' => $threadId, 'comment_author' => $user->display_name, 'comment_author_email' => $user->user_email, 'comment_author_IP' => $_SERVER['REMOTE_ADDR'], 'comment_parent' => intval($answerId), 'comment_content' => apply_filters('comment_text', $content), 'comment_approved' => intval($approved), 'comment_date' => current_time('mysql'), 'comment_type' => self::COMMENT_TYPE, 'user_id' => $userId)); do_action('cma_comment_post_before', $comment); if ($comment->save()) { do_action('cma_comment_post_after', $comment); if ($approved) { $comment->sendNotifications(); } else { wp_notify_moderator($comment->getId()); } return $comment; } else { throw new Exception(CMA::__('Failed to add comment.')); } }
/** * Widget options form * @param WP_Widget $instance */ public function form($instance) { $instance = wp_parse_args((array) $instance, array('title' => '', 'limit' => 5, 'sort' => CMA_Settings::getOption(CMA_Settings::OPTION_INDEX_ORDER_BY), 'order' => 'desc', 'cat' => '', 'author' => '', 'contributor' => '', 'answered' => null, 'resolved' => '', 'form' => false, 'pagination' => false, 'ajax' => false, 'formOnTop' => false, 'displaySearch' => false, 'displayTags' => false, 'displayCategories' => true, 'displayResolvedPrefix' => true, 'displayIcons' => true, 'displayViews' => false, 'displayVotes' => false, 'displayAnswers' => false, 'displayUpdated' => true, 'displayAuthorInfo' => true, 'displayStatusInfo' => false, 'displayNavBar' => false, 'displayWrapperClass' => 'cma-sidebar-questions')); $title = $instance['title']; $limit = $instance['limit']; $sort = $instance['sort']; $order = $instance['order']; $cat = $instance['cat']; $author = $instance['author']; $contributor = $instance['contributor']; $answered = $instance['answered']; $resolved = $instance['resolved']; $form = $instance['form']; $pagination = $instance['pagination']; $ajax = $instance['ajax']; $formOnTop = $instance['formOnTop']; $displaySearch = $instance['displaySearch']; $displayTags = $instance['displayTags']; $displayCategories = $instance['displayCategories']; $displayResolvedPrefix = $instance['displayResolvedPrefix']; $displayIcons = $instance['displayIcons']; $displayViews = $instance['displayViews']; $displayVotes = $instance['displayVotes']; $displayAnswers = $instance['displayAnswers']; $displayUpdated = $instance['displayUpdated']; $displayAuthorInfo = $instance['displayAuthorInfo']; $displayStatusInfo = $instance['displayStatusInfo']; $displayNavBar = $instance['displayNavBar']; $displayWrapperClass = $instance['displayWrapperClass']; ?> <p> <label for="<?php echo esc_attr($this->get_field_id('title')); ?> "> Title: <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?> " name="<?php echo esc_attr($this->get_field_name('title')); ?> " type="text" value="<?php echo esc_attr($title); ?> " /> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('limit')); ?> "> Limit: <input class="widefat" id="<?php echo esc_attr($this->get_field_id('limit')); ?> " name="<?php echo esc_attr($this->get_field_name('limit')); ?> " type="text" value="<?php echo esc_attr($limit); ?> " /> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('sort')); ?> "> Sort by: <select class="widefat" id="<?php echo esc_attr($this->get_field_id('sort')); ?> " name="<?php echo esc_attr($this->get_field_name('sort')); ?> "> <?php $options = array('newest' => 'orderby_newest', 'hottest' => 'orderby_hottest', 'views' => 'orderby_most_views', 'votes' => 'orderby_most_votes'); foreach ($options as $key => $name) { echo '<option value="' . $key . '"'; if ($key == $sort) { echo ' selected="selected"'; } echo '>' . CMA_Labels::getLocalized($name) . '</option>'; } ?> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('order')); ?> ">Sort order:<select class="widefat" id="<?php echo esc_attr($this->get_field_id('order')); ?> " name="<?php echo esc_attr($this->get_field_name('order')); ?> "> <option value=""<?php if (!strlen($order)) { echo ' selected="selected"'; } ?> >any</option> <option value="desc"<?php if ($order == 'desc') { echo ' selected="selected"'; } ?> >DESC</option> <option value="asc"<?php if ($order == 'asc') { echo ' selected="selected"'; } ?> >ASC</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('cat')); ?> ">Category: <select class="widefat" id="<?php echo esc_attr($this->get_field_id('cat')); ?> " name="<?php echo esc_attr($this->get_field_name('cat')); ?> "> <option value="">All categories</option> <?php $options = get_terms(CMA_Category::TAXONOMY, array('orderby' => 'name', 'hide_empty' => 0)); foreach ($options as $term) { echo '<option value="' . $term->term_id . '"'; if ($term->term_id == $cat) { echo ' selected="selected"'; } echo '>' . $term->name . '</option>'; } ?> </select> </label> </p> <div><p> <label for="<?php echo esc_attr($this->get_field_id('author')); ?> ">Author: <span class="user-name"><?php $user = null; if (!empty($author) and $user = get_user_by('slug', $author)) { echo esc_html($user->display_name); } else { echo 'any'; } ?> </span><span class="cma-user-remove"<?php if (empty($user)) { echo ' style="display:none"'; } ?> ><a href="#" class="btn-user-remove">remove</a></span></label><br /> <label><span style="display:inline-block;width:100px;">Find user:</span><input class="cma-users-search" type="text" /></label> <input id="<?php echo esc_attr($this->get_field_id('author')); ?> " name="<?php echo esc_attr($this->get_field_name('author')); ?> " type="hidden" value="<?php echo esc_attr($author); ?> " /> <ul class="searchUsersResults" style="display:none"></ul> </p></div> <div><p> <label for="<?php echo esc_attr($this->get_field_id('contributor')); ?> ">Contributor: <span class="user-name"><?php $user = null; if (!empty($contributor) and $user = get_user_by('slug', $contributor)) { echo esc_html($user->display_name); } else { echo 'any'; } ?> </span><span class="cma-user-remove"<?php if (empty($user)) { echo ' style="display:none"'; } ?> ><a href="#" class="btn-user-remove">remove</a></span></label><br /> <label><span style="display:inline-block;width:100px;">Find user:</span><input class="cma-users-search" type="text" /></label> <input id="<?php echo esc_attr($this->get_field_id('contributor')); ?> " name="<?php echo esc_attr($this->get_field_name('contributor')); ?> " type="hidden" value="<?php echo esc_attr($contributor); ?> " style="width:200px" /> <ul class="searchUsersResults" style="display:none"></ul> </p></div> <p> <label for="<?php echo esc_attr($this->get_field_id('answered')); ?> ">Answered filter:<select class="widefat" id="<?php echo esc_attr($this->get_field_id('answered')); ?> " name="<?php echo esc_attr($this->get_field_name('answered')); ?> "> <option value=""<?php if (!strlen($answered)) { echo ' selected="selected"'; } ?> >show all</option> <option value="0"<?php if (strlen($answered) and !$answered) { echo ' selected="selected"'; } ?> >show only unanswered</option> <option value="1"<?php if (strlen($answered) and $answered) { echo ' selected="selected"'; } ?> >show only answered</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('resolved')); ?> ">Resolved filter:<select class="widefat" id="<?php echo esc_attr($this->get_field_id('resolved')); ?> " name="<?php echo esc_attr($this->get_field_name('resolved')); ?> "> <option value=""<?php if (!strlen($resolved)) { echo ' selected="selected"'; } ?> >show all</option> <option value="0"<?php if (strlen($resolved) and !$resolved) { echo ' selected="selected"'; } ?> >show only unresolved</option> <option value="1"<?php if (strlen($resolved) and $resolved) { echo ' selected="selected"'; } ?> >show only resolved</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('displayCategories')); ?> ">Display categories:<select class="widefat" id="<?php echo esc_attr($this->get_field_id('displayCategories')); ?> " name="<?php echo esc_attr($this->get_field_name('displayCategories')); ?> "> <option value="0"<?php if (!$displayCategories) { echo ' selected="selected"'; } ?> >No</option> <option value="1"<?php if ($displayCategories) { echo ' selected="selected"'; } ?> >Yes</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('displayResolvedPrefix')); ?> ">Display [RESOLVED] prefix:<select class="widefat" id="<?php echo esc_attr($this->get_field_id('displayResolvedPrefix')); ?> " name="<?php echo esc_attr($this->get_field_name('displayResolvedPrefix')); ?> "> <option value="0"<?php if (!$displayResolvedPrefix) { echo ' selected="selected"'; } ?> >No</option> <option value="1"<?php if ($displayResolvedPrefix) { echo ' selected="selected"'; } ?> >Yes</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('displayIcons')); ?> ">Display icons:<select class="widefat" id="<?php echo esc_attr($this->get_field_id('displayIcons')); ?> " name="<?php echo esc_attr($this->get_field_name('displayIcons')); ?> "> <option value="0"<?php if (!$displayIcons) { echo ' selected="selected"'; } ?> >No</option> <option value="1"<?php if ($displayIcons) { echo ' selected="selected"'; } ?> >Yes</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('form')); ?> ">Show Form: <select class="widefat" id="<?php echo esc_attr($this->get_field_id('form')); ?> " name="<?php echo esc_attr($this->get_field_name('form')); ?> "> <option value="0"<?php if (!$form) { echo ' selected="selected"'; } ?> >No</option> <option value="1"<?php if ($form) { echo ' selected="selected"'; } ?> >Yes</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('pagination')); ?> ">Show Pagination: <select class="widefat" id="<?php echo esc_attr($this->get_field_id('pagination')); ?> " name="<?php echo esc_attr($this->get_field_name('pagination')); ?> "> <option value="0"<?php if (!$pagination) { echo ' selected="selected"'; } ?> >No</option> <option value="1"<?php if ($pagination) { echo ' selected="selected"'; } ?> >Yes</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('ajax')); ?> ">AJAX support: <select class="widefat" id="<?php echo esc_attr($this->get_field_id('ajax')); ?> " name="<?php echo esc_attr($this->get_field_name('ajax')); ?> "> <option value="0"<?php if (!$ajax) { echo ' selected="selected"'; } ?> >No</option> <option value="1"<?php if ($ajax) { echo ' selected="selected"'; } ?> >Yes</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('formOnTop')); ?> ">Show question form on top: <select class="widefat" id="<?php echo esc_attr($this->get_field_id('formOnTop')); ?> " name="<?php echo esc_attr($this->get_field_name('formOnTop')); ?> "> <option value="0"<?php if (!$formOnTop) { echo ' selected="selected"'; } ?> >No</option> <option value="1"<?php if ($formOnTop) { echo ' selected="selected"'; } ?> >Yes</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('displaySearch')); ?> ">Show Search: <select class="widefat" id="<?php echo esc_attr($this->get_field_id('displaySearch')); ?> " name="<?php echo esc_attr($this->get_field_name('displaySearch')); ?> "> <option value="0"<?php if (!$displaySearch) { echo ' selected="selected"'; } ?> >No</option> <option value="1"<?php if ($displaySearch) { echo ' selected="selected"'; } ?> >Yes</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('displayTags')); ?> ">Show Tags: <select class="widefat" id="<?php echo esc_attr($this->get_field_id('displayTags')); ?> " name="<?php echo esc_attr($this->get_field_name('displayTags')); ?> "> <option value="0"<?php if (!$displayTags) { echo ' selected="selected"'; } ?> >No</option> <option value="1"<?php if ($displayTags) { echo ' selected="selected"'; } ?> >Yes</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('displayViews')); ?> ">Show Views: <select class="widefat" id="<?php echo esc_attr($this->get_field_id('displayViews')); ?> " name="<?php echo esc_attr($this->get_field_name('displayViews')); ?> "> <option value="0"<?php if (!$displayViews) { echo ' selected="selected"'; } ?> >No</option> <option value="1"<?php if ($displayViews) { echo ' selected="selected"'; } ?> >Yes</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('displayVotes')); ?> ">Show Votes: <select class="widefat" id="<?php echo esc_attr($this->get_field_id('displayVotes')); ?> " name="<?php echo esc_attr($this->get_field_name('displayVotes')); ?> "> <option value="0"<?php if (!$displayVotes) { echo ' selected="selected"'; } ?> >No</option> <option value="1"<?php if ($displayVotes) { echo ' selected="selected"'; } ?> >Yes</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('displayAnswers')); ?> ">Show Answers: <select class="widefat" id="<?php echo esc_attr($this->get_field_id('displayAnswers')); ?> " name="<?php echo esc_attr($this->get_field_name('displayAnswers')); ?> "> <option value="0"<?php if (!$displayAnswers) { echo ' selected="selected"'; } ?> >No</option> <option value="1"<?php if ($displayAnswers) { echo ' selected="selected"'; } ?> >Yes</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('displayUpdated')); ?> ">Show Updated: <select class="widefat" id="<?php echo esc_attr($this->get_field_id('displayUpdated')); ?> " name="<?php echo esc_attr($this->get_field_name('displayUpdated')); ?> "> <option value="0"<?php if (!$displayUpdated) { echo ' selected="selected"'; } ?> >No</option> <option value="1"<?php if ($displayUpdated) { echo ' selected="selected"'; } ?> >Yes</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('displayAuthorInfo')); ?> ">Show Author: <select class="widefat" id="<?php echo esc_attr($this->get_field_id('displayAuthorInfo')); ?> " name="<?php echo esc_attr($this->get_field_name('displayAuthorInfo')); ?> "> <option value="0"<?php if (!$displayAuthorInfo) { echo ' selected="selected"'; } ?> >No</option> <option value="1"<?php if ($displayAuthorInfo) { echo ' selected="selected"'; } ?> >Yes</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('displayStatusInfo')); ?> ">Show Status: <select class="widefat" id="<?php echo esc_attr($this->get_field_id('displayStatusInfo')); ?> " name="<?php echo esc_attr($this->get_field_name('displayStatusInfo')); ?> "> <option value="0"<?php if (!$displayStatusInfo) { echo ' selected="selected"'; } ?> >No</option> <option value="1"<?php if ($displayStatusInfo) { echo ' selected="selected"'; } ?> >Yes</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('displayNavBar')); ?> ">Show Navigation Bar: <select class="widefat" id="<?php echo esc_attr($this->get_field_id('displayNavBar')); ?> " name="<?php echo esc_attr($this->get_field_name('displayNavBar')); ?> "> <option value="0"<?php if (!$displayNavBar) { echo ' selected="selected"'; } ?> >No</option> <option value="1"<?php if ($displayNavBar) { echo ' selected="selected"'; } ?> >Yes</option> </select> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('displayWrapperClass')); ?> "> Container Class: <input class="widefat" id="<?php echo esc_attr($this->get_field_id('displayWrapperClass')); ?> " name="<?php echo esc_attr($this->get_field_name('displayWrapperClass')); ?> " type="text" value="<?php echo esc_attr($displayWrapperClass); ?> " /> </label> </p> <style type="text/css"> .searchUsersResults {margin:0;padding:0;list-style:none;margin-left:101px;margin-top:-15px;border:solid 1px #ccc;padding:5px;width:200px;} .searchUsersResults li {margin:0;padding:0; cursor: pointer;} .cma-user-remove {float: right;} </style> <script type="text/javascript"> jQuery(function($) { $('.btn-user-remove').click(function() { var obj = $(this); obj.parents('div').find('input[type=hidden]').val(''); obj.parents('label').find('.user-name').html('any'); obj.parents('span').first().hide(); return false; }); var addHandler = function() { var item = $(this); var container = item.parents('div').first(); container.find('input[type=hidden]').val(item.text()); container.find('input[type=text]').val(''); container.find('.user-name').text(item.text()); container.find('.cma-user-remove').show(); container.find('.searchUsersResults').hide(); }; $('.cma-users-search').keyup(function() { var searchInput = $(this); var container = searchInput.parents('div').first(); var resultsContainer = container.find('.searchUsersResults'); var hiddenInput = container.find('input[type=hidden]'); clearTimeout(this.searchTimer); this.searchTimer = setTimeout(function() { var search = $.trim(searchInput.val()); if (search) { $.ajax({ url: 'admin.php', data: {page: 'CMA_settings_search_users', q: search}, success: function(data) { data = $.trim(data); resultsContainer.show(); if (data.length == 0) resultsContainer.html('No results'); else { var users = data.split("\n"); for (var i=0; i<users.length; i++) { var item = $('<li/>').text(users[i]); item.click(addHandler); resultsContainer.append(item); } } } }); } }, 500); }); }); </script> <?php }
function __construct() { parent::__construct(CMA_Labels::getLocalized(static::ERROR_MSG)); }
/** * Initialize custom Questions Index AJAX page. */ public static function initCustomQuestionsIndexPage() { if (!self::getCustomQuestionsIndexPage($publish = true) and CMA_Settings::getOption(CMA_Settings::OPTION_CREATE_AJAX_PAGE)) { $permalink = CMA_Settings::getOption(CMA_Settings::OPTION_ANSWERS_PERMALINK) . '-ajax'; $post = array('post_title' => CMA_Labels::getLocalized('index_page_title'), 'post_name' => $permalink, 'post_content' => '[cma-index]', 'post_author' => get_current_user_id(), 'post_status' => 'publish', 'post_type' => 'page', 'comment_status' => 'closed', 'ping_status' => 'closed'); $result = wp_insert_post($post); if (is_numeric($result)) { add_post_meta($result, self::CUSTOM_QUESTIONS_INDEX_PAGE_META_KEY, self::CUSTOM_QUESTIONS_INDEX_PAGE_META_VALUE); } } }
public function updateQuestionContent($userId, $title, $content) { global $wpdb; $errors = array(); $title = self::titleFilter($title); $content = self::contentFilter($content, $userId); self::validateTitle($title, $editId = $this->getId(), $errors); if (!CMA_Settings::getOption(CMA_Settings::OPTION_QUESTION_DESCRIPTION_OPTIONAL) && empty($content)) { $errors[] = CMA::__('Content cannot be empty'); } if (($badWord = CMA_BadWords::filterIfEnabled($content)) !== false) { $errors[] = sprintf(CMA_Labels::getLocalized('msg_content_includes_bad_word'), $badWord); } if (empty($errors)) { if ($this->getAuthorId() == $userId) { $update = array('ID' => $this->post->ID, 'post_content' => $content, 'post_title' => $title); if (!wp_update_post($update)) { $errors[] = 'Failed to update the question.'; } } else { $errors[] = 'Cannot edit question of another author.'; } } if (!empty($errors)) { throw new Exception(serialize($errors)); } else { do_action('cma_question_update_after', $this); return true; } }
public static function formatNotification($action, $item_id, $secondary_item_id, $total_items, $format = 'string') { $text = $link = null; switch ($action) { case self::ACTION_NOTIFICATION_THREAD: if ($thread = CMA_Thread::getInstance($item_id)) { $text = CMA_Labels::getLocalized('Question') . ': ' . sprintf('<a href="%s">%s</a>', esc_attr($thread->getPermalink()), esc_html($thread->getTitle())); $link = $thread->getPermalink(); } break; case self::ACTION_NOTIFICATION_ANSWER: if ($answer = CMA_Answer::getById($item_id) and $thread = $answer->getThread()) { $text = sprintf(CMA::__('Answer in thread %s'), sprintf('<a href="%s">%s</a>', esc_attr($thread->getPermalink()), esc_html($thread->getTitle()))) . ': ' . sprintf('<a href="%s">%s</a>', esc_attr($answer->getPermalink()), esc_html($answer->getExcerpt())); $link = $answer->getPermalink(); } break; } if (!is_null($text)) { if ('string' == $format) { return $text; } else { return array('text' => strip_tags($text), 'link' => $link); } } }
/** * Your __construct() method will contain configuration options for * your extension, and will pass them to parent::init() */ function __construct() { $categoryId = $this->getRelatedCategory(); $args = array('slug' => 'cm-answers', 'name' => CMA_Labels::getLocalized('Questions'), 'enable_nav_item' => !empty($categoryId)); parent::init($args); }
/** * 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 loadScripts() { wp_register_style('CMA-css', CMA_URL . '/views/resources/app.css', array(), CMA::version()); add_action('wp_head', array(__CLASS__, 'high_priority_style'), PHP_INT_MAX); add_action('wp_footer', array(__CLASS__, 'high_priority_style'), PHP_INT_MAX); wp_enqueue_style('dashicons'); $cmaVariables = array('CMA_URL' => get_post_type_archive_link(CMA_Thread::POST_TYPE), 'ajaxUrl' => admin_url('admin-ajax.php'), 'loaderBarUrl' => CMA_URL . '/views/resources/imgs/ajax-loader-bar.gif', 'loaderUrl' => CMA_URL . '/views/resources/imgs/ajax-loader.gif', 'navBarAutoSubmit' => CMA_Settings::getOption(CMA_Settings::OPTION_NAVBAR_AUTO_SUBMIT), 'bestAnswerRemoveOther' => CMA_Settings::getOption(CMA_Settings::OPTION_BEST_ANSWER_REMOVE_OTHER), 'bestAnswerRemoveOtherLabel' => CMA_Labels::getLocalized('best_answer_remove_other_confirm'), 'confirmThreadDelete' => CMA::__('Do you really want to delete this question?')); wp_enqueue_script('cma-script', CMA_RESOURCE_URL . 'script.js', array('jquery', 'cma-toast', 'jquery-ui-dialog', 'suggest'), false, true); wp_localize_script('cma-script', 'CMA_Variables', $cmaVariables); wp_enqueue_script('jquery'); wp_enqueue_script('cma-toast', CMA_RESOURCE_URL . 'toast/js/jquery.toastmessage.js', array('jquery'), false, true); wp_enqueue_style('cma-toast-css', CMA_RESOURCE_URL . 'toast/resources/css/jquery.toastmessage.css', array(), false); wp_enqueue_script('jquery-ui-dialog'); wp_enqueue_style("wp-jquery-ui-dialog"); wp_enqueue_script('suggest'); }
public static function answersTitle() { if ($authorSlug = self::_getParam('author')) { if ($user = get_user_by('slug', $authorSlug)) { return esc_html($user->display_name) . ' - ' . CMA_Labels::getLocalized('Answers'); } } }