<?php $Comments = new PerchBlog_Comments($API); $pending_comment_count = $Comments->get_count('PENDING'); echo $HTML->subnav($CurrentUser, array(array('page' => array('perch_blog', 'perch_blog/delete', 'perch_blog/edit'), 'label' => 'Add/Edit'), array('page' => array('perch_blog/comments', 'perch_blog/comments/edit'), 'label' => 'Comments', 'badge' => $pending_comment_count, 'priv' => 'perch_blog.comments.moderate'), array('page' => array('perch_blog/authors', 'perch_blog/authors/edit', 'perch_blog/authors/delete'), 'label' => 'Authors', 'priv' => 'perch_blog.authors.manage'), array('page' => array('perch_blog/sections', 'perch_blog/sections/edit', 'perch_blog/sections/delete'), 'label' => 'Sections', 'priv' => 'perch_blog.sections.manage')));
<?php $HTML = $API->get('HTML'); $Paging = $API->get('Paging'); $Paging->set_per_page(20); $Comments = new PerchBlog_Comments($API); $Posts = new PerchBlog_Posts($API); $Form = $API->get('Form'); if ($Form->posted() && $Form->validate()) { $comments = $Form->find_items('comment-', true); if (PerchUtil::count($comments)) { $status = $_POST['commentStatus']; foreach ($comments as $commentID) { $Comment = $Comments->find($commentID); if ($status == 'DELETE') { // was the comment live? If so update the post's comment count. if ($Comment->commentStatus() == 'LIVE') { $Post = $Posts->find($Comment->postID()); if ($Post) { $Post->update_comment_count(); } } $Comment->delete(); } else { $Comment->set_status($status); } } } } $pending_comment_count = $Comments->get_count('PENDING'); $comments = array();
<?php include 'PerchBlog_Posts.class.php'; include 'PerchBlog_Post.class.php'; include 'PerchBlog_Authors.class.php'; include 'PerchBlog_Author.class.php'; include 'PerchBlog_Comments.class.php'; include 'PerchBlog_Comment.class.php'; $API = new PerchAPI(1, 'perch_blog'); $Lang = $API->get('Lang'); $Posts = new PerchBlog_Posts($API); $posts = $Posts->get_recent(5); $Comments = new PerchBlog_Comments($API); $comment_count = $Comments->get_count(); $comments = array(); $comments['Pending'] = $Comments->get_count('PENDING'); $comments['Live'] = $Comments->get_count('LIVE'); $comments['Rejected'] = $Comments->get_count('REJECTED'); $comments['Spam'] = $Comments->get_count('SPAM'); ?> <div class="widget"> <h2> <?php echo $Lang->get('Blog'); ?> <a href="<?php echo PerchUtil::html(PERCH_LOGINPATH . '/addons/apps/perch_blog/edit/'); ?> " class="add button"><?php echo $Lang->get('Add Post'); ?>
<?php $HTML = $API->get('HTML'); $Form = $API->get('Form'); $message = false; $Comments = new PerchBlog_Comments(); $Posts = new PerchBlog_Posts(); include realpath('.') . '/../../PerchBlog_Akismet.class.php'; if (!$CurrentUser->has_priv('perch_blog.comments.moderate')) { PerchUtil::redirect($API->app_path()); } if (isset($_GET['id']) && $_GET['id'] != '') { $commentID = (int) $_GET['id']; $Comment = $Comments->find($commentID); $details = $Comment->to_array(); } else { $message = $HTML->failure_message('Sorry, that comment could not be found.'); $details = array(); } $Template = $API->get('Template'); $Template->set('blog/comment.html', 'blog'); $Form->handle_empty_block_generation($Template); $tags = $Template->find_all_tags_and_repeaters(); $Form->set_required_fields_from_template($Template, $details); if ($Form->submitted()) { $postvars = array('perch_commentName', 'perch_commentEmail', 'perch_commentHTML', 'commentStatus', 'perch_commentDateTime', 'perch_commentURL'); $data = $Form->receive($postvars); if (PerchUtil::count($data)) { foreach ($data as $key => $val) { if (strpos($key, 'perch_') === 0) { $data[str_replace('perch_', '', $key)] = $val;
function perch_blog_delete_old_spam($days) { $API = new PerchAPI(1.0, 'perch_blog'); $Comments = new PerchBlog_Comments($API); return $Comments->delete_old_spam($days); }
public function import_from_wp($wordpress_file, $format = "textile", $callback = false, $sectionID = 1) { $out = array(); // LOAD XML $xml = simplexml_load_file(PerchUtil::file_path(PERCH_PATH . '/addons/apps/' . $this->api->app_id . '/import_data/' . $wordpress_file)); // AUTHORS $Authors = new PerchBlog_Authors($this->api); foreach ($xml->channel->children('wp', true) as $tag) { if ($tag->getName() == 'author') { $data = array(); $data['authorEmail'] = (string) $tag->author_email; $data['authorSlug'] = PerchUtil::urlify((string) $tag->author_display_name); $data['authorGivenName'] = (string) $tag->author_first_name; $data['authorFamilyName'] = (string) $tag->author_last_name; $data['authorImportRef'] = (string) $tag->author_login; if ($data['authorGivenName'] == '') { $data['authorGivenName'] = (string) $tag->author_login; } $Author = $Authors->find_or_create_by_email((string) $tag->author_email, $data); if ($Author) { $out[] = array('type' => 'success', 'messages' => array('Author ' . (string) $tag->author_display_name, 'Successfully imported')); } } } // POSTS $Posts = new PerchBlog_Posts($this->api); $Template = $this->api->get('Template'); $Template->set('blog/post.html', 'blog'); foreach ($xml->channel->item as $item) { $post = array(); $post['postTitle'] = (string) $item->title; $post['postTags'] = ''; $post['postLegacyURL'] = parse_url((string) $item->link, PHP_URL_PATH); $post_type = false; foreach ($item->children('wp', true) as $tag) { $tagName = $tag->getName(); switch ($tagName) { case 'post_id': $post['postImportID'] = (string) $tag; break; case 'post_type': $post_type = (string) $tag; break; case 'post_date_gmt': $val = strtotime((string) $tag); if ($val) { $post['postDateTime'] = date('Y-m-d H:i:s', $val); } break; case 'post_date': $val = strtotime((string) $tag); if ($val) { $post['postDateTime'] = date('Y-m-d H:i:s', $val); } break; case 'comment_status': $val = (string) $tag; if ($val == 'open') { $post['postAllowComments'] = '1'; } else { $post['postAllowComments'] = '0'; } break; case 'post_name': $post['postSlug'] = (string) $tag; break; case 'status': $val = (string) $tag; $post['postStatus'] = 'Draft'; if ($val == 'publish') { $post['postStatus'] = 'Published'; } break; } } // if it's not of type 'post', skip. if ($post_type != 'post') { continue; } // At this point, check we don't already have the post (as we know have the postImportID to identify it) if (isset($post['postImportID'])) { $Post = $Posts->find_by_importID($post['postImportID']); if (is_object($Post)) { $out[] = array('type' => 'success', 'messages' => array('Post ' . $Post->postTitle(), 'Already imported')); continue; } } foreach ($item->children('dc', true) as $tag) { $tagName = $tag->getName(); switch ($tagName) { case 'creator': $val = (string) $tag; $Author = $Authors->get_one_by('authorImportRef', $val); if (is_object($Author)) { $post['authorID'] = $Author->id(); } break; } } foreach ($item->children('content', true) as $tag) { $tagName = $tag->getName(); switch ($tagName) { case 'encoded': $raw = (string) $tag; if ($format == 'textile') { $html = PerchUtil::text_to_html($raw); $post['postDescRaw'] = $raw; $post['postDescHTML'] = $html; } else { $post['postDescRaw'] = $raw; $post['postDescHTML'] = $raw; } break; } } foreach ($item->children('excerpt', true) as $tag) { $tagName = $tag->getName(); switch ($tagName) { case 'encoded': $raw = (string) $tag; $html = PerchUtil::text_to_html($raw); $fields = array(); $fields['excerpt'] = array(); if ($format == 'textile') { $fields['excerpt']['raw'] = $raw; $fields['excerpt']['processed'] = $html; } else { $fields['excerpt']['raw'] = $html; $fields['excerpt']['processed'] = $html; } $post['postDynamicFields'] = PerchUtil::json_safe_encode($fields); break; } } // Callbacks if ($callback) { $post = call_user_func($callback, $post, $Template); } // Section $post['sectionID'] = $sectionID; // Create the post $Post = $Posts->create($post, $Template); if (is_object($Post)) { $out[] = array('type' => 'success', 'messages' => array('Post ' . $Post->postTitle(), 'Successfully imported')); // CATEGORIES AND TAGS $Categories = new PerchCategories_Categories(); $Tags = new PerchBlog_Tags($this->api); $postTags = array(); $cat_ids = array(); foreach ($item->category as $category) { $attributes = $category->attributes(); $slug = (string) $attributes['nicename']; $label = (string) $category; switch ((string) $attributes['domain']) { case 'post_tag': $Tag = $Tags->find_or_create($slug, $label); if (is_object($Tag)) { $postTags[] = $Tag->tagSlug(); $out[] = array('type' => 'success', 'messages' => array('Tag ' . $Tag->tagSlug(), 'Successfully imported')); } break; case 'category': PerchUtil::debug("Find or create {$slug}", 'notice'); $Category = $Categories->find_or_create('blog/' . $slug . '/', $label); if (is_object($Category)) { $cat_ids[] = $Category->id(); $out[] = array('type' => 'success', 'messages' => array('Category ' . $label, 'Successfully imported')); } break; } } if (PerchUtil::count($postTags)) { $post['postTags'] = implode(', ', $postTags); } if (PerchUtil::count($cat_ids)) { $fields['categories'] = $cat_ids; $post['postDynamicFields'] = PerchUtil::json_safe_encode($fields); } $Post->Template = $Template; $Post->update($post); $Post->index($Template); // COMMENTS $Comments = new PerchBlog_Comments($this->api); foreach ($item->children('wp', true) as $tag) { $tagName = $tag->getName(); if ($tagName == 'comment') { if ((string) $tag->comment_type == 'pingback') { continue; // this is a pingback, so skip it. } $html = PerchUtil::text_to_html((string) $tag->comment_content); $comment = array(); $comment['postID'] = $Post->id(); $comment['commentName'] = (string) $tag->comment_author; $comment['commentEmail'] = (string) $tag->comment_author_email; $comment['commentURL'] = (string) $tag->comment_author_url; $comment['commentIP'] = ip2long((string) $tag->comment_author_IP); $comment['commentDateTime'] = date('Y-m-d H:i:s', strtotime((string) $tag->comment_date_gmt)); $comment['commentHTML'] = $html; $comment['commentSpamData'] = ''; $comment['commentDynamicFields'] = ''; if ((string) $tag->comment_approved == '1') { $comment['commentStatus'] = 'LIVE'; $Comment = $Comments->create($comment); $out[] = array('type' => 'success', 'messages' => array('Comment from ' . $comment['commentName'], 'Successfully imported')); } } } $Post->update_comment_count(); } } return $out; }