| 1 |
<?php
|
| 2 |
// $Id
|
| 3 |
|
| 4 |
// Copyright of Fabio Mucciante. See LICENSE for redistribution allowances.
|
| 5 |
/**
|
| 6 |
* Implementation of hook_help().
|
| 7 |
*
|
| 8 |
*/
|
| 9 |
function last_node_help($section) {
|
| 10 |
switch ($section) {
|
| 11 |
case 'admin/help#last_node':
|
| 12 |
$output = t('<p>This module displays the list of inserted lately items (sorted by time) for each node.<BR>Set your own nodes that you want to see at <a href="?q=admin/settings/last_node">settings page</a> and view this page with <a href="?q=last_node/">last_node/</a> address, you can specify a title and image for each item.</p>');
|
| 13 |
$output .= t('<p>This module provide:<ul> <li>Block <em>Last 10</em>: Show your last 10 items of all nodes; <li>Block <em>Navigate Last Node</em>: Show Block of all Type node allowed; <li>Menu Items for each node type; <li>API for display in your own page:');
|
| 14 |
$output .= t('<ol><li><em>lastnode_display($title,$node_type,$num_item)</em>: if you want show your last items for node specified at own page; <li><em>lastnode_imgdisplay($title,$node_type,$num_item)</em>: show also image for each node; <li><em>lastnode_css()</em>; include css of this module if you don\'t use other block.</ol> </ul></p>');
|
| 15 |
$output .= t('<h3>Example for API usage:</h3><p> <ul><li> Enable the page and story module at <a href="?q=admin/modules">administer » modules</a> page. <li>Select <a href="?q=node/add/page">create content » page</a>; <li>For input format, select PHP code; <li>Check frontpage option; <li>Give the page a title. For body, put: <pre><?php print lastnode_display(\'Last 10 Node of Story\',\'story\',10); ?></pre> <li>Save the page.</ul></p>');
|
| 16 |
return $output;
|
| 17 |
break;
|
| 18 |
case 'admin/modules#description':
|
| 19 |
return t('This module displays the list of inserted lately items (sorted by time) for each node and provide blocks and api for a fast access to these informations.');
|
| 20 |
break;
|
| 21 |
}
|
| 22 |
}
|
| 23 |
|
| 24 |
/**
|
| 25 |
* Implementation of hook_block().
|
| 26 |
*
|
| 27 |
*/
|
| 28 |
function last_node_block($op = 'list',$delta = 0) {
|
| 29 |
if ($op == 'list') {
|
| 30 |
$blocks[0]['info'] = t('Last 10 Nodes');
|
| 31 |
$blocks[1]['info'] = t('Navigate Last Node');
|
| 32 |
return $blocks;
|
| 33 |
}
|
| 34 |
else if ($op == 'view') {
|
| 35 |
switch ($delta) {
|
| 36 |
case 0:
|
| 37 |
$block['subject'] = t('Last 10:');
|
| 38 |
$block['content'] = _last_node_contents(1);
|
| 39 |
break;
|
| 40 |
case 1:
|
| 41 |
$block['subject'] = t('Last Node:');
|
| 42 |
$block['content'] = _last_node_contents(2);
|
| 43 |
break;
|
| 44 |
}
|
| 45 |
return $block;
|
| 46 |
}
|
| 47 |
}
|
| 48 |
|
| 49 |
/**
|
| 50 |
* A block content function.
|
| 51 |
*/
|
| 52 |
function _last_node_contents($which_block) {
|
| 53 |
if ($which_block == 1) {
|
| 54 |
$node = variable_get('last_node_check',array());
|
| 55 |
if (!empty($node)) {
|
| 56 |
$placeholders = implode(',', array_fill(0, count($node), "'%s'"));
|
| 57 |
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title FROM {node} n WHERE n.type in ($placeholders) AND n.status = 1 ORDER BY n.created DESC"), $node, 0, 10);
|
| 58 |
while ($node = db_fetch_object($result)) {
|
| 59 |
$output .= l($node->title,'node/'. $node->nid) ."<BR>-<BR>";
|
| 60 |
}
|
| 61 |
}
|
| 62 |
$output = '<marquee id="last_node-block" direction="up" scrollamount="1" scrolldelay="1" onMouseOver="this.stop()" onMouseOut="this.start()">'. $output .'</marquee>';
|
| 63 |
theme_add_style(drupal_get_path("module","last_node") ."/last_node.css");
|
| 64 |
return $output;
|
| 65 |
}
|
| 66 |
if ($which_block == 2) {
|
| 67 |
$output = '<div class="last_node-nodeblock"><div class="last_node-linknodetypeblock">';
|
| 68 |
$args['class'] = 'last_node-linknodetypeblock';
|
| 69 |
$node = variable_get('last_node_check',array());
|
| 70 |
if (!empty($node)) {
|
| 71 |
foreach ($node as $key => $value) {
|
| 72 |
$nodes["$value"] = variable_get('last_node_labelnode_'. $value, $value);
|
| 73 |
}
|
| 74 |
asort($nodes);
|
| 75 |
reset($nodes);
|
| 76 |
foreach ($nodes as $key => $value) {
|
| 77 |
$title = _last_node_normalize_linkblock($value, $key);
|
| 78 |
$output .= html_entity_decode(l($title,'last_node/'. $key, $args)) .'<BR>';
|
| 79 |
}
|
| 80 |
}
|
| 81 |
theme_add_style(drupal_get_path("module","last_node") ."/last_node.css");
|
| 82 |
return $output .'</div></div>';
|
| 83 |
}
|
| 84 |
}
|
| 85 |
|
| 86 |
function lastnode_css() {
|
| 87 |
return theme_stylesheet_import(drupal_get_path("module","last_node") ."/last_node.css");
|
| 88 |
}
|
| 89 |
|
| 90 |
function lastnode_display($title,$node_type,$numitem = 5) {
|
| 91 |
$lista = array();
|
| 92 |
|
| 93 |
$result = db_query_range("SELECT n.title, n.nid, n.created FROM {node} n WHERE n.status = 1 AND n.type = '%s' ORDER BY n.created DESC", $node_type, 0, $numitem);
|
| 94 |
|
| 95 |
while ($node = db_fetch_object($result)) {
|
| 96 |
$lista[] = l($node->title ." (". format_date($node->created,'small') .")",'node/'. $node->nid);
|
| 97 |
}
|
| 98 |
|
| 99 |
$output = theme('item_list',$lista);
|
| 100 |
$output = '<h2 class="page-title"><div class="last_node-linknodetype">'. html_entity_decode(l($title,'last_node/'. $node_type,$args)) .'</div></h2><BR>'. $output;
|
| 101 |
|
| 102 |
//---Feed RSS
|
| 103 |
$output .= theme('xml_icon',url('last_node/feed/'. $node_type));
|
| 104 |
drupal_add_link(array('rel' => 'alternate',
|
| 105 |
'type' => 'application/rss+xml',
|
| 106 |
'title' => html_entity_decode("RSS - $title"),
|
| 107 |
'href' => url("last_node/feed/$node_type")));
|
| 108 |
return $output;
|
| 109 |
}
|
| 110 |
|
| 111 |
function lastnode_imgdisplay($title,$node_type,$numitem = 5) {
|
| 112 |
return lastnode_display(_last_node_normalize_title($title,$node_type),$node_type,$numitem);
|
| 113 |
}
|
| 114 |
|
| 115 |
function _last_node_normalize_title($title,$node_type) {
|
| 116 |
$image = variable_get('last_node_imagenode_'. $node_type,'');
|
| 117 |
if ($image) {
|
| 118 |
$title = " ¤ <img class=\"last_node-imagenode\" src=$image> ". $title;
|
| 119 |
}
|
| 120 |
else $title = " ¤ ". $title;
|
| 121 |
return $title;
|
| 122 |
}
|
| 123 |
|
| 124 |
function _last_node_normalize_linkblock($title,$node_type) {
|
| 125 |
$image = variable_get('last_node_imagenode_'. $node_type,'');
|
| 126 |
if ($image) {
|
| 127 |
$title = "<img class=\"last_node-imagelinkblock\" src=$image> ". $title;
|
| 128 |
}
|
| 129 |
else $title = " ¤ ". $title;
|
| 130 |
return $title;
|
| 131 |
}
|
| 132 |
|
| 133 |
/*
|
| 134 |
** menu hook
|
| 135 |
*/
|
| 136 |
function last_node_menu($may_cache) {
|
| 137 |
$items = array();
|
| 138 |
|
| 139 |
if ($may_cache) {
|
| 140 |
$items[] = array('path' => 'last_node', 'title' => t('Last Node'),
|
| 141 |
'callback' => 'last_node_page',
|
| 142 |
'access' => user_access('access content'),
|
| 143 |
'type' => MENU_NORMAL_ITEM);
|
| 144 |
|
| 145 |
$node = variable_get('last_node_check', array());
|
| 146 |
if (!empty($node)) {
|
| 147 |
foreach ($node as $key => $value) {
|
| 148 |
$title = variable_get('last_node_labelnode_' .$value,$value);
|
| 149 |
$items[] = array('path' => 'last_node/'. $value, 'title' => $title,
|
| 150 |
'access' => user_access('access content'),
|
| 151 |
'type' => MENU_NORMAL_ITEM);
|
| 152 |
}
|
| 153 |
}
|
| 154 |
}
|
| 155 |
return $items;
|
| 156 |
}
|
| 157 |
|
| 158 |
function _last_node_validnode($type) {
|
| 159 |
$node = variable_get('last_node_check', array());
|
| 160 |
|
| 161 |
if (empty($node)) {
|
| 162 |
return FALSE;
|
| 163 |
}
|
| 164 |
if ($type) {
|
| 165 |
return in_array($type, array_values($node));
|
| 166 |
}
|
| 167 |
return TRUE;
|
| 168 |
}
|
| 169 |
|
| 170 |
function _last_node_feed($type) {
|
| 171 |
if (!_last_node_validnode($type)) {
|
| 172 |
drupal_not_found();
|
| 173 |
return;
|
| 174 |
}
|
| 175 |
$result = db_query_range("SELECT n.nid, n.title, n.created, u.name, u.uid FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = '%s' AND n.status = 1 ORDER BY n.created DESC", $type, 0, 10);
|
| 176 |
$channel['title'] = variable_get('site_name', 'drupal') ." ". variable_get('last_node_labelnode_'. $type, $type);
|
| 177 |
$channel['link'] = url('last_node/'. $type, NULL, NULL, TRUE);
|
| 178 |
$channel['description'] = variable_get('site_name', 'drupal') ." Sezione ". variable_get('last_node_labelnode_'. $type, $type);
|
| 179 |
$channel['language'] = 'it';
|
| 180 |
node_feed($result, $channel);
|
| 181 |
}
|
| 182 |
|
| 183 |
function last_node_page($type = NULL, $id = NULL) {
|
| 184 |
if ($type == 'feed') {
|
| 185 |
if ($id) {
|
| 186 |
_last_node_feed($id);
|
| 187 |
}
|
| 188 |
else drupal_not_found();
|
| 189 |
return;
|
| 190 |
}
|
| 191 |
else {
|
| 192 |
_last_node_page($type);
|
| 193 |
return;
|
| 194 |
}
|
| 195 |
}
|
| 196 |
|
| 197 |
function _last_node_page($type = NULL) {
|
| 198 |
if (!_last_node_validnode($type)) {
|
| 199 |
drupal_not_found();
|
| 200 |
return;
|
| 201 |
}
|
| 202 |
|
| 203 |
$output = theme_stylesheet_import(drupal_get_path("module","last_node") ."/last_node.css");
|
| 204 |
if (!$type) {
|
| 205 |
$node = variable_get('last_node_check', array());
|
| 206 |
if (!empty($node)) {
|
| 207 |
foreach ($node as $key => $value) {
|
| 208 |
$title = variable_get('last_node_labelnode_'. $value, $value);
|
| 209 |
$output .= lastnode_imgdisplay($title, $value);
|
| 210 |
}
|
| 211 |
}
|
| 212 |
print theme('page', $output);
|
| 213 |
return;
|
| 214 |
}
|
| 215 |
|
| 216 |
drupal_set_title(_last_node_normalize_title(drupal_get_title(), $type));
|
| 217 |
|
| 218 |
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = '%s' AND n.status = 1 ORDER BY n.created DESC"), variable_get('default_nodes_main', 10), 0, NULL, $type);
|
| 219 |
|
| 220 |
while ($node = db_fetch_object($result)) {
|
| 221 |
$output .= node_view(node_load(array('nid' => $node->nid)), 1);
|
| 222 |
}
|
| 223 |
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
|
| 224 |
print theme('page', $output);
|
| 225 |
}
|
| 226 |
|
| 227 |
/**
|
| 228 |
* Implementation of hook_settings()
|
| 229 |
*/
|
| 230 |
function last_node_settings() {
|
| 231 |
$node_types = drupal_map_assoc(node_list());
|
| 232 |
foreach ($node_types as $k => $v) {
|
| 233 |
$nodes[$k] = $v;
|
| 234 |
|
| 235 |
$form .= form_textfield(t('Label for ') . $nodes[$k],
|
| 236 |
'last_node_labelnode_'. $nodes[$k],
|
| 237 |
variable_get('last_node_labelnode_'. $nodes[$k],$nodes[$k]),
|
| 238 |
32, 128);
|
| 239 |
$form .= form_textfield(t('Image for ') . $nodes[$k] .' <em>(Relative path)</em>',
|
| 240 |
'last_node_imagenode_'. $nodes[$k],
|
| 241 |
variable_get('last_node_imagenode_'. $nodes[$k], ''),
|
| 242 |
32, 128);
|
| 243 |
}
|
| 244 |
|
| 245 |
$form .= form_checkboxes(t('Nodes including when you point at <em>last_node/</em> node'),
|
| 246 |
'last_node_check',variable_get('last_node_check', array()), $nodes, NULL, NULL, TRUE);
|
| 247 |
return $form;
|
| 248 |
}
|
| 249 |
|
| 250 |
?>
|