public function get_author() { $Authors = new PerchBlog_Authors(); return $Authors->find($this->authorID()); }
private function _standard_where_callback($opts) { $preview_mode = self::$preview_mode; $db = $this->db; return function (PerchQuery $Query) use($opts, $preview_mode, $db) { // section if (isset($opts['section'])) { $Sections = new PerchBlog_Sections(); if (is_numeric($opts['section'])) { $Section = $Sections->find($opts['section']); } else { $Section = $Sections->find_by_slug($opts['section']); } if (is_object($Section)) { $Query->where[] = ' sectionID=' . $db->pdb($Section->id()); } else { $Query->where[] = ' sectionID IS NULL '; } } // author if (isset($opts['author'])) { $Authors = new PerchBlog_Authors(); if (is_numeric($opts['author'])) { $Author = $Authors->find($opts['author']); } else { $Author = $Authors->find_by_slug($opts['author']); } if (is_object($Author)) { $Query->where[] = ' authorID=' . $db->pdb($Author->id()); } else { $Query->where[] = ' authorID IS NULL '; } } // tags if (isset($opts['tag'])) { $tags = $opts['tag']; if (!is_array($tags)) { $tags = array($tags); } $do_tag = array(); $do_not_tag = array(); foreach ($tags as $tag) { if (substr($tag, 0, 1) == '!') { $do_not_tag[] = ltrim($tag, '!'); } else { $do_tag[] = $tag; } } if (is_array($tags)) { $Query->select .= ' LEFT JOIN ' . PERCH_DB_PREFIX . 'blog_posts_to_tags p2t ON tbl.postID=p2t.postID LEFT JOIN ' . PERCH_DB_PREFIX . 'blog_tags t ON p2t.tagID=t.tagID '; if (PerchUtil::count($do_tag)) { $Query->where[] = ' tagSlug IN (' . $db->implode_for_sql_in($do_tag) . ') '; } if (PerchUtil::count($do_not_tag)) { $Query->where[] = ' tbl.postID NOT IN ( SELECT p2.postID FROM ' . $this->table . ' p2, ' . PERCH_DB_PREFIX . 'blog_posts_to_tags p2t2, ' . PERCH_DB_PREFIX . 'blog_tags t2 WHERE p2.postID=p2t2.postID AND p2t2.tagID=t2.tagID AND t2.tagSlug IN (' . $db->implode_for_sql_in($do_not_tag) . ') )'; } } } if ($preview_mode || isset($opts['admin']) && $opts['admin']) { // nothing } else { $Query->where[] = 'postStatus=\'Published\' AND postDateTime<=' . $db->pdb(date('Y-m-d H:i:00')) . ' '; } return $Query; }; }
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 $Authors = new PerchBlog_Authors($API); $HTML = $API->get('HTML'); $Form = $API->get('Form'); $message = false; if (!$CurrentUser->has_priv('perch_blog.authors.manage')) { PerchUtil::redirect($API->app_path()); } if (isset($_GET['id']) && $_GET['id'] != '') { $authorID = (int) $_GET['id']; $Author = $Authors->find($authorID); $details = $Author->to_array(); } else { $message = $HTML->failure_message('Sorry, that author could not be updated.'); $details = false; } $Template = $API->get('Template'); $Template->set('blog/author.html', 'blog'); $Form->handle_empty_block_generation($Template); $tags = $Template->find_all_tags_and_repeaters(); $Form->require_field('authorGivenName', 'Required'); $Form->require_field('authorEmail', 'Required'); $Form->set_required_fields_from_template($Template, $details); if ($Form->submitted()) { $postvars = array('authorGivenName', 'authorFamilyName', 'authorEmail', 'authorSlug'); $data = $Form->receive($postvars); $prev = false; if (isset($details['authorDynamicFields'])) { $prev = PerchUtil::json_safe_decode($details['authorDynamicFields'], true); }
<?php $Authors = new PerchBlog_Authors($API); $HTML = $API->get('HTML'); $Form = $API->get('Form'); $Form->set_name('delete'); if (!$CurrentUser->has_priv('perch_blog.authors.manage')) { PerchUtil::redirect($API->app_path()); } $message = false; if (isset($_GET['id']) && $_GET['id'] != '') { $Author = $Authors->find($_GET['id']); } else { PerchUtil::redirect($API->app_path()); } if ($Form->submitted()) { if (is_object($Author)) { $Author->delete(); // clear the caches PerchBlog_Cache::expire_all(); if ($Form->submitted_via_ajax) { echo $API->app_path() . '/authors/'; exit; } else { PerchUtil::redirect($API->app_path() . '/authors/'); } } else { $message = $HTML->failure_message('Sorry, that author could not be deleted.'); } } $details = $Author->to_array();