Ejemplo n.º 1
0
function qa_category_nav_to_browse(&$navigation, $categories, $categoryid, $favoritemap)
{
    foreach ($navigation as $key => $navlink) {
        $category = $categories[$navlink['categoryid']];
        if (!$category['childcount']) {
            unset($navigation[$key]['url']);
        } elseif ($navlink['selected']) {
            $navigation[$key]['state'] = 'open';
            $navigation[$key]['url'] = qa_path_html('categories/' . qa_category_path_request($categories, $category['parentid']));
        } else {
            $navigation[$key]['state'] = 'closed';
        }
        if (@$favoritemap[$navlink['categoryid']]) {
            $navigation[$key]['favorited'] = true;
        }
        $navigation[$key]['note'] = '';
        $navigation[$key]['note'] .= ' - <a href="' . qa_path_html('questions/' . implode('/', array_reverse(explode('/', $category['backpath'])))) . '">' . ($category['qcount'] == 1 ? qa_lang_html_sub('main/1_question', '1', '1') : qa_lang_html_sub('main/x_questions', qa_format_number($category['qcount'], 0, true))) . '</a>';
        if (strlen($category['content'])) {
            $navigation[$key]['note'] .= qa_html(' - ' . $category['content']);
        }
        if (isset($navlink['subnav'])) {
            qa_category_nav_to_browse($navigation[$key]['subnav'], $categories, $categoryid, $favoritemap);
        }
    }
}
 /**
  * Test number formatting including compact numbers (e.g. 1.3k)
  */
 public function test__qa_format_number__compact()
 {
     // set options/lang cache to bypass database
     global $qa_options_cache, $qa_phrases_custom;
     $qa_options_cache['show_compact_numbers'] = '1';
     $qa_phrases_custom['main']['_decimal_point'] = '.';
     $qa_phrases_custom['main']['_thousands_separator'] = ',';
     $qa_phrases_custom['main']['_thousands_suffix'] = 'k';
     $qa_phrases_custom['main']['_millions_suffix'] = 'm';
     // $decimal parameter ignored when 'show_compact_numbers' is true
     $this->assertSame('5.5', qa_format_number(5.452, 0, true));
     $this->assertSame('5.5', qa_format_number(5.452, 1, true));
     $this->assertSame('5', qa_format_number(5, 1, true));
     $this->assertSame('9.1k', qa_format_number(9123, 0, true));
     $this->assertSame('9.1k', qa_format_number(9123, 1, true));
     $this->assertSame('9k', qa_format_number(9040, 0, true));
     $this->assertSame('9k', qa_format_number(9040, 1, true));
     $this->assertSame('9.1k', qa_format_number(9050, 0, true));
     $this->assertSame('123m', qa_format_number(123456789, 0, true));
     $this->assertSame('23.5m', qa_format_number(23456789, 1, true));
     $this->assertSame('123m', qa_format_number(123456789, 1, true));
     $this->assertSame('235m', qa_format_number(234567891, 1, true));
     $this->assertSame('1,223m', qa_format_number(1223456789, 0, true));
     $this->assertSame('9,000', qa_format_number(9000, 0, false));
     $this->assertSame('912.3', qa_format_number(912.3, 1, false));
     $this->assertSame('123,456,789', qa_format_number(123456789, 0, false));
     // change separators and compact suffixes
     $qa_phrases_custom['main']['_decimal_point'] = ',';
     $qa_phrases_custom['main']['_thousands_separator'] = '.';
     $qa_phrases_custom['main']['_thousands_suffix'] = 'th';
     $qa_phrases_custom['main']['_millions_suffix'] = 'mi';
     $this->assertSame('9,1th', qa_format_number(9123, 0, true));
     $this->assertSame('123mi', qa_format_number(123456789, 0, true));
 }
 public function output_count($themeobject, $value, $langsingular, $langplural)
 {
     require_once QA_INCLUDE_DIR . 'app/format.php';
     $themeobject->output('<p class="qa-activity-count-item">');
     if ($value == 1) {
         $themeobject->output(qa_lang_html_sub($langsingular, '<span class="qa-activity-count-data">1</span>', '1'));
     } else {
         $themeobject->output(qa_lang_html_sub($langplural, '<span class="qa-activity-count-data">' . qa_format_number((int) $value, 0, true) . '</span>'));
     }
     $themeobject->output('</p>');
 }
Ejemplo n.º 4
0
 public function logged_in()
 {
     require_once QA_INCLUDE_DIR . 'app/format.php';
     if (qa_is_logged_in()) {
         // output user avatar to login bar
         $this->output('<div class="qa-logged-in-avatar">', QA_FINAL_EXTERNAL_USERS ? qa_get_external_avatar_html(qa_get_logged_in_userid(), 24, true) : qa_get_user_avatar_html(qa_get_logged_in_flags(), qa_get_logged_in_email(), qa_get_logged_in_handle(), qa_get_logged_in_user_field('avatarblobid'), qa_get_logged_in_user_field('avatarwidth'), qa_get_logged_in_user_field('avatarheight'), 24, true), '</div>');
     }
     qa_html_theme_base::logged_in();
     if (qa_is_logged_in()) {
         // adds points count after logged in username
         $userpoints = qa_get_logged_in_points();
         $pointshtml = $userpoints == 1 ? qa_lang_html_sub('main/1_point', '1', '1') : qa_lang_html_sub('main/x_points', qa_html(qa_format_number($userpoints)));
         $this->output('<span class="qa-logged-in-points">', '(' . $pointshtml . ')', '</span>');
     }
 }
 public function admin_form(&$qa_content)
 {
     require_once QA_INCLUDE_DIR . 'app/upload.php';
     $saved = false;
     if (qa_clicked('wysiwyg_editor_save_button')) {
         qa_opt('wysiwyg_editor_upload_images', (int) qa_post_text('wysiwyg_editor_upload_images_field'));
         qa_opt('wysiwyg_editor_upload_all', (int) qa_post_text('wysiwyg_editor_upload_all_field'));
         qa_opt('wysiwyg_editor_upload_max_size', min(qa_get_max_upload_size(), 1048576 * (double) qa_post_text('wysiwyg_editor_upload_max_size_field')));
         $saved = true;
     }
     qa_set_display_rules($qa_content, array('wysiwyg_editor_upload_all_display' => 'wysiwyg_editor_upload_images_field', 'wysiwyg_editor_upload_max_size_display' => 'wysiwyg_editor_upload_images_field'));
     // handle AJAX requests to 'wysiwyg-editor-ajax'
     $js = array('function wysiwyg_editor_ajax(totalEdited) {', '	$.ajax({', '		url: ' . qa_js(qa_path('wysiwyg-editor-ajax')) . ',', '		success: function(response) {', '			var postsEdited = parseInt(response, 10);', '			var $btn = $("#wysiwyg_editor_ajax");', '			if (isNaN(postsEdited)) {', '				$btn.text("ERROR");', '			}', '			else if (postsEdited < 5) {', '				$btn.text("All posts converted.");', '			}', '			else {', '				totalEdited += postsEdited;', '				$btn.text("Updating posts... " + totalEdited)', '				window.setTimeout(function() {', '					wysiwyg_editor_ajax(totalEdited);', '				}, 1000);', '			}', '		}', '	});', '}', '$("#wysiwyg_editor_ajax").click(function() {', '	wysiwyg_editor_ajax(0);', '	return false;', '});');
     $ajaxHtml = 'Update broken images from old CKeditor Smiley plugin: ' . '<button id="wysiwyg_editor_ajax">click here</button> ' . '<script>' . implode("\n", $js) . '</script>';
     return array('ok' => $saved ? 'WYSIWYG editor settings saved' : null, 'fields' => array(array('label' => 'Allow images to be uploaded', 'type' => 'checkbox', 'value' => (int) qa_opt('wysiwyg_editor_upload_images'), 'tags' => 'name="wysiwyg_editor_upload_images_field" id="wysiwyg_editor_upload_images_field"'), array('id' => 'wysiwyg_editor_upload_all_display', 'label' => 'Allow other content to be uploaded, e.g. Flash, PDF', 'type' => 'checkbox', 'value' => (int) qa_opt('wysiwyg_editor_upload_all'), 'tags' => 'name="wysiwyg_editor_upload_all_field"'), array('id' => 'wysiwyg_editor_upload_max_size_display', 'label' => 'Maximum size of uploads:', 'suffix' => 'MB (max ' . qa_html(qa_format_number($this->bytes_to_mega(qa_get_max_upload_size()))) . ')', 'type' => 'number', 'value' => qa_html(number_format($this->bytes_to_mega(qa_opt('wysiwyg_editor_upload_max_size')))), 'tags' => 'name="wysiwyg_editor_upload_max_size_field"'), array('type' => 'custom', 'html' => $ajaxHtml)), 'buttons' => array(array('label' => 'Save Changes', 'tags' => 'name="wysiwyg_editor_save_button"')));
 }
Ejemplo n.º 6
0
/**
 * Return the translated language ID string replacing the progress and total in it.
 * @access private
 * @param string $langId Language string ID that contains 2 placeholders (^1 and ^2)
 * @param int $progress Amount of processed elements
 * @param int $total Total amount of elements
 *
 * @return string Returns the language string ID with their placeholders replaced with
 * the formatted progress and total numbers
 */
function qa_recalc_progress_lang($langId, $progress, $total)
{
    return strtr(qa_lang($langId), array('^1' => qa_format_number($progress), '^2' => qa_format_number($total)));
}
Ejemplo n.º 7
0
function qa_favorite_categories_view($categories)
{
    require_once QA_INCLUDE_DIR . 'app/format.php';
    $nav_list_categories = array('nav' => array(), 'type' => 'browse-cat');
    foreach ($categories as $category) {
        $cat_url = qa_path_html('questions/' . implode('/', array_reverse(explode('/', $category['backpath']))));
        $cat_anchor = $category['qcount'] == 1 ? qa_lang_html_sub('main/1_question', '1', '1') : qa_lang_html_sub('main/x_questions', qa_format_number($category['qcount'], 0, true));
        $cat_descr = strlen($category['content']) ? qa_html(' - ' . $category['content']) : '';
        $nav_list_categories['nav'][$category['categoryid']] = array('label' => qa_html($category['title']), 'state' => 'open', 'favorited' => true, 'note' => ' - <a href="' . $cat_url . '">' . $cat_anchor . '</a>' . $cat_descr);
    }
    return $nav_list_categories;
}
Ejemplo n.º 8
0
function qa_mailing_progress_message()
{
    require_once QA_INCLUDE_DIR . 'app/format.php';
    if (strlen(qa_opt('mailing_last_userid'))) {
        return strtr(qa_lang('admin/mailing_progress'), array('^1' => qa_format_number(qa_opt('mailing_done_users')), '^2' => qa_format_number(qa_opt('mailing_total_users'))));
    } else {
        return null;
    }
}
Ejemplo n.º 9
0
function qa_category_navigation_sub($parentcategories, $parentid, $selecteds, $pathprefix, $showqcount, $pathparams, $favoritemap = null)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    $navigation = array();
    if (!isset($parentid)) {
        $navigation['all'] = array('url' => qa_path_html($pathprefix, $pathparams), 'label' => qa_lang_html('main/all_categories'), 'selected' => !count($selecteds), 'categoryid' => null);
    }
    if (isset($parentcategories[$parentid])) {
        foreach ($parentcategories[$parentid] as $category) {
            $navigation[qa_html($category['tags'])] = array('url' => qa_path_html($pathprefix . $category['tags'], $pathparams), 'label' => qa_html($category['title']), 'popup' => qa_html(@$category['content']), 'selected' => isset($selecteds[$category['categoryid']]), 'note' => $showqcount ? '(' . qa_html(qa_format_number($category['qcount'], 0, true)) . ')' : null, 'subnav' => qa_category_navigation_sub($parentcategories, $category['categoryid'], $selecteds, $pathprefix . $category['tags'] . '/', $showqcount, $pathparams, $favoritemap), 'categoryid' => $category['categoryid'], 'favorited' => @$favoritemap['category'][$category['backpath']]);
        }
    }
    return $navigation;
}
Ejemplo n.º 10
0
require_once QA_INCLUDE_DIR . 'app/format.php';
//	Get list of all users
$start = qa_get_start();
$users = qa_db_select_with_pending(qa_db_top_users_selectspec($start, qa_opt_if_loaded('page_size_users')));
$usercount = qa_opt('cache_userpointscount');
$pagesize = qa_opt('page_size_users');
$users = array_slice($users, 0, $pagesize);
$usershtml = qa_userids_handles_html($users);
//	Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('main/highest_users');
$qa_content['ranking'] = array('items' => array(), 'rows' => ceil($pagesize / qa_opt('columns_users')), 'type' => 'users');
if (count($users)) {
    foreach ($users as $userid => $user) {
        if (QA_FINAL_EXTERNAL_USERS) {
            $avatarhtml = qa_get_external_avatar_html($user['userid'], qa_opt('avatar_users_size'), true);
        } else {
            $avatarhtml = qa_get_user_avatar_html($user['flags'], $user['email'], $user['handle'], $user['avatarblobid'], $user['avatarwidth'], $user['avatarheight'], qa_opt('avatar_users_size'), true);
        }
        // avatar and handle now listed separately for use in themes
        $qa_content['ranking']['items'][] = array('avatar' => $avatarhtml, 'label' => $usershtml[$user['userid']], 'score' => qa_html(qa_format_number($user['points'], 0, true)), 'raw' => $user);
    }
} else {
    $qa_content['title'] = qa_lang_html('main/no_active_users');
}
$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $usercount, qa_opt('pages_prev_next'));
$qa_content['navigation']['sub'] = qa_users_sub_navigation();
return $qa_content;
/*
	Omit PHP closing tag to help avoid accidental output
*/
} else {
    $qa_content['form'] = array('tags' => 'method="post" action="' . qa_path_html(qa_request()) . '"', 'ok' => $savedoptions ? qa_lang_html('admin/options_saved') : null, 'style' => 'tall', 'fields' => array('intro' => array('label' => qa_lang_html('admin/categories_introduction'), 'type' => 'static')), 'buttons' => array('save' => array('tags' => 'name="dosaveoptions" id="dosaveoptions"', 'label' => qa_lang_html('main/save_button')), 'add' => array('tags' => 'name="doaddcategory"', 'label' => qa_lang_html('admin/add_category_button'))), 'hidden' => array('code' => qa_get_form_security_code('admin/categories')));
    if (count($categories)) {
        unset($qa_content['form']['fields']['intro']);
        $navcategoryhtml = '';
        foreach ($categories as $category) {
            if (!isset($category['parentid'])) {
                $navcategoryhtml .= '<a href="' . qa_path_html('admin/categories', array('edit' => $category['categoryid'])) . '">' . qa_html($category['title']) . '</a> - ' . ($category['qcount'] == 1 ? qa_lang_html_sub('main/1_question', '1', '1') : qa_lang_html_sub('main/x_questions', qa_format_number($category['qcount']))) . '<br/>';
            }
        }
        $qa_content['form']['fields']['nav'] = array('label' => qa_lang_html('admin/top_level_categories'), 'type' => 'static', 'value' => $navcategoryhtml);
        $qa_content['form']['fields']['allow_no_category'] = array('label' => qa_lang_html('options/allow_no_category'), 'tags' => 'name="option_allow_no_category"', 'type' => 'checkbox', 'value' => qa_opt('allow_no_category'));
        if (!qa_opt('allow_no_category')) {
            $nocatcount = qa_db_count_categoryid_qs(null);
            if ($nocatcount) {
                $qa_content['form']['fields']['allow_no_category']['error'] = strtr(qa_lang_html('admin/category_none_error'), array('^q' => qa_format_number($nocatcount), '^1' => '<a href="' . qa_path_html(qa_request(), array('missing' => 1)) . '">', '^2' => '</a>'));
            }
        }
        $qa_content['form']['fields']['allow_no_sub_category'] = array('label' => qa_lang_html('options/allow_no_sub_category'), 'tags' => 'name="option_allow_no_sub_category"', 'type' => 'checkbox', 'value' => qa_opt('allow_no_sub_category'));
    } else {
        unset($qa_content['form']['buttons']['save']);
    }
}
if (qa_get('recalc')) {
    $qa_content['form']['ok'] = '<span id="recalc_ok">' . qa_lang_html('admin/recalc_categories') . '</span>';
    $qa_content['form']['hidden']['code_recalc'] = qa_get_form_security_code('admin/recalc');
    $qa_content['script_rel'][] = 'qa-content/qa-admin.js?' . QA_VERSION;
    $qa_content['script_var']['qa_warning_recalc'] = qa_lang('admin/stop_recalc_warning');
    $qa_content['script_onloads'][] = array("qa_recalc_click('dorecalccategories', document.getElementById('dosaveoptions'), null, 'recalc_ok');");
}
$qa_content['navigation']['sub'] = qa_admin_sub_navigation();
Ejemplo n.º 12
0
         $userfields = qa_db_single_select(qa_db_userfields_selectspec());
         $listhtml = '';
         foreach ($userfields as $userfield) {
             $listhtml .= '<li><b>' . qa_html(qa_user_userfield_label($userfield)) . '</b>';
             $listhtml .= strtr(qa_lang_html('admin/edit_field'), array('^1' => '<a href="' . qa_path_html('admin/userfields', array('edit' => $userfield['fieldid'])) . '">', '^2' => '</a>'));
             $listhtml .= '</li>';
         }
         $listhtml .= '<li><b><a href="' . qa_path_html('admin/userfields') . '">' . qa_lang_html('admin/add_new_field') . '</a></b></li>';
         $qa_content['form']['fields'][] = array('type' => 'blank');
         $qa_content['form']['fields']['userfields'] = array('label' => qa_lang_html('admin/profile_fields'), 'id' => 'profile_fields', 'style' => 'tall', 'type' => 'custom', 'html' => strlen($listhtml) ? '<ul style="margin-bottom:0;">' . $listhtml . '</ul>' : null);
     }
     $qa_content['form']['fields'][] = array('type' => 'blank');
     $pointstitle = qa_get_points_to_titles();
     $listhtml = '';
     foreach ($pointstitle as $points => $title) {
         $listhtml .= '<li><b>' . $title . '</b> - ' . ($points == 1 ? qa_lang_html_sub('main/1_point', '1', '1') : qa_lang_html_sub('main/x_points', qa_html(qa_format_number($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':
     $listhtml = '';
     $widgetmodules = qa_load_modules_with('widget', 'allow_template');
     foreach ($widgetmodules as $tryname => $trywidget) {
         if (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_admin_module_options_path('widget', $tryname) . '">', '^2' => '</a>'));
Ejemplo n.º 13
0
require_once QA_INCLUDE_DIR . 'app/format.php';
//	Get popular tags
$start = qa_get_start();
$userid = qa_get_logged_in_userid();
$populartags = qa_db_select_with_pending(qa_db_popular_tags_selectspec($start, qa_opt_if_loaded('page_size_tags')));
$tagcount = qa_opt('cache_tagcount');
$pagesize = qa_opt('page_size_tags');
//	Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('main/popular_tags');
$qa_content['ranking'] = array('items' => array(), 'rows' => ceil($pagesize / qa_opt('columns_tags')), 'type' => 'tags');
if (count($populartags)) {
    $favoritemap = qa_get_favorite_non_qs_map();
    $output = 0;
    foreach ($populartags as $word => $count) {
        $qa_content['ranking']['items'][] = array('label' => qa_tag_html($word, false, @$favoritemap['tag'][qa_strtolower($word)]), 'count' => qa_format_number($count, 0, true));
        if (++$output >= $pagesize) {
            break;
        }
    }
} else {
    $qa_content['title'] = qa_lang_html('main/no_tags_found');
}
$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $tagcount, qa_opt('pages_prev_next'));
if (empty($qa_content['page_links'])) {
    $qa_content['suggest_next'] = qa_html_suggest_ask();
}
return $qa_content;
/*
	Omit PHP closing tag to help avoid accidental output
*/
Ejemplo n.º 14
0
    $votegavevalue .= $downvotes == 1 ? qa_lang_html_sub('profile/1_down_vote', $innervalue, '1') : qa_lang_html_sub('profile/x_down_votes', $innervalue);
    $qa_content['form_activity']['fields']['votegave'] = array('type' => 'static', 'label' => qa_lang_html('profile/gave_out'), 'value' => $votegavevalue, 'id' => 'votegave');
    $innervalue = '<span class="qa-uf-user-upvoteds">' . qa_format_number(@$userpoints['upvoteds']) . '</span>';
    $votegotvalue = (@$userpoints['upvoteds'] == 1 ? qa_lang_html_sub('profile/1_up_vote', $innervalue, '1') : qa_lang_html_sub('profile/x_up_votes', $innervalue)) . ', ';
    $innervalue = '<span class="qa-uf-user-downvoteds">' . qa_format_number(@$userpoints['downvoteds']) . '</span>';
    $votegotvalue .= @$userpoints['downvoteds'] == 1 ? qa_lang_html_sub('profile/1_down_vote', $innervalue, '1') : qa_lang_html_sub('profile/x_down_votes', $innervalue);
    $qa_content['form_activity']['fields']['votegot'] = array('type' => 'static', 'label' => qa_lang_html('profile/received'), 'value' => $votegotvalue, 'id' => 'votegot');
}
if (@$userpoints['points']) {
    $qa_content['form_activity']['fields']['points']['value'] .= qa_lang_html_sub('profile/ranked_x', '<span class="qa-uf-user-rank">' . qa_format_number($userrank) . '</span>');
}
if (@$userpoints['aselects']) {
    $qa_content['form_activity']['fields']['questions']['value'] .= $userpoints['aselects'] == 1 ? qa_lang_html_sub('profile/1_with_best_chosen', '<span class="qa-uf-user-q-selects">1</span>', '1') : qa_lang_html_sub('profile/x_with_best_chosen', '<span class="qa-uf-user-q-selects">' . qa_format_number($userpoints['aselects']) . '</span>');
}
if (@$userpoints['aselecteds']) {
    $qa_content['form_activity']['fields']['answers']['value'] .= $userpoints['aselecteds'] == 1 ? qa_lang_html_sub('profile/1_chosen_as_best', '<span class="qa-uf-user-a-selecteds">1</span>', '1') : qa_lang_html_sub('profile/x_chosen_as_best', '<span class="qa-uf-user-a-selecteds">' . qa_format_number($userpoints['aselecteds']) . '</span>');
}
//	For plugin layers to access
$qa_content['raw']['userid'] = $userid;
$qa_content['raw']['points'] = $userpoints;
$qa_content['raw']['rank'] = $userrank;
//	Wall posts
if (!QA_FINAL_EXTERNAL_USERS && qa_opt('allow_user_walls')) {
    $qa_content['message_list'] = array('title' => '<a name="wall">' . qa_lang_html_sub('profile/wall_for_x', $userhtml) . '</a>', 'tags' => 'id="wallmessages"', 'form' => array('tags' => 'name="wallpost" method="post" action="' . qa_self_html() . '#wall"', 'style' => 'tall', 'hidden' => array('qa_click' => '', 'handle' => qa_html($useraccount['handle']), 'start' => 0, 'code' => qa_get_form_security_code('wall-' . $useraccount['handle']))), 'messages' => array());
    if ($wallposterrorhtml) {
        $qa_content['message_list']['error'] = $wallposterrorhtml;
    } else {
        $qa_content['message_list']['form']['fields'] = array('message' => array('tags' => 'name="message" id="message"', 'value' => qa_html(@$inmessage, false), 'rows' => 2, 'error' => qa_html(@$errors['message'])));
        $qa_content['message_list']['form']['buttons'] = array('post' => array('tags' => 'name="dowallpost" onclick="return qa_submit_wall_post(this, true);"', 'label' => qa_lang_html('profile/post_wall_button')));
    }
    foreach ($usermessages as $message) {
Ejemplo n.º 15
0
function qa_upload_file($localfilename, $sourcefilename, $maxfilesize = null, $onlyimage = false, $imagemaxwidth = null, $imagemaxheight = null)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    $result = array();
    //	Check per-user upload limits
    require_once QA_INCLUDE_DIR . 'app/users.php';
    require_once QA_INCLUDE_DIR . 'app/limits.php';
    switch (qa_user_permit_error(null, QA_LIMIT_UPLOADS)) {
        case 'limit':
            $result['error'] = qa_lang('main/upload_limit');
            return $result;
        case false:
            qa_limits_increment(qa_get_logged_in_userid(), QA_LIMIT_UPLOADS);
            break;
        default:
            $result['error'] = qa_lang('users/no_permission');
            return $result;
    }
    //	Check the uploaded file is not too large
    $filesize = filesize($localfilename);
    if (isset($maxfilesize)) {
        $maxfilesize = min($maxfilesize, qa_get_max_upload_size());
    } else {
        $maxfilesize = qa_get_max_upload_size();
    }
    if ($filesize <= 0 || $filesize > $maxfilesize) {
        // if file was too big for PHP, $filesize will be zero
        $result['error'] = qa_lang_sub('main/max_upload_size_x', qa_format_number($maxfilesize / 1048576, 1) . 'MB');
        return $result;
    }
    //	Find out what type of source file was uploaded and if appropriate, check it's an image and get preliminary size measure
    $pathinfo = pathinfo($sourcefilename);
    $format = strtolower(@$pathinfo['extension']);
    $isimage = $format == 'png' || $format == 'gif' || $format == 'jpeg' || $format == 'jpg';
    // allowed image extensions
    if ($isimage) {
        $imagesize = @getimagesize($localfilename);
        if (is_array($imagesize)) {
            $result['width'] = $imagesize[0];
            $result['height'] = $imagesize[1];
            switch ($imagesize['2']) {
                // reassign format based on actual content, if we can
                case IMAGETYPE_GIF:
                    $format = 'gif';
                    break;
                case IMAGETYPE_JPEG:
                    $format = 'jpeg';
                    break;
                case IMAGETYPE_PNG:
                    $format = 'png';
                    break;
            }
        }
    }
    $result['format'] = $format;
    if ($onlyimage) {
        if (!$isimage || !is_array($imagesize)) {
            $result['error'] = qa_lang_sub('main/image_not_read', 'GIF, JPG, PNG');
            return $result;
        }
    }
    //	Read in the raw file contents
    $content = file_get_contents($localfilename);
    //	If appropriate, get more accurate image size and apply constraints to it
    require_once QA_INCLUDE_DIR . 'util/image.php';
    if ($isimage && qa_has_gd_image()) {
        $image = @imagecreatefromstring($content);
        if (is_resource($image)) {
            $result['width'] = $width = imagesx($image);
            $result['height'] = $height = imagesy($image);
            if (isset($imagemaxwidth) || isset($imagemaxheight)) {
                if (qa_image_constrain($width, $height, isset($imagemaxwidth) ? $imagemaxwidth : $width, isset($imagemaxheight) ? $imagemaxheight : $height)) {
                    qa_gd_image_resize($image, $width, $height);
                    if (is_resource($image)) {
                        $content = qa_gd_image_jpeg($image);
                        $result['format'] = $format = 'jpeg';
                        $result['width'] = $width;
                        $result['height'] = $height;
                    }
                }
            }
            if (is_resource($image)) {
                // might have been lost
                imagedestroy($image);
            }
        }
    }
    //	Create the blob and return
    require_once QA_INCLUDE_DIR . 'app/blobs.php';
    $userid = qa_get_logged_in_userid();
    $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create();
    $result['blobid'] = qa_create_blob($content, $format, $sourcefilename, $userid, $cookieid, qa_remote_ip_address());
    if (!isset($result['blobid'])) {
        $result['error'] = qa_lang('main/general_error');
        return $result;
    }
    $result['bloburl'] = qa_get_blob_url($result['blobid'], true);
    return $result;
}
Ejemplo n.º 16
0
//	Check admin privileges (do late to allow one DB query)
if (!qa_admin_check_privileges($qa_content)) {
    return $qa_content;
}
//	Get the information to display
$qcount = (int) qa_opt('cache_qcount');
$qcount_anon = qa_db_count_posts('Q', false);
$acount = (int) qa_opt('cache_acount');
$acount_anon = qa_db_count_posts('A', false);
$ccount = (int) qa_opt('cache_ccount');
$ccount_anon = qa_db_count_posts('C', false);
//	Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('admin/admin_title') . ' - ' . qa_lang_html('admin/stats_title');
$qa_content['error'] = qa_admin_page_error();
$qa_content['form'] = array('style' => 'wide', 'fields' => array('q2a_version' => array('label' => qa_lang_html('admin/q2a_version'), 'value' => qa_html(QA_VERSION)), 'q2a_date' => array('label' => qa_lang_html('admin/q2a_build_date'), 'value' => qa_html(QA_BUILD_DATE)), 'q2a_latest' => array('label' => qa_lang_html('admin/q2a_latest_version'), 'type' => 'custom', 'html' => '<iframe src="http://www.question2answer.org/question2answer-latest.php?version=' . urlencode(QA_VERSION) . '&language=' . urlencode(qa_opt('site_language')) . '" width="100" height="16" style="vertical-align:middle; border:0; background:transparent;" allowTransparency="true" scrolling="no" frameborder="0"></iframe>'), 'break0' => array('type' => 'blank'), 'db_version' => array('label' => qa_lang_html('admin/q2a_db_version'), 'value' => qa_html(qa_opt('db_version'))), 'db_size' => array('label' => qa_lang_html('admin/q2a_db_size'), 'value' => qa_html(qa_format_number(qa_db_table_size() / 1048576, 1) . ' MB')), 'break1' => array('type' => 'blank'), 'php_version' => array('label' => qa_lang_html('admin/php_version'), 'value' => qa_html(phpversion())), 'mysql_version' => array('label' => qa_lang_html('admin/mysql_version'), 'value' => qa_html(qa_db_mysql_version())), 'break2' => array('type' => 'blank'), 'qcount' => array('label' => qa_lang_html('admin/total_qs'), 'value' => qa_html(qa_format_number($qcount))), 'qcount_users' => array('label' => qa_lang_html('admin/from_users'), 'value' => qa_html(qa_format_number($qcount - $qcount_anon))), 'qcount_anon' => array('label' => qa_lang_html('admin/from_anon'), 'value' => qa_html(qa_format_number($qcount_anon))), 'break3' => array('type' => 'blank'), 'acount' => array('label' => qa_lang_html('admin/total_as'), 'value' => qa_html(qa_format_number($acount))), 'acount_users' => array('label' => qa_lang_html('admin/from_users'), 'value' => qa_html(qa_format_number($acount - $acount_anon))), 'acount_anon' => array('label' => qa_lang_html('admin/from_anon'), 'value' => qa_html(qa_format_number($acount_anon))), 'break4' => array('type' => 'blank'), 'ccount' => array('label' => qa_lang_html('admin/total_cs'), 'value' => qa_html(qa_format_number($ccount))), 'ccount_users' => array('label' => qa_lang_html('admin/from_users'), 'value' => qa_html(qa_format_number($ccount - $ccount_anon))), 'ccount_anon' => array('label' => qa_lang_html('admin/from_anon'), 'value' => qa_html(qa_format_number($ccount_anon))), 'break5' => array('type' => 'blank'), 'users' => array('label' => qa_lang_html('admin/users_registered'), 'value' => QA_FINAL_EXTERNAL_USERS ? '' : qa_html(qa_format_number(qa_db_count_users()))), 'users_active' => array('label' => qa_lang_html('admin/users_active'), 'value' => qa_html(qa_format_number((int) qa_opt('cache_userpointscount')))), 'users_posted' => array('label' => qa_lang_html('admin/users_posted'), 'value' => qa_html(qa_format_number(qa_db_count_active_users('posts')))), 'users_voted' => array('label' => qa_lang_html('admin/users_voted'), 'value' => qa_html(qa_format_number(qa_db_count_active_users('uservotes'))))));
if (QA_FINAL_EXTERNAL_USERS) {
    unset($qa_content['form']['fields']['users']);
} else {
    unset($qa_content['form']['fields']['users_active']);
}
foreach ($qa_content['form']['fields'] as $index => $field) {
    if (empty($field['type'])) {
        $qa_content['form']['fields'][$index]['type'] = 'static';
    }
}
$qa_content['form_2'] = array('tags' => 'method="post" action="' . qa_path_html('admin/recalc') . '"', 'title' => qa_lang_html('admin/database_cleanup'), 'style' => 'basic', 'buttons' => array('recount_posts' => array('label' => qa_lang_html('admin/recount_posts'), 'tags' => 'name="dorecountposts" onclick="return qa_recalc_click(this.name, this, ' . qa_js(qa_lang_html('admin/recount_posts_stop')) . ', \'recount_posts_note\');"', 'note' => '<span id="recount_posts_note">' . qa_lang_html('admin/recount_posts_note') . '</span>'), 'reindex_content' => array('label' => qa_lang_html('admin/reindex_content'), 'tags' => 'name="doreindexcontent" onclick="return qa_recalc_click(this.name, this, ' . qa_js(qa_lang_html('admin/reindex_content_stop')) . ', \'reindex_content_note\');"', 'note' => '<span id="reindex_content_note">' . qa_lang_html('admin/reindex_content_note') . '</span>'), 'recalc_points' => array('label' => qa_lang_html('admin/recalc_points'), 'tags' => 'name="dorecalcpoints" onclick="return qa_recalc_click(this.name, this, ' . qa_js(qa_lang_html('admin/recalc_stop')) . ', \'recalc_points_note\');"', 'note' => '<span id="recalc_points_note">' . qa_lang_html('admin/recalc_points_note') . '</span>'), 'refill_events' => array('label' => qa_lang_html('admin/refill_events'), 'tags' => 'name="dorefillevents" onclick="return qa_recalc_click(this.name, this, ' . qa_js(qa_lang_html('admin/recalc_stop')) . ', \'refill_events_note\');"', 'note' => '<span id="refill_events_note">' . qa_lang_html('admin/refill_events_note') . '</span>'), 'recalc_categories' => array('label' => qa_lang_html('admin/recalc_categories'), 'tags' => 'name="dorecalccategories" onclick="return qa_recalc_click(this.name, this, ' . qa_js(qa_lang_html('admin/recalc_stop')) . ', \'recalc_categories_note\');"', 'note' => '<span id="recalc_categories_note">' . qa_lang_html('admin/recalc_categories_note') . '</span>'), 'delete_hidden' => array('label' => qa_lang_html('admin/delete_hidden'), 'tags' => 'name="dodeletehidden" onclick="return qa_recalc_click(this.name, this, ' . qa_js(qa_lang_html('admin/delete_stop')) . ', \'delete_hidden_note\');"', 'note' => '<span id="delete_hidden_note">' . qa_lang_html('admin/delete_hidden_note') . '</span>')), 'hidden' => array('code' => qa_get_form_security_code('admin/recalc')));
if (!qa_using_categories()) {
    unset($qa_content['form_2']['buttons']['recalc_categories']);
}
if (defined('QA_BLOBS_DIRECTORY')) {