Пример #1
0
 public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     require_once QA_INCLUDE_DIR . 'db/selects.php';
     $populartags = qa_db_single_select(qa_db_popular_tags_selectspec(0, (int) qa_opt('tag_cloud_count_tags')));
     $maxcount = reset($populartags);
     // $themeobject->output(sprintf('<h2 style="margin-top: 0; padding-top: 0;">%s</h2>', qa_lang_html('main/popular_tags')));
     // $themeobject->output('<div style="font-size: 10px;">');
     $themeobject->output(sprintf('<div class="panel panel-primary" style="padding: 0;"><div class="panel-heading"><h3 class="panel-title">%s</h3></div>', qa_lang_html('main/popular_tags')));
     $themeobject->output('<div class="panel-body">');
     $maxsize = qa_opt('tag_cloud_font_size');
     $minsize = qa_opt('tag_cloud_minimal_font_size');
     $scale = qa_opt('tag_cloud_size_popular');
     $blockwordspreg = qa_get_block_words_preg();
     foreach ($populartags as $tag => $count) {
         $matches = qa_block_words_match_all($tag, $blockwordspreg);
         if (empty($matches)) {
             if ($scale) {
                 $size = number_format($maxsize * $count / $maxcount, 1);
                 if ($size < $minsize) {
                     $size = $minsize;
                 }
             } else {
                 $size = $maxsize;
             }
             $themeobject->output(sprintf('<a href="%s" style="font-size: %dpx; vertical-align: baseline;">%s</a>', qa_path_html('tag/' . $tag), $size, qa_html($tag)));
         }
     }
     // $themeobject->output('</div>');
     $themeobject->output('</div></div>');
 }
 function q_list_item($q_item)
 {
     $userid = qa_get_logged_in_userid();
     if (qa_opt('obvious_content_on') && $userid) {
         require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
         $fav_tags = qa_db_single_select(qa_db_user_favorite_tags_selectspec($userid));
         foreach ($fav_tags as $k => $v) {
             $tag[$k] = $v['word'];
         }
         $post_tags = explode(",", $q_item['raw']['tags']);
         $result = array_diff($tag, $post_tags);
         if (sizeof($result) != sizeof($tag) && $tag) {
             @($q_item['classes'] .= " is_favorite");
         }
     }
     if (qa_opt('obvious_content_category_on') && $userid) {
         require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
         $fav_cats = qa_db_single_select(qa_db_user_favorite_categories_selectspec($userid));
         foreach ($fav_cats as $k => $v) {
             $cat[$k] = $v['word'];
         }
         $post_cat = explode(",", $q_item['raw']['category']);
         $result = array_diff($cat, $post_cat);
         if (sizeof($result) != sizeof($cat) && $cat) {
             @($q_item['classes'] .= " is_favorite_cat");
         }
     }
     qa_html_theme_base::q_list_item($q_item);
     // call back through to the default function
 }
Пример #3
0
function qa_priv_notification($uid, $oid, $badge_slug)
{
    require_once QA_INCLUDE_DIR . 'qa-app-users.php';
    require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
    if (QA_FINAL_EXTERNAL_USERS) {
        $publictohandle = qa_get_public_from_userids(array($uid));
        $handle = @$publictohandle[$uid];
    } else {
        $user = qa_db_single_select(qa_db_user_account_selectspec($uid, true));
        $handle = @$user['handle'];
    }
    $subject = qa_opt('badge_email_subject');
    $body = qa_opt('badge_email_body');
    $body = preg_replace('/\\^if_post_text="([^"]*)"/', $oid ? '$1' : '', $body);
    // if post text
    $site_url = qa_opt('site_url');
    $profile_url = qa_path_html('user/' . $handle, null, $site_url);
    if ($oid) {
        $post = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $oid), true);
        if ($post['parentid']) {
            $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $post['parentid']), true);
        }
        if (isset($parent)) {
            $anchor = urlencode(qa_anchor($post['basetype'], $oid));
            $post_title = $parent['title'];
            $post_url = qa_path_html(qa_q_request($parent['postid'], $parent['title']), null, qa_opt('site_url'), null, $anchor);
        } else {
            $post_title = $post['title'];
            $post_url = qa_path_html(qa_q_request($post['postid'], $post['title']), null, qa_opt('site_url'));
        }
    }
    $subs = array('^badge_name' => qa_opt('badge_' . $badge_slug . '_name'), '^post_title' => @$post_title, '^post_url' => @$post_url, '^profile_url' => $profile_url, '^site_url' => $site_url);
    qa_send_notification($uid, '@', $handle, $subject, $body, $subs);
}
Пример #4
0
 function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
     $populartags = qa_db_single_select(array('columns' => array('word' => 'BINARY word', 'tagcount'), 'source' => '^words JOIN (SELECT wordid FROM ^words WHERE tagcount>=# ORDER BY tagcount DESC LIMIT #,#) y ON ^words.wordid=y.wordid', 'arguments' => array((int) qa_opt('log_tag_cloud_min_count'), 0, (int) qa_opt('log_tag_cloud_count_tags')), 'arraykey' => 'word', 'arrayvalue' => 'tagcount', 'sortdesc' => 'tagcount'));
     if (empty($populartags)) {
         return false;
     }
     $maxsize = (int) qa_opt('log_tag_cloud_font_size');
     $minsize = (int) qa_opt('log_tag_cloud_min_font_size');
     $scale = qa_opt('log_tag_cloud_size_popular');
     if ($scale) {
         // convert from linear to log
         $populartags = $this->FromParetoCurve($populartags, $minsize, $maxsize);
     }
     if (qa_opt('log_tag_cloud_sort_type') == 'alphabetical') {
         // sort alphabetical
         ksort($populartags);
     }
     if (qa_opt('log_tag_cloud_header') != '') {
         $themeobject->output('<DIV CLASS="qa-nav-cat-list qa-nav-cat-link" STYLE="margin:0;">', qa_opt('log_tag_cloud_header'), '</DIV>');
     }
     $themeobject->output('<DIV STYLE="font-size:10px;">');
     foreach ($populartags as $tag => $count) {
         $size = number_format($scale ? $count : $maxsize, 1);
         $themeobject->output('<A HREF="' . qa_path_html('tag/' . $tag) . '" STYLE="font-size:' . $size . 'px; vertical-align:baseline;">' . qa_html($tag) . '</A>');
     }
     $themeobject->output('</DIV>');
 }
Пример #5
0
function qa_create_event_for_category($categoryid, $questionid, $updatetype, $lastuserid, $timestamp = null)
{
    if (isset($categoryid)) {
        require_once QA_INCLUDE_DIR . 'db/selects.php';
        require_once QA_INCLUDE_DIR . 'app/format.php';
        $categories = qa_category_path(qa_db_single_select(qa_db_category_nav_selectspec($categoryid, true)), $categoryid);
        foreach ($categories as $category) {
            qa_db_event_create_for_entity(QA_ENTITY_CATEGORY, $category['categoryid'], $questionid, $questionid, $updatetype, $lastuserid, $timestamp);
        }
    }
}
 function getHandleFromId($userid)
 {
     require_once QA_INCLUDE_DIR . 'qa-app-users.php';
     if (QA_FINAL_EXTERNAL_USERS) {
         $publictohandle = qa_get_public_from_userids(array($userid));
         $handle = @$publictohandle[$userid];
     } else {
         $user = qa_db_single_select(qa_db_user_account_selectspec($userid, true));
         $handle = @$user['handle'];
     }
     return $handle;
 }
 function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
     $favoritetags = qa_db_single_select(qa_db_user_favorite_tags_selectspec(qa_get_logged_in_userid()));
     $themeobject->output('<span class="qa-nav-cat-list qa-nav-cat-link">Favorite Tags</span><br>');
     foreach ($favoritetags as $k => $v) {
         if ($k == qa_opt('obvious_max_tags')) {
             break;
         }
         $tag = $v['word'];
         $count = $v['tagcount'];
         $question = $count > 1 ? 'questions' : 'question';
         $themeobject->output('<a href="' . qa_path_html('tag/' . $tag) . '" class="qa-tag-link" title="Tagged in ' . $count . ' ' . $question . '">' . qa_html($tag) . '</a>');
     }
 }
Пример #8
0
 function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
     $populartags = qa_db_single_select(qa_db_popular_tags_selectspec(0, (int) qa_opt('tag_cloud_count_tags')));
     reset($populartags);
     $maxcount = current($populartags);
     $themeobject->output('<H2 STYLE="margin-top:0; padding-top:0;">', qa_lang_html('main/popular_tags'), '</H2>');
     $themeobject->output('<DIV STYLE="font-size:10px;">');
     $maxsize = qa_opt('tag_cloud_font_size');
     $scale = qa_opt('tag_cloud_size_popular');
     foreach ($populartags as $tag => $count) {
         $size = number_format($scale ? $maxsize * $count / $maxcount : $maxsize, 1);
         if ($size >= 5 || !$scale) {
             $themeobject->output('<A HREF="' . qa_path_html('tag/' . $tag) . '" STYLE="font-size:' . $size . 'px; vertical-align:baseline;">' . qa_html($tag) . '</A>');
         }
     }
     $themeobject->output('</DIV>');
 }
 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>');
 }
Пример #10
0
 function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
     $widget_opt = @$themeobject->current_widget['param']['options'];
     if (@$themeobject->current_widget['param']['locations']['show_title']) {
         $themeobject->output('<h3 class="widget-title">' . qa_lang('cleanstrap/tags') . '<a href="' . qa_path_html('tags') . '">' . qa_lang('cleanstrap/view_all') . '</a></h3>');
     }
     $to_show = (int) $widget_opt['cs_tags_count'];
     $populartags = qa_db_single_select(qa_db_popular_tags_selectspec(0, !empty($to_show) ? $to_show : 20));
     reset($populartags);
     $themeobject->output('<div class="ra-tags-widget clearfix">');
     $blockwordspreg = qa_get_block_words_preg();
     foreach ($populartags as $tag => $count) {
         if (count(qa_block_words_match_all($tag, $blockwordspreg))) {
             continue;
         }
         // skip censored tags
         $themeobject->output('<a href="' . qa_path_html('tag/' . $tag) . '" class="widget-tag">' . qa_html($tag) . '<span>' . $count . '</span></a>');
     }
     $themeobject->output('</div>');
 }
 function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
     $populartags = qa_db_single_select(qa_db_popular_tags_selectspec(0, (int) qa_opt('tag_cloud_count_tags')));
     reset($populartags);
     $maxcount = current($populartags);
     $themeobject->output('<h2 style="margin-top:0; padding-top:0;">', qa_lang_html('main/popular_tags'), '</h2>');
     $themeobject->output('<div style="font-size:10px;">');
     $maxsize = qa_opt('tag_cloud_font_size');
     $scale = qa_opt('tag_cloud_size_popular');
     $blockwordspreg = qa_get_block_words_preg();
     foreach ($populartags as $tag => $count) {
         if (count(qa_block_words_match_all($tag, $blockwordspreg))) {
             continue;
         }
         // skip censored tags
         $size = number_format($scale ? $maxsize * $count / $maxcount : $maxsize, 1);
         if ($size >= 5 || !$scale) {
             $themeobject->output('<a href="' . qa_path_html('tag/' . $tag) . '" style="font-size:' . $size . 'px; vertical-align:baseline;">' . qa_html($tag) . '</a>');
         }
     }
     $themeobject->output('</div>');
 }
Пример #12
0
 function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     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, qa_opt('page_size_related_qs')));
     $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 ($region == 'side') {
         $themeobject->output('<DIV CLASS="qa-related-qs">', '<H2 STYLE="margin-top:0; padding-top:0;">', $titlehtml, '</H2>');
         $themeobject->output('<UL CLASS="qa-related-q-list">');
         foreach ($questions as $question) {
             $themeobject->output('<LI CLASS="qa-related-q-item"><A HREF="' . qa_q_path_html($question['postid'], $question['title']) . '">' . qa_html($question['title']) . '</A></LI>');
         }
         $themeobject->output('</UL>', '</DIV>');
     } else {
         $themeobject->output('<H2>', $titlehtml, '</H2>');
         $q_list = array('form' => array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"'), 'qs' => array());
         $options = qa_post_html_defaults('Q');
         $usershtml = qa_userids_handles_html($questions);
         foreach ($questions as $question) {
             $q_list['qs'][] = qa_post_html_fields($question, $userid, $cookieid, $usershtml, null, $options);
         }
         $themeobject->q_list_and_form($q_list);
     }
 }
Пример #13
0
 public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     require_once QA_INCLUDE_DIR . 'db/selects.php';
     if (!isset($qa_content['q_view']['raw']['type']) || $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, qa_opt('page_size_related_qs')));
     $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 ($region == 'side') {
         $themeobject->output('<div class="qa-related-qs">', '<h2 style="margin-top:0; padding-top:0;">', $titlehtml, '</h2>');
         $themeobject->output('<ul class="qa-related-q-list">');
         foreach ($questions as $question) {
             $themeobject->output('<li class="qa-related-q-item">' . '<a href="' . qa_q_path_html($question['postid'], $question['title']) . '">' . qa_html($question['title']) . '</a>' . '</li>');
         }
         $themeobject->output('</ul>', '</div>');
     } else {
         $themeobject->output('<h2>', $titlehtml, '</h2>');
         $q_list = array('form' => array('tags' => 'method="post" action="' . qa_self_html() . '"', 'hidden' => array('code' => qa_get_form_security_code('vote'))), 'qs' => array());
         $defaults = qa_post_html_defaults('Q');
         $usershtml = qa_userids_handles_html($questions);
         foreach ($questions as $question) {
             $q_list['qs'][] = qa_post_html_fields($question, $userid, $cookieid, $usershtml, null, qa_post_html_options($question, $defaults));
         }
         $themeobject->q_list_and_form($q_list);
     }
 }
function qa_comment_set_status($oldcomment, $status, $userid, $handle, $cookieid, $question, $parent)
{
    require_once QA_INCLUDE_DIR . 'qa-app-format.php';
    if (!isset($parent)) {
        $parent = $question;
    }
    // for backwards compatibility with old answer parameter
    $washidden = $oldcomment['type'] == 'C_HIDDEN';
    $wasqueued = $oldcomment['type'] == 'C_QUEUED';
    $wasrequeued = $wasqueued && isset($oldcomment['updated']);
    qa_post_unindex($oldcomment['postid']);
    $setupdated = false;
    $event = null;
    if ($status == QA_POST_STATUS_QUEUED) {
        $newtype = 'C_QUEUED';
        if (!$wasqueued) {
            $event = 'c_requeue';
        }
        // same event whether it was hidden or shown before
    } elseif ($status == QA_POST_STATUS_HIDDEN) {
        $newtype = 'C_HIDDEN';
        if (!$washidden) {
            $event = $wasqueued ? 'c_reject' : 'c_hide';
            if (!$wasqueued) {
                $setupdated = true;
            }
        }
    } elseif ($status == QA_POST_STATUS_NORMAL) {
        $newtype = 'C';
        if ($wasqueued) {
            $event = 'c_approve';
        } elseif ($washidden) {
            $event = 'c_reshow';
            $setupdated = true;
        }
    } else {
        qa_fatal_error('Unknown status in qa_comment_set_status(): ' . $status);
    }
    qa_db_post_set_type($oldcomment['postid'], $newtype, $setupdated ? $userid : null, $setupdated ? qa_remote_ip_address() : null, QA_UPDATE_VISIBLE);
    if ($wasqueued && $status == QA_POST_STATUS_NORMAL && qa_opt('moderate_update_time')) {
        // ... for approval of a post, can set time to now instead
        if ($wasrequeued) {
            qa_db_post_set_updated($oldcomment['postid'], null);
        } else {
            qa_db_post_set_created($oldcomment['postid'], null);
        }
    }
    qa_db_ccount_update();
    qa_db_points_update_ifuser($oldcomment['userid'], array('cposts'));
    if ($wasqueued || $status == QA_POST_STATUS_QUEUED) {
        qa_db_queuedcount_update();
    }
    if ($oldcomment['flagcount']) {
        qa_db_flaggedcount_update();
    }
    if ($question['type'] == 'Q' && ($parent['type'] == 'Q' || $parent['type'] == 'A') && $status == QA_POST_STATUS_NORMAL) {
        // only index if none of the things it depends on are hidden or queued
        qa_post_index($oldcomment['postid'], 'C', $question['postid'], $oldcomment['parentid'], null, $oldcomment['content'], $oldcomment['format'], qa_viewer_text($oldcomment['content'], $oldcomment['format']), null, $oldcomment['categoryid']);
    }
    $eventparams = array('postid' => $oldcomment['postid'], 'parentid' => $oldcomment['parentid'], 'parenttype' => $parent['basetype'], 'parent' => $parent, 'questionid' => $question['postid'], 'question' => $question, 'content' => $oldcomment['content'], 'format' => $oldcomment['format'], 'text' => qa_viewer_text($oldcomment['content'], $oldcomment['format']), 'categoryid' => $oldcomment['categoryid'], 'name' => $oldcomment['name']);
    if (isset($event)) {
        qa_report_event($event, $userid, $handle, $cookieid, $eventparams + array('oldcomment' => $oldcomment));
    }
    if ($wasqueued && $status == QA_POST_STATUS_NORMAL && !$wasrequeued) {
        require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
        require_once QA_INCLUDE_DIR . 'qa-util-string.php';
        $commentsfollows = qa_db_single_select(qa_db_full_child_posts_selectspec(null, $oldcomment['parentid']));
        $thread = array();
        foreach ($commentsfollows as $comment) {
            if ($comment['type'] == 'C' && $comment['parentid'] == $parent['postid']) {
                $thread[] = $comment;
            }
        }
        qa_report_event('c_post', $oldcomment['userid'], $oldcomment['handle'], $oldcomment['cookieid'], $eventparams + array('thread' => $thread, 'notify' => isset($oldcomment['notify']), 'email' => qa_email_validate($oldcomment['notify']) ? $oldcomment['notify'] : null, 'delayed' => $oldcomment['created']));
    }
}
Пример #15
0
function cs_tag_list($limit = 20)
{
    $populartags = qa_db_single_select(qa_db_popular_tags_selectspec(0, $limit));
    $i = 1;
    foreach ($populartags as $tag => $count) {
        echo '<li><a class="icon-tag" href="' . qa_path_html('tag/' . $tag) . '">' . qa_html($tag) . '<span>' . filter_var($count, FILTER_SANITIZE_NUMBER_INT) . '</span></a></li>';
    }
}
Пример #16
0
function qa_post_get_answer_commentsfollows($answerid)
{
    $commentsfollows = array();
    $childposts = qa_db_single_select(qa_db_full_child_posts_selectspec(null, $answerid));
    foreach ($childposts as $postid => $post) {
        if ($post['basetype'] == 'Q' || $post['basetype'] == 'C') {
            $commentsfollows[$postid] = $post;
        }
    }
    return $commentsfollows;
}
     $listhtml = '';
     $widgetmodules = qa_load_modules_with('widget', 'allow_template');
     foreach ($widgetmodules as $tryname => $trywidget) {
         if (method_exists($trywidget, 'allow_region')) {
             $listhtml .= '<li><b>' . qa_html($tryname) . '</b>';
             $listhtml .= strtr(qa_lang_html('admin/add_widget_link'), array('^1' => '<a href="' . qa_path_html('admin/layoutwidgets', array('title' => $tryname)) . '">', '^2' => '</a>'));
             if (method_exists($trywidget, 'admin_form')) {
                 $listhtml .= strtr(qa_lang_html('admin/widget_global_options'), array('^1' => '<a href="' . qa_admin_module_options_path('widget', $tryname) . '">', '^2' => '</a>'));
             }
             $listhtml .= '</li>';
         }
     }
     if (strlen($listhtml)) {
         $qa_content['form']['fields']['plugins'] = array('label' => qa_lang_html('admin/widgets_explanation'), 'style' => 'tall', 'type' => 'custom', 'html' => '<ul style="margin-bottom:0;">' . $listhtml . '</ul>');
     }
     $widgets = qa_db_single_select(qa_db_widgets_selectspec());
     $listhtml = '';
     $placeoptions = qa_admin_place_options();
     foreach ($widgets as $widget) {
         $listhtml .= '<li><b>' . qa_html($widget['title']) . '</b> - ' . '<a href="' . qa_path_html('admin/layoutwidgets', array('edit' => $widget['widgetid'])) . '">' . @$placeoptions[$widget['place']] . '</a>';
         $listhtml .= '</li>';
     }
     if (strlen($listhtml)) {
         $qa_content['form']['fields']['widgets'] = array('label' => qa_lang_html('admin/active_widgets_explanation'), 'type' => 'custom', 'html' => '<ul style="margin-bottom:0;">' . $listhtml . '</ul>');
     }
     break;
 case 'permissions':
     $qa_content['form']['fields']['permit_block'] = array('type' => 'static', 'label' => qa_lang_html('options/permit_block'), 'value' => qa_lang_html('options/permit_moderators'));
     if (!QA_FINAL_EXTERNAL_USERS) {
         $qa_content['form']['fields']['permit_approve_users'] = array('type' => 'static', 'label' => qa_lang_html('options/permit_approve_users'), 'value' => qa_lang_html('options/permit_moderators'));
         $qa_content['form']['fields']['permit_create_experts'] = array('type' => 'static', 'label' => qa_lang_html('options/permit_create_experts'), 'value' => qa_lang_html('options/permit_moderators'));
Пример #18
0
         $inslug = qa_post_text('slug');
         if (!isset($inslug)) {
             $inslug = implode('-', qa_string_to_words($inname));
         }
         break;
     case 1:
         $inslug = qa_lang_sub('admin/category_default_slug', $inslug);
         break;
     default:
         $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)) {
Пример #19
0
function qa_recalc_perform_step(&$state)
{
    $continue = false;
    @(list($operation, $length, $next, $done) = explode(',', $state));
    switch ($operation) {
        case 'doreindexposts':
            qa_recalc_transition($state, 'doreindexposts_postcount');
            break;
        case 'doreindexposts_postcount':
            qa_db_qcount_update();
            qa_db_acount_update();
            qa_db_ccount_update();
            qa_recalc_transition($state, 'doreindexposts_reindex');
            break;
        case 'doreindexposts_reindex':
            $posts = qa_db_posts_get_for_reindexing($next, 10);
            if (count($posts)) {
                require_once QA_INCLUDE_DIR . 'qa-app-format.php';
                $lastpostid = max(array_keys($posts));
                qa_db_prepare_for_reindexing($next, $lastpostid);
                foreach ($posts as $postid => $post) {
                    qa_post_index($postid, $post['type'], $post['questionid'], $post['title'], qa_viewer_text($post['content'], $post['format']), $post['tags'], true);
                }
                $next = 1 + $lastpostid;
                $done += count($posts);
                $continue = true;
            } else {
                qa_db_truncate_indexes($next);
                qa_recalc_transition($state, 'doreindexposts_wordcount');
            }
            break;
        case 'doreindexposts_wordcount':
            $wordids = qa_db_words_prepare_for_recounting($next, 1000);
            if (count($wordids)) {
                $lastwordid = max($wordids);
                qa_db_words_recount($next, $lastwordid);
                $next = 1 + $lastwordid;
                $done += count($wordids);
                $continue = true;
            } else {
                qa_db_tagcount_update();
                // this is quick so just do it here
                qa_recalc_transition($state, 'doreindexposts_complete');
            }
            break;
        case 'dorecountposts':
            qa_recalc_transition($state, 'dorecountposts_postcount');
            break;
        case 'dorecountposts_postcount':
            qa_db_qcount_update();
            qa_db_acount_update();
            qa_db_ccount_update();
            qa_db_unaqcount_update();
            qa_recalc_transition($state, 'dorecountposts_recount');
            break;
        case 'dorecountposts_recount':
            $postids = qa_db_posts_get_for_recounting($next, 1000);
            if (count($postids)) {
                $lastpostid = max($postids);
                qa_db_posts_recount($next, $lastpostid);
                $next = 1 + $lastpostid;
                $done += count($postids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecountposts_complete');
            }
            break;
        case 'dorecalcpoints':
            qa_recalc_transition($state, 'dorecalcpoints_usercount');
            break;
        case 'dorecalcpoints_usercount':
            qa_db_userpointscount_update();
            // for progress update - not necessarily accurate
            qa_recalc_transition($state, 'dorecalcpoints_recalc');
            break;
        case 'dorecalcpoints_recalc':
            $userids = qa_db_users_get_for_recalc_points($next, 10);
            if (count($userids)) {
                $lastuserid = max($userids);
                qa_db_users_recalc_points($next, $lastuserid);
                $next = 1 + $lastuserid;
                $done += count($userids);
                $continue = true;
            } else {
                qa_db_truncate_userpoints($next);
                qa_db_userpointscount_update();
                // quick so just do it here
                qa_recalc_transition($state, 'dorecalcpoints_complete');
            }
            break;
        case 'dorecalccategories':
            qa_recalc_transition($state, 'dorecalccategories_postcount');
            break;
        case 'dorecalccategories_postcount':
            qa_db_acount_update();
            qa_db_ccount_update();
            qa_recalc_transition($state, 'dorecalccategories_postupdate');
            break;
        case 'dorecalccategories_postupdate':
            $postids = qa_db_posts_get_for_recategorizing($next, 100);
            if (count($postids)) {
                $lastpostid = max($postids);
                qa_db_posts_recalc_categoryid($next, $lastpostid);
                qa_db_posts_calc_category_path($next, $lastpostid);
                $next = 1 + $lastpostid;
                $done += count($postids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecalccategories_recount');
            }
            break;
        case 'dorecalccategories_recount':
            $categoryids = qa_db_categories_get_for_recalcs($next, 10);
            if (count($categoryids)) {
                $lastcategoryid = max($categoryids);
                foreach ($categoryids as $categoryid) {
                    qa_db_ifcategory_qcount_update($categoryid);
                }
                $next = 1 + $lastcategoryid;
                $done += count($categoryids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecalccategories_backpaths');
            }
            break;
        case 'dorecalccategories_backpaths':
            $categoryids = qa_db_categories_get_for_recalcs($next, 10);
            if (count($categoryids)) {
                $lastcategoryid = max($categoryids);
                qa_db_categories_recalc_backpaths($next, $lastcategoryid);
                $next = 1 + $lastcategoryid;
                $done += count($categoryids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecalccategories_complete');
            }
            break;
        case 'dodeletehidden':
            qa_recalc_transition($state, 'dodeletehidden_comments');
            break;
        case 'dodeletehidden_comments':
            $posts = qa_db_posts_get_for_deleting('C', $next, 1);
            if (count($posts)) {
                $postid = $posts[0];
                $oldcomment = qa_db_single_select(qa_db_full_post_selectspec(null, $postid));
                $parent = qa_db_single_select(qa_db_full_post_selectspec(null, $oldcomment['parentid']));
                if ($parent['basetype'] == 'Q') {
                    $question = $parent;
                    $answer = null;
                } else {
                    $question = qa_db_single_select(qa_db_full_post_selectspec(null, $parent['parentid']));
                    $answer = $parent;
                }
                qa_comment_delete($oldcomment, $question, $answer, null, null, null);
                $next = 1 + $postid;
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dodeletehidden_answers');
            }
            break;
        case 'dodeletehidden_answers':
            $posts = qa_db_posts_get_for_deleting('A', $next, 1);
            if (count($posts)) {
                $postid = $posts[0];
                $oldanswer = qa_db_single_select(qa_db_full_post_selectspec(null, $postid));
                $question = qa_db_single_select(qa_db_full_post_selectspec(null, $oldanswer['parentid']));
                qa_answer_delete($oldanswer, $question, null, null, null);
                $next = 1 + $postid;
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dodeletehidden_questions');
            }
            break;
        case 'dodeletehidden_questions':
            $posts = qa_db_posts_get_for_deleting('Q', $next, 1);
            if (count($posts)) {
                $postid = $posts[0];
                $oldquestion = qa_db_single_select(qa_db_full_post_selectspec(null, $postid));
                qa_question_delete($oldquestion, null, null, null);
                $next = 1 + $postid;
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dodeletehidden_complete');
            }
            break;
        default:
            $state = '';
            break;
    }
    if ($continue) {
        $state = $operation . ',' . $length . ',' . $next . ',' . $done;
    }
    return $continue && $done < $length;
}
Пример #20
0
function qa_comment_set_hidden($oldcomment, $hidden, $userid, $handle, $cookieid, $question, $parent)
{
    require_once QA_INCLUDE_DIR . 'qa-app-format.php';
    if (!isset($parent)) {
        $parent = $question;
    }
    // for backwards compatibility with old answer parameter
    $wasqueued = $oldcomment['type'] == 'C_QUEUED';
    qa_post_unindex($oldcomment['postid']);
    $setupdated = $hidden || !$wasqueued;
    // don't record approval of a post as an update action...
    qa_db_post_set_type($oldcomment['postid'], $hidden ? 'C_HIDDEN' : 'C', $setupdated ? $userid : null, $setupdated ? qa_remote_ip_address() : null, QA_UPDATE_VISIBLE);
    if (!$setupdated) {
        // ... for approval of a post, set created time to now instead
        qa_db_post_set_created($oldcomment['postid'], null);
    }
    qa_db_points_update_ifuser($oldcomment['userid'], array('cposts'));
    qa_db_ccount_update();
    if ($question['type'] == 'Q' && ($parent['type'] == 'Q' || $parent['type'] == 'A') && !$hidden) {
        // only index if none of the things it depends on are hidden or queued
        qa_post_index($oldcomment['postid'], 'C', $question['postid'], $oldcomment['parentid'], null, $oldcomment['content'], $oldcomment['format'], qa_viewer_text($oldcomment['content'], $oldcomment['format']), null, $oldcomment['categoryid']);
    }
    qa_report_event($wasqueued ? $hidden ? 'c_reject' : 'c_approve' : ($hidden ? 'c_hide' : 'c_reshow'), $userid, $handle, $cookieid, array('postid' => $oldcomment['postid'], 'parentid' => $oldcomment['parentid'], 'oldcomment' => $oldcomment, 'parenttype' => $parent['basetype'], 'questionid' => $question['postid']));
    if ($wasqueued && !$hidden) {
        require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
        require_once QA_INCLUDE_DIR . 'qa-util-string.php';
        $commentsfollows = qa_db_single_select(qa_db_full_child_posts_selectspec(null, $oldcomment['parentid']));
        $thread = array();
        foreach ($commentsfollows as $comment) {
            if ($comment['type'] == 'C' && $comment['parentid'] == $parent['postid']) {
                $thread[] = $comment;
            }
        }
        qa_report_event('c_post', $oldcomment['userid'], $oldcomment['handle'], $oldcomment['cookieid'], array('postid' => $oldcomment['postid'], 'parentid' => $oldcomment['parentid'], 'parenttype' => $parent['basetype'], 'parent' => $parent, 'questionid' => $question['postid'], 'question' => $question, 'thread' => $thread, 'content' => $oldcomment['content'], 'format' => $oldcomment['format'], 'text' => qa_viewer_text($oldcomment['content'], $oldcomment['format']), 'categoryid' => $oldcomment['categoryid'], 'notify' => isset($oldcomment['notify']), 'email' => qa_email_validate($oldcomment['notify']) ? $oldcomment['notify'] : null, 'delayed' => $oldcomment['created']));
    }
}
 function notify($uid, $notices)
 {
     require_once QA_INCLUDE_DIR . 'qa-app-users.php';
     require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
     if (QA_FINAL_EXTERNAL_USERS) {
         $publictohandle = qa_get_public_from_userids(array($uid));
         $handle = @$publictohandle[$uid];
     } else {
         $user = qa_db_single_select(qa_db_user_account_selectspec($uid, true));
         $handle = @$user['handle'];
     }
     $subject = qa_opt('priv_email_subject');
     $body = qa_opt('priv_email_body');
     $n = explode(',', $notices);
     if (count($n) > 1) {
         $body = preg_replace('/\\^single=`([^`]+)`/', '', $body);
         preg_match('/\\^multi=`([^`]+)`/', $body, $multi);
         $m = str_replace('#', count($n), $multi[1]);
         $body = preg_replace('/\\^multi=`([^`]+)`/', $m, $body);
     } else {
         $body = preg_replace('/\\^single=`([^`]+)`/', '$1', $body);
         $body = preg_replace('/\\^multi=`([^`]+)`/', '', $body);
     }
     $site_url = qa_opt('site_url');
     $profile_url = qa_path_html('user/' . $handle, null, $site_url);
     $subs = array('^profile_url' => $profile_url, '^site_url' => $site_url);
     qa_send_notification($uid, '@', $handle, $subject, $body, $subs);
 }
 function ajaxCommentVote($vote, $postid)
 {
     global $topage, $qa_cookieid;
     $post = qa_db_select_with_pending(qa_db_full_post_selectspec($this->logged_in_userid, $postid));
     $voteerror = $this->comment_vote_error_html($post, $this->logged_in_userid, $topage);
     if ($voteerror === false) {
         $this->comment_vote_set($post, $this->logged_in_userid, qa_get_logged_in_handle(), $qa_cookieid, $vote);
         $comment = qa_db_single_select(qa_db_full_post_selectspec(null, $postid));
         $votes = $comment['netvotes'];
         $up_text = qa_lang_html('main/vote' . ($vote == 1 ? 'd' : '') . '_up_popup');
         $down_text = qa_lang_html('main/vote' . ($vote == -1 ? 'd' : '') . '_down_popup');
         echo '{"status":"1","data":"' . $votes . '","up":"' . $up_text . '","down":"' . $down_text . '"}';
     } else {
         echo '{"status":"0","data":"' . $voteerror . '"}';
     }
 }
Пример #23
0
 function qa_get_logged_in_userid()
 {
     if (qa_to_override(__FUNCTION__)) {
         $args = func_get_args();
         return qa_call_override(__FUNCTION__, $args);
     }
     global $qa_logged_in_userid_checked;
     $suffix = qa_session_var_suffix();
     if (!$qa_logged_in_userid_checked) {
         // only check once
         qa_start_session();
         // this will load logged in userid from the native PHP session, but that's not enough
         $sessionuserid = @$_SESSION['qa_session_userid_' . $suffix];
         if (isset($sessionuserid)) {
             // check verify code matches
             if (@$_SESSION['qa_session_verify_' . $suffix] != qa_session_verify_code($sessionuserid)) {
                 qa_clear_session_user();
             }
         }
         if (!empty($_COOKIE['qa_session'])) {
             @(list($handle, $sessioncode, $remember) = explode('/', $_COOKIE['qa_session']));
             if ($remember) {
                 qa_set_session_cookie($handle, $sessioncode, $remember);
             }
             // extend 'remember me' cookies each time
             $sessioncode = trim($sessioncode);
             // trim to prevent passing in blank values to match uninitiated DB rows
             // Try to recover session from the database if PHP session has timed out
             if (!isset($_SESSION['qa_session_userid_' . $suffix]) && !empty($handle) && !empty($sessioncode)) {
                 require_once QA_INCLUDE_DIR . 'db/selects.php';
                 $userinfo = qa_db_single_select(qa_db_user_account_selectspec($handle, false));
                 // don't get any pending
                 if (strtolower(trim($userinfo['sessioncode'])) == strtolower($sessioncode)) {
                     qa_set_session_user($userinfo['userid'], $userinfo['sessionsource']);
                 } else {
                     qa_clear_session_cookie();
                 }
                 // if cookie not valid, remove it to save future checks
             }
         }
         $qa_logged_in_userid_checked = true;
     }
     return @$_SESSION['qa_session_userid_' . $suffix];
 }
Пример #24
0
/**
 * Return the data specified by each element of $selectspecs, where the keys of the
 * returned array match the keys of the supplied $selectspecs array. See long comment above.
 */
function qa_db_multi_select($selectspecs)
{
    if (!count($selectspecs)) {
        return array();
    }
    //	Perform simple queries if the database is local or there are only 0 or 1 selectspecs
    if (QA_OPTIMIZE_LOCAL_DB || count($selectspecs) <= 1) {
        $outresults = array();
        foreach ($selectspecs as $selectkey => $selectspec) {
            $outresults[$selectkey] = qa_db_single_select($selectspec);
        }
        return $outresults;
    }
    //	Otherwise, parse columns for each spec to deal with columns without an 'AS' specification
    foreach ($selectspecs as $selectkey => $selectspec) {
        $selectspecs[$selectkey]['outcolumns'] = array();
        $selectspecs[$selectkey]['autocolumn'] = array();
        foreach ($selectspec['columns'] as $columnas => $columnfrom) {
            if (is_int($columnas)) {
                $periodpos = strpos($columnfrom, '.');
                $columnas = is_numeric($periodpos) ? substr($columnfrom, $periodpos + 1) : $columnfrom;
                $selectspecs[$selectkey]['autocolumn'][$columnas] = true;
            }
            if (isset($selectspecs[$selectkey]['outcolumns'][$columnas])) {
                qa_fatal_error('Duplicate column name in qa_db_multi_select()');
            }
            $selectspecs[$selectkey]['outcolumns'][$columnas] = $columnfrom;
        }
        if (isset($selectspec['arraykey'])) {
            if (!isset($selectspecs[$selectkey]['outcolumns'][$selectspec['arraykey']])) {
                qa_fatal_error('Used arraykey not in columns in qa_db_multi_select()');
            }
        }
        if (isset($selectspec['arrayvalue'])) {
            if (!isset($selectspecs[$selectkey]['outcolumns'][$selectspec['arrayvalue']])) {
                qa_fatal_error('Used arrayvalue not in columns in qa_db_multi_select()');
            }
        }
    }
    //	Work out the full list of columns used
    $outcolumns = array();
    foreach ($selectspecs as $selectspec) {
        $outcolumns = array_unique(array_merge($outcolumns, array_keys($selectspec['outcolumns'])));
    }
    //	Build the query based on this full list
    $query = '';
    foreach ($selectspecs as $selectkey => $selectspec) {
        $subquery = "(SELECT '" . qa_db_escape_string($selectkey) . "'" . (empty($query) ? ' AS selectkey' : '');
        foreach ($outcolumns as $columnas) {
            $subquery .= ', ' . (isset($selectspec['outcolumns'][$columnas]) ? $selectspec['outcolumns'][$columnas] : 'NULL');
            if (empty($query) && !isset($selectspec['autocolumn'][$columnas])) {
                $subquery .= ' AS ' . $columnas;
            }
        }
        if (strlen(@$selectspec['source'])) {
            $subquery .= ' FROM ' . $selectspec['source'];
        }
        $subquery .= ')';
        if (strlen($query)) {
            $query .= ' UNION ALL ';
        }
        $query .= qa_db_apply_sub($subquery, @$selectspec['arguments']);
    }
    //	Perform query and extract results
    $rawresults = qa_db_read_all_assoc(qa_db_query_raw($query));
    $outresults = array();
    foreach ($selectspecs as $selectkey => $selectspec) {
        $outresults[$selectkey] = array();
    }
    foreach ($rawresults as $rawresult) {
        $selectkey = $rawresult['selectkey'];
        $selectspec = $selectspecs[$selectkey];
        $keepresult = array();
        foreach ($selectspec['outcolumns'] as $columnas => $columnfrom) {
            $keepresult[$columnas] = $rawresult[$columnas];
        }
        if (isset($selectspec['arraykey'])) {
            $outresults[$selectkey][$keepresult[$selectspec['arraykey']]] = $keepresult;
        } else {
            $outresults[$selectkey][] = $keepresult;
        }
    }
    //	Post-processing to apply various stuff include sorting request, since we can't rely on ORDER BY due to UNION
    foreach ($selectspecs as $selectkey => $selectspec) {
        qa_db_post_select($outresults[$selectkey], $selectspec);
    }
    //	Return results
    return $outresults;
}
Пример #25
0
<?php

require_once 'qa-include/qa-base.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/q-list.php';
//require_once QA_INCLUDE_DIR.'app/users.php';
//$user = qa_get_logged_in_user();
//$userid=$user["userid"];//qa_get_logged_in_userid();
list($questions, $categories, $categoryid) = qa_db_select_with_pending(qa_db_qs_selectspec(null, 'hotness', 0, null, null, false, true), qa_db_category_nav_selectspec(null, false, false, true), null);
foreach ($questions as $key => $question) {
    $questionid = $question["postid"];
    $answers = array();
    $childposts = qa_db_single_select(qa_db_full_child_posts_selectspec(null, $questionid));
    foreach ($childposts as $postid => $post) {
        if ($post['basetype'] == 'A') {
            $answers[$postid] = $post;
        }
    }
    $questions[$key]["answers"] = $answers;
}
$salida = [];
foreach ($questions as $pregunta) {
    $salida[$pregunta["postid"]] = ['userid' => $pregunta["userid"], 'contenido' => substr($pregunta["title"] . ". " . strip_tags($pregunta["content"]), 0, 100)];
    foreach ($pregunta["answers"] as $resp) {
        //$u = Medico::where('user_id','=',$resp["userid"])->first();
        //if($u){
        $salida[$pregunta["postid"]]["respuestas"][] = ["userid" => $resp["userid"], "contenido" => substr(strip_tags($resp["content"]), 0, 100)];
        //}
    }
}
header('Content-Type: application/json');