コード例 #1
0
function qa_question_validate($title, $content, $format, $text, $tagstring, $notify, $email)
{
    require_once QA_INCLUDE_DIR . 'qa-app-options.php';
    $options = qa_get_options(array('min_len_q_title', 'max_len_q_title', 'min_len_q_content', 'min_num_q_tags', 'max_num_q_tags'));
    $errors = array();
    $maxtitlelength = max($options['min_len_q_title'], min($options['max_len_q_title'], QA_DB_MAX_TITLE_LENGTH));
    qa_length_validate($errors, 'title', $title, $options['min_len_q_title'], $maxtitlelength);
    qa_length_validate($errors, 'content', $content, 0, QA_DB_MAX_CONTENT_LENGTH);
    // for storage
    qa_length_validate($errors, 'content', $text, $options['min_len_q_content'], null);
    // for display
    if (isset($tagstring)) {
        $counttags = count(qa_tagstring_to_tags($tagstring));
        $mintags = min($options['min_num_q_tags'], $options['max_num_q_tags']);
        // to deal with silly settings
        if ($counttags < $mintags) {
            $errors['tags'] = qa_lang_sub('question/min_tags_x', $mintags);
        } elseif ($counttags > $options['max_num_q_tags']) {
            $errors['tags'] = qa_lang_sub('question/max_tags_x', $options['max_num_q_tags']);
        } else {
            qa_length_validate($errors, 'tags', $tagstring, 0, QA_DB_MAX_TAGS_LENGTH);
        }
    }
    qa_notify_validate($errors, $notify, $email);
    return $errors;
}
コード例 #2
0
ファイル: functions.php プロジェクト: microbye/Donut
/**
 * Returns the language value as defined in lang/donut-options-lang-*.php
 *
 * @param      $indentifier
 * @param null $subs
 *
 * @return mixed|string
 */
function donut_options_lang($indentifier, $subs = null)
{
    if (!is_array($subs)) {
        return empty($subs) ? qa_lang('donut_options/' . $indentifier) : qa_lang_sub('donut_options/' . $indentifier, $subs);
    } else {
        return strtr(qa_lang('donut_options/' . $indentifier), $subs);
    }
}
コード例 #3
0
ファイル: qa-feed.php プロジェクト: swuit/swuit-q2a
function qa_feed_load_ifcategory($categoryslugs, $allkey, $catkey, &$title, $questionselectspec1 = null, $questionselectspec2 = null, $questionselectspec3 = null, $questionselectspec4 = null)
{
    $countslugs = @count($categoryslugs);
    list($questions1, $questions2, $questions3, $questions4, $categories, $categoryid) = qa_db_select_with_pending($questionselectspec1, $questionselectspec2, $questionselectspec3, $questionselectspec4, $countslugs ? qa_db_category_nav_selectspec($categoryslugs, false) : null, $countslugs ? qa_db_slugs_to_category_id_selectspec($categoryslugs) : null);
    if ($countslugs && !isset($categoryid)) {
        qa_feed_not_found();
    }
    if (isset($allkey)) {
        $title = isset($categoryid) && isset($catkey) ? qa_lang_sub($catkey, $categories[$categoryid]['title']) : qa_lang($allkey);
    }
    return array_merge(is_array($questions1) ? $questions1 : array(), is_array($questions2) ? $questions2 : array(), is_array($questions3) ? $questions3 : array(), is_array($questions4) ? $questions4 : array());
}
コード例 #4
0
ファイル: q-list.php プロジェクト: kosmoluna/question2answer
function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitle, $nonetitle, $navcategories, $categoryid, $categoryqcount, $categorypathprefix, $feedpathprefix, $suggest, $pagelinkparams = null, $categoryparams = null, $dummy = null)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    require_once QA_INCLUDE_DIR . 'app/format.php';
    require_once QA_INCLUDE_DIR . 'app/updates.php';
    $userid = qa_get_logged_in_userid();
    //	Chop down to size, get user information for display
    if (isset($pagesize)) {
        $questions = array_slice($questions, 0, $pagesize);
    }
    $usershtml = qa_userids_handles_html(qa_any_get_userids_handles($questions));
    //	Prepare content for theme
    $qa_content = qa_content_prepare(true, array_keys(qa_category_path($navcategories, $categoryid)));
    $qa_content['q_list']['form'] = array('tags' => 'method="post" action="' . qa_self_html() . '"', 'hidden' => array('code' => qa_get_form_security_code('vote')));
    $qa_content['q_list']['qs'] = array();
    if (count($questions)) {
        $qa_content['title'] = $sometitle;
        $defaults = qa_post_html_defaults('Q');
        if (isset($categorypathprefix)) {
            $defaults['categorypathprefix'] = $categorypathprefix;
        }
        foreach ($questions as $question) {
            $fields = qa_any_to_q_html_fields($question, $userid, qa_cookie_get(), $usershtml, null, qa_post_html_options($question, $defaults));
            if (!empty($fields['raw']['closedbyid'])) {
                $fields['closed'] = array('state' => qa_lang_html('main/closed'));
            }
            $qa_content['q_list']['qs'][] = $fields;
        }
    } else {
        $qa_content['title'] = $nonetitle;
    }
    if (isset($userid) && isset($categoryid)) {
        $favoritemap = qa_get_favorite_non_qs_map();
        $categoryisfavorite = @$favoritemap['category'][$navcategories[$categoryid]['backpath']];
        $qa_content['favorite'] = qa_favorite_form(QA_ENTITY_CATEGORY, $categoryid, $categoryisfavorite, qa_lang_sub($categoryisfavorite ? 'main/remove_x_favorites' : 'main/add_category_x_favorites', $navcategories[$categoryid]['title']));
    }
    if (isset($count) && isset($pagesize)) {
        $qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'), $pagelinkparams);
    }
    if (empty($qa_content['page_links'])) {
        $qa_content['suggest_next'] = $suggest;
    }
    if (qa_using_categories() && count($navcategories) && isset($categorypathprefix)) {
        $qa_content['navigation']['cat'] = qa_category_navigation($navcategories, $categoryid, $categorypathprefix, $categoryqcount, $categoryparams);
    }
    if (isset($feedpathprefix) && (qa_opt('feed_per_category') || !isset($categoryid))) {
        $qa_content['feed'] = array('url' => qa_path_html(qa_feed_request($feedpathprefix . (isset($categoryid) ? '/' . qa_category_path_request($navcategories, $categoryid) : ''))), 'label' => strip_tags($sometitle));
    }
    return $qa_content;
}
コード例 #5
0
ファイル: emails.php プロジェクト: kosmoluna/question2answer
function qa_send_notification($userid, $email, $handle, $subject, $body, $subs, $html = false)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    global $qa_notifications_suspended;
    if ($qa_notifications_suspended > 0) {
        return false;
    }
    require_once QA_INCLUDE_DIR . 'db/selects.php';
    require_once QA_INCLUDE_DIR . 'util/string.php';
    if (isset($userid)) {
        $needemail = !qa_email_validate(@$email);
        // take from user if invalid, e.g. @ used in practice
        $needhandle = empty($handle);
        if ($needemail || $needhandle) {
            if (QA_FINAL_EXTERNAL_USERS) {
                if ($needhandle) {
                    $handles = qa_get_public_from_userids(array($userid));
                    $handle = @$handles[$userid];
                }
                if ($needemail) {
                    $email = qa_get_user_email($userid);
                }
            } else {
                $useraccount = qa_db_select_with_pending(array('columns' => array('email', 'handle'), 'source' => '^users WHERE userid = #', 'arguments' => array($userid), 'single' => true));
                if ($needhandle) {
                    $handle = @$useraccount['handle'];
                }
                if ($needemail) {
                    $email = @$useraccount['email'];
                }
            }
        }
    }
    if (isset($email) && qa_email_validate($email)) {
        $subs['^site_title'] = qa_opt('site_title');
        $subs['^handle'] = $handle;
        $subs['^email'] = $email;
        $subs['^open'] = "\n";
        $subs['^close'] = "\n";
        return qa_send_email(array('fromemail' => qa_opt('from_email'), 'fromname' => qa_opt('site_title'), 'toemail' => $email, 'toname' => $handle, 'subject' => strtr($subject, $subs), 'body' => (empty($handle) ? '' : qa_lang_sub('emails/to_handle_prefix', $handle)) . strtr($body, $subs), 'html' => $html));
    } else {
        return false;
    }
}
コード例 #6
0
function qa_time_to_string($seconds)
{
    $seconds = max($seconds, 1);
    $scales = array(31557600 => array('main/1_year', 'main/x_years'), 2629800 => array('main/1_month', 'main/x_months'), 604800 => array('main/1_week', 'main/x_weeks'), 86400 => array('main/1_day', 'main/x_days'), 3600 => array('main/1_hour', 'main/x_hours'), 60 => array('main/1_minute', 'main/x_minutes'), 1 => array('main/1_second', 'main/x_seconds'));
    foreach ($scales as $scale => $phrases) {
        if ($seconds >= $scale) {
            $count = floor($seconds / $scale);
            if ($count == 1) {
                $string = qa_lang($phrases[0]);
            } else {
                $string = qa_lang_sub($phrases[1], $count);
            }
            break;
        }
    }
    return $string;
}
コード例 #7
0
 function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     $widget_opt = @$themeobject->current_widget['param']['options'];
     require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
     if (@$qa_content['q_view']['raw']['type'] != 'Q') {
         // question might not be visible, etc...
         return;
     }
     $questionid = $qa_content['q_view']['raw']['postid'];
     $userid = qa_get_logged_in_userid();
     $cookieid = qa_cookie_get();
     $questions = qa_db_single_select(qa_db_related_qs_selectspec($userid, $questionid, (int) $widget_opt['count']));
     $minscore = qa_match_to_min_score(qa_opt('match_related_qs'));
     foreach ($questions as $key => $question) {
         if ($question['score'] < $minscore) {
             unset($questions[$key]);
         }
     }
     $titlehtml = qa_lang_html(count($questions) ? 'main/related_qs_title' : 'main/no_related_qs_title');
     if (@$themeobject->current_widget['param']['locations']['show_title']) {
         $themeobject->output('<h3 class="widget-title">' . qa_lang('cleanstrap/related_questions') . '</h3>');
     }
     $themeobject->output('<div class="ra-rq-widget">');
     $themeobject->output('<ul>');
     foreach ($questions as $p) {
         $timeCode = qa_when_to_html($p['created'], 7);
         $when = @$timeCode['prefix'] . @$timeCode['data'] . @$timeCode['suffix'];
         $themeobject->output('<li>' . cs_get_post_avatar($p, $p['userid'], 30, true));
         $themeobject->output('<div class="post-content">');
         $themeobject->output('<a class="title" href="' . qa_q_path_html($p['postid'], $p['title']) . '">' . qa_html($p['title']) . '</a>');
         $themeobject->output('<div class="meta">');
         $themeobject->output('<span>' . qa_lang_sub('cleanstrap/x_answers', $p['acount']) . '</span>');
         $themeobject->output('<span class="time icon-time">' . $when . '</span>');
         $themeobject->output('<span class="vote-count icon-thumbs-up2">' . qa_lang_sub('cleanstrap/x_votes', $p['netvotes']) . '</span>');
         $themeobject->output('</div>');
         $themeobject->output('</div>');
         $themeobject->output('</li>');
     }
     $themeobject->output('</ul>');
     $themeobject->output('</div>');
 }
コード例 #8
0
 function cs_top_users($limit = 5, $size)
 {
     $users = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^users JOIN ^userpoints ON ^users.userid=^userpoints.userid ORDER BY ^userpoints.points DESC LIMIT #', $limit));
     $output = '<ul class="top-users-list clearfix">';
     foreach ($users as $u) {
         if (defined('QA_WORDPRESS_INTEGRATE_PATH')) {
             require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
             $u['handle'] = qa_post_userid_to_handle($u['userid']);
         }
         $output .= '<li class="top-user clearfix">';
         $output .= cs_get_post_avatar($u, $u['userid'], $size, true);
         $output .= '<div class="top-user-data">';
         $output .= '<span class="points">' . $u['points'] . ' ' . qa_lang('cleanstrap/points') . '</span>';
         $output .= '<a href="' . qa_path_html('user/' . $u['handle']) . '" class="name">' . $u['handle'] . '</a>';
         $output .= '<p class="counts"><span>' . qa_lang_sub('cleanstrap/x_questions', $u['qposts']) . '</span> <span>' . qa_lang_sub('cleanstrap/x_answers', $u['aposts']) . '</span><span>' . qa_lang_sub('cleanstrap/x_comments', $u['cposts']) . '</span></p>';
         $output .= '</div>';
         $output .= '</li>';
     }
     $output .= '</ul>';
     return $output;
 }
コード例 #9
0
    require_once QA_INCLUDE_DIR . 'qa-db-points.php';
    qa_db_points_set_bonus($userid, (int) qa_post_text('bonus'));
    qa_db_points_update_ifuser($userid, null);
    qa_redirect(qa_request(), null, null, null, 'activity');
}
//	Get information on user references in answers and other stuff need for page
$pagesize = qa_opt('page_size_user_posts');
$questions = qa_any_sort_and_dedupe(array_merge($questions, $answerqs, $commentqs, $editqs));
$questions = array_slice($questions, 0, $pagesize);
$usershtml = qa_userids_handles_html(qa_any_get_userids_handles($questions));
$usershtml[$userid] = $userhtml;
//	Prepare content for theme
$qa_content = qa_content_prepare(true);
$qa_content['title'] = qa_lang_html_sub('profile/user_x', $userhtml);
if (isset($loginuserid) && !QA_FINAL_EXTERNAL_USERS) {
    $qa_content['favorite'] = qa_favorite_form(QA_ENTITY_USER, $useraccount['userid'], $favorite, qa_lang_sub($favorite ? 'main/remove_x_favorites' : 'users/add_user_x_favorites', $handle));
}
//	General information about the user, only available if we're using internal user management
if (!QA_FINAL_EXTERNAL_USERS) {
    $qa_content['form_profile'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'wide', 'fields' => array('avatar' => array('type' => 'image', 'style' => 'tall', 'label' => '', 'html' => qa_get_user_avatar_html($useraccount['flags'], $useraccount['email'], $useraccount['handle'], $useraccount['avatarblobid'], $useraccount['avatarwidth'], $useraccount['avatarheight'], qa_opt('avatar_profile_size'))), 'removeavatar' => null, 'duration' => array('type' => 'static', 'label' => qa_lang_html('users/member_for'), 'value' => qa_html(qa_time_to_string(qa_opt('db_time') - $useraccount['created']))), 'level' => array('type' => 'static', 'label' => qa_lang_html('users/member_type'), 'tags' => 'NAME="level"', 'value' => qa_html(qa_user_level_string($useraccount['level'])), 'note' => $useraccount['flags'] & QA_USER_FLAGS_USER_BLOCKED && isset($maxlevelassign) ? qa_lang_html('users/user_blocked') : '')));
    if (empty($qa_content['form_profile']['fields']['avatar']['html'])) {
        unset($qa_content['form_profile']['fields']['avatar']);
    }
    //	Private message form
    if (qa_opt('allow_private_messages') && isset($loginuserid) && $loginuserid != $userid && !($useraccount['flags'] & QA_USER_FLAGS_NO_MESSAGES)) {
        $qa_content['form_profile']['fields']['level']['value'] .= strtr(qa_lang_html('profile/send_private_message'), array('^1' => '<A HREF="' . qa_path_html('message/' . $handle) . '">', '^2' => '</A>'));
    }
    //	Show any extra privileges due to user's level or their points
    $showpermits = array();
    $permitoptions = qa_get_permit_options();
    foreach ($permitoptions as $permitoption) {
コード例 #10
0
$userid = qa_get_logged_in_userid();
//	Find the questions with this tag
if (!strlen($tag)) {
    qa_redirect('tags');
}
list($questions, $tagword) = qa_db_select_with_pending(qa_db_tag_recent_qs_selectspec($userid, $tag, $start, false, qa_opt_if_loaded('page_size_tag_qs')), qa_db_tag_word_selectspec($tag));
$pagesize = qa_opt('page_size_tag_qs');
$questions = array_slice($questions, 0, $pagesize);
$usershtml = qa_userids_handles_html($questions);
//	Prepare content for theme
$qa_content = qa_content_prepare(true);
$qa_content['title'] = qa_lang_html_sub('main/questions_tagged_x', qa_html($tag));
if (isset($userid) && isset($tagword)) {
    $favoritemap = qa_get_favorite_non_qs_map();
    $favorite = @$favoritemap['tag'][qa_strtolower($tagword['word'])];
    $qa_content['favorite'] = qa_favorite_form(QA_ENTITY_TAG, $tagword['wordid'], $favorite, qa_lang_sub($favorite ? 'main/remove_x_favorites' : 'main/add_tag_x_favorites', $tagword['word']));
}
if (!count($questions)) {
    $qa_content['q_list']['title'] = qa_lang_html('main/no_questions_found');
}
$qa_content['q_list']['form'] = array('tags' => 'method="post" action="' . qa_self_html() . '"', 'hidden' => array('code' => qa_get_form_security_code('vote')));
$qa_content['q_list']['qs'] = array();
foreach ($questions as $postid => $question) {
    $qa_content['q_list']['qs'][] = qa_post_html_fields($question, $userid, qa_cookie_get(), $usershtml, null, qa_post_html_options($question));
}
$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $tagword['tagcount'], qa_opt('pages_prev_next'));
if (empty($qa_content['page_links'])) {
    $qa_content['suggest_next'] = qa_html_suggest_qs_tags(true);
}
if (qa_opt('feed_for_tag_qs')) {
    $qa_content['feed'] = array('url' => qa_path_html(qa_feed_request('tag/' . $tag)), 'label' => qa_lang_html_sub('main/questions_tagged_x', qa_html($tag)));
コード例 #11
0
             $inslug = qa_lang_sub('admin/category_default_slug', $attempt - 1);
             break;
     }
     $matchcategoryid = qa_db_category_slug_to_id($inparentid, $inslug);
     // query against DB since MySQL ignores accents, etc...
     if (!isset($inparentid)) {
         $matchpage = qa_db_single_select(qa_db_page_full_selectspec($inslug, false));
     } else {
         $matchpage = null;
     }
     if (empty($inslug)) {
         $errors['slug'] = qa_lang('main/field_required');
     } elseif (qa_strlen($inslug) > QA_DB_MAX_CAT_PAGE_TAGS_LENGTH) {
         $errors['slug'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TAGS_LENGTH);
     } elseif (preg_match('/[\\+\\/]/', $inslug)) {
         $errors['slug'] = qa_lang_sub('admin/slug_bad_chars', '+ /');
     } elseif (!isset($inparentid) && qa_admin_is_slug_reserved($inslug)) {
         // only top level is a problem
         $errors['slug'] = qa_lang('admin/slug_reserved');
     } elseif (isset($matchcategoryid) && strcmp($matchcategoryid, @$editcategory['categoryid'])) {
         $errors['slug'] = qa_lang('admin/category_already_used');
     } elseif (isset($matchpage)) {
         $errors['slug'] = qa_lang('admin/page_already_used');
     } else {
         unset($errors['slug']);
     }
     if (isset($editcategory['categoryid']) || !isset($errors['slug'])) {
         // don't try other options if editing existing category
         break;
     }
 }
コード例 #12
0
if (qa_clicked('dofeedback')) {
    require_once QA_INCLUDE_DIR . 'qa-util-emailer.php';
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    $inmessage = qa_post_text('message');
    $inname = qa_post_text('name');
    $inemail = qa_post_text('email');
    $inreferer = qa_post_text('referer');
    if (empty($inmessage)) {
        $errors['message'] = qa_lang('misc/feedback_empty');
    }
    if ($usecaptcha) {
        qa_captcha_validate($_POST, $errors);
    }
    if (empty($errors)) {
        $subs = array('^message' => $inmessage, '^name' => empty($inname) ? '-' : $inname, '^email' => empty($inemail) ? '-' : $inemail, '^previous' => empty($inreferer) ? '-' : $inreferer, '^url' => isset($qa_login_userid) ? qa_path('user/' . qa_get_logged_in_handle(), null, qa_opt('site_url')) : '-', '^ip' => qa_remote_ip_address(), '^browser' => @$_SERVER['HTTP_USER_AGENT']);
        if (qa_send_email(array('fromemail' => qa_email_validate(@$inemail) ? $inemail : qa_opt('from_email'), 'fromname' => $inname, 'toemail' => qa_opt('feedback_email'), 'toname' => qa_opt('site_title'), 'subject' => qa_lang_sub('emails/feedback_subject', qa_opt('site_title')), 'body' => strtr(qa_lang('emails/feedback_body'), $subs), 'html' => false))) {
            $feedbacksent = true;
        } else {
            $page_error = qa_lang_html('main/general_error');
        }
        qa_report_event('feedback', $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, array('email' => $inemail, 'name' => $inname, 'message' => $inmessage, 'previous' => $inreferer, 'browser' => @$_SERVER['HTTP_USER_AGENT']));
    }
}
//	Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('misc/feedback_title');
$qa_content['error'] = @$page_error;
$qa_content['form'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array('message' => array('type' => $feedbacksent ? 'static' : '', 'label' => qa_lang_html_sub('misc/feedback_message', qa_opt('site_title')), 'tags' => 'NAME="message" ID="message"', 'value' => qa_html(@$inmessage), 'rows' => 8, 'error' => qa_html(@$errors['message'])), 'name' => array('type' => $feedbacksent ? 'static' : '', 'label' => qa_lang_html('misc/feedback_name'), 'tags' => 'NAME="name"', 'value' => qa_html(isset($inname) ? $inname : @$userprofile['name'])), 'email' => array('type' => $feedbacksent ? 'static' : '', 'label' => qa_lang_html('misc/feedback_email'), 'tags' => 'NAME="email"', 'value' => qa_html(isset($inemail) ? $inemail : qa_get_logged_in_email()), 'note' => $feedbacksent ? null : qa_opt('email_privacy'))), 'buttons' => array('send' => array('label' => qa_lang_html('main/send_button'))), 'hidden' => array('dofeedback' => '1', 'referer' => qa_html(isset($inreferer) ? $inreferer : @$_SERVER['HTTP_REFERER'])));
if ($usecaptcha && !$feedbacksent) {
    qa_set_up_captcha_field($qa_content, $qa_content['form']['fields'], @$errors);
}
コード例 #13
0
function qa_password_validate($password, $olduser = null)
{
    $error = null;
    $filtermodules = qa_load_modules_with('filter', 'validate_password');
    foreach ($filtermodules as $filtermodule) {
        $error = $filtermodule->validate_password($password, $olduser);
        if (isset($error)) {
            break;
        }
    }
    if (!isset($error)) {
        $minpasslen = max(QA_MIN_PASSWORD_LEN, 1);
        if (qa_strlen($password) < $minpasslen) {
            $error = qa_lang_sub('users/password_min', $minpasslen);
        }
    }
    if (isset($error)) {
        return array('password' => $error);
    }
    return array();
}
コード例 #14
0
 function validate_length(&$errors, $field, $input, $minlength, $maxlength)
 {
     if (isset($input)) {
         $length = qa_strlen($input);
         if ($length < $minlength) {
             $errors[$field] = $minlength == 1 ? qa_lang('main/field_required') : qa_lang_sub('main/min_length_x', $minlength);
         } elseif (isset($maxlength) && $length > $maxlength) {
             $errors[$field] = qa_lang_sub('main/max_length_x', $maxlength);
         }
     }
 }
コード例 #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 . 'qa-app-users.php';
    require_once QA_INCLUDE_DIR . 'qa-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', number_format($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 . 'qa-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 . 'qa-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;
}
コード例 #16
0
ファイル: widget_posts.php プロジェクト: microbye/CleanStrap
 function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     $widget_opt = @$themeobject->current_widget['param']['options'];
     if ($widget_opt['post_type'] == 'Q') {
         $what = qa_lang_html('cleanstrap/questions');
     } elseif ($widget_opt['post_type'] == 'A') {
         $what = qa_lang_html('cleanstrap/answers');
     } elseif ($widget_opt['post_type'] == 'C') {
         $what = qa_lang_html('cleanstrap/comments');
     }
     if (@$themeobject->current_widget['param']['locations']['show_title']) {
         $themeobject->output('<h3 class="widget-title">' . qa_lang_sub('cleanstrap/recent_posts', $what) . '</h3>');
     }
     $themeobject->output('<div class="ra-post-list-widget">');
     $themeobject->output($this->cs_post_list($widget_opt['post_type'], (int) $widget_opt['cs_qa_count']));
     $themeobject->output('</div>');
 }
コード例 #17
0
if (qa_clicked('docancel')) {
    qa_redirect('admin/users');
} elseif (qa_clicked('dosavefield')) {
    require_once QA_INCLUDE_DIR . 'qa-db-admin.php';
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    if (qa_post_text('dodelete')) {
        qa_db_userfield_delete($editfield['fieldid']);
        qa_redirect('admin/users');
    } else {
        $inname = qa_post_text('name');
        $inflags = qa_post_text('flags');
        $inposition = qa_post_text('position');
        $errors = array();
        //	Verify the name is legitimate
        if (qa_strlen($inname) > QA_DB_MAX_PROFILE_TITLE_LENGTH) {
            $errors['name'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_PROFILE_TITLE_LENGTH);
        }
        //	Perform appropriate database action
        if (isset($editfield['fieldid'])) {
            // changing existing user field
            qa_db_userfield_set_fields($editfield['fieldid'], isset($errors['name']) ? $editfield['content'] : $inname, $inflags);
            qa_db_userfield_move($editfield['fieldid'], $inposition);
            if (empty($errors)) {
                qa_redirect('admin/users');
            } else {
                $userfields = qa_db_select_with_pending(qa_db_userfields_selectspec());
                // reload after changes
                foreach ($userfields as $userfield) {
                    if ($userfield['fieldid'] == $editfield['fieldid']) {
                        $editfield = $userfield;
                    }
コード例 #18
0
 /**
  * Check that a field meets the length requirements. If we're editing the post we can ignore missing fields.
  *
  * @param array $errors    Array of errors, with keys matching $post
  * @param array $post      The post containing the field we want to validate
  * @param string $key      The element of $post to validate
  * @param int $minlength
  * @param int $maxlength
  */
 private function validate_field_length(&$errors, &$post, $key, $minlength, $maxlength, $errorKey = null)
 {
     if (!$errorKey) {
         $errorKey = $key;
     }
     // skip the field is key not set (for example, 'title' when recategorizing questions)
     if (array_key_exists($key, $post)) {
         $length = qa_strlen($post[$key]);
         if ($length < $minlength) {
             $errors[$errorKey] = $minlength == 1 ? qa_lang('main/field_required') : qa_lang_sub('main/min_length_x', $minlength);
         } else {
             if (isset($maxlength) && $length > $maxlength) {
                 $errors[$errorKey] = qa_lang_sub('main/max_length_x', $maxlength);
             }
         }
     }
 }
コード例 #19
0
function qw_send_notification($userid, $email, $handle, $subject, $body, $subs)
{
    global $qa_notifications_suspended;
    if ($qa_notifications_suspended > 0) {
        return false;
    }
    require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    if (isset($userid)) {
        $needemail = !qa_email_validate(@$email);
        // take from user if invalid, e.g. @ used in practice
        $needhandle = empty($handle);
        if ($needemail || $needhandle) {
            if (QA_FINAL_EXTERNAL_USERS) {
                if ($needhandle) {
                    $handles = qa_get_public_from_userids(array($userid));
                    $handle = @$handles[$userid];
                }
                if ($needemail) {
                    $email = qa_get_user_email($userid);
                }
            } else {
                $useraccount = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true));
                if ($needhandle) {
                    $handle = @$useraccount['handle'];
                }
                if ($needemail) {
                    $email = @$useraccount['email'];
                }
            }
        }
    }
    if (isset($email) && qa_email_validate($email)) {
        $subs['^site_title'] = qa_opt('site_title');
        $subs['^handle'] = $handle;
        $subs['^email'] = $email;
        $subs['^open'] = "\n";
        $subs['^close'] = "\n";
        $email_param = array('fromemail' => qa_opt('from_email'), 'fromname' => qa_opt('site_title'), 'toemail' => $email, 'toname' => $handle, 'handle' => $handle, 'subject' => strtr($subject, $subs), 'body' => (empty($handle) ? '' : qa_lang_sub('emails/to_handle_prefix', $handle)) . strtr($body, $subs), 'html' => true);
        $email_param['body'] = qw_get_email_template($email_param);
        if (QW_SEND_EMAIL_DEBUG_MODE) {
            //this will write to the log file
            return qw_send_email_fake($email_param);
        }
        return qa_send_email($email_param);
    } else {
        return false;
    }
}
コード例 #20
0
ファイル: qa-wysiwyg-upload.php プロジェクト: ramo01/1kapp
 function process_request($request)
 {
     $message = '';
     $url = '';
     if (is_array($_FILES) && count($_FILES)) {
         //	Check that we're allowed to upload images (if not, no other uploads are allowed either)
         if (!qa_opt('wysiwyg_editor_upload_images')) {
             $message = qa_lang('users/no_permission');
         }
         //	Check that we haven't reached the upload limit and are not blocked
         if (empty($message)) {
             require_once QA_INCLUDE_DIR . 'qa-app-users.php';
             require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
             switch (qa_user_permit_error(null, QA_LIMIT_UPLOADS)) {
                 case 'limit':
                     $message = qa_lang('main/upload_limit');
                     break;
                 case false:
                     qa_limits_increment(qa_get_logged_in_userid(), QA_LIMIT_UPLOADS);
                     break;
                 default:
                     $message = qa_lang('users/no_permission');
                     break;
             }
         }
         //	Find out some information about the uploaded file and check it's not too large
         if (empty($message)) {
             require_once QA_INCLUDE_DIR . 'qa-app-blobs.php';
             $file = reset($_FILES);
             $pathinfo = pathinfo($file['name']);
             $extension = strtolower(@$pathinfo['extension']);
             $filesize = $file['size'];
             $maxsize = min(qa_opt('wysiwyg_editor_upload_max_size'), qa_get_max_upload_size());
             if ($filesize <= 0 || $filesize > $maxsize) {
                 // if file was too big for PHP, $filesize will be zero
                 $message = qa_lang_sub('main/max_upload_size_x', number_format($maxsize / 1048576, 1) . 'MB');
             }
         }
         //	If it's only allowed to be an image, check it's an image
         if (empty($message)) {
             if (qa_get('qa_only_image') || !qa_opt('wysiwyg_editor_upload_all')) {
                 // check if we need to confirm it's an image
                 switch ($extension) {
                     case 'png':
                         // these are allowed image extensions
                     // these are allowed image extensions
                     case 'gif':
                     case 'jpeg':
                     case 'jpg':
                         if (function_exists('getimagesize')) {
                             // getimagesize() does not require GD library
                             if (!is_array(@getimagesize($file['tmp_name']))) {
                                 $message = qa_lang_sub('main/image_not_read', 'GIF, JPG, PNG');
                             }
                         }
                         break;
                     default:
                         $message = qa_lang_sub('main/image_not_read', 'GIF, JPG, PNG');
                         break;
                 }
             }
         }
         //	If there have been no errors, looks like we're all set...
         if (empty($message)) {
             require_once QA_INCLUDE_DIR . 'qa-db-blobs.php';
             $userid = qa_get_logged_in_userid();
             $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create();
             $blobid = qa_db_blob_create(file_get_contents($file['tmp_name']), $extension, @$file['name'], $userid, $cookieid, qa_remote_ip_address());
             if (isset($blobid)) {
                 $url = qa_get_blob_url($blobid, true);
             } else {
                 $message = 'Failed to create object in database - please try again';
             }
         }
     }
     echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction(" . qa_js(qa_get('CKEditorFuncNum')) . ", " . qa_js($url) . ", " . qa_js($message) . ");</script>";
     return null;
 }
コード例 #21
0
 function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     $widget_opt = @$themeobject->current_widget['param']['options'];
     $handle = $qa_content['raw']['account']['handle'];
     if (@$themeobject->current_widget['param']['locations']['show_title']) {
         $themeobject->output('<h3 class="widget-title">' . qa_lang_sub('cleanstrap/x_activities', $handle) . '</h3>');
     }
     $themeobject->output('<div class="ra-ua-widget">');
     $themeobject->output($this->get_user_activity($handle, (int) $widget_opt['cs_ua_count']));
     $themeobject->output('</div>');
 }
コード例 #22
0
/**
 * Returns the language value as defined in qa-dhp-lang-*.php
 *
 * @param      $indentifier
 * @param null $subs
 *
 * @return mixed|string
 */
function dhp_lang($indentifier, $subs = null)
{
    if (!is_array($subs)) {
        return empty($subs) ? qa_lang('ami_dhp/' . $indentifier) : qa_lang_sub('ami_dhp/' . $indentifier, $subs);
    } else {
        return strtr(qa_lang('ami_dhp/' . $indentifier), $subs);
    }
}
コード例 #23
0
ファイル: functions.php プロジェクト: rahularyan/dude-theme
function qw_activitylist($limit)
{
    $offset = (int) qa_get('start');
    // get points for each activity
    require_once QA_INCLUDE_DIR . 'qa-db-points.php';
    require_once QA_INCLUDE_DIR . 'qa-db-users.php';
    $optionnames = qa_db_points_option_names();
    $options = qa_get_options($optionnames);
    $multi = (int) $options['points_multiple'];
    $upvote = '';
    $downvote = '';
    if (@$options['points_per_q_voted_up']) {
        $upvote = '_up';
        $downvote = '_down';
    }
    $event_point['in_q_vote_up'] = (int) $options['points_per_q_voted' . $upvote] * $multi;
    $event_point['in_q_vote_down'] = (int) $options['points_per_q_voted' . $downvote] * $multi * -1;
    $event_point['in_q_unvote_up'] = (int) $options['points_per_q_voted' . $upvote] * $multi * -1;
    $event_point['in_q_unvote_down'] = (int) $options['points_per_q_voted' . $downvote] * $multi;
    $event_point['a_vote_up'] = (int) $options['points_per_a_voted' . $upvote] * $multi;
    $event_point['in_a_vote_down'] = (int) $options['points_per_a_voted' . $downvote] * $multi * -1;
    $event_point['in_a_unvote_up'] = (int) $options['points_per_a_voted' . $upvote] * $multi * -1;
    $event_point['in_a_unvote_down'] = (int) $options['points_per_a_voted' . $downvote] * $multi;
    $event_point['in_a_select'] = (int) $options['points_a_selected'] * $multi;
    $event_point['in_a_unselect'] = (int) $options['points_a_selected'] * $multi * -1;
    $event_point['q_post'] = (int) $options['points_post_q'] * $multi;
    $event_point['a_post'] = (int) $options['points_post_a'] * $multi;
    $event_point['a_select'] = (int) $options['points_select_a'] * $multi;
    $event_point['q_vote_up'] = (int) $options['points_vote_up_q'] * $multi;
    $event_point['q_vote_down'] = (int) $options['points_vote_down_q'] * $multi;
    $event_point['a_vote_up'] = (int) $options['points_vote_up_a'] * $multi;
    $event_point['a_vote_down'] = (int) $options['points_vote_down_a'] * $multi;
    // Get Events
    $userid = qa_get_logged_in_userid();
    $eventslist = qa_db_read_all_assoc(qa_db_query_sub('SELECT id, UNIX_TIMESTAMP(datetime) AS datetime, userid, postid, effecteduserid, event, params, `read` FROM ^ra_userevent WHERE effecteduserid=# AND event NOT IN ("u_wall_post", "u_message") ORDER BY datetime DESC LIMIT # OFFSET #', $userid, $limit, $offset));
    if (count($eventslist) > 0) {
        $event = array();
        $output = '';
        $i = 0;
        //
        $userids = array();
        foreach ($eventslist as $event) {
            $userids[$event['userid']] = $event['userid'];
            $userids[$event['effecteduserid']] = $event['effecteduserid'];
        }
        if (QA_FINAL_EXTERNAL_USERS) {
            $handles = qa_get_public_from_userids($userids);
        } else {
            $handles = qa_db_user_get_userid_handles($userids);
        }
        // get event's: time, type, parameters
        // get post id of questions
        foreach ($eventslist as $event) {
            $title = '';
            $link = '';
            $vote_status = '';
            $handle = isset($handles[$event['userid']]) ? $handles[$event['userid']] : qa_lang('main/anonymous');
            $datetime = $event['datetime'];
            $event['date'] = qa_html(qa_time_to_string(qa_opt('db_time') - $datetime));
            $event['params'] = json_decode($event['params'], true);
            $id = ' data-id="' . $event['id'] . '"';
            $read = $event['read'] ? ' read' : ' unread';
            $mark_as_read = !$event['read'] ? '<span class="icon icon-tick"></span>' : '';
            $url_param = array('ra_notification' => $event['id']);
            $user_link = qa_path_html('user/' . $handle, $url_param, QW_BASE_URL);
            switch ($event['event']) {
                case 'related':
                    // related question to an answer
                    $url = qa_path_html(qa_q_request($event['postid'], $event['params']['title']), $url_param, QW_BASE_URL, null, null);
                    echo '<div class="event-content clearfix' . $read . '' . $read . '"' . $id . '>
                                                <div class="avatar"><a href="' . $user_link . '">' . qw_get_avatar($handle, 32, true) . '</a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <strong class="user">' . $handle . '</strong>
                                                                  <span class="what">' . qa_lang_html('dude/asked_question_related_to_your') . '</span>
                                                                  <strong class="where">' . qa_lang_html('dude/answer') . '</strong>
                                                            </div>
                                                            <div class="footer">
                                                                  <span class="event-icon icon-link"></span>
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'a_post':
                    // user's question had been answered
                    $anchor = qa_anchor('A', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                    $title = qw_truncate($event['params']['qtitle'], 60);
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a href="' . $user_link . '">' . qw_get_avatar($handle, 32, true) . '</a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <strong class="user">' . $handle . '</strong>
                                                                  <span class="what">' . qa_lang_html('dude/answered_your') . '</span>
                                                                  <strong class="where">' . qa_lang_html('dude/question') . '</strong>
                                                            </div>
                                                            <div class="footer">
                                                                  <span class="event-icon icon-answer"></span>
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'c_post':
                    // user's question had been commented
                    $anchor = qa_anchor('C', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                    if ($event['params']['parenttype'] == 'Q') {
                        $type = qa_lang_html('dude/question');
                    } elseif ($event['params']['parenttype'] == 'A') {
                        $type = qa_lang_html('dude/answer');
                    } else {
                        $type = qa_lang_html('dude/comment');
                    }
                    if (isset($event['params']['parent_uid']) && $event['params']['parent_uid'] != $userid) {
                        $what = qa_lang_html('dude/followup_comment');
                        $type = qa_lang_html('dude/comment');
                    } else {
                        $what = qa_lang_html('dude/replied_to_your');
                    }
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a href="' . $user_link . '">' . qw_get_avatar($handle, 32, true) . '</a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <strong class="user">' . $handle . '</strong>
                                                                  <span class="what">' . $what . '</span>
                                                                  <strong class="where">' . $type . '</strong>
                                                            </div>
                                                            <div class="footer">
                                                                  <span class="event-icon icon-arrow-back"></span>
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'q_reshow':
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, null);
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a class="icon icon-eye" href="' . $url . '"></a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <span>' . qa_lang_html('dude/your') . '</span>
                                                                  <strong>' . qa_lang_html('dude/question') . '</strong>
                                                                  <span class="what">' . qa_lang_html('dude/is_visible') . '</span>
                                                            </div>
                                                            <div class="footer">
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'a_reshow':
                    // user's question had been answered
                    $anchor = qa_anchor('A', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a class="icon icon-eye" href="' . $url . '"></a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <span>' . qa_lang_html('dude/your') . '</span>
                                                                  <strong>' . qa_lang_html('dude/answer') . '</strong>
                                                                  <span class="what">' . qa_lang_html('dude/is_visible') . '</span>
                                                            </div>
                                                            <div class="footer">
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'c_reshow':
                    // user's question had been answered
                    $anchor = qa_anchor('C', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a class="icon icon-eye" href="' . $url . '"></a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <span>' . qa_lang_html('dude/your') . '</span>
                                                                  <strong>' . qa_lang_html('dude/comment') . '</strong>
                                                                  <span class="what">' . qa_lang_html('dude/is_visible') . '</span>
                                                            </div>
                                                            <div class="footer">
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'a_select':
                    $anchor = qa_anchor('A', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a href="' . $user_link . '">' . qw_get_avatar($handle, 32, true) . '</a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <strong class="user">' . $handle . '</strong>
                                                                  <span class="what">' . qa_lang_html('dude/selected_as_best') . '</span>
                                                            </div>
                                                            <div class="footer">
                                                                  <span class="event-icon icon-award"></span>
                                                                  <span class="points">' . qa_lang_sub('dude/you_have_earned_x_points', $event_point['a_post']) . '</span>
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'q_vote_up':
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null);
                    $title = qw_truncate($event['params']['qtitle'], 60);
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a href="' . $user_link . '">' . qw_get_avatar($handle, 32, true) . '</a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <strong class="user">' . $handle . '</strong>
                                                                  <span class="what">' . qa_lang_html('dude/upvoted_on_your') . '</span>
                                                                  <strong class="where">' . qa_lang_html('dude/question') . '</strong>
                                                            </div>
                                                            <div class="footer">
                                                                  <span class="event-icon icon-thumb-up"></span>
                                                                  <span class="points">' . qa_lang_sub('dude/you_have_earned_x_points', $event_point['a_vote_up']) . '</span>
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'a_vote_up':
                    $anchor = qa_anchor('A', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a href="' . $user_link . '">' . qw_get_avatar($handle, 32, true) . '</a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <strong class="user">' . $handle . '</strong>
                                                                  <span class="what">' . qa_lang_html('dude/upvoted_on_your') . '</span>
                                                                  <strong class="where">' . qa_lang_html('dude/answer') . '</strong>
                                                            </div>
                                                            <div class="footer">
                                                                  <span class="event-icon icon-thumb-up"></span>
                                                                  <span class="points">' . qa_lang_sub('dude/you_have_earned_x_points', $event_point['a_vote_up']) . '</span>
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'q_approve':
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null);
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a class="icon icon-input-checked" href="' . $url . '"></a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <strong class="user">' . $handle . '</strong>
                                                                  <span class="what">' . qa_lang_html('dude/approved_your') . '</span>
                                                                  <strong class="where">' . qa_lang_html('dude/question') . '</strong>
                                                            </div>
                                                            <div class="footer">
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'a_approve':
                    $anchor = qa_anchor('A', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a class="icon icon-input-checked" href="' . $url . '"></a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <strong class="user">' . $handle . '</strong>
                                                                  <span class="what">' . qa_lang_html('dude/approved_your') . '</span>
                                                                  <strong class="where">' . qa_lang_html('dude/answer') . '</strong>
                                                            </div>
                                                            <div class="footer">
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'u_favorite':
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a href="' . $user_link . '">' . qw_get_avatar($handle, 32, true) . '</a></div>
                                                <div class="event-right">
                                                      <a href="' . $user_link . '">
                                                            <div class="head">
                                                                  <strong class="user">' . $handle . '</strong>
                                                                  <span class="what">' . qa_lang_html('dude/added_you_to') . '</span>
                                                                  <strong class="where">' . qa_lang_html('dude/favourite') . '</strong>
                                                            </div>
                                                            <div class="footer">
                                                                  <span class="event-icon icon-heart"></span>                                                     
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'q_favorite':
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a href="' . $user_link . '">' . qw_get_avatar($handle, 32, true) . '</a></div>
                                                <div class="event-right">
                                                      <a href="' . $user_link . '">
                                                            <div class="head">
                                                                  <strong class="user">' . $handle . '</strong>
                                                                  <span class="what">' . qa_lang_html('dude/added_your_question_to') . '</span>
                                                                  <strong class="where">' . qa_lang_html('dude/favourite') . '</strong>
                                                            </div>
                                                            <div class="footer">
                                                                  <span class="event-icon icon-heart"></span>                                                     
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'q_vote_down':
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null);
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a class="icon icon-thumb-down" href="' . $url . '"></a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <span class="what">' . qa_lang_html('dude/you_have_received_down_vote') . '</span>
                                                                  <strong class="where">' . qa_lang_html('dude/question') . '</strong>
                                                            </div>
                                                            <div class="footer">
                                                                  <span class="points">' . qa_lang_sub('dude/you_have_lost_x_points', $event_point['q_vote_down']) . '</span>
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'c_approve':
                    $anchor = qa_anchor('C', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a class="icon icon-input-checked" href="' . $url . '"></a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <strong class="user">' . $handle . '</strong>
                                                                  <span class="what">' . qa_lang_html('dude/approved_your') . '</span>
                                                                  <strong class="where">' . qa_lang_html('dude/comment') . '</strong>
                                                            </div>
                                                            <div class="footer">                                                    
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'q_reject':
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null);
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a class="icon icon-times" href="' . $url . '"></a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <strong class="user">' . $handle . '</strong>
                                                                  <span class="what">' . qa_lang_html('dude/your_question_is_rejected') . '</span>
                                                            </div>
                                                            <div class="footer">
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'a_reject':
                    $anchor = qa_anchor('A', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a class="icon icon-times" href="' . $url . '"></a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <strong class="user">' . $handle . '</strong>
                                                                  <span class="what">' . qa_lang_html('dude/your_answer_is_rejected') . '</span>
                                                            </div>
                                                            <div class="footer">                                                    
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'c_reject':
                    $anchor = qa_anchor('C', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a class="icon icon-times" href="' . $url . '"></a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <strong class="user">' . $handle . '</strong>
                                                                  <span class="what">' . qa_lang_html('dude/your_comment_is_rejected') . '</span>
                                                            </div>
                                                            <div class="footer">                                                    
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
                case 'u_level':
                    $url = qa_path_absolute('user/' . $event['params']['handle']);
                    $old_level = $event['params']['oldlevel'];
                    $new_level = $event['params']['level'];
                    if ($new_level < $old_level) {
                        break;
                    }
                    $approved_only = "";
                    if ($new_level == QA_USER_LEVEL_APPROVED && $old_level < QA_USER_LEVEL_APPROVED) {
                        $approved_only = true;
                    } else {
                        $approved_only = false;
                    }
                    if ($approved_only === false) {
                        $new_designation = qw_get_user_desg($new_level);
                    }
                    $content = strtr(qa_lang($approved_only ? 'notification/u_level_approved_notf' : 'notification/u_level_improved_notf'), array('^new_designation' => @$new_designation));
                    echo '<div class="event-content clearfix' . $read . '"' . $id . '>
                                                <div class="avatar"><a class="icon icon-user" href="' . $url . '"></a></div>
                                                <div class="event-right">
                                                      <a href="' . $url . '">
                                                            <div class="head">
                                                                  <strong class="user">' . $handle . '</strong>
                                                                  <span class="what">' . @$content . '</span>
                                                            </div>
                                                            <div class="footer">
                                                                  <span class="points">' . qa_lang_sub('dude/you_have_earned_x_points', $event_point['a_vote_up']) . '</span>
                                                                  <span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
                                                            </div>
                                                      </a>
                                                </div>
                                          </div>';
                    break;
            }
        }
        //code for pagination
    } else {
        echo '<div class="no-more-activity">' . qa_lang_html('dude/no_more_activity') . '</div>';
    }
}
コード例 #24
0
function qa_book_plugin_createBook($return = false)
{
    $book = qa_opt('book_plugin_template');
    // static replacements
    $book = str_replace('[css]', qa_opt('book_plugin_css'), $book);
    $book = str_replace('[front]', qa_opt('book_plugin_template_front'), $book);
    $book = str_replace('[back]', qa_opt('book_plugin_template_back'), $book);
    $iscats = qa_opt('book_plugin_cats');
    // categories
    if ($iscats) {
        $cats = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^categories' . (qa_opt('book_plugin_catex') ? ' WHERE categoryid NOT IN (' . qa_opt('book_plugin_catex') . ')' : '')));
        $navcats = array();
        foreach ($cats as $cat) {
            $navcats[$cat['categoryid']] = $cat;
        }
    } else {
        $cats = array(false);
    }
    // intro
    $intro = qa_lang('book/intro');
    $intro = str_replace('[sort_questions]', qa_lang('book/' . (qa_opt('book_plugin_sort_q') == 0 ? 'sort_upvotes' : 'sort_date')), $intro);
    $intro = str_replace('[sort_categories]', $iscats ? qa_lang('book/sort_categories') : '', $intro);
    $intro = str_replace('[restrict_questions]', qa_opt('book_plugin_req_qv') ? qa_lang_sub('book/restrict_q_x_votes', qa_opt('book_plugin_req_qv_no')) : qa_lang('book/all_questions'), $intro);
    $rq = array();
    if (qa_opt('book_plugin_req_sel')) {
        $rq[] = qa_lang('book/restrict_selected');
    }
    if (qa_opt('book_plugin_req_abest')) {
        $rq[] = qa_lang('book/restrict_best_a');
    }
    if (qa_opt('book_plugin_req_av')) {
        $rq[] = qa_lang_sub('book/restrict_a_x_votes', qa_opt('book_plugin_req_av_no'));
    }
    if (empty($rq)) {
        $intro = str_replace('[restrict_answers]', '', $intro);
    } else {
        $rqs = qa_lang('book/restrict_answers_clause_' . count($rq));
        foreach ($rq as $i => $v) {
            $rqs = str_replace('(' . ($i + 1) . ')', $v, $rqs);
        }
        $intro = str_replace('[restrict_answers]', $rqs, $intro);
    }
    $book = str_replace('[intro]', $intro, $book);
    $tocout = '';
    $qout = '';
    foreach ($cats as $cat) {
        $incsql = '';
        $sortsql = '';
        $toc = '';
        $qhtml = '';
        if (qa_opt('book_plugin_sort_q') == 0) {
            $sortsql = 'ORDER BY qs.netvotes DESC, qs.created ASC';
        } else {
            $sortsql = 'ORDER BY qs.created ASC';
        }
        if (qa_opt('book_plugin_req_sel')) {
            $incsql .= ' AND qs.selchildid=ans.postid';
        }
        if (qa_opt('book_plugin_req_abest')) {
            $sortsql .= ', ans.netvotes DESC';
        }
        // get all, limit later with break
        if (qa_opt('book_plugin_req_qv')) {
            $incsql .= ' AND qs.netvotes >= ' . (int) qa_opt('book_plugin_req_qv_no');
        }
        if (qa_opt('book_plugin_req_av')) {
            $incsql .= ' AND ans.netvotes >= ' . (int) qa_opt('book_plugin_req_av_no');
        }
        $selectspec = "SELECT qs.postid AS postid, BINARY qs.title AS title, BINARY qs.content AS content, qs.format AS format, qs.netvotes AS netvotes, BINARY ans.content AS acontent, ans.format AS aformat, ans.userid AS auserid, ans.netvotes AS anetvotes FROM ^posts AS qs, ^posts AS ans WHERE qs.type='Q' AND ans.type='A' AND ans.parentid=qs.postid" . ($iscats ? " AND qs.categoryid=" . $cat['categoryid'] . " " : "") . $incsql . " " . $sortsql;
        $qs = qa_db_read_all_assoc(qa_db_query_sub($selectspec));
        if (empty($qs)) {
            // no questions in this category
            continue;
        }
        $q2 = array();
        foreach ($qs as $q) {
            // group by questions
            $q2['q' . $q['postid']][] = $q;
        }
        foreach ($q2 as $qs) {
            // toc entry
            $toc .= str_replace('[qlink]', '<a href="#question' . $qs[0]['postid'] . '">' . $qs[0]['title'] . '</a>', qa_opt('book_plugin_template_toc'));
            // answer html
            $as = '';
            $nv = false;
            foreach ($qs as $idx => $q) {
                if (qa_opt('book_plugin_req_abest') && qa_opt('book_plugin_req_abest_max') && $idx >= qa_opt('book_plugin_req_abest_max')) {
                    break;
                }
                if ($nv !== false && qa_opt('book_plugin_req_abest') && $nv != $q['anetvotes']) {
                    // best answers only
                    break;
                }
                $acontent = '';
                if (!empty($q['acontent'])) {
                    $viewer = qa_load_viewer($q['acontent'], $q['aformat']);
                    $acontent = $viewer->get_html($q['acontent'], $q['aformat'], array());
                }
                $a = str_replace('[answer]', $acontent, qa_opt('book_plugin_template_answer'));
                $a = str_replace('[answerer]', qa_get_user_name($q['auserid']), $a);
                $as .= $a;
                $nv = $q['anetvotes'];
            }
            // question html
            $qcontent = '';
            if (!empty($q['content'])) {
                $viewer = qa_load_viewer($q['content'], $q['format']);
                $qcontent = $viewer->get_html($q['content'], $q['format'], array());
            }
            $oneq = str_replace('[question-title]', $q['title'], qa_opt('book_plugin_template_question'));
            $oneq = str_replace('[qanchor]', 'question' . $q['postid'], $oneq);
            $oneq = str_replace('[qurl]', qa_html(qa_q_request($q['postid'], $q['title'])), $oneq);
            $oneq = str_replace('[question]', $qcontent, $oneq);
            // output with answers
            $qhtml .= str_replace('[answers]', $as, $oneq);
        }
        if ($iscats) {
            $tocout .= '<li><a href="#cat' . $cat['categoryid'] . '" class="toc-cat">' . $cat['title'] . '</a><ul class="toc-ul">' . $toc . '</ul></li>';
            // todo fix category link
            $catout = str_replace('[cat-url]', qa_path_html('questions/' . qa_category_path_request($navcats, $cat['categoryid'])), qa_opt('book_plugin_template_category'));
            $catout = str_replace('[cat-anchor]', 'cat' . $cat['categoryid'], $catout);
            $catout = str_replace('[cat-title]', $cat['title'], $catout);
            $catout = str_replace('[questions]', $qhtml, $catout);
            $qout .= $catout;
        } else {
            $tocout .= '<ul class="toc-ul">' . $toc . '</ul>';
            $catout = str_replace('[questions]', $qhtml, qa_opt('book_plugin_template_questions'));
            $qout .= $catout;
        }
    }
    if ($iscats) {
        $tocout = '<ul class="toc-ul">' . $tocout . '</ul>';
    }
    // add toc and questions
    $book = str_replace('[toc]', $tocout, $book);
    $book = str_replace('[categories]', $qout, $book);
    // misc subs
    $book = str_replace('[site-title]', qa_opt('site_title'), $book);
    $book = str_replace('[site-url]', qa_opt('site_url'), $book);
    $book = str_replace('[date]', date('M j, Y'), $book);
    qa_opt('book_plugin_refresh_last', time());
    error_log('Q2A Book Created on ' . date('M j, Y \\a\\t H\\:i\\:s'));
    if ($return) {
        return $book;
    }
    file_put_contents(qa_opt('book_plugin_loc'), $book);
    if (qa_opt('book_plugin_pdf')) {
        qa_book_plugin_create_pdf();
    }
    return 'Book Created';
    //return 'Error creating '.qa_opt('book_plugin_loc').'; check the error log.';
}
コード例 #25
0
 /**
  * Get Question List.
  *
  * @param array $args ($username, $password, $data['sort', 'start', 'cats', 'full', 'size', 'action', 'action_id', 'action_data'])
  * @return array (questions);
  * 
  */
 function call_get_questions($args)
 {
     // Parse the arguments, assuming they're in the correct order
     $username = qa_db_escape_string($args[0]);
     $password = qa_db_escape_string($args[1]);
     $data = @$args[2];
     if (!$this->login($username, $password)) {
         return $this->error;
     }
     $userid = qa_get_logged_in_userid();
     $output = array();
     if (isset($data['action'])) {
         $action_message = $this->do_action($data);
     }
     $sort = @$data['sort'];
     $start = (int) @$data['start'];
     $size = (int) @$data['size'];
     $full = isset($data['full']);
     switch ($sort) {
         case 'updated':
             $qarray = $this->get_updated_qs($size);
             break;
         case 'favorites':
             $selectspec = qa_db_posts_basic_selectspec($userid, true);
             $selectspec['source'] .= " JOIN ^userfavorites AS uf ON ^posts.postid=uf.entityid WHERE uf.userid=\$ AND uf.entitytype=\$ AND ^posts.type='Q' LIMIT #";
             array_push($selectspec['arguments'], $userid, QA_ENTITY_QUESTION, $size + 1);
             $selectspec['sortdesc'] = 'created';
             $qarray = qa_db_select_with_pending($selectspec);
             break;
         default:
             $qarray = qa_db_select_with_pending(qa_db_qs_selectspec($userid, $sort, $start, null, null, false, $full, $size + 1));
             break;
     }
     $more = false;
     if (count($qarray) > $size && $sort != 'updated') {
         $more = true;
         array_pop($qarray);
     }
     $questions = array();
     if (isset($data['more']) && $start > 0) {
         $questions[] = "<less>";
     }
     foreach ($qarray as $question) {
         if (isset($data['action_id']) && isset($data['postid']) && $question['postid'] == $data['postid']) {
             $output['acted'] = count($questions);
         }
         $question = $this->get_single_question($data, $question);
         if ($question) {
             $questions[] = $question;
         }
     }
     // add extra list item for loading more
     if ($more && isset($data['more'])) {
         $questions[] = "<more>";
     }
     if (empty($questions)) {
         $output['message'] = qa_lang('xmlrpc/no_items_found');
     } else {
         if (isset($data['action'])) {
             $output['message'] = $action_message;
         } else {
             $output['message'] = qa_lang_sub('xmlrpc/x_items_found', count($questions));
         }
     }
     if (isset($data['meta'])) {
         $output['meta'] = $this->get_meta_data();
     }
     $output['confirmation'] = true;
     $output['data'] = $questions;
     return $output;
 }
コード例 #26
0
ファイル: addon.php プロジェクト: rahularyan/dude-theme
    public function messagelist()
    {
        $offset = (int) qa_get('offset');
        $offset = isset($offset) ? $offset * 15 : 0;
        require_once QA_INCLUDE_DIR . 'qa-db-users.php';
        // Get Events
        $message_events = array('u_message', 'u_wall_post');
        $events = "'" . implode("','", $message_events) . "'";
        $userid = qa_get_logged_in_userid();
        $eventslist = qa_db_read_all_assoc(qa_db_query_sub('SELECT id, UNIX_TIMESTAMP(datetime) AS datetime, userid, postid, effecteduserid, event, params, `read` FROM ^ra_userevent WHERE effecteduserid=# AND `read` = 0 AND event IN (' . $events . ') ORDER BY id DESC LIMIT 15 OFFSET #', $userid, $offset));
        if (count($eventslist) > 0) {
            $event = array();
            $userids = array();
            foreach ($eventslist as $event) {
                $userids[$event['userid']] = $event['userid'];
                $userids[$event['effecteduserid']] = $event['effecteduserid'];
            }
            if (QA_FINAL_EXTERNAL_USERS) {
                $handles = qa_get_public_from_userids($userids);
            } else {
                $handles = qa_db_user_get_userid_handles($userids);
            }
            // get event's: time, type, parameters
            // get post id of questions
            foreach ($eventslist as $event) {
                $title = '';
                $link = '';
                $handle = $handles[$event['userid']];
                $reciever_handle = $handles[$event['effecteduserid']];
                $reciever_link = qa_path('user/' . $reciever_handle);
                $datetime = $event['datetime'];
                $event['date'] = qa_html(qa_time_to_string(qa_opt('db_time') - $datetime));
                $event['params'] = json_decode($event['params'], true);
                $message = substr($event['params']['message'], 0, 30) . '..';
                $id = ' data-id="' . $event['id'] . '"';
                $read = $event['read'] ? ' read' : ' unread';
                $url_param = array('ra_notification' => $event['id']);
                $user_link = qa_path_html('user/' . $handle, $url_param);
                switch ($event['event']) {
                    case 'u_message':
                        // related question to an answer
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a href="' . $user_link . '">' . ra_get_avatar($handle, 32, true) . '</a></div>
								<div class="event-right">
									<a href="' . qa_path_html('message/' . $handle, $url_param, QW_BASE_URL) . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/sent_you_a_private_message') . '</span>
											<span class="message">' . $message . '</span>
										</div>
										<div class="footer">
											<span class="event-icon icon-email"></span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'u_wall_post':
                        // user's question had been answered
                        $url = qa_path_html('user/' . $reciever_handle . '/wall', $url_param, QW_BASE_URL);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a href="' . $user_link . '">' . ra_get_avatar($handle, 32, true) . '</a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/posted_on_your_wall') . '</span>
											<span class="message">' . $message . '</span>
										</div>
										<div class="footer">
											<span class="event-icon icon-pin"></span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                }
            }
        } else {
            echo '<div class="no-more-activity">' . qa_lang_html('dude/no_more_messages') . '</div>';
        }
        die;
    }
コード例 #27
0
 if (is_array(@$_FILES['file']) && $_FILES['file']['size']) {
     require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
     switch (qa_user_permit_error(null, QA_LIMIT_UPLOADS)) {
         case 'limit':
             $errors['avatar'] = qa_lang('main/upload_limit');
             break;
         default:
             $errors['avatar'] = qa_lang('users/no_permission');
             break;
         case false:
             qa_limits_increment($userid, QA_LIMIT_UPLOADS);
             $toobig = qa_image_file_too_big($_FILES['file']['tmp_name'], qa_opt('avatar_store_size'));
             if ($toobig) {
                 $errors['avatar'] = qa_lang_sub('main/image_too_big_x_pc', (int) ($toobig * 100));
             } elseif (!qa_set_user_avatar($userid, file_get_contents($_FILES['file']['tmp_name']), $useraccount['avatarblobid'])) {
                 $errors['avatar'] = qa_lang_sub('main/image_not_read', implode(', ', qa_gd_image_formats()));
             }
             break;
     }
 }
 if (count($inprofile)) {
     $filtermodules = qa_load_modules_with('filter', 'filter_profile');
     foreach ($filtermodules as $filtermodule) {
         $filtermodule->filter_profile($inprofile, $errors, $useraccount, $userprofile);
     }
 }
 foreach ($userfields as $userfield) {
     if (!isset($errors[$userfield['fieldid']])) {
         qa_db_user_profile_set($userid, $userfield['title'], $inprofile[$userfield['fieldid']]);
     }
 }
コード例 #28
0
ファイル: user-profile.php プロジェクト: swuit/swuit-q2a
}
//	Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html_sub('profile/user_x', $userhtml);
$qa_content['error'] = @$errors['page'];
if (isset($loginuserid) && $loginuserid != $useraccount['userid'] && !QA_FINAL_EXTERNAL_USERS) {
    $favoritemap = qa_get_favorite_non_qs_map();
    $favorite = @$favoritemap['user'][$useraccount['userid']];
    $qa_content['favorite'] = qa_favorite_form(QA_ENTITY_USER, $useraccount['userid'], $favorite, qa_lang_sub($favorite ? 'main/remove_x_favorites' : 'users/add_user_x_favorites', $handle));
}
$qa_content['script_rel'][] = 'qa-content/qa-user.js?' . QA_VERSION;
//	General information about the user, only available if we're using internal user management
if (!QA_FINAL_EXTERNAL_USERS) {
    $membertime = qa_time_to_string(qa_opt('db_time') - $useraccount['created']);
    $joindate = qa_when_to_html($useraccount['created'], 0);
    $qa_content['form_profile'] = array('tags' => 'method="post" action="' . qa_self_html() . '"', 'style' => 'wide', 'fields' => array('avatar' => array('type' => 'image', 'style' => 'tall', 'label' => '', 'html' => qa_get_user_avatar_html($useraccount['flags'], $useraccount['email'], $useraccount['handle'], $useraccount['avatarblobid'], $useraccount['avatarwidth'], $useraccount['avatarheight'], qa_opt('avatar_profile_size')), 'id' => 'avatar'), 'removeavatar' => null, 'duration' => array('type' => 'static', 'label' => qa_lang_html('users/member_for'), 'value' => qa_html($membertime . ' (' . qa_lang_sub('main/since_x', $joindate['data']) . ')'), 'id' => 'duration'), 'level' => array('type' => 'static', 'label' => qa_lang_html('users/member_type'), 'tags' => 'name="level"', 'value' => qa_html(qa_user_level_string($useraccount['level'])), 'note' => $useraccount['flags'] & QA_USER_FLAGS_USER_BLOCKED && isset($maxlevelassign) ? qa_lang_html('users/user_blocked') : '', 'id' => 'level')));
    if (empty($qa_content['form_profile']['fields']['avatar']['html'])) {
        unset($qa_content['form_profile']['fields']['avatar']);
    }
    //	Private message link
    if (qa_opt('allow_private_messages') && isset($loginuserid) && $loginuserid != $userid && !($useraccount['flags'] & QA_USER_FLAGS_NO_MESSAGES) && !$userediting) {
        $qa_content['form_profile']['fields']['level']['value'] .= strtr(qa_lang_html('profile/send_private_message'), array('^1' => '<a href="' . qa_path_html('message/' . $handle) . '">', '^2' => '</a>'));
    }
    //	Levels editing or viewing (add category-specific levels)
    if ($userediting) {
        if (isset($maxlevelassign)) {
            $qa_content['form_profile']['fields']['level']['type'] = 'select';
            $showlevels = array(QA_USER_LEVEL_BASIC);
            if (qa_opt('moderate_users')) {
                $showlevels[] = QA_USER_LEVEL_APPROVED;
            }
コード例 #29
0
function qa_default_option($name)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    $fixed_defaults = array('allow_change_usernames' => 1, 'allow_close_questions' => 1, 'allow_multi_answers' => 1, 'allow_private_messages' => 1, 'allow_self_answer' => 1, 'allow_view_q_bots' => 1, 'avatar_allow_gravatar' => 1, 'avatar_allow_upload' => 1, 'avatar_profile_size' => 200, 'avatar_q_list_size' => 0, 'avatar_q_page_a_size' => 40, 'avatar_q_page_c_size' => 20, 'avatar_q_page_q_size' => 50, 'avatar_store_size' => 400, 'avatar_users_size' => 30, 'captcha_on_anon_post' => 1, 'captcha_on_feedback' => 1, 'captcha_on_register' => 1, 'captcha_on_reset_password' => 1, 'captcha_on_unconfirmed' => 0, 'columns_tags' => 3, 'columns_users' => 2, 'comment_on_as' => 1, 'comment_on_qs' => 0, 'confirm_user_emails' => 1, 'do_ask_check_qs' => 0, 'do_complete_tags' => 1, 'do_count_q_views' => 1, 'do_example_tags' => 1, 'feed_for_activity' => 1, 'feed_for_qa' => 1, 'feed_for_questions' => 1, 'feed_for_unanswered' => 1, 'feed_full_text' => 1, 'feed_number_items' => 50, 'feed_per_category' => 1, 'feedback_enabled' => 1, 'flagging_hide_after' => 5, 'flagging_notify_every' => 2, 'flagging_notify_first' => 1, 'flagging_of_posts' => 1, 'follow_on_as' => 1, 'hot_weight_a_age' => 100, 'hot_weight_answers' => 100, 'hot_weight_q_age' => 100, 'hot_weight_views' => 100, 'hot_weight_votes' => 100, 'mailing_per_minute' => 500, 'match_ask_check_qs' => 3, 'match_example_tags' => 3, 'match_related_qs' => 3, 'max_copy_user_updates' => 10, 'max_len_q_title' => 120, 'max_num_q_tags' => 5, 'max_rate_ip_as' => 50, 'max_rate_ip_cs' => 40, 'max_rate_ip_flags' => 10, 'max_rate_ip_logins' => 20, 'max_rate_ip_messages' => 10, 'max_rate_ip_qs' => 20, 'max_rate_ip_registers' => 5, 'max_rate_ip_uploads' => 20, 'max_rate_ip_votes' => 600, 'max_rate_user_as' => 25, 'max_rate_user_cs' => 20, 'max_rate_user_flags' => 5, 'max_rate_user_messages' => 5, 'max_rate_user_qs' => 10, 'max_rate_user_uploads' => 10, 'max_rate_user_votes' => 300, 'max_store_user_updates' => 50, 'min_len_a_content' => 12, 'min_len_c_content' => 12, 'min_len_q_content' => 0, 'min_len_q_title' => 12, 'min_num_q_tags' => 0, 'moderate_notify_admin' => 1, 'moderate_points_limit' => 150, 'nav_ask' => 1, 'nav_qa_not_home' => 1, 'nav_questions' => 1, 'nav_tags' => 1, 'nav_unanswered' => 1, 'nav_users' => 1, 'neat_urls' => QA_URL_FORMAT_SAFEST, 'notify_users_default' => 1, 'page_size_activity' => 20, 'page_size_ask_check_qs' => 5, 'page_size_ask_tags' => 5, 'page_size_home' => 20, 'page_size_hot_qs' => 20, 'page_size_q_as' => 10, 'page_size_qs' => 20, 'page_size_related_qs' => 5, 'page_size_search' => 10, 'page_size_tag_qs' => 20, 'page_size_tags' => 30, 'page_size_una_qs' => 20, 'page_size_user_posts' => 20, 'page_size_users' => 20, 'pages_prev_next' => 3, 'permit_anon_view_ips' => QA_PERMIT_EDITORS, 'permit_close_q' => QA_PERMIT_EDITORS, 'permit_delete_hidden' => QA_PERMIT_MODERATORS, 'permit_edit_a' => QA_PERMIT_EXPERTS, 'permit_edit_c' => QA_PERMIT_EDITORS, 'permit_edit_q' => QA_PERMIT_EDITORS, 'permit_flag' => QA_PERMIT_CONFIRMED, 'permit_hide_show' => QA_PERMIT_EDITORS, 'permit_moderate' => QA_PERMIT_EXPERTS, 'permit_select_a' => QA_PERMIT_EXPERTS, 'permit_view_q_page' => QA_PERMIT_ALL, 'permit_vote_a' => QA_PERMIT_USERS, 'permit_vote_down' => QA_PERMIT_USERS, 'permit_vote_q' => QA_PERMIT_USERS, 'points_a_selected' => 30, 'points_a_voted_max_gain' => 20, 'points_a_voted_max_loss' => 5, 'points_base' => 100, 'points_multiple' => 10, 'points_post_a' => 4, 'points_post_q' => 2, 'points_q_voted_max_gain' => 10, 'points_q_voted_max_loss' => 3, 'points_select_a' => 3, 'q_urls_title_length' => 50, 'show_a_c_links' => 1, 'show_a_form_immediate' => 'if_no_as', 'show_c_reply_buttons' => 1, 'show_custom_welcome' => 1, 'show_fewer_cs_count' => 5, 'show_fewer_cs_from' => 10, 'show_full_date_days' => 7, 'show_message_history' => 1, 'show_selected_first' => 1, 'show_url_links' => 1, 'show_user_points' => 1, 'show_user_titles' => 1, 'show_when_created' => 1, 'site_theme' => 'Snow', 'smtp_port' => 25, 'sort_answers_by' => 'created', 'tags_or_categories' => 'tc', 'voting_on_as' => 1, 'voting_on_qs' => 1);
    if (isset($fixed_defaults[$name])) {
        $value = $fixed_defaults[$name];
    } else {
        switch ($name) {
            case 'site_url':
                $value = 'http://' . @$_SERVER['HTTP_HOST'] . strtr(dirname($_SERVER['SCRIPT_NAME']), '\\', '/') . '/';
                break;
            case 'site_title':
                $value = qa_default_site_title();
                break;
            case 'site_theme_mobile':
                $value = qa_opt('site_theme');
                break;
            case 'from_email':
                // heuristic to remove short prefix (e.g. www. or qa.)
                $parts = explode('.', @$_SERVER['HTTP_HOST']);
                if (count($parts) > 2 && strlen($parts[0]) < 5 && !is_numeric($parts[0])) {
                    unset($parts[0]);
                }
                $value = 'no-reply@' . (count($parts) > 1 ? implode('.', $parts) : 'example.com');
                break;
            case 'email_privacy':
                $value = qa_lang_html('options/default_privacy');
                break;
            case 'show_custom_sidebar':
                $value = strlen(qa_opt('custom_sidebar')) ? true : false;
                break;
            case 'show_custom_header':
                $value = strlen(qa_opt('custom_header')) ? true : false;
                break;
            case 'show_custom_footer':
                $value = strlen(qa_opt('custom_footer')) ? true : false;
                break;
            case 'show_custom_in_head':
                $value = strlen(qa_opt('custom_in_head')) ? true : false;
                break;
            case 'custom_sidebar':
                $value = qa_lang_html_sub('options/default_sidebar', qa_html(qa_opt('site_title')));
                break;
            case 'editor_for_qs':
            case 'editor_for_as':
                require_once QA_INCLUDE_DIR . 'qa-app-format.php';
                $value = '-';
                // to match none by default, i.e. choose based on who is best at editing HTML
                qa_load_editor('', 'html', $value);
                break;
            case 'permit_post_q':
                // convert from deprecated option if available
                $value = qa_opt('ask_needs_login') ? QA_PERMIT_USERS : QA_PERMIT_ALL;
                break;
            case 'permit_post_a':
                // convert from deprecated option if available
                $value = qa_opt('answer_needs_login') ? QA_PERMIT_USERS : QA_PERMIT_ALL;
                break;
            case 'permit_post_c':
                // convert from deprecated option if available
                $value = qa_opt('comment_needs_login') ? QA_PERMIT_USERS : QA_PERMIT_ALL;
                break;
            case 'permit_retag_cat':
                // convert from previous option that used to contain it too
                $value = qa_opt('permit_edit_q');
                break;
            case 'points_vote_up_q':
            case 'points_vote_down_q':
                $oldvalue = qa_opt('points_vote_on_q');
                $value = is_numeric($oldvalue) ? $oldvalue : 1;
                break;
            case 'points_vote_up_a':
            case 'points_vote_down_a':
                $oldvalue = qa_opt('points_vote_on_a');
                $value = is_numeric($oldvalue) ? $oldvalue : 1;
                break;
            case 'points_per_q_voted_up':
            case 'points_per_q_voted_down':
                $oldvalue = qa_opt('points_per_q_voted');
                $value = is_numeric($oldvalue) ? $oldvalue : 1;
                break;
            case 'points_per_a_voted_up':
            case 'points_per_a_voted_down':
                $oldvalue = qa_opt('points_per_a_voted');
                $value = is_numeric($oldvalue) ? $oldvalue : 2;
                break;
            case 'captcha_module':
                $captchamodules = qa_list_modules('captcha');
                if (count($captchamodules)) {
                    $value = reset($captchamodules);
                } else {
                    $value = '';
                }
                break;
            case 'mailing_from_name':
                $value = qa_opt('site_title');
                break;
            case 'mailing_from_email':
                $value = qa_opt('from_email');
                break;
            case 'mailing_subject':
                $value = qa_lang_sub('options/default_subject', qa_opt('site_title'));
                break;
            case 'mailing_body':
                $value = "\n\n\n--\n" . qa_opt('site_title') . "\n" . qa_opt('site_url');
                break;
            default:
                // call option_default method in any registered modules
                $moduletypes = qa_list_module_types();
                foreach ($moduletypes as $moduletype) {
                    $modules = qa_load_modules_with($moduletype, 'option_default');
                    foreach ($modules as $module) {
                        $value = $module->option_default($name);
                        if (strlen($value)) {
                            return $value;
                        }
                    }
                }
                $value = '';
                break;
        }
    }
    return $value;
}
コード例 #30
0
function qa_news_plugin_createNewsletter($send)
{
    $news = qa_opt('news_plugin_template');
    // static replacements
    $news = str_replace('[css]', qa_opt('news_plugin_css'), $news);
    $lastdate = time() - qa_opt('news_plugin_send_days') * 24 * 60 * 60;
    if (qa_opt('news_plugin_max_q') > 0) {
        $selectspec = "SELECT postid, BINARY title AS title, BINARY content AS content, format, netvotes, userid FROM ^posts WHERE type='Q' AND FROM_UNIXTIME(#) <= created AND netvotes > 0 ORDER BY netvotes DESC, created ASC LIMIT " . (int) qa_opt('news_plugin_max_q');
        $sub = qa_db_query_sub($selectspec, $lastdate);
        while (($post = qa_db_read_one_assoc($sub, true)) !== null) {
            $qcontent = '';
            if (!empty($post['content'])) {
                $viewer = qa_load_viewer($post['content'], $post['format']);
                $content = $viewer->get_html($post['content'], $post['format'], array());
            }
            $one = str_replace('[question-title]', $post['title'], qa_opt('news_plugin_template_question'));
            $one = str_replace('[anchor]', 'question' . $post['postid'], $one);
            $one = str_replace('[url]', qa_html(qa_q_request($post['postid'], $post['title'])), $one);
            $one = str_replace('[question]', $content, $one);
            $votes = str_replace('[number]', ($post['netvotes'] > 0 ? '+' : ($post['netvotes'] < 0 ? '-' : '')) . $post['netvotes'], qa_opt('news_plugin_template_votes'));
            $one = str_replace('[voting]', $votes, $one);
            $uid = $post['userid'];
            $handles = qa_userids_to_handles(array($uid));
            $handle = $handles[$uid];
            $one = str_replace('[meta]', qa_lang_sub('newsletter/meta', '<a href="' . qa_opt('site_url') . 'user/' . $handle . '">' . $handle . '</a>'), $one);
            $qhtml[] = $one;
        }
    }
    if (qa_opt('news_plugin_max_a') > 0) {
        $selectspec = "SELECT a.postid AS postid, a.parentid AS parentid, BINARY a.content AS content, a.format AS format, a.netvotes AS netvotes, a.userid as userid, q.title AS qtitle FROM ^posts AS q, ^posts AS a WHERE a.type='A' AND q.postid=a.parentid AND FROM_UNIXTIME(#) <= a.created AND a.netvotes > 0 ORDER BY a.netvotes DESC, a.created ASC LIMIT " . (int) qa_opt('news_plugin_max_a');
        $sub = qa_db_query_sub($selectspec, $lastdate);
        while (($post = qa_db_read_one_assoc($sub, true)) !== null) {
            $content = '';
            if (!empty($post['content'])) {
                $viewer = qa_load_viewer($post['content'], $post['format']);
                $content = $viewer->get_html($post['content'], $post['format'], array());
            }
            $anchor = qa_anchor('C', $post['postid']);
            $purl = qa_path_html(qa_q_request($post['parentid'], $post['qtitle']), null, qa_opt('site_url'));
            $url = qa_path_html(qa_q_request($post['parentid'], $post['qtitle']), null, qa_opt('site_url'), null, $anchor);
            $response = qa_lang_sub('newsletter/response_to_question', '<a href="' . $purl . '">' . $post['qtitle'] . '</a>');
            $response = str_replace('[url]', $url, $response);
            $one = str_replace('[parent-ref]', $response, qa_opt('news_plugin_template_answer'));
            $one = str_replace('[anchor]', 'answer' . $post['postid'], $one);
            $one = str_replace('[answer]', $content, $one);
            $votes = str_replace('[number]', ($post['netvotes'] > 0 ? '+' : ($post['netvotes'] < 0 ? '-' : '')) . $post['netvotes'], qa_opt('news_plugin_template_votes'));
            $one = str_replace('[voting]', $votes, $one);
            $uid = $post['userid'];
            $handles = qa_userids_to_handles(array($uid));
            $handle = $handles[$uid];
            $one = str_replace('[meta]', qa_lang_sub('newsletter/meta', '<a href="' . qa_opt('site_url') . 'user/' . $handle . '">' . $handle . '</a>'), $one);
            $ahtml[] = $one;
        }
    }
    if (qa_opt('news_plugin_max_c') > 0) {
        $selectspec = "SELECT c.postid AS postid, c.parentid AS parentid, BINARY c.content AS content, c.format AS format, c.netvotes AS netvotes, c.userid as userid, p.title AS ptitle, p.parentid AS gpostid, g.title AS gtitle FROM ^posts AS c INNER JOIN ^posts AS p ON c.type='C' AND p.postid=c.parentid AND FROM_UNIXTIME(#) <= c.created LEFT JOIN ^posts AS g ON g.postid=p.parentid AND g.type='Q' AND c.netvotes > 0 ORDER BY c.netvotes DESC, c.created ASC LIMIT " . (int) qa_opt('news_plugin_max_a');
        $sub = qa_db_query_sub($selectspec, $lastdate);
        while (($post = qa_db_read_one_assoc($sub, true)) !== null) {
            $content = '';
            if (!empty($post['content'])) {
                $viewer = qa_load_viewer($post['content'], $post['format']);
                $content = $viewer->get_html($post['content'], $post['format'], array());
            }
            if (isset($post['gtitle'])) {
                $parent = 'answer';
                $title = $post['gtitle'];
                $parentid = $post['gpostid'];
                $aurl = qa_path_html(qa_q_request($post['parentid'], $title), null, qa_opt('site_url'), null, qa_anchor('A', $post['parentid']));
            } else {
                $parent = 'question';
                $title = $post['ptitle'];
                $parentid = $post['parentid'];
            }
            $anchor = qa_anchor('C', $post['postid']);
            $purl = qa_path_html(qa_q_request($parentid, $title), null, qa_opt('site_url'));
            $url = qa_path_html(qa_q_request($parentid, $title), null, qa_opt('site_url'), null, $anchor);
            $response = qa_lang_sub('newsletter/response_to_' . $parent, '<a href="' . $purl . '">' . $title . '</a>');
            $response = str_replace('[url]', $url, $response);
            if (isset($aurl)) {
                $response = str_replace('[aurl]', $aurl, $response);
            }
            $one = str_replace('[parent-ref]', $response, qa_opt('news_plugin_template_comment'));
            $one = str_replace('[anchor]', 'comment' . $post['postid'], $one);
            $one = str_replace('[comment]', $content, $one);
            $votes = str_replace('[number]', ($post['netvotes'] > 0 ? '+' : ($post['netvotes'] < 0 ? '-' : '')) . $post['netvotes'], qa_opt('news_plugin_template_votes'));
            $one = str_replace('[voting]', $votes, $one);
            $uid = $post['userid'];
            $handles = qa_userids_to_handles(array($uid));
            $handle = $handles[$uid];
            $one = str_replace('[meta]', qa_lang_sub('newsletter/meta', '<a href="' . qa_opt('site_url') . 'user/' . $handle . '">' . $handle . '</a>'), $one);
            $chtml[] = $one;
        }
    }
    $news = str_replace('[questions]', implode('<hr class="inner">', $qhtml), $news);
    $news = str_replace('[answers]', implode('<hr class="inner">', $ahtml), $news);
    $news = str_replace('[comments]', implode('<hr class="inner">', $chtml), $news);
    // misc subs
    $news = str_replace('[intro]', qa_lang('newsletter/intro'), $news);
    $news = str_replace('[footer]', qa_lang('newsletter/footer'), $news);
    $news = str_replace('[site-title]', qa_opt('site_title'), $news);
    $news = str_replace('[site-url]', qa_opt('site_url'), $news);
    $news = str_replace('[last-date]', date('M j, Y', $lastdate), $news);
    $news = str_replace('[date]', date('M j, Y'), $news);
    $news = str_replace('[days]', qa_opt('news_plugin_send_days'), $news);
    $news = str_replace('[profile-url]', qa_path('my-profile'), $news);
    error_log('Q2A Newsletter Created on ' . date('M j, Y \\a\\t H\\:i\\:s'));
    file_put_contents(qa_opt('news_plugin_loc'), $news);
    if (qa_opt('news_plugin_pdf')) {
        qa_news_plugin_create_pdf();
    }
    if ($send) {
        qa_news_plugin_send_newsletter($news);
        qa_opt('news_plugin_send_last', time());
        return 'Newsletter Sent';
    }
    return 'Newsletter Created';
    //return 'Error creating '.qa_opt('news_plugin_loc').'; check the error log.';
}