public function to_array($template_ids = false) { $out = parent::to_array(); if (PerchUtil::count($template_ids) && in_array('postURL', $template_ids)) { $API = new PerchAPI(1.0, 'perch_blog'); $Posts = new PerchBlog_Posts($API); $Post = $Posts->find($this->postID()); if (is_object($Post)) { $out['postURL'] = $Post->postURL(); } } if ($out['commentDynamicFields'] != '') { $dynamic_fields = PerchUtil::json_safe_decode($out['commentDynamicFields'], true); if (PerchUtil::count($dynamic_fields)) { foreach ($dynamic_fields as $key => $value) { $out['perch_' . $key] = $value; } } $out = array_merge($dynamic_fields, $out); } return $out; }
$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(); $status = 'pending'; if (isset($_GET['status']) && $_GET['status'] != '') {
<?php $Blogs = new PerchBlog_Blogs($API); $Posts = new PerchBlog_Posts($API); $message = false; $Authors = new PerchBlog_Authors(); $Author = $Authors->find_or_create($CurrentUser); $HTML = $API->get('HTML'); if (!$CurrentUser->has_priv('perch_blog.post.create')) { PerchUtil::redirect($API->app_path()); } if (isset($_GET['id']) && $_GET['id'] != '') { $postID = (int) $_GET['id']; $Post = $Posts->find($postID, true); $details = $Post->to_array(); $template = $Post->postMetaTemplate(); } $Blog = false; if (PERCH_RUNWAY) { if ($Post) { $Blog = $Post->get_blog(); } else { if (PerchUtil::get('blog')) { $Blog = $Blogs->find((int) PerchUtil::get('blog')); } } } if (!$Blog) { $Blog = $Blogs->find(1); } $Sections = new PerchBlog_Sections();
public function receive_new_comment($SubmittedForm) { $input = $SubmittedForm->data; if ($input['postID']) { $Posts = new PerchBlog_Posts(); $Post = $Posts->find((int) $input['postID']); if (is_object($Post)) { $data = array(); $data['postID'] = $Post->id(); $data['commentDateTime'] = date('Y-m-d H:i:s'); foreach ($this->static_fields as $field) { if (!isset($data[$field])) { if (isset($input[$field]) && $input[$field] != '') { $data[$field] = trim($input[$field]); } } } // dynamic fields $dynamic_fields = array(); foreach ($input as $field => $val) { if (!isset($data[$field])) { $dynamic_fields[$field] = trim($val); } } $data['commentDynamicFields'] = PerchUtil::json_safe_encode($dynamic_fields); // Anti-spam $Settings = $this->api->get('Settings'); $akismetAPIKey = $Settings->get('perch_blog_akismet_key')->val(); $spam = false; $antispam = $SubmittedForm->get_antispam_values(); $environment = $_SERVER; $spam_data = array(); $spam_data['fields'] = $antispam; $spam_data['environment'] = $environment; $data['commentSpamData'] = PerchUtil::json_safe_encode($spam_data); $data['commentIP'] = ip2long($_SERVER['REMOTE_ADDR']); $spam = $this->_check_for_spam($antispam, $environment, $akismetAPIKey); if ($spam) { $data['commentStatus'] = 'SPAM'; } else { $Users = new PerchUsers(); $CurrentUser = $Users->get_current_user(); if (is_object($CurrentUser) && $CurrentUser->logged_in()) { $data['commentStatus'] = 'LIVE'; } else { $data['commentStatus'] = 'PENDING'; } } foreach ($data as $key => $val) { switch ($key) { case 'commentHTML': if (!class_exists('\\Netcarver\\Textile\\Parser', false) && class_exists('Textile', true)) { // sneaky autoloading hack } if (PERCH_HTML5) { $Textile = new \Netcarver\Textile\Parser('html5'); } else { $Textile = new \Netcarver\Textile\Parser(); } if (PERCH_RWD) { $val = $Textile->setDimensionlessImages(true)->textileRestricted($val); } else { $val = $Textile->textileRestricted($val); } if (defined('PERCH_XHTML_MARKUP') && PERCH_XHTML_MARKUP == false) { $val = str_replace(' />', '>', $val); } break; case 'commentURL': if (!parse_url($val, PHP_URL_SCHEME)) { $val = 'http://' . $val; } if (!parse_url($val, PHP_URL_SCHEME)) { $val = ''; } $val = strtolower($val); break; case 'commentEmail': $val = strtolower($val); break; } $data[$key] = $val; } $r = $this->create($data); $Post->update_comment_count(); if (is_object($r) && $r->commentStatus() == 'PENDING') { $this->_notify_author_of_comment($Post, $r); } return $r; } } PerchUtil::debug($SubmittedForm); }
<?php $Blog = new PerchBlog_Posts($API); $message = false; $Authors = new PerchBlog_Authors(); $Author = $Authors->find_or_create($CurrentUser); $Sections = new PerchBlog_Sections(); $sections = $Sections->all(); $HTML = $API->get('HTML'); if (!$CurrentUser->has_priv('perch_blog.post.create')) { PerchUtil::redirect($API->app_path()); } if (isset($_GET['id']) && $_GET['id'] != '') { $postID = (int) $_GET['id']; $Post = $Blog->find($postID, true); $details = $Post->to_array(); //PerchUtil::debug($details, 'notice'); $template = $Post->postTemplate(); } else { $Post = false; $postID = false; $details = array(); if (!$CurrentUser->has_priv('perch_blog.post.create')) { PerchUtil::redirect($API->app_path()); } $template = false; } if (!$template) { $template = 'post.html'; } $Template = $API->get('Template');
function perch_blog_author_for_post($id_or_slug, $opts = array(), $return = false) { $id_or_slug = rtrim($id_or_slug, '/'); $default_opts = array('template' => 'author.html', 'skip-template' => false, 'split-items' => false, 'cache' => true); if (is_array($opts)) { $opts = array_merge($default_opts, $opts); } else { $opts = $default_opts; } if ($opts['skip-template'] || $opts['split-items']) { $return = true; } $cache = false; if ($opts['cache']) { $cache_key = 'perch_blog_author_for_post' . md5($id_or_slug . serialize($opts)); $cache = PerchBlog_Cache::get_static($cache_key, 10); } if ($cache) { if ($return) { return $cache; } echo $cache; return ''; } $API = new PerchAPI(1.0, 'perch_blog'); $BlogPosts = new PerchBlog_Posts($API); if (is_numeric($id_or_slug)) { $Post = $BlogPosts->find($id_or_slug); } else { $Post = $BlogPosts->find_by_slug($id_or_slug); } if (is_object($Post)) { $Authors = new PerchBlog_Authors(); $Author = $Authors->find($Post->authorID()); if (is_object($Author)) { if ($opts['skip-template']) { return $Author->to_array(); } $Template = $API->get('Template'); $Template->set('blog/' . $opts['template'], 'blog'); $r = $Template->render($Author); if ($r != '') { PerchBlog_Cache::save_static($cache_key, $r); } if ($return) { return $r; } echo $r; } } return false; }
<?php $Blog = new PerchBlog_Posts($API); $Authors = new PerchBlog_Authors($API); $HTML = $API->get('HTML'); $Form = $API->get('Form'); $message = false; if (!$CurrentUser->has_priv('perch_blog.post.delete')) { PerchUtil::redirect($API->app_path()); } if (isset($_GET['id']) && $_GET['id'] != '') { $Post = $Blog->find($_GET['id'], true); } if (!is_object($Post)) { PerchUtil::redirect($API->app_path()); } $Form->set_name('delete'); if ($Form->submitted()) { if (is_object($Post)) { $Post->delete(); $Blog->update_category_counts(); $Authors->update_post_counts(); if ($Form->submitted_via_ajax) { echo $API->app_path() . '/'; exit; } else { PerchUtil::redirect($API->app_path() . '/'); } } else { $message = $HTML->failure_message('Sorry, that post could not be deleted.'); }