function admin_form(&$qa_content)
 {
     // Process form input
     $ok = null;
     if (qa_clicked('ajax_comment_save')) {
         qa_opt('ajax_comment_enable', (bool) qa_post_text('ajax_comment_enable'));
         qa_opt('ajax_comment_format', (int) qa_post_text('ajax_comment_format'));
         qa_opt('ajax_comment_username', (bool) qa_post_text('ajax_comment_username'));
         qa_opt('ajax_comment_flash_star', (bool) qa_post_text('ajax_comment_flash_star'));
         qa_opt('ajax_comment_answer_reminder', (bool) qa_post_text('ajax_comment_answer_reminder'));
         qa_opt('ajax_comment_answer_reminder_text', qa_post_text('ajax_comment_answer_reminder_text'));
         qa_opt('ajax_comment_popup_notice', (bool) qa_post_text('ajax_comment_popup_notice'));
         qa_opt('ajax_comment_popup_notice_text', qa_post_text('ajax_comment_popup_notice_text'));
         $ok = 'Settings Saved.';
     }
     $formats = array();
     $formats[] = 'plain text';
     $editors = qa_list_modules('viewer');
     if (in_array('Markdown Viewer', $editors)) {
         $formats[] = 'markdown';
     }
     $formats[] = 'html';
     // Create the form for display
     $fields = array();
     $fields[] = array('label' => 'Enable ajax comment form', 'tags' => 'NAME="ajax_comment_enable"', 'value' => qa_opt('ajax_comment_enable'), 'type' => 'checkbox');
     $fields[] = array('label' => 'Comment format', 'tags' => 'NAME="ajax_comment_format"', 'type' => 'select', 'options' => $formats, 'value' => @$formats[qa_opt('ajax_comment_format')]);
     $fields[] = array('label' => 'Add @username to comment box', 'tags' => 'NAME="ajax_comment_username"', 'value' => (int) qa_opt('ajax_comment_username'), 'type' => 'checkbox');
     $fields[] = array('label' => 'Show reminder text if commenting on answer to own question', 'tags' => 'NAME="ajax_comment_answer_reminder" onclick="if(this.checked) jQuery(\'#ajax_comment_answer_reminder_text\').fadeIn(); else jQuery(\'#ajax_comment_answer_reminder_text\').fadeOut();"', 'value' => (int) qa_opt('ajax_comment_answer_reminder'), 'type' => 'checkbox');
     $fields[] = array('tags' => 'id="ajax_comment_answer_reminder_text" name="ajax_comment_answer_reminder_text" style="display:' . (qa_opt('ajax_comment_answer_reminder') ? 'block' : 'none') . '"', 'value' => qa_html(qa_opt('ajax_comment_answer_reminder_text')), 'type' => 'text');
     $fields[] = array('label' => 'Flash select star if commenting on answer to own question', 'tags' => 'NAME="ajax_comment_flash_star"', 'value' => (int) qa_opt('ajax_comment_flash_star'), 'type' => 'checkbox');
     $fields[] = array('label' => 'Show reminder pop-up if if voting up answer to own question', 'tags' => 'NAME="ajax_comment_popup_notice" onclick="if(this.checked) jQuery(\'#ajax_comment_popup_notice_text\').fadeIn(); else jQuery(\'#ajax_comment_popup_notice_text\').fadeOut();"', 'value' => (int) qa_opt('ajax_comment_popup_notice'), 'type' => 'checkbox');
     $fields[] = array('tags' => 'id="ajax_comment_popup_notice_text" name="ajax_comment_popup_notice_text" style="display:' . (qa_opt('ajax_comment_popup_notice') ? 'block' : 'none') . '"', 'value' => qa_html(qa_opt('ajax_comment_popup_notice_text')), 'type' => 'text');
     return array('ok' => $ok && !isset($error) ? $ok : null, 'fields' => $fields, 'buttons' => array(array('label' => 'Save', 'tags' => 'NAME="ajax_comment_save"')));
 }
Example #2
0
 function head_custom()
 {
     qa_html_theme_base::head_custom();
     if (@$this->template == 'user' && qa_opt('signatures_enable')) {
         $formats = qa_list_modules('editor');
         $editorname = $formats[qa_opt('signatures_format')];
         $handle = preg_replace('/^[^\\/]+\\/([^\\/]+).*/', "\$1", $this->request);
         if (qa_get_logged_in_handle() == $handle && (!$editorname || $editorname == 'Markdown Editor')) {
             $this->output_raw('<script src="' . QA_HTML_THEME_LAYER_URLTOROOT . 'textLimitCount.js" type="text/javascript"></script>');
             $this->output_raw("\n<script>\n\tvar signature_max_length = " . (qa_opt('signatures_length') ? qa_opt('signatures_length') : 1000) . ";\n\tjQuery('document').ready(function(){\n\t\ttextLimiter(jQuery('textarea[name=\"signature_text\"]'),{\n\t\tmaxLength: signature_max_length,\n\t\telCount: 'elCount'\n\t  });\n\t});\n</script>");
         }
     }
 }
Example #3
0
 function admin_form(&$qa_content)
 {
     // Process form input
     $ok = null;
     if (qa_clicked('signatures_save')) {
         if (qa_post_text('signatures_length') > 1000) {
             $error = 'Max possible signature length is 1000 characters';
         } else {
             if (!qa_opt('signatures_enable') && qa_post_text('signatures_enable')) {
                 qa_db_query_sub('CREATE TABLE IF NOT EXISTS ^usersignatures (' . 'userid INT(11) NOT NULL,' . 'signature VARCHAR (1000) DEFAULT \'\',' . 'format VARCHAR (20) DEFAULT \'\',' . 'id INT(11) NOT NULL AUTO_INCREMENT,' . 'UNIQUE (userid),' . 'PRIMARY KEY (id)' . ') ENGINE=MyISAM DEFAULT CHARSET=utf8');
             }
             qa_opt('signatures_enable', (bool) qa_post_text('signatures_enable'));
             qa_opt('signatures_q_enable', (bool) qa_post_text('signatures_q_enable'));
             qa_opt('signatures_a_enable', (bool) qa_post_text('signatures_a_enable'));
             qa_opt('signatures_c_enable', (bool) qa_post_text('signatures_c_enable'));
             qa_opt('signatures_profile_enable', (bool) qa_post_text('signatures_profile_enable'));
             qa_opt('signatures_length', (int) qa_post_text('signatures_length'));
             qa_opt('signatures_format', (int) qa_post_text('signatures_format'));
             qa_opt('signatures_html', (bool) qa_post_text('signatures_html'));
             qa_opt('signatures_header', qa_post_text('signatures_header'));
             qa_opt('signatures_footer', qa_post_text('signatures_footer'));
             $ok = 'Settings Saved.';
         }
     }
     // Create the form for display
     $formats = qa_list_modules('editor');
     foreach ($formats as $key => $format) {
         if (!strlen($format)) {
             $formats[$key] = qa_lang_html('admin/basic_editor');
         }
     }
     $fields = array();
     $fields[] = array('label' => 'Enable signatures', 'tags' => 'NAME="signatures_enable"', 'value' => qa_opt('signatures_enable'), 'type' => 'checkbox');
     $fields[] = array('label' => 'in questions', 'tags' => 'NAME="signatures_q_enable"', 'value' => qa_opt('signatures_q_enable'), 'type' => 'checkbox');
     $fields[] = array('label' => 'in answers', 'tags' => 'NAME="signatures_a_enable"', 'value' => qa_opt('signatures_a_enable'), 'type' => 'checkbox');
     $fields[] = array('label' => 'in comments', 'tags' => 'NAME="signatures_c_enable"', 'value' => qa_opt('signatures_c_enable'), 'type' => 'checkbox');
     $fields[] = array('type' => 'blank');
     $fields[] = array('label' => 'Show signatures in public profiles', 'tags' => 'NAME="signatures_profile_enable"', 'value' => qa_opt('signatures_profile_enable'), 'type' => 'checkbox');
     $fields[] = array('label' => 'Signature length (chars)', 'type' => 'number', 'value' => (int) qa_opt('signatures_length'), 'tags' => 'NAME="signatures_length"', 'note' => 'max possible is 1000 characters');
     $fields[] = array('label' => 'Signature format', 'tags' => 'NAME="signatures_format"', 'type' => 'select', 'options' => $formats, 'value' => @$formats[qa_opt('signatures_format')]);
     $fields[] = array('label' => 'Allow HTML', 'tags' => 'NAME="signatures_html"', 'value' => qa_opt('signatures_html'), 'type' => 'checkbox');
     $fields[] = array('type' => 'blank');
     $fields[] = array('label' => 'Signature header', 'type' => 'text', 'value' => qa_html(qa_opt('signatures_header')), 'tags' => 'NAME="signatures_header"');
     $fields[] = array('label' => 'Signature footer', 'type' => 'text', 'value' => qa_html(qa_opt('signatures_footer')), 'tags' => 'NAME="signatures_footer"');
     return array('ok' => $ok && !isset($error) ? $ok : null, 'fields' => $fields, 'buttons' => array(array('label' => 'Save', 'tags' => 'NAME="signatures_save"')));
 }
        if (strlen(@$metadata['description'])) {
            $deschtml = qa_html($metadata['description']) . '<BR>';
        } else {
            $deschtml = '';
        }
        $pluginhtml = $namehtml . ' ' . $authorhtml . '<BR>' . $deschtml . '<SMALL STYLE="color:#666">' . qa_html(dirname($pluginfile) . '/') . '</SMALL>';
        if (is_numeric($metadata['min_q2a']) && (double) QA_VERSION > 0 && $metadata['min_q2a'] > (double) QA_VERSION) {
            $pluginhtml = '<STRIKE STYLE="color:#999">' . $pluginhtml . '</STRIKE><BR><SPAN STYLE="color:#f00">' . qa_lang_html_sub('admin/requires_q2a_version', qa_html($metadata['min_q2a'])) . '</SPAN>';
        }
        $qa_content['form']['fields'][] = array('type' => 'custom', 'html' => $pluginhtml);
    }
}
$formadded = false;
$moduletypes = qa_list_module_types();
foreach ($moduletypes as $type) {
    $modulenames = qa_list_modules($type);
    foreach ($modulenames as $name) {
        $module = qa_load_module($type, $name);
        if (method_exists($module, 'admin_form')) {
            $form = $module->admin_form($qa_content);
            if (!isset($form['title'])) {
                $form['title'] = qa_html($name);
            }
            $identifierhtml = qa_html(md5($type . '/' . $name));
            $form['title'] = '<A NAME="' . $identifierhtml . '">' . $form['title'] . '</A>';
            if (!isset($form['tags'])) {
                $form['tags'] = 'METHOD="POST" ACTION="' . qa_self_html() . '#' . $identifierhtml . '"';
            }
            if (!isset($form['style'])) {
                $form['style'] = 'tall';
            }
Example #5
0
function qa_load_modules_with($type, $method)
{
    $modules = array();
    $trynames = qa_list_modules($type);
    foreach ($trynames as $tryname) {
        $module = qa_load_module($type, $tryname);
        if (method_exists($module, $method)) {
            $modules[$tryname] = $module;
        }
    }
    return $modules;
}
     $optionfield['note'] = qa_lang_html_sub('main/x_comments', '');
     break;
 case 'match_related_qs':
 case 'match_ask_check_qs':
 case 'match_example_tags':
     qa_optionfield_make_select($optionfield, qa_admin_match_options(), $value, 3);
     break;
 case 'block_bad_words':
     $optionfield['style'] = 'tall';
     $optionfield['rows'] = 4;
     $optionfield['note'] = qa_lang_html('admin/block_words_note');
     break;
 case 'editor_for_qs':
 case 'editor_for_as':
 case 'editor_for_cs':
     $editors = qa_list_modules('editor');
     $selectoptions = array();
     $optionslinks = false;
     foreach ($editors as $editor) {
         $selectoptions[qa_html($editor)] = strlen($editor) ? qa_html($editor) : qa_lang_html('admin/basic_editor');
         if ($editor == $value) {
             $module = qa_load_module('editor', $editor);
             if (method_exists($module, 'admin_form')) {
                 $optionfield['note'] = '<a href="' . qa_admin_module_options_path('editor', $editor) . '">' . qa_lang_html('admin/options') . '</a>';
             }
         }
     }
     qa_optionfield_make_select($optionfield, $selectoptions, $value, '');
     break;
 case 'show_custom_ask':
 case 'extra_field_active':
Example #7
0
function qa_get_badge_list()
{
    // badges - add to this list to add a new badge, it will be imported when you run this function.  Don't change existing slugs!
    $badges = array();
    if (!QA_FINAL_EXTERNAL_USERS) {
        $badges['verified'] = array('type' => 0);
        $badges['profiler'] = array('type' => 0);
        $badges['avatar'] = array('type' => 0);
    }
    $badges['nice_question'] = array('var' => 2, 'type' => 0);
    $badges['good_question'] = array('var' => 5, 'type' => 1);
    $badges['great_question'] = array('var' => 10, 'type' => 2);
    $badges['notable_question'] = array('var' => 50, 'type' => 0);
    $badges['popular_question'] = array('var' => 100, 'type' => 1);
    $badges['famous_question'] = array('var' => 500, 'type' => 2);
    $badges['nice_answer'] = array('var' => 2, 'type' => 0);
    $badges['good_answer'] = array('var' => 5, 'type' => 1);
    $badges['great_answer'] = array('var' => 10, 'type' => 2);
    $badges['nice_answer_old'] = array('var' => 30, 'type' => 0);
    $badges['good_answer_old'] = array('var' => 60, 'type' => 1);
    $badges['great_answer_old'] = array('var' => 120, 'type' => 2);
    $badges['gifted'] = array('var' => 1, 'type' => 0);
    $badges['wise'] = array('var' => 10, 'type' => 1);
    $badges['enlightened'] = array('var' => 30, 'type' => 2);
    $badges['grateful'] = array('var' => 1, 'type' => 0);
    $badges['respectful'] = array('var' => 20, 'type' => 1);
    $badges['reverential'] = array('var' => 50, 'type' => 2);
    $badges['liked'] = array('var' => 20, 'type' => 0);
    $badges['loved'] = array('var' => 50, 'type' => 1);
    $badges['revered'] = array('var' => 200, 'type' => 2);
    $badges['asker'] = array('var' => 10, 'type' => 0);
    $badges['questioner'] = array('var' => 25, 'type' => 1);
    $badges['inquisitor'] = array('var' => 50, 'type' => 2);
    $badges['answerer'] = array('var' => 25, 'type' => 0);
    $badges['lecturer'] = array('var' => 50, 'type' => 1);
    $badges['preacher'] = array('var' => 100, 'type' => 2);
    $badges['commenter'] = array('var' => 50, 'type' => 0);
    $badges['commentator'] = array('var' => 100, 'type' => 1);
    $badges['annotator'] = array('var' => 500, 'type' => 2);
    $badges['voter'] = array('var' => 10, 'type' => 0);
    $badges['avid_voter'] = array('var' => 50, 'type' => 1);
    $badges['devoted_voter'] = array('var' => 200, 'type' => 2);
    $badges['editor'] = array('var' => 1, 'type' => 0);
    $badges['copy_editor'] = array('var' => 15, 'type' => 1);
    $badges['senior_editor'] = array('var' => 50, 'type' => 2);
    $badges['watchdog'] = array('var' => 1, 'type' => 0);
    $badges['bloodhound'] = array('var' => 10, 'type' => 1);
    $badges['pitbull'] = array('var' => 30, 'type' => 2);
    $badges['reader'] = array('var' => 20, 'type' => 0);
    $badges['avid_reader'] = array('var' => 50, 'type' => 1);
    $badges['devoted_reader'] = array('var' => 200, 'type' => 2);
    $badges['dedicated'] = array('var' => 10, 'type' => 0);
    $badges['devoted'] = array('var' => 25, 'type' => 1);
    $badges['zealous'] = array('var' => 50, 'type' => 2);
    $badges['visitor'] = array('var' => 30, 'type' => 0);
    $badges['trouper'] = array('var' => 100, 'type' => 1);
    $badges['veteran'] = array('var' => 200, 'type' => 2);
    $badges['regular'] = array('var' => 90, 'type' => 0);
    $badges['old_timer'] = array('var' => 180, 'type' => 1);
    $badges['ancestor'] = array('var' => 365, 'type' => 2);
    $badges['100_club'] = array('var' => 100, 'type' => 0);
    $badges['1000_club'] = array('var' => 1000, 'type' => 1);
    $badges['10000_club'] = array('var' => 10000, 'type' => 2);
    $badges['medalist'] = array('var' => 10, 'type' => 0);
    $badges['champion'] = array('var' => 30, 'type' => 1);
    $badges['olympian'] = array('var' => 100, 'type' => 2);
    // get badges from other plugins - experimental!
    $moduletypes = qa_list_module_types();
    foreach ($moduletypes as $moduletype) {
        $modulenames = qa_list_modules($moduletype);
        foreach ($modulenames as $modulename) {
            $module = qa_load_module($moduletype, $modulename);
            if (method_exists($module, 'custom_badges')) {
                $badges = array_merge($badges, $module->custom_badges());
            }
        }
    }
    return $badges;
}
function qa_get_request_content()
{
    $qa_content = qa_get_request_content_base();
    // displays signature form in user profile
    $qa_request = strtolower(qa_request());
    $reqs = explode('/', $qa_request);
    if ($reqs[0] == 'user') {
        // permissions
        if (isset($qa_content['form_profile']['fields']['permits'])) {
            $ov = $qa_content['form_profile']['fields']['permits']['value'];
            $ov = str_replace('[profile/signature_allow]', qa_lang('signature_plugin/signature_allow'), $ov);
            $ov = str_replace('[profile/signature_edit_allow]', qa_lang('signature_plugin/signature_edit_allow'), $ov);
            $qa_content['form_profile']['fields']['permits']['value'] = $ov;
        }
        $qa_content['user_signature_form'] = array();
        $userid = @$qa_content['raw']['userid'];
        if (!$userid) {
            return $qa_content;
        }
        $handles = qa_userids_to_handles(array($userid));
        $handle = $handles[$userid];
        if (qa_get_logged_in_handle() == $handle && !qa_user_permit_error('signature_allow') || !qa_user_permit_error('signature_edit_allow')) {
            $ok = null;
            $formats = qa_list_modules('editor');
            $format = qa_opt('signatures_format');
            $editorname = $formats[$format];
            if (!strlen($editorname)) {
                $editorname = qa_lang_html('admin/basic_editor');
            }
            $editor = qa_load_editor('', '', $editorname);
            qa_db_query_sub('CREATE TABLE IF NOT EXISTS ^usersignatures (' . 'userid INT(11) NOT NULL,' . 'signature VARCHAR (1000) DEFAULT \'\',' . 'format VARCHAR (20) DEFAULT \'\',' . 'id INT(11) NOT NULL AUTO_INCREMENT,' . 'UNIQUE (userid),' . 'PRIMARY KEY (id)' . ') ENGINE=MyISAM DEFAULT CHARSET=utf8');
            if (qa_clicked('signature_save')) {
                if (strlen(qa_post_text('signature_text')) > qa_opt('signatures_length')) {
                    $error = 'Max possible signature length is 1000 characters';
                } else {
                    $readdata = $editor->read_post('signature_text');
                    $informat = $readdata['format'];
                    $incontent = qa_post_text('signature_text');
                    qa_db_query_sub('INSERT INTO ^usersignatures (userid,signature,format) VALUES (#,$,$) ON DUPLICATE KEY UPDATE signature=$,format=$', $userid, $incontent, $informat, $incontent, $informat);
                    $ok = 'Signature Saved.';
                }
            }
            $content = qa_db_read_one_assoc(qa_db_query_sub('SELECT BINARY signature AS signature,format FROM ^usersignatures WHERE userid=#', $userid), true);
            $field = qa_editor_load_field($editor, $qa_content, $content['signature'], $content['format'], 'signature_text', 12, false);
            $field['label'] = qa_lang_html('signature_plugin/signature');
            $fields['content'] = $field;
            if (!$editorname || $editorname == 'Markdown Editor') {
                $fields['elCount'] = array('label' => '<div id="elCount">' . qa_opt('signatures_length') . '</div>', 'type' => 'static');
            }
            $form = array('ok' => $ok && !isset($error) ? $ok : null, 'error' => @$error, 'style' => 'tall', 'title' => '<a name="signature_text"></a>' . qa_lang_html('signature_plugin/signature'), 'tags' => 'action="' . qa_self_html() . '#signature_text" method="POST"', 'fields' => $fields, 'buttons' => array(array('label' => qa_lang_html('main/save_button'), 'tags' => 'NAME="signature_save"')), 'hidden' => array('editor' => qa_html($editorname), 'dosavesig' => '1'));
            $qa_content['user_signature_form'] = $form;
        } else {
            if (qa_opt('signatures_profile_enable')) {
                $content = qa_db_read_one_assoc(qa_db_query_sub('SELECT BINARY signature as signature, format FROM ^usersignatures WHERE userid=#', $userid), true);
                if (!$content) {
                    return $qa_content;
                }
                $informat = $content['format'];
                $viewer = qa_load_viewer($content['signature'], $informat);
                global $options;
                $signature = qa_viewer_html($content['signature'], $informat, array('blockwordspreg' => @$options['blockwordspreg'], 'showurllinks' => @$options['showurllinks'], 'linksnewwindow' => @$options['linksnewwindow']));
                $fields[] = array('label' => qa_opt('signatures_header') . $signature . qa_opt('signatures_footer'), 'type' => 'static');
                $qa_content['user_signature_form'] = array('title' => 'Signature', 'fields' => $fields, 'style' => 'tall');
            }
        }
    }
    return $qa_content;
}
 function ajaxPostComment($text, $aid = false)
 {
     if ($aid) {
         $answer = qa_db_single_select(qa_db_full_post_selectspec(null, $aid));
     }
     require_once QA_INCLUDE_DIR . 'qa-page-question-post.php';
     global $qa_login_userid, $qa_cookieid, $question, $questionid, $formtype, $formpostid, $errors, $reloadquestion, $pageerror, $qa_request, $ineditor, $incomment, $informat, $innotify, $inemail, $commentsfollows, $jumptoanchor, $usecaptcha;
     $parent = isset($answer) ? $answer : $question;
     switch (qa_user_permit_error('permit_post_c', 'C')) {
         case 'login':
             $pageerror = qa_insert_login_links(qa_lang_html('question/comment_must_login'), $qa_request);
             break;
         case 'confirm':
             $pageerror = qa_insert_login_links(qa_lang_html('question/comment_must_confirm'), $qa_request);
             break;
         case 'limit':
             $pageerror = qa_lang_html('question/comment_limit');
             break;
         default:
             $pageerror = qa_lang_html('users/no_permission');
             break;
         case false:
             $incomment = qa_post_text('ajax_comment_content');
             if (!isset($incomment)) {
                 $pageerror = qa_lang_html('bork');
             } else {
                 $innotify = qa_post_text('notify') ? true : false;
                 $inemail = qa_post_text('email');
                 $this->ajaxEditor($ineditor, $incomment, $informat, $intext);
                 // use our own format types
                 $formats = array();
                 $formats[] = '';
                 $editors = qa_list_modules('viewer');
                 if (in_array('Markdown Viewer', $editors)) {
                     $formats[] = 'markdown';
                 }
                 $formats[] = 'html';
                 $informat = $formats[qa_opt('ajax_comment_format')];
                 $errors = qa_comment_validate($incomment, $informat, $intext, $innotify, $inemail);
                 if ($usecaptcha) {
                     qa_captcha_validate($_POST, $errors);
                 }
                 if (empty($errors)) {
                     $isduplicate = false;
                     foreach ($commentsfollows as $comment) {
                         if ($comment['basetype'] == 'C' && $comment['parentid'] == $parent['postid'] && !$comment['hidden']) {
                             if (implode(' ', qa_string_to_words($comment['content'])) == implode(' ', qa_string_to_words($incomment))) {
                                 $isduplicate = true;
                             }
                         }
                     }
                     if (!$isduplicate) {
                         if (!isset($qa_login_userid)) {
                             $qa_cookieid = qa_cookie_get_create();
                         }
                         // create a new cookie if necessary
                         // get editor format
                         $commentid = qa_comment_create($qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $incomment, $informat, $intext, $innotify, $inemail, $question, @$answer, $commentsfollows);
                         qa_report_write_action($qa_login_userid, $qa_cookieid, 'c_post', $questionid, @$answer['postid'], $commentid);
                     } else {
                         $pageerror = qa_lang_html('question/duplicate_content');
                     }
                 }
             }
             break;
     }
     if ($pageerror) {
         $this->output_raw('### ' . $pageerror);
     } else {
         if (!empty($errors)) {
             $this->output_raw('### ' . implode(',', $errors));
         } else {
             // return c_item
             $c_item = $this->ajaxCommentCreate($parent, $commentid);
             if (isset($c_item['classes'])) {
                 $c_item['classes'] .= ' ajax-comment-hidden';
             } else {
                 $c_item['classes'] = ' ajax-comment-hidden';
             }
             $this->c_list_item($c_item);
         }
     }
 }
Example #10
0
function qa_content_prepare($voting = false, $categoryids = null)
{
    global $qa_root_url_relative, $qa_request, $qa_template, $qa_login_userid, $qa_vote_error_html, $qa_nav_pages_cached, $qa_widgets_cached, $QA_CONST_ROUTING;
    if (QA_DEBUG_PERFORMANCE) {
        qa_usage_mark('control');
    }
    if (isset($categoryids) && !is_array($categoryids)) {
        // accept old-style parameter
        $categoryids = array($categoryids);
    }
    $lastcategoryid = count($categoryids) ? end($categoryids) : null;
    $qa_content = array('content_type' => 'text/html; charset=utf-8', 'site_title' => qa_html(qa_opt('site_title')), 'head_lines' => array(), 'navigation' => array('user' => array(), 'main' => array(), 'footer' => array('feedback' => array('url' => qa_path_html('feedback'), 'label' => qa_lang_html('main/nav_feedback')))), 'sidebar' => qa_opt('show_custom_sidebar') ? qa_opt('custom_sidebar') : null, 'sidepanel' => qa_opt('show_custom_sidepanel') ? qa_opt('custom_sidepanel') : null, 'widgets' => array());
    if (qa_opt('show_custom_in_head')) {
        $qa_content['head_lines'][] = qa_opt('custom_in_head');
    }
    if (qa_opt('show_custom_header')) {
        $qa_content['body_header'] = qa_opt('custom_header');
    }
    if (qa_opt('show_custom_footer')) {
        $qa_content['body_footer'] = qa_opt('custom_footer');
    }
    if (isset($categoryids)) {
        $qa_content['categoryids'] = $categoryids;
    }
    foreach ($qa_nav_pages_cached as $page) {
        if ($page['nav'] == 'B') {
            qa_navigation_add_page($qa_content['navigation']['main'], $page);
        }
    }
    if (qa_opt('nav_home') && qa_opt('show_custom_home')) {
        $qa_content['navigation']['main']['$'] = array('url' => qa_path_html(''), 'label' => qa_lang_html('main/nav_home'));
    }
    if (qa_opt('nav_activity')) {
        $qa_content['navigation']['main']['activity'] = array('url' => qa_path_html('activity'), 'label' => qa_lang_html('main/nav_activity'));
    }
    $hascustomhome = qa_has_custom_home();
    if (qa_opt($hascustomhome ? 'nav_qa_not_home' : 'nav_qa_is_home')) {
        $qa_content['navigation']['main'][$hascustomhome ? 'qa' : '$'] = array('url' => qa_path_html($hascustomhome ? 'qa' : ''), 'label' => qa_lang_html('main/nav_qa'));
    }
    if (qa_opt('nav_questions')) {
        $qa_content['navigation']['main']['questions'] = array('url' => qa_path_html('questions'), 'label' => qa_lang_html('main/nav_qs'));
    }
    if (qa_opt('nav_hot')) {
        $qa_content['navigation']['main']['hot'] = array('url' => qa_path_html('hot'), 'label' => qa_lang_html('main/nav_hot'));
    }
    if (qa_opt('nav_unanswered')) {
        $qa_content['navigation']['main']['unanswered'] = array('url' => qa_path_html('unanswered'), 'label' => qa_lang_html('main/nav_unanswered'));
    }
    if (qa_using_tags() && qa_opt('nav_tags')) {
        $qa_content['navigation']['main']['tag'] = array('url' => qa_path_html('tags'), 'label' => qa_lang_html('main/nav_tags'));
    }
    if (qa_using_categories() && qa_opt('nav_categories')) {
        $qa_content['navigation']['main']['categories'] = array('url' => qa_path_html('categories'), 'label' => qa_lang_html('main/nav_categories'));
    }
    if (qa_opt('nav_users')) {
        $qa_content['navigation']['main']['user'] = array('url' => qa_path_html('users'), 'label' => qa_lang_html('main/nav_users'));
    }
    if (qa_user_permit_error('permit_post_q') != 'level') {
        $qa_content['navigation']['main']['ask'] = array('url' => qa_path_html('ask', qa_using_categories() && strlen($lastcategoryid) ? array('cat' => $lastcategoryid) : null), 'label' => qa_lang_html('main/nav_ask'));
    }
    if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
        $qa_content['navigation']['main']['admin'] = array('url' => qa_path_html(isset($_COOKIE['qa_admin_last']) && isset($QA_CONST_ROUTING[$_COOKIE['qa_admin_last']]) ? $_COOKIE['qa_admin_last'] : 'admin'), 'label' => qa_lang_html('main/nav_admin'));
    }
    $qa_content['search'] = array('form_tags' => 'METHOD="GET" ACTION="' . qa_path_html('search') . '"', 'form_extra' => qa_path_form_html('search'), 'title' => qa_lang_html('main/search_title'), 'field_tags' => 'NAME="q"', 'button_label' => qa_lang_html('main/search_button'));
    if (!qa_opt('feedback_enabled')) {
        unset($qa_content['navigation']['footer']['feedback']);
    }
    foreach ($qa_nav_pages_cached as $page) {
        if ($page['nav'] == 'M' || $page['nav'] == 'O' || $page['nav'] == 'F') {
            qa_navigation_add_page($qa_content['navigation'][$page['nav'] == 'F' ? 'footer' : 'main'], $page);
        }
    }
    $regioncodes = array('F' => 'full', 'M' => 'main', 'S' => 'side');
    $placecodes = array('T' => 'top', 'H' => 'high', 'L' => 'low', 'B' => 'bottom');
    foreach ($qa_widgets_cached as $widget) {
        if (is_numeric(strpos(',' . $widget['tags'] . ',', ',' . $qa_template . ',')) || is_numeric(strpos(',' . $widget['tags'] . ',', ',all,'))) {
            // see if it has been selected for display on this template
            $region = @$regioncodes[substr($widget['place'], 0, 1)];
            $place = @$placecodes[substr($widget['place'], 1, 2)];
            if (isset($region) && isset($place)) {
                // check region/place codes recognized
                $module = qa_load_module('widget', $widget['title']);
                if (isset($module) && method_exists($module, 'allow_template') && $module->allow_template($qa_template) && method_exists($module, 'allow_region') && $module->allow_region($region) && method_exists($module, 'output_widget')) {
                    $qa_content['widgets'][$region][$place][] = $module;
                }
                // if module loaded and happy to be displayed here, tell theme about it
            }
        }
    }
    $logoshow = qa_opt('logo_show');
    $logourl = qa_opt('logo_url');
    $logowidth = qa_opt('logo_width');
    $logoheight = qa_opt('logo_height');
    if ($logoshow) {
        $qa_content['logo'] = '<A HREF="' . qa_path_html('') . '" CLASS="qa-logo-link" TITLE="' . qa_html(qa_opt('site_title')) . '">' . '<IMG SRC="' . qa_html(is_numeric(strpos($logourl, '://')) ? $logourl : $qa_root_url_relative . $logourl) . '"' . ($logowidth ? ' WIDTH="' . $logowidth . '"' : '') . ($logoheight ? ' HEIGHT="' . $logoheight . '"' : '') . ' BORDER="0"/></A>';
    } else {
        $qa_content['logo'] = '<A HREF="' . qa_path_html('') . '" CLASS="qa-logo-link">' . qa_html(qa_opt('site_title')) . '</A>';
    }
    $topath = qa_get('to');
    // lets user switch between login and register without losing destination page
    $userlinks = qa_get_login_links($qa_root_url_relative, isset($topath) ? $topath : qa_path($qa_request, $_GET, ''));
    $qa_content['navigation']['user'] = array();
    if (isset($qa_login_userid)) {
        $qa_content['loggedin'] = qa_lang_html_sub_split('main/logged_in_x', QA_FINAL_EXTERNAL_USERS ? qa_get_logged_in_user_html(qa_get_logged_in_user_cache(), $qa_root_url_relative, false) : qa_get_one_user_html(qa_get_logged_in_handle(), false));
        if (!QA_FINAL_EXTERNAL_USERS) {
            $qa_content['navigation']['user']['account'] = array('url' => qa_path_html('account'), 'label' => qa_lang_html('main/nav_account'));
        }
        if (!empty($userlinks['logout'])) {
            $qa_content['navigation']['user']['logout'] = array('url' => qa_html(@$userlinks['logout']), 'label' => qa_lang_html('main/nav_logout'));
        }
        if (!QA_FINAL_EXTERNAL_USERS) {
            $source = qa_get_logged_in_source();
            if (strlen($source)) {
                $modulenames = qa_list_modules('login');
                foreach ($modulenames as $tryname) {
                    $module = qa_load_module('login', $tryname);
                    if (method_exists($module, 'match_source') && $module->match_source($source) && method_exists($module, 'logout_html')) {
                        ob_start();
                        $module->logout_html(qa_path('logout', array(), qa_opt('site_url')));
                        $qa_content['navigation']['user']['logout'] = array('label' => ob_get_clean());
                    }
                }
            }
        }
    } else {
        $modulenames = qa_list_modules('login');
        foreach ($modulenames as $tryname) {
            $module = qa_load_module('login', $tryname);
            if (method_exists($module, 'login_html')) {
                ob_start();
                $module->login_html(isset($topath) ? qa_opt('site_url') . $topath : qa_path($qa_request, $_GET, qa_opt('site_url')), 'menu');
                $qa_content['navigation']['user'][$tryname] = array('label' => ob_get_clean());
            }
        }
        if (!empty($userlinks['login'])) {
            $qa_content['navigation']['user']['login'] = array('url' => qa_html(@$userlinks['login']), 'label' => qa_lang_html('main/nav_login'));
        }
        if (!empty($userlinks['register'])) {
            $qa_content['navigation']['user']['register'] = array('url' => qa_html(@$userlinks['register']), 'label' => qa_lang_html('main/nav_register'));
        }
    }
    $qa_content['script_rel'] = array('qa-content/jquery-1.6.1.min.js');
    if ($voting) {
        $qa_content['error'] = @$qa_vote_error_html;
        $qa_content['script_rel'][] = 'qa-content/qa-votes.js?' . QA_VERSION;
    }
    $qa_content['script_var'] = array('qa_root' => $qa_root_url_relative, 'qa_request' => $qa_request);
    return $qa_content;
}
Example #11
0
function qa_admin_is_slug_reserved($requestpart)
{
    global $QA_CONST_ROUTING, $QA_CONST_PATH_MAP;
    $requestpart = trim(strtolower($requestpart));
    if (isset($QA_CONST_ROUTING[$requestpart]) || isset($QA_CONST_ROUTING[$requestpart . '/']) || is_numeric($requestpart)) {
        return true;
    }
    if (isset($QA_CONST_PATH_MAP)) {
        foreach ($QA_CONST_PATH_MAP as $requestmap) {
            if (trim(strtolower($requestmap)) == $requestpart) {
                return true;
            }
        }
    }
    switch ($requestpart) {
        case '':
        case 'qa':
        case 'feed':
        case 'install':
        case 'url':
        case 'image':
        case 'ajax':
            return true;
    }
    $modulenames = qa_list_modules('page');
    foreach ($modulenames as $tryname) {
        $trypage = qa_load_module('page', $tryname);
        if (method_exists($trypage, 'match_request') && $trypage->match_request($requestpart)) {
            return true;
        }
    }
    return false;
}
Example #12
0
function qa_load_viewer($content, $format)
{
    $maxviewer = null;
    $maxquality = 0;
    $modulenames = qa_list_modules('viewer');
    foreach ($modulenames as $tryname) {
        $tryviewer = qa_load_module('viewer', $tryname);
        $tryquality = $tryviewer->calc_quality($content, $format);
        if ($tryquality > $maxquality) {
            $maxviewer = $tryviewer;
            $maxquality = $tryquality;
        }
    }
    return $maxviewer;
}
Example #13
0
function qa_report_event($event, $userid, $handle, $cookieid, $params = array())
{
    global $qa_event_reports_suspended;
    if ($qa_event_reports_suspended > 0) {
        return;
    }
    require_once QA_INCLUDE_DIR . 'qa-app-cookies.php';
    $modulenames = qa_list_modules('event');
    foreach ($modulenames as $tryname) {
        $trymodule = qa_load_module('event', $tryname);
        if (method_exists($trymodule, 'process_event')) {
            $trymodule->process_event($event, $userid, $handle, $cookieid, $params);
        }
    }
}
    $qa_template = 'custom';
    $qa_content = qa_content_prepare();
    $qa_content['title'] = qa_html($custompage['heading']);
    $qa_content['custom'] = $custompage['content'];
    if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
        $qa_content['navigation']['sub'] = array('admin/pages' => array('label' => qa_lang('admin/edit_custom_page'), 'url' => qa_path_html('admin/pages', array('edit' => $custompage['pageid']))));
    }
    return $qa_content;
}
//	Then, see if we should redirect because the 'qa' page is the same as the home page
if ($explicitqa && !qa_is_http_post() && !qa_has_custom_home()) {
    qa_redirect(qa_category_path_request($categories, $categoryid), $_GET);
}
//	Then, if there's a slug that matches no category, check page modules provided by plugins
if (!$explicitqa && $countslugs && !isset($categoryid)) {
    $modulenames = qa_list_modules('page');
    foreach ($modulenames as $tryname) {
        $trypage = qa_load_module('page', $tryname);
        if (method_exists($trypage, 'match_request') && $trypage->match_request($qa_request)) {
            $qa_template = 'plugin';
            return $trypage->process_request($qa_request);
        }
    }
}
//	Then, check whether we are showing a custom home page
if (!$explicitqa && !$countslugs && qa_opt('show_custom_home')) {
    $qa_template = 'custom';
    $qa_content = qa_content_prepare();
    $qa_content['title'] = qa_html(qa_opt('custom_home_heading'));
    if (qa_opt('show_home_description')) {
        $qa_content['description'] = qa_html(qa_opt('home_description'));
Example #15
0
function qa_default_option($name)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    $fixed_defaults = array('allow_change_usernames' => 1, 'allow_close_questions' => 1, 'allow_multi_answers' => 1, 'allow_private_messages' => 1, 'allow_self_answer' => 1, 'allow_view_q_bots' => 1, 'avatar_allow_gravatar' => 1, 'avatar_allow_upload' => 1, 'avatar_profile_size' => 200, 'avatar_q_list_size' => 0, 'avatar_q_page_a_size' => 40, 'avatar_q_page_c_size' => 20, 'avatar_q_page_q_size' => 50, 'avatar_store_size' => 400, 'avatar_users_size' => 30, 'captcha_on_anon_post' => 1, 'captcha_on_feedback' => 1, 'captcha_on_register' => 1, 'captcha_on_reset_password' => 1, 'captcha_on_unconfirmed' => 0, 'columns_tags' => 3, 'columns_users' => 2, 'comment_on_as' => 1, 'comment_on_qs' => 0, 'confirm_user_emails' => 1, 'do_ask_check_qs' => 0, 'do_complete_tags' => 1, 'do_count_q_views' => 1, 'do_example_tags' => 1, 'feed_for_activity' => 1, 'feed_for_qa' => 1, 'feed_for_questions' => 1, 'feed_for_unanswered' => 1, 'feed_full_text' => 1, 'feed_number_items' => 50, 'feed_per_category' => 1, 'feedback_enabled' => 1, 'flagging_hide_after' => 5, 'flagging_notify_every' => 2, 'flagging_notify_first' => 1, 'flagging_of_posts' => 1, 'follow_on_as' => 1, 'hot_weight_a_age' => 100, 'hot_weight_answers' => 100, 'hot_weight_q_age' => 100, 'hot_weight_views' => 100, 'hot_weight_votes' => 100, 'mailing_per_minute' => 500, 'match_ask_check_qs' => 3, 'match_example_tags' => 3, 'match_related_qs' => 3, 'max_copy_user_updates' => 10, 'max_len_q_title' => 120, 'max_num_q_tags' => 5, 'max_rate_ip_as' => 50, 'max_rate_ip_cs' => 40, 'max_rate_ip_flags' => 10, 'max_rate_ip_logins' => 20, 'max_rate_ip_messages' => 10, 'max_rate_ip_qs' => 20, 'max_rate_ip_registers' => 5, 'max_rate_ip_uploads' => 20, 'max_rate_ip_votes' => 600, 'max_rate_user_as' => 25, 'max_rate_user_cs' => 20, 'max_rate_user_flags' => 5, 'max_rate_user_messages' => 5, 'max_rate_user_qs' => 10, 'max_rate_user_uploads' => 10, 'max_rate_user_votes' => 300, 'max_store_user_updates' => 50, 'min_len_a_content' => 12, 'min_len_c_content' => 12, 'min_len_q_content' => 0, 'min_len_q_title' => 12, 'min_num_q_tags' => 0, 'moderate_notify_admin' => 1, 'moderate_points_limit' => 150, 'nav_ask' => 1, 'nav_qa_not_home' => 1, 'nav_questions' => 1, 'nav_tags' => 1, 'nav_unanswered' => 1, 'nav_users' => 1, 'neat_urls' => QA_URL_FORMAT_SAFEST, 'notify_users_default' => 1, 'page_size_activity' => 20, 'page_size_ask_check_qs' => 5, 'page_size_ask_tags' => 5, 'page_size_home' => 20, 'page_size_hot_qs' => 20, 'page_size_q_as' => 10, 'page_size_qs' => 20, 'page_size_related_qs' => 5, 'page_size_search' => 10, 'page_size_tag_qs' => 20, 'page_size_tags' => 30, 'page_size_una_qs' => 20, 'page_size_user_posts' => 20, 'page_size_users' => 20, 'pages_prev_next' => 3, 'permit_anon_view_ips' => QA_PERMIT_EDITORS, 'permit_close_q' => QA_PERMIT_EDITORS, 'permit_delete_hidden' => QA_PERMIT_MODERATORS, 'permit_edit_a' => QA_PERMIT_EXPERTS, 'permit_edit_c' => QA_PERMIT_EDITORS, 'permit_edit_q' => QA_PERMIT_EDITORS, 'permit_flag' => QA_PERMIT_CONFIRMED, 'permit_hide_show' => QA_PERMIT_EDITORS, 'permit_moderate' => QA_PERMIT_EXPERTS, 'permit_select_a' => QA_PERMIT_EXPERTS, 'permit_view_q_page' => QA_PERMIT_ALL, 'permit_vote_a' => QA_PERMIT_USERS, 'permit_vote_down' => QA_PERMIT_USERS, 'permit_vote_q' => QA_PERMIT_USERS, 'points_a_selected' => 30, 'points_a_voted_max_gain' => 20, 'points_a_voted_max_loss' => 5, 'points_base' => 100, 'points_multiple' => 10, 'points_post_a' => 4, 'points_post_q' => 2, 'points_q_voted_max_gain' => 10, 'points_q_voted_max_loss' => 3, 'points_select_a' => 3, 'q_urls_title_length' => 50, 'show_a_c_links' => 1, 'show_a_form_immediate' => 'if_no_as', 'show_c_reply_buttons' => 1, 'show_custom_welcome' => 1, 'show_fewer_cs_count' => 5, 'show_fewer_cs_from' => 10, 'show_full_date_days' => 7, 'show_message_history' => 1, 'show_selected_first' => 1, 'show_url_links' => 1, 'show_user_points' => 1, 'show_user_titles' => 1, 'show_when_created' => 1, 'site_theme' => 'Snow', 'smtp_port' => 25, 'sort_answers_by' => 'created', 'tags_or_categories' => 'tc', 'voting_on_as' => 1, 'voting_on_qs' => 1);
    if (isset($fixed_defaults[$name])) {
        $value = $fixed_defaults[$name];
    } else {
        switch ($name) {
            case 'site_url':
                $value = 'http://' . @$_SERVER['HTTP_HOST'] . strtr(dirname($_SERVER['SCRIPT_NAME']), '\\', '/') . '/';
                break;
            case 'site_title':
                $value = qa_default_site_title();
                break;
            case 'site_theme_mobile':
                $value = qa_opt('site_theme');
                break;
            case 'from_email':
                // heuristic to remove short prefix (e.g. www. or qa.)
                $parts = explode('.', @$_SERVER['HTTP_HOST']);
                if (count($parts) > 2 && strlen($parts[0]) < 5 && !is_numeric($parts[0])) {
                    unset($parts[0]);
                }
                $value = 'no-reply@' . (count($parts) > 1 ? implode('.', $parts) : 'example.com');
                break;
            case 'email_privacy':
                $value = qa_lang_html('options/default_privacy');
                break;
            case 'show_custom_sidebar':
                $value = strlen(qa_opt('custom_sidebar')) ? true : false;
                break;
            case 'show_custom_header':
                $value = strlen(qa_opt('custom_header')) ? true : false;
                break;
            case 'show_custom_footer':
                $value = strlen(qa_opt('custom_footer')) ? true : false;
                break;
            case 'show_custom_in_head':
                $value = strlen(qa_opt('custom_in_head')) ? true : false;
                break;
            case 'custom_sidebar':
                $value = qa_lang_html_sub('options/default_sidebar', qa_html(qa_opt('site_title')));
                break;
            case 'editor_for_qs':
            case 'editor_for_as':
                require_once QA_INCLUDE_DIR . 'qa-app-format.php';
                $value = '-';
                // to match none by default, i.e. choose based on who is best at editing HTML
                qa_load_editor('', 'html', $value);
                break;
            case 'permit_post_q':
                // convert from deprecated option if available
                $value = qa_opt('ask_needs_login') ? QA_PERMIT_USERS : QA_PERMIT_ALL;
                break;
            case 'permit_post_a':
                // convert from deprecated option if available
                $value = qa_opt('answer_needs_login') ? QA_PERMIT_USERS : QA_PERMIT_ALL;
                break;
            case 'permit_post_c':
                // convert from deprecated option if available
                $value = qa_opt('comment_needs_login') ? QA_PERMIT_USERS : QA_PERMIT_ALL;
                break;
            case 'permit_retag_cat':
                // convert from previous option that used to contain it too
                $value = qa_opt('permit_edit_q');
                break;
            case 'points_vote_up_q':
            case 'points_vote_down_q':
                $oldvalue = qa_opt('points_vote_on_q');
                $value = is_numeric($oldvalue) ? $oldvalue : 1;
                break;
            case 'points_vote_up_a':
            case 'points_vote_down_a':
                $oldvalue = qa_opt('points_vote_on_a');
                $value = is_numeric($oldvalue) ? $oldvalue : 1;
                break;
            case 'points_per_q_voted_up':
            case 'points_per_q_voted_down':
                $oldvalue = qa_opt('points_per_q_voted');
                $value = is_numeric($oldvalue) ? $oldvalue : 1;
                break;
            case 'points_per_a_voted_up':
            case 'points_per_a_voted_down':
                $oldvalue = qa_opt('points_per_a_voted');
                $value = is_numeric($oldvalue) ? $oldvalue : 2;
                break;
            case 'captcha_module':
                $captchamodules = qa_list_modules('captcha');
                if (count($captchamodules)) {
                    $value = reset($captchamodules);
                } else {
                    $value = '';
                }
                break;
            case 'mailing_from_name':
                $value = qa_opt('site_title');
                break;
            case 'mailing_from_email':
                $value = qa_opt('from_email');
                break;
            case 'mailing_subject':
                $value = qa_lang_sub('options/default_subject', qa_opt('site_title'));
                break;
            case 'mailing_body':
                $value = "\n\n\n--\n" . qa_opt('site_title') . "\n" . qa_opt('site_url');
                break;
            default:
                // call option_default method in any registered modules
                $moduletypes = qa_list_module_types();
                foreach ($moduletypes as $moduletype) {
                    $modules = qa_load_modules_with($moduletype, 'option_default');
                    foreach ($modules as $module) {
                        $value = $module->option_default($name);
                        if (strlen($value)) {
                            return $value;
                        }
                    }
                }
                $value = '';
                break;
        }
    }
    return $value;
}
Example #16
0
    }
} else {
    $pageerror = qa_lang('users/login_limit');
}
//	Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('users/login_title');
$qa_content['error'] = @$pageerror;
if (empty($inemailhandle) || isset($errors['emailhandle'])) {
    $forgotpath = qa_path('forgot');
} else {
    $forgotpath = qa_path('forgot', array('e' => $inemailhandle));
}
$forgothtml = '<A HREF="' . qa_html($forgotpath) . '">' . qa_lang_html('users/forgot_link') . '</A>';
$qa_content['form'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'tall', 'ok' => $passwordsent ? qa_lang_html('users/password_sent') : null, 'fields' => array('email_handle' => array('label' => qa_lang_html('users/email_handle_label'), 'tags' => 'NAME="emailhandle" ID="emailhandle"', 'value' => qa_html(@$inemailhandle), 'error' => qa_html(@$errors['emailhandle'])), 'password' => array('type' => 'password', 'label' => qa_lang_html('users/password_label'), 'tags' => 'NAME="password" ID="password"', 'value' => qa_html(@$inpassword), 'error' => empty($errors['password']) ? '' : qa_html(@$errors['password']) . ' - ' . $forgothtml . ' ->' . qa_html(@$errors['category']) . '<-', 'note' => $passwordsent ? qa_lang_html('users/password_sent') : $forgothtml), 'category' => array('label' => qa_lang_html('question/q_category_label'), 'tags' => 'NAME="category" ID="category"', 'value' => qa_html(@$incategory), 'error' => qa_html(@$errors['category'])), 'remember' => array('type' => 'checkbox', 'label' => qa_lang_html('users/remember_label'), 'tags' => 'NAME="remember"', 'value' => @$inremember ? true : false)), 'buttons' => array('login' => array('label' => qa_lang_html('users/login_button'))), 'hidden' => array('dologin' => '1'));
$modulenames = qa_list_modules('login');
foreach ($modulenames as $tryname) {
    $module = qa_load_module('login', $tryname);
    if (method_exists($module, 'login_html')) {
        ob_start();
        $module->login_html(qa_opt('site_url') . qa_get('to'), 'login');
        $html = ob_get_clean();
        if (strlen($html)) {
            @($qa_content['custom'] .= '<BR>' . $html . '<BR>');
        }
    }
}
$qa_content['focusid'] = isset($inemailhandle) && !isset($errors['emailhandle']) ? 'password' : 'emailhandle';
// add handling of sub categories
//if (qa_using_categories() && count($categories)) {
//	$incategoryid=qa_get_category_field_value('category');
 function qa_check_all_users_badges()
 {
     $awarded = 0;
     $users;
     $temp = qa_db_query_sub('SELECT * FROM ^posts');
     while (($post = qa_db_read_one_assoc($temp, true)) !== null) {
         if (!$post['userid']) {
             continue;
         }
         $user = '******' . $post['userid'];
         $pid = $post['postid'];
         $pt = $post['type'];
         // get post count
         if (isset($users[$user]) && isset($users[$user][$pt])) {
             $users[$user][$pt]++;
         } else {
             $users[$user][$pt] = 1;
         }
         // get post votes
         if ($post['netvotes'] != 0) {
             $users[$user][$pt . 'votes'][] = array('id' => $pid, 'votes' => (int) $post['netvotes'], 'parentid' => $post['parentid'], 'created' => $post['created']);
         }
         // get post views
         if ($post['views']) {
             $users[$user]['views'][] = array('id' => $pid, 'views' => $post['views']);
         }
     }
     //votes received and given out
     $voter = qa_db_read_all_assoc(qa_db_query_sub('SELECT userid,qupvotes,qdownvotes,aupvotes,adownvotes,upvoteds FROM ^userpoints'));
     foreach ($voter as $idx => $votes) {
         $user = '******' . $votes['userid'];
         // votes
         $users[$user]['votes'] = (int) $votes['qupvotes'] + (int) $votes['qdownvotes'] + (int) $votes['aupvotes'] + (int) $votes['adownvotes'];
         // voteds
         $users[$user]['voted'] = (int) $votes['upvoteds'];
         unset($voter[$idx]);
     }
     // flags
     $flag_result = qa_db_read_all_values(qa_db_query_sub('SELECT userid FROM ^uservotes WHERE flag > 0'));
     foreach ($flag_result as $idx => $flag) {
         $user = '******' . $flag;
         // get flag count
         if (isset($users[$user]) && isset($users[$user]['flags'])) {
             $users[$user]['flags']++;
         } else {
             $users[$user]['flags'] = 1;
         }
         unset($flag_result[$idx]);
     }
     // per user loop
     foreach ($users as $user => $data) {
         $uid = (int) substr($user, 4);
         // bulk posts
         $badges = array('Q' => array('asker', 'questioner', 'inquisitor'), 'A' => array('answerer', 'lecturer', 'preacher'), 'C' => array('commenter', 'commentator', 'annotator'));
         foreach ($badges as $pt => $slugs) {
             if (!isset($data[$pt])) {
                 continue;
             }
             $awarded += count(qa_badge_award_check($slugs, $data[$pt], $uid, null, 0));
         }
         // nice Q&A
         $badges = array('nice_question', 'good_question', 'great_question', 'nice_answer', 'good_answer', 'great_answer');
         if ($this->badge_activated($badges)) {
             $badges = array('Q' => array('nice_question', 'good_question', 'great_question'), 'A' => array('nice_answer', 'good_answer', 'great_answer'));
             foreach ($badges as $pt => $slugs) {
                 foreach ($slugs as $badge_slug) {
                     if (!isset($data[$pt . 'votes'])) {
                         continue;
                     }
                     foreach ($data[$pt . 'votes'] as $idv) {
                         // poll plugin integration
                         if ($pt == 'A' && qa_opt('poll_enable')) {
                             $poll = qa_db_read_one_value(qa_db_query_sub('SELECT meta_value FROM ^postmeta WHERE post_id=# AND meta_key=$', $idv['id'], 'is_poll'), true);
                             if ($poll) {
                                 continue;
                             }
                         }
                         if ((int) $idv['votes'] >= (int) qa_opt('badge_' . $badge_slug . '_var') && qa_opt('badge_' . $badge_slug . '_enabled') !== '0') {
                             $result = qa_db_read_one_value(qa_db_query_sub('SELECT badge_slug FROM ^userbadges WHERE user_id=# AND object_id=# AND badge_slug=$', $uid, $idv['id'], $badge_slug), true);
                             if ($result == null) {
                                 // not already awarded this badge
                                 $this->award_badge($idv['id'], $uid, $badge_slug, false, true);
                                 $awarded++;
                             }
                             // old question answer vote checks
                             if ($pt == 'A') {
                                 $qid = $idv['parentid'];
                                 $create = strtotime($idv['created']);
                                 $parent = $this->get_post_data($qid);
                                 $pcreate = strtotime($parent['created']);
                                 $diff = round(abs($pcreate - $create) / 60 / 60 / 24);
                                 $badge_slug2 = $badge_slug . '_old';
                                 if ($diff >= (int) qa_opt('badge_' . $badge_slug2 . '_var') && qa_opt('badge_' . $badge_slug2 . '_enabled') !== '0') {
                                     $result = qa_db_read_one_value(qa_db_query_sub('SELECT badge_slug FROM ^userbadges WHERE user_id=# AND object_id=# AND badge_slug=$', $uid, $idv['id'], $badge_slug2), true);
                                     if ($result == null) {
                                         // not already awarded for this answer
                                         $this->award_badge($idv['id'], $uid, $badge_slug2);
                                         $awarded++;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         // votes per user badges
         if (isset($data['votes'])) {
             $votes = $data['votes'];
             $badges = array('voter', 'avid_voter', 'devoted_voter');
             $awarded += count(qa_badge_award_check($badges, $votes, $uid, null, 0));
         }
         // voted per user badges
         if (isset($data['voted'])) {
             $votes = $data['voted'];
             $badges = array('liked', 'loved', 'revered');
             $awarded += count(qa_badge_award_check($badges, $votes, $uid, null, 0));
         }
         // views per post badges
         if (isset($data['views'])) {
             $badges = array('notable_question', 'popular_question', 'famous_question');
             foreach ($data['views'] as $idv) {
                 $awarded += count(qa_badge_award_check($badges, $idv['views'], $uid, $idv['id'], 0));
             }
         }
         // flags per user
         if (isset($data['flags'])) {
             $flags = $data['flags'];
             $badges = array('watchdog', 'bloodhound', 'pitbull');
             $awarded += count(qa_badge_award_check($badges, $flags, $uid, null, 0));
         }
         unset($users[$user]);
     }
     // selects, selecteds
     $badges = array('gifted', 'wise', 'enlightened', 'grateful', 'respectful', 'reverential');
     if ($this->badge_activated($badges)) {
         $selects = qa_db_read_all_assoc(qa_db_query_sub('SELECT aselects, aselecteds, userid FROM ^userpoints'));
         foreach ($selects as $idx => $s) {
             $uid = $s['userid'];
             if (isset($s['aselecteds'])) {
                 $count = $s['aselecteds'];
                 $badges = array('gifted', 'wise', 'enlightened');
                 $awarded += count(qa_badge_award_check($badges, $count, $uid, null, 0));
             }
             if (isset($s['aselects'])) {
                 $count = $s['aselects'];
                 $badges = array('grateful', 'respectful', 'reverential');
                 $awarded += count(qa_badge_award_check($badges, $count, $uid, null, 0));
             }
             unset($selects[$idx]);
         }
     }
     // achievements
     $badges = array('dedicated', 'devoted', 'zealous', 'visitor', 'trouper', 'veteran', 'regular', 'old_timer', 'ancestor', 'reader', 'avid_reader', 'devoted_reader');
     if ($this->badge_activated($badges)) {
         $userq = qa_db_query_sub('SELECT user_id AS uid,questions_read AS qr,oldest_consec_visit AS ocv,longest_consec_visit AS lcv,total_days_visited AS tdv,last_visit AS lv,first_visit AS fv,posts_edited AS pe FROM ^achievements');
         while (($user = qa_db_read_one_assoc($userq, true)) !== null) {
             $uid = $user['uid'];
             // edits
             $count = $user['pe'];
             $badges = array('editor', 'copy_editor', 'senior_editor');
             $awarded += count(qa_badge_award_check($badges, $count, $uid, null, 0));
             // on-sign-in badges
             // check lapse in days since last visit
             // using julian days
             $todayj = GregorianToJD(date('n'), date('j'), date('Y'));
             $last_visit = strtotime($user['lv']);
             $lastj = GregorianToJD(date('n', $last_visit), date('j', $last_visit), date('Y', $last_visit));
             $last_diff = $todayj - $lastj;
             $first_visit = strtotime($user['fv']);
             $first_visitj = GregorianToJD(date('n', $first_visit), date('j', $first_visit), date('Y', $first_visit));
             $first_visit_diff = $todayj - $first_visitj;
             $badges = array('dedicated', 'devoted', 'zealous');
             $awarded += count(qa_badge_award_check($badges, $user['lcv'], $uid, null, 0));
             $badges = array('visitor', 'trouper', 'veteran');
             $awarded += count(qa_badge_award_check($badges, $user['tdv'], $uid, null, 0));
             $badges = array('regular', 'old_timer', 'ancestor');
             $awarded += count(qa_badge_award_check($badges, $first_visit_diff, $uid, null, 0));
             // views
             $badges = array('reader', 'avid_reader', 'devoted_reader');
             $awarded += count(qa_badge_award_check($badges, $user['qr'], $uid, null, 0));
         }
     }
     // points
     $badges = array('100_club', '1000_club', '10000_club');
     if ($this->badge_activated($badges)) {
         $userq = qa_db_query_sub('SELECT userid, points FROM ^userpoints');
         while (($user = qa_db_read_one_assoc($userq, true)) !== null) {
             $awarded += count(qa_badge_award_check($badges, $user['points'], $user['userid'], null, 0));
         }
     }
     if (!QA_FINAL_EXTERNAL_USERS) {
         // verified
         $badges = array('verified');
         if ($this->badge_activated($badges)) {
             $userq = qa_db_query_sub('SELECT userid, flags FROM ^users WHERE flags&#', QA_USER_FLAGS_EMAIL_CONFIRMED);
             while (($user = qa_db_read_one_assoc($userq, true)) !== null) {
                 $awarded += count(qa_badge_award_check($badges, false, $user['userid'], null, 0));
             }
         }
         // profile stuff
         $badges = array('avatar', 'profiler');
         if ($this->badge_activated($badges)) {
             $userq = qa_db_query_sub('SELECT userid FROM ^users');
             while (($userid = qa_db_read_one_value($userq, true)) !== null) {
                 list($useraccount, $userprofile, $userfields) = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true), qa_db_user_profile_selectspec($userid, true), qa_db_userfields_selectspec());
                 // avatar badge
                 if (qa_opt('avatar_allow_upload') && isset($useraccount['avatarblobid'])) {
                     $badges = array('avatar');
                     $awarded += count(qa_badge_award_check($badges, false, $userid, null, 0));
                 }
                 // profile completion
                 $missing = false;
                 foreach ($userfields as $userfield) {
                     if (!isset($userprofile[$userfield['title']]) || @$userprofile[$userfield['title']] === '') {
                         $missing = true;
                         break;
                     }
                 }
                 if (!$missing) {
                     $badges = array('profiler');
                     $awarded += count(qa_badge_award_check($badges, false, $userid, null, 0));
                 }
             }
         }
     }
     // rebuild badges from other plugins - experimental! - $module->custom_badges_rebuild() returns number of badges awarded.
     $moduletypes = qa_list_module_types();
     foreach ($moduletypes as $moduletype) {
         $modulenames = qa_list_modules($moduletype);
         foreach ($modulenames as $modulename) {
             $module = qa_load_module($moduletype, $modulename);
             if (method_exists($module, 'custom_badges_rebuild')) {
                 $awarded += $module->custom_badges_rebuild();
             }
         }
     }
     // badges
     $badges = array('medalist', 'champion', 'olympian');
     if ($this->badge_activated($badges)) {
         $badgelist = qa_db_read_all_values(qa_db_query_sub('SELECT user_id FROM ^userbadges'));
         $users = array();
         foreach ($badgelist as $idx => $medal) {
             $user = '******' . $medal;
             // get badge count
             if (isset($users[$user]) && isset($users[$user]['medals'])) {
                 $users[$user]['medals']++;
             } else {
                 $users[$user]['medals'] = 1;
             }
             unset($badgelist[$idx]);
         }
         foreach ($users as $user => $data) {
             $uid = (int) substr($user, 4);
             // check badges
             if (isset($data['medals'])) {
                 $uid = (int) substr($user, 4);
                 $count = $data['medals'];
                 $awarded += count(qa_badge_award_check($badges, $count, $uid, null, 0));
             }
             unset($users[$user]);
         }
     }
     // return ok text
     return $awarded . ' badge' . ($awarded != 1 ? 's' : '') . ' awarded.';
 }
Example #18
0
         $listhtml .= '<LI><B><A HREF="' . qa_path_html('admin/userfields') . '">' . qa_lang_html('admin/add_new_field') . '</A></B></LI>';
         $qa_content['form']['fields']['userfields'] = array('label' => qa_lang_html('admin/profile_fields'), 'style' => 'tall', 'type' => 'custom', 'html' => strlen($listhtml) ? '<UL STYLE="margin-bottom:0;">' . $listhtml . '</UL>' : null);
     }
     $qa_content['form']['fields'][] = array('type' => 'blank');
     $pointstitle = qa_get_points_to_titles();
     $listhtml = '';
     foreach ($pointstitle as $points => $title) {
         $listhtml .= '<LI><B>' . $title . '</B> - ' . ($points == 1 ? qa_lang_html_sub('main/1_point', '1', '1') : qa_lang_html_sub('main/x_points', qa_html(number_format($points))));
         $listhtml .= strtr(qa_lang_html('admin/edit_title'), array('^1' => '<A HREF="' . qa_path_html('admin/usertitles', array('edit' => $points)) . '">', '^2' => '</A>'));
         $listhtml .= '</LI>';
     }
     $listhtml .= '<LI><B><A HREF="' . qa_path_html('admin/usertitles') . '">' . qa_lang_html('admin/add_new_title') . '</A></B></LI>';
     $qa_content['form']['fields']['usertitles'] = array('label' => qa_lang_html('admin/user_titles'), 'style' => 'tall', 'type' => 'custom', 'html' => strlen($listhtml) ? '<UL STYLE="margin-bottom:0;">' . $listhtml . '</UL>' : null);
     break;
 case 'layout':
     $modulenames = qa_list_modules('widget');
     $listhtml = '';
     foreach ($modulenames as $tryname) {
         $trywidget = qa_load_module('widget', $tryname);
         if (method_exists($trywidget, 'allow_template') && method_exists($trywidget, 'allow_region')) {
             $listhtml .= '<LI><B>' . qa_html($tryname) . '</B>';
             $listhtml .= strtr(qa_lang_html('admin/add_widget_link'), array('^1' => '<A HREF="' . qa_path_html('admin/layoutwidgets', array('title' => $tryname)) . '">', '^2' => '</A>'));
             if (method_exists($trywidget, 'admin_form')) {
                 $listhtml .= strtr(qa_lang_html('admin/widget_global_options'), array('^1' => '<A HREF="' . qa_path_html('admin/plugins', null, null, null, md5('widget/' . $tryname)) . '">', '^2' => '</A>'));
             }
             $listhtml .= '</LI>';
         }
     }
     if (strlen($listhtml)) {
         $qa_content['form']['fields']['plugins'] = array('label' => qa_lang_html('admin/plugin_widgets_explanation'), 'style' => 'tall', 'type' => 'custom', 'html' => '<UL STYLE="margin-bottom:0;">' . $listhtml . '</UL>');
     }