Created
March 29, 2012 20:42
-
-
Save evolvingweb/2243606 to your computer and use it in GitHub Desktop.
Recent Nodes Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implementation of hook_init(). | |
* | |
* Displays a diagnostic message to the user. | |
*/ | |
function ew_recent_nodes_init() { | |
$message = t("The Recent Nodes module is enabled!"); | |
drupal_set_message($message); | |
} | |
/** | |
* Implements hook_menu(). | |
*/ | |
function ew_recent_nodes_menu() { | |
$items = array(); | |
$items['recent-nodes'] = array( | |
'title' => 'Recently Added Nodes', | |
'page callback' => 'ew_recent_nodes_listing', | |
'type' => MENU_CALLBACK, //this is the default type | |
'access callback' => 'user_access', //this is the default access callback | |
'access arguments' => array('view recent nodes'), //by default all users have this permission | |
); | |
//dpm($items); | |
return $items; | |
} | |
/* | |
* Implements hook_permission(). | |
* | |
* Adds a permission to view recent nodes. | |
*/ | |
function ew_recent_nodes_permission() { | |
$perm = array( | |
'view recent nodes' => array( | |
'title' => 'View Recent Nodes', | |
), | |
); | |
return $perm; | |
} | |
/* | |
* Display a list of recent nodes. | |
* | |
*/ | |
function ew_recent_nodes_listing() { | |
$result = db_query("SELECT nid, type, title, uid, created FROM {node} ORDER BY created DESC LIMIT 10"); | |
foreach ($result as $node_data) { | |
//dpm($node_data); | |
$nodes[] = array($node_data->nid, check_plain($node_data->title), $node_data->uid, $node_data->created); | |
} | |
if (isset($nodes)) { | |
return array( | |
'#theme' => 'table', | |
'#header' => array('Owner NID', 'Title', 'Owner UID', 'Created'), | |
'#rows' => $nodes, | |
); | |
} else { | |
return ""; | |
} | |
} | |
/* | |
* Implements hook_block_info() | |
* Adds a custom block to display recent nodes | |
*/ | |
function ew_recent_nodes_block_info() { | |
$blocks['recent-nodes'] = array( | |
'info' => t('Recent Nodes'), | |
); | |
return $blocks; | |
} | |
function ew_recent_nodes_block_view($delta = '') { | |
$block = array(); | |
switch ($delta) { | |
case 'recent-nodes': | |
$block['subject'] = t('Recent Nodes'); | |
$block['content'] = ew_recent_nodes_list(); | |
break; | |
} | |
return $block; | |
} | |
function ew_recent_nodes_list() { | |
$result = db_query("SELECT nid, type, title, uid, created FROM {node} ORDER BY created DESC LIMIT 10"); | |
foreach ($result as $node_data) { | |
$nodes[] = array($node_data->title); | |
} | |
if (isset($nodes)) { | |
return array( | |
'#theme' => 'item_list', | |
'#items' => $nodes, | |
'#type' => 'ul', | |
); | |
} else { | |
return ""; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment