/**
 * Insert notification in ap_meta table
 *
 * @param  integer  		$current_user_id   	User id of user triggering this hook
 * @param  integer  		$affected_user_id  	User id of user who is being affected
 * @param  string 			$notification_type 	Type of notification
 * @param  boolean|array 	$args              	arguments for the notification
 * @return integer|boolean
 */
function ap_insert_notification($current_user_id, $affected_user_id, $notification_type, $args = false)
{
    //if effected user id and current user id are same or is anonymous then return
    if ($affected_user_id <= 0 || $affected_user_id == $current_user_id) {
        return;
    }
    //Convert array to query string
    if ($args === false) {
        $args = array();
    }
    switch ($notification_type) {
        case 'new_answer':
        case 'question_update':
        case 'answer_update':
            $post = get_post($args['post_id']);
            $args['permalink'] = get_permalink($post->ID);
            $args['post_title'] = ap_truncate_chars($post->post_title, 50);
            break;
        case 'comment_on_question':
        case 'comment_on_answer':
            $post = get_post($args['post_id']);
            $args['permalink'] = get_comment_link($args['comment_id']);
            $args['post_title'] = ap_truncate_chars($post->post_title, 50);
            break;
        case 'vote_up':
            $post = get_post($args['post_id']);
            $args['user_id'] = $current_user_id;
            $args['permalink'] = get_permalink($post->ID);
            $args['post_title'] = ap_truncate_chars($post->post_title, 50);
            break;
        case 'new_follower':
            $args['permalink'] = ap_user_link($current_user_id);
            $args['user_id'] = $current_user_id;
            break;
        case 'answer_selected':
            $post = get_post($args['post_id']);
            $args['permalink'] = get_permalink($post->ID);
            $args['post_title'] = ap_truncate_chars($post->post_title, 50);
            break;
        case 'received_reputation':
            $args['reputation'] = $args['reputation'];
            $args['permalink'] = ap_user_link($affected_user_id, 'reputation');
            break;
        default:
            $args = apply_filters('ap_notification_args', $args, func_get_args());
            break;
    }
    $args = urlencode(strip_tags(build_query($args)));
    $row = ap_add_meta($current_user_id, 'unread_notification', $affected_user_id, $args, $notification_type);
    if ($row !== false) {
        do_action('ap_insert_notification', $current_user_id, $affected_user_id, $notification_type, $args);
    }
    return $row;
}
示例#2
0
 public function column_post_title($post)
 {
     if ($post->post_type == 'question') {
         $title = '<a href="' . esc_url(add_query_arg(array('post' => $post->ID, 'action' => 'edit'), 'post.php')) . '" class="row-title">' . $post->post_title . '</a>';
     } else {
         $title = '<a href="' . esc_url(add_query_arg(array('post' => $post->ID, 'action' => 'edit'), 'post.php')) . '" class="row-title">' . ap_truncate_chars(strip_tags($post->post_content), 80) . '</a>';
     }
     if ('trash' == $this->current_status) {
         $actions = array('untrash' => sprintf('<a href="%s">%s</a>', ap_untrash_post($post->ID), __('Restore', 'anspress-question-answer')), 'delete' => sprintf('<a href="%s">%s</a>', get_delete_post_link($post->ID, null, true), __('Delete permanently', 'anspress-question-answer')));
     } else {
         $actions = array('edit' => sprintf('<a href="%s">%s</a>', get_edit_post_link($post->ID), __('Edit', 'anspress-question-answer')), 'trash' => sprintf('<a href="%s">%s</a>', get_delete_post_link($post->ID), __('Trash', 'anspress-question-answer')), 'view' => sprintf('<a href="%s">%s</a>', get_permalink($post->ID), __('View', 'anspress-question-answer')));
     }
     return sprintf('%1$s %2$s', $title, $this->row_actions($actions));
 }
示例#3
0
 public function column_post_title($post)
 {
     $edit_flag = esc_url(add_query_arg(array('post_id' => $post->ID), 'admin.php?page=ap_post_flag'));
     if ($post->post_type == 'question') {
         $title = '<a href="' . $edit_flag . '" class="row-title">' . $post->post_title . '</a>';
     } else {
         $title = '<a href="' . $edit_flag . '" class="row-title">' . ap_truncate_chars(strip_tags($post->post_content), 80) . '</a>';
     }
     $actions = array();
     $actions['edit_flag'] = sprintf('<a href="%s">%s</a>', $edit_flag, __('Edit flags', 'ap'));
     if ('trash' == $this->current_status) {
         $actions['untrash'] = sprintf('<a href="%s">%s</a>', ap_untrash_post($post->ID), __('Restore', 'ap'));
         $actions['delete'] = sprintf('<a href="%s">%s</a>', get_delete_post_link($post->ID, null, true), __('Delete permanently', 'ap'));
     } else {
         $actions['edit'] = sprintf('<a href="%s">%s</a>', get_edit_post_link($post->ID), __('Edit', 'ap'));
         $actions['trash'] = sprintf('<a href="%s">%s</a>', get_delete_post_link($post->ID), __('Trash', 'ap'));
         $actions['view'] = sprintf('<a href="%s">%s</a>', get_permalink($post->ID), __('View', 'ap'));
     }
     return sprintf('%1$s %2$s', $title, $this->row_actions($actions));
 }
示例#4
0
function ap_conversations_list($recipient_id = false, $offset = 0, $limit = 10, $search = false)
{
    if (!$recipient_id) {
        $recipient_id = get_current_user_id();
    }
    if ($search) {
        $search_string = sanitize_text_field($_GET['s']);
        $conversation = ap_search_conversations($recipient_id, $search_string, $limit);
    } else {
        $conversation = ap_get_conversations($recipient_id, $offset, $limit);
    }
    if ($conversation) {
        $count = count($conversation);
        $i = 1;
        echo '<ul class="ap-conversations ap-nav">';
        foreach ($conversation as $message) {
            ?>
	
			<li class="<?php 
            echo $i == 1 ? 'active ' : '';
            ?>
clearfix" data-action="ap-show-conversation" data-args="<?php 
            echo wp_create_nonce('show-conversation') . '-' . $message->message_conversation;
            ?>
">
				<time><?php 
            printf(__('%s ago', 'ap'), ap_human_time($message->message_date, false));
            ?>
</time>				
				<div class="ap-avatar"><?php 
            echo ap_get_conversation_users_avatar($message->users);
            ?>
</div>
				<div class="ap-message-summery">
					<strong><?php 
            echo ap_get_conversation_users_name($message->users);
            ?>
</strong>
					<span>
						<span class="ap-last-action <?php 
            echo $message->message_sender == get_current_user_id() ? 'ap-icon-reply' : 'ap-icon-forward';
            ?>
"></span>
						<?php 
            echo ap_truncate_chars(strip_tags(stripcslashes($message->message_content)), 40);
            ?>
</span>
				</div>
			</li>			
		<?php 
            $i++;
        }
        if ($count < $limit) {
            echo '<li class="ap-no-more-message">' . __('There is no more messages to load', 'ap') . '</li>';
        }
        echo '</ul>';
    }
    ap_total_conversations($recipient_id);
}
示例#5
0
function ap_get_user_question_list($user_id, $limit = 5, $title_limit = 50)
{
    $q_args = array('post_type' => 'question', 'post_status' => 'publish', 'author' => $user_id, 'showposts' => $limit);
    $questions = get_posts($q_args);
    $o = '<ul class="ap-user-answers-list">';
    foreach ($questions as $q) {
        $o .= '<li class="clearfix">';
        $o .= '<div class="ap-mini-counts">';
        $o .= ap_count_ans_meta($q->ID);
        $o .= '</div>';
        $o .= '<a class="ap-answer-title answer-hyperlink" href="' . get_permalink($q->ID) . '">' . ap_truncate_chars($q->post_title, $title_limit) . '</a>';
        $o .= '</li>';
    }
    $o .= '</ul>';
    return $o;
}
示例#6
0
									<span class="ap-sub-category">
									<?php 
        printf(_n('%d Sub category', '%d Sub categories', 'categories_for_anspress', $sub_cat_count), $sub_cat_count);
        ?>
									</span>
								<?php 
    }
    ?>
							</div>

							<?php 
    if ($category->description != '') {
        ?>
								<div class="ap-taxo-description">
									<?php 
        echo ap_truncate_chars($category->description, 70);
        ?>
								</div>
							<?php 
    }
    ?>
						</div>
					</li>
				<?php 
}
?>
			</ul>
		</div>
		<?php 
ap_pagination();
?>
示例#7
0
文件: addon.php 项目: jessor/anspress
 public function new_comment($comment, $post_type, $question_id)
 {
     $emails = ap_get_email_to_notify($comment->comment_post_ID, $comment->user_id);
     $post = get_post($question_id);
     if ($post_type == 'question') {
         $subject = __('New comment on: ', 'ap') . $post->post_title;
         $message = sprintf(__('Hello!,<br /><br /> A new comment is posted by %s <br />', 'ap'), ap_user_display_name($comment->user_id, true));
         $message .= ap_truncate_chars($comment->comment_content, 100);
         $message .= "<br /><br /><a href='" . get_comments_link($parent->ID) . "'>" . __('View comment', 'ap') . "</a><br />";
         $message .= '<p style="color:#777; font-size:11px">' . __('Powered by', 'ap') . '<a href="http://open-wp.com">AnsPress</a></p>';
         if (!empty($emails)) {
             foreach ($emails as $email) {
                 wp_mail($email, $subject, $message);
             }
         }
     } else {
         $subject = __('New comment on answer of: ', 'ap') . $post->post_title;
         $message = sprintf(__('Hello!,<br /><br /> A new comment is posted by %s <br />', 'ap'), ap_user_display_name($comment->user_id, true));
         $message .= ap_truncate_chars($comment->comment_content, 100);
         $message .= "<br /><br /><a href='" . get_comments_link($parent->ID) . "'>" . __('View comment', 'ap') . "</a><br />";
         $message .= '<p style="color:#777; font-size:11px">' . __('Powered by', 'ap') . '<a href="http://open-wp.com">AnsPress</a></p>';
         if (!empty($emails)) {
             foreach ($emails as $email) {
                 wp_mail($email, $subject, $message);
             }
         }
     }
 }
示例#8
0
?>
				</div>
				<div class="ap-meta">
					<?php 
printf(__('<span class="when">answered about %s ago</span>', 'ap'), ap_human_time(get_the_time('U')));
?>
							
				</div>			
			</div>
			<div class="answer-content">
				<strong class="ap-answer-title"><?php 
echo get_the_title($answer->post->post_parent);
?>
</strong>
				<?php 
echo ap_truncate_chars(strip_tags(get_the_content()), 100);
?>
				<div class="ap-ans-action">
					<a href="<?php 
echo ap_answer_edit_link();
?>
" class="edit-btn" title="<?php 
_e('Edit this question', 'ap');
?>
"><?php 
_e('Edit', 'ap');
?>
</a>
					
					<?php 
ap_flag_btn_html();
示例#9
0
 public function ap_suggest_tags()
 {
     $keyword = sanitize_text_field($_POST['q']);
     $tags = get_terms('question_tags', array('orderby' => 'count', 'order' => 'DESC', 'hide_empty' => false, 'search' => $keyword, 'number' => 8));
     if ($tags) {
         $items = array();
         foreach ($tags as $k => $t) {
             $items[$k]['id'] = $t->slug;
             $items[$k]['name'] = $t->name;
             $items[$k]['count'] = $t->count;
             $items[$k]['description'] = ap_truncate_chars($t->description, 80);
         }
         $result = array('status' => true, 'items' => $items, 'form' => '<div class="clearfix"></div><div class="ap-cntlabel"><a href="#" id="ap-load-new-tag-form" data-args="' . wp_create_nonce('new_tag_form') . '">' . __('Create new tag', 'ap') . '</a></div>');
     } else {
         $form = '';
         if (ap_user_can_create_tag()) {
             $form = '<div class="ap-esw warning">' . __('No tags found', 'ap') . '</div>' . ap_tag_form();
         }
         $result = array('status' => false, 'message' => __('No related tags found', 'ap'), 'form' => $form);
     }
     die(json_encode($result));
 }
 public function ap_after_update_question($question_id)
 {
     $current_user = wp_get_current_user();
     $question = get_post($question_id);
     $this->emails = array();
     if (ap_opt('notify_admin_email') != $current_user->user_email && ap_opt('notify_admin_edit_question')) {
         $this->emails[] = ap_opt('notify_admin_email');
     }
     $subscribers = ap_get_subscribers($question_id, array('q_post', 'q_all'), 100, true);
     $post_author = get_user_by('id', $post->post_author);
     if (!ap_in_array_r($post_author->data->user_email, $subscribers)) {
         $subscribers[] = (object) array('user_email' => $post_author->data->user_email, 'ID' => $post_author->ID, 'display_name' => $post_author->data->display_name);
     }
     if ($subscribers) {
         foreach ($subscribers as $s) {
             if (!empty($s->user_email) && $s->user_email != $current_user->user_email) {
                 $this->emails[] = $s->user_email;
             }
         }
     }
     if (!is_array($this->emails) || empty($this->emails)) {
         return;
     }
     $args = array('{asker}' => ap_user_display_name($question->post_author), '{editor}' => ap_user_display_name(get_current_user_id()), '{question_title}' => $question->post_title, '{question_link}' => get_permalink($question->ID), '{question_content}' => $question->post_content, '{question_excerpt}' => ap_truncate_chars(strip_tags($question->post_content), 100));
     $args = apply_filters('ap_edit_question_email_tags', $args);
     $this->subject = $this->replace_tags(ap_opt('edit_question_email_subject'), $args);
     $this->message = $this->replace_tags(ap_opt('edit_question_email_body'), $args);
     $this->initiate_send_email();
 }
示例#11
0
文件: tags.php 项目: jessor/anspress
					<div class="ap-term-list-inner">
						<a class="term-title" href="<?php 
        echo get_category_link($tag);
        ?>
"><span>
							<?php 
        echo $tag->name;
        ?>
						</span></a>
						
						<span> &times; <?php 
        echo $tag->count;
        ?>
</span>		
						<p><?php 
        echo ap_truncate_chars($tag->description, 70);
        ?>
</p>					
					</div>
				</li>
			<?php 
    }
    ?>
		</ul>
	</div>
<?php 
} else {
    ?>
	<div class="ap-tax-disabled">
		<?php 
    _e('Tags are disabled', 'ap');
示例#12
0
?>
		</div>
		<?php 
do_action('ap_hover_card_before_status', ap_user_get_the_ID());
?>

		<div class="ap-card-header">
			<a href="<?php 
ap_user_the_link();
?>
" class="ap-card-name"><?php 
ap_user_the_display_name();
?>
</a>
			<span class="ap-card-desc"><?php 
echo ap_truncate_chars(get_user_meta(ap_user_get_the_ID(), 'signature', true), 50);
?>
</span>
		</div>

		<div class="ap-card-count clearfix">
			<div class="ap-card-reputation">
				<span><?php 
ap_user_the_reputation();
?>
</span>
				<i><?php 
_e('Total Reputation', 'anspress-question-answer');
?>
</i>
			</div>