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;
 }
Example #2
0
 public static function init($pluginFilePath)
 {
     register_activation_hook($pluginFilePath, array(__CLASS__, 'install'));
     register_uninstall_hook($pluginFilePath, array(__CLASS__, 'uninstall'));
     add_action('init', array('CMA_Update', 'run'), 0);
     add_action('widgets_init', array('CMA_AnswerController', 'registerSidebars'));
     // Check licensing API before controller init
     $licensingApi = new CMA_Cminds_Licensing_API('CM Answers Pro', CMA_Thread::ADMIN_MENU, 'CM Answers Pro', CMA_PLUGIN_FILE, array('release-notes' => 'http://answers.cminds.com/release-notes/'), '', array('CM Answers Pro'));
     self::$isLicenseOk = $licensingApi->isLicenseOk();
     CMA_Labels::bootstrap();
     CMA_Thread::init();
     add_action('plugins_loaded', array('CMA_BuddyPress', 'bootstrap'));
     add_action('init', array('CMA_BaseController', 'bootstrap'));
     add_action('wp_enqueue_scripts', array(__CLASS__, 'enable_scripts'));
     add_action('admin_enqueue_scripts', array(__CLASS__, 'enable_admin_scripts'));
     add_action('wp_head', array(__CLASS__, 'add_base_url'));
     add_filter('bp_blogs_record_comment_post_types', array(get_class(), 'bp_record_my_custom_post_type_comments'));
     add_filter('plugin_action_links_' . CMA_PLUGINNAME, array(__CLASS__, 'cma_settings_link'));
     add_filter('cm_micropayments_integrations', function ($a = array()) {
         if (!is_array($a)) {
             $a = array();
         }
         $a[] = 'CM Answers Pro';
         return $a;
     });
     add_action('plugins_loaded', array(__CLASS__, 'cm_lang_init'));
 }
 public static function bootstrap()
 {
     self::loadLabelFile();
     do_action('cma_labels_init');
     /* You can use the following filters to add new labels for CMA:
     		add_filter('cma_labels_init_labels', function($labels) {
     			$labels['label_name'] = array('default' => 'Value', 'desc' => 'Description', 'category' => 'Other');
     			return $labels;
     		});
     		add_filter('cma_labels_init_labels_by_categories', function($labelsByCategories) {
     			$labelsByCategories['Other'][] = 'label_name';
     			return $labelsByCategories;
     		});
     		*/
     self::$labels = apply_filters('cma_labels_init_labels', self::$labels);
     self::$labelsByCategories = apply_filters('cma_labels_init_labels_by_categories', self::$labelsByCategories);
 }
 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);
 }
 public static function update_2_9_3()
 {
     if ($questionsTitle = get_option('cma_questions_title')) {
         CMA_Labels::setLabel('index_page_title', $questionsTitle);
     }
 }
    /**
     * 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 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;
 }
 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');
         }
     }
 }