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); }
/** * 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 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'); } }
function add_feeds(&$sitemap_xml) { global $serendipity; // add the category-newsfeed URLs if ($this->should_add('sm_categories')) { foreach ($this->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_feedCategoryURL($data); } else { $url = serendipity_rewriteURL(PATH_FEEDS . '/' . PATH_CATEGORIES . '/' . serendipity_makePermalink(PERM_FEEDS_CATEGORIES, array('id' => $category['id'], 'title' => $category['category_name']))); } $this->addtoxml($sitemap_xml, $url, $max, 0.0); } } // add the global newsfeed URLs if ($this->should_add('sm_feeds')) { $filelist = array('/index.rss', '/index.rss1', '/index.rss2', '/atom.xml'); foreach ($filelist as $curfile) { $url = serendipity_rewriteURL(PATH_FEEDS . $curfile); $this->addtoxml($sitemap_xml, $url, $max, 0.0); } } }