当前位置: 首页>>代码示例>>PHP>>正文


PHP qa_string_to_words函数代码示例

本文整理汇总了PHP中qa_string_to_words函数的典型用法代码示例。如果您正苦于以下问题:PHP qa_string_to_words函数的具体用法?PHP qa_string_to_words怎么用?PHP qa_string_to_words使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了qa_string_to_words函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: qa_shorten_string_line

function qa_shorten_string_line($string, $length)
{
    $string = strtr($string, "\r\n\t", '   ');
    if (qa_strlen($string) > $length) {
        $remaining = $length - 5;
        $words = qa_string_to_words($string, false, true);
        $countwords = count($words);
        $prefix = '';
        $suffix = '';
        for ($addword = 0; $addword < $countwords; $addword++) {
            $tosuffix = $addword % 3 == 1;
            // order: prefix, suffix, prefix, prefix, suffix, prefix, ...
            if ($tosuffix) {
                $word = array_pop($words);
            } else {
                $word = array_shift($words);
            }
            if (qa_strlen($word) > $remaining) {
                break;
            }
            if ($tosuffix) {
                $suffix = $word . $suffix;
            } else {
                $prefix .= $word;
            }
            $remaining -= qa_strlen($word);
        }
        $string = $prefix . ' ... ' . $suffix;
    }
    return $string;
}
开发者ID:TheProjecter,项目名称:microprobe,代码行数:31,代码来源:qa-util-string.php

示例2: test__qa_string_to_words

 public function test__qa_string_to_words()
 {
     $test1 = qa_string_to_words($this->strBasic);
     $expected1 = array('so', 'i', 'tied', 'an', 'onion', 'to', 'my', 'belt', 'which', 'was', 'the', 'style', 'at', 'the', 'time');
     $test2 = qa_string_to_words($this->strBasic, false);
     $expected2 = array('So', 'I', 'tied', 'an', 'onion', 'to', 'my', 'belt', 'which', 'was', 'the', 'style', 'at', 'the', 'time');
     $this->assertEquals($expected1, $test1);
     $this->assertEquals($expected2, $test2);
 }
开发者ID:kosmoluna,项目名称:question2answer,代码行数:9,代码来源:UtilStringTest.php

示例3: elseif

 } elseif (qa_strlen($inname) > QA_DB_MAX_CAT_PAGE_TITLE_LENGTH) {
     $errors['name'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TITLE_LENGTH);
 } else {
     foreach ($incategories as $category) {
         if (!strcmp($category['parentid'], $inparentid) && strcmp($category['categoryid'], @$editcategory['categoryid']) && qa_strtolower($category['title']) == qa_strtolower($inname)) {
             $errors['name'] = qa_lang('admin/category_already_used');
         }
     }
 }
 //	Verify the slug is legitimate for that parent ID
 for ($attempt = 0; $attempt < 100; $attempt++) {
     switch ($attempt) {
         case 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;
开发者ID:kosmoluna,项目名称:question2answer,代码行数:31,代码来源:admin-categories.php

示例4: qa_shorten_string_line

/**
 * Converts a string to a single line and removes words from it until it fits in the given length. Words are removed
 * from a position around two thirds of the string and are replaced by the given ellipsis string
 *
 * @param string $string Text that will be turned into a single line and cut, if necessary
 * @param int $length Maximum allowed length of the returned string. This value can be overriden by the length of the
 * ellipsis if it is higher than the maximum allowed length
 * @param string $ellipsis Text used to replace the removed words from the original text
 * @return string The string turned into a single line and cut to fit the given length
 */
function qa_shorten_string_line($string, $length, $ellipsis = ' ... ')
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    $string = strtr($string, "\r\n\t", '   ');
    if (qa_strlen($string) > $length) {
        $remaining = $length - qa_strlen($ellipsis);
        $words = qa_string_to_words($string, false, true);
        $countwords = count($words);
        $prefix = '';
        $suffix = '';
        for ($addword = 0; $addword < $countwords; $addword++) {
            $tosuffix = $addword % 3 == 1;
            // order: prefix, suffix, prefix, prefix, suffix, prefix, ...
            $word = $tosuffix ? array_pop($words) : array_shift($words);
            $wordLength = qa_strlen($word);
            if ($wordLength > $remaining) {
                break;
            }
            if ($tosuffix) {
                $suffix = $word . $suffix;
            } else {
                $prefix .= $word;
            }
            $remaining -= $wordLength;
        }
        $string = $prefix . $ellipsis . $suffix;
    }
    return $string;
}
开发者ID:amiyasahu,项目名称:question2answer,代码行数:42,代码来源:string.php

示例5: qa_redirect

         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;
                 }
             }
         }
     } elseif (empty($errors)) {
         // creating a new user field
         for ($attempt = 0; $attempt < 1000; $attempt++) {
             $suffix = $attempt ? '-' . (1 + $attempt) : '';
             $newtag = qa_substr(implode('-', qa_string_to_words($inname)), 0, QA_DB_MAX_PROFILE_TITLE_LENGTH - strlen($suffix)) . $suffix;
             $uniquetag = true;
             foreach ($userfields as $userfield) {
                 if (qa_strtolower(trim($newtag)) == qa_strtolower(trim($userfield['title']))) {
                     $uniquetag = false;
                 }
             }
             if ($uniquetag) {
                 $fieldid = qa_db_userfield_create($newtag, $inname, $inflags);
                 qa_db_userfield_move($fieldid, $inposition);
                 qa_redirect('admin/users');
             }
         }
         qa_fatal_error('Could not create a unique database tag');
     }
 }
开发者ID:TheProjecter,项目名称:microprobe,代码行数:31,代码来源:qa-page-admin-userfields.php

示例6: qa_content_prepare


//.........这里部分代码省略.........
    foreach ($navpages as $page) {
        if ($page['nav'] == 'M' || $page['nav'] == 'O' || $page['nav'] == 'F') {
            qa_navigation_add_page($qa_content['navigation'][$page['nav'] == 'F' ? 'footer' : 'main'], $page);
        }
    }
    $regioncodes = array('F' => 'full', 'M' => 'main', 'S' => 'side');
    $placecodes = array('T' => 'top', 'H' => 'high', 'L' => 'low', 'B' => 'bottom');
    foreach ($widgets as $widget) {
        if (is_numeric(strpos(',' . $widget['tags'] . ',', ',' . $qa_template . ',')) || is_numeric(strpos(',' . $widget['tags'] . ',', ',all,'))) {
            // see if it has been selected for display on this template
            $region = @$regioncodes[substr($widget['place'], 0, 1)];
            $place = @$placecodes[substr($widget['place'], 1, 2)];
            if (isset($region) && isset($place)) {
                // check region/place codes recognized
                $module = qa_load_module('widget', $widget['title']);
                if (isset($module) && method_exists($module, 'allow_template') && $module->allow_template(substr($qa_template, 0, 7) == 'custom-' ? 'custom' : $qa_template) && method_exists($module, 'allow_region') && $module->allow_region($region) && method_exists($module, 'output_widget')) {
                    $qa_content['widgets'][$region][$place][] = $module;
                }
                // if module loaded and happy to be displayed here, tell theme about it
            }
        }
    }
    $logoshow = qa_opt('logo_show');
    $logourl = qa_opt('logo_url');
    $logowidth = qa_opt('logo_width');
    $logoheight = qa_opt('logo_height');
    if ($logoshow) {
        $qa_content['logo'] = '<a href="' . qa_path_html('') . '" class="qa-logo-link" title="' . qa_html(qa_opt('site_title')) . '">' . '<img src="' . qa_html(is_numeric(strpos($logourl, '://')) ? $logourl : qa_path_to_root() . $logourl) . '"' . ($logowidth ? ' width="' . $logowidth . '"' : '') . ($logoheight ? ' height="' . $logoheight . '"' : '') . ' border="0" alt="' . qa_html(qa_opt('site_title')) . '"/></a>';
    } else {
        $qa_content['logo'] = '<a href="' . qa_path_html('') . '" class="qa-logo-link">' . qa_html(qa_opt('site_title')) . '</a>';
    }
    $topath = qa_get('to');
    // lets user switch between login and register without losing destination page
    $userlinks = qa_get_login_links(qa_path_to_root(), isset($topath) ? $topath : qa_path($request, $_GET, ''));
    $qa_content['navigation']['user'] = array();
    if (qa_is_logged_in()) {
        $qa_content['loggedin'] = qa_lang_html_sub_split('main/logged_in_x', QA_FINAL_EXTERNAL_USERS ? qa_get_logged_in_user_html(qa_get_logged_in_user_cache(), qa_path_to_root(), false) : qa_get_one_user_html(qa_get_logged_in_handle(), false));
        $qa_content['navigation']['user']['updates'] = array('url' => qa_path_html('updates'), 'label' => qa_lang_html('main/nav_updates'));
        if (!empty($userlinks['logout'])) {
            $qa_content['navigation']['user']['logout'] = array('url' => qa_html(@$userlinks['logout']), 'label' => qa_lang_html('main/nav_logout'));
        }
        if (!QA_FINAL_EXTERNAL_USERS) {
            $source = qa_get_logged_in_source();
            if (strlen($source)) {
                $loginmodules = qa_load_modules_with('login', 'match_source');
                foreach ($loginmodules as $module) {
                    if ($module->match_source($source) && method_exists($module, 'logout_html')) {
                        ob_start();
                        $module->logout_html(qa_path('logout', array(), qa_opt('site_url')));
                        $qa_content['navigation']['user']['logout'] = array('label' => ob_get_clean());
                    }
                }
            }
        }
        $notices = qa_db_get_pending_result('notices');
        foreach ($notices as $notice) {
            $qa_content['notices'][] = qa_notice_form($notice['noticeid'], qa_viewer_html($notice['content'], $notice['format']), $notice);
        }
    } else {
        require_once QA_INCLUDE_DIR . 'util/string.php';
        if (!QA_FINAL_EXTERNAL_USERS) {
            $loginmodules = qa_load_modules_with('login', 'login_html');
            foreach ($loginmodules as $tryname => $module) {
                ob_start();
                $module->login_html(isset($topath) ? qa_opt('site_url') . $topath : qa_path($request, $_GET, qa_opt('site_url')), 'menu');
                $label = ob_get_clean();
                if (strlen($label)) {
                    $qa_content['navigation']['user'][implode('-', qa_string_to_words($tryname))] = array('label' => $label);
                }
            }
        }
        if (!empty($userlinks['login'])) {
            $qa_content['navigation']['user']['login'] = array('url' => qa_html(@$userlinks['login']), 'label' => qa_lang_html('main/nav_login'));
        }
        if (!empty($userlinks['register'])) {
            $qa_content['navigation']['user']['register'] = array('url' => qa_html(@$userlinks['register']), 'label' => qa_lang_html('main/nav_register'));
        }
    }
    if (QA_FINAL_EXTERNAL_USERS || !qa_is_logged_in()) {
        if (qa_opt('show_notice_visitor') && !isset($topath) && !isset($_COOKIE['qa_noticed'])) {
            $qa_content['notices'][] = qa_notice_form('visitor', qa_opt('notice_visitor'));
        }
    } else {
        setcookie('qa_noticed', 1, time() + 86400 * 3650, '/', QA_COOKIE_DOMAIN);
        // don't show first-time notice if a user has logged in
        if (qa_opt('show_notice_welcome') && qa_get_logged_in_flags() & QA_USER_FLAGS_WELCOME_NOTICE) {
            if ($requestlower != 'confirm' && $requestlower != 'account') {
                // let people finish registering in peace
                $qa_content['notices'][] = qa_notice_form('welcome', qa_opt('notice_welcome'));
            }
        }
    }
    $qa_content['script_rel'] = array('qa-content/jquery-1.11.2.min.js');
    $qa_content['script_rel'][] = 'qa-content/qa-page.js?' . QA_VERSION;
    if ($voting) {
        $qa_content['error'] = @$qa_page_error_html;
    }
    $qa_content['script_var'] = array('qa_root' => qa_path_to_root(), 'qa_request' => $request);
    return $qa_content;
}
开发者ID:Trideon,项目名称:gigolo,代码行数:101,代码来源:qa-page.php

示例7: header

	More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) {
    // don't allow this page to be requested directly from browser
    header('Location: ../');
    exit;
}
// report that we entered this page
qa_report_event('page_enter', qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), array('params' => $_SERVER['QUERY_STRING'], 'path' => $_SERVER['SCRIPT_NAME']));
require_once QA_INCLUDE_DIR . 'qa-app-format.php';
//	Perform the search if appropriate
if (strlen(qa_get('q'))) {
    require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    $inquery = trim(qa_get('q'));
    $words = qa_string_to_words($inquery);
    $retrieve = 2 * QA_DB_RETRIEVE_QS_AS + 1;
    // get enough results to be able to give some idea of how many pages of search results there are
    $questions = qa_db_select_with_pending(qa_db_search_posts_selectspec($qa_login_userid, $words, $words, $words, $words, $inquery, $qa_start, false, $retrieve));
    $pagesize = qa_opt('page_size_search');
    $gotcount = count($questions);
    $questions = array_slice($questions, 0, $pagesize);
    $usershtml = qa_userids_handles_html($questions);
    qa_report_event('search', $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, array('query' => $inquery, 'start' => $qa_start));
}
//	Prepare content for theme
$qa_content = qa_content_prepare(true);
if (strlen(qa_get('q'))) {
    $qa_content['search']['value'] = qa_html($inquery);
}
if (isset($questions)) {
开发者ID:TheProjecter,项目名称:microprobe,代码行数:31,代码来源:qa-page-search.php

示例8: qa_q_request

function qa_q_request($questionid, $title)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    require_once QA_INCLUDE_DIR . 'qa-app-options.php';
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    $title = qa_block_words_replace($title, qa_get_block_words_preg());
    $words = qa_string_to_words($title, true, false, false);
    $wordlength = array();
    foreach ($words as $index => $word) {
        $wordlength[$index] = qa_strlen($word);
    }
    $remaining = qa_opt('q_urls_title_length');
    if (array_sum($wordlength) > $remaining) {
        arsort($wordlength, SORT_NUMERIC);
        // sort with longest words first
        foreach ($wordlength as $index => $length) {
            if ($remaining > 0) {
                $remaining -= $length;
            } else {
                unset($words[$index]);
            }
        }
    }
    $title = implode('-', $words);
    if (qa_opt('q_urls_remove_accents')) {
        $title = qa_string_remove_accents($title);
    }
    return (int) $questionid . '/' . $title;
}
开发者ID:netham91,项目名称:question2answer,代码行数:32,代码来源:qa-base.php

示例9: qa_post_index

function qa_post_index($postid, $type, $questionid, $title, $text, $tagstring, $skipcounts = false)
{
    global $qa_post_indexing_suspended;
    if ($qa_post_indexing_suspended > 0) {
        return;
    }
    //	Get words from each textual element
    $titlewords = array_unique(qa_string_to_words($title));
    $contentcount = array_count_values(qa_string_to_words($text));
    $tagwords = array_unique(qa_string_to_words($tagstring));
    $wholetags = array_unique(qa_tagstring_to_tags($tagstring));
    //	Map all words to their word IDs
    $words = array_unique(array_merge($titlewords, array_keys($contentcount), $tagwords, $wholetags));
    $wordtoid = qa_db_word_mapto_ids_add($words);
    //	Add to title words index
    $titlewordids = qa_array_filter_by_keys($wordtoid, $titlewords);
    qa_db_titlewords_add_post_wordids($postid, $titlewordids);
    //	Add to content words index (including word counts)
    $contentwordidcounts = array();
    foreach ($contentcount as $word => $count) {
        if (isset($wordtoid[$word])) {
            $contentwordidcounts[$wordtoid[$word]] = $count;
        }
    }
    qa_db_contentwords_add_post_wordidcounts($postid, $type, $questionid, $contentwordidcounts);
    //	Add to tag words index
    $tagwordids = qa_array_filter_by_keys($wordtoid, $tagwords);
    qa_db_tagwords_add_post_wordids($postid, $tagwordids);
    //	Add to whole tags index
    $wholetagids = qa_array_filter_by_keys($wordtoid, $wholetags);
    qa_db_posttags_add_post_wordids($postid, $wholetagids);
    //	Update counts cached in database
    if (!$skipcounts) {
        qa_db_word_titlecount_update($titlewordids);
        qa_db_word_contentcount_update(array_keys($contentwordidcounts));
        qa_db_word_tagwordcount_update($tagwordids);
        qa_db_word_tagcount_update($wholetagids);
        qa_db_tagcount_update();
    }
}
开发者ID:TheProjecter,项目名称:microprobe,代码行数:40,代码来源:qa-app-post-create.php

示例10: ajaxPostComment

 function ajaxPostComment($text, $aid = false)
 {
     if ($aid) {
         $answer = qa_db_single_select(qa_db_full_post_selectspec(null, $aid));
     }
     require_once QA_INCLUDE_DIR . 'qa-page-question-post.php';
     global $qa_login_userid, $qa_cookieid, $question, $questionid, $formtype, $formpostid, $errors, $reloadquestion, $pageerror, $qa_request, $ineditor, $incomment, $informat, $innotify, $inemail, $commentsfollows, $jumptoanchor, $usecaptcha;
     $parent = isset($answer) ? $answer : $question;
     switch (qa_user_permit_error('permit_post_c', 'C')) {
         case 'login':
             $pageerror = qa_insert_login_links(qa_lang_html('question/comment_must_login'), $qa_request);
             break;
         case 'confirm':
             $pageerror = qa_insert_login_links(qa_lang_html('question/comment_must_confirm'), $qa_request);
             break;
         case 'limit':
             $pageerror = qa_lang_html('question/comment_limit');
             break;
         default:
             $pageerror = qa_lang_html('users/no_permission');
             break;
         case false:
             $incomment = qa_post_text('ajax_comment_content');
             if (!isset($incomment)) {
                 $pageerror = qa_lang_html('bork');
             } else {
                 $innotify = qa_post_text('notify') ? true : false;
                 $inemail = qa_post_text('email');
                 $this->ajaxEditor($ineditor, $incomment, $informat, $intext);
                 // use our own format types
                 $formats = array();
                 $formats[] = '';
                 $editors = qa_list_modules('viewer');
                 if (in_array('Markdown Viewer', $editors)) {
                     $formats[] = 'markdown';
                 }
                 $formats[] = 'html';
                 $informat = $formats[qa_opt('ajax_comment_format')];
                 $errors = qa_comment_validate($incomment, $informat, $intext, $innotify, $inemail);
                 if ($usecaptcha) {
                     qa_captcha_validate($_POST, $errors);
                 }
                 if (empty($errors)) {
                     $isduplicate = false;
                     foreach ($commentsfollows as $comment) {
                         if ($comment['basetype'] == 'C' && $comment['parentid'] == $parent['postid'] && !$comment['hidden']) {
                             if (implode(' ', qa_string_to_words($comment['content'])) == implode(' ', qa_string_to_words($incomment))) {
                                 $isduplicate = true;
                             }
                         }
                     }
                     if (!$isduplicate) {
                         if (!isset($qa_login_userid)) {
                             $qa_cookieid = qa_cookie_get_create();
                         }
                         // create a new cookie if necessary
                         // get editor format
                         $commentid = qa_comment_create($qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $incomment, $informat, $intext, $innotify, $inemail, $question, @$answer, $commentsfollows);
                         qa_report_write_action($qa_login_userid, $qa_cookieid, 'c_post', $questionid, @$answer['postid'], $commentid);
                     } else {
                         $pageerror = qa_lang_html('question/duplicate_content');
                     }
                 }
             }
             break;
     }
     if ($pageerror) {
         $this->output_raw('### ' . $pageerror);
     } else {
         if (!empty($errors)) {
             $this->output_raw('### ' . implode(',', $errors));
         } else {
             // return c_item
             $c_item = $this->ajaxCommentCreate($parent, $commentid);
             if (isset($c_item['classes'])) {
                 $c_item['classes'] .= ' ajax-comment-hidden';
             } else {
                 $c_item['classes'] = ' ajax-comment-hidden';
             }
             $this->c_list_item($c_item);
         }
     }
 }
开发者ID:microbye,项目名称:q2a-comment-ajax,代码行数:83,代码来源:qa-comment-layer.php

示例11: cs_relative_post_list

    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>';
//.........这里部分代码省略.........
开发者ID:microbye,项目名称:CleanStrap,代码行数:101,代码来源:widget_ticker.php

示例12: doctype

 function doctype()
 {
     //qa_error_log($this->content);
     if ($this->request == 'admin/permissions' && function_exists('qa_register_plugin_phrases') && qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
         $permits[] = 'expert_question_ask';
         $permits[] = 'expert_question_roles';
         foreach ($permits as $optionname) {
             $value = qa_opt($optionname);
             $optionfield = array('id' => $optionname, 'label' => qa_lang_html('expert_question/' . $optionname) . ':', 'tags' => 'NAME="option_' . $optionname . '" ID="option_' . $optionname . '"', 'error' => qa_html(@$errors[$optionname]));
             $widest = QA_PERMIT_USERS;
             $narrowest = QA_PERMIT_ADMINS;
             $permitoptions = qa_admin_permit_options($widest, $narrowest, !QA_FINAL_EXTERNAL_USERS && qa_opt('confirm_user_emails'));
             if (count($permitoptions) > 1) {
                 qa_optionfield_make_select($optionfield, $permitoptions, $value, $value == QA_PERMIT_CONFIRMED ? QA_PERMIT_USERS : min(array_keys($permitoptions)));
             }
             $this->content['form']['fields'][$optionname] = $optionfield;
             $this->content['form']['fields'][$optionname . '_points'] = array('id' => $optionname . '_points', 'tags' => 'NAME="option_' . $optionname . '_points" ID="option_' . $optionname . '_points"', 'type' => 'number', 'value' => qa_opt($optionname . '_points'), 'prefix' => qa_lang_html('admin/users_must_have') . '&nbsp;', 'note' => qa_lang_html('admin/points'));
             $checkboxtodisplay[$optionname . '_points'] = '(option_' . $optionname . '==' . qa_js(QA_PERMIT_POINTS) . ') ||(option_' . $optionname . '==' . qa_js(QA_PERMIT_POINTS_CONFIRMED) . ')';
         }
         qa_set_display_rules($this->content, $checkboxtodisplay);
     }
     $this->expert_user = $this->is_expert_user();
     if (!$this->expert_user) {
         foreach ($this->content['navigation']['main'] as $key => $nav) {
             if ($nav['url'] == qa_path_html(qa_opt('expert_question_page_url'))) {
                 unset($this->content['navigation']['main'][$key]);
             }
         }
     }
     if (qa_clicked('do_expert_answeradd') && ($this->expert_user || $this->content['q_view']['raw']['userid'] === qa_get_logged_in_userid())) {
         global $qa_login_userid, $questionid, $question, $answers, $question, $qa_request;
         $innotify = qa_post_text('notify') ? true : false;
         $inemail = qa_post_text('email');
         qa_get_post_content('editor', 'content', $ineditor, $incontent, $informat, $intext);
         $isduplicate = false;
         foreach ($answers as $answer) {
             if (!$answer['hidden']) {
                 if (implode(' ', qa_string_to_words($answer['content'])) == implode(' ', qa_string_to_words($incontent))) {
                     $isduplicate = true;
                 }
             }
         }
         if (!$isduplicate) {
             if (!isset($qa_login_userid)) {
                 $qa_cookieid = qa_cookie_get_create();
             }
             // create a new cookie if necessary
             $answerid = qa_answer_create($qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $incontent, $informat, $intext, $innotify, $inemail, $question);
             qa_report_write_action($qa_login_userid, $qa_cookieid, 'a_post', $questionid, $answerid, null);
             qa_redirect($qa_request, null, null, null, qa_anchor('A', $answerid));
         } else {
             $pageerror = qa_lang_html('question/duplicate_content');
         }
         qa_page_q_load_q();
         // reload since we may have changed something
     }
     if (qa_opt('expert_question_enable')) {
         if ($this->expert_user && qa_opt('expert_question_show_count')) {
             $this->expertcount = qa_db_read_one_value(qa_db_query_sub("SELECT COUNT(postid) FROM ^postmeta, ^posts WHERE ^postmeta.meta_key='is_expert_question' AND ^postmeta.post_id=^posts.postid AND ^posts.acount=0" . (is_array($this->expert_user) ? " AND ^posts.categoryid IN (#)" : " AND \$"), $this->expert_user), true);
             if ($this->expertcount) {
                 foreach ($this->content['navigation']['main'] as $key => $nav) {
                     if ($nav['url'] == qa_path_html(qa_opt('expert_question_page_url'))) {
                         $this->content['navigation']['main'][$key]['label'] .= ' (' . $this->expertcount . ')';
                     }
                 }
             }
         }
         global $qa_request;
         if ($qa_request == qa_opt('expert_question_page_url')) {
             $this->content['navigation']['sub'] = array('special' => 1);
         }
         if ($this->template == 'ask' && in_array(qa_opt('expert_question_type'), array(0, 2)) && !qa_user_permit_error('permit_post_q') && !qa_permit_value_error(qa_opt('expert_question_ask'), qa_get_logged_in_userid(), qa_get_logged_in_level(), qa_get_logged_in_flags()) && !qa_opt('site_maintenance')) {
             $this->content['form']['fields'][] = array('tags' => 'NAME="is_expert_question" ID="is_expert_question"', 'value' => qa_get(qa_opt('expert_question_page_url')) == 'true' ? qa_opt('expert_question_yes') : qa_opt('expert_question_no'), 'type' => 'select-radio', 'options' => array('no' => qa_opt('expert_question_no'), 'yes' => qa_opt('expert_question_yes')));
         }
         if ($this->template == 'user' && qa_get_logged_in_handle() === $this->_user_handle()) {
             if (!isset($this->content['navigation']['sub'])) {
                 $this->content['navigation']['sub'] = array('profile' => array('url' => qa_path_html('user/' . $this->_user_handle(), null, qa_opt('site_url')), 'label' => $this->_user_handle(), 'selected' => !qa_get('tab') ? true : false), qa_opt('expert_question_page_url') => array('url' => qa_path_html('user/' . $this->_user_handle(), array('tab' => qa_opt('expert_question_page_url')), qa_opt('site_url')), 'label' => qa_opt('expert_question_page_title'), 'selected' => qa_get('tab') == qa_opt('expert_question_page_url') ? true : false));
             } else {
                 $this->content['navigation']['sub'][qa_opt('expert_question_page_url')] = array('url' => qa_path_html('user/' . $this->_user_handle(), array('tab' => qa_opt('expert_question_page_url')), qa_opt('site_url')), 'label' => qa_opt('expert_question_page_title'), 'selected' => qa_get('tab') == qa_opt('expert_question_page_url') ? true : false);
             }
         }
         if ($this->template == 'question') {
             $qid = $this->content['q_view']['raw']['postid'];
             $expert = qa_db_read_one_value(qa_db_query_sub("SELECT meta_value FROM ^postmeta WHERE meta_key='is_expert_question' AND post_id=#", $qid), true);
             if ($expert) {
                 // is expert question
                 $this->expert_question = 1;
                 // modify post elements
                 // title
                 $this->content['title'] .= ' ' . qa_opt('expert_question_title');
                 // css class
                 $this->content['q_view']['tags'] .= ' class="qa-expert-question"';
                 // remove hidden stuff
                 unset($this->content['q_view']['hidden']);
                 unset($this->content['hidden']);
             }
         }
     }
     qa_html_theme_base::doctype();
 }
开发者ID:rkarimabadi,项目名称:q2a-expert-questions,代码行数:100,代码来源:qa-expert-layer.php

示例13: qa_q_request

function qa_q_request($questionid, $title)
{
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    $words = qa_string_to_words($title, true, false, false);
    $wordlength = array();
    foreach ($words as $index => $word) {
        $wordlength[$index] = qa_strlen($word);
    }
    $remaining = qa_opt('q_urls_title_length');
    if (array_sum($wordlength) > $remaining) {
        arsort($wordlength, SORT_NUMERIC);
        // sort with longest words first
        foreach ($wordlength as $index => $length) {
            if ($remaining > 0) {
                $remaining -= $length;
            } else {
                unset($words[$index]);
            }
        }
    }
    $title = implode('-', $words);
    if (qa_opt('q_urls_remove_accents')) {
        $title = qa_string_remove_accents($title);
    }
    return (int) $questionid . '/' . $title;
}
开发者ID:TheProjecter,项目名称:microprobe,代码行数:26,代码来源:qa-base.php

示例14: qa_get_tags_field_value

function qa_get_tags_field_value($fieldname)
{
    require_once QA_INCLUDE_DIR . 'util/string.php';
    $text = qa_remove_utf8mb4(qa_post_text($fieldname));
    if (qa_opt('tag_separator_comma')) {
        return array_unique(preg_split('/\\s*,\\s*/', trim(qa_strtolower(strtr($text, '/', ' '))), -1, PREG_SPLIT_NO_EMPTY));
    } else {
        return array_unique(qa_string_to_words($text, true, false, false, false));
    }
}
开发者ID:amiyasahu,项目名称:question2answer,代码行数:10,代码来源:format.php

示例15: qa_post_text

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/
require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
require_once QA_INCLUDE_DIR . 'qa-util-string.php';
//	Collect the information we need from the database
$intitle = qa_post_text('title');
$doaskcheck = qa_opt('do_ask_check_qs');
$doexampletags = qa_using_tags() && qa_opt('do_example_tags');
if ($doaskcheck || $doexampletags) {
    $countqs = max($doexampletags ? QA_DB_RETRIEVE_ASK_TAG_QS : 0, $doaskcheck ? qa_opt('page_size_ask_check_qs') : 0);
    $relatedquestions = qa_db_select_with_pending(qa_db_search_posts_selectspec(null, qa_string_to_words($intitle), null, null, null, null, 0, false, $countqs));
}
//	Collect example tags if appropriate
if ($doexampletags) {
    require_once QA_INCLUDE_DIR . 'qa-app-format.php';
    $tagweight = array();
    foreach ($relatedquestions as $question) {
        $tags = qa_tagstring_to_tags($question['tags']);
        foreach ($tags as $tag) {
            @($tagweight[$tag] += exp($question['score']));
        }
    }
    arsort($tagweight, SORT_NUMERIC);
    $exampletags = array();
    $minweight = exp(qa_match_to_min_score(qa_opt('match_example_tags')));
    $maxcount = qa_opt('page_size_ask_tags');
开发者ID:ramo01,项目名称:1kapp,代码行数:31,代码来源:qa-ajax-asktitle.php


注:本文中的qa_string_to_words函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。