/** * Implementation of module_content */ function admin_content() { global $ssc_user, $ssc_database; $out = ''; if ($_GET['path'] != '/admin' || $ssc_user->gid == SSC_USER_GUEST) { ssc_not_found(); return; } switch ($_GET['param']) { case '': ssc_set_title("Administration"); $out = _admin_base_content(); break; default: // Check for sub-page. args can be claimed from $_GET[param] $_GET['param'] = explode("/", $_GET['param']); $_GET['admin_page'] = array_shift($_GET['param']); if (!login_check_auth($_GET['admin_page'])) { ssc_not_allowed(); } else { $out = module_hook('admin', $_GET['admin_page']); } if (empty($out)) { ssc_not_found(); } break; } return $out; }
function module_invoke($module, $hook) { $args = func_get_args(); unset($args[0], $args[1]); if (module_hook($module, $hook)) { return call_user_func_array($module . '_' . $hook, $args); } }
public function getModuleHookInfo($module, $hook) { if (!module_hook($module, $hook)) { throw new HookNotImplementedByModuleException($module, $hook); } // File should now be included. // Drupal hook implementation will probably never change in 7 // but still worth noting that this is dirty. $functionReflector = new \ReflectionFunction($module . '_' . $hook); return array('file' => $functionReflector->getFileName(), 'invoke' => function () use($module, $hook) { $args = func_get_args(); array_unshift($args, $module, $hook); return call_user_func_array('module_invoke', $args); }); }
function navin_process_maintenance_page(&$variables) { // Include @font-your-face support if (module_exists('fontyourface')) { fontyourface_preprocess_page($variables); $fonts = (array) $variables['fontyourface']; foreach ($fonts as $font) { if (module_hook($font->provider, 'preprocess_page')) { call_user_func_array($font->provider . '_preprocess_page', array(&$variables)); } } } // Add theme's maintenance CSS drupal_add_css(path_to_theme() . '/css/maintenance.css', array('group' => CSS_THEME, 'weight' => 10)); // Reset variables $variables['head'] = drupal_get_html_head(); $variables['css'] = drupal_add_css(); $variables['styles'] = drupal_get_css(); $variables['scripts'] = drupal_get_js(); }
/** * Get info about hooks from Drupal Core. * * This invokes hook_hook_info(). * * @param $file_data * An array of file data for a hook documentation file. * * @return * The data from the implementation of hook_hook_info() for the module that * provided the documentation file. */ protected function getDrupalHookInfo($file_data) { // Note that the 'module' key is flaky: some modules use a different name // for their api.php file. $module = $file_data['module']; $hook_info = array(); if (module_hook($module, 'hook_info')) { $hook_info = module_invoke($module, 'hook_info'); } return $hook_info; }
<?php include_once "includes/common.inc"; drupal_page_header(); check_php_setting("magic_quotes_gpc", 0); menu_build("system"); $mod = arg(0); if (isset($mod) && module_hook($mod, "page")) { module_invoke($mod, "page"); } else { if (module_hook(variable_get("site_frontpage", "node"), "page")) { module_invoke(variable_get("site_frontpage", "node"), "page"); } else { theme("header"); theme("footer"); } } drupal_page_footer();
*/ define("_VALID_SSC", 1); define("SSC_CRON_MIN_TIME", 60 * 59); // Minimum 1hr time // Only load from internally if (isset($_SERVER['REMOTE_ADDR']) || !isset($_SERVER['argv'])) { die('Restricted access'); } $sites = glob('./config/*.settings.inc.php'); if ($sites === false) { die('Restricted access'); } include './includes/core.inc.php'; foreach ($sites as $site) { $site = str_replace(".settings.inc.php", "", $site); $site = substr($site, 9); $_SERVER['SERVER_NAME'] = $site; if ($site == 'default') { continue; } // Begin application startup ssc_init(SSC_INIT_EXTENSION); $lastrun = ssc_var_get("cron_last_run", 0); $now = time(); // Run only if not up to hardcoded minimum per-run time if ($lastrun < $now - SSC_CRON_MIN_TIME) { module_hook('cron'); } ssc_var_set("cron_last_run", $now); ssc_close(); }
function module_invoke() { $args = func_get_args(); $module = $args[0]; $hook = $args[1]; unset($args[0], $args[1]); $function = $module . '_' . $hook; if (module_hook($module, $hook)) { return call_user_func_array($function, $args); } }
/** * Loop through and load up each module as needed */ function module_load() { global $ssc_site_path, $ssc_database, $SSC_MODULES; // Make sure we only run once to avoid excess HDD usage / include_once overhead static $has_run = 0; if ($has_run == 1) { return; } // Set up modules "superglobal" $SSC_MODULES = array(); // Retrieve all enabled modules $result = $ssc_database->query("SELECT id, filename, weight FROM #__module WHERE status >= %d ORDER BY weight ASC", SSC_MODULE_ENABLED); // Load each module while ($data = $ssc_database->fetch_assoc($result)) { $SSC_MODULES[$data['filename']] = $data; ssc_debug(array('title' => 'module_load', 'body' => "Loading {$data['filename']}.module.php")); include "{$ssc_site_path}/modules/{$data['filename']}/{$data['filename']}.module.php"; } // Initialise module module_hook("init"); // Mark function as run $has_run = 1; }
/** * Called when HTML meta, CSS and JS tags may be output * function theme_meta(){ ob_start(); module_hook('meta'); $data = ob_get_contents(); ob_end_clean(); return $data; } /** * Called when a page title should be generated, for example the site name in a header * @param int $count Header level. Use 1 for primary title and 2 for a quip or subtitle. * function theme_title($count){ return "SSC"; } /** * Called when one of 'n' sidebar locations is created. * @param int $count Number of the sidebar. Used to decide which module * 'mini' output versions should be shown */ function theme_side($count) { global $ssc_database; $result = $ssc_database->query("SELECT filename, args FROM #__module, #__sidebar WHERE #__module.id = #__sidebar.module AND location = %d ORDER BY #__sidebar.weight ASC", $count); if ($ssc_database->number_rows() < 1) { return ' '; } $ret = array(); while ($data = $ssc_database->fetch_assoc($result)) { $dat = module_hook('widget', $data['filename'], explode(',', $data['args'])); if ($dat) { $ret[] = theme_template('widget', $dat); } } return implode("\n", $ret); }
/** * Builds complete hook data array from downloaded files and stores in a file. * * (Replaces module_builder_process_hook_data().) * * @param hook_file_data * An array of data about the files to process, keyed by (safe) filename: * -[MODULE.FILENAME] => Array // eg system.core.php * - [path] => full path to the file * - [destination] => %module.module * - [group] => GROUP // eg core * - [hook_destinations] => array(%module.foo => hook_foo, etc) * - [hook_dependencies] => array() * This is the same format as returned by update.inc. * * @return * An array keyed by originating file of the following form: * [GROUP] => array( // grouping for UI. [hook_foo] => array( [name] => hook_foo [definition] => function hook_foo($node, $teaser = FALSE, $page = FALSE) [description] => Description. [destination] => Destination module file for hook code from this file. ... further properties: 'type' => $hook_data_raw['type'][$key], 'name' => $hook, 'definition' => $hook_data_raw['definitions'][$key], 'description' => $hook_data_raw['descriptions'][$key], // TODO: Don't store this, just use it to figure out // callback dependencies! //'documentation' => $hook_data_raw['documentation'][$key], 'destination' => $destination, 'dependencies' => $hook_dependencies, 'group' => $group, 'file_path' => $file_data['path'], 'body' => $hook_data_raw['bodies'][$key], */ function processHookData($hook_file_data) { //print_r($hook_file_data); // check file_exists? // Sort the files into a better order than just random. // TODO: allow for some control over this, eg frequently used core, // then rarer core, then contrib in the order defined by the MB hook. ksort($hook_file_data); // Build list of hooks $hook_groups = array(); foreach ($hook_file_data as $file => $file_data) { $hook_data_raw = $this->processHookFile($file_data['path']); $file_name = basename($file, '.php'); $group = $file_data['group']; // Should probably use module_hook_info(), but I don't use undocumented code FFS. // Note that the 'module' key is flaky: see module_builder_update_documentation() $module = $file_data['module']; $hook_info = array(); if (module_hook($module, 'hook_info')) { $hook_info = module_invoke($module, 'hook_info'); } // Create an array in the form of: // array( // 'filename' => array( // array('hook' => 'hook_foo', 'description' => 'hook_foo description'), // ... // ), // ... // ); foreach ($hook_data_raw['names'] as $key => $hook) { // The destination is possibly specified per-hook; if not, then given // for the whole file. if (isset($file_data['hook_destinations'][$hook])) { $destination = $file_data['hook_destinations'][$hook]; } else { $destination = $file_data['destination']; } // Also try to get destinations from hook_hook_info(). // Argh why don't we have the short name here yet???? // @todo: clean up! $short_name = substr($hook, 5); if (isset($hook_info[$short_name])) { print_r($hook_info); $destination = '%module.' . $hook_info[$short_name]['group'] . '.inc'; } // Process hook dependendies for the file. $hook_dependencies = array(); if (isset($file_data['hook_dependencies'])) { // Incoming data is of the form: // 'required hook' => array('dependent hooks') // where the latter may be a regexp. foreach ($file_data['hook_dependencies'] as $required_hook => $dependency_data) { foreach ($dependency_data as $match) { if (preg_match("@{$match}@", $hook)) { $hook_dependencies[] = $required_hook; } } } } // See if the hook has any callbacks as dependencies. We assume that // mention of a string of the form 'callback_foo()' means it's needed // for the hook. // TODO: see if there's a way to label this in the resulting source // as associated with the hook that requested this. $matches = array(); preg_match_all("@(callback_\\w+)\\(\\)@", $hook_data_raw['documentation'][$key], $matches); if (!empty($matches[1])) { $hook_dependencies += $matches[1]; } // Because we're working through the raw data array, we keep the incoming // sort order. // But if there are multiple hook files for one module / group, then // they will go sequentially one after the other. // TODO: should this be improved, eg to group also by filename? $hook_groups[$group][$hook] = array('type' => $hook_data_raw['type'][$key], 'name' => $hook, 'definition' => $hook_data_raw['definitions'][$key], 'description' => $hook_data_raw['descriptions'][$key], 'destination' => $destination, 'dependencies' => $hook_dependencies, 'group' => $group, 'file_path' => $file_data['path'], 'body' => $hook_data_raw['bodies'][$key]); //dsm($hook_groups); //drush_print_r($hook_groups); } // foreach hook_data } // foreach files //dsm($hook_groups); //print_r($hook_groups); // Write the processed data to a file. $directory = $this->environment->hooks_directory; $serialized = serialize($hook_groups); file_put_contents("{$directory}/hooks_processed.php", $serialized); return $hook_groups; }
/** * Post submission */ function blog_post_submit() { global $ssc_user, $ssc_database; $blog = (int) $_POST['bid']; $id = (int) $_POST['id']; // Someone trying to circumvent things if ($blog == 0) { return; } if (isset($_POST['prev'])) { ssc_add_message(SSC_MSG_INFO, "Below is a preview of your post. Nothing has been saved yet."); return; } $require_redir = false; if ($id == 0) { // Insert $result = $ssc_database->query("INSERT INTO #__blog_post (blog_id, title, created, modified, body, urltext, author_id, is_draft, publish_time) VALUES (%d, '%s', %d, %d, '%s', '%s', %d, %d, 0)", $blog, $_POST['title'], time(), time(), $_POST['body'], $_POST['url'], $ssc_user->id, $_POST['is_draft'] + ($_POST['is_draft'] ? $_POST['repub'] << 1 : 0)); $_POST['id'] = $id = $ssc_database->last_id(); if (!$result) { ssc_add_message(SSC_MSG_CRIT, 'Error inserting into DB'); return; } $require_redir = true; if ($_POST['is_draft'] == 0) { module_hook('mod_blog_post_publish', null, array($blog, $id, t($_POST['title']))); } } else { // Update // Determine changes.... $result = $ssc_database->query("SELECT body FROM #__blog_post p WHERE id = %d AND blog_id = %d", $id, $blog); if ($result && ($data = $ssc_database->fetch_assoc($result))) { $dirty = $data['body'] != $_POST['body']; if (!$dirty) { if ($_POST['repub']) { $ssc_database->query("UPDATE #__blog_post b SET title = '%s', urltext = '%s', is_draft = %d, created = %d, modified = %d WHERE id = %d AND blog_id = %d", $_POST['title'], $_POST['url'], $_POST['is_draft'] + ($_POST['is_draft'] ? $_POST['repub'] << 1 : 0), time(), time(), $id, $blog); } else { $ssc_database->query("UPDATE #__blog_post b SET title = '%s', urltext = '%s', is_draft = %d WHERE id = %d AND blog_id = %d", $_POST['title'], $_POST['url'], $_POST['is_draft'] + ($_POST['is_draft'] ? $_POST['repub'] << 1 : 0), $id, $blog); } } else { if ($_POST['repub']) { $ssc_database->query("UPDATE #__blog_post b SET title = '%s', body = '%s', urltext = '%s', is_draft = %d, created = %d, modified = %d WHERE id = %d AND blog_id = %d", $_POST['title'], $_POST['body'], $_POST['url'], $_POST['is_draft'] + ($_POST['is_draft'] ? $_POST['repub'] << 1 : 0), time(), time(), $id, $blog); } else { $ssc_database->query("UPDATE #__blog_post b SET title = '%s', body = '%s', urltext = '%s', is_draft = %d WHERE id = %d AND blog_id = %d", $_POST['title'], $_POST['body'], $_POST['url'], $_POST['is_draft'] + ($_POST['is_draft'] ? $_POST['repub'] << 1 : 0), $id, $blog); } } if ($_POST['is_draft'] == 0) { if ($_POST['repub']) { module_hook('mod_blog_post_publish', null, array($blog, $id, t($_POST['title']))); } else { if ($dirty) { module_hook('mod_blog_post_update', null, array($blog, $id, t($_POST['title']))); } } } } } // Tags $result = $ssc_database->query("SELECT tag_id FROM #__blog_relation WHERE post_id = %d", $id); $exist = array(); // Retrieve existing list of tags while ($data = $ssc_database->fetch_assoc($result)) { $exist[] = $data['tag_id']; } $exist = ',' . implode(',', $exist) . ','; if (isset($_POST['tid'])) { $tID = $_POST['tid']; // Loop through each tag id foreach ($tID as $key => $value) { $key = (int) $key; if ($key > 0 && strpos($exist, ',' . $key . ',') === false) { // If not present already, add to the relation table $ssc_database->query("INSERT INTO #__blog_relation (post_id, tag_id) VALUES (%d, %d)", $id, $key); } else { // Else, it's already there so don't need to add. // Remove from todelete list $exist = str_replace(',' . $key, '', $exist); } } } $exist = explode(',', $exist); $total = count($exist); for ($i = 0; $i < $total; $i++) { if ($tID = intval($exist[$i])) { $ssc_database->query("DELETE FROM #__blog_relation WHERE post_id = %d AND tag_id = %d LIMIT 1", $id, $tID); } } ssc_add_message(SSC_MSG_INFO, t('Post saved')); if ($require_redir) { ssc_redirect("/admin/blog/edit/{$blog}/post/{$id}"); } }
/** * Runs page related queries to handle form submissions, etc */ function ssc_execute() { // Find the module responsible for the current URI return module_hook('content', $_GET['handler']); }