Example #1
0
 function main_parts($content)
 {
     if ($this->template == 'admin' && $this->request == 'admin/plugins') {
         $fields['plugins'] = array('type' => 'custom', 'label' => '<a name="plugin_contents">Plugin Settings:</a>', 'html' => '');
         $moduletypes = qa_list_module_types();
         foreach ($moduletypes as $moduletype) {
             $plugins[] = qa_load_modules_with($moduletype, 'option_default');
         }
         $anchors = array();
         foreach ($content as $key => $part) {
             if (strpos($key, 'form_') === 0) {
                 $content[$key]['title'] .= ' <font size="1" style="cursor:pointer; color:blue" onclick="jQuery(document).scrollTop(0)">top</font>';
                 foreach ($content[$key]['fields'] as $idx => $field) {
                     if (isset($field['tags']) && preg_match('|name="([^"]+)"|i', $field['tags'], $name)) {
                         $name = $name[1];
                         foreach ($plugins as $modules) {
                             foreach ($modules as $module) {
                                 $value = $module->option_default($name);
                                 $value = preg_replace('|\\n|', '\\\\n', $value);
                                 $value = str_replace('"', '&quot;', $value);
                                 $value = str_replace('\'', '\\\'', $value);
                                 if (strlen($value)) {
                                     $content[$key]['fields'][$idx]['label'] = @$content[$key]['fields'][$idx]['label'] . '&nbsp;<input type="button" onclick="$(\'[name=' . $name . ']\').val(\'' . $value . '\')" value="r" style="font-size:8pt; width:10px" title="reset to default value">';
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     qa_html_theme_base::main_parts($content);
 }
 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 #3
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;
}
            $authorhtml = '';
        }
        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'])) {
Example #5
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;
}
Example #6
0
function ra_installed_plugin()
{
    $tables = qa_db_list_tables_lc();
    $moduletypes = qa_list_module_types();
    $pluginfiles = glob(QA_PLUGIN_DIR . '*/qa-plugin.php');
    foreach ($moduletypes as $type) {
        $modules = qa_load_modules_with($type, 'init_queries');
        foreach ($modules as $name => $module) {
            $queries = $module->init_queries($tables);
            if (!empty($queries)) {
                if (qa_is_http_post()) {
                    qa_redirect('install');
                } else {
                    $qa_content['error'] = strtr(qa_lang_html('admin/module_x_database_init'), array('^1' => qa_html($name), '^2' => qa_html($type), '^3' => '<a href="' . qa_path_html('install') . '">', '^4' => '</a>'));
                }
            }
        }
    }
    if (qa_is_http_post() && !qa_check_form_security_code('admin/plugins', qa_post_text('qa_form_security_code'))) {
        $qa_content['error'] = qa_lang_html('misc/form_security_reload');
        $showpluginforms = false;
    } else {
        $showpluginforms = true;
    }
    $plugin = array();
    if (count($pluginfiles)) {
        foreach ($pluginfiles as $pluginindex => $pluginfile) {
            $plugindirectory = dirname($pluginfile) . '/';
            $hash = qa_admin_plugin_directory_hash($plugindirectory);
            $showthisform = $showpluginforms && qa_get('show') == $hash;
            $contents = file_get_contents($pluginfile);
            $metadata = qa_admin_addon_metadata($contents, array('name' => 'Plugin Name', 'uri' => 'Plugin URI', 'description' => 'Plugin Description', 'version' => 'Plugin Version', 'date' => 'Plugin Date', 'author' => 'Plugin Author', 'author_uri' => 'Plugin Author URI', 'license' => 'Plugin License', 'min_q2a' => 'Plugin Minimum Question2Answer Version', 'min_php' => 'Plugin Minimum PHP Version', 'update' => 'Plugin Update Check URI'));
            if (strlen(@$metadata['name'])) {
                $namehtml = qa_html($metadata['name']);
            } else {
                $namehtml = qa_lang_html('admin/unnamed_plugin');
            }
            $plugin_name = $namehtml;
            if (strlen(@$metadata['uri'])) {
                $plugin_uri = qa_html($metadata['uri']);
            }
            if (strlen(@$metadata['version'])) {
                $plugin_version = qa_html($metadata['version']);
            }
            if (strlen(@$metadata['author'])) {
                $plugin_author = qa_html($metadata['author']);
                if (strlen(@$metadata['author_uri'])) {
                    $plugin_author_url = qa_html($metadata['author_uri']);
                }
            }
            if (strlen(@$metadata['version']) && strlen(@$metadata['update'])) {
                $elementid = 'version_check_' . md5($plugindirectory);
                $plugin_update = '(<span id="' . $elementid . '"></span>)';
                $qa_content['script_onloads'][] = array("qa_version_check(" . qa_js($metadata['update']) . ", 'Plugin Version', " . qa_js($metadata['version'], true) . ", 'Plugin URI', " . qa_js($elementid) . ");");
            }
            if (strlen(@$metadata['description'])) {
                $plugin_description = qa_html($metadata['description']);
            }
            //if (isset($pluginoptionmodules[$plugindirectory]))
            $plugin_option = qa_admin_plugin_options_path($plugindirectory);
            if (qa_qa_version_below(@$metadata['min_q2a'])) {
                $plugin_error = qa_lang_html_sub('admin/requires_q2a_version', qa_html($metadata['min_q2a']));
            } elseif (qa_php_version_below(@$metadata['min_php'])) {
                $plugin_error = qa_lang_html_sub('admin/requires_php_version', qa_html($metadata['min_php']));
            }
            $plugin[] = array('tags' => 'id="' . qa_html($hash) . '"', 'name' => @$plugin_name, 'uri' => @$plugin_uri, 'version' => @$plugin_version, 'author' => @$plugin_author, 'author_url' => @$plugin_author_url, 'update' => @$plugin_update, 'description' => @$plugin_description, 'path' => @$plugindirectory, 'option' => @$plugin_option, 'error' => @$plugin_error, 'fields' => array(array('type' => 'custom')));
        }
    }
    return $plugin;
}