/** * Implements module_widget */ function login_widget($type) { global $ssc_user; if ($_GET['q'] == 'user/login') { return; } if ($ssc_user->gid == SSC_USER_GUEST) { // Do we show the login box? if (!ssc_var_get('login_show_login', true)) { return; } $menu[] = array('t' => t('Forgotten password'), 'p' => '/user/forgot', 'h' => t('Reset the password on an account')); if (ssc_var_get('login_user_create', true)) { $menu[] = array('t' => t('Create new account'), 'p' => '/user/register'); } $links = nav_widget($menu); return array('title' => t('User login'), 'body' => ssc_generate_form('login_form') . $links['body']); } else { $menu = array(); $menu[] = array('t' => t('Edit profile'), 'p' => '/user/profile'); $menu[] = array('t' => t('Log out'), 'p' => '/user/logout'); $links = nav_widget($menu); return array('title' => 'Profile', 'body' => t('Welcome, !name', array('!name' => $ssc_user->fullname)) . $links['body']); } }
/** * Implementation of module_widget() * @param mixed $block Will contain either an integer based on which database "block" * to display or an array structure indicating a navigation tree * @return string Marked up nav block */ function nav_widget($block, $title = '') { $out = "<ul>\n"; if (is_array($block)) { // Array version - this is gonna need recursion foreach ($block as $link) { $out .= " <li>\n " . l($link['t'], $link['p'], !empty($link['h']) ? array('attributes' => array('title' => $link['h'])) : array()) . "</li>\n"; if (!empty($link['c'])) { $out .= " <li>" . nav_widget($link['c']) . "</li>\n"; } } } else { // Grab data from DB global $ssc_database; $result = $ssc_database->query("SELECT node.id, node.url, node.description, node.title, (COUNT(node.id) - 1) AS depth\n\t\t\t\tFROM #__navigation AS node,\n\t\t\t\t#__navigation AS parent\n\t\t\t\tWHERE node.l BETWEEN parent.l AND parent.r AND node.bid = %d AND parent.bid = %d\n\t\t\t\tGROUP BY node.id\n\t\t\t\tORDER BY node.l", $block, $block); echo $ssc_database->error(); if (!$ssc_database->number_rows()) { return; } // Get path to current $path = $ssc_database->query("SELECT parent.id FROM #__navigation AS node,\n\t\t\t\t#__navigation AS parent\n\t\t\t\tWHERE node.l BETWEEN parent.l AND parent.r\n\t\t\t\tAND node.url = '/%s' AND parent.bid = %d AND node.bid = %d\n\t\t\t\tORDER BY parent.l", $_GET['q'], $block, $block); $tree = array(); while ($data = $ssc_database->fetch_object($path)) { $tree[] = $data->id; } $out .= '<li>'; $prev_depth = 0; $i = 0; // Parent listings $parent = array(0, 0); $p =& $parent[1]; // Loop through while ($data = $ssc_database->fetch_object($result)) { // Prepare tooltip if (!empty($data->desc)) { $op = array('attributes' => array('title' => $data->description)); } else { $op = array(); } // Are we a child of previous? if ($data->depth > $prev_depth) { // New level // Do we accept new level? Yes if root node or if parent in path if ($p == 0 || array_search($p, $tree) !== false) { // Level accepted $prev_depth++; $out .= " <ul>\n <li>"; array_unshift($parent, $data->id); } else { // Not accepted so ignore it do { $data = $ssc_database->fetch_object($result); } while ($data && $data->depth > $prev_depth); // Check if there is another link if ($data) { // Yes - prepare to show it $out .= "</li>\n<li>"; } else { // No - cut and run break; } } } elseif ($data->depth < $prev_depth) { // We're dropping levels instead $out .= '</li>'; do { $prev_depth--; $out .= "</ul></li>\n"; array_shift($parent); } while ($prev_depth > $data->depth); $out .= "<li>"; } else { // Same level so repeat level if ($i) { $out .= "</li>\n<li>"; } else { $i++; } } $out .= l($data->title, $data->url, $op); } // We finish with more levels to close? while ($data && $prev_depth > $data->depth) { $prev_depth--; $out .= " </li></ul>\n"; } $out .= '</li>'; } $out .= '</ul>'; return array('body' => $out, 'title' => $title); }
function blog_widget($args) { global $ssc_database; // Only show widgets on the blog module if ($_GET['handler'] != 'blog') { return; } // Return details $block = array(); // 1 - Tag listing if ($args == 1) { $result = $ssc_database->query("SELECT tag, COUNT(post_id) AS cnt FROM #__blog_post p, #__blog_tag t LEFT JOIN \n\t\t\t#__blog_relation r ON tag_id = t.id WHERE post_id = p.id AND p.is_draft = 0 AND blog_id = %d GROUP BY t.id ORDER BY tag ASC", $_GET['path-id']); if ($result && $ssc_database->number_rows() > 0) { while ($data = $ssc_database->fetch_assoc($result)) { $block[] = array('t' => $data['tag'] . " ({$data['cnt']})", 'p' => $_GET['path'] . '/tag/' . $data['tag']); } return nav_widget($block, 'Tags'); } } elseif ($args == 2) { $result = $ssc_database->query("SELECT YEAR( FROM_UNIXTIME(created) ) AS yr, COUNT( FROM_UNIXTIME(created) )\n\t\t\t AS cnt FROM #__blog_post p WHERE blog_id = %d AND p.is_draft = 0 GROUP BY YEAR( FROM_UNIXTIME(created) ) ORDER BY yr DESC", $_GET['path-id']); if ($result && $ssc_database->number_rows() > 0) { while ($data = $ssc_database->fetch_assoc($result)) { $block[] = array('t' => $data['yr'] . " ({$data['cnt']})", 'p' => $_GET['path'] . '/' . $data['yr']); } return nav_widget($block, 'Archive'); } } elseif ($args == 3) { if (!login_check_auth("blog")) { return; } $result = $ssc_database->query("SELECT p.title, p.urltext, COUNT(c.post_id) cnt, p.created FROM #__blog_post p\n\t\t\t\t\t\tLEFT JOIN #__blog_comment c ON (post_id = p.id AND (c.status & %d = 0)) WHERE blog_id = %d AND p.is_draft = 0\n\t\t\t\t\t\tGROUP BY p.id HAVING cnt > 0 ORDER BY p.created DESC", SSC_BLOG_COMMENT_READ, $_GET['path-id']); // AND p.author_id = %d if ($result && $ssc_database->number_rows() > 0) { while ($data = $ssc_database->fetch_assoc($result)) { $block[] = array('t' => $data['title'] . " ({$data['cnt']})", 'p' => $_GET['path'] . date("/Y/m/d/", $data['created']) . $data['urltext'] . '/mark'); } return nav_widget($block, 'Unread comments'); } } elseif ($args == 4) { return array('title' => 'Spam Count', 'body' => '<ul><li> ' . ssc_var_get('akismet_count', 0) . ' spam comments</li></ul>'); } }