'anyedit/edit', 'title' => t('anyedit edit'), 'access' => user_access('access anyedit'), 'type' => MENU_CALLBACK, 'callback' => 'anyedit_edit'); // callback for node properties $items[] = array('path' => 'anyedit/node', 'title' => t('anyedit select node'), 'access' => user_access('access anyedit'), 'type' => MENU_CALLBACK, 'callback' => 'anyedit_select_node'); } return $items; } /** * Implementation of hook_settings(). */ function anyedit_settings() { $form['messages'] = array('#type' => 'fieldset', '#title' => t('Messages'), '#collapsible' => true); $form['messages']['anyedit_updated_msg'] = array( '#type' => 'textfield', '#title' => t('Updated Message'), '#default_value' => variable_get('anyedit_updated_msg', 'updated'), '#size' => 40, '#maxlength' => 200, '#required' => true, ); $form['messages']['anyedit_error_msg'] = array('#type' => 'textfield', '#title' => t('Error Message'), '#description' => t('%response is a placeholder for what the server will return back as a more specific error response'), '#default_value' => variable_get('anyedit_error_msg', 'error updating (%response)'), '#size' => 40, '#maxlength' => 200, '#required' => true, ); $form['node_types_options'] = array('#type' => 'fieldset', '#title' => t('Node Types'), '#collapsible' => true); $form['node_types_options']['anyedit_node_types'] = array('#type' => 'checkboxes', '#title' => NULL, '#default_value' => variable_get('anyedit_node_types', node_get_types()), '#options' => node_get_types(), //'#prefix' => '
'. print_r(node_get_types(), true) .'
' ); if (module_exist('tinymce') && user_access('administer tinymce')) { $form['tinymce'] = array('#type' => 'fieldset', '#title' => t('TinyMCE'), '#collapsible' => true); $form['tinymce']['anyedit_tinymce'] = array('#type' => 'checkbox', '#title' => t('enable TinyMCE on textarea editing'), '#default_value' => variable_get('anyedit_tinymce', true) ); } return $form; } /** * Implementation of hook_nodeapi(). */ function anyedit_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { static $anyedit_include; if ($node && $op == 'view' && user_access('access anyedit')) { if (!$anyedit_include) { $available_nodes = variable_get('anyedit_node_types', node_get_types()); foreach ($available_nodes as $available_node => $node_type) { if ($node_type == $node->type) { _anyedit_jquery(); _anyedit(); _anyedit_js('anyedit.nodes.js'); $anyedit_include = true; break; } } } // oh so sneaky if ($page) { $node->body .= '
'. $node->nid .'
'. "\n"; } else if ($teaser) { $node->teaser .= '
'. $node->nid .'
'. "\n"; } } } /** * grabbing node content */ function anyedit_select_node() { $nid = $_POST['nid']; $property = $_POST['property']; if (is_numeric($nid) && $property) { $node = node_load(array('nid' => $nid)); print $node->$property; } exit(); } /** * main edit callback */ function anyedit_edit() { global $user; // if this is a node edit we do node permissions check if ($_POST['nid']) { $node = node_load(array('nid' => $_POST['nid'])); if (!anyedit_node_access($node)) return; $node->$_POST['property'] = $_POST['value']; node_save($node); print $node->$_POST['property']; } else if ($_POST['db_table']) { if (db_affected_rows() > 0) { print variable_get('anyedit_updated_msg', 'updated'); } else { // TODO: $response needs to be a more specific error message ? print t(variable_get('anyedit_error_msg', 'error updating (%response)'), array('%response' => $response)); } } exit(); } /** * handle node permissions */ function anyedit_node_access($node) { global $user; if ((user_access('edit own '. $node->type) && ($user->uid == $node->uid)) || user_access('administer '. $node->type)) { return true; } } /** * helper functions */ function _anyedit_js($filename) { drupal_add_js(drupal_get_path('module', 'anyedit') .'/js/'. $filename); } function _anyedit_jquery($f = 'jquery-svn.js') { _anyedit_js($f); } function _anyedit() { static $included; $configs = array(); if (module_exist('tinymce') && user_access('access tinymce') && variable_get('anyedit_tinymce', true)) { $configs['tinymce'] = 'true'; } if (!$included) { // we need a base_path for the js side of things so we don't ever break paths $head = ''. "\n"; drupal_set_html_head($head); // include our version if jquery until jquery is in core _anyedit_jquery(); // use my simple wrapper function of drupal_add_js _anyedit_js('anyedit.js'); // include a stylesheet theme('anyedit_styles'); $included = true; } } /** * theme functions */ function theme_anyedit_styles() { drupal_set_html_head(theme('stylesheet_import', base_path() . drupal_get_path('module', 'anyedit') .'/anyedit.css')); }