function qa_captcha_validate_post(&$errors)
{
    if (qa_captcha_available()) {
        $captcha = qa_load_module('captcha', qa_opt('captcha_module'));
        if (!$captcha->validate_post($error)) {
            $errors['captcha'] = $error;
            return false;
        }
    }
    return true;
}
Esempio n. 2
0
function ra_widget($name, $t)
{
    $module = qa_load_module('widget', $name);
    $module->output_widget('side', 'top', $t, $t->template, $t->request, $t->content);
}
Esempio n. 3
0
 if (qa_clicked('nonuser')) {
     qa_db_install_tables();
     $success .= 'The additional Question2Answer database tables have been created.';
 }
 if (qa_clicked('upgrade')) {
     qa_db_upgrade_tables();
     $success .= 'Your Question2Answer database has been updated.';
 }
 if (qa_clicked('repair')) {
     qa_db_install_tables();
     $success .= 'The Question2Answer database tables have been repaired.';
 }
 if (qa_clicked('module')) {
     $moduletype = qa_post_text('moduletype');
     $modulename = qa_post_text('modulename');
     $module = qa_load_module($moduletype, $modulename);
     $queries = $module->init_queries(qa_db_list_tables_lc());
     if (!empty($queries)) {
         if (!is_array($queries)) {
             $queries = array($queries);
         }
         foreach ($queries as $query) {
             qa_db_upgrade_query($query);
         }
     }
     $success .= 'The ' . $modulename . ' ' . $moduletype . ' module has completed database initialization.';
 }
 if (qa_clicked('super')) {
     require_once QA_INCLUDE_DIR . 'qa-db-users.php';
     require_once QA_INCLUDE_DIR . 'qa-app-users-edit.php';
     $inemail = qa_post_text('email');
Esempio n. 4
0
 function get_widget_form($name, $options = false)
 {
     $module = qa_load_module('widget', $name);
     if (is_object($module) && method_exists($module, 'cs_widget_form')) {
         $fields = $module->cs_widget_form();
         if ($options) {
             foreach ($options as $k => $opt) {
                 if (isset($fields['fields'][$k])) {
                     $fields['fields'][$k]['value'] = $opt;
                 }
             }
         }
         $this->form($fields);
     }
 }
Esempio n. 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;
}
Esempio n. 6
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;
}
Esempio n. 7
0
function qa_get_post_content($editorfield, $contentfield, &$ineditor, &$incontent, &$informat, &$intext)
{
    require_once QA_INCLUDE_DIR . 'util/string.php';
    $ineditor = qa_post_text($editorfield);
    $editor = qa_load_module('editor', $ineditor);
    $readdata = $editor->read_post($contentfield);
    // sanitise 4-byte Unicode
    $incontent = qa_remove_utf8mb4($readdata['content']);
    $informat = $readdata['format'];
    $intext = qa_remove_utf8mb4(qa_viewer_text($incontent, $informat));
}
 function ajaxEditor(&$ineditor, &$incontent, &$informat, &$intext)
 {
     $ineditor = qa_post_text('editor');
     $editor = qa_load_module('editor', $ineditor);
     $readdata = $editor->read_post('ajax_comment_content');
     $incontent = $readdata['content'];
     $informat = $readdata['format'];
     $viewer = qa_load_viewer($incontent, $informat);
     $intext = $viewer->get_text($incontent, $informat, array());
 }
Esempio n. 9
0
 function cs_get_widget($name, $show_title = false, $position)
 {
     $module = qa_load_module('widget', ltrim($name));
     if (is_object($module)) {
         ob_start();
         echo '<div class="widget ' . strtolower(str_replace(' ', '_', $name)) . '">';
         $module->output_widget('side', 'top', $this, $this->template, $this->request, $this->content);
         echo '</div>';
         $this->output(ob_get_clean());
     }
     return;
 }
Esempio n. 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;
}
Esempio n. 11
0
    $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');
//	if (!isset($incategoryid))
//		$incategoryid=qa_get('cat');
Esempio n. 12
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;
}
Esempio n. 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);
        }
    }
}
Esempio n. 14
0
    $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'));
    }
    $qa_content['custom'] = qa_opt('custom_home_content');
 function html_to_text($html)
 {
     $viewer = qa_load_module('viewer', '');
     return $viewer->get_text($html, 'html', array());
 }
Esempio n. 16
0
 function shortcode_widget($att, $cont = NULL)
 {
     if (qw_hook_exist(__FUNCTION__)) {
         $args = func_get_args();
         array_unshift($args, $this);
         return qw_event_hook(__FUNCTION__, $args, NULL);
     }
     $module = qa_load_module('widget', $att['name']);
     if (is_object($module)) {
         ob_start();
         $module->output_widget('side', 'top', $this, $this->template, $this->request, $this->content);
         return ob_get_clean();
     }
     return;
 }
}
list($widgets, $pages) = qa_db_select_with_pending(qa_db_widgets_selectspec(), qa_db_pages_selectspec());
if (isset($widgetid)) {
    $editwidget = null;
    foreach ($widgets as $widget) {
        if ($widget['widgetid'] == $widgetid) {
            $editwidget = $widget;
        }
    }
} else {
    $editwidget = array('title' => qa_post_text('title'));
    if (!isset($editwidget['title'])) {
        $editwidget['title'] = qa_get('title');
    }
}
$module = qa_load_module('widget', @$editwidget['title']);
$widgetfound = isset($module);
//	Check admin privileges (do late to allow one DB query)
if (!qa_admin_check_privileges($qa_content)) {
    return $qa_content;
}
//	Define an array of relevant templates we can use
$templatelangkeys = array('question' => 'admin/question_pages', 'qa' => 'main/recent_qs_as_title', 'activity' => 'main/recent_activity_title', 'questions' => 'admin/question_lists', 'hot' => 'main/hot_qs_title', 'unanswered' => 'main/unanswered_qs_title', 'tags' => 'main/popular_tags', 'categories' => 'misc/browse_categories', 'users' => 'main/highest_users', 'ask' => 'question/ask_title', 'tag' => 'admin/tag_pages', 'user' => 'admin/user_pages', 'message' => 'misc/private_message_title', 'search' => 'main/search_title', 'feedback' => 'misc/feedback_title', 'login' => 'users/login_title', 'register' => 'users/register_title', 'account' => 'profile/my_account_title', 'favorites' => 'misc/my_favorites_title', 'updates' => 'misc/recent_updates_title', 'ip' => 'admin/ip_address_pages', 'admin' => 'admin/admin_title');
$templateoptions = array();
if (isset($module) && method_exists($module, 'allow_template')) {
    foreach ($templatelangkeys as $template => $langkey) {
        if ($module->allow_template($template)) {
            $templateoptions[$template] = qa_lang_html($langkey);
        }
    }
    if ($module->allow_template('custom')) {
Esempio n. 18
0
function qa_content_prepare($voting = false, $categoryids = null)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    global $qa_template, $qa_page_error_html;
    if (QA_DEBUG_PERFORMANCE) {
        global $qa_usage;
        $qa_usage->mark('control');
    }
    $request = qa_request();
    $requestlower = qa_request();
    $navpages = qa_db_get_pending_result('navpages');
    $widgets = qa_db_get_pending_result('widgets');
    if (isset($categoryids) && !is_array($categoryids)) {
        // accept old-style parameter
        $categoryids = array($categoryids);
    }
    $lastcategoryid = count($categoryids) ? end($categoryids) : null;
    $charset = 'utf-8';
    $qa_content = array('content_type' => 'text/html; charset=' . $charset, 'charset' => $charset, 'direction' => qa_opt('site_text_direction'), '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 ($navpages 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'), 'selected_on' => array('tags$', 'tag/'));
    }
    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'), 'selected_on' => array('categories$', 'categories/'));
    }
    if (qa_opt('nav_users')) {
        $qa_content['navigation']['main']['user'] = array('url' => qa_path_html('users'), 'label' => qa_lang_html('main/nav_users'), 'selected_on' => array('users$', 'users/', 'user/'));
    }
    // Only the 'level' permission error prevents the menu option being shown - others reported on qa-page-ask.php
    if (qa_opt('nav_ask') && qa_user_maximum_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_user_maximum_permit_error('permit_moderate') || !qa_user_maximum_permit_error('permit_hide_show') || !qa_user_maximum_permit_error('permit_delete_hidden')) {
        $qa_content['navigation']['main']['admin'] = array('url' => qa_path_html('admin'), 'label' => qa_lang_html('main/nav_admin'), 'selected_on' => array('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 ($navpages 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 ($widgets 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(substr($qa_template, 0, 7) == 'custom-' ? 'custom' : $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_path_to_root() . $logourl) . '"' . ($logowidth ? ' width="' . $logowidth . '"' : '') . ($logoheight ? ' height="' . $logoheight . '"' : '') . ' border="0" alt="' . qa_html(qa_opt('site_title')) . '"/></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_path_to_root(), isset($topath) ? $topath : qa_path($request, $_GET, ''));
    $qa_content['navigation']['user'] = array();
    if (qa_is_logged_in()) {
        $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_path_to_root(), false) : qa_get_one_user_html(qa_get_logged_in_handle(), false));
        $qa_content['navigation']['user']['updates'] = array('url' => qa_path_html('updates'), 'label' => qa_lang_html('main/nav_updates'));
        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)) {
                $loginmodules = qa_load_modules_with('login', 'match_source');
                foreach ($loginmodules as $module) {
                    if ($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());
                    }
                }
            }
        }
        $notices = qa_db_get_pending_result('notices');
        foreach ($notices as $notice) {
            $qa_content['notices'][] = qa_notice_form($notice['noticeid'], qa_viewer_html($notice['content'], $notice['format']), $notice);
        }
    } else {
        require_once QA_INCLUDE_DIR . 'util/string.php';
        if (!QA_FINAL_EXTERNAL_USERS) {
            $loginmodules = qa_load_modules_with('login', 'login_html');
            foreach ($loginmodules as $tryname => $module) {
                ob_start();
                $module->login_html(isset($topath) ? qa_opt('site_url') . $topath : qa_path($request, $_GET, qa_opt('site_url')), 'menu');
                $label = ob_get_clean();
                if (strlen($label)) {
                    $qa_content['navigation']['user'][implode('-', qa_string_to_words($tryname))] = array('label' => $label);
                }
            }
        }
        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'));
        }
    }
    if (QA_FINAL_EXTERNAL_USERS || !qa_is_logged_in()) {
        if (qa_opt('show_notice_visitor') && !isset($topath) && !isset($_COOKIE['qa_noticed'])) {
            $qa_content['notices'][] = qa_notice_form('visitor', qa_opt('notice_visitor'));
        }
    } else {
        setcookie('qa_noticed', 1, time() + 86400 * 3650, '/', QA_COOKIE_DOMAIN);
        // don't show first-time notice if a user has logged in
        if (qa_opt('show_notice_welcome') && qa_get_logged_in_flags() & QA_USER_FLAGS_WELCOME_NOTICE) {
            if ($requestlower != 'confirm' && $requestlower != 'account') {
                // let people finish registering in peace
                $qa_content['notices'][] = qa_notice_form('welcome', qa_opt('notice_welcome'));
            }
        }
    }
    $qa_content['script_rel'] = array('qa-content/jquery-1.11.2.min.js');
    $qa_content['script_rel'][] = 'qa-content/qa-page.js?' . QA_VERSION;
    if ($voting) {
        $qa_content['error'] = @$qa_page_error_html;
    }
    $qa_content['script_var'] = array('qa_root' => qa_path_to_root(), 'qa_request' => $request);
    return $qa_content;
}
     }
     $feedisexample = true;
     break;
 case 'feed_for_search':
     $feedrequest = 'search/why do birds sing';
     $feedisexample = true;
     break;
 case 'moderate_users':
     $optionfield['note'] = '<a href="' . qa_path_html('admin/users', null, null, null, 'profile_fields') . '">' . qa_lang_html('admin/registration_fields') . '</a>';
     break;
 case 'captcha_module':
     $captchaoptions = array();
     foreach ($captchamodules as $modulename) {
         $captchaoptions[qa_html($modulename)] = qa_html($modulename);
         if ($modulename == $value) {
             $module = qa_load_module('captcha', $modulename);
             if (method_exists($module, 'admin_form')) {
                 $optionfield['note'] = '<a href="' . qa_admin_module_options_path('captcha', $modulename) . '">' . qa_lang_html('admin/options') . '</a>';
             }
         }
     }
     qa_optionfield_make_select($optionfield, $captchaoptions, $value, '');
     break;
 case 'moderate_update_time':
     qa_optionfield_make_select($optionfield, array('0' => qa_lang_html('options/time_written'), '1' => qa_lang_html('options/time_approved')), $value, '0');
     break;
 case 'max_rate_ip_as':
 case 'max_rate_ip_cs':
 case 'max_rate_ip_flags':
 case 'max_rate_ip_logins':
 case 'max_rate_ip_messages':
Esempio n. 20
0
function qa_get_post_content($editorfield, $contentfield, &$ineditor, &$incontent, &$informat, &$intext)
{
    $ineditor = qa_post_text($editorfield);
    $editor = qa_load_module('editor', $ineditor);
    $readdata = $editor->read_post($contentfield);
    $incontent = $readdata['content'];
    $informat = $readdata['format'];
    $intext = qa_viewer_text($incontent, $informat);
}
Esempio n. 21
0
function qa_default_option($name)
{
    global $qa_root_url_inferred;
    $fixed_defaults = array('allow_change_usernames' => 1, 'allow_multi_answers' => 1, 'allow_private_messages' => 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, 'do_related_qs' => 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, 'match_ask_check_qs' => 3, 'match_example_tags' => 3, 'match_related_qs' => 3, '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_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, '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, '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_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_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_select_a' => QA_PERMIT_EXPERTS, 'permit_view_q_page' => QA_PERMIT_ALL, 'permit_vote_a' => 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_per_a_voted' => 2, 'points_per_q_voted' => 1, '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_selected_first' => 1, 'show_url_links' => 1, 'show_user_points' => 1, 'show_user_titles' => 1, 'show_when_created' => 1, 'site_theme' => 'Default', '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 = $qa_root_url_inferred;
                // from qa-index.php
                break;
            case 'site_title':
                $value = qa_default_site_title();
                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_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 '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;
            default:
                // call option_default method in any registered modules
                $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, 'option_default')) {
                            $value = $module->option_default($name);
                            if (isset($value)) {
                                return $value;
                            }
                        }
                    }
                }
                $value = '';
                break;
        }
    }
    return $value;
}
Esempio n. 22
0
 function read_post($fieldname)
 {
     $html = qa_post_text($fieldname);
     $htmlformatting = preg_replace('/<\\s*\\/?\\s*(br|p)\\s*\\/?\\s*>/i', '', $html);
     // remove <p>, <br>, etc... since those are OK in text
     if (preg_match('/<.+>/', $htmlformatting)) {
         // if still some other tags, it's worth keeping in HTML
         return array('format' => 'html', 'content' => qa_sanitize_html($html, false, true));
     } else {
         // convert to text
         $viewer = qa_load_module('viewer', '');
         return array('format' => '', 'content' => $viewer->get_text($html, 'html', array()));
     }
 }
        } 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';
            }
            $qa_content['form_' . $type . '_' . $name] = $form;
            $formadded = true;
 function get_text($content, $format, $options)
 {
     $viewer = qa_load_module('viewer', '');
     $text = $viewer->get_text($content, 'html', array());
     return $text;
 }
 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.';
 }
Esempio n. 26
0
     $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>');
     }
     $widgets = qa_db_single_select(qa_db_widgets_selectspec());
     $listhtml = '';
     $placeoptions = qa_admin_place_options();