function carousel_item($type, $limit, $col_item = 1) { require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; $post = qa_db_query_sub('SELECT * FROM ^postmetas, ^posts INNER JOIN ^users ON ^posts.userid=^users.userid WHERE ^posts.type=$ and ( ^postmetas.postid = ^posts.postid and ^postmetas.title = "featured_question" ) ORDER BY ^posts.created DESC LIMIT #', $type, $limit); $output = '<div class="item"><div class="row">'; $i = 1; while ($p = mysql_fetch_array($post)) { if ($type == 'Q') { $what = qa_lang('cleanstrap/asked'); } elseif ($type == 'A') { $what = qa_lang('cleanstrap/answered'); } elseif ('C') { $what = qa_lang('cleanstrap/commented'); } $handle = $p['handle']; if ($type == 'Q') { $link_header = '<a href="' . qa_q_path_html($p['postid'], $p['title']) . '" title="' . $p['title'] . '">'; } elseif ($type == 'A') { $link_header = '<a href="' . cs_post_link($p['parentid']) . '#a' . $p['postid'] . '">'; } else { $link_header = '<a href="' . cs_post_link($p['parentid']) . '#c' . $p['postid'] . '">'; } $output .= '<div class="slider-item col-sm-' . 12 / $col_item . '">'; $output .= '<div class="slider-item-inner">'; $featured_img = get_featured_thumb($p['postid']); if ($featured_img) { $output .= $link_header . '<div class="featured-image">' . $featured_img . '</div></a>'; } if ($type == 'Q') { $output .= '<div class="big-ans-count pull-left">' . $p['acount'] . '<span> ans</span></div>'; } elseif ($type == 'A') { $output .= '<div class="big-ans-count pull-left vote">' . $p['netvotes'] . '<span>' . qa_lang('cleanstrap/vote') . '</span></div>'; } $output .= '<h5>' . $link_header . cs_truncate(qa_html($p['title']), 50) . '</a></h5>'; $output .= '<div class="meta">'; $when = qa_when_to_html(strtotime($p['created']), 7); $avatar = cs_get_avatar($handle, 15, false); if ($avatar) { $output .= '<img src="' . $avatar . '" />'; } $output .= '<span class="icon-time">' . implode(' ', $when) . '</span>'; $output .= '<span class="vote-count">' . $p['netvotes'] . ' ' . qa_lang('cleanstrap/votes') . '</span></div>'; $output .= '</div>'; $output .= '</div>'; if ($col_item == $i) { $output .= '</div></div><div class="item active"><div class="row">'; } $i++; } $output .= '</div></div>'; return $output; }
function cs_new_users($limit, $size, $widget_opt) { $output = '<ul class="users-list clearfix">'; if (defined('QA_FINAL_WORDPRESS_INTEGRATE_PATH')) { global $wpdb; $users = $wpdb->get_results("SELECT ID from {$wpdb->users} order by ID DESC LIMIT {$limit}"); require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; foreach ($users as $u) { $handle = qa_post_userid_to_handle($u->ID); $output .= '<li class="user">'; $output .= '<div class="avatar" data-handle="' . $handle . '" data-id="' . qa_handle_to_userid($handle) . '"><img src="' . cs_get_avatar($u['handle'], $size, false) . '" /></div>'; $output .= '</li>'; } } else { if (qa_opt('avatar_allow_upload') && @$widget_opt['cs_nu_with_avatar']) { $users = qa_db_read_all_assoc(qa_db_query_sub("SELECT * FROM ^users WHERE avatarblobid IS NOT NULL ORDER BY created DESC LIMIT #", $limit)); } elseif (qa_opt('avatar_allow_gravatar') || qa_opt('avatar_default_show') && strlen(qa_opt('avatar_default_blobid'))) { $users = qa_db_read_all_assoc(qa_db_query_sub("SELECT * FROM ^users ORDER BY created DESC LIMIT #", $limit)); } //refresh every 10 minutes foreach ($users as $u) { if (isset($u['handle'])) { $handle = $u['handle']; $avatar = cs_get_avatar($handle, $size, false); if (isset($u['useid'])) { $id = $u['useid']; } else { $id = qa_handle_to_userid($handle); } $output .= '<li class="user">'; if (!empty($avatar)) { $output .= '<a href="' . qa_path_html('user/' . $handle) . '"><div class="avatar" data-handle="' . $handle . '" data-id="' . $id . '"><img src="' . $avatar . '" /></div></a>'; } $output .= '</li>'; } } } $output .= '</ul>'; echo $output; }
function cs_ajax_user_popover() { $handle_id = qa_post_text('handle'); $handle = qa_post_text('handle'); require_once QA_INCLUDE_DIR . 'qa-db-users.php'; if (isset($handle)) { $userid = qa_handle_to_userid($handle); //$badges = cs_user_badge($handle); if (defined('QA_WORDPRESS_INTEGRATE_PATH')) { $userid = qa_handle_to_userid($handle); $cover = get_user_meta($userid, 'cover'); $cover = $cover[0]; } else { $data = cs_user_data($handle); } ?> <div id="<?php echo $userid; ?> _popover" class="user-popover"> <div class="counts clearfix"> <div class="points"> <?php echo '<span>' . $data['points'] . '</span>Points'; ?> </div> <div class="qcount"> <?php echo '<span>' . $data['qposts'] . '</span>Questions'; ?> </div> <div class="acount"> <?php echo '<span>' . $data['aposts'] . '</span>Answers'; ?> </div> <div class="ccount"> <?php echo '<span>' . $data['cposts'] . '</span>Comments'; ?> </div> </div> <div class="bottom"> <div class="avatar pull-left"><?php echo cs_get_avatar($handle, 30); ?> </div> <span class="name"><?php echo cs_name($handle); ?> </span> <span class="level"><?php echo qa_user_level_string($data['level']); ?> </span> </div> </div> <?php } die; }
function cs_ajax_get_question_suggestion() { $query = strip_tags($_REQUEST['start_with']); $relatedquestions = qa_db_select_with_pending(qa_db_search_posts_selectspec(null, qa_string_to_words($query), null, null, null, null, 0, false, 10)); //print_r($relatedquestions); if (isset($relatedquestions) && !empty($relatedquestions)) { $data = array(); foreach ($relatedquestions as $k => $q) { $data[$k]['title'] = $q['title']; $data[$k]['blob'] = cs_get_avatar($q['handle'], 30, false); $data[$k]['url'] = qa_q_path_html($q['postid'], $q['title']); $data[$k]['tags'] = $q['tags']; $data[$k]['answers'] = $q['acount']; } echo json_encode($data); } die; }
function cs_relative_post_list($limit, $slug, $type, $return = false, $avatar_size) { require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; if (!empty($slug)) { if ($type == 'Category') { $post_type = 'Q'; $categories = explode("/", $slug); if (count($categories)) { $category_bread_crup = implode(" > ", $categories); $category_link = implode("/", $categories); $categories = array_reverse($categories); $slug = implode("/", $categories); } $posts = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE ^posts.type=$ AND categoryid=(SELECT categoryid FROM ^categories WHERE ^categories.backpath=$ LIMIT 1) ORDER BY ^posts.created DESC LIMIT #', 'Q', $slug, $limit)); //refresh every 15 minutes $title = 'Questions in <a href="' . qa_path_html('questions/' . qa_strtolower($category_link)) . '">' . $category_bread_crup . '</a>'; } elseif ($type == 'Tags') { $post_type = 'Q'; $title = 'Questions in <a href="' . qa_path_html('tag/' . qa_strtolower($slug)) . '">' . $slug . '</a>'; $posts = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE ^posts.type=$ AND ^posts.postid IN (SELECT postid FROM ^posttags WHERE wordid=(SELECT wordid FROM ^words WHERE word=$ OR word=$ COLLATE utf8_bin LIMIT 1) ORDER BY postcreated DESC) ORDER BY ^posts.created DESC LIMIT #', 'Q', $slug, qa_strtolower($slug), $limit)); } else { // Relative to Keyword require_once QA_INCLUDE_DIR . 'qa-app-search.php'; $keyword = $slug; $userid = qa_get_logged_in_userid(); $title = 'Posts About <a href="' . qa_path_html('search/' . qa_strtolower($keyword)) . '">' . $keyword . '</a>'; //$post=qa_get_search_results($keyword, 0, $limit, $userid , false, false); $words = qa_string_to_words($keyword); $posts = qa_db_select_with_pending(qa_db_search_posts_selectspec($userid, $words, $words, $words, $words, trim($keyword), 0, false, $limit)); $output = '<h3 class="widget-title">' . $title . '</h3>'; $output .= '<ul class="question-list">'; foreach ($posts as $post) { $post_type = $post['type']; if ($post_type == 'Q') { $what = qa_lang('cleanstrap/asked'); } elseif ($post_type == 'A') { $what = qa_lang('cleanstrap/answered'); } elseif ('C') { $what = qa_lang('cleanstrap/commented'); } $handle = qa_post_userid_to_handle($post['userid']); $avatar = cs_get_post_avatar($post, $avatar_size); $output .= '<li id="q-list-' . $post['postid'] . '" class="question-item">'; $output .= '<div class="pull-left avatar" data-handle="' . $handle . '" data-id="' . $post['userid'] . '">' . $avatar . '</div>'; $output .= '<div class="list-right">'; if ($post_type == 'Q') { $output .= '<a class="title" href="' . qa_q_path_html($post['postid'], $post['title']) . '" title="' . $post['title'] . '">' . cs_truncate(strip_tags($post['title']), 70) . '</a>'; } elseif ($post_type == 'A') { $output .= '<p><a href="' . cs_post_link($post['parentid']) . '#a' . $post['postid'] . '">' . cs_truncate(strip_tags($post['content']), 70) . '</a></p>'; } else { $output .= '<p><a href="' . cs_post_link($post['parentid']) . '#c' . $post['postid'] . '">' . cs_truncate(strip_tags($post['content']), 70) . '</a></p>'; } $output .= '<div class="meta"><a href="' . qa_path_html('user/' . $handle) . '">' . cs_name($handle) . '</a> ' . $what; if ($post_type == 'Q') { $output .= ' <span class="vote-count">' . $post['netvotes'] . ' votes</span>'; $output .= ' <span class="ans-count">' . $post['acount'] . ' ans</span>'; } elseif ($post_type == 'A') { $output .= ' <span class="vote-count">' . $post['netvotes'] . ' votes</span>'; } $output .= '</div></div>'; $output .= '</li>'; } $output .= '</ul>'; if ($return) { return $output; } echo $output; return; } } else { return; } $output = '<h3 class="widget-title">' . $title . '</h3>'; $output .= '<ul class="question-list">'; foreach ($posts as $p) { if (empty($p['userid'])) { $p['userid'] = NULL; } // to prevent error for anonymous posts while calling qa_post_userid_to_handle() if ($post_type == 'Q') { $what = qa_lang_html('cleanstrap/asked'); } elseif ($post_type == 'A') { $what = qa_lang_html('cleanstrap/answered'); } elseif ('C') { $what = qa_lang_html('cleanstrap/commented'); } $handle = qa_post_userid_to_handle($p['userid']); $avatar = cs_get_avatar($handle, 35, false); $output .= '<li id="q-list-' . $p['postid'] . '" class="question-item">'; $output .= '<div class="pull-left avatar" data-handle="' . $handle . '" data-id="' . qa_handle_to_userid($handle) . '">' . (isset($avatar) ? '<img src="' . $avatar . '" />' : '') . '</div>'; $output .= '<div class="list-right">'; if ($post_type == 'Q') { $output .= '<a class="title" href="' . qa_q_path_html($p['postid'], $p['title']) . '" title="' . $p['title'] . '">' . cs_truncate(qa_html($p['title']), 70) . '</a>'; } elseif ($post_type == 'A') { $output .= '<p><a href="' . cs_post_link($p['parentid']) . '#a' . $p['postid'] . '">' . cs_truncate(strip_tags($p['content']), 70) . '</a></p>'; } else { $output .= '<p><a href="' . cs_post_link($p['parentid']) . '#c' . $p['postid'] . '">' . cs_truncate(strip_tags($p['content']), 70) . '</a></p>'; } $output .= '<div class="meta"><a href="' . qa_path_html('user/' . $handle) . '">' . cs_name($handle) . '</a> ' . $what; if ($post_type == 'Q') { $output .= ' <span class="vote-count">' . $p['netvotes'] . ' votes</span>'; $output .= ' <span class="ans-count">' . $p['acount'] . ' ans</span>'; } elseif ($post_type == 'A') { $output .= ' <span class="vote-count">' . $p['netvotes'] . ' votes</span>'; } $output .= '</div></div>'; $output .= '</li>'; } $output .= '</ul>'; if ($return) { return $output; } echo $output; }