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'));
     }
 }
 protected function getSubcategoryTitle($category, $subcategory)
 {
     $subcategories = $this->getSubcategories();
     if (isset($subcategories[$category]) and isset($subcategories[$category][$subcategory])) {
         return CMA_Settings::__($subcategories[$category][$subcategory]);
     } else {
         return CMA_Settings::__($subcategory);
     }
 }
 static function theContent($content)
 {
     global $post;
     $supportedPostTypes = CMA_Settings::getOption(CMA_Settings::OPTION_RELATED_QUESTIONS_POST_TYPES);
     if (is_main_query() and is_single() and !get_query_var('cma_prepared_single') and $post and isset($post->post_type)) {
         if (in_array($post->post_type, $supportedPostTypes) or 'enable' == get_post_meta($post->ID, self::POST_META_RELATED_QUESTIONS_ENABLED, true)) {
             $params = CMA_Settings::getOption(CMA_Settings::OPTION_RELATED_QUESTIONS_SHORTCODE_PARAMS);
             $postTags = array_map(function ($tag) {
                 return $tag->slug;
             }, wp_get_post_tags($post->ID));
             if (!empty($postTags)) {
                 $code = '[cma-questions tag="' . implode(',', $postTags) . '" ' . $params . ']';
                 $content .= do_shortcode($code);
             }
         }
     }
     return $content;
 }
예제 #4
0
 public static function display($content = null)
 {
     if (empty($content) or !is_string($content)) {
         $adName = preg_replace('/^' . preg_quote(self::ACTION_PREFIX, '/') . '/', self::SETTINGS_PREFIX, current_filter());
         $content = CMA_Settings::getOption($adName);
         // 	    	$content = $adName;
     }
     $content = trim($content);
     if (!empty($content)) {
         if (substr($content, 0, 1) == '[' and substr($content, -1, 1) == ']') {
             $result = do_shortcode($content);
         } else {
             $result = $content;
         }
     }
     if (!empty($result)) {
         $className = isset($adName) ? str_replace(self::SETTINGS_PREFIX, self::CSS_CLASS_PREFIX . '-', $adName) : '';
         echo '<div class="' . self::CSS_CLASS_PREFIX . ' ' . $className . '">' . $result . '</div>';
     }
 }
 public static function send($senderId, $recipientId, $title, $question)
 {
     $title = trim($title);
     $question = trim($question);
     $errors = array();
     if (empty($senderId)) {
         $errors['sender'] = 'Invalid sender ID.';
     }
     if (empty($recipientId)) {
         $errors['recipient'] = 'Invalid recipient ID.';
     }
     if (empty($title)) {
         $errors['title'] = 'Title is required.';
     }
     if (empty($question)) {
         $errors['question'] = 'Question is required.';
     }
     if (!empty($errors)) {
         throw new Exception(serialize($errors));
     }
     if ($senderId == $recipientId) {
         $errors['recipient'] = 'You cannot send question to yourself.';
     }
     $sender = get_userdata($senderId);
     if (empty($sender)) {
         $errors['sender'] = 'Unknown sender.';
     }
     $recipient = get_userdata($recipientId);
     if (empty($recipient)) {
         $errors['recipient'] = 'Unknown recipient.';
     }
     if (!empty($errors)) {
         throw new Exception(serialize($errors));
     }
     $replace = array('[blogname]' => get_bloginfo('name'), '[username]' => strip_tags($sender->display_name), '[title]' => htmlspecialchars($title), '[question]' => htmlspecialchars($question));
     $to = sprintf('%s <%s>', $recipient->display_name, $recipient->user_email);
     $replyTo = sprintf('%s <%s>', $sender->display_name, $sender->user_email);
     CMA_Email::send($to, CMA_Settings::getOption(CMA_Settings::OPTION_PRIVATE_QUESTION_EMAIL_SUBJECT), CMA_Settings::getOption(CMA_Settings::OPTION_PRIVATE_QUESTION_EMAIL_TEMPLATE), $replace, array('Reply-To: ' . $replyTo));
     // 		return wp_mail($to, $subject, $template, array('Reply-To: '. $replyTo));
 }
 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 an HTML select box.
  * 
  * @param string $name
  * @param array $options
  * @param string $current Value to select.
  * @return string
  */
 public static function getSelectBox($name, array $options, $current = null)
 {
     $content = '';
     foreach ($options as $value => $label) {
         $content .= sprintf('<option value="%s"%s>%s</option>', esc_attr($value), $current == $value ? ' selected="selected"' : '', esc_html(CMA_Settings::__($label)));
     }
     return sprintf('<select name="%s">%s</select>', esc_attr($name), $content);
 }
예제 #8
0
 public static function getThreadPageTemplate()
 {
     return static::getCustomPageTemplate(CMA_Settings::getOption(CMA_Settings::OPTION_THREAD_PAGE_TEMPLATE));
 }
$options = '';
foreach ($roles as $roleName => $roleInfo) {
    $options .= sprintf('<option value="%s"%s>%s</option>', esc_attr($roleName), in_array($roleName, $categoryRoles) ? ' selected="selected"' : '', esc_html($roleName));
}
$label = CMA_Settings::__('Restrict access to chosen roles');
$content = <<<HTML
\t<fieldset class="cma-access-restriction-enable">
\t\t<label><input type="radio" name="cma_roles_enable" value="0"%s> %s</label>
\t\t<label><input type="radio" name="cma_roles_enable" value="1"%s> %s</label>
\t</fieldset>
\t<div class="roles">
\t\t<select name="cma_roles[]" multiple="multiple" style="min-width:200px">%s</select>
\t\t<p class="description">%s</p>
\t</div>
HTML;
printf($template, $label, sprintf($content, checked(0, intval(!empty($categoryRoles)), false), CMA_Settings::__('No'), checked(1, intval(!empty($categoryRoles)), false), CMA_Settings::__('Yes'), $options, CMA_Settings::__('Choose roles which will have access to the category. If no roles selected, then every user can view it.')));
?>

<style type="text/css">
.cma-access-restriction-enable input {width: auto !important;;}
</style>

<script type="text/javascript">
jQuery(function($) {

	function rolesVisible(obj) {
		if (obj.val() == '1') {
			obj.parents('.form-field').find('.roles').show();
		} else {
			obj.parents('.form-field').find('.roles').hide();
		}
 static function bestAnswerNotification(CMA_Thread $thread)
 {
     global $wpdb;
     $answer = $thread->getBestAnswer();
     $receivers = array();
     $receiversOption = CMA_Settings::getOption(CMA_Settings::OPTION_NOTIF_BEST_ANSWER_RECEIVERS);
     if (in_array(CMA_Settings::NOTIF_QUESTION_AUTHOR, $receiversOption)) {
         $receivers[] = $thread->getAuthorEmail();
     }
     if (in_array(CMA_Settings::NOTIF_ANSWER_AUTHOR, $receiversOption)) {
         $receivers[] = $answer->getAuthorEmail();
     }
     if (in_array(CMA_Settings::NOTIF_FOLLOWERS, $receiversOption)) {
         $receivers = array_merge($receivers, $thread->getFollowersEmails());
     }
     if (in_array(CMA_Settings::NOTIF_CONTRIBUTORS, $receiversOption)) {
         $receivers = array_merge($receivers, $thread->getContributorsEmails());
         $receivers[] = $thread->getAuthorEmail();
     }
     $receivers = array_filter(array_unique($receivers));
     if (!empty($receivers)) {
         $message = CMA_Settings::getOption(CMA_Settings::OPTION_NOTIF_BEST_ANSWER_CONTENT);
         $title = CMA_Settings::getOption(CMA_Settings::OPTION_NOTIF_BEST_ANSWER_TITLE);
         $replace = array('[blogname]' => get_bloginfo('name'), '[question_title]' => strip_tags($thread->getTitle()), '[question_body]' => strip_tags($thread->getContent()), '[question_author]' => strip_tags($thread->getAuthorName()), '[answer]' => strip_tags($answer->getContent()), '[answer_link]' => $answer->getPermalink(), '[answer_author]' => strip_tags($answer->getAuthorName()));
         CMA_Email::send($receivers, $title, $message, $replace);
     }
 }
예제 #11
0
 public function canMarkBestAnswer($userId = null)
 {
     if (empty($userId)) {
         $userId = get_current_user_id();
     }
     $thread = $this->getThread();
     return user_can($userId, 'manage_options') or CMA_Settings::getOption(CMA_Settings::OPTION_ENABLED_MARK_BEST_ANSWER) and $thread->getAuthorId() == $userId and (CMA_Settings::getOption(CMA_Settings::OPTION_ALLOW_OWN_BEST_ANSWER) or $thread->getAuthorId() != $this->getAuthorId());
 }
 public function questionResolvedMessageSuccess($msg)
 {
     $points = intval(CMA_Settings::getOption(CMA_Settings::OPTION_MP_REWARD_BEST_ANSWER_POINTS));
     $msg .= '<br />' . sprintf(CMA_Labels::getLocalized('mp_thread_reward_best_answer_msg'), $points);
     return $msg;
 }
 static function canBeFollower()
 {
     return is_user_logged_in() and CMA_Settings::getOption(CMA_Settings::OPTION_NEW_QUESTION_NOTIFY_EVERYBODY_OPTINOUT);
 }
예제 #14
0
 public function sendNotifications()
 {
     $thread = $this->getThread();
     $receivers = array();
     // Admin notification emails
     if (CMA_Settings::getOption(CMA_Settings::OPTION_NEW_COMMENT_ADMIN_NOTIFICATION_ENABLED)) {
         $receivers = array_merge($receivers, CMA_Settings::getOption(CMA_Settings::OPTION_POST_ADMIN_NOTIFICATION_EMAIL));
     }
     // User subscribers email
     if (CMA_Settings::getOption(CMA_Settings::OPTION_ENABLE_THREAD_FOLLOWING) and CMA_Settings::getOption(CMA_Settings::OPTION_NEW_COMMENT_NOTIFICATION_ENABLED)) {
         $followers = $thread->getFollowersEngine()->getFollowers();
         if (!empty($followers)) {
             foreach ($followers as $user_id) {
                 if ($user_id != $this->getAuthorId() and $thread->isVisible($user_id)) {
                     $user = get_userdata($user_id);
                     if (!empty($user->user_email)) {
                         $receivers[] = $user->user_email;
                     }
                 }
             }
         }
     }
     $receivers = array_filter(array_unique($receivers));
     if (!empty($receivers)) {
         $replace = array('[blogname]' => get_bloginfo('name'), '[question_title]' => strip_tags($thread->getTitle()), '[question_body]' => strip_tags($thread->getContent()), '[comment_link]' => $this->getPermalink(), '[comment]' => strip_tags($this->getContent()), '[author]' => strip_tags($this->getAuthor()->display_name), '[opt_out_url]' => CMA_ThreadNewsletter::getOptOutUrl($this->getThread(), CMA_ThreadNewsletter::TYPE_THREAD));
         $subject = strtr(CMA_Settings::getOption(CMA_Settings::OPTION_NEW_COMMENT_NOTIFICATION_TITLE), $replace);
         $message = strtr(CMA_Settings::getOption(CMA_Settings::OPTION_NEW_COMMENT_NOTIFICATION_CONTENT), $replace);
         CMA_Email::send($receivers, $subject, $message);
         /* $headers = array();
            foreach($receivers as $email) {
            	$email = trim($email);
            	if (is_email($email)) {
            		$headers[] = ' Bcc: '. $email;
            	}
            }
            
            if (!empty($headers)) wp_mail(null, $subject, $message, $headers); */
     }
 }
예제 #15
0
 public static function canBeFollower()
 {
     if (!CMA_Settings::getOption(CMA_Settings::OPTION_ENABLE_CATEGORY_FOLLOWING)) {
         return false;
     }
     return CMA_FollowersEngine::canBeFollower();
 }
예제 #16
0
 protected static function getBadWordsList()
 {
     return array_filter(array_map('trim', explode("\n", CMA_Settings::getOption(CMA_Settings::OPTION_BAD_WORDS_LIST))));
 }
 public static function processSettings()
 {
     if (empty($_POST)) {
         return;
     }
     // CSRF protection
     if (!empty($_POST) and (empty($_POST['nonce']) or !wp_verify_nonce($_POST['nonce'], self::ADMIN_SETTINGS))) {
         die('Invalid nonce');
     }
     CMA_Settings::processPostRequest();
     CMA_Thread::setDisclaimerEnabled(isset($_POST['disclaimer_approve']) && $_POST['disclaimer_approve'] == 1);
     CMA_Thread::setDisclaimerContent(stripslashes($_POST['disclaimer_content']));
     CMA_Thread::setDisclaimerContentAccept(stripslashes($_POST['disclaimer_content_accept']));
     CMA_Thread::setDisclaimerContentReject(stripslashes($_POST['disclaimer_content_reject']));
     CMA_Thread::setSidebarSettings('before_widget', stripslashes($_POST['sidebar_before_widget']));
     CMA_Thread::setSidebarSettings('after_widget', stripslashes($_POST['sidebar_after_widget']));
     CMA_Thread::setSidebarSettings('before_title', stripslashes($_POST['sidebar_before_title']));
     CMA_Thread::setSidebarSettings('after_title', stripslashes($_POST['sidebar_after_title']));
     CMA_Thread::setSidebarEnabled(isset($_POST['sidebar_enable']) && $_POST['sidebar_enable'] == 1);
     CMA_Thread::setSidebarMaxWidth((int) $_POST['sidebar_max_width']);
     CMA_Thread::setSidebarContributorEnabled(isset($_POST['sidebar_contributor_enable']) ? $_POST['sidebar_contributor_enable'] : '1');
     // Social login
     if (isset($_POST['fb_app_id']) && isset($_POST['fb_app_secret'])) {
         update_option('_cma_fb_app_id', trim($_POST['fb_app_id']));
         update_option('_cma_fb_app_secret', trim($_POST['fb_app_secret']));
     }
     if (isset($_POST['google_client_id']) && isset($_POST['google_client_secret'])) {
         update_option('_cma_google_client_id', trim($_POST['google_client_id']));
         update_option('_cma_google_client_secret', trim($_POST['google_client_secret']));
     }
     if (isset($_POST['linkedin_api_key']) && isset($_POST['linkedin_secret_key'])) {
         update_option('_cma_linkedin_api_key', trim($_POST['linkedin_api_key']));
         update_option('_cma_linkedin_secret_key', trim($_POST['linkedin_secret_key']));
     }
     if (isset($_POST['twitter_consumer_key']) && isset($_POST['twitter_consumer_secret'])) {
         update_option('_cma_twitter_consumer_key', trim($_POST['twitter_consumer_key']));
         update_option('_cma_twitter_consumer_secret', trim($_POST['twitter_consumer_secret']));
     }
     if (isset($_POST['live_client_id']) && isset($_POST['live_client_secret'])) {
         update_option('_cma_live_client_id', trim($_POST['live_client_id']));
         update_option('_cma_live_client_secret', trim($_POST['live_client_secret']));
     }
     // Labels
     $labels = CMA_Labels::getLabels();
     foreach ($labels as $labelKey => $label) {
         if (isset($_POST['label_' . $labelKey])) {
             CMA_Labels::setLabel($labelKey, stripslashes($_POST['label_' . $labelKey]));
         }
     }
     CMA_Thread::setSpamFilter(isset($_POST['spamFilter']) && $_POST['spamFilter'] == 1);
     CMA_Thread::setReferralEnabled(isset($_POST['referral_enable']) && $_POST['referral_enable'] == 1);
     if (!empty($_POST['affiliate_code'])) {
         CMA_Thread::setAffiliateCode(stripslashes($_POST['affiliate_code']));
     }
     if (isset($_POST['custom_css'])) {
         CMA_Thread::setCustomCss(stripslashes($_POST['custom_css']));
     }
     // Clear the permalinks
     flush_rewrite_rules(true);
     delete_option('rewrite_rules');
     wp_redirect($_SERVER['REQUEST_URI']);
     exit;
 }
 static function add_meta_boxes()
 {
     if (CMA_Settings::getOption(CMA_Settings::OPTION_USER_RELATED_QUESTIONS_ENABLE)) {
         add_meta_box('cma-user-related-questions', 'User Related Questions', array(__CLASS__, 'render_meta_box'), CMA_Thread::POST_TYPE, 'normal', 'high');
     }
 }
 public static function displayAnswerComments($threadId, $answerId)
 {
     if (CMA_Settings::getOption(CMA_Settings::OPTION_COMMENTS_ANSWER_ENABLE)) {
         self::displayComments($threadId, $answerId);
     }
 }
예제 #20
0
 public static function filterShortcodes($content)
 {
     $whitelist = CMA_Settings::getOption(CMA_Settings::OPTION_SHORTCODES_WHITELIST);
     if (!empty($whitelist) and is_array($whitelist)) {
         $pattern = get_shortcode_regex();
         if (preg_match_all('/' . $pattern . '/s', $content, $matches) and !empty($matches[2]) and is_array($matches[2])) {
             foreach ($matches[2] as $shrotcodeName) {
                 if (!in_array($shrotcodeName, $whitelist)) {
                     $content = str_replace('[' . $shrotcodeName, '&lsqb;' . $shrotcodeName, $content);
                     $content = str_replace('[/' . $shrotcodeName, '&lsqb;/' . $shrotcodeName, $content);
                 }
             }
         }
     }
     return $content;
 }
예제 #21
0
 public static function update_2_4_13()
 {
     global $wpdb;
     // Comment rating
     $commentsIds = array();
     if (CMA_Settings::getOption(CMA_Settings::OPTION_NEGATIVE_RATING_ALLOWED)) {
         // Copy comments' ratings to the rating handicap fields.
         $ratings = $wpdb->get_results($wpdb->prepare("SELECT m.comment_id, m.meta_value, c.comment_post_ID\n\t\t\t\tFROM {$wpdb->commentmeta} m\n\t\t\t\tINNER JOIN {$wpdb->comments} c ON m.comment_id = c.comment_ID\n\t\t\t\tWHERE m.meta_key = %s", CMA_Thread::$_meta['rating']), ARRAY_A);
         foreach ($ratings as $record) {
             add_comment_meta($record['comment_id'], CMA_Answer::META_USER_RATING_HANDICAP, $record['meta_value'], $unique = true);
             $commentsIds[$record['comment_id']] = $record['comment_id'];
         }
     } else {
         // Only positive ratings - move voters to the positive voters meta
         $voters = $wpdb->get_results($wpdb->prepare("SELECT m.comment_id, m.meta_value, c.comment_post_ID\n\t\t\t\tFROM {$wpdb->commentmeta} m\n\t\t\t\tINNER JOIN {$wpdb->comments} c ON m.comment_id = c.comment_ID\n\t\t\t\tWHERE m.meta_key = %s", CMA_Answer::META_USERS_RATED), ARRAY_A);
         foreach ($voters as $record) {
             $commentRatingPositive = get_comment_meta($record['comment_id'], CMA_Answer::META_USER_RATING_POSITIVE, $single = false);
             if (!in_array($record['meta_value'], $commentRatingPositive)) {
                 add_comment_meta($record['comment_id'], CMA_Answer::META_USER_RATING_POSITIVE, $record['meta_value'], $unique = false);
             }
             $commentsIds[$record['comment_id']] = $record['comment_id'];
         }
     }
     // ----------------------------------------------------
     // Post rating
     $postsIds = array();
     if (CMA_Settings::getOption(CMA_Settings::OPTION_NEGATIVE_RATING_ALLOWED)) {
         // Copy posts' ratings to the rating handicap fields.
         $ratings = $wpdb->get_results($wpdb->prepare("SELECT post_id, meta_value FROM {$wpdb->postmeta}\n\t\t\t\tWHERE meta_key = %s", CMA_Thread::$_meta['rating']), ARRAY_A);
         foreach ($ratings as $record) {
             add_post_meta($record['post_id'], CMA_Thread::$_meta['userRatingHandicap'], $record['meta_value'], $unique = true);
             $postsIds[$record['post_id']] = $record['post_id'];
         }
     } else {
         // Only positive ratings - copy voters to the positive voters meta
         $voters = $wpdb->get_results($wpdb->prepare("SELECT post_id, meta_value FROM {$wpdb->postmeta}\n\t\t\t\tWHERE meta_key = %s", CMA_Thread::$_meta['usersRated']), ARRAY_A);
         foreach ($voters as $record) {
             $postRatingPositive = get_post_meta($record['post_id'], CMA_Thread::$_meta['userRatingPositive'], $single = false);
             if (!in_array($record['meta_value'], $postRatingPositive)) {
                 add_post_meta($record['post_id'], CMA_Thread::$_meta['userRatingPositive'], $record['meta_value'], $unique = false);
             }
             $postsIds[$record['post_id']] = $record['post_id'];
         }
     }
     // ----------------------------------------------------
     // Update comments counter cache
     foreach ($commentsIds as $commentId) {
         if ($answer = CMA_Answer::getById($commentId)) {
             $answer->updateRatingCache();
         }
     }
     // Update posts counter cache
     foreach ($postsIds as $postId) {
         if ($thread = CMA_Thread::getInstance($postId)) {
             $thread->updateRatingCache();
         }
     }
 }
 /**
  * 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);
         }
     }
 }
 protected function renderMultiCheckboxItem($name, $value, $label, $currentValue = null)
 {
     if (is_null($currentValue)) {
         $currentValue = CMA_Settings::getOption($name);
     }
     if (!is_array($currentValue)) {
         $currentValue = array();
     }
     return sprintf('<div><label><input type="checkbox" name="%s[]" value="%s"%s /> %s</label></div>', esc_attr($name), esc_attr($value), in_array($value, $currentValue) ? ' checked="checked"' : '', esc_html(CMA_Settings::__($label)));
 }
예제 #24
0
 protected function appendMetaGeolocation($meta, $ip)
 {
     // Find country by IPGeolocation
     if ($apiKey = CMA_Settings::getOption(CMA_Settings::OPTION_GEOLOCIATION_API_KEY)) {
         $service = new CMA_IPGeolocation();
         $service->setKey($apiKey);
         $response = $service->getCountry($ip);
         if (!empty($response['countryCode']) and $response['countryCode'] != '-') {
             $meta[self::META_COUNTRY_CODE] = $response['countryCode'];
         }
         if (!empty($response['countryName']) and $response['countryName'] != '-') {
             $meta[self::META_COUNTRY_NAME] = $response['countryName'];
         }
     }
     return $meta;
 }
 /**
  * display() contains the markup that will be displayed on the main 
  * plugin tab
  */
 function display($group_id = null)
 {
     echo do_shortcode(sprintf('[cma-questions cat=%d %s]', $this->getRelatedCategory($group_id), CMA_Settings::getOption(CMA_Settings::OPTION_BP_GROUP_SHORTCODE_ATTR)));
 }
    /**
     * 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 
    }
 public function getThumb($size = 'thumbnail', $icon = true, $atts = array())
 {
     $size = CMA_Settings::getOption(CMA_Settings::OPTION_EMBED_ATTACHED_IMAGES_SIZE);
     $atts['style'] = sprintf('max-width:%dpx;max-height:%dpx;', $size, $size);
     return $this->getImage($size, $icon, $atts);
 }