/** * Widget options form * @param WP_Widget $instance */ public function form($instance) { if (isset($instance['title'])) { $title = $instance['title']; } else { $title = CMA::__('Login'); } $limit = isset($instance['limit']) ? $instance['limit'] : 10; ?> <p> <label for="<?php echo esc_attr($this->get_field_name('title')); ?> "><?php _e('Title:'); ?> </label> <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); ?> " /> </p> <?php }
/** * settings_screen() is the catch-all method for displaying the content * of the edit, create, and Dashboard admin panels */ function settings_screen($group_id = NULL) { $categories = CMA_Category::getCategoriesTree(null, 0, $onlyVisible = false); $currentCategory = $this->getRelatedCategory(); $options = '<option value="">-- none --</option>'; foreach ($categories as $categoryId => $categoryName) { $options .= sprintf('<option value="%s"%s>%s</option>', esc_attr($categoryId), selected($categoryId, $currentCategory, false), esc_html($categoryName)); } printf('<p><label for="cma-category">%s</label> <select name="cma-category" id="cma-category">%s</select></p>', CMA::__('Related CM Answers category'), $options); }
public static function displayAdminWarning($class = null) { if (empty($class)) { $class = 'error'; } $reasons = ''; foreach (self::$checkConfigFilters as $filter => $msg) { if (!apply_filters($filter, FALSE)) { $reasons .= sprintf('<li>%s</li>', CMA::__($msg)); } } printf('<div class="%s"><p>%s</p><ul style="list-style:disc;margin:0 0 1em 2em;">%s</ul><p>%s</p></div>', esc_attr($class), CMA::__('<strong>CM Answers Pro</strong> would not integrate with the <strong>CM Micropayments</strong> plugin because of the following reasons:'), $reasons, sprintf('<a href="%s" class="button">%s</a>', esc_attr(admin_url('admin.php?page=cm-micropayment-platform-settings')), CMA::__('CM Micropayments Settings'))); }
public function getStatus() { return CMA::__($this->isApproved() ? 'approved' : 'pending'); }
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; } }
protected static function createNotifyLink($param, $id) { $page = CMA_BaseController::ADMIN_BP_NOTIFY; $url = sprintf('./?page=%s&%s=%d&nonce=%s&backlink=%s', urlencode($page), urlencode($param), urlencode($id), urlencode(wp_create_nonce($page)), urlencode(base64_encode($_SERVER['REQUEST_URI']))); return sprintf('<a href="%s" title="%s">%s</a>', esc_attr($url), esc_attr(CMA::__('Notify all users using BuddyPress notifications')), esc_html(CMA::__('Notify all BP users'))); }
public function getAuthorLink($simple = false) { if ($user = $this->getAuthor()) { return $simple ? $user->link : $user->richLink; } else { if ($author = $this->getCommentAuthor()) { return $author; } else { return CMA::__('unknown'); } } }
<?php if (!empty($term)) { $template = <<<HTML \t<tr class="form-field"> \t\t<th scope="row"><label for="cma_custom_fields">%s</label></th> \t\t<td>%s</td> \t</tr> HTML; } else { $template = <<<HTML \t<div class="form-field"> \t\t<label for="cma_custom_fields">%s</label> \t\t%s \t</div> HTML; } $items = ''; for ($i = 0; $i < CMA_Category::CUSTOM_FIELDS_NUMBER; $i++) { $items .= sprintf('<label>Custom field %d: <input type="text" name="%s[%d]" value="%s" /></label><br />', $i + 1, CMA_CategoryController::FIELD_CUSTOM_FIELDS, $i, $fields[$i]); } $content = <<<HTML \t<div class="cma_custom_fields"> \t\t%s \t\t<input type="hidden" name="%s" value="%s" /> \t</div> HTML; $content = sprintf($content, $items, CMA_CategoryController::NONCE_CUSTOM_FIELDS, wp_create_nonce(CMA_CategoryController::NONCE_CUSTOM_FIELDS)); printf($template, CMA::__('Custom fields for new questions'), $content);
/** * 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']; echo $before_widget; if (!empty($title)) { echo $before_title . $title . $after_title; } ?> <div class="cma-tags-container"> <?php $terms = self::get_terms_by_post_type(array('post_tag'), array('cma_thread')); if (!empty($terms)) { $qs = '?'; if (isset($_GET["sort"])) { $qs .= 'sort=' . urlencode($_GET["sort"]) . "&"; } if (isset($_GET["s"])) { $qs .= 's=' . urlencode($_GET["s"]) . "&"; } foreach ($terms as $term) { $url = get_post_type_archive_link(CMA_Thread::POST_TYPE) . $qs . 'cmatag=' . urlencode($term->slug); printf('<div><a href="%s">%s</a> <span>(%d)</span></div>', esc_attr($url), esc_html($term->name), esc_html($term->cnt)); if (--$limit <= 0) { break; } } } else { echo 'No tags'; } ?> </div> <?php echo $after_widget; }
/** * 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; }
static function getDefaultTitle() { return CMA::__('Answers Stats'); }
public static function getLocalized($labelKey) { return CMA::__(self::getLabel($labelKey)); }
protected static function _processCommentDelete() { header('content-type: application/json'); $response = array('success' => 0, 'msg' => CMA::__('An error occured.')); $commentId = self::_getParam('cma-comment-id'); if (empty($_POST['nonce']) or !wp_verify_nonce($_POST['nonce'], 'cma_comment_delete')) { $response['msg'] = CMA::__('Invalid nonce.'); } else { if ($commentId and $comment = CMA_Comment::getById($commentId)) { $comment->trash(); $response = array('success' => 1, 'msg' => CMA::__('Comment moved to trash.')); } } echo json_encode(apply_filters('cma_comment_delete_ajax_response', $response)); exit; }
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'); }
\t<div class="form-field"> \t\t<label for="cma_experts">%s</label> \t\t%s \t</div> HTML; } $listItem = <<<HTML <li data-user-id="%d" data-user-login="******"> \t<a href="%s">%s</a> <a href="" class="btn-list-remove">×</a> \t<input type="hidden" name="%s[]" value="%d" /> </li> HTML; $list = ''; foreach ($experts as $userId) { if ($user = get_userdata($userId)) { $list .= sprintf($listItem, intval($userId), $user->user_login, esc_attr(get_edit_user_link($userId)), esc_html($user->user_login), 'cma_experts', intval($userId)); } } $content = <<<HTML \t<div class="cma_experts"> \t\t<div class="suggest-user" data-field-name="%s"> \t\t\t<ul>%s</ul> \t\t\t<div><span>%s:</span><input type="text" /> <input type="button" value="%s" /></div> \t\t\t<input type="hidden" name="cma_experts_nonce" value="%s" /> \t\t</div> \t\t<p class="description">%s</p> \t</div> HTML; $content = sprintf($content, 'cma_experts', $list, CMA::__('Find user'), esc_attr(CMA::__('Add')), wp_create_nonce('cma_experts_nonce'), CMA::__('Experts will receive notifications about new questions.')); printf($template, CMA::__('Select experts'), $content);
static function getLocalized($msg) { return CMA::__($msg); }
protected static function _processPrivateQuestionSend() { header('content-type: application/json'); try { $nonce = self::_getParam('nonce'); if (!CMA_Settings::getOption(CMA_Settings::OPTION_PRIVATE_QUESTIONS_ENABLED)) { throw new Exception(serialize(array('global' => CMA::__('Private questions are disabled.')))); } else { if (empty($nonce) or !wp_verify_nonce($nonce, 'private_question')) { throw new Exception(serialize(array('global' => CMA::__('Invalid nonce.')))); } else { if (CMA_PrivateQuestion::send(get_current_user_id(), self::_getParam('user'), self::_getParam('title'), self::_getParam('question'))) { echo json_encode(array('success' => 1, 'msg' => CMA_Labels::getLocalized('private_question_sent_success'))); } else { throw new Exception(serialize(array('email' => CMA::__('Cannot send email. Please try again.')))); } } } } catch (Exception $e) { echo json_encode(array('success' => 0, 'msg' => CMA::__('An error occured.'), 'errors' => unserialize($e->getMessage()))); } exit; }