function showElementEntrylist($filter = array(), $limit = 0) { global $serendipity; $filter_sql = implode(' AND ', $filter); $orderby = 'timestamp DESC'; // Fetch the entries $entries = serendipity_fetchEntries(false, false, $limit, true, false, $orderby, $filter_sql); $rows = 0; if (!is_array($entries)) { return; } foreach ($entries as $entry) { $rows++; // Find out if the entry has been modified later than 30 minutes after creation if ($entry['timestamp'] <= $entry['last_modified'] - 60 * 30) { $lm = '<a href="#" title="' . LAST_UPDATED . ': ' . serendipity_formatTime(DATE_FORMAT_SHORT, $entry['last_modified']) . '" onclick="alert(this.title)"><img src="' . serendipity_getTemplateFile('admin/img/clock.png') . '" alt="*" style="border: 0px none ; vertical-align: bottom;" /></a>'; } else { $lm = ''; } if (!$serendipity['showFutureEntries'] && $entry['timestamp'] >= serendipity_serverOffsetHour()) { $entry_pre = '<a href="#" title="' . ENTRY_PUBLISHED_FUTURE . '" onclick="alert(this.title)"><img src="' . serendipity_getTemplateFile('admin/img/clock_future.png') . '" alt="*" style="border: 0px none ; vertical-align: bottom;" /></a> '; } else { $entry_pre = ''; } if (serendipity_db_bool($entry['properties']['ep_is_sticky'])) { $entry_pre .= ' ' . STICKY_POSTINGS . ': '; } if (serendipity_db_bool($entry['isdraft'])) { $entry_pre .= ' ' . DRAFT . ': '; } ?> <div class="serendipity_admin_list_item serendipity_admin_list_item_<?php echo $rows % 2 ? 'even' : 'uneven'; ?> "> <table width="100%" cellspacing="0" cellpadding="3"> <tr> <td> <strong><?php echo $entry_pre; ?> <a href="?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=edit&serendipity[id]=<?php echo $entry['id']; ?> " title="#<?php echo $entry['id']; ?> "><?php echo serendipity_truncateString(function_exists('serendipity_specialchars') ? serendipity_specialchars($entry['title']) : htmlspecialchars($entry['title'], ENT_COMPAT, LANG_CHARSET), 50); ?> </a></strong> </td> <td align="right"> <?php echo serendipity_formatTime(DATE_FORMAT_SHORT, $entry['timestamp']) . ' ' . $lm; ?> </td> </tr> <tr> <td> <?php echo POSTED_BY . ' ' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($entry['author']) : htmlspecialchars($entry['author'], ENT_COMPAT, LANG_CHARSET)); if (count($entry['categories'])) { echo ' ' . IN . ' '; $cats = array(); foreach ($entry['categories'] as $cat) { $caturl = serendipity_categoryURL($cat); $cats[] = '<a href="' . $caturl . '">' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($cat['category_name']) : htmlspecialchars($cat['category_name'], ENT_COMPAT, LANG_CHARSET)) . '</a>'; } echo implode(', ', $cats); } $entry['link'] = serendipity_archiveURL($entry['id'], $entry['title'], 'serendipityHTTPPath', true, array('timestamp' => $entry['timestamp'])); $entry['preview_link'] = '?serendipity[noBanner]=true&serendipity[noSidebar]=true&serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=preview&serendipity[id]=' . $entry['id']; ?> </td> <td align="right"> <?php if (serendipity_db_bool($entry['isdraft']) || !$serendipity['showFutureEntries'] && $entry['timestamp'] >= serendipity_serverOffsetHour()) { ?> <a target="_blank" href="<?php echo $entry['preview_link']; ?> &<?php echo serendipity_setFormToken('url'); ?> " title="<?php echo PREVIEW . ' #' . $entry['id']; ?> " class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/zoom.png'); ?> " alt="<?php echo PREVIEW; ?> " /><?php echo PREVIEW; ?> </a> <?php } else { ?> <a target="_blank" href="<?php echo $entry['link']; ?> " title="<?php echo VIEW . ' #' . $entry['id']; ?> " class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/zoom.png'); ?> " alt="<?php echo VIEW; ?> " /><?php echo VIEW; ?> </a> <?php } ?> <a href="?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=edit&serendipity[id]=<?php echo $entry['id']; ?> " title="<?php echo EDIT . ' #' . $entry['id']; ?> " class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/edit.png'); ?> " alt="<?php echo EDIT; ?> " /><?php echo EDIT; ?> </a> </td> </tr> </table> </div> <?php } // end entries output }
/** * Shows the entry panel overview * * Shows a list of existing entries, with pagination and cookie-remember settings. * * @access public * @return null */ function serendipity_drawList() { global $serendipity, $sort_order, $per_page; $filter_import = array('author', 'category', 'isdraft'); $sort_import = array('perPage', 'ordermode', 'order'); foreach ($filter_import as $f_import) { serendipity_restoreVar($serendipity['COOKIE']['entrylist_filter_' . $f_import], $serendipity['GET']['filter'][$f_import]); serendipity_JSsetCookie('entrylist_filter_' . $f_import, $serendipity['GET']['filter'][$f_import]); } foreach ($sort_import as $s_import) { serendipity_restoreVar($serendipity['COOKIE']['entrylist_sort_' . $s_import], $serendipity['GET']['sort'][$s_import]); serendipity_JSsetCookie('entrylist_sort_' . $s_import, $serendipity['GET']['sort'][$s_import]); } $perPage = !empty($serendipity['GET']['sort']['perPage']) ? $serendipity['GET']['sort']['perPage'] : $per_page[0]; $page = (int) $serendipity['GET']['page']; $offSet = $perPage * $page; if (empty($serendipity['GET']['sort']['ordermode']) || $serendipity['GET']['sort']['ordermode'] != 'ASC') { $serendipity['GET']['sort']['ordermode'] = 'DESC'; } if (!empty($serendipity['GET']['sort']['order']) && !empty($sort_order[$serendipity['GET']['sort']['order']])) { $orderby = serendipity_db_escape_string($serendipity['GET']['sort']['order'] . ' ' . $serendipity['GET']['sort']['ordermode']); } else { $orderby = 'timestamp ' . serendipity_db_escape_string($serendipity['GET']['sort']['ordermode']); } $filter = array(); if (!empty($serendipity['GET']['filter']['author'])) { $filter[] = "e.authorid = '" . serendipity_db_escape_string($serendipity['GET']['filter']['author']) . "'"; } if (!empty($serendipity['GET']['filter']['category'])) { $filter[] = "ec.categoryid = '" . serendipity_db_escape_string($serendipity['GET']['filter']['category']) . "'"; } if (!empty($serendipity['GET']['filter']['isdraft'])) { if ($serendipity['GET']['filter']['isdraft'] == 'draft') { $filter[] = "e.isdraft = 'true'"; } elseif ($serendipity['GET']['filter']['isdraft'] == 'publish') { $filter[] = "e.isdraft = 'false'"; } } if (!empty($serendipity['GET']['filter']['body'])) { if ($serendipity['dbType'] == 'mysql') { $filter[] = "MATCH (title,body,extended) AGAINST ('" . serendipity_db_escape_string($serendipity['GET']['filter']['body']) . "')"; $full = true; } } $filter_sql = implode(' AND ', $filter); // Fetch the entries $entries = serendipity_fetchEntries(false, false, serendipity_db_limit($offSet, $perPage + 1), true, false, $orderby, $filter_sql); ?> <div class="serendipity_admin_list"> <form action="?" method="get"> <input type="hidden" name="serendipity[action]" value="admin" /> <input type="hidden" name="serendipity[adminModule]" value="entries" /> <input type="hidden" name="serendipity[adminAction]" value="editSelect" /> <table width="100%" class="serendipity_admin_filters"> <tr> <td class="serendipity_admin_filters_headline" colspan="6"><strong><?php echo FILTERS; ?> </strong> - <?php echo FIND_ENTRIES; ?> </td> </tr> <tr> <td valign="top" width="80"><?php echo AUTHOR; ?> </td> <td valign="top"> <select name="serendipity[filter][author]"> <option value="">--</option> <?php $users = serendipity_fetchUsers('', null, true); if (is_array($users)) { foreach ($users as $user) { if (isset($user['artcount']) && $user['artcount'] < 1) { continue; } echo '<option value="' . $user['authorid'] . '" ' . (isset($serendipity['GET']['filter']['author']) && $serendipity['GET']['filter']['author'] == $user['authorid'] ? 'selected="selected"' : '') . '>' . htmlspecialchars($user['realname']) . '</option>' . "\n"; } } ?> </select> <select name="serendipity[filter][isdraft]"> <option value="all"><?php echo COMMENTS_FILTER_ALL; ?> </option> <option value="draft" <?php echo isset($serendipity['GET']['filter']['isdraft']) && $serendipity['GET']['filter']['isdraft'] == 'draft' ? 'selected="selected"' : ''; ?> ><?php echo DRAFT; ?> </option> <option value="publish" <?php echo isset($serendipity['GET']['filter']['isdraft']) && $serendipity['GET']['filter']['isdraft'] == 'publish' ? 'selected="selected"' : ''; ?> ><?php echo PUBLISH; ?> </option> </select> </td> <td valign="top" width="80"><?php echo CATEGORY; ?> </td> <td valign="top"> <select name="serendipity[filter][category]"> <option value="">--</option> <?php $categories = serendipity_fetchCategories(); $categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED); foreach ($categories as $cat) { echo '<option value="' . $cat['categoryid'] . '"' . ($serendipity['GET']['filter']['category'] == $cat['categoryid'] ? ' selected="selected"' : '') . '>' . str_repeat(' ', $cat['depth']) . htmlspecialchars($cat['category_name']) . '</option>' . "\n"; } ?> </select> </td> <td valign="top" width="80"><?php echo CONTENT; ?> </td> <td valign="top"><input class="input_textbox" size="10" type="text" name="serendipity[filter][body]" value="<?php echo isset($serendipity['GET']['filter']['body']) ? htmlspecialchars($serendipity['GET']['filter']['body']) : ''; ?> " /></td> </tr> <tr> <td class="serendipity_admin_filters_headline" colspan="6"><strong><?php echo SORT_ORDER; ?> </strong></td> </tr> <tr> <td> <?php echo SORT_BY; ?> </td> <td> <select name="serendipity[sort][order]"> <?php foreach ($sort_order as $so_key => $so_val) { echo '<option value="' . $so_key . '" ' . (isset($serendipity['GET']['sort']['order']) && $serendipity['GET']['sort']['order'] == $so_key ? 'selected="selected"' : '') . '>' . $so_val . '</option>' . "\n"; } ?> </select> </td> <td><?php echo SORT_ORDER; ?> </td> <td> <select name="serendipity[sort][ordermode]"> <option value="DESC" <?php echo isset($serendipity['GET']['sort']['ordermode']) && $serendipity['GET']['sort']['ordermode'] == 'DESC' ? 'selected="selected"' : ''; ?> ><?php echo SORT_ORDER_DESC; ?> </option> <option value="ASC" <?php echo isset($serendipity['GET']['sort']['ordermode']) && $serendipity['GET']['sort']['ordermode'] == 'ASC' ? 'selected="selected"' : ''; ?> ><?php echo SORT_ORDER_ASC; ?> </option> </select> </td> <td><?php echo ENTRIES_PER_PAGE; ?> </td> <td> <select name="serendipity[sort][perPage]"> <?php foreach ($per_page as $per_page_nr) { echo '<option value="' . $per_page_nr . '" ' . (isset($serendipity['GET']['sort']['perPage']) && $serendipity['GET']['sort']['perPage'] == $per_page_nr ? 'selected="selected"' : '') . '>' . $per_page_nr . '</option>' . "\n"; } ?> </select> </td> </tr> <tr> <td align="right" colspan="6"><input type="submit" name="go" value="<?php echo GO; ?> " class="serendipityPrettyButton input_button" /></td> </tr> </table> </form> <table class="serendipity_admin_list" cellpadding="5" width="100%"> <?php if (is_array($entries)) { $count = count($entries); $qString = '?serendipity[adminModule]=entries&serendipity[adminAction]=editSelect'; foreach ((array) $serendipity['GET']['sort'] as $k => $v) { $qString .= '&serendipity[sort][' . $k . ']=' . $v; } foreach ((array) $serendipity['GET']['filter'] as $k => $v) { $qString .= '&serendipity[filter][' . $k . ']=' . $v; } $linkPrevious = $qString . '&serendipity[page]=' . ($page - 1); $linkNext = $qString . '&serendipity[page]=' . ($page + 1); ?> <tr> <td> <?php if ($offSet > 0) { ?> <a href="<?php echo $linkPrevious; ?> " class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/previous.png'); ?> " /><?php echo PREVIOUS; ?> </a> <?php } ?> </td> <td align="right"> <?php if ($count > $perPage) { ?> <a href="<?php echo $linkNext; ?> " class="serendipityIconLinkRight"><?php echo NEXT; ?> <img src="<?php echo serendipity_getTemplateFile('admin/img/next.png'); ?> " /></a> <?php } ?> </td> </tr> </table> <script type="text/javascript"> function invertSelection() { var f = document.formMultiDelete; for (var i = 0; i < f.elements.length; i++) { if (f.elements[i].type == 'checkbox') { f.elements[i].checked = !(f.elements[i].checked); } } } </script> <form action="?" method="post" name="formMultiDelete" id="formMultiDelete"> <?php echo serendipity_setFormToken(); ?> <input type="hidden" name="serendipity[action]" value="admin" /> <input type="hidden" name="serendipity[adminModule]" value="entries" /> <input type="hidden" name="serendipity[adminAction]" value="multidelete" /> <?php // Print the entries $rows = 0; foreach ($entries as $entry) { $rows++; if ($rows > $perPage) { continue; } // Find out if the entry has been modified later than 30 minutes after creation if ($entry['timestamp'] <= $entry['last_modified'] - 60 * 30) { $lm = '<a href="#" title="' . LAST_UPDATED . ': ' . serendipity_formatTime(DATE_FORMAT_SHORT, $entry['last_modified']) . '" onclick="alert(this.title)"><img src="' . serendipity_getTemplateFile('admin/img/clock.png') . '" alt="*" style="border: 0px none ; vertical-align: bottom;" /></a>'; } else { $lm = ''; } if (!$serendipity['showFutureEntries'] && $entry['timestamp'] >= serendipity_serverOffsetHour()) { $entry_pre = '<a href="#" title="' . ENTRY_PUBLISHED_FUTURE . '" onclick="alert(this.title)"><img src="' . serendipity_getTemplateFile('admin/img/clock_future.png') . '" alt="*" style="border: 0px none ; vertical-align: bottom;" /></a> '; } else { $entry_pre = ''; } if (serendipity_db_bool($entry['properties']['ep_is_sticky'])) { $entry_pre .= ' ' . STICKY_POSTINGS . ': '; } if (serendipity_db_bool($entry['isdraft'])) { $entry_pre .= ' ' . DRAFT . ': '; } ?> <!-- <div class="serendipity_admin_list_item serendipity_admin_list_item_<?php echo $rows % 2 ? 'even' : 'uneven'; ?> "> --> <div class="serendipity_admin_list_item serendipity_admin_list_item_<?php echo $rows % 2 ? 'even' : 'uneven'; ?> "> <table width="100%" cellspacing="0" cellpadding="3"> <tr> <td> <strong><?php echo $entry_pre; ?> <a href="?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=edit&serendipity[id]=<?php echo $entry['id']; ?> " title="#<?php echo $entry['id']; ?> "><?php echo serendipity_truncateString(htmlspecialchars($entry['title']), 50); ?> </a></strong> </td> <td align="right"> <?php echo serendipity_formatTime(DATE_FORMAT_SHORT, $entry['timestamp']) . ' ' . $lm; ?> </td> </tr> <tr> <td> <?php echo POSTED_BY . ' ' . htmlspecialchars($entry['author']); if (count($entry['categories'])) { echo ' ' . IN . ' '; $cats = array(); foreach ($entry['categories'] as $cat) { $caturl = serendipity_categoryURL($cat); $cats[] = '<a href="' . $caturl . '">' . htmlspecialchars($cat['category_name']) . '</a>'; } echo implode(', ', $cats); } $entry['link'] = serendipity_archiveURL($entry['id'], $entry['title'], 'serendipityHTTPPath', true, array('timestamp' => $entry['timestamp'])); $entry['preview_link'] = '?serendipity[noBanner]=true&serendipity[noSidebar]=true&serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=preview&serendipity[id]=' . $entry['id']; ?> </td> <td align="right"> <?php if (serendipity_db_bool($entry['isdraft']) || !$serendipity['showFutureEntries'] && $entry['timestamp'] >= serendipity_serverOffsetHour()) { ?> <a target="_blank" href="<?php echo $entry['preview_link']; ?> " title="<?php echo PREVIEW . ' #' . $entry['id']; ?> " class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/zoom.png'); ?> " alt="<?php echo PREVIEW; ?> " /><?php echo PREVIEW; ?> </a> <?php } else { ?> <a target="_blank" href="<?php echo $entry['link']; ?> " title="<?php echo VIEW . ' #' . $entry['id']; ?> " class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/zoom.png'); ?> " alt="<?php echo VIEW; ?> " /><?php echo VIEW; ?> </a> <?php } ?> <a href="?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=edit&serendipity[id]=<?php echo $entry['id']; ?> " title="<?php echo EDIT . ' #' . $entry['id']; ?> " class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/edit.png'); ?> " alt="<?php echo EDIT; ?> " /><?php echo EDIT; ?> </a> <a href="?<?php echo serendipity_setFormToken('url'); ?> &serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=delete&serendipity[id]=<?php echo $entry['id']; ?> " title="<?php echo DELETE . ' #' . $entry['id']; ?> " class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/delete.png'); ?> " alt="<?php echo DELETE; ?> " /><?php echo DELETE; ?> </a> <input class="input_checkbox" type="checkbox" name="serendipity[multiDelete][]" value="<?php echo $entry['id']; ?> " /> </td> </tr> </table> </div> <?php } // end entries output ?> <table class="serendipity_admin_list" cellpadding="5" width="100%"> <tr> <td> <?php if ($offSet > 0) { ?> <a href="<?php echo $linkPrevious; ?> " class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/previous.png'); ?> " /><?php echo PREVIOUS; ?> </a> <?php } ?> </td> <td align="right"> <?php if ($count > $perPage) { ?> <a href="<?php echo $linkNext; ?> " class="serendipityIconLinkRight"><?php echo NEXT; ?> <img src="<?php echo serendipity_getTemplateFile('admin/img/next.png'); ?> " /></a> <?php } ?> </td> </tr> </table> <table class="serendipity_admin_list" cellpadding="0" width="100%"> <tr> <td align="right"> <input type="button" name="toggle" value="<?php echo INVERT_SELECTIONS; ?> " onclick="invertSelection()" class="serendipityPrettyButton input_button" /> <input type="submit" name="toggle" value="<?php echo DELETE_SELECTED_ENTRIES; ?> " class="serendipityPrettyButton input_button" /> </td> </tr> </table> </form> <div class="serendipity_admin_list_item serendipity_admin_list_item_<?php echo ($rows + 1) % 2 ? 'even' : 'uneven'; ?> "> <table width="100%" cellspacing="0" cellpadding="3"> <tr> <td> <form action="?" method="get"> <input type="hidden" name="serendipity[action]" value="admin" /> <input type="hidden" name="serendipity[adminModule]" value="entries" /> <input type="hidden" name="serendipity[adminAction]" value="editSelect" /> <?php echo EDIT_ENTRY; ?> : #<input class="input_textbox" type="text" size="3" name="serendipity[id]" /> <input type="submit" name="serendipity[editSubmit]" value="<?php echo GO; ?> " class="serendipityPrettyButton input_button" /> </form> </td> </tr> </table> </div> <?php } else { // We've got nothing ?> <tr> <td align="center" class="serendipityAdminMsgNote"> <img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="<?php echo serendipity_getTemplateFile('admin/img/admin_msg_note.png'); ?> " alt="" /> <?php echo NO_ENTRIES_TO_PRINT; ?> </td> </tr> </table> <?php } ?> </div> <?php }
/** * Parses entries to display them for RSS/Atom feeds to be passed on to generic Smarty templates * * This function searches for existing RSS feed template customizations. As long as a template * with the same name as the $version variable exists, it will be emitted. * * @access public * @see serendipity_fetchEntries(), rss.php * @param array A superarray of entries to output * @param string The version/type of a RSS/Atom feed to display (atom1_0, rss2_0 etc) * @param boolean If true, this is a comments feed. If false, it's an Entry feed. * @param boolean Indicates if this feed is a fulltext feed (true) or only excercpt (false) * @param boolean Indicates if E-Mail addresses should be shown (true) or hidden (false) * @return */ function serendipity_printEntries_rss(&$entries, $version, $comments = false, $fullFeed = false, $showMail = true) { global $serendipity; $options = array('version' => $version, 'comments' => $comments, 'fullFeed' => $fullFeed, 'showMail' => $showMail); serendipity_plugin_api::hook_event('frontend_entries_rss', $entries, $options); if (is_array($entries)) { foreach ($entries as $key => $_entry) { $entry =& $entries[$key]; if (isset($entry['entrytimestamp'])) { $e_ts = $entry['entrytimestamp']; } else { $e_ts = $entry['timestamp']; } $entry['feed_id'] = isset($entry['entryid']) && !empty($entry['entryid']) ? $entry['entryid'] : $entry['id']; // set feed guid only, if not already defined externaly if (empty($entry['feed_guid'])) { $entry['feed_guid'] = serendipity_rss_getguid($entry, $options['comments']); } $entry['feed_entryLink'] = serendipity_archiveURL($entry['feed_id'], $entry['title'], 'baseURL', true, array('timestamp' => $e_ts)); if ($options['comments'] == true) { // Display username as part of the title for easier feed-readability if ($entry['type'] == 'TRACKBACK' && !empty($entry['ctitle'])) { $entry['author'] .= ' - ' . $entry['ctitle']; } $entry['title'] = (!empty($entry['author']) ? $entry['author'] : ANONYMOUS) . ': ' . $entry['title']; // No HTML allowed here: $entry['body'] = strip_tags($entry['body']); } // Embed a link to extended entry, if existing if ($options['fullFeed']) { $entry['body'] .= ' ' . $entry['extended']; $ext = ''; } elseif ($entry['exflag']) { $ext = '<br /><a href="' . $entry['feed_entryLink'] . '#extended">' . sprintf(VIEW_EXTENDED_ENTRY, htmlspecialchars($entry['title'])) . '</a>'; } else { $ext = ''; } $addData = array('from' => 'functions_entries:printEntries_rss', 'rss_options' => $options); serendipity_plugin_api::hook_event('frontend_display', $entry, $addData); // Do some relative -> absolute URI replacing magic. Replaces all HREF/SRC (<a>, <img>, ...) references to only the serendipitypath with the full baseURL URI // garvin: Could impose some problems. Closely watch this one. $entry['body'] = preg_replace('@(href|src)=("|\')(' . preg_quote($serendipity['serendipityHTTPPath']) . ')(.*)("|\')(.*)>@imsU', '\\1=\\2' . $serendipity['baseURL'] . '\\4\\2\\6>', $entry['body']); // jbalcorn: clean up body for XML compliance as best we can. $entry['body'] = xhtml_cleanup($entry['body']); // extract author information if (isset($entry['no_email']) && $entry['no_email'] || $options['showMail'] === FALSE) { $entry['email'] = '*****@*****.**'; // RSS Feeds need an E-Mail address! } elseif (empty($entry['email'])) { $query = "select email FROM {$serendipity['dbPrefix']}authors WHERE authorid = '" . serendipity_db_escape_string($entry['authorid']) . "'"; $results = serendipity_db_query($query); $entry['email'] = $results[0]['email']; } if (!is_array($entry['categories'])) { $entry['categories'] = array(0 => array('category_name' => $entry['category_name'], 'feed_category_name' => serendipity_utf8_encode(htmlspecialchars($entry['category_name'])), 'categoryURL' => serendipity_categoryURL($entry, 'baseURL'))); } else { foreach ($entry['categories'] as $cid => $_cat) { $cat =& $entry['categories'][$cid]; $cat['categoryURL'] = serendipity_categoryURL($cat, 'baseURL'); $cat['feed_category_name'] = serendipity_utf8_encode(htmlspecialchars($cat['category_name'])); } } // Prepare variables // 1. UTF8 encoding + htmlspecialchars. $entry['feed_title'] = serendipity_utf8_encode(htmlspecialchars($entry['title'])); $entry['feed_blogTitle'] = serendipity_utf8_encode(htmlspecialchars($serendipity['blogTitle'])); $entry['feed_title'] = serendipity_utf8_encode(htmlspecialchars($entry['title'])); $entry['feed_author'] = serendipity_utf8_encode(htmlspecialchars($entry['author'])); $entry['feed_email'] = serendipity_utf8_encode(htmlspecialchars($entry['email'])); // 2. gmdate $entry['feed_timestamp'] = gmdate('Y-m-d\\TH:i:s\\Z', serendipity_serverOffsetHour($entry['timestamp'])); $entry['feed_last_modified'] = gmdate('Y-m-d\\TH:i:s\\Z', serendipity_serverOffsetHour($entry['last_modified'])); $entry['feed_timestamp_r'] = date('r', serendipity_serverOffsetHour($entry['timestamp'])); // 3. UTF8 encoding $entry['feed_body'] = serendipity_utf8_encode($entry['body']); $entry['feed_ext'] = serendipity_utf8_encode($ext); $entry_hook = 'frontend_display:unknown:per-entry'; switch ($version) { case 'opml1.0': $entry_hook = 'frontend_display:opml-1.0:per_entry'; break; case '0.91': $entry_hook = 'frontend_display:rss-0.91:per_entry'; break; case '1.0': $entry_hook = 'frontend_display:rss-1.0:per_entry'; break; case '2.0': $entry_hook = 'frontend_display:rss-2.0:per_entry'; break; case 'atom0.3': $entry_hook = 'frontend_display:atom-0.3:per_entry'; break; case 'atom1.0': $entry_hook = 'frontend_display:atom-1.0:per_entry'; break; } serendipity_plugin_api::hook_event($entry_hook, $entry); $entry['per_entry_display_dat'] = $entry['display_dat']; } } }
/** * Return HTML containing a list of categories * * Prints a list of categories for use in forms, the sidebar, or whereever... * * @access public * @param array An array of categories, typically gathered by serendipity_fetchCategories() * @param array An array which holds IDs which are meant to be selected within a HTML SELECT form field [used for recursion] * @param int The type of category list (0: HTML span list, 1/2: <option>s, 3: HTML Div list, 4: CSV data) to return * @param int The parent ID of a category [for recursion] * @param int The current nesting level [for recursion] * @param string Tells the function, whether or not to display the XML button for each category. * If empty, no links to the xml feeds will be displayed; If you want to, you can * pass an image here (this setting is only used, when type==3). * @param string The character to use for blank indenting * @see serendipity_fetchCategories() */ function serendipity_generateCategoryList($cats, $select = array(0), $type = 0, $id = 0, $level = 0, $xmlImg = '', $blank_char = '�') { global $serendipity; if (!is_array($cats) || !count($cats)) { return; } $ret = ''; foreach ($cats as $cat) { if ($cat['parentid'] == $id) { switch ($type) { case 0: $ret .= str_repeat(' ', $level * 2) . '• <span id="catItem_' . $cat['categoryid'] . '"' . ($cat['categoryid'] && in_array($cat['categoryid'], $select) ? ' selected="selected"' : '') . '><a href="?serendipity[adminModule]=category&serendipity[cat][catid]=' . $cat['categoryid'] . '">' . (!empty($cat['category_icon']) ? '<img style="vertical-align: middle;" src="' . $cat['category_icon'] . '" border="0" alt="' . $cat['category_name'] . '"/> ' : '') . htmlspecialchars($cat['category_name']) . (!empty($cat['category_description']) ? ' - ' . htmlspecialchars($cat['category_description']) : '') . '</a></span><br/>' . "\n"; break; case 1: case 2: $ret .= '<option value="' . $cat['categoryid'] . '"' . ($cat['categoryid'] && in_array($cat['categoryid'], $select) ? ' selected="selected"' : '') . '>'; $ret .= str_repeat(' ', $level * 2) . htmlspecialchars($cat['category_name']) . ($type == 1 && !empty($cat['category_description']) ? ' - ' . htmlspecialchars($cat['category_description']) : ''); $ret .= '</option>'; break; case 3: $category_id = serendipity_makeFilename($cat['category_name']); if (!empty($xmlImg)) { $ret .= sprintf('<div style="padding-bottom: 2px;">' . '<a href="%s" title="%s"><img alt="xml" src="%s" style="vertical-align: bottom; display: inline; border: 0px" /></a> %s' . '<a href="%s" title="%s">%s</a>' . '</div>', $serendipity['serendipityHTTPPath'] . 'rss.php?category=' . $cat['categoryid'] . '_' . $category_id, htmlspecialchars($cat['category_description']), $xmlImg, str_repeat(' ', $level * 3), serendipity_categoryURL($cat, 'serendipityHTTPPath'), htmlspecialchars($cat['category_description']), htmlspecialchars($cat['category_name'])); } else { $ret .= sprintf('%s<a href="%s" title="%s">%s</a><br />', str_repeat(' ', $level * 3), serendipity_categoryURL($cat, 'serendipityHTTPPath'), htmlspecialchars($cat['category_description']), htmlspecialchars($cat['category_name'])); } break; case 4: $ret .= $cat['categoryid'] . '|||' . str_repeat($blank_char, $level * 2) . $cat['category_name'] . '@@@'; break; } $ret .= serendipity_generateCategoryList($cats, $select, $type, $cat['categoryid'], $level + 1, $xmlImg, $blank_char); } } return $ret; }
function generateSitemap(&$bag) { global $serendipity; // decide which NULL-function to use switch ($serendipity['dbType']) { case 'postgres': $sqlnullfunction = 'COALESCE'; break; case 'sqlite': case 'mysql': case 'mysqli': $sqlnullfunction = 'IFNULL'; break; default: $sqlnullfunction = ''; } $hooks =& $bag->get('event_hooks'); $do_pingback = serendipity_db_bool($this->get_config('sitemap_pingback', false)); $pingback_url = $this->get_config('sitemap_pingback_urls', false); // start the xml $sitemap_xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $sitemap_xml .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n"; $sitemap_xml .= "\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; $sitemap_xml .= "\txsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\n"; $sitemap_xml .= "\t\t\thttp://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n"; // add link to the main page $this->addtoxml($sitemap_xml, $serendipity['baseURL'], time(), 0.6); // fetch all entries from the db (tested with: mysql, sqlite, postgres) $entries = serendipity_db_query('SELECT entries.id AS id, entries.title AS title, ' . $sqlnullfunction . '(entries.last_modified,0) AS timestamp_1, ' . $sqlnullfunction . '(MAX(comments.timestamp),0) AS timestamp_2 FROM ' . $serendipity['dbPrefix'] . 'entries entries LEFT JOIN ' . $serendipity['dbPrefix'] . 'comments comments ON entries.id = comments.entry_id WHERE entries.isdraft = \'false\' GROUP BY entries.id, entries.title, entries.last_modified ORDER BY entries.id', false, 'assoc'); if (is_array($entries)) { // add entries foreach ($entries as $entry) { $max = max($entry['timestamp_1'] + 0, $entry['timestamp_2'] + 0); $url = serendipity_archiveURL($entry['id'], $entry['title']); $this->addtoxml($sitemap_xml, $url, $max, 0.7); } } // add possible perm links $permlink = serendipity_db_query('SELECT entryid, timestamp, value FROM ' . $serendipity['dbPrefix'] . 'entryproperties AS entryproperties, ' . $serendipity['dbPrefix'] . 'entries AS entries WHERE entryproperties.property = \'permalink\' AND entries.id=entryproperties.entryid', false, 'assoc'); if (is_array($permlink)) { foreach ($permlink as $cur) { $path_quoted = preg_quote($serendipity['serendipityHTTPPath'], '#'); $url = $serendipity['baseURL'] . preg_replace("#{$path_quoted}#", '', $cur['value'], 1); $cur_time = $cur['timestamp'] == 0 ? null : (int) $cur['timestamp']; $this->addtoxml($sitemap_xml, $url, $cur_time, 0.8); } // check for the right order of plugins $order = serendipity_db_query('SELECT name, sort_order FROM ' . $serendipity['dbPrefix'] . 'plugins plugins WHERE plugins.name LIKE \'%serendipity_event_mobile_output%\' OR plugins.name LIKE \'%serendipity_event_custom_permalinks%\' ORDER BY plugins.sort_order', false, 'assoc'); if (is_array($order)) { if (strpos($order[0]['name'], 'serendipity_event_custom_permalinks') === FALSE) { echo '<br/>' . PLUGIN_EVENT_MOBILE_OUTPUT_SITEMAP_PERMALINK_WARNING . '<br/>'; } } } // fetch categories and their last entry date (tested with: mysql, sqlite, postgres) $q = 'SELECT category.categoryid AS id, category_name, category_description, MAX(entries.last_modified) AS last_mod FROM ' . $serendipity['dbPrefix'] . 'category category, ' . $serendipity['dbPrefix'] . 'entrycat entrycat, ' . $serendipity['dbPrefix'] . 'entries entries WHERE category.categoryid = entrycat.categoryid AND entrycat.entryid = entries.id GROUP BY category.categoryid, category.category_name, category.category_description ORDER BY category.categoryid'; $categories = serendipity_db_query($q, false, 'assoc'); // add categories if (is_array($categories)) { foreach ($categories as $category) { $max = 0 + $category['last_mod']; /* v0.9 */ if (version_compare((double) $serendipity['version'], '0.9', '>=')) { $data = array('categoryid' => $category['id'], 'category_name' => $category['category_name'], 'category_description' => $category['category_description']); $url = serendipity_categoryURL($data); } else { $url = serendipity_rewriteURL(PATH_CATEGORIES . '/' . serendipity_makePermalink(PERM_CATEGORIES, array('id' => $category['id'], 'title' => $category['category_name']))); } $this->addtoxml($sitemap_xml, $url, $max, 0.4); } } else { $categories = array(); } // finish the xml $sitemap_xml .= "</urlset>\n"; $do_gzip = serendipity_db_bool($this->get_config('gzip_sitemap', true)); // decide whether to use gzip-output or not if ($do_gzip && function_exists('gzencode')) { $filename = '/mobile_sitemap.xml.gz'; $temp = gzencode($sitemap_xml); // only use the compressed data and filename if no error occured if (!($temp === FALSE)) { $sitemap_xml = $temp; } else { $filename = '/mobile_sitemap.xml'; } } else { $filename = '/mobile_sitemap.xml'; } // write result to file $outfile = fopen($serendipity['serendipityPath'] . $filename, 'w'); if ($outfile === false) { echo '<strong>' . PLUGIN_EVENT_MOBILE_OUTPUT_SITEMAP_FAILEDOPEN . '</strong>'; return false; } flock($outfile, LOCK_EX); fputs($outfile, $sitemap_xml); flock($outfile, LOCK_UN); fclose($outfile); // Walk through the list of pingback-URLs foreach (explode(';', $pingback_url) as $cur_pingback_url) { $pingback_name = PLUGIN_EVENT_MOBILE_OUTPUT_SITEMAP_UNKNOWN_HOST; $cur_url = sprintf($cur_pingback_url, rawurlencode($serendipity['baseURL'] . $filename)); // extract domain-portion from URL if (preg_match('@^https?://([^/]+)@', $cur_pingback_url, $matches) > 0) { $pingback_name = $matches[1]; } if (!serendipity_db_bool($eventData['isdraft']) && $do_pingback && $cur_url) { $answer = $this->send_ping($cur_url); if ($answer) { printf(PLUGIN_EVENT_MOBILE_OUTPUT_SITEMAP_REPORT_OK, $pingback_name); } else { printf(PLUGIN_EVENT_MOBILE_OUTPUT_SITEMAP_REPORT_ERROR, $pingback_name, $cur_url); } } else { printf(PLUGIN_EVENT_MOBILE_OUTPUT_SITEMAP_REPORT_MANUAL, $pingback_name, $cur_url); } } return true; }
function metaWeblog_getCategories($message) { global $serendipity; $val = $message->params[1]; $username = $val->getval(); $val = $message->params[2]; $password = $val->getval(); if (!serendipity_authenticate_author($username, $password)) { return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED); } $cats = serendipity_fetchCategories($serendipity['authorid']); $xml_entries_vals = array(); foreach ((array) $cats as $cat) { if ($cat['categoryid']) { $xml_entries_vals[] = new XML_RPC_Value(array('categoryName' => new XML_RPC_Value($cat['category_name'], 'string'), 'description' => new XML_RPC_Value($cat['category_name'], 'string'), 'htmlUrl' => new XML_RPC_Value(serendipity_categoryURL($cat, 'baseURL'), 'string'), 'rssUrl' => new XML_RPC_Value(serendipity_feedCategoryURL($cat, 'baseURL'), 'string')), 'struct'); } } $xml_entries = new XML_RPC_Value($xml_entries_vals, 'array'); return new XML_RPC_Response($xml_entries); }
function generate_content(&$title) { global $serendipity; $title = $this->get_config('title'); $smarty = serendipity_db_bool($this->get_config('smarty', false)); $which_category = $this->get_config('authorid'); $sort = $this->get_config('sort_order'); if ($sort == 'none') { $sort = ''; } else { $sort .= ' ' . $this->get_config('sort_method'); } $is_form = serendipity_db_bool($this->get_config('allow_select')); if ($which_category === "login") { $which_category = (int) $serendipity['authorid']; if ($which_category === 0) { $which_category = -1; // Set to -1 for anonymous authors to get a proper match. } } $categories = serendipity_fetchCategories(empty($which_category) ? 'all' : $which_category, '', $sort, 'read'); $cat_count = array(); if (serendipity_db_bool($this->get_config('show_count'))) { $cat_sql = "SELECT c.categoryid, c.category_name, count(e.id) as postings\n FROM {$serendipity['dbPrefix']}entrycat ec,\n {$serendipity['dbPrefix']}category c,\n {$serendipity['dbPrefix']}entries e\n WHERE ec.categoryid = c.categoryid\n AND ec.entryid = e.id\n AND e.isdraft = 'false'\n " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp <= " . serendipity_db_time() : '') . "\n GROUP BY c.categoryid, c.category_name\n ORDER BY postings DESC"; $category_rows = serendipity_db_query($cat_sql); if (is_array($category_rows)) { foreach ($category_rows as $cat) { $cat_count[$cat['categoryid']] = $cat['postings']; } } } $html = ''; if (!$smarty && $is_form) { $html .= '<form action="' . $serendipity['baseURL'] . $serendipity['indexFile'] . '?frontpage" method="post"> <div id="serendipity_category_form_content">'; } if (!$smarty) { $html .= '<ul id="serendipity_categories_list" style="list-style: none; margin: 0px; padding: 0px">'; } $image = $this->get_config('image', serendipity_getTemplateFile('img/xml.gif')); $image = $image == "'none'" || $image == 'none' ? '' : $image; $use_parent = $this->get_config('parent_base'); $hide_parent = serendipity_db_bool($this->get_config('hide_parent')); $parentdepth = 0; $hide_parallel = serendipity_db_bool($this->get_config('hide_parallel')); $hidedepth = 0; if (is_array($categories) && count($categories)) { $categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED); foreach ($categories as $cid => $cat) { // Hide parents not wanted if ($use_parent && $use_parent != 'all') { if ($parentdepth == 0 && $cat['parentid'] != $use_parent && $cat['categoryid'] != $use_parent) { unset($categories[$cid]); continue; } else { if ($hide_parent && $cat['categoryid'] == $use_parent) { unset($categories[$cid]); continue; } if ($cat['depth'] < $parentdepth) { $parentdepth = 0; unset($categories[$cid]); continue; } if ($parentdepth == 0) { $parentdepth = $cat['depth']; } } } // Hide parents outside of our tree if ($hide_parallel && $serendipity['GET']['category']) { if ($hidedepth == 0 && $cat['parentid'] != $serendipity['GET']['category'] && $cat['categoryid'] != $serendipity['GET']['category']) { unset($categories[$cid]); continue; } else { if ($cat['depth'] < $hidedepth) { $hidedepth = 0; unset($categories[$cid]); continue; } if ($hidedepth == 0) { $hidedepth = $cat['depth']; } } } $categories[$cid]['feedCategoryURL'] = serendipity_feedCategoryURL($cat, 'serendipityHTTPPath'); $categories[$cid]['categoryURL'] = serendipity_categoryURL($cat, 'serendipityHTTPPath'); $categories[$cid]['paddingPx'] = $cat['depth'] * 6; $categories[$cid]['catdepth'] = $cat['depth']; if (!empty($cat_count[$cat['categoryid']])) { $categories[$cid]['true_category_name'] = $cat['category_name']; $categories[$cid]['category_name'] .= ' (' . $cat_count[$cat['categoryid']] . ')'; $categories[$cid]['article_count'] = $cat_count[$cat['categoryid']]; } if (!$smarty) { $html .= '<li class="category_depth' . $cat['depth'] . ' category_' . $cat['categoryid'] . '" style="display: block;">'; if ($is_form) { $html .= '<input style="width: 15px" type="checkbox" name="serendipity[multiCat][]" value="' . $cat['categoryid'] . '" />'; } if (!empty($image)) { $html .= '<a class="serendipity_xml_icon" href="' . $categories[$cid]['feedCategoryURL'] . '"><img src="' . $image . '" alt="XML" style="border: 0px" /></a> '; } $html .= '<a href="' . $categories[$cid]['categoryURL'] . '" title="' . htmlspecialchars($cat['category_description']) . '" style="padding-left: ' . $categories[$cid]['paddingPx'] . 'px">' . htmlspecialchars($categories[$cid]['category_name']) . '</a>'; $html .= '</li>' . "\n"; } } } if (!$smarty) { $html .= '</ul>'; } if (!$smarty && $is_form) { $html .= '<div class="category_submit"><br /><input type="submit" name="serendipity[isMultiCat]" value="' . GO . '" /></div>'; } if (!$smarty) { $html .= sprintf('<div class="category_link_all"><br /><a href="%s" title="%s">%s</a></div>', $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?frontpage', ALL_CATEGORIES, ALL_CATEGORIES); } if (!$smarty && $is_form) { $html .= '</div></form>'; } if (!$smarty) { echo $html; } else { $plugin_categories_data = array('is_form' => $is_form, 'category_image' => $image, 'form_url' => $serendipity['baseURL'] . $serendipity['indexFile'] . '?frontpage', 'categories' => is_array($categories) ? $categories : array()); $serendipity['smarty']->assign($plugin_categories_data); echo serendipity_smarty_fetch('CATEGORIES', 'plugin_categories.tpl'); } }
$qString .= '&serendipity[sort][' . $k . ']=' . $v; } foreach ((array) $serendipity['GET']['filter'] as $k => $v) { $qString .= '&serendipity[filter][' . $k . ']=' . $v; } $data['linkFirst'] = $qString . '&serendipity[page]=' . 0; $data['linkPrevious'] = $qString . '&serendipity[page]=' . ($page - 1); $data['linkNext'] = $qString . '&serendipity[page]=' . ($page + 1); $data['linkLast'] = $qString . '&serendipity[page]='; // is done in tpl per $totalPages $smartentries = array(); foreach ($entries as $ey) { $entry_cats = array(); if (count($ey['categories'])) { foreach ($ey['categories'] as $cat) { $cat['link'] = serendipity_categoryURL($cat); $entry_cats[] = $cat; } } $smartentries[] = array('id' => $ey['id'], 'title' => serendipity_specialchars($ey['title']), 'timestamp' => (int) $ey['timestamp'], 'last_modified' => (int) $ey['last_modified'], 'isdraft' => serendipity_db_bool($ey['isdraft']), 'ep_is_sticky' => serendipity_db_bool($ey['properties']['ep_is_sticky']) ? true : false, 'pubdate' => date("c", (int) $ey['timestamp']), 'author' => serendipity_specialchars($ey['author']), 'cats' => $entry_cats, 'preview' => serendipity_db_bool($ey['isdraft']) || !$serendipity['showFutureEntries'] && $ey['timestamp'] >= serendipity_serverOffsetHour() ? true : false, 'archive_link' => serendipity_archiveURL($ey['id'], $ey['title'], 'serendipityHTTPPath', true, array('timestamp' => $ey['timestamp'])), 'preview_link' => '?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=preview&' . serendipity_setFormToken('url') . '&serendipity[id]=' . $ey['id']); } $data['entries'] = $smartentries; $data['urltoken'] = serendipity_setFormToken('url'); $data['formtoken'] = serendipity_setFormToken(); $data['serverOffsetHour'] = serendipity_serverOffsetHour(); $data['showFutureEntries'] = $serendipity['showFutureEntries']; $data['filter_import'] = $filter_import; $data['sort_import'] = $sort_import; } else { $data['no_entries'] = true; }
/** * Create a permalink for the given input data * * You can pass an entry array, or an author array to this function * and then get a permalink valid for that array * * @access public * @param array The input data used for building the permalink * @param string The type of the permalink (entry|category|author) * @return string The permalink */ function serendipity_getPermalink(&$data, $type = 'entry') { switch ($type) { case 'entry': return serendipity_archiveURL($data['id'], $data['title'], '', false, array('timestamp' => $data['timestamp'])); break; case 'category': return serendipity_categoryURL($data, '', false); break; case 'author': return serendipity_authorURL($data, '', false); break; } return false; }
/** * Creates a DHTML menu of serendipity categories. * * The menu is echoed out. * * @param string $title (Serves as the top level menu item if present) * @return void * @see http://pear.php.net/HTML_TreeMenu PEAR::HTML_TreeMenu */ function generate_content(&$title) { global $serendipity; $title = $this->get_config('title', $this->title); // may want to put this in bundled_libs or a sub directory of this directory $pear = false; if (@(include_once 'HTML/TreeMenu.php')) { $pear = true; } elseif (@(include_once 'HTML_TreeMenu/TreeMenu.php')) { $pear = true; } if ($pear) { $which_category = $this->get_config('authorid'); // build an accessible array of categories foreach (serendipity_fetchCategories(empty($which_category) ? 'all' : $which_category) as $cat) { if (!is_array($cat) || !isset($cat['categoryid'])) { continue; } $categories[$cat['categoryid']] = $cat; } // create an array of numbers of entries per category $cat_count = array(); if (serendipity_db_bool($this->get_config('show_count'))) { $cat_sql = "SELECT c.categoryid, c.category_name, count(e.id) as postings\n FROM {$serendipity['dbPrefix']}entrycat ec,\n {$serendipity['dbPrefix']}category c,\n {$serendipity['dbPrefix']}entries e\n WHERE ec.categoryid = c.categoryid\n AND ec.entryid = e.id\n AND e.isdraft = 'false'\n " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp <= " . serendipity_db_time() : '') . "\n GROUP BY c.categoryid, c.category_name\n ORDER BY postings DESC"; $category_rows = serendipity_db_query($cat_sql); if (is_array($category_rows)) { foreach ($category_rows as $cat) { $cat_count[$cat['categoryid']] = $cat['postings']; } } } $image = $this->get_config('image', serendipity_getTemplateFile('img/xml.gif')); $image = $image == "'none'" || $image == 'none' ? '' : $image; // create nodes foreach ($categories as $cid => $cat) { if (function_exists('serendipity_categoryURL')) { $link = serendipity_categoryURL($cat, 'serendipityHTTPPath'); } else { $link = serendipity_rewriteURL(PATH_CATEGORIES . '/' . serendipity_makePermalink(PERM_CATEGORIES, array('id' => $cat['categoryid'], 'title' => $cat['category_name'])), 'serendipityHTTPPath'); } if (!empty($cat_count[$cat['categoryid']])) { // $categories[$cid]['true_category_name'] = $cat['category_name']; $cat['category_name'] .= ' (' . $cat_count[$cat['categoryid']] . ')'; // $categories[$cid]['article_count'] = $cat_count[$cat['categoryid']]; } if (!empty($image)) { $feedURL = serendipity_feedCategoryURL($cat, 'serendipityHTTPPath'); $feed = '<a class="serendipity_xml_icon" href="' . $feedURL . '"><img src="' . $image . '" alt="XML" style="border: 0px;vertical-align:middle"/></a> '; $link = '<a href="' . $link . '" target="_self"><span>' . $cat['category_name'] . '</span></a>'; // work around a problem in HTML_TreeNode: when there is a href in 'text', 'link' is not converted to a link. $cat_nodes[$cat['categoryid']] = new HTML_TreeNode(array('text' => $feed . $link)); } else { $cat_nodes[$cat['categoryid']] = new HTML_TreeNode(array('text' => $feed . $cat['category_name'], 'link' => $link)); } } // create a top level for "all categories" // this serves as the title $cat_nodes[0] = new HTML_TreeNode(array('text' => ALL_CATEGORIES, 'link' => $serendipity['baseURL'])); // nest nodes (thanks to PHP references) foreach ($categories as $category) { $cat_nodes[$category['parentid']]->addItem($cat_nodes[$category['categoryid']]); } // nest the "all categories" category $menu = new HTML_TreeMenu(); $menu->addItem($cat_nodes[0]); $tree = new HTML_TreeMenu_DHTML($menu, array('images' => $serendipity['baseURL'] . $this->get_config('image_path'))); // Add heading for block #$output = '<h2 class="serendipitySideBarTitle" style="font-weight: bold;">'.$title.'</h2><br />'; // Put inside a div with "overflow:hidden" to avoid items of the sidebar plugin running outside the blog // Maybe we can put a config setting to choose if the block should be displayed with or without overflow setting. $output .= '<div style="overflow: hidden;">'; $output .= $tree->toHTML(); $output .= '</div>'; echo '<script type="text/javascript" src="' . $serendipity['baseURL'] . $this->get_config('script_path') . '"></script>'; } else { $output .= "Please install PEAR package HTML_TreeMenu to enable this plugin."; } echo $output; }
function add_categories(&$sitemap_xml) { global $serendipity; // fetch categories and their last entry date (tested with: mysql, sqlite, postgres) $categories = serendipity_db_query('SELECT category.categoryid AS id, category_name, category_description, MAX(entries.last_modified) AS last_mod FROM ' . $serendipity['dbPrefix'] . 'category category, ' . $serendipity['dbPrefix'] . 'entrycat entrycat, ' . $serendipity['dbPrefix'] . 'entries entries WHERE category.categoryid = entrycat.categoryid AND entrycat.entryid = entries.id GROUP BY category.categoryid, category.category_name, category.category_description ORDER BY category.categoryid', false, 'assoc'); if (is_array($categories)) { foreach ($categories as $category) { $max = 0 + $category['last_mod']; /* v0.9 */ if (version_compare((double) $serendipity['version'], '0.9', '>=')) { $data = array('categoryid' => $category['id'], 'category_name' => $category['category_name'], 'category_description' => $category['category_description']); $url = serendipity_categoryURL($data); } else { $url = serendipity_rewriteURL(PATH_CATEGORIES . '/' . serendipity_makePermalink(PERM_CATEGORIES, array('id' => $category['id'], 'title' => $category['category_name']))); } $this->addtoxml($sitemap_xml, $url, $max, 0.4); } } else { $categories = array(); } // remember for category-feeds and archives $this->categories = $categories; }
function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; if ($event == 'frontend_header') { $start_url = $serendipity['baseURL']; $start_title = $serendipity['blogTitle']; echo '<link rel="start" href="' . $start_url . '" title="' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($start_title) : htmlspecialchars($start_title, ENT_COMPAT, LANG_CHARSET)) . '" />' . "\n"; if ($serendipity['GET']['action'] == 'read' && !empty($serendipity['GET']['id'])) { // Article detail view echo '<link rel="up" href="' . $start_url . '" title="' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($start_title) : htmlspecialchars($start_title, ENT_COMPAT, LANG_CHARSET)) . '" />' . "\n"; $this->backAndForth($this->showPaging($serendipity['GET']['id'])); // END article detail view echo '<link rel="canonical" href="' . $this->getEntry($serendipity['GET']['id']) . '" />' . "\n"; } elseif ($serendipity['GET']['action'] == 'read' && is_array($serendipity['range'])) { // Specific Date Archives view echo '<link rel="up" href="' . serendipity_rewriteURL(PATH_ARCHIVE) . '" title="' . ARCHIVES . '" />' . "\n"; echo '<link rel="canonical" href="' . $this->getArchiveParameters() . '" />' . "\n"; $links = array(); $add_query = ''; $year = date('Y', $serendipity['range'][0]); $month = date('m', $serendipity['range'][0]); $day = date('d', $serendipity['range'][0]); $pageMonthNext = array('day' => '1', 'month' => $month + 1, 'year' => $year); $pageMonthPrev = array('day' => '1', 'month' => $month - 1, 'year' => $year); $pageDayNext = array('day' => $day + 1, 'month' => $month, 'year' => $year); $pageDayPrev = array('day' => $day - 1, 'month' => $month, 'year' => $year); $diff = $serendipity['range'][1] - $serendipity['range'][0]; if (isset($serendipity['GET']['category'])) { $categoryid = (int) serendipity_db_escape_string($serendipity['GET']['category']); $add_query = '/C' . $categoryid; } if ($diff < 86400) { // Paging day by day $ts = mktime(0, 0, 0, $pageDayPrev['month'], $pageDayPrev['day'], $pageDayPrev['year']); $links['prev'] = array('link' => serendipity_archiveDateUrl(sprintf('%4d/%02d/%02d', date('Y', $ts), date('m', $ts), date('d', $ts))), 'title' => sprintf(ENTRIES_FOR, serendipity_formatTime(DATE_FORMAT_ENTRY, $ts, false))); $ts = mktime(0, 0, 0, $pageDayNext['month'], $pageDayNext['day'], $pageDayNext['year']); $links['next'] = array('link' => serendipity_archiveDateUrl(sprintf('%4d/%02d/%02d', date('Y', $ts), date('m', $ts), date('d', $ts))), 'title' => sprintf(ENTRIES_FOR, serendipity_formatTime(DATE_FORMAT_ENTRY, $ts, false))); } elseif ($diff < 86400 * 28) { // Paging by week // TODO - Don't know :-) } else { // Paging by month $ts = mktime(0, 0, 0, $pageMonthPrev['month'], $pageMonthPrev['day'], $pageMonthPrev['year']); $links['prev'] = array('link' => serendipity_archiveDateUrl(sprintf('%4d/%02d', date('Y', $ts), date('m', $ts))), 'title' => sprintf(ENTRIES_FOR, serendipity_formatTime('%B %Y', $ts, false))); $ts = mktime(0, 0, 0, $pageMonthNext['month'], $pageMonthNext['day'], $pageMonthNext['year']); $links['next'] = array('link' => serendipity_archiveDateUrl(sprintf('%4d/%02d', date('Y', $ts), date('m', $ts))), 'title' => sprintf(ENTRIES_FOR, serendipity_formatTime('%B %Y', $ts, false))); } $this->backAndForth($links); // END Specific Date Archives view } elseif ($serendipity['GET']['action'] == 'archives') { // Full month/year archives overview echo '<link rel="up" href="' . serendipity_rewriteURL(PATH_ARCHIVE) . '" title="' . ARCHIVES . '" />' . "\n"; // END Full month/year archives overview echo '<link rel="canonical" href="' . $this->getArchiveParameters() . '" />' . "\n"; } elseif (!empty($serendipity['GET']['category'])) { // Category based view $cInfo = serendipity_fetchCategoryInfo($serendipity['GET']['category']); if (function_exists('serendipity_categoryURL')) { $categories_url = serendipity_categoryURL($cInfo, 'serendipityHTTPPath'); } else { $categories_url = serendipity_rewriteURL(PATH_CATEGORIES . '/' . serendipity_makePermalink(PERM_CATEGORIES, array('id' => $cInfo['categoryid'], 'title' => $cInfo['category_name'])), 'serendipityHTTPPath'); } echo '<link rel="up" href="' . $categories_url . '" title="' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($cInfo['category_name']) : htmlspecialchars($cInfo['category_name'], ENT_COMPAT, LANG_CHARSET)) . '" />' . "\n"; echo '<link rel="canonical" href="' . $categories_url . '" />' . "\n"; $categories = serendipity_fetchCategories('all'); $links = array(); if (is_array($categories) && count($categories)) { $categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED); $capture_next = false; foreach ($categories as $cat) { if ($capture_next) { $links['next'] = $this->getCat($cat); break; } if (is_array($prev_cat) && $cat['categoryid'] == $serendipity['GET']['category']) { $links['prev'] = $this->getCat($prev_cat); $capture_next = true; } $prev_cat = $cat; } } $this->backAndForth($links); // END Category based view } elseif (!empty($serendipity['GET']['viewAuthor'])) { // User view $uInfo = serendipity_fetchUsers(); $links = array(); if (is_array($uInfo)) { $capture_next = false; foreach ($uInfo as $user) { if ($capture_next) { $links['next'] = $this->getUser($user); break; } if ($user['authorid'] == $serendipity['GET']['viewAuthor']) { $authors_url = $this->getUser($user); echo '<link rel="up" href="' . $authors_url['link'] . '" title="' . $authors_url['title'] . '" />' . "\n"; echo '<link rel="canonical" href="' . $authors_url['link'] . '" />' . "\n"; if (is_array($prev_user)) { $links['prev'] = $this->getUser($prev_user); $capture_next = true; } } $prev_user = $user; } $this->backAndForth($links); } // END User view } else { // Frontpage $this->backAndForth(); // END Frontpage if ($serendipity['view'] == 'start') { echo '<link rel="canonical" href="' . $serendipity['baseURL'] . '" />' . "\n"; } } } }
function generate_content(&$title) { global $serendipity; $title = $this->get_config('title', $this->title); $current_cat = $serendipity['GET']['category']; $current_page = $serendipity['GET']['page']; $current_auth = $serendipity['GET']['viewAuthor']; $current_rng = $serendipity['range']; $serendipity['GET']['page'] = 0; unset($serendipity['GET']['viewAuthor']); unset($serendipity['range']); $c = $this->get_config('category'); if ($c > 0) { $serendipity['GET']['category'] = (int) $c; } $showtitle = serendipity_db_bool($this->get_config('showtitle')); $showext = serendipity_db_bool($this->get_config('showext')); if (serendipity_db_bool($this->get_config('skip'))) { $limit = serendipity_db_limit($serendipity['fetchLimit'], $this->get_config('number')); } else { $limit = serendipity_db_limit(0, $this->get_config('number')); } $entries = serendipity_fetchEntries(null, true, $limit, false, false, 'timestamp DESC', '', false, true); if (is_array($entries)) { foreach ($entries as $i => $entry) { serendipity_plugin_api::hook_event('frontend_display', $entry); /* Pulled from serendipity_printEntries */ $entry['link'] = serendipity_archiveURL($entry['id'], $entry['title'], 'serendipityHTTPPath', true, array('timestamp' => $entry['timestamp'])); $entry['commURL'] = serendipity_archiveURL($entry['id'], $entry['title'], 'baseURL', false, array('timestamp' => $entry['timestamp'])); $entry['rdf_ident'] = serendipity_archiveURL($entry['id'], $entry['title'], 'baseURL', true, array('timestamp' => $entry['timestamp'])); $entry['title'] = function_exists('serendipity_specialchars') ? serendipity_specialchars($entry['title']) : htmlspecialchars($entry['title'], ENT_COMPAT, LANG_CHARSET); $entry['link_allow_comments'] = $serendipity['baseURL'] . 'comment.php?serendipity[switch]=enable&serendipity[entry]=' . $entry['id']; $entry['link_deny_comments'] = $serendipity['baseURL'] . 'comment.php?serendipity[switch]=disable&serendipity[entry]=' . $entry['id']; $entry['allow_comments'] = serendipity_db_bool($entry['allow_comments']); $entry['moderate_comments'] = serendipity_db_bool($entry['moderate_comments']); $entry['link_popup_comments'] = $serendipity['serendipityHTTPPath'] . 'comment.php?serendipity[entry_id]=' . $entry['id'] . '&serendipity[type]=comments'; $entry['link_popup_trackbacks'] = $serendipity['serendipityHTTPPath'] . 'comment.php?serendipity[entry_id]=' . $entry['id'] . '&serendipity[type]=trackbacks'; $entry['link_edit'] = $serendipity['baseURL'] . 'serendipity_admin.php?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=edit&serendipity[id]=' . $entry['id']; $entry['link_trackback'] = $serendipity['baseURL'] . 'comment.php?type=trackback&entry_id=' . $entry['id']; $entry['link_rdf'] = serendipity_rewriteURL(PATH_FEEDS . '/ei_' . $entry['id'] . '.rdf'); $entry['link_viewmode_threaded'] = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?url=' . $entry['commURL'] . '&serendipity[cview]=' . VIEWMODE_THREADED; $entry['link_viewmode_linear'] = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?url=' . $entry['commURL'] . '&serendipity[cview]=' . VIEWMODE_LINEAR; if ($_SESSION['serendipityAuthedUser'] === true && ($_SESSION['serendipityAuthorid'] == $entry['authorid'] || serendipity_checkPermission('adminEntriesMaintainOthers'))) { $entry['is_entry_owner'] = true; } if (is_array($entry['categories'])) { foreach ($entry['categories'] as $k => $v) { $entry['categories'][$k]['category_link'] = serendipity_categoryURL($entry['categories'][$k]); } } $entries[$i] = $entry; } } $serendipity['smarty']->assign(array('showtitle' => $showtitle, 'showext' => $showext, 'entries' => $entries)); $tfile = serendipity_getTemplateFile('plugin_showentries.tpl', 'serendipityPath'); if (!$tfile) { $tfile = dirname(__FILE__) . '/plugin_showentries.tpl'; } $inclusion = $serendipity['smarty']->security_settings[INCLUDE_ANY]; $serendipity['smarty']->security_settings[INCLUDE_ANY] = true; $content = $serendipity['smarty']->fetch('file:' . $tfile); $serendipity['smarty']->security_settings[INCLUDE_ANY] = $inclusion; echo $content; $serendipity['GET']['category'] = $current_cat; $serendipity['GET']['page'] = $current_page; $serendipity['GET']['viewAuthor'] = $current_auth; $serendipity['range'] = $current_rng; }