'MyHook Administration', 'page callback' => 'myhookadmin_admin', 'access arguments' => array('define custom hooks'), 'file' => 'myhookadmin.inc', ); return $items; } /** * Implements hook_permission(). */ function myhookadmin_permission() { return array( 'define custom hooks' => array( 'title' => 'Define custom hooks', 'restrict access' => TRUE, ), ); } /** * Gets a myhook variable */ function myhookadmin_var_get($name, $default = NULL, $reset = FALSE) { static $vars = array(); if ($reset || !array_key_exists($name, $vars)) { $vars[$name] = db_query('SELECT value FROM {myhookadmin} WHERE name = :name', array(':name' => $name))->fetchField(); } return isset($vars[$name]) ? $vars[$name] : $default; } /** * Sets a myhook variable */ function myhookadmin_var_set($name, $value = NULL) { db_delete('myhookadmin')->condition('name', $name)->execute(); isset($value) && db_insert('myhookadmin')->fields(array('name' => $name, 'value' => $value))->execute(); myhookadmin_var_get($name, NULL, TRUE); } /** * Includes/evaluates custom code/hooks. */ function myhookadmin_myhook() { if (isset($_GET['myhook']) && !$_GET['myhook']) { module_load_include('module', 'user'); if (user_access('define custom hooks')) { return; } } // Include file if (variable_get('myhookadmin_is_inc', 0)) { $inc_path = variable_get('myhookadmin_inc_path', ''); if ($inc_path && @is_readable($inc_path)) { $included = include_once $inc_path; if ($included) { return; } } } // Include failed. Eval code. $code = myhookadmin_var_get('myhook_code'); if (!empty($code)) { eval($code); } } // Include/execute custom code/myhooks. module_exists('myhook') && myhookadmin_myhook();