/** * Returns the most appropriate category ID for the current entry. * Only called from genpage hook. * @global array $serendipity Determines the current entry from HTTP variables * @return int|string Category ID if custom template defined or category * view, otherwise 'default' */ function getID() { global $serendipity; // If category view, just return the current category ID if ($serendipity['GET']['category'] && !isset($serendipity['GET']['id'])) { return (int) $serendipity['GET']['category']; } // If entry view, determine the best category ID for custom templating if ($serendipity['GET']['id']) { // Find all the category IDs that have custom templates $cidstr = $this->get_config('cat_precedence', false); if ($cidstr === false) { // No precedence set: default to old, alphabetical precedence. $tcats = $this->getTemplatizedCats(); $cids = array(); if (is_array($tcats)) { foreach ($tcats as $cat) { $cids[] = $cat['categoryid']; } } } else { if ($cidstr) { $cids = explode(',', $cidstr); } else { // Possibly it's set, but no categories, therefore empty $cids = array(); } } // Get all the categories' IDs belonging to this entry $entrycats = serendipity_fetchEntryCategories($serendipity['GET']['id']); $entrycids = array(); foreach ($entrycats as $catdata) { $entrycids[] = $catdata['categoryid']; } // Return the first customized template in the entry's categories // Could try array_intersect(), but will it keep order? foreach ($cids as $idx => $candidate) { if (in_array($candidate, $entrycids)) { return $candidate; } } // End if we know of any customized categories // If set to force, ALWAYS set the category to a forced category. if ((string) $this->get_config('fixcat') === 'hard') { return $entrycids[0]; } } // End if entry return 'default'; }
/** * Fetch a single entry by a specific condition * * @access public * @param string The column to compare $val against (like 'id') * @param string The value of the colum $key to compare with (like '4711') * @param boolean Indicates if the full entry will be fetched (body+extended: TRUE), or only the body (FALSE). * @param string Indicates whether drafts should be fetched * @return */ function &serendipity_fetchEntry($key, $val, $full = true, $fetchDrafts = 'false') { global $serendipity; $cond = array(); $cond['and'] = " "; // intentional dummy string to attach dummy AND parts to the WHERE clauses if ($fetchDrafts == 'false') { $cond['and'] = " AND e.isdraft = 'false' " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp <= " . serendipity_db_time() : ''); } if (isset($serendipity['GET']['adminModule']) && $serendipity['GET']['adminModule'] == 'entries' && !serendipity_checkPermission('adminEntriesMaintainOthers')) { $cond['and'] = " AND e.authorid = '" . $serendipity['authorid'] . "'"; } serendipity_ACL_SQL($cond, true); serendipity_plugin_api::hook_event('frontend_fetchentry', $cond, array('noSticky' => true)); $querystring = "SELECT e.id,\n e.title,\n e.timestamp,\n e.body,\n e.comments,\n e.trackbacks,\n e.extended,\n e.exflag,\n e.authorid,\n e.isdraft,\n e.allow_comments,\n e.last_modified,\n e.moderate_comments,\n\n a.realname AS author,\n a.username AS loginname,\n a.email\n FROM\n {$serendipity['dbPrefix']}entries e\n LEFT JOIN {$serendipity['dbPrefix']}authors a\n ON e.authorid = a.authorid\n {$cond['joins']}\n WHERE\n e.{$key} " . ($key == 'id' ? '=' : 'LIKE') . " '" . serendipity_db_escape_string($val) . "'\n {$cond['and']}\n\n {$cond['single_group']}\n {$cond['single_having']}\n {$cond['single_orderby']}\n LIMIT 1"; $ret =& serendipity_db_query($querystring, true, 'assoc'); if (is_array($ret)) { $ret['categories'] =& serendipity_fetchEntryCategories($ret['id']); $ret['properties'] =& serendipity_fetchEntryProperties($ret['id']); $stack = array(); $stack[0] =& $ret; $assoc_ids = array($ret['id'] => 0); serendipity_plugin_api::hook_event('frontend_entryproperties', $stack, $assoc_ids); } return $ret; }
function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks =& $bag->get('event_hooks'); $comic_cat = $this->get_config('category', ''); $show_t = $this->get_config('show_title', 'true'); $show_raw = $this->get_config('raw', 'true'); $hide_fp = $this->get_config('hide', 'true'); if ($event == 'css') { if (stristr('.serendipity_comics', $addData)) { // class exists in CSS, so a user has customized it and we don't need default return true; } ?> .serendipity_comics { font-size: 15px; font-weight: bold; text-align: center; margin-top: 5px; margin-bottom: 10px; margin-left: auto; margin-right: auto; border: 0px; display: block; } <?php return true; } elseif ($event == 'entries_header' || $event == 'frontend_fetchentries') { // determine location and show on the front page only $geturi = serendipity_getUriArguments($GLOBALS['uri']); if (!isset($geturi[0]) && !isset($serendipity['GET']['id']) && !isset($serendipity['GET']['category']) && $comic_cat) { $comic = serendipity_db_query("SELECT e.id, e.title, e.timestamp, e.body\n\t\t\t\t\tFROM {$serendipity['dbPrefix']}entries e\n\t\t\t\t\tINNER JOIN {$serendipity['dbPrefix']}entrycat\n\t\t\t\t\t\tON e.id = {$serendipity['dbPrefix']}entrycat.entryid\n\t\t\t\t\tWHERE e.isdraft = 'false'\n\t\t\t\t\t\tAND e.timestamp <= " . $this->timeOffset(time()) . "\n\t\t\t\t\t\tAND {$serendipity['dbPrefix']}entrycat.categoryid = {$comic_cat}\n\t\t\t\t\tORDER BY e.timestamp DESC\n\t\t\t\t\tLIMIT 1"); if ($event == 'entries_header' && $serendipity['GET']['page'] == '1') { if ($show_t == 'true') { echo '<h4 class="serendipity_title"><a href="' . serendipity_archiveURL($comic[0]['id'], $comic[0]['title'], 'baseURL', true, array('timestamp' => $comic[0]['timestamp'])) . '">'; echo PLUGIN_COMICS_LATEST . (function_exists('serendipity_specialchars') ? serendipity_specialchars(serendipity_strftime(DATE_FORMAT_ENTRY, $comic['0']['timestamp'])) : htmlspecialchars(serendipity_strftime(DATE_FORMAT_ENTRY, $comic['0']['timestamp']), ENT_COMPAT, LANG_CHARSET)) . '</a></h4>'; } if ($show_raw == 'true') { echo $comic['0']['body']; } else { echo '<div class="serendipity_entry"><div class="serendipity_entry_body">'; $entry = array('html_nugget' => $comic['0']['body']); serendipity_plugin_api::hook_event('frontend_display', $entry); echo $entry['html_nugget']; echo '</div></div>'; } echo $this->jumplinks($comic['0']['id'], $comic_cat); } elseif ($event == 'frontend_fetchentries' && !$serendipity['GET']['page'] && !isset($serendipity['GET']['adminModule'])) { if ($hide_fp == 'true') { $cond = " INNER JOIN {$serendipity['dbPrefix']}entrycat ON e.id = {$serendipity['dbPrefix']}entrycat.entryid "; if (empty($eventData['joins'])) { $eventData['joins'] = $cond; } else { $eventData['joins'] .= $cond; } $cond = "{$serendipity['dbPrefix']}entrycat.categoryid != {$comic_cat}"; } else { $cond = "e.id != {$comic['0']['id']}"; } if (empty($eventData['and'])) { $eventData['and'] = " WHERE {$cond} "; } else { $eventData['and'] .= " AND {$cond} "; } } } return true; } elseif ($event == 'entry_display' && isset($serendipity['GET']['id']) && $comic_cat) { $thiscat = serendipity_fetchEntryCategories($serendipity['GET']['id']); if ($thiscat['0']['0'] == $comic_cat) { $elements = count($eventData); for ($i = 0; $i < $elements; $i++) { unset($eventData[$i]['properties']['ep_cache_extended']); $eventData[$i]['exflag'] = 1; $eventData[$i]['extended'] .= sprintf($this->jumplinks($serendipity['GET']['id'], $comic_cat)); } } return true; } else { return false; } }