本文整理汇总了PHP中get_topic函数的典型用法代码示例。如果您正苦于以下问题:PHP get_topic函数的具体用法?PHP get_topic怎么用?PHP get_topic使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_topic函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: beforeSendRepost
public function beforeSendRepost($param)
{
//检测话题的存在性
$topic = get_topic($param['content']);
if (isset($topic) && !is_null($topic)) {
foreach ($topic as $e) {
$tik = D('Weibo/Topic')->where(array('name' => $e))->find();
//没有这个话题的时候创建这个话题
if (!$tik) {
D('Weibo/Topic')->add(array('name' => $e));
}
}
}
}
开发者ID:suhanyujie,项目名称:digitalOceanVps,代码行数:14,代码来源:InsertTopicAddon.class.php
示例2: addTopic
public function addTopic(&$content)
{
//检测话题的存在性
$topic = get_topic($content);
if (isset($topic) && !is_null($topic)) {
foreach ($topic as $e) {
$tik = $this->where(array('name' => $e))->find();
//没有这个话题的时候创建这个话题
if (!$tik) {
$this->add(array('name' => $e));
}
}
}
}
开发者ID:terrydeng,项目名称:beimeibang1205,代码行数:14,代码来源:TopicModel.class.php
示例3: parse_topic
function parse_topic($content)
{
//找出话题
$topic = get_topic($content);
//将##替换成链接
foreach ($topic as $e) {
$tik = D('Weibo/Topic')->where(array('name' => $e))->find();
//没有这个话题的时候创建这个话题
if ($tik) {
//D('Weibo/Topic')->add(array('name'=> $e));
$space_url = U('Weibo/Topic/index', array('topk' => urlencode($e)));
$content = str_replace("#{$e}#", "<a href=\"{$space_url}\" target=\"_blank\">#{$e}# </a>", $content);
}
}
//返回替换的文本
return $content;
}
开发者ID:xiaolw,项目名称:wacms,代码行数:17,代码来源:parse.php
示例4: mod_notification_new_post
function mod_notification_new_post()
{
global $bbdb, $topic_id, $bb_current_user;
$all_moderators = notification_select_all_mods();
$topic = get_topic($topic_id);
$header = 'From: ' . bb_get_option('name') . ' <' . bb_get_option('from_email') . '>';
$header .= 'MIME-Version: 1.0' . "\n";
$header .= 'Content-Type: text/plain; charset="' . BBDB_CHARSET . '"' . "\n";
$header .= 'Content-Transfer-Encoding: 7bit' . "\n";
$subject = '[DHAnswers] New Post';
foreach ($all_moderators as $userdata) {
if (mod_notification_is_activated($userdata->ID)) {
$msg = "Hello,\n\nA new post has been added to \"" . $topic->topic_title . "\" at DHAnswers. \n\n" . get_topic_link($topic_id);
mail($userdata->user_email, $subject, $msg, $header);
}
}
}
开发者ID:achorg,项目名称:DH-Answers,代码行数:17,代码来源:moderator_notification.php
示例5: bb_auth
<?php
require './bb-load.php';
bb_auth('logged_in');
if (!bb_is_user_logged_in()) {
bb_die(__('You need to be logged in to add a tag.'));
}
$topic_id = (int) @$_POST['id'];
$page = (int) @$_POST['page'];
$tag = @$_POST['tag'];
$tag = stripslashes($tag);
bb_check_admin_referer('add-tag_' . $topic_id);
if (!($topic = get_topic($topic_id))) {
bb_die(__('Topic not found.'));
}
if (bb_add_topic_tags($topic_id, $tag)) {
nxt_redirect(get_topic_link($topic_id, $page));
} else {
bb_die(__('The tag was not added. Either the tag name was invalid or the topic is closed.'));
}
exit;
开发者ID:nxtclass,项目名称:NXTClass,代码行数:21,代码来源:tag-add.php
示例6: ass_group_notification_forum_posts
/**
* When a new forum topic or post is posted in bbPress, either:
* 1) Send emails to all group subscribers
* 2) Prepares to record it for digest purposes - see {@link ass_group_forum_record_digest()}.
*
* Hooks into the bbPress action - 'bb_new_post' - to easily identify new forum posts vs edits.
*/
function ass_group_notification_forum_posts($post_id)
{
global $bp, $wpdb;
$post = bb_get_post($post_id);
// Check to see if user has been registered long enough
if (!ass_registered_long_enough($post->poster_id)) {
return;
}
$topic = get_topic($post->topic_id);
$group = groups_get_current_group();
// if the current group isn't available, grab it
if (empty($group)) {
// get the group ID by looking up the forum ID in the groupmeta table
$group_id = $wpdb->get_var($wpdb->prepare("\n\t\t\t\tSELECT group_id\n\t\t\t\tFROM {$bp->groups->table_name_groupmeta}\n\t\t\t\tWHERE meta_key = %s\n\t\t\t\tAND meta_value = %d\n\t\t\t", 'forum_id', $topic->forum_id));
// now get the group
$group = groups_get_group(array('group_id' => $group_id));
}
$primary_link = trailingslashit(bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug);
$blogname = '[' . get_blog_option(BP_ROOT_BLOG, 'blogname') . ']';
$is_topic = false;
// initialize faux activity object for backpat filter reasons
//
// due to r-a-y being an idiot here:
// https://github.com/boonebgorges/buddypress-group-email-subscription/commit/526b80c617fe9058a859ac4eb4cfb1d42d333aa0
//
// because we moved the email recording process to 'bb_new_post' from the BP activity save hook,
// we need to ensure that 3rd-party code will continue to work as-is
//
// we can't add the 'id' because we're firing the filters before the activity item is created :(
$activity = new stdClass();
$activity->user_id = $post->poster_id;
$activity->component = 'groups';
$activity->item_id = $group->id;
$activity->content = $post->post_text;
// this is a new topic
if ($post->post_position == 1) {
$is_topic = true;
// more faux activity items!
$activity->type = 'new_forum_topic';
$activity->secondary_item_id = $topic->topic_id;
$activity->primary_link = $primary_link;
$action = $activity->action = sprintf(__('%s started the forum topic "%s" in the group "%s"', 'bp-ass'), bp_core_get_user_displayname($post->poster_id), $topic->topic_title, $group->name);
$subject = apply_filters('bp_ass_new_topic_subject', $action . ' ' . $blogname, $action, $blogname);
$the_content = apply_filters('bp_ass_new_topic_content', $post->post_text, $activity, $topic, $group);
} else {
// more faux activity items!
$activity->type = 'new_forum_post';
$activity->secondary_item_id = $post_id;
$action = $activity->action = sprintf(__('%s replied to the forum topic "%s" in the group "%s"', 'bp-ass'), bp_core_get_user_displayname($post->poster_id), $topic->topic_title, $group->name);
// calculate the topic page for pagination purposes
$pag_num = apply_filters('bp_ass_topic_pag_num', 15);
$page = ceil($topic->topic_posts / $pag_num);
if ($page > 1) {
$primary_link .= '?topic_page=' . $page;
}
$primary_link .= "#post-" . $post_id;
$activity->primary_link = $primary_link;
$subject = apply_filters('bp_ass_forum_reply_subject', $action . ' ' . $blogname, $action, $blogname);
$the_content = apply_filters('bp_ass_forum_reply_content', $post->post_text, $activity, $topic, $group);
}
// Convert entities and do other cleanup
$the_content = ass_clean_content($the_content);
// if group is not public, change primary link to login URL to verify
// authentication and for easier redirection after logging in
if ($group->status != 'public') {
$primary_link = ass_get_login_redirect_url($primary_link, 'legacy_forums_view');
$text_before_primary = __('To view or reply to this topic, go to:', 'bp-ass');
// if public, show standard text
} else {
$text_before_primary = __('To view or reply to this topic, log in and go to:', 'bp-ass');
}
// setup the email meessage
$message = sprintf(__('%s
"%s"
%s
%s
---------------------
', 'bp-ass'), $action . ':', $the_content, $text_before_primary, $primary_link);
// get subscribed users
$subscribed_users = groups_get_groupmeta($group->id, 'ass_subscribed_users');
// do this for forum replies only
if (!$is_topic) {
// pre-load these arrays to reduce db calls in the loop
$ass_replies_to_my_topic = ass_user_settings_array('ass_replies_to_my_topic');
$ass_replies_after_me_topic = ass_user_settings_array('ass_replies_after_me_topic');
$previous_posters = ass_get_previous_posters($post->topic_id);
// make sure manually-subscribed topic users and regular group subscribed users are combined
$user_topic_status = groups_get_groupmeta($group->id, 'ass_user_topic_status_' . $topic->topic_id);
if (!empty($subscribed_users) && !empty($user_topic_status)) {
$subscribed_users = $subscribed_users + $user_topic_status;
//.........这里部分代码省略.........
开发者ID:pausaura,项目名称:agora_nodes,代码行数:101,代码来源:bp-activity-subscription-functions.php
示例7: _e
<h3 id="useractivity"><?php
_e('User Activity');
?>
</h3>
<div id="user-replies" class="user-recent"><h4><?php
_e('Recent Replies');
?>
</h4>
<?php
if ($posts) {
?>
<ol>
<?php
foreach ($posts as $bb_post) {
$topic = get_topic($bb_post->topic_id);
?>
<li<?php
alt_class('replies');
?>
>
<a href="<?php
topic_link();
?>
"><?php
topic_title();
?>
</a> -
<?php
if ($user->ID == bb_get_current_user_info('id')) {
printf(__('You last replied: %s ago'), bb_get_post_time());
开发者ID:laiello,项目名称:cartonbank,代码行数:31,代码来源:profile.php
示例8: get_topic
<?php
require 'admin-action.php';
$topic_id = (int) $_GET['id'];
$topic = get_topic($topic_id);
if (!$topic) {
bb_die(__('There is a problem with that topic, pardner.'));
}
if (!bb_current_user_can('close_topic', $topic_id)) {
nxt_redirect(bb_get_uri(null, null, BB_URI_CONTEXT_HEADER));
exit;
}
bb_check_admin_referer('close-topic_' . $topic_id);
if (topic_is_open($topic_id)) {
bb_close_topic($topic_id);
$message = 'closed';
} else {
bb_open_topic($topic_id);
$message = 'opened';
}
if ($sendto = nxt_get_referer()) {
$sendto = remove_query_arg('message', $sendto);
$sendto = add_query_arg('message', $message, $sendto);
} else {
$sendto = get_topic_link($topic_id);
}
bb_safe_redirect($sendto);
exit;
开发者ID:nxtclass,项目名称:NXTClass-Plugin,代码行数:28,代码来源:topic-toggle.php
示例9: bb_ksd_new_post
function bb_ksd_new_post($post_id)
{
global $bb_ksd_pre_post_status;
if ('2' != $bb_ksd_pre_post_status) {
return;
}
$bb_post = bb_get_post($post_id);
$topic = get_topic($bb_post->topic_id);
if (0 == $topic->topic_posts) {
bb_delete_topic($topic->topic_id, 2);
}
}
开发者ID:laiello,项目名称:cartonbank,代码行数:12,代码来源:akismet.php
示例10: parse_topic
function parse_topic($content)
{
//找出话题
$topic = get_topic($content);
//将##替换成链接
foreach ($topic as $e) {
$tik = D('Weibo/Topic')->where(array('name' => $e))->find();
//没有这个话题的时候创建这个话题
if ($tik) {
//D('Weibo/Topic')->add(array('name'=> $e));
$space_url = U('Weibo/Topic/index', array('topk' => urlencode($e)));
if (modC('HIGH_LIGHT_TOPIC', 1, 'Weibo')) {
$content = str_replace("#{$e}#", " <a class='label label-badge label-info' href=\"{$space_url}\" target=\"_blank\">#{$e}# </a> ", $content);
} else {
$content = str_replace("#{$e}#", " <a href=\"{$space_url}\" target=\"_blank\">#{$e}# </a> ", $content);
}
}
}
//返回替换的文本
return $content;
}
开发者ID:ccccy,项目名称:wuanlife,代码行数:21,代码来源:function.php
示例11: bb_get_topic_tags
/**
* bb_get_topic_tags() - Returns all of the bb_topic_tags associated with the specified topic.
*
* @param int $topic_id
* @param mixed $args
* @return array|false Term objects (back-compat), false on failure
*/
function bb_get_topic_tags($topic_id = 0, $args = null)
{
global $wp_taxonomy_object;
if (!($topic = get_topic(get_topic_id($topic_id)))) {
return false;
}
$topic_id = (int) $topic->topic_id;
$cache_id = $topic_id . serialize($args);
$terms = wp_cache_get($cache_id, 'bb_topic_tag_terms');
if (false === $terms) {
$terms = $wp_taxonomy_object->get_object_terms((int) $topic->topic_id, 'bb_topic_tag', $args);
wp_cache_set($cache_id, $terms, 'bb_topic_tag_terms');
}
if (is_wp_error($terms)) {
return false;
}
for ($i = 0; isset($terms[$i]); $i++) {
_bb_make_tag_compat($terms[$i]);
}
return $terms;
}
开发者ID:hscale,项目名称:webento,代码行数:28,代码来源:functions.bb-topic-tags.php
示例12: bb_add_user_favorite
function bb_add_user_favorite($user_id, $topic_id)
{
global $bbdb;
$user_id = (int) $user_id;
$topic_id = (int) $topic_id;
$user = bb_get_user($user_id);
$topic = get_topic($topic_id);
if (!$user || !$topic) {
return false;
}
$favorites_key = $bbdb->prefix . 'favorites';
$fav = $user->{$favorites_key} ? explode(',', $user->{$favorites_key}) : array();
if (!in_array($topic_id, $fav)) {
$fav[] = $topic_id;
$fav = implode(',', $fav);
bb_update_usermeta($user->ID, $favorites_key, $fav);
}
do_action('bb_add_user_favorite', $user_id, $topic_id);
return true;
}
开发者ID:danielcoats,项目名称:schoolpress,代码行数:20,代码来源:functions.bb-users.php
示例13: view_increment
$page_no_var = $var;
//get the current Page from URL
}
}
//--increment views of poem--//
$update_poem = view_increment($database, $poem_id);
//--get poem information--//
$get_poem = get_poem($database, $poem_id);
//--get topic information--//
if ($get_poem['topic_id']) {
$poem_topics_array = array();
//get topic ids as array
$poem_topics = unserialize($get_poem['topic_id']);
foreach ($poem_topics as $poem_topic_id) {
if (!array_key_exists($poem_topic_id, $poem_topics_array)) {
$poem_topic_array[$poem_topic_id] = get_topic($database, $poem_topic_id);
}
}
$get_poem['topic_id'] = $poem_topic_array;
}
//--get author information--//
// $author_id = $get_poem['author_id'];
// if($get_poem['author_id']){
// $get_poem['author_id'] = get_author($database, $get_poem['author_id']);
// $tpl->author_info = $get_poem['author_id'];
// //get_user_info
// // submitter_id
// }
$submitter_id = $get_poem['submitter_id'];
if ($get_poem['submitter_id']) {
$data = get_user_info($database, $get_poem['submitter_id']);
开发者ID:ronak2ram,项目名称:fnji,代码行数:31,代码来源:phpfunction.php
示例14: bb_export_topic_posts
function bb_export_topic_posts($r, $topic_id)
{
if (!get_topic($topic_id)) {
return;
}
$r .= "\n";
$page = 1;
while ($posts = get_thread($topic_id, array('post_status' => 'all', 'page' => $page++))) {
foreach ($posts as $post) {
$r .= bb_export_post($post->post_id);
}
}
return $r;
}
开发者ID:nxtclass,项目名称:NXTClass-Plugin,代码行数:14,代码来源:export.php
示例15: blocklist_check
function blocklist_check($post_id = 0, $wall = false)
{
if (bb_current_user_can('moderate') || bb_current_user_can('throttle')) {
return;
}
if ($wall) {
$bb_post = user_wall_get_post($post_id);
} else {
$bb_post = bb_get_post($post_id);
}
if (empty($post_id) || empty($bb_post) || !empty($bb_post->post_status)) {
return;
}
global $blocklist, $bbdb;
blocklist_initialize();
if (empty($blocklist['data'])) {
return;
}
(array) ($data = explode("\r\n", $blocklist['data']));
$user = bb_get_user($bb_post->poster_id);
foreach ($data as $item) {
if (empty($item) || strlen($item) < 4 || ord($item) == 35) {
continue;
}
if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/', $item)) {
// is IP
if (strpos($bb_post->poster_ip, $item) === 0) {
$found = "IP address";
$bad = $item;
break;
}
} else {
// is word
$qitem = preg_quote($item);
if (preg_match('/\\b' . $qitem . '/simU', $user->user_email)) {
$found = "email";
$bad = $item;
break;
}
if (preg_match('/\\b' . $qitem . '/simU', $user->user_login)) {
$found = "username";
$bad = $item;
break;
}
if (preg_match('/\\b' . $qitem . '/simU', $bb_post->post_text)) {
$found = "post text";
$bad = $item;
break;
} elseif (!$wall && $bb_post->post_position == 1) {
if (empty($topic)) {
$topic = get_topic($bb_post->topic_id);
}
if (!empty($topic->topic_title) && preg_match('/\\b' . $qitem . '/simU', $topic->topic_title)) {
$found = "topic title";
$bad = $item;
break;
}
}
}
if (!empty($bad)) {
break;
}
}
if (!empty($bad)) {
if ($wall) {
user_wall_delete_post($post_id, 2);
$uri = bb_get_option('uri') . "bb-admin/admin-base.php?post_status=2&plugin=user_wall_admin&user-wall-recent=1";
} else {
bb_delete_post($post_id, 2);
if (empty($topic)) {
$topic = get_topic($bb_post->topic_id);
}
if (empty($topic->topic_posts)) {
bb_delete_topic($topic->topic_id, 2);
}
// if no posts in topic, also set topic to spam
$uri = bb_get_option('uri') . 'bb-admin/' . (defined('BACKPRESS_PATH') ? '' : 'content-') . 'posts.php?post_status=2';
}
if (empty($blocklist['email'])) {
return;
}
(array) ($email = explode("\r\n", $blocklist['email']));
$message = "The blocklist has been triggered... \r\n\r\n";
$message .= "Matching entry " . '"' . $bad . '"' . " found in {$found}.\r\n";
$message .= "{$uri}\r\n\r\n";
$message .= sprintf(__('Username: %s'), stripslashes($user->user_login)) . "\r\n";
$message .= sprintf(__('Profile: %s'), get_user_profile_link($user->ID)) . "\r\n";
$message .= sprintf(__('Email: %s'), stripslashes($user->user_email)) . "\r\n";
$message .= sprintf(__('IP address: %s'), $_SERVER['REMOTE_ADDR']) . "\r\n";
$message .= sprintf(__('Agent: %s'), substr(stripslashes($_SERVER["HTTP_USER_AGENT"]), 0, 255)) . "\r\n\r\n";
foreach ($email as $to) {
if (empty($to) || strlen($to) < 8) {
continue;
}
@bb_mail($to, "[" . bb_get_option('name') . "] blocklist triggered", $message);
}
}
}
开发者ID:achorg,项目名称:DH-Answers,代码行数:98,代码来源:blocklist.php
示例16: bb_subscription_management
/**
* Updates user's subscription status in database.
*
* Gets user's new subscription status for topic and
* adds new status to database.
*
* @since 1.1
*
* @param int $topic_id ID of topic for subscription
* @param string $new_status New subscription status
* @param int $user_id Optional. ID of user for subscription
*/
function bb_subscription_management($topic_id, $new_status, $user_id = '')
{
global $bbdb, $nxt_taxonomy_object;
$topic = get_topic($topic_id);
if (!$user_id) {
$user_id = bb_get_current_user_info('id');
}
do_action('bb_subscripton_management', $topic_id, $new_status, $user_id);
switch ($new_status) {
case 'add':
$tt_ids = $nxt_taxonomy_object->set_object_terms($user_id, 'topic-' . $topic->topic_id, 'bb_subscribe', array('append' => true, 'user_id' => $user_id));
break;
case 'remove':
// I hate this with the passion of a thousand suns
$term_id = $bbdb->get_var("SELECT term_id FROM {$bbdb->terms} WHERE slug = 'topic-{$topic->topic_id}'");
$term_taxonomy_id = $bbdb->get_var("SELECT term_taxonomy_id FROM {$bbdb->term_taxonomy} WHERE term_id = {$term_id} AND taxonomy = 'bb_subscribe'");
$bbdb->query("DELETE FROM {$bbdb->term_relationships} WHERE object_id = {$user_id} AND term_taxonomy_id = {$term_taxonomy_id}");
$bbdb->query("DELETE FROM {$bbdb->term_taxonomy} WHERE term_id = {$term_id} AND taxonomy = 'bb_subscribe'");
break;
}
}
开发者ID:nxtclass,项目名称:NXTClass,代码行数:33,代码来源:functions.bb-posts.php
示例17: ac_notifier_remove_notification_for_topic
/**
* @since 1.0.3
* it is not used any more because qwe are linking to threaded view
* Remove notification for group forum posts/new topic
*/
function ac_notifier_remove_notification_for_topic()
{
global $bp;
//is group & group forum active ?
if (!(bp_is_active("groups") && bp_is_active("forums"))) {
return;
}
//if either group or forum is not actuive do not do anything
//check if we are on single topic screen, right?
if (bp_is_group_forum_topic() && is_user_logged_in()) {
$topic_id = bp_forums_get_topic_id_from_slug($bp->action_variables[1]);
//get id from slug
$topic = get_topic($topic_id);
$group_id = $bp->groups->current_group->id;
//find activity id for this topic
$activity_id = bp_activity_get_activity_id(array('user_id' => $topic->poster_id, 'component' => $bp->groups->id, 'type' => "new_forum_topic", "item_id" => $group_id, 'secondary_item_id' => $topic_id));
//remove notification for new topic comments: easy
if (!empty($activity_id)) {
bp_core_delete_notifications_by_item_id($bp->loggedin_user->id, $activity_id, $bp->ac_notifier->id, 'new_activity_comment_' . $activity_id);
}
$posts = ac_notifier_get_forum_post_ids($topic_id);
if (!empty($posts)) {
//find all activities for the post
$activities = ac_notifier_get_activity_ids(array("item_id" => $group_id, "secondary_ids" => $posts, "component" => $bp->groups->id, "type" => "new_forum_post"));
//pass the array
foreach ((array) $activities as $ac_id) {
bp_core_delete_notifications_by_item_id($bp->loggedin_user->id, $ac_id, $bp->ac_notifier->id, 'new_activity_comment_' . $ac_id);
}
}
}
}
开发者ID:pyropictures,项目名称:wordpress-plugins,代码行数:36,代码来源:ac-notify.php
示例18: bb_get_tag_remove_link
function bb_get_tag_remove_link($args = null)
{
if (is_scalar($args) || is_object($args)) {
$args = array('tag' => $args);
}
$defaults = array('tag' => 0, 'topic' => 0, 'list_id' => 'tags-list');
$args = wp_parse_args($args, $defaults);
extract($args, EXTR_SKIP);
if (is_object($tag) && isset($tag->tag_id)) {
} elseif (!($tag = bb_get_tag(bb_get_tag_id($tag)))) {
return false;
}
if (!($topic = get_topic(get_topic_id($topic)))) {
return false;
}
if (!bb_current_user_can('edit_tag_by_on', $tag->user_id, $topic->topic_id)) {
return false;
}
$url = bb_get_uri('tag-remove.php', array('tag' => $tag->tag_id, 'user' => $tag->user_id, 'topic' => $topic->topic_id));
$url = esc_url(bb_nonce_url($url, 'remove-tag_' . $tag->tag_id . '|' . $topic->topic_id));
$title = esc_attr__('Remove this tag');
$list_id = esc_attr($list_id);
return "[<a href='{$url}' class='delete:{$list_id}:tag-{$tag->tag_id}_{$tag->user_id}' title='{$title}'>×</a>]";
}
开发者ID:abc2mit,项目名称:abc2mit.github.io,代码行数:24,代码来源:functions.bb-template.php
示例19: get_topic
function get_topic($topic_id, $use_cache = true)
{
bb_log_deprecated('class::function', __CLASS__ . '::' . __FUNCTION__, 'get_topic');
return get_topic($topic_id, $use_cache);
}
开发者ID:nxtclass,项目名称:NXTClass,代码行数:5,代码来源:functions.bb-deprecated.php
示例20: find_aiml_matches
/**
* function find_aiml_matches()
* This function builds the sql to use to get a match from the tbl
* @param array $convoArr - conversation array
* @return array $convoArr
**/
function find_aiml_matches($convoArr)
{
global $dbConn, $dbn, $error_response, $use_parent_bot;
runDebug(__FILE__, __FUNCTION__, __LINE__, "Finding the aiml matches from the DB", 4);
$i = 0;
//TODO convert to get_it
$bot_id = $convoArr['conversation']['bot_id'];
$bot_parent_id = $convoArr['conversation']['bot_parent_id'];
$default_aiml_pattern = $convoArr['conversation']['default_aiml_pattern'];
#$lookingfor = get_convo_var($convoArr,"aiml","lookingfor");
$convoArr['aiml']['lookingfor'] = str_replace(' ', ' ', $convoArr['aiml']['lookingfor']);
$lookingfor = trim(strtoupper($convoArr['aiml']['lookingfor']));
//get the first and last words of the cleaned user input
$lastInputWord = get_last_word($lookingfor);
$firstInputWord = get_first_word($lookingfor);
//get the stored topic
$storedtopic = get_topic($convoArr);
runDebug(__FILE__, __FUNCTION__, __LINE__, "Stored topic = '{$storedtopic}'", 4);
//get the cleaned user input
$lastthat = isset($convoArr['that'][1][1]) ? $convoArr['that'][1][1] : '';
//build like patterns
if ($lastthat != '') {
$thatPatternSQL = " OR " . make_like_pattern($lastthat, 'thatpattern');
$thatPatternSQL = rtrim($thatPatternSQL, ' OR');
} else {
$thatPattern = '';
$thatPatternSQL = '';
}
//get the word count
$word_count = wordsCount_inSentence($lookingfor);
if ($bot_parent_id != 0 and $bot_parent_id != $bot_id) {
$sql_bot_select = " (bot_id = '{$bot_id}' OR bot_id = '{$bot_parent_id}') ";
} else {
$sql_bot_select = " bot_id = '{$bot_id}' ";
}
if (!empty($storedtopic)) {
$topic_select = "AND (`topic`='' OR `topic`='{$storedtopic}')";
} else {
$topic_select = '';
}
if ($word_count == 1) {
//if there is one word do this
$sql = "SELECT `id`, `pattern`, `thatpattern`, `topic` FROM `{$dbn}`.`aiml` WHERE\n {$sql_bot_select} AND (\n `pattern` = '_' OR\n `pattern` = '*' OR\n `pattern` = '{$lookingfor}' OR\n `pattern` = '{$default_aiml_pattern}'\n {$thatPatternSQL}\n ) {$topic_select} order by `topic` desc, `pattern` asc, `thatpattern` asc,`id` asc;";
} else {
//otherwise do this
$sql_add = make_like_pattern($lookingfor, 'pattern');
$sql = "SELECT `id`, `bot_id`, `pattern`, `thatpattern`, `topic` FROM `{$dbn}`.`aiml` WHERE\n {$sql_bot_select} AND (\n `pattern` = '_' OR\n `pattern` = '*' OR\n `pattern` = '{$lookingfor}' OR {$sql_add} OR\n `pattern` = '{$default_aiml_pattern}'\n {$thatPatternSQL}\n ) {$topic_select}\n order by `topic` desc, `pattern` asc, `thatpattern` asc,`id` asc;";
}
runDebug(__FILE__, __FUNCTION__, __LINE__, "Core Match AIML sql: {$sql}", 3);
$result = db_fetchAll($sql, null, __FILE__, __FUNCTION__, __LINE__);
$num_rows = count($result);
if ($result && $num_rows > 0) {
$tmp_rows = number_format($num_rows);
runDebug(__FILE__, __FUNCTION__, __LINE__, "FOUND: ({$num_rows}) potential AIML matches", 2);
$tmp_content = date('H:i:s') . ": SQL:\n{$sql}\nRows = {$tmp_rows}\n\n";
//loop through results
foreach ($result as $row) {
$row['aiml_id'] = $row['id'];
$row['bot_id'] = $bot_id;
$row['score'] = 0;
$row['track_score'] = '';
$allrows[] = $row;
$mu = memory_get_usage(true);
if ($mu >= MEM_TRIGGER) {
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Current operation exceeds memory threshold. Aborting data retrieval.', 0);
break;
}
}
} else {
runDebug(__FILE__, __FUNCTION__, __LINE__, "Error: FOUND NO AIML matches in DB", 1);
$allrows[$i]['aiml_id'] = "-1";
$allrows[$i]['bot_id'] = $bot_id;
$allrows[$i]['pattern'] = "no results";
$allrows[$i]['thatpattern'] = '';
$allrows[$i]['topic'] = '';
}
return $allrows;
}
开发者ID:ramdesh,项目名称:Program-O,代码行数:84,代码来源:find_aiml.php
注:本文中的get_topic函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论