/** * Fetches and prints a listing of comments by author */ function serendipity_printCommentsByAuthor() { global $serendipity; $type = serendipity_db_escape_string($serendipity['GET']['commentMode']); if ($type == 'comments' || empty($type)) { $type = 'NORMAL'; } elseif ($type == 'trackbacks') { $type = 'TRACKBACK'; } elseif ($type == 'comments_and_trackbacks') { $type = '%'; } if (!empty($serendipity['GET']['viewCommentAuthor'])) { $sql_where = " AND co.author = '" . serendipity_db_escape_string($serendipity['GET']['viewCommentAuthor']) . "'"; $group_by = "GROUP BY co.author"; } else { $sql_where = " AND 1"; // Required fake 'where' condition $group_by = ""; } if (!empty($serendipity['GET']['commentStartTime'])) { $sql_where .= " AND co.timestamp >= " . (int) $serendipity['GET']['commentStartTime']; } if (!empty($serendipity['GET']['commentEndTime'])) { $sql_where .= " AND co.timestamp <= " . (int) $serendipity['GET']['commentEndTime']; } if (empty($serendipity['GET']['page'])) { $serendipity['GET']['page'] = 1; } $sql_limit = $serendipity['fetchLimit'] * ($serendipity['GET']['page'] - 1) . ',' . $serendipity['fetchLimit']; $c = serendipity_fetchComments(null, $sql_limit, 'co.entry_id DESC, co.id ASC', false, $type, $sql_where); $entry_comments = array(); foreach ($c as $i => $comment) { if (!isset($entry_comments[$comment['entry_id']])) { $comment['link'] = serendipity_archiveURL($comment['entry_id'], $comment['title'], 'serendipityHTTPPath', true, array('timestamp' => $comment['entrytimestamp'])); $entry_comments[$comment['entry_id']] = $comment; } $entry_comments[$comment['entry_id']]['comments'][] = $comment; } foreach ($entry_comments as $entry_id => $_data) { $entry_comments[$entry_id]['tpl_comments'] =& serendipity_printComments($_data['comments'], VIEWMODE_LINEAR, 0, null, 'COMMENTS', 'comments.tpl'); } $serendipity['smarty']->assign_by_ref('comments_by_authors', $entry_comments); if (!empty($id)) { $and .= " AND co.entry_id = '" . (int) $id . "'"; } if (!$showAll) { $and .= ' AND co.status = \'approved\''; } $fc = "SELECT count(co.id) AS counter\n FROM {$serendipity['dbPrefix']}comments AS co\n WHERE co.entry_id > 0\n AND co.type LIKE '" . $type . "'\n AND co.status = 'approved' " . $sql_where . " " . $group_by; $cc = serendipity_db_query($fc, true, 'assoc'); if (!isset($cc['counter'])) { $totalComments = 0; } else { $totalComments = $cc['counter']; } serendipity_printEntryFooter('', $totalComments); serendipity_smarty_fetch('ENTRIES', 'comments_by_author.tpl'); return true; }
/** * Get a list of Sidebar plugins and pass them to Smarty * * @access public * @param string The side of plugins to show (left/right/hide/event/eventh) * @param string deprecated: Indicated which wrapping HTML element to use for plugins * @param boolean Indicates whether only all plugins should be shown that are not in the $side list * @param string Only show plugins of this plugin class * @param string Only show a plugin with this instance ID * @return string Smarty HTML output */ function generate_plugins($side, $tag = '', $negate = false, $class = null, $id = null, $tpl = 'sidebar.tpl') { global $serendipity; /* $tag parameter is deprecated and used in Smarty templates instead. Only use it in function * header for layout.php BC. */ $plugins = serendipity_plugin_api::enum_plugins($side, $negate, $class, $id); if (!is_array($plugins)) { return; } if (!isset($serendipity['smarty'])) { $serendipity['smarty_raw_mode'] = true; serendipity_smarty_init(); } $pluginData = array(); $addData = func_get_args(); serendipity_plugin_api::hook_event('frontend_generate_plugins', $plugins, $addData); if (count($plugins) == 0) { $serendipity['prevent_sidebar_plugins_' . $side] = true; } $loggedin = false; if (serendipity_userLoggedIn() && serendipity_checkPermission('adminPlugins')) { $loggedin = true; } foreach ($plugins as $plugin_data) { $plugin =& serendipity_plugin_api::load_plugin($plugin_data['name'], $plugin_data['authorid'], $plugin_data['path']); if (is_object($plugin)) { $class = get_class($plugin); $title = ''; /* TODO: make generate_content NOT echo its output */ ob_start(); $show_plugin = $plugin->generate_content($title); $content = ob_get_contents(); ob_end_clean(); if ($loggedin) { $content .= '<div class="serendipity_edit_nugget"><a href="' . $serendipity['serendipityHTTPPath'] . 'serendipity_admin.php?serendipity[adminModule]=plugins&serendipity[plugin_to_conf]=' . htmlentities($plugin->instance) . '">' . EDIT . '</a></div>'; } if ($show_plugin !== false) { $pluginData[] = array('side' => $side, 'class' => $class, 'title' => $title, 'content' => $content, 'id' => $plugin->instance); } } else { $pluginData[] = array('side' => $side, 'title' => ERROR, 'class' => $class, 'content' => sprintf(INCLUDE_ERROR, $plugin_data['name'])); } } serendipity_plugin_api::hook_event('frontend_sidebar_plugins', $pluginData, $addData); $serendipity['smarty']->assign_by_ref('plugindata', $pluginData); $serendipity['smarty']->assign('pluginside', ucfirst($side)); return serendipity_smarty_fetch('sidebar_' . $side, $tpl, true); }
/** * Prints a media item * * @param array Array of image metadata * @param string URL for maintenance tasks * @param boolean Whether to show maintenance task items * @param int how many media items to display per row * @param boolean Enclose within a table cell? * @param array Additional Smarty variables * @param boolean If TRUE, will echo Smarty output. * @return string Smarty block name * */ function serendipity_showMedia(&$file, &$paths, $url = '', $manage = false, $lineBreak = 3, $enclose = true, $smarty_vars = array(), $smarty_display = true) { global $serendipity; $form_hidden = ''; foreach ($serendipity['GET'] as $g_key => $g_val) { if (!is_array($g_val) && $g_key != 'page') { $form_hidden .= '<input type="hidden" name="serendipity[' . $g_key . ']" value="' . htmlspecialchars($g_val) . '" />'; } } serendipity_smarty_init(); $media = array('manage' => $manage, 'lineBreak' => $lineBreak, 'lineBreakP' => round(1 / $lineBreak * 100), 'url' => $url, 'enclose' => $enclose, 'zoomIMG' => serendipity_getTemplateFile('admin/img/big_zoom.png'), 'renameIMG' => serendipity_getTemplateFile('admin/img/big_rename.png'), 'resizeIMG' => serendipity_getTemplateFile('admin/img/big_resize.png'), 'rotatecwIMG' => serendipity_getTemplateFile('admin/img/big_rotate_cw.png'), 'rotateccwIMG' => serendipity_getTemplateFile('admin/img/big_rotate_ccw.png'), 'configureIMG' => serendipity_getTemplateFile('admin/img/configure.png'), 'deleteIMG' => serendipity_getTemplateFile('admin/img/big_delete.png'), 'prevIMG' => serendipity_getTemplateFile('admin/img/previous.png'), 'nextIMG' => serendipity_getTemplateFile('admin/img/next.png'), 'token' => serendipity_setFormToken(), 'form_hidden' => $form_hidden, 'blimit_path' => basename($limit_path), 'only_path' => $serendipity['GET']['only_path'], 'only_filename' => $serendipity['GET']['only_filename'], 'sortorder' => $serendipity['GET']['sortorder'], 'keywords_selected' => $serendipity['GET']['keywords'], 'filter' => $serendipity['GET']['filter'], 'sort_order' => serendipity_getImageFields(), 'authors' => serendipity_fetchUsers(), 'sort_row_interval' => array(8, 16, 50, 100), 'nr_files' => count($file), 'keywords' => explode(';', $serendipity['mediaKeywords'])); $media = array_merge($media, $smarty_vars); $media['files'] =& $file; if (count($paths) > 0) { $media['paths'] =& $paths; } else { $media['paths'] =& serendipity_getMediaPaths(); } $serendipity['smarty']->assign_by_ref('media', $media); if ($enclose) { serendipity_smarty_fetch('MEDIA_ITEMS', 'admin/media_items.tpl'); $block = 'admin/media_pane.tpl'; if ($smarty_display) { $serendipity['smarty']->display(serendipity_getTemplateFile('admin/media_pane.tpl', 'serendipityPath')); } } else { serendipity_smarty_fetch('MEDIA_ITEMS', 'admin/media_items.tpl'); $block = 'admin/media_properties.tpl'; if ($smarty_display) { $serendipity['smarty']->display(serendipity_getTemplateFile('admin/media_properties.tpl', 'serendipityPath')); } } return $block; }
function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks =& $bag->get('event_hooks'); if (isset($hooks[$event])) { switch ($event) { case 'backend_category_showForm': $pages = $this->fetchStaticPages(true); $categorypage = $this->fetchCatProp((int) $eventData); if (debug_staticpage == 'true') { echo "category "; echo (int) $eventData . " "; echo " staticpage "; echo $this->fetchCatProp((int) $eventData); } ?> <tr> <td valign="top"><label for="staticpage_categorypage"><?php echo STATICPAGE_CATEGORYPAGE; ?> </label></td> <td> <select name="serendipity[cat][staticpage_categorypage]"> <option value=""><?php echo NONE; ?> </option> <?php $pages = $this->fetchStaticPages(); if (is_array($pages)) { $pages = serendipity_walkRecursive($pages); foreach ($pages as $page) { if ($this->checkPageUser($page['authorid'])) { echo ' <option value="' . $page['id'] . '" ' . ($page['id'] == $this->fetchCatProp((int) $eventData) ? 'selected="selected"' : '') . '>'; echo str_repeat(' ', $page['depth']) . (function_exists('serendipity_specialchars') ? serendipity_specialchars($page['pagetitle']) : htmlspecialchars($page['pagetitle'], ENT_COMPAT, LANG_CHARSET)) . '</option>'; } } } ?> </select> </td> </tr> <?php return true; break; case 'backend_category_delete': $this->setCatProps($eventData, null, true); /* ** problem: different to backend_category_update and backend_category_addNew, here $eventData did not contain the id of the category, so ** the entry in the table _staticpage_categorypage is not deleted :-( Every time I get "35 AND 36" in the debug-modus. ** GARVIN: Yes, the ID contains a SQL statement for Category ID because the category children are contained as well! */ break; case 'backend_category_update': case 'backend_category_addNew': $val = array('categoryid ' => (int) $eventData, 'staticpage_categorypage' => $serendipity['POST']['cat']['staticpage_categorypage']); $this->setCatProps($eventData, $val); break; case 'frontend_fetchentries': case 'frontend_rss': $this->smarty_init(); break; case 'genpage': $this->setupDB(); $args = implode('/', serendipity_getUriArguments($eventData, true)); if ($serendipity['rewrite'] != 'none') { $nice_url = $serendipity['serendipityHTTPPath'] . $args; } else { $nice_url = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?/' . $args; } // Manko10 patch: http://board.s9y.org/viewtopic.php?f=3&t=17910&p=10426432#p10426432 // Check if static page exists or if this is an error 404 // // NOTE: as soon as you set a static page to be a 404 handler // from within the backend, you need to add a specific redirect rule // to your .htaccess for each static page generated by other // plugins such as serendipity_event_contactform // This behavior might change in future releases. $this->error_404 = $_SERVER['REDIRECT_STATUS'] == '404'; $pages = $this->fetchStaticPages(true, $nice_url); if (is_array($pages)) { foreach ($pages as $page) { if ($page['permalink'] == $nice_url) { $this->error_404 = FALSE; if ($pages['is_404_page']) { $this->error_404 = TRUE; } break; } } } // Set static page to 404 error document if page not found if ($this->error_404) { $serendipity['GET']['subpage'] = $this->get404Errorpage(); } // Set static page with is_startpage flag set as startpage if ((empty($args) || preg_match('@' . $serendipity['indexFile'] . '\\??$@', trim($args))) && empty($serendipity['GET']['subpage'])) { $serendipity['GET']['subpage'] = $this->getStartpage(); } // Set static page according to requested URL if (empty($serendipity['GET']['subpage'])) { $serendipity['GET']['subpage'] = $nice_url; } if ($this->selected()) { $te = $this->get_static('title_element'); if (!empty($te)) { $serendipity['head_title'] = function_exists('serendipity_specialchars') ? serendipity_specialchars($te) : htmlspecialchars($te, ENT_COMPAT, LANG_CHARSET); $serendipity['head_subtitle'] = ''; } else { $serendipity['head_title'] = $this->get_static('headline'); $serendipity['head_subtitle'] = $serendipity['blogTitle']; } } break; case 'frontend_header': $md = function_exists('serendipity_specialchars') ? serendipity_specialchars($this->get_static('meta_description')) : htmlspecialchars($this->get_static('meta_description'), ENT_COMPAT, LANG_CHARSET); $mk = function_exists('serendipity_specialchars') ? serendipity_specialchars($this->get_static('meta_keywords')) : htmlspecialchars($this->get_static('meta_keywords'), ENT_COMPAT, LANG_CHARSET); if (!empty($md)) { echo ' <meta name="description" content="' . $md . '" />' . "\n"; } if (!empty($mk)) { echo ' <meta name="keywords" content="' . $mk . '" />' . "\n"; } break; case 'frontend_fetchentries': if ($serendipity['GET']['action'] == 'search') { serendipity_smarty_fetch('ENTRIES', 'entries.tpl', true); } break; case 'entry_display': $this->smarty_init(); if ($this->selected()) { if (is_array($eventData)) { $eventData['clean_page'] = true; // This is important to not display an entry list! } else { $eventData = array('clean_page' => true); } } break; case 'backend_sidebar_entries': $this->setupDB(); echo '<li class="serendipitySideBarMenuLink serendipitySideBarMenuEntryLinks"><a href="?serendipity[adminModule]=event_display&serendipity[adminAction]=staticpages">' . STATICPAGE_TITLE . '</a></li>'; break; case 'backend_sidebar_entries_event_display_staticpages': $this->showBackend(); break; case 'backend_media_rename': // Only MySQL supported, since I don't know how to use REGEXPs differently. if ($serendipity['dbType'] != 'mysql' && $serendipity['dbType'] != 'mysqli') { echo STATICPAGE_MEDIA_DIRECTORY_MOVE_ENTRY . '<br />'; break; } if (!isset($eventData[0]['oldDir'])) { return true; } if ($eventData[0]['type'] == 'dir') { } elseif ($eventData[0]['type'] == 'filedir') { $eventData[0]['oldDir'] .= $eventData[0]['name']; $eventData[0]['newDir'] .= $eventData[0]['name']; } $q = "SELECT id, content, pre_content\n FROM {$serendipity['dbPrefix']}staticpages\n WHERE content REGEXP '(src=|href=|window.open.)(\\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . "|" . serendipity_db_escape_string($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ")'\n OR pre_content REGEXP '(src=|href=|window.open.)(\\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . "|" . serendipity_db_escape_string($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ")'\n "; $dirs = serendipity_db_query($q); if (is_array($dirs)) { foreach ($dirs as $dir) { $dir['content'] = preg_replace('@(src=|href=|window.open.)(\'|")(' . preg_quote($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . '|' . preg_quote($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ')@', '\\1\\2' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['newDir'], $dir['content']); $dir['pre_content'] = preg_replace('@(src=|href=|window.open.)(\'|")(' . preg_quote($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . '|' . preg_quote($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ')@', '\\1\\2' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['newDir'], $dir['pre_content']); $uq = "UPDATE {$serendipity['dbPrefix']}staticpages\n SET content = '" . serendipity_db_escape_string($dir['content']) . "' ,\n pre_content = '" . serendipity_db_escape_string($dir['pre_content']) . "'\n WHERE id = " . serendipity_db_escape_string($dir['id']); serendipity_db_query($uq); } printf(STATICPAGE_MEDIA_DIRECTORY_MOVE_ENTRIES . '<br />', count($dirs)); } break; case 'external_plugin': $parts = explode('_', $eventData); if (!empty($parts[1])) { $param = (int) $parts[1]; } else { $param = null; } if ($parts[0] == 'dtree.js') { header('Content-Type: text/javascript'); echo file_get_contents(dirname(__FILE__) . '/dtree.js'); } break; case 'entries_header': if (!$this->isplugin()) { $this->show(); } break; case 'entries_footer': if ($serendipity['GET']['action'] == 'search' && serendipity_db_bool($this->get_config('use_quicksearch'))) { $this->showSearch(); } break; case 'css_backend': if (!strpos($eventData, '#serendipityStaticpagesNav')) { // class exists in CSS, so a user has customized it and we don't need default echo file_get_contents(dirname(__FILE__) . '/style_staticpage_backend.css'); } break; default: return false; } return true; } return false; }
/** * Gather an archive listing of older entries and passes it to Smarty * * The archives are created according to the current timestamp and show the current year. * $serendipity['GET']['category'] is honoured like in serendipity_fetchEntries() * $serendipity['GET']['viewAuthor'] is honoured like in serendipity_fetchEntries() * * @access public * @return null */ function serendipity_printArchives() { global $serendipity; $f = serendipity_db_query("SELECT timestamp FROM {$serendipity['dbPrefix']}entries ORDER BY timestamp ASC LIMIT 1"); switch ($serendipity['calendar']) { case 'gregorian': default: $lastYear = date('Y', serendipity_serverOffsetHour($f[0][0])); $lastMonth = date('m', serendipity_serverOffsetHour($f[0][0])); $thisYear = date('Y', serendipity_serverOffsetHour()); $thisMonth = date('m', serendipity_serverOffsetHour()); break; case 'persian-utf8': require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php'; $lastYear = persian_date_utf('Y', serendipity_serverOffsetHour($f[0][0])); $lastMonth = persian_date_utf('m', serendipity_serverOffsetHour($f[0][0])); $thisYear = persian_date_utf('Y', serendipity_serverOffsetHour()); $thisMonth = persian_date_utf('m', serendipity_serverOffsetHour()); break; } $max = 1; if (isset($serendipity['GET']['category'])) { $cat_sql = serendipity_getMultiCategoriesSQL($serendipity['GET']['category']); $cat_get = '/C' . (int) $serendipity['GET']['category']; } else { $cat_sql = ''; $cat_get = ''; } if (isset($serendipity['GET']['viewAuthor'])) { $author_get = '/A' . (int) $serendipity['GET']['viewAuthor']; } else { $author_get = ''; } if ($serendipity['dbType'] == 'postgres' || $serendipity['dbType'] == 'pdo-postgres') { $distinct = 'DISTINCT e.id,'; } else { $distinct = ''; } $q = "SELECT {$distinct} e.timestamp\n FROM {$serendipity['dbPrefix']}entries e\n " . (!empty($cat_sql) ? "\n LEFT JOIN {$serendipity['dbPrefix']}entrycat ec\n ON e.id = ec.entryid\n LEFT JOIN {$serendipity['dbPrefix']}category c\n ON ec.categoryid = c.categoryid" : "") . "\n WHERE isdraft = 'false'" . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND timestamp <= " . serendipity_db_time() : '') . (!empty($cat_sql) ? ' AND ' . $cat_sql : '') . (!empty($serendipity['GET']['viewAuthor']) ? ' AND e.authorid = ' . (int) $serendipity['GET']['viewAuthor'] : '') . (!empty($cat_sql) ? " GROUP BY e.id, e.timestamp" : ''); $entries =& serendipity_db_query($q, false, 'assoc'); $group = array(); if (is_array($entries)) { foreach ($entries as $entry) { $group[date('Ym', $entry['timestamp'])]++; } } $output = array(); for ($y = $thisYear; $y >= $lastYear; $y--) { $output[$y]['year'] = $y; for ($m = 12; $m >= 1; $m--) { /* If the month we are checking are in the future, we drop it */ if ($m > $thisMonth && $y == $thisYear) { continue; } /* If the month is lower than the lowest month containing entries, we're done */ if ($m < $lastMonth && $y <= $lastYear) { break; } switch ($serendipity['calendar']) { case 'gregorian': default: $s = serendipity_serverOffsetHour(mktime(0, 0, 0, $m, 1, $y), true); $e = serendipity_serverOffsetHour(mktime(23, 59, 59, $m, date('t', $s), $y), true); break; case 'persian-utf8': require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php'; $s = serendipity_serverOffsetHour(persian_mktime(0, 0, 0, $m, 1, $y), true); $e = serendipity_serverOffsetHour(persian_mktime(23, 59, 59, $m, date('t', $s), $y), true); break; } $entry_count = (int) $group[$y . (strlen($m) == 1 ? '0' : '') . $m]; /* A silly hack to get the maximum amount of entries per month */ if ($entry_count > $max) { $max = $entry_count; } $data = array(); $data['entry_count'] = $entry_count; $data['link'] = serendipity_archiveDateUrl($y . '/' . sprintf('%02s', $m) . $cat_get . $author_get); $data['link_summary'] = serendipity_archiveDateUrl($y . '/' . sprintf('%02s', $m) . $cat_get . $author_get, true); $data['date'] = $s; $output[$y]['months'][] = $data; } } $serendipity['smarty']->assign_by_ref('archives', $output); $serendipity['smarty']->assign_by_ref('max_entries', $max); serendipity_smarty_fetch('ARCHIVES', 'entries_archives.tpl', true); }
function getHTML() { global $serendipity; $content_type = $this->get_config('content_type', 'categories'); if ($content_type == 'newsboxes') { // Wrap content from my contained newsboxes. $contents = array(); serendipity_plugin_api::hook_event('newsbox:get_content', $contents, array('id' => $this->instance)); $nb = serendipity_getTemplateFile('newsbox.tpl'); if ($nb && $nb != 'newsbox.tpl') { // The template should be able to handle this $serendipity['smarty']->assign('NEWSBOX', $contents); $newsbox_data = array(); $newsbox_data['title'] = $this->get_config('title', PLUGIN_EVENT_NEWSBOX_DEFAULT_TITLE); $newsbox_data['cats'] = ''; $newsbox_data['content_type'] = $content_type; $newsbox_data['isContainer'] = true; $newsbox_data['multicat_action'] = ''; $serendipity['smarty']->assign('newsbox_data', $newsbox_data); $this->html = serendipity_smarty_fetch('NEWSBOX', 'newsbox.tpl', false); } else { $this->html = "\n<div class=\"newsbox_container\"><h3 class=\"newsbox_title\">" . $this->get_config('title') . "</h3>\n"; foreach ($contents as $box) { $this->html .= $box . "\n"; } $this->html .= '<div style="clear:both;"><br /></div>' . "\n"; $this->html .= "\n</div><!--newsbox_container-->\n"; } } return $this->html; }
/** * Prints a media item * * @param array Array of image metadata * @param string URL for maintenance tasks * @param boolean Whether to show maintenance task items * @param int how many media items to display per row * @param boolean Enclose within a table cell? * @param array Additional Smarty variables * @return string Generated HTML * */ function serendipity_showMedia(&$file, &$paths, $url = '', $manage = false, $lineBreak = 3, $enclose = true, $smarty_vars = array()) { global $serendipity; $form_hidden = ''; // do not add, if not for the default media list form if (($serendipity['GET']['adminAction'] == 'default' || empty($serendipity['GET']['adminAction'])) && !$serendipity['GET']['fid']) { foreach ($serendipity['GET'] as $g_key => $g_val) { // do not add token, since this is assigned separately to properties and list forms if (!is_array($g_val) && $g_key != 'page' && $g_key != 'token') { $form_hidden .= ' <input type="hidden" name="serendipity[' . $g_key . ']" value="' . serendipity_specialchars($g_val) . '">' . "\n"; } } } if (!is_object($serendipity['smarty'])) { serendipity_smarty_init(); } $order_fields = serendipity_getImageFields(); // reset filename for building template filters, since this is hardcoded as 'only_filename' unset($order_fields['i.name']); $media = array('manage' => $manage, 'multiperm' => serendipity_checkPermission('adminImagesDirectories'), 'lineBreak' => $lineBreak, 'lineBreakP' => round(1 / $lineBreak * 100), 'url' => $url, 'enclose' => $enclose, 'token' => serendipity_setFormToken(), 'form_hidden' => $form_hidden, 'blimit_path' => empty($smarty_vars['limit_path']) ? '' : basename($smarty_vars['limit_path']), 'only_path' => $serendipity['GET']['only_path'], 'only_filename' => $serendipity['GET']['only_filename'], 'sortorder' => $serendipity['GET']['sortorder'], 'keywords_selected' => $serendipity['GET']['keywords'], 'filter' => $serendipity['GET']['filter'], 'sort_order' => $order_fields, 'simpleFilters' => $serendipity['simpleFilters'], 'hideSubdirFiles' => $serendipity['GET']['hideSubdirFiles'], 'authors' => serendipity_fetchUsers(), 'sort_row_interval' => array(8, 16, 50, 100), 'nr_files' => count($file), 'keywords' => explode(';', $serendipity['mediaKeywords']), 'thumbSize' => $serendipity['thumbSize'], 'sortParams' => array('perpage', 'order', 'ordermode')); $media = array_merge($media, $smarty_vars); $media['files'] =& $file; if (count($paths) > 0) { $media['paths'] =& $paths; } else { $media['paths'] =& serendipity_getMediaPaths(); } $serendipity['smarty']->assignByRef('media', $media); if ($enclose) { serendipity_smarty_fetch('MEDIA_ITEMS', 'admin/media_items.tpl'); return serendipity_smarty_show('admin/media_pane.tpl'); } else { serendipity_smarty_fetch('MEDIA_ITEMS', 'admin/media_items.tpl'); return serendipity_smarty_show('admin/media_properties.tpl'); } }
$media['css_imgedit'] = serendipity_getTemplateFile('admin/imgedit.css'); if (isset($serendipity['GET']['fid'])) { $file = serendipity_fetchImageFromDatabase($serendipity['GET']['fid']); if (!is_array($file) || !serendipity_checkPermission('adminImagesDelete') || !serendipity_checkPermission('adminImagesMaintainOthers') && $file['authorid'] != '0' && $file['authorid'] != $serendipity['authorid']) { return; } $fullfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $file['name'] . '.' . $file['extension']; $httpfile = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $file['path'] . $file['name'] . '.' . $file['extension']; $img = new imgedit($fullfile, $httpfile); // Set the filenames used for the cropping areas. Width/Height are automagically detected. Orientation is either horizontal or vertical. $img->setArea('imgedit_area.gif', 'h'); $img->setArea('imgedit_varea.gif', 'v'); // Let the IMGEditor do its magic. It will parse its results straightly into a template variable array. $img->main(); $serendipity['smarty']->assign('imgedit', $img->imgedit_smarty); serendipity_smarty_fetch('IMGEDIT', $img->output_template); } break; case 'sync': if (!serendipity_checkPermission('adminImagesSync')) { echo '<div class="warning"><em>' . PERM_DENIED . '</em></div>'; break; } // Make the form to actually do sync with deleting or not $n = "\n"; $warning = preg_replace('#\\\\n#', '<br />', WARNING_THIS_BLAHBLAH); echo '<div class="serendipityAdminMsgNote">' . $warning . '</div>'; echo ' <form method="POST" action="serendipity_admin.php?serendipity[adminModule]=media&serendipity[adminAction]=doSync">' . $n; echo ' <p>' . $n . ' <fieldset>' . $n; echo ' <legend>' . SYNC_OPTION_LEGEND . '</legend>' . $n; echo ' <input type="radio" name="serendipity[deleteThumbs]" value="no" checked="checked" id="keepthumbs" />' . $n;
/** * Shut down the Smarty Framework, output all parsed data * * This function is meant to be used in embedded installations, like in Gallery. * Function can be called from foreign applications. ob_start() needs to * have been called before, and will be parsed into Smarty here * * @access public * @param string The path to Serendipity * @return null */ function serendipity_smarty_shutdown($serendipity_directory = '') { global $serendipity; #$cwd = getcwd(); chdir($serendipity_directory); $raw_data = ob_get_contents(); ob_end_clean(); $serendipity['smarty']->assignByRef('content_message', $raw_data); serendipity_smarty_fetch('CONTENT', 'content.tpl'); $serendipity['smarty']->assign('ENTRIES', ''); if (empty($serendipity['smarty_file'])) { $serendipity['smarty_file'] = '404.tpl'; } $serendipity['smarty']->display(serendipity_getTemplateFile($serendipity['smarty_file'], 'serendipityPath')); }
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'); } }
break; // Show the archive // Show the archive case 'archives': $serendipity['head_subtitle'] = ARCHIVES; $serendipity['smarty']->assign('head_subtitle', $serendipity['head_subtitle']); serendipity_printArchives(); break; case 'custom': if ($serendipity['smarty_custom_vars']) { $serendipity['smarty']->assign($serendipity['smarty_custom_vars']); } break; case 'empty': break; // Welcome screen or whatever // Welcome screen or whatever default: if ($serendipity['use_internal_cache']) { $entries = serendipity_fetchEntries(null, true, $serendipity['fetchLimit']); if (!serendipity_printEntriesCached($entries)) { serendipity_printEntries($entries); } } else { serendipity_printEntries(serendipity_fetchEntries(null, true, $serendipity['fetchLimit'])); } break; } serendipity_smarty_fetch('CONTENT', 'content.tpl'); $serendipity['smarty']->assign('ENTRIES', ''); /* vim: set sts=4 ts=4 expandtab : */
if (!empty($serendipity['GET']['adminAction']) && $serendipity['GET']['adminModule'] == 'images' && $serendipity['GET']['adminAction'] != 'default') { // Might need to set $serendipity['adminFile_redirect'] here. $serendipity['adminFile'] = 'serendipity_admin_image_selector.php'; ob_start(); include S9Y_INCLUDE_PATH . 'include/admin/images.inc.php'; $media['external'] = ob_get_contents(); $media['case'] = 'external'; ob_end_clean(); break; } $media['case'] = 'default'; $add_url = ''; if (!empty($serendipity['GET']['htmltarget'])) { $add_url .= '&serendipity[htmltarget]=' . htmlspecialchars($serendipity['GET']['htmltarget']); } if (!empty($serendipity['GET']['filename_only'])) { $add_url .= '&serendipity[filename_only]=' . htmlspecialchars($serendipity['GET']['filename_only']); } if (!isset($serendipity['thumbPerPage2'])) { $serendipity['thumbPerPage2'] = 3; } ob_start(); $block = serendipity_displayImageList(isset($serendipity['GET']['page']) ? $serendipity['GET']['page'] : 1, $serendipity['thumbPerPage2'], $serendipity['showMediaToolbar'] ? true : false, '?serendipity[step]=1' . $add_url . '&serendipity[textarea]=' . $serendipity['GET']['textarea'], true, null, false); $media['external'] = ob_get_contents(); ob_end_clean(); serendipity_smarty_fetch('MEDIA_LIST', $block); } $media = array_merge($serendipity['GET'], $media); $serendipity['smarty']->assign_by_ref('media', $media); $serendipity['smarty']->display(serendipity_getTemplateFile($showFile, 'serendipityPath')); /* vim: set sts=4 ts=4 expandtab : */
function generate_content(&$title) { global $serendipity; $title = $this->title; // Usage of serendipity_serverOffsetHour is as follow: // * Whenever a date to display needs to be set, apply the timezone offset // * Whenever we USE the date anywhere in the database, subtract the timezone offset // * Whenever we DISPLAY the date, we do not apply additional timezone addition to it. if (!isset($serendipity['GET']['calendarZoom'])) { if (!isset($serendipity['range'])) { $serendipity['GET']['calendarZoom'] = serendipity_serverOffsetHour(time()); } else { $serendipity['GET']['calendarZoom'] = serendipity_serverOffsetHour($serendipity['range'][0]); } } $month = date('m', serendipity_serverOffsetHour($serendipity['GET']['calendarZoom'], true)); $year = date('Y', serendipity_serverOffsetHour($serendipity['GET']['calendarZoom'], true)); $bow = (int) $this->get_config('beginningOfWeek', 1); // Check for faulty input, is so - run the default if ($bow > 6) { $bow = 1; } // Catch faulty month $month = (int) $month; if ($month < 1) { $month = 1; } switch ($serendipity['calendar']) { default: case 'gregorian': // How many days does the month have? $ts = strtotime($year . '-' . sprintf('%02d', $month) . '-01'); $now = serendipity_serverOffsetHour(time()); $nrOfDays = date('t', $ts); $firstDayWeekDay = date('w', $ts); $firstts = $ts; $endts = mktime(0, 0, 0, $month + 1, 1, $year); break; case 'persian-utf8': require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php'; list(, $jy, $jm, $jd) = $serendipity['uriArguments']; if (isset($jd) && $jd) { list($gy, $gm, $gd) = p2g($jy, $jm, $jd); } elseif (isset($jm) && $jm) { list($gy, $gm, $gd) = p2g($jy, $jm, 1); } else { $gy = $year; $gm = $month; $gd = (int) date('d'); } list($year, $month, $day) = g2p($gy, $gm, $gd); // How many days does the month have? $ts = strtotime($gy . '-' . sprintf('%02d', $gm) . '-' . sprintf('%02d', $gd)); $now = serendipity_serverOffsetHour(time()); $nrOfDays = persian_strftime_utf('%m', $ts); $j_days_in_month = array(0, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29); if ($year % 4 == 3 && $nrOfDays == 12) { $nrOfDays = $j_days_in_month[(int) $nrOfDays] + 1; } else { $nrOfDays = $j_days_in_month[(int) $nrOfDays]; } // Calculate first timestamp of the month list($firstgy, $firstgm, $firstgd) = p2g($year, $month, 1); $firstts = mktime(0, 0, 0, $firstgm, $firstgd, $firstgy); // Calculate first persian day, week day name $firstDayWeekDay = date('w', $firstts); // Calculate end timestamp of the month list($end_year, $end_month, $end_day) = p2g($year, $month + 1, 1); $endts = mktime(0, 0, 0, $end_month, $end_day, $end_year); break; } // end switch // Calculate the first day of the week, based on the beginning of the week ($bow) if ($bow > $firstDayWeekDay) { $firstDayWeekDay = $firstDayWeekDay + 7 - $bow; } elseif ($bow < $firstDayWeekDay) { $firstDayWeekDay = $firstDayWeekDay - $bow; } else { $firstDayWeekDay = 0; } // Calculate the number of next/previous month if ($month > 1) { $previousMonth = $month - 1; $previousYear = $year; } else { $previousMonth = 12; $previousYear = $year - 1; } if ($month < 12) { $nextMonth = $month + 1; $nextYear = $year; } else { $nextMonth = 1; $nextYear = $year + 1; } // Get first and last entry $minmax = serendipity_db_query("SELECT MAX(timestamp) AS max, MIN(timestamp) AS min FROM {$serendipity['dbPrefix']}entries"); if (!is_array($minmax) || !is_array($minmax[0]) || $minmax[0]['min'] < 1 || $minmax[0]['max'] < 1) { // If no entry is available yet, allow scrolling a year back and forth $minmax = array('0' => array('min' => mktime(0, 0, 0, 1, 1, date('Y', $now) - 1), 'max' => mktime(0, 0, 0, 1, 1, date('Y', $now) + 1))); } // Find out about diary entries $add_query = ''; $base_query = ''; $cond = array(); $cond['and'] = "WHERE e.timestamp >= " . serendipity_serverOffsetHour($firstts, true) . "\n AND e.timestamp <= " . serendipity_serverOffsetHour($endts, true) . "\n " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp <= " . serendipity_db_time() : '') . "\n AND e.isdraft = 'false'"; serendipity_plugin_api::hook_event('frontend_fetchentries', $cond, array('noCache' => false, 'noSticky' => false, 'source' => 'calendar')); // Event Calendar $cat = $this->get_config('category', 'all'); if ($cat != 'all') { $catid = (int) $cat; } elseif (isset($serendipity['GET']['category'])) { $catid = (int) $serendipity['GET']['category']; } else { $catid = false; } if ($catid) { $base_query = 'C' . $catid; $add_query = '/' . $base_query; $querystring = "SELECT timestamp\n FROM {$serendipity['dbPrefix']}category c,\n {$serendipity['dbPrefix']}entrycat ec,\n {$serendipity['dbPrefix']}entries e\n {$cond['joins']}\n {$cond['and']}\n AND e.id = ec.entryid\n AND c.categoryid = ec.categoryid\n AND (" . serendipity_getMultiCategoriesSQL($catid) . ")"; } if (!isset($querystring)) { $querystring = "SELECT id, timestamp\n FROM {$serendipity['dbPrefix']}entries e\n {$cond['joins']}\n {$cond['and']}"; } $rows = serendipity_db_query($querystring); switch ($serendipity['calendar']) { default: case 'gregorian': $activeDays = array(); if (is_array($rows)) { foreach ($rows as $row) { $row['timestamp'] = serendipity_serverOffsetHour($row['timestamp']); $activeDays[date('j', $row['timestamp'])] = $row['timestamp']; } } $today_day = date('j', $now); $today_month = date('m', $now); $today_year = date('Y', $now); break; case 'persian-utf8': $activeDays = array(); if (is_array($rows)) { foreach ($rows as $row) { $row['timestamp'] = serendipity_serverOffsetHour($row['timestamp']); $activeDays[(int) persian_date_utf('j', $row['timestamp'])] = $row['timestamp']; } } $today_day = persian_date_utf('j', $now); $today_month = persian_date_utf('m', $now); $today_year = persian_date_utf('Y', $now); break; } // end switch $externalevents = array(); if (serendipity_db_bool($this->get_config('enableExtEvents', 'false'))) { serendipity_plugin_api::hook_event('frontend_calendar', $externalevents, array('Month' => $month, 'Year' => $year, 'TS' => $ts, 'EndTS' => $endts)); } // Print the calendar $currDay = 1; $nrOfRows = ceil(($nrOfDays + $firstDayWeekDay) / 7); for ($x = 0; $x < 6; $x++) { // Break out if we are out of days if ($currDay > $nrOfDays) { break; } // Prepare row for ($y = 0; $y < 7; $y++) { $cellProps = array(); $printDay = ''; $link = ''; if ($x == 0) { $cellProps['FirstRow'] = 1; } if ($y == 0) { $cellProps['FirstInRow'] = 1; } if ($y == 6) { $cellProps['LastInRow'] = 1; } if ($x == $nrOfRows - 1) { $cellProps['LastRow'] = 1; } // If it's not a blank day, we print the day if (($x > 0 || $y >= $firstDayWeekDay) && $currDay <= $nrOfDays) { $printDay = $currDay; if ($today_day == $currDay && $today_month == $month && $today_year == $year) { $cellProps['Today'] = 1; } if (isset($externalevents[$currDay])) { if (isset($externalevents[$currDay]['Class'])) { $cellProps[$externalevents[$currDay]['Class']] = 1; } if (isset($externalevents[$currDay]['Title'])) { $cellProps['Title'] = serendipity_specialchars($externalevents[$currDay]['Title']); } if (isset($externalevents[$currDay]['Extended'])) { foreach ($externalevents[$currDay]['Extended'] as $ext_key => $ext_val) { $cellProps[$ext_key] = $ext_val; } } } if (isset($activeDays[$currDay]) && $activeDays[$currDay] > 1) { $cellProps['Active'] = 1; $cellProps['Link'] = serendipity_archiveDateUrl(sprintf('%4d/%02d/%02d', $year, $month, $currDay) . $add_query); } $currDay++; } $smartyRows[$x]['days'][] = array('name' => $printDay, 'properties' => $cellProps, 'classes' => implode(' ', array_keys($cellProps))); } // end for } // end for $serendipity['smarty']->assignByRef('plugin_calendar_weeks', $smartyRows); $dow = array(); for ($i = 1; $i <= 7; $i++) { $dow[] = array('date' => mktime(0, 0, 0, 3, $bow + $i - 1, 2004)); } $serendipity['smarty']->assignByRef('plugin_calendar_dow', $dow); $plugin_calendar_data = array('month_date' => $ts, 'uri_previous' => serendipity_archiveDateUrl(sprintf('%04d/%02d', $previousYear, $previousMonth) . $add_query), 'uri_month' => serendipity_archiveDateUrl(sprintf('%04d/%02d', $year, $month) . $add_query), 'uri_next' => serendipity_archiveDateUrl(sprintf('%04d/%02d', $nextYear, $nextMonth) . $add_query), 'minScroll' => $minmax[0]['min'], 'maxScroll' => $minmax[0]['max']); $serendipity['smarty']->assignByRef('plugin_calendar_head', $plugin_calendar_data); echo serendipity_smarty_fetch('CALENDAR', 'plugin_calendar.tpl'); }
function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks =& $bag->get('event_hooks'); if (isset($hooks[$event])) { switch ($event) { case 'frontend_fetchentries': if ($serendipity['GET']['action'] == 'search') { serendipity_smarty_fetch('ENTRIES', 'entries.tpl', true); } break; case 'entries_footer': if ($serendipity['GET']['action'] == 'search') { $this->showSearch(); } break; default: return false; } return true; } return false; }