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


PHP comment_exists函数代码示例

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


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

示例1: main

 function main()
 {
     global $fpdb;
     $fpdb->query(array('count' => -1, 'fullparse' => true));
     $q = $fpdb->getQuery();
     $comments = $entries = array('count' => 0, 'words' => 0, 'chars' => 0, 'size' => 0, 'topten' => array());
     $entries['comments'] = 0;
     $toplist = array();
     while ($q->hasMore()) {
         list($id, $e) = $q->getEntry();
         $entries['count']++;
         $entries['words'] += str_word_count($e['subject']) + str_word_count($e['content']);
         $entries['chars'] += strlen($e['subject']) + strlen($e['content']);
         $entries['size'] += filesize(entry_exists($id));
         $cc = $q->hasComments();
         $entries['comments'] += $cc;
         $toplist[$id] = $cc;
         $toplistsubj[$id] = $e['subject'];
         $comments['count'] += $cc;
         while ($q->comments->hasMore()) {
             list($cid, $c) = $q->comments->getComment();
             $comments['words'] += str_word_count($c['content']);
             $comments['chars'] += strlen($c['content']);
             $comments['size'] += filesize(comment_exists($id, $cid));
         }
     }
     arsort($toplist);
     $i = 0;
     foreach ($toplist as $k => $v) {
         if ($i >= 10 || $v < 1) {
             break;
         }
         $entries['topten'][$k] = array('subject' => $toplistsubj[$k], 'comments' => $v);
         $i++;
     }
     $decunit = array('', 'Thousand', 'Million', 'Billion', 'Trillion', 'Zillion', 'Gazillion');
     $binunit = array('Bytes', 'KiloBytes', 'MegaBytes', 'GigaBytes', 'TeraBytes', 'Many', 'ManyBytes');
     list($count, $approx) = $this->format_number($entries['count'], 1000);
     $entries['count'] = $count . ' ' . $decunit[$approx];
     list($count, $approx) = $this->format_number($entries['words'], 1000);
     $entries['words'] = $count . ' ' . $decunit[$approx];
     list($count, $approx) = $this->format_number($entries['chars'], 1000);
     $entries['chars'] = $count . ' ' . $decunit[$approx];
     list($count, $approx) = $this->format_number($entries['comments'], 1000);
     $entries['comments'] = $count . ' ' . $decunit[$approx];
     list($count, $approx) = $this->format_number($entries['size'], 1024);
     $entries['size'] = $count . ' ' . $binunit[$approx];
     $this->smarty->assign('entries', $entries);
     list($count, $approx) = $this->format_number($comments['count'], 1000);
     $comments['count'] = $count . ' ' . $decunit[$approx];
     list($count, $approx) = $this->format_number($comments['words'], 1000);
     $comments['words'] = $count . ' ' . $decunit[$approx];
     list($count, $approx) = $this->format_number($comments['chars'], 1000);
     $comments['chars'] = $count . ' ' . $decunit[$approx];
     list($count, $approx) = $this->format_number($comments['size'], 1024);
     $comments['size'] = $count . ' ' . $binunit[$approx];
     $this->smarty->assign('comments', $comments);
 }
开发者ID:mroussel,项目名称:flatpress,代码行数:58,代码来源:admin.entry.stats.php

示例2: comment_parse

function comment_parse($entryid, $id)
{
    $f = comment_exists($entryid, $id);
    if (!$f) {
        return false;
    }
    $fc = io_load_file($f);
    $arr = utils_kexplode($fc);
    //$arr['EMAIL'] = apply_filters('comment_email', $arr['EMAIL']);
    // hackish: dash to underscore for ip-address :( todo: clean this up here or somewhere else
    //$arr['ip_address'] = $arr['ip-address'];
    return array_change_key_case($arr, CASE_LOWER);
}
开发者ID:mroussel,项目名称:flatpress,代码行数:13,代码来源:core.comment.php

示例3: cherry_plugin_import_posts


//.........这里部分代码省略.........
                            if (!is_wp_error($t)) {
                                $term_id = $t['term_id'];
                                do_action('cherry_plugin_import_insert_term', $t, $term, $post_id, $post);
                            } else {
                                // Failed to import
                                do_action('cherry_plugin_import_insert_term_failed', $t, $term, $post_id, $post);
                                continue;
                            }
                        }
                        $terms_to_set[$taxonomy][] = intval($term_id);
                    }
                    foreach ($terms_to_set as $tax => $ids) {
                        $tt_ids = wp_set_post_terms($post_id, $ids, $tax);
                        do_action('wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post);
                    }
                    unset($post['terms'], $terms_to_set);
                }
                if (!isset($post['comments'])) {
                    $post['comments'] = array();
                }
                $post['comments'] = apply_filters('wp_import_post_comments', $post['comments'], $post_id, $post);
                // add/update comments
                if (!empty($post['comments'])) {
                    $num_comments = 0;
                    $inserted_comments = array();
                    foreach ($post['comments'] as $comment) {
                        $comment_id = $comment['comment_id'];
                        $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
                        $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
                        $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
                        $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
                        $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
                        $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
                        $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
                        $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
                        $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
                        $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
                        $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
                        $newcomments[$comment_id]['commentmeta'] = isset($comment['commentmeta']) ? $comment['commentmeta'] : array();
                        if (isset($processed_authors[$comment['comment_user_id']])) {
                            $newcomments[$comment_id]['user_id'] = $processed_authors[$comment['comment_user_id']];
                        }
                    }
                    ksort($newcomments);
                    foreach ($newcomments as $key => $comment) {
                        // if this is a new post we can skip the comment_exists() check
                        if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) {
                            if (isset($inserted_comments[$comment['comment_parent']])) {
                                $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
                            }
                            $comment = wp_filter_comment($comment);
                            $inserted_comments[$key] = wp_insert_comment($comment);
                            do_action('cherry_plugin_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post);
                            foreach ($comment['commentmeta'] as $meta) {
                                $value = maybe_unserialize($meta['value']);
                                add_comment_meta($inserted_comments[$key], $meta['key'], $value);
                            }
                            $num_comments++;
                        }
                    }
                    unset($newcomments, $inserted_comments, $post['comments']);
                }
                if (!isset($post['postmeta'])) {
                    $post['postmeta'] = array();
                }
                $post['postmeta'] = apply_filters('wp_import_post_meta', $post['postmeta'], $post_id, $post);
                // add/update post meta
                if (isset($post['postmeta'])) {
                    foreach ($post['postmeta'] as $meta) {
                        $key = apply_filters('import_post_meta_key', $meta['key']);
                        $value = false;
                        if ('_edit_last' == $key) {
                            if (isset($processed_authors[intval($meta['value'])])) {
                                $value = $processed_authors[intval($meta['value'])];
                            } else {
                                $key = false;
                            }
                        }
                        if ($key) {
                            // export gets meta straight from the DB so could have a serialized string
                            if (!$value) {
                                $value = maybe_unserialize($meta['value']);
                            }
                            ini_set('max_execution_time', -1);
                            set_time_limit(0);
                            add_post_meta($post_id, $key, $value);
                            do_action('cherry_plugin_import_post_meta', $post_id, $key, $value);
                            // if the post has a featured image, take note of this in case of remap
                            if ('_thumbnail_id' == $key) {
                                $_SESSION['featured_images'][$post_id] = (int) $value;
                            }
                        }
                    }
                }
            }
        }
    }
    $_SESSION['attachment_posts'] = $attachment_posts;
    exit('import_menu_item');
}
开发者ID:drupalninja,项目名称:schome_org,代码行数:101,代码来源:import-functions.php

示例4: setup

 function setup()
 {
     $this->nosuchcomment = !comment_exists($_REQUEST['entry'], $_REQUEST['comment']);
     $this->smarty->assign('entryid', $_REQUEST['entry']);
     $this->smarty->assign('id', $_REQUEST['comment']);
 }
开发者ID:mroussel,项目名称:flatpress,代码行数:6,代码来源:admin.entry.commedit.php

示例5: import_posts


//.........这里部分代码省略.........
			$post_title = $wpdb->escape(trim($post_title[1]));

			preg_match('|<pubDate>(.*?)</pubDate>|is', $post, $post_date);
			$post_date = strtotime($post_date[1]);
			$post_date = gmdate('Y-m-d H:i:s', $post_date);

			preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
			$categories = $categories[1];

			$cat_index = 0;
			foreach ($categories as $category) {
				$categories[$cat_index] = $wpdb->escape($this->unhtmlentities($category));
				$cat_index++;
			}

			if(strcasecmp($post_type, "photo") === 0) {
				preg_match('|<sizedPhotoUrl>(.*?)</sizedPhotoUrl>|is', $post, $post_content);
				$post_content = '<img src="'.trim($post_content[1]).'" />';
				$post_content = $this->unhtmlentities($post_content);
			} else {
				preg_match('|<body>(.*?)</body>|is', $post, $post_content);
				$post_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($post_content[1]));
				$post_content = $this->unhtmlentities($post_content);
			}

			// Clean up content
			$post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content);
			$post_content = str_replace('<br>', '<br />', $post_content);
			$post_content = str_replace('<hr>', '<hr />', $post_content);
			$post_content = $wpdb->escape($post_content);

			$post_author = $current_user->ID;
			preg_match('|<postStatus>(.*?)</postStatus>|is', $post, $post_status);
			$post_status = trim($post_status[1]);

			echo '<li>';
			if ($post_id = post_exists($post_title, $post_content, $post_date)) {
				printf(__('Post <em>%s</em> already exists.'), stripslashes($post_title));
			} else {
				printf(__('Importing post <em>%s</em>...'), stripslashes($post_title));
				$postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
				$post_id = wp_insert_post($postdata);
				if ( is_wp_error( $post_id ) ) {
					return $post_id;
				}
				if (!$post_id) {
					_e("Couldn't get post ID");
					echo '</li>';
					break;
				}
				if(0 != count($categories))
					wp_create_categories($categories, $post_id);
			}

			preg_match_all('|<comment>(.*?)</comment>|is', $post, $comments);
			$comments = $comments[1];

			if ( $comments ) {
				$comment_post_ID = (int) $post_id;
				$num_comments = 0;
				foreach ($comments as $comment) {
					preg_match('|<body>(.*?)</body>|is', $comment, $comment_content);
					$comment_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($comment_content[1]));
					$comment_content = $this->unhtmlentities($comment_content);

					// Clean up content
					$comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content);
					$comment_content = str_replace('<br>', '<br />', $comment_content);
					$comment_content = str_replace('<hr>', '<hr />', $comment_content);
					$comment_content = $wpdb->escape($comment_content);

					preg_match('|<pubDate>(.*?)</pubDate>|is', $comment, $comment_date);
					$comment_date = trim($comment_date[1]);
					$comment_date = date('Y-m-d H:i:s', strtotime($comment_date));

					preg_match('|<author>(.*?)</author>|is', $comment, $comment_author);
					$comment_author = $wpdb->escape(trim($comment_author[1]));

					$comment_author_email = NULL;

					$comment_approved = 1;
					// Check if it's already there
					if (!comment_exists($comment_author, $comment_date)) {
						$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_date', 'comment_content', 'comment_approved');
						$commentdata = wp_filter_comment($commentdata);
						wp_insert_comment($commentdata);
						$num_comments++;
					}
				}
			}
			if ( $num_comments ) {
				echo ' ';
				printf( __ngettext('%s comment', '%s comments', $num_comments), $num_comments );
			}
			echo '</li>';
			flush();
			ob_flush();
		}
		echo '</ol>';
	}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:101,代码来源:blogware.php

示例6: process_posts


//.........这里部分代码省略.........
                 do_action('wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post);
             }
             unset($post['terms'], $terms_to_set);
         }
         if (!isset($post['comments'])) {
             $post['comments'] = array();
         }
         $post['comments'] = apply_filters('wp_import_post_comments', $post['comments'], $post_id, $post);
         // add/update comments
         if (!empty($post['comments'])) {
             $num_comments = 0;
             $inserted_comments = array();
             foreach ($post['comments'] as $comment) {
                 $comment_id = $comment['comment_id'];
                 $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
                 $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
                 $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
                 $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
                 $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
                 $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
                 $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
                 $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
                 $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
                 $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
                 $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
                 $newcomments[$comment_id]['commentmeta'] = isset($comment['commentmeta']) ? $comment['commentmeta'] : array();
                 if (isset($this->processed_authors[$comment['comment_user_id']])) {
                     $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
                 }
             }
             ksort($newcomments);
             foreach ($newcomments as $key => $comment) {
                 // if this is a new post we can skip the comment_exists() check
                 if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) {
                     if (isset($inserted_comments[$comment['comment_parent']])) {
                         $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
                     }
                     $comment = wp_filter_comment($comment);
                     $inserted_comments[$key] = wp_insert_comment($comment);
                     do_action('wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post);
                     foreach ($comment['commentmeta'] as $meta) {
                         $value = maybe_unserialize($meta['value']);
                         add_comment_meta($inserted_comments[$key], $meta['key'], $value);
                     }
                     $num_comments++;
                 }
             }
             unset($newcomments, $inserted_comments, $post['comments']);
         }
         if (!isset($post['postmeta'])) {
             $post['postmeta'] = array();
         }
         $post['postmeta'] = apply_filters('wp_import_post_meta', $post['postmeta'], $post_id, $post);
         // add/update post meta
         if (!empty($post['postmeta'])) {
             foreach ($post['postmeta'] as $meta) {
                 $key = apply_filters('import_post_meta_key', $meta['key'], $post_id, $post);
                 $value = false;
                 if ('_edit_last' == $key) {
                     if (isset($this->processed_authors[intval($meta['value'])])) {
                         $value = $this->processed_authors[intval($meta['value'])];
                     } else {
                         $key = false;
                     }
                 }
                 if ($key) {
开发者ID:amankatoch,项目名称:wp-plugin,代码行数:67,代码来源:wordpress-importer.php

示例7: process_posts


//.........这里部分代码省略.........
             if ($post_id = post_exists($post_title, '', $post_date)) {
                 echo '<li>';
                 printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
             } else {
                 echo '<li>';
                 printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
                 $post_author = $this->checkauthor($post_author);
                 //just so that if a post already exists, new users are not created by checkauthor
                 $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt');
                 $post_id = wp_insert_post($postdata);
                 // Add categories.
                 if (0 != count($post_categories)) {
                     wp_create_categories($post_categories, $post_id);
                 }
             }
             $comment_post_ID = $post_id;
             // Now for comments
             $comments = explode("-----\nCOMMENT:", $comments[0]);
             $num_comments = 0;
             foreach ($comments as $comment) {
                 if ('' != trim($comment)) {
                     // Author
                     preg_match("|AUTHOR:(.*)|", $comment, $comment_author);
                     $comment_author = $wpdb->escape(trim($comment_author[1]));
                     $comment = preg_replace('|(\\n?AUTHOR:.*)|', '', $comment);
                     preg_match("|EMAIL:(.*)|", $comment, $comment_author_email);
                     $comment_author_email = $wpdb->escape(trim($comment_author_email[1]));
                     $comment = preg_replace('|(\\n?EMAIL:.*)|', '', $comment);
                     preg_match("|IP:(.*)|", $comment, $comment_author_IP);
                     $comment_author_IP = trim($comment_author_IP[1]);
                     $comment = preg_replace('|(\\n?IP:.*)|', '', $comment);
                     preg_match("|URL:(.*)|", $comment, $comment_author_url);
                     $comment_author_url = $wpdb->escape(trim($comment_author_url[1]));
                     $comment = preg_replace('|(\\n?URL:.*)|', '', $comment);
                     preg_match("|DATE:(.*)|", $comment, $comment_date);
                     $comment_date = trim($comment_date[1]);
                     $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
                     $comment = preg_replace('|(\\n?DATE:.*)|', '', $comment);
                     $comment_content = $wpdb->escape(trim($comment));
                     $comment_content = str_replace('-----', '', $comment_content);
                     // Check if it's already there
                     if (!comment_exists($comment_author, $comment_date)) {
                         $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content');
                         $commentdata = wp_filter_comment($commentdata);
                         wp_insert_comment($commentdata);
                         $num_comments++;
                     }
                 }
             }
             if ($num_comments) {
                 printf(__('(%s comments)'), $num_comments);
             }
             // Finally the pings
             // fix the double newline on the first one
             $pings[0] = str_replace("-----\n\n", "-----\n", $pings[0]);
             $pings = explode("-----\nPING:", $pings[0]);
             $num_pings = 0;
             foreach ($pings as $ping) {
                 if ('' != trim($ping)) {
                     // 'Author'
                     preg_match("|BLOG NAME:(.*)|", $ping, $comment_author);
                     $comment_author = $wpdb->escape(trim($comment_author[1]));
                     $ping = preg_replace('|(\\n?BLOG NAME:.*)|', '', $ping);
                     preg_match("|IP:(.*)|", $ping, $comment_author_IP);
                     $comment_author_IP = trim($comment_author_IP[1]);
                     $ping = preg_replace('|(\\n?IP:.*)|', '', $ping);
                     preg_match("|URL:(.*)|", $ping, $comment_author_url);
                     $comment_author_url = $wpdb->escape(trim($comment_author_url[1]));
                     $ping = preg_replace('|(\\n?URL:.*)|', '', $ping);
                     preg_match("|DATE:(.*)|", $ping, $comment_date);
                     $comment_date = trim($comment_date[1]);
                     $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
                     $ping = preg_replace('|(\\n?DATE:.*)|', '', $ping);
                     preg_match("|TITLE:(.*)|", $ping, $ping_title);
                     $ping_title = $wpdb->escape(trim($ping_title[1]));
                     $ping = preg_replace('|(\\n?TITLE:.*)|', '', $ping);
                     $comment_content = $wpdb->escape(trim($ping));
                     $comment_content = str_replace('-----', '', $comment_content);
                     $comment_content = "<strong>{$ping_title}</strong>\n\n{$comment_content}";
                     $comment_type = 'trackback';
                     // Check if it's already there
                     if (!comment_exists($comment_author, $comment_date)) {
                         $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_type');
                         $commentdata = wp_filter_comment($commentdata);
                         wp_insert_comment($commentdata);
                         $num_pings++;
                     }
                 }
             }
             if ($num_pings) {
                 printf(__('(%s pings)'), $num_pings);
             }
             echo "</li>";
         }
         flush();
     }
     echo '</ol>';
     wp_import_cleanup($this->id);
     echo '<h3>' . sprintf(__('All done. <a href="%s">Have fun!</a>'), get_option('home')) . '</h3>';
 }
开发者ID:robertlange81,项目名称:Website,代码行数:101,代码来源:mt.php

示例8: import_comment

 function import_comment($entry)
 {
     global $importing_blog;
     // Drop the #fragment and we have the comment's old post permalink.
     foreach ($entry->links as $link) {
         if ($link['rel'] == 'alternate') {
             $parts = parse_url($link['href']);
             $entry->old_permalink = $parts['fragment'];
             $entry->old_post_permalink = $parts['path'];
             break;
         }
     }
     $comment_post_ID = (int) $this->blogs[$importing_blog]['posts'][$entry->old_post_permalink];
     preg_match('#<name>(.+?)</name>.*(?:\\<uri>(.+?)</uri>)?#', $entry->author, $matches);
     $comment_author = addslashes($this->no_apos(strip_tags((string) $matches[1])));
     $comment_author_url = addslashes($this->no_apos(strip_tags((string) $matches[2])));
     $comment_date = $this->convert_date($entry->updated);
     $comment_content = addslashes($this->no_apos(html_entity_decode($entry->content)));
     // Clean up content
     $comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('\$1')", $comment_content);
     $comment_content = str_replace('<br>', '<br />', $comment_content);
     $comment_content = str_replace('<hr>', '<hr />', $comment_content);
     // Checks for duplicates
     if (isset($this->blogs[$importing_blog]['comments'][$entry->old_permalink]) || comment_exists($comment_author, $comment_date)) {
         ++$this->blogs[$importing_blog]['comments_skipped'];
     } else {
         $comment = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_date', 'comment_content');
         $comment_id = wp_insert_comment($comment);
         $this->blogs[$importing_blog]['comments'][$entry->old_permalink] = $comment_id;
         ++$this->blogs[$importing_blog]['comments_done'];
     }
     $this->save_vars();
 }
开发者ID:pravinhirmukhe,项目名称:flow1,代码行数:33,代码来源:blogger.php

示例9: import_posts

	function import_posts() {
		global $wpdb, $current_user;
		
		set_magic_quotes_runtime(0);
		$importdata = file($this->file); // Read the file into an array
		$importdata = implode('', $importdata); // squish it
		$importdata = str_replace(array ("\r\n", "\r"), "\n", $importdata);

		preg_match_all('|<entry>(.*?)</entry>|is', $importdata, $posts);
		$posts = $posts[1];
		unset($importdata);
		echo '<ol>';		
		foreach ($posts as $post) {
			flush();
			preg_match('|<subject>(.*?)</subject>|is', $post, $post_title);
			$post_title = $wpdb->escape(trim($post_title[1]));
			if ( empty($post_title) ) {
				preg_match('|<itemid>(.*?)</itemid>|is', $post, $post_title);
				$post_title = $wpdb->escape(trim($post_title[1]));
			}

			preg_match('|<eventtime>(.*?)</eventtime>|is', $post, $post_date);
			$post_date = strtotime($post_date[1]);
			$post_date = gmdate('Y-m-d H:i:s', $post_date);

			preg_match('|<event>(.*?)</event>|is', $post, $post_content);
			$post_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($post_content[1]));
			$post_content = $this->unhtmlentities($post_content);

			// Clean up content
			$post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content);
			$post_content = str_replace('<br>', '<br />', $post_content);
			$post_content = str_replace('<hr>', '<hr />', $post_content);
			$post_content = $wpdb->escape($post_content);

			$post_author = $current_user->ID;
			$post_status = 'publish';

			echo '<li>';
			if ($post_id = post_exists($post_title, $post_content, $post_date)) {
				printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
			} else {
				printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
				$postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
				$post_id = wp_insert_post($postdata);
				if (!$post_id) {
					_e("Couldn't get post ID");
					echo '</li>';
					break;
				}
			}

			preg_match_all('|<comment>(.*?)</comment>|is', $post, $comments);
			$comments = $comments[1];
			
			if ( $comments ) {
				$comment_post_ID = (int) $post_id;
				$num_comments = 0;
				foreach ($comments as $comment) {
					preg_match('|<event>(.*?)</event>|is', $comment, $comment_content);
					$comment_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($comment_content[1]));
					$comment_content = $this->unhtmlentities($comment_content);

					// Clean up content
					$comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content);
					$comment_content = str_replace('<br>', '<br />', $comment_content);
					$comment_content = str_replace('<hr>', '<hr />', $comment_content);
					$comment_content = $wpdb->escape($comment_content);

					preg_match('|<eventtime>(.*?)</eventtime>|is', $comment, $comment_date);
					$comment_date = trim($comment_date[1]);
					$comment_date = date('Y-m-d H:i:s', strtotime($comment_date));

					preg_match('|<name>(.*?)</name>|is', $comment, $comment_author);
					$comment_author = $wpdb->escape(trim($comment_author[1]));

					preg_match('|<email>(.*?)</email>|is', $comment, $comment_author_email);
					$comment_author_email = $wpdb->escape(trim($comment_author_email[1]));

					$comment_approved = 1;
					// Check if it's already there
					if (!comment_exists($comment_author, $comment_date)) {
						$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_date', 'comment_content', 'comment_approved');
						$commentdata = wp_filter_comment($commentdata);
						wp_insert_comment($commentdata);
						$num_comments++;
					}
				}
			}
			if ( $num_comments ) {
				echo ' ';
				printf(__('(%s comments)'), $num_comments);
			}
			echo '</li>';
			flush();
			ob_flush();
		}
		echo '</ol>';
	}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:99,代码来源:livejournal.php

示例10: test_invalid_timezone_should_fall_back_on_blog

 /**
  * @ticket 33871
  */
 public function test_invalid_timezone_should_fall_back_on_blog()
 {
     $p = self::factory()->post->create();
     $c = self::factory()->comment->create(array('comment_author' => 1, 'comment_post_ID' => $p, 'comment_date' => '2014-05-06 12:00:00', 'comment_date_gmt' => '2014-05-06 07:00:00'));
     $this->assertEquals($p, comment_exists(1, '2014-05-06 12:00:00', 'not_a_valid_value'));
 }
开发者ID:nkeat12,项目名称:dv,代码行数:9,代码来源:includesComment.php

示例11: process_post


//.........这里部分代码省略.........
				printf(__('Importing post <em>%s</em>...'), stripslashes($post_title));
				$comment_post_ID = $post_id = wp_insert_post($postdata);
			}

			if ( is_wp_error( $post_id ) )
				return $post_id;

			// Memorize old and new ID.
			if ( $post_id && $post_ID ) {
				$this->post_ids_processed[intval($post_ID)] = intval($post_id);
			}

			// Add categories.
			if (count($categories) > 0) {
				$post_cats = array();
				foreach ($categories as $category) {
					if ( '' == $category )
						continue;
					$slug = sanitize_term_field('slug', $category, 0, 'category', 'db');
					$cat = get_term_by('slug', $slug, 'category');
					$cat_ID = 0;
					if ( ! empty($cat) )
						$cat_ID = $cat->term_id;
					if ($cat_ID == 0) {
						$category = $wpdb->escape($category);
						$cat_ID = wp_insert_category(array('cat_name' => $category));
						if ( is_wp_error($cat_ID) )
							continue;
					}
					$post_cats[] = $cat_ID;
				}
				wp_set_post_categories($post_id, $post_cats);
			}

			// Add tags.
			if (count($tags) > 0) {
				$post_tags = array();
				foreach ($tags as $tag) {
					if ( '' == $tag )
						continue;
					$slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
					$tag_obj = get_term_by('slug', $slug, 'post_tag');
					$tag_id = 0;
					if ( ! empty($tag_obj) )
						$tag_id = $tag_obj->term_id;
					if ( $tag_id == 0 ) {
						$tag = $wpdb->escape($tag);
						$tag_id = wp_insert_term($tag, 'post_tag');
						if ( is_wp_error($tag_id) )
							continue;
						$tag_id = $tag_id['term_id'];
					}
					$post_tags[] = intval($tag_id);
				}
				wp_set_post_tags($post_id, $post_tags);
			}
		}

		// Now for comments
		preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments);
		$comments = $comments[1];
		$num_comments = 0;
		if ( $comments) { foreach ($comments as $comment) {
			$comment_author       = $this->get_tag( $comment, 'wp:comment_author');
			$comment_author_email = $this->get_tag( $comment, 'wp:comment_author_email');
			$comment_author_IP    = $this->get_tag( $comment, 'wp:comment_author_IP');
			$comment_author_url   = $this->get_tag( $comment, 'wp:comment_author_url');
			$comment_date         = $this->get_tag( $comment, 'wp:comment_date');
			$comment_date_gmt     = $this->get_tag( $comment, 'wp:comment_date_gmt');
			$comment_content      = $this->get_tag( $comment, 'wp:comment_content');
			$comment_approved     = $this->get_tag( $comment, 'wp:comment_approved');
			$comment_type         = $this->get_tag( $comment, 'wp:comment_type');
			$comment_parent       = $this->get_tag( $comment, 'wp:comment_parent');

			// if this is a new post we can skip the comment_exists() check
			if ( !$post_exists || !comment_exists($comment_author, $comment_date) ) {
				$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_approved', 'comment_type', 'comment_parent');
				wp_insert_comment($commentdata);
				$num_comments++;
			}
		} }

		if ( $num_comments )
			printf(' '.__ngettext('(%s comment)', '(%s comments)', $num_comments), $num_comments);

		// Now for post meta
		preg_match_all('|<wp:postmeta>(.*?)</wp:postmeta>|is', $post, $postmeta);
		$postmeta = $postmeta[1];
		if ( $postmeta) { foreach ($postmeta as $p) {
			$key   = $this->get_tag( $p, 'wp:meta_key' );
			$value = $this->get_tag( $p, 'wp:meta_value' );
			$value = stripslashes($value); // add_post_meta() will escape.

			$this->process_post_meta($post_id, $key, $value);

		} }

		do_action('import_post_added', $post_id);
		print "</li>\n";
	}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:101,代码来源:wordpress.php

示例12: test_invalid_timezone_should_fall_back_on_blog

 /**
  * @ticket 33871
  */
 public function test_invalid_timezone_should_fall_back_on_blog()
 {
     $this->assertEquals(self::$post_id, comment_exists(1, '2014-05-06 12:00:00', 'not_a_valid_value'));
 }
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:7,代码来源:includesComment.php

示例13: comments2wp

 function comments2wp($comments = '')
 {
     // General Housekeeping
     global $wpdb;
     $count = 0;
     $txpcm2wpcm = array();
     $postarr = get_option('txpposts2wpposts');
     // Magic Mojo
     if (is_array($comments)) {
         echo '<p>' . __('Importing Comments...', 'textpattern-importer') . '<br /><br /></p>';
         foreach ($comments as $comment) {
             $count++;
             extract($comment);
             // WordPressify Data
             $comment_ID = ltrim($discussid, '0');
             $comment_post_ID = $postarr[$parentid];
             $comment_approved = 1 == $visible ? 1 : 0;
             $name = $wpdb->escape($name);
             $email = $wpdb->escape($email);
             $web = $wpdb->escape($web);
             $message = $wpdb->escape($message);
             $comment = array('comment_post_ID' => $comment_post_ID, 'comment_author' => $name, 'comment_author_IP' => $ip, 'comment_author_email' => $email, 'comment_author_url' => $web, 'comment_date' => $posted, 'comment_content' => $message, 'comment_approved' => $comment_approved);
             $comment = wp_filter_comment($comment);
             if ($cinfo = comment_exists($name, $posted)) {
                 // Update comments
                 $comment['comment_ID'] = $cinfo;
                 $ret_id = wp_update_comment($comment);
             } else {
                 // Insert comments
                 $ret_id = wp_insert_comment($comment);
             }
             $txpcm2wpcm[$comment_ID] = $ret_id;
         }
         // Store Comment ID translation for future use
         add_option('txpcm2wpcm', $txpcm2wpcm);
         // Associate newly formed categories with posts
         get_comment_count($ret_id);
         echo '<p>' . sprintf(__('Done! <strong>%1$s</strong> comments imported.', 'textpattern-importer'), $count) . '<br /><br /></p>';
         return true;
     }
     echo __('No Comments to Import!', 'textpattern-importer');
     return false;
 }
开发者ID:BennyHudson,项目名称:nicola-clarke,代码行数:43,代码来源:textpattern-importer.php

示例14: process_posts


//.........这里部分代码省略.........
                 }
                 foreach ($terms_to_set as $tax => $ids) {
                     $tt_ids = wp_set_post_terms($post_id, $ids, $tax);
                 }
                 unset($post['terms'], $terms_to_set);
             }
             // add/update comments
             if (!empty($post['comments'])) {
                 $num_comments = 0;
                 $inserted_comments = array();
                 foreach ($post['comments'] as $comment) {
                     $comment_id = $comment['comment_id'];
                     $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
                     $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
                     $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
                     $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
                     $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
                     $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
                     $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
                     $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
                     $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
                     $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
                     $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
                     $newcomments[$comment_id]['commentmeta'] = isset($comment['commentmeta']) ? $comment['commentmeta'] : array();
                     // This will be empty in the Knol WXR
                     /*
                     if ( isset( $this->processed_authors[$comment['comment_user_id']] ) )
                     	$newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
                     */
                 }
                 ksort($newcomments);
                 foreach ($newcomments as $key => $comment) {
                     // if this is a new post we can skip the comment_exists() check
                     if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) {
                         if (isset($inserted_comments[$comment['comment_parent']])) {
                             $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
                         }
                         $comment = wp_filter_comment($comment);
                         $inserted_comments[$key] = wp_insert_comment($comment);
                         foreach ($comment['commentmeta'] as $meta) {
                             $value = maybe_unserialize($meta['value']);
                             add_comment_meta($inserted_comments[$key], $meta['key'], $value);
                         }
                         $num_comments++;
                     }
                 }
                 unset($newcomments, $inserted_comments, $post['comments']);
             }
             // add/update post meta
             $author_snapshot = array();
             // Save the primary author in the author snapshot first
             $snapshot = $snapshot_template;
             $snapshot['id'] = $this->authors[$post['post_author']]['author_id'];
             $snapshot['email'] = $this->authors[$post['post_author']]['author_email'];
             $snapshot['surname'] = $this->authors[$post['post_author']]['author_first_name'];
             $snapshot['given_names'] = $this->authors[$post['post_author']]['author_last_name'];
             $author_snapshot[$post['post_author']] = $snapshot;
             if (isset($post['postmeta']) && is_array($post['postmeta'])) {
                 foreach ($post['postmeta'] as $meta) {
                     $key = apply_filters('import_post_meta_key', $meta['key']);
                     $value = false;
                     // Store both the Knol ID and WP ID, for potential future users/associations.
                     if (strpos($key, '_anno_knol_author_') !== false) {
                         $knol_author_id = str_replace('_anno_knol_author_', '', $key);
                         if (isset($this->author_mapping[$knol_author_id])) {
                             $wp_author_id = $this->author_mapping[$knol_author_id];
开发者ID:nameofname,项目名称:momo-wordpress-theme,代码行数:67,代码来源:knol-importer.php

示例15: process_posts


//.........这里部分代码省略.........
                         do_action('wp_import_insert_term', $t, $term, $post_id, $post);
                     } else {
                         if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) {
                         }
                         do_action('wp_import_insert_term_failed', $t, $term, $post_id, $post);
                         continue;
                     }
                 }
                 $terms_to_set[$taxonomy][] = intval($term_id);
             }
             foreach ($terms_to_set as $tax => $ids) {
                 $tt_ids = wp_set_post_terms($post_id, $ids, $tax);
                 do_action('wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post);
             }
             unset($post['terms'], $terms_to_set);
         }
         if (!isset($post['comments'])) {
             $post['comments'] = array();
         }
         $post['comments'] = apply_filters('wp_import_post_comments', $post['comments'], $post_id, $post);
         // add/update comments
         if (!empty($post['comments'])) {
             $num_comments = 0;
             $inserted_comments = array();
             foreach ($post['comments'] as $comment) {
                 $comment_id = $comment['comment_id'];
                 $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
                 $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
                 $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
                 $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
                 $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
                 $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
                 $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
                 $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
                 $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
                 $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
                 $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
                 $newcomments[$comment_id]['commentmeta'] = isset($comment['commentmeta']) ? $comment['commentmeta'] : array();
                 if (isset($this->processed_authors[$comment['comment_user_id']])) {
                     $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
                 }
             }
             ksort($newcomments);
             foreach ($newcomments as $key => $comment) {
                 // if this is a new post we can skip the comment_exists() check
                 if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) {
                     if (isset($inserted_comments[$comment['comment_parent']])) {
                         $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
                     }
                     $comment = wp_filter_comment($comment);
                     $inserted_comments[$key] = wp_insert_comment($comment);
                     do_action('wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post);
                     foreach ($comment['commentmeta'] as $meta) {
                         $value = maybe_unserialize($meta['value']);
                         add_comment_meta($inserted_comments[$key], $meta['key'], $value);
                     }
                     $num_comments++;
                 }
             }
             unset($newcomments, $inserted_comments, $post['comments']);
         }
         if (!isset($post['postmeta'])) {
             $post['postmeta'] = array();
         }
         $post['postmeta'] = apply_filters('wp_import_post_meta', $post['postmeta'], $post_id, $post);
         // add/update post meta
         if (!empty($post['postmeta'])) {
             foreach ($post['postmeta'] as $meta) {
                 $key = apply_filters('import_post_meta_key', $meta['key'], $post_id, $post);
                 $value = false;
                 if ('_edit_last' == $key) {
                     if (isset($this->processed_authors[intval($meta['value'])])) {
                         $value = $this->processed_authors[intval($meta['value'])];
                     } else {
                         $key = false;
                     }
                 }
                 if ($key) {
                     // export gets meta straight from the DB so could have a serialized string
                     if (!$value) {
                         $value = maybe_unserialize($meta['value']);
                     }
                     if (!$this->method) {
                         // FIX IMAGES URL'S AND UPLOAD LOCAL IMAGES
                         $value = $this->ww_replace_image_links_with_local($value);
                     }
                     add_post_meta($post_id, $key, $value);
                     do_action('import_post_meta', $post_id, $key, $value);
                     // if the post has a featured image, take note of this in case of remap
                     if ('_thumbnail_id' == $key) {
                         $value = $this->ww_replace_image_links_with_local($value, false, true);
                     }
                 }
             }
         }
         $i++;
     }
     unset($this->posts);
     return true;
 }
开发者ID:vinhnq1211,项目名称:funy,代码行数:101,代码来源:wordpress-importer.php


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