array(
'name' => t('Site Note'),
'module' => 'sitenotes',
'description' => t('Create site notes for admin user(s).'),
)
);
}
/**
* Implementation of hook_perm().
*/
function sitenotes_perm() {
return array('access site notes');
}
/**
* Implementation of hook_access().
*/
function sitenotes_access($op, $node) {
global $user;
if ($op == 'create' || $op == 'update' || $op == 'delete' || $op == 'view') {
return user_access('access site notes');
}
}
/**
* Implementation of hook_form_alter().
* Disables the 'promote to front' option.
* Redirects the user to the view function.
* Remove sitenotes content from the advanced search options to prevent it being found.
* - Copied from: http://drupal.org/node/84955#comment-162473
*/
function sitenotes_form_alter($form_id, &$form){
if ($form_id == "sitenotes_node_form"){
$form['options']['promote']['#value'] = 0;
$form['#redirect'] = 'admin/build/sitenotes';
}
if ($form_id == 'search_form') {
unset($form['advanced']['type']['#options']['sitenotes']);
}
}
/**
* Implementation of hook_help().
* The first case adds a little help text.
* The second case adds some submission guidelines on the create content page.
*/
function sitenotes_help($section) {
switch ($section) {
case 'admin/help#sitenotes':
$output = '
'. t('The site designer can create site notes for later reference. Usually only super users can read them, unless other roles are given persmissions.') .'
';
return $output;
case 'node/add/sitenotes':
$output = t('Remember: you should insert <!--Break--> after the text you want to show in the teaser.
');
return $output;
}
}
/**
* Implementation of hook_form().
* Creates the form for adding the sitnenotes content type.
*/
function sitenotes_form(&$node) {
$type = node_get_types('type', $node);
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -5,
);
$form['body_filter']['body'] = array(
'#type' => 'textarea',
'#title' => check_plain($type->body_label),
'#default_value' => $node->body,
'#rows' => 20,
'#required' => TRUE,
);
$form['body_filter']['filter'] = filter_form($node->format);
$form['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#default_value' => $node->weight,
'#delta' => 20,
'#description' => t('Optional. The heavier items will sink and the lighter items will be positioned nearer the top.'),
);
return $form;
}
/**
* Implementation of hook_menu().
* Add a menu item to the Administer >> Site building menu for displaying the sitenotes.
*/
function sitenotes_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'node/add/sitenotes',
'title' => t('Site notes'),
'access' => user_access('access site notes'),
);
$items[] = array(
'path' => 'admin/build/sitenotes',
'title' => t('Site notes'),
'description' => t('Show all site notes'),
'callback' => 'sitenotes_list',
'access' => user_access('access site notes'),
);
}
return $items;
}
/**
* Implementation of sitenotes_list().
* Called from the Administer >> Site building menu to retrieve the sitenotes teasers.
* Note the use of styling classes for individual customization.
*/
function sitenotes_list() {
$sql = "SELECT n.nid FROM {node} n WHERE type='sitenotes' AND status=1 ORDER BY n.sticky DESC, n.created DESC";
$result = pager_query(db_rewrite_sql($sql), 10);
$output = '>> '. l(t('Add a new Site Note'), 'node/add/sitenotes') ."\n";
$output .= ''."\n";
while ($notes = db_fetch_object($result)) {
$node = node_load($notes->nid);
if ($node->sticky) { $output .= '
'; }
if(strlen($node->teaser) == strlen($node->body)){
$read = "";
} else {
$read = '
'. l("read more...", "node/". $node->nid) .'
';
}
$output .= '
'. l($node->title, "node/". $node->nid) ."\n"
.'
'. $node->teaser ."
\n". $read;
if ($node->sticky) { $output .= "
\n"; }
}
$output .= "
\n". theme('pager', NULL, 10);
return $output;
}
/**
* Implementation of hook_view().
* List all the sitenotes and provide breadcrumbs on the display.
*/
function sitenotes_view($node, $teaser = FALSE, $page = FALSE) {
$node = node_prepare($node, $teaser);
$node->content['note'] = array(
'#value' => theme('sitenotes_note', $node),
'#weight' => 1,
);
$breadcrumb = array();
$breadcrumb[] = array('path' => 'admin/build/sitenotes', 'title' => "Site Notes");
$breadcrumb[] = array('path' => 'node/'. $node->nid);
menu_set_location($breadcrumb);
return $node;
}
/**
* Implementation of hook_nodeapi
* On submit, encode the weight in the sticky field.
* On load, decode the weight from the sticky field.
*/
function sitenotes_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($node->type != 'sitenotes') { return; } /* don't do any others */
switch ($op) {
case 'submit':
// non-weighted nodes have a weight of zero
if (is_null($node->weight)){ $node->weight = 0; }
// here we're 'encoding' weight into the sticky value for the database
// stickiness is the inverse of weight
// - stickiness is sorted DESC while weight is sorted ASC so we invert
// the weight before saving... if sticky box is checked, add 100 to
// weight unweighted sticky nodes will have a value of 100
if($node->sticky) { $node->sticky = 100 - $node->weight; }
// unweighted non-sticky nodes will have a value of -100
else { $node->sticky = -100 - $node->weight; }
break;
case 'load':
$sticky = $node->sticky; /* save value */
$node->sticky = ($sticky > 0) ? 1 : 0;
$node->weight = ($sticky > 0) ? 100 - $sticky : -100 - $sticky;
break;
}
}
/**
* Implementation of hook_update_index.
* Remove sitenotes content from the search index to prevent it being found.
* Copied from: http://drupal.org/node/84955#comment-162473
**/
function sitenotes_update_index() {
if (function_exists('search_wipe')) {
$result = db_query("SELECT nid FROM {node} WHERE type = 'sitenotes'");
while ($data = db_fetch_object($result)) {
search_wipe($data->nid, 'node');
}
}
}