本文整理汇总了PHP中Comment::type方法的典型用法代码示例。如果您正苦于以下问题:PHP Comment::type方法的具体用法?PHP Comment::type怎么用?PHP Comment::type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Comment
的用法示例。
在下文中一共展示了Comment::type方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: module_setup
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
*/
protected function module_setup()
{
$user = User::get_by_name('posts_test');
if (!$user) {
$user = User::create(array('username' => 'posts_test', 'email' => 'posts_test@example.com', 'password' => md5('q' . rand(0, 65535))));
}
$this->user = $user;
$post = Post::create(array('title' => 'Test Post', 'content' => 'These tests expect there to be at least one post.', 'user_id' => $user->id, 'status' => Post::status('published'), 'content_type' => Post::type('entry')));
$this->post_id = $post->id;
$this->paramarray = array('id' => 'foofoo', 'post_id' => $this->post_id, 'name' => 'test', 'email' => 'test@example.org', 'url' => 'http://example.org', 'ip' => ip2long('127.0.0.1'), 'content' => 'test content', 'status' => Comment::status('unapproved'), 'date' => DateTime::date_create(), 'type' => Comment::type('comment'));
$this->comment = Comment::create($this->paramarray);
}
示例2: get
/**
* function get
* Returns requested comments
* @param array An associated array of parameters, or a querystring
* @return array An array of Comment objects, one for each query result
*
* <code>
* $comments = comments::get( array ( "author" => "skippy" ) );
* $comments = comments::get( array ( "slug" => "first-post", "status" => "1", "orderby" => "date ASC" ) );
* </code>
*
**/
public static function get($paramarray = array())
{
$params = array();
$fns = array('get_results', 'get_row', 'get_value');
$select = '';
// what to select -- by default, everything
foreach (Comment::default_fields() as $field => $value) {
$select .= '' == $select ? "{comments}.{$field}" : ", {comments}.{$field}";
}
// defaults
$orderby = 'date DESC';
$limit = Options::get('pagination');
// Put incoming parameters into the local scope
$paramarray = Utils::get_params($paramarray);
// Transact on possible multiple sets of where information that is to be OR'ed
if (isset($paramarray['where']) && is_array($paramarray['where'])) {
$wheresets = $paramarray['where'];
} else {
$wheresets = array(array());
}
$wheres = array();
$joins = array();
if (isset($paramarray['where']) && is_string($paramarray['where'])) {
$wheres[] = $paramarray['where'];
} else {
foreach ($wheresets as $paramset) {
// safety mechanism to prevent empty queries
$where = array('1=1');
$paramset = array_merge((array) $paramarray, (array) $paramset);
if (isset($paramset['id']) && (is_numeric($paramset['id']) || is_array($paramset['id']))) {
if (is_numeric($paramset['id'])) {
$where[] = "{comments}.id= ?";
$params[] = $paramset['id'];
} else {
if (is_array($paramset['id']) && !empty($paramset['id'])) {
$id_list = implode(',', $paramset['id']);
// Clean up the id list - remove all non-numeric or comma information
$id_list = preg_replace("/[^0-9,]/", "", $id_list);
// You're paranoid, ringmaster! :P
$limit = count($paramset['id']);
$where[] = '{comments}.id IN (' . addslashes($id_list) . ')';
}
}
}
if (isset($paramset['status']) && FALSE !== $paramset['status']) {
if (is_array($paramset['status'])) {
$paramset['status'] = array_diff($paramset['status'], array('any'));
array_walk($paramset['status'], create_function('&$a,$b', '$a = Comment::status( $a );'));
$where[] = "{comments}.status IN (" . Utils::placeholder_string(count($paramset['status'])) . ")";
$params = array_merge($params, $paramset['status']);
} else {
$where[] = "{comments}.status= ?";
$params[] = Comment::status($paramset['status']);
}
}
if (isset($paramset['type']) && FALSE !== $paramset['type']) {
if (is_array($paramset['type'])) {
$paramset['type'] = array_diff($paramset['type'], array('any'));
array_walk($paramset['type'], create_function('&$a,$b', '$a = Comment::type( $a );'));
$where[] = "type IN (" . Utils::placeholder_string(count($paramset['type'])) . ")";
$params = array_merge($params, $paramset['type']);
} else {
$where[] = "type= ?";
$params[] = Comment::type($paramset['type']);
}
}
if (isset($paramset['name'])) {
$where[] = "name= ?";
$params[] = $paramset['name'];
}
if (isset($paramset['email'])) {
$where[] = "email= ?";
$params[] = $paramset['email'];
}
if (isset($paramset['url'])) {
$where[] = "url= ?";
$params[] = $paramset['url'];
}
if (isset($paramset['post_id'])) {
$where[] = "{comments}.post_id= ?";
$params[] = $paramset['post_id'];
}
if (isset($paramset['ip'])) {
$where[] = "ip= ?";
$params[] = $paramset['ip'];
}
/* do searching */
if (isset($paramset['post_author'])) {
//.........这里部分代码省略.........
示例3: remove_type
/**
* Remove a comment type from the database
* @param integer|string $type The type of the comment
* @param bool $delete If true, delete the type and all comments of that type instead of deactivating it
*/
public static function remove_type($type, $delete = false)
{
if ($delete) {
// Delete comments of this type, delete type
$type_id = Comment::type($type);
DB::delete(DB::table('comments'), array('type' => $type_id));
DB::exec('DELETE FROM {commentinfo} WHERE comment_id IN (SELECT {commentinfo}.comment_id FROM {commentinfo} LEFT JOIN {comments} ON {commentinfo}.comment_id = {comments}.id WHERE {comments}.id IS NULL)');
DB::delete(DB::table('commenttype'), array('name' => Comment::type_name($type)));
} else {
DB::update(DB::table('commenttype'), array('name' => Comment::type_name($type), 'active' => 0), array('name'));
}
}
示例4: action_auth_ajax_wp_import_comments
public function action_auth_ajax_wp_import_comments()
{
// get the values post'd in
$inputs = $_POST->filter_keys(array('db_name', 'db_host', 'db_user', 'db_pass', 'db_prefix', 'category_import', 'import_index'));
$inputs = $inputs->getArrayCopy();
// make sure we have all our default values
$inputs = array_merge($this->default_values, $inputs);
// get the wpdb
$wpdb = $this->wp_connect($inputs['db_host'], $inputs['db_name'], $inputs['db_user'], $inputs['db_pass']);
// if we couldn't connect, error out
if (!$wpdb) {
EventLog::log(_t('Failed to import from "%s"', array($inputs['db_name'])));
Session::error(_t('Failed to import from "%s"', array($inputs['db_name'])));
echo '<p>' . _t('Failed to connect using the given database connection details.') . '</p>';
}
// we connected just fine, let's get moving!
// begin a transaction. if we error out at any point, we want to roll back to before import began
DB::begin_transaction();
// fetch the number of comments from the wordpress database so we can batch things up
$num_comments = $wpdb->get_value('select count(comment_id) from ' . $inputs['db_prefix'] . 'comments');
// figure out the LIMIT we're at
$min = $inputs['import_index'] * IMPORT_BATCH;
$max = min($min + IMPORT_BATCH, $num_comments);
// for display only
echo '<p>' . _t('Importing comments %1$d - %2$d of %3$d.', array($min, $max, $num_comments)) . '</p>';
// get all the imported users so we can link old comment authors to new comment authors
$users = DB::get_results('select user_id, value from {userinfo} where name = :name', array(':name' => 'wp_id'));
// create an easy user map of old ID -> new ID
$user_map = array();
foreach ($users as $info) {
$user_map[$info->value] = $info->user_id;
}
// get all the imported posts so we can link old post IDs to new post IDs
$posts = DB::get_results('select post_id, value from {postinfo} where name = :name', array(':name' => 'wp_id'));
// create an easy post map of old ID -> new ID
$post_map = array();
foreach ($posts as $info) {
$post_map[$info->value] = $info->post_id;
}
// get all the comment IDs we've imported so far to make sure we don't duplicate any
$comment_map = DB::get_column('select value from {commentinfo} where name = :name', array(':name' => 'wp_id'));
// now we're ready to start importing comments
$comments = $wpdb->get_results('select comment_id, comment_post_id, comment_author, comment_author_email, comment_author_url, comment_author_ip, comment_date, comment_content, comment_karma, comment_approved, comment_agent, comment_type, comment_parent, user_id from ' . $inputs['db_prefix'] . 'comments order by comment_id asc limit ' . $min . ', ' . IMPORT_BATCH);
foreach ($comments as $comment) {
// if this post is already in the list we've imported, skip it
if (in_array($comment->id, $comment_map)) {
continue;
}
// if the post this comment belongs to is not in the list of imported posts, skip it
if (!isset($post_map[$comment->comment_post_id])) {
continue;
}
// create the new comment
$c = new Comment(array('content' => MultiByte::convert_encoding($comment->comment_content), 'name' => MultiByte::convert_encoding($comment->comment_author), 'email' => MultiByte::convert_encoding($comment->comment_author_email), 'url' => MultiByte::convert_encoding($comment->comment_author_url), 'date' => HabariDateTime::date_create($comment->comment_date), 'post_id' => $post_map[$comment->comment_post_id]));
// figure out the comment type
switch ($comment->comment_type) {
case 'pingback':
$c->type = Comment::type('pingback');
break;
case 'trackback':
$c->type = Comment::type('trackback');
break;
default:
case 'comment':
$c->type = Comment::type('comment');
break;
}
// figure out the comment status
switch ($comment->comment_approved) {
case '1':
$c->status = Comment::status('approved');
break;
case '':
case '0':
$c->status = Comment::status('unapproved');
break;
case 'spam':
$c->status = Comment::status('spam');
break;
default:
// Comment::status() returns false if it doesn't recognize the status type
$status = Comment::status($comment->comment_status);
// store in a temp value because if you try and set ->status to an invalid value the Comment class freaks
if ($status == false) {
// we're not importing statuses we don't recognize - continue 2 to break out of the switch and the loop and continue to the next comment
continue 2;
} else {
$c->status = $status;
}
break;
}
// save the old comment ID in info
$c->info->wp_id = $comment->comment_id;
// save the old post ID in info
$c->info->wp_post_id = $comment->comment_post_id;
// save the old comment karma - but only if it is something
if ($comment->comment_karma != '0') {
$c->info->wp_karma = $comment->comment_karma;
}
// save the old comment user agent - but only if it is something
//.........这里部分代码省略.........
示例5: upgrade_db_post_5112
public function upgrade_db_post_5112()
{
$this->create_base_comment_types();
// Throw the existing values out far to avoid collisions
DB::query('UPDATE {comments} SET status = status + 30, type = type + 30');
// Update statuses
$updates = array('unapproved' => 0, 'approved' => 1, 'spam' => 2, 'deleted' => 3);
foreach ($updates as $name => $oldvalue) {
DB::query('UPDATE {comments} SET status = :newstatus WHERE status = :oldstatus', array('newstatus' => Comment::status($name), 'oldstatus' => 30 + $oldvalue));
}
// Update types
$updates = array('comment' => 0, 'pingback' => 1, 'trackback' => 2);
foreach ($updates as $name => $oldvalue) {
DB::query('UPDATE {comments} SET type = :newtype WHERE type = :oldtype', array('newtype' => Comment::type($name), 'oldtype' => 30 + $oldvalue));
}
}
示例6: make_comment
private function make_comment($post, $time)
{
$comment = Comment::create(array('post_id' => $post->id, 'name' => $this->get_comment_name(), 'url' => 'http://example.com', 'content' => $this->get_comment_content(), 'status' => $this->get_comment_status(), 'type' => Comment::type('comment'), 'date' => DateTime::date_create($time)));
$comment->info->lipsum = true;
$comment->info->commit();
}
示例7: add_comment
/**
* Add a comment to the site
*
* @param mixed $post A Post object instance or Post object id
* @param string $name The commenter's name
* @param string $email The commenter's email address
* @param string $url The commenter's website URL
* @param string $content The comment content
* @param array $extra An associative array of extra values that should be considered
*/
function add_comment($post, $name = null, $email = null, $url = null, $content = null, $extra = null)
{
if (is_numeric($post)) {
$post = Post::get(array('id' => $post));
}
if (!$post instanceof Post) {
// Not sure what you're trying to pull here, but that's no good
header('HTTP/1.1 403 Forbidden', true, 403);
die;
}
/* Sanitize data */
foreach (array('name', 'url', 'email', 'content') as $k) {
${$k} = InputFilter::filter(${$k});
}
// there should never be any HTML in the name, so do some extra filtering on it
$name = strip_tags(html_entity_decode($name, ENT_QUOTES, 'UTF-8'));
/* Sanitize the URL */
if (!empty($url)) {
$parsed = InputFilter::parse_url($url);
if ($parsed['is_relative']) {
// guess if they meant to use an absolute link
$parsed = InputFilter::parse_url('http://' . $url);
if (!$parsed['is_error']) {
$url = InputFilter::glue_url($parsed);
} else {
// disallow relative URLs
$url = '';
}
}
if ($parsed['is_pseudo'] || $parsed['scheme'] !== 'http' && $parsed['scheme'] !== 'https') {
// allow only http(s) URLs
$url = '';
} else {
// reconstruct the URL from the error-tolerant parsing
// http:moeffju.net/blog/ -> http://moeffju.net/blog/
$url = InputFilter::glue_url($parsed);
}
}
/* Create comment object*/
$comment = new Comment(array('post_id' => $post->id, 'name' => $name, 'email' => $email, 'url' => $url, 'ip' => Utils::get_ip(), 'content' => $content, 'status' => Comment::status('approved'), 'date' => DateTime::create(), 'type' => Comment::type('comment')));
// Should this really be here or in a default filter?
// In any case, we should let plugins modify the status after we set it here.
$user = User::identify();
if ($user->loggedin && $comment->email == $user->email) {
$comment->status = 'approved';
}
// Allow themes to work with comment hooks
Themes::create();
// Allow plugins to change comment data and add commentinfo based on plugin-added form fields
Plugins::act('comment_accepted', $comment, $this->handler_vars, $extra);
$spam_rating = 0;
$spam_rating = Plugins::filter('spam_filter', $spam_rating, $comment, $this->handler_vars, $extra);
if ($spam_rating >= Options::get('spam_percentage', 100)) {
$comment->status = 'spam';
}
$comment->insert();
$anchor = '';
// If the comment was saved
if ($comment->id && $comment->status != 'spam') {
$anchor = '#comment-' . $comment->id;
// store in the user's session that this comment is pending moderation
if ($comment->status == 'unapproved') {
Session::notice(_t('Your comment is pending moderation.'), 'comment_' . $comment->id);
}
// if no cookie exists, we should set one
// but only if the user provided some details
$cookie_name = 'comment_' . Options::get('public-GUID');
// build the string we store for the cookie
$cookie_content = implode('#', array($comment->name, $comment->email, $comment->url));
// if the user is not logged in and there is no cookie OR the cookie differs from the current set
if (User::identify()->loggedin == false && (!isset($_COOKIE[$cookie_name]) || $_COOKIE[$cookie_name] != $cookie_content)) {
// update the cookie
setcookie($cookie_name, $cookie_content, time() + DateTime::YEAR, Site::get_path('base', true));
}
}
// Return the commenter to the original page.
Utils::redirect($post->permalink . $anchor);
}