/** * @todo . */ public function messageHandler() { if (!isset($_POST['serviceKey']) || !nodejs_is_valid_service_key($_POST['serviceKey'])) { return new JsonResponse(array('error' => 'Invalid service key.')); } if (!isset($_POST['messageJson'])) { return new JsonResponse(array('error' => 'No message.')); } $message = Json::decode($_POST['messageJson']); $response = array(); switch ($message['messageType']) { case 'authenticate': $response = nodejs_auth_check($message); break; case 'userOffline': nodejs_user_set_offline($message['uid']); break; default: $handlers = array(); foreach (module_implements('nodejs_message_callback') as $module) { $function = $module . '_nodejs_message_callback'; $handlers += $function($message['messageType']); } foreach ($handlers as $callback) { $callback($message, $response); } } \Drupal::moduleHandler()->alter('nodejs_message_response', $response, $message); return new JsonResponse($response ? $response : array('error' => 'Not implemented')); }
/** * Grant permissions to a specific role, if it exists. * * @param string $role * Role machine name. * @param string $permission * Permission machine name. * @param string $module * Module name. * * @return bool * TRUE if operation was successful, FALSE otherwise. */ public function grantPermission($role, $permission, $module = NULL) { $permission_rebuilt =& drupal_static(__CLASS__ . ':' . __FUNCTION__); if (!$permission_rebuilt) { // Make sure the list of available node types is up to date. node_types_rebuild(); // Reset hook_permission() cached information. module_implements('permission', FALSE, TRUE); $permission_rebuilt = TRUE; } $permissions = is_array($permission) ? $permission : array($permission); $role_object = user_role_load_by_name($role); if ($role_object) { // Use code from user_role_grant_permissions() in order to be able // to force medule field in special cases. $modules = user_permission_get_modules(); // Grant new permissions for the role. foreach ($permissions as $name) { $modules[$name] = isset($modules[$name]) ? $modules[$name] : $module; db_merge('role_permission')->key(array('rid' => $role_object->rid, 'permission' => $name))->fields(array('module' => $modules[$name]))->execute(); } // Clear the user access cache. drupal_static_reset('user_access'); drupal_static_reset('user_role_permissions'); return TRUE; } else { return FALSE; } }
function __construct($template_id) { $this->_template_id = $template_id; $context_options = cache_get('maestro_taskclass_info'); // Test if context options are cached - if not then we will set it // The class function getContextMenu will read options from the cache if ($context_options === FALSE) { $context_options = array(); // Scan through each available class type and fetch its corresponding context menu. foreach (module_implements('maestro_get_taskobject_info') as $module) { $function = $module . '_maestro_get_taskobject_info'; if ($arr = $function()) { $context_options = maestro_array_add($context_options, $arr); } } cache_set('maestro_taskclass_info', $context_options); } $handler_options = cache_get('maestro_handler_options'); // Test if task type handler options are cached - if not then we will set it // The class function getHandlerOptions will read options from the cache if ($handler_options === FALSE) { // Scan through each available class type and fetch its corresponding context menu. foreach (module_implements('maestro_handler_options') as $module) { $function = $module . '_maestro_handler_options'; if ($arr = $function()) { $handler_options = maestro_array_merge_keys($arr, $handler_options); } } cache_set('maestro_handler_options', $handler_options); } }
/** * Endpoint authentication configuration form. */ function services_edit_form_endpoint_authentication($form_state) { $endpoint = services_endpoint_load(arg(4)); // Loading runtime include as needed by services_authentication_info(). module_load_include('runtime.inc', 'services'); $form = array(); $auth_modules = module_implements('services_authentication_info'); $form['endpoint_object'] = array('#type' => 'value', '#value' => $endpoint); if (empty($auth_modules)) { $form['message'] = array('#type' => 'item', '#title' => t('Authentication'), '#description' => t('No authentication modules are installed, all requests will be anonymous.')); return $form; } if (empty($endpoint->authentication)) { $form['message'] = array('#type' => 'item', '#title' => t('Authentication'), '#description' => t('No authentication modules are enabled, all requests will be anonymous.')); return $form; } // Add configuration fieldsets for the authentication modules foreach ($endpoint->authentication as $module => $settings) { $info = services_authentication_info($module); if (empty($info)) { continue; } $form[$module] = array('#type' => 'fieldset', '#title' => isset($info['title']) ? $info['title'] : $module, '#tree' => TRUE); $module_settings_form = services_auth_invoke($module, 'security_settings', $settings); if (!empty($module_settings_form) && $module_settings_form !== TRUE && $settings == $module || is_array($settings)) { $form[$module] += $module_settings_form; } else { $form[$module]['message'] = array('#type' => 'item', '#value' => t('@module has no settings available.', array('@module' => drupal_ucfirst($module)))); } } $form['submit'] = array('#type' => 'submit', '#value' => 'Save'); return $form; }
/** * Constructor * * @param $users * Mandatory - An array of integers or single integer specifying the Drupal users to notify. * * @param $defaultMessage * String: The default message to send in the email, overridden with the message stored in the template_data record * * @param $defaultSubject * String: The default email subject, overridden with the message stored in the template_data record * * @param $queueID * Integer: The QueueID associated with the message you're sending out * * @param $type * String: The actual notification type using the MaestroNotificationTypes Constants */ function __construct($defaultMessage = '', $defaultSubject = '', $queueID = 0, $type = MaestroNotificationTypes::ASSIGNMENT) { $observers = array(); $this->_notificationType = $type; $this->_queueID = $queueID; $this->getNotificationUserIDs(); $this->setNotificationSubjectAndMessage($defaultMessage, $defaultSubject); //Now, lets determine if we've got our observers cached. If not, lets rebuild that observer list //This is how we subscribe to becoming a notification provider for Maestro. $observers = cache_get('maestro_notification_observers'); if ($observers === FALSE) { //build the observer cache //need to scan through each available class type and fetch its corresponding context menu. foreach (module_implements('maestro_notification_observer') as $module) { $function = $module . '_maestro_notification_observer'; if ($declaredObserver = $function()) { foreach ($declaredObserver as $observerToCache) { $observers[] = $observerToCache; $this->_observers[] = $observerToCache; } } } cache_set('maestro_notification_observers', $observers); } else { $this->_observers = $observers->data; } }
/** * Return a list of valid addresses where key = email address and value = associated UID. * EG. $array['*****@*****.**'] = 1 * * @return list of valid addresses */ private function get_valid_address_list() { // Define a hook -- this plugin is intended to be used with mailhandler_singlebox // but it could be implemented using another email address to uid mapping function. $addresses = array(); foreach (module_implements('mailhandler_sendto_addresses') as $module) { $addresses += module_invoke($module, 'mailhandler_sendto_addresses'); } return $addresses; }
/** * Get data from other modules via hook_groupadmin_ functions. */ function _groupadmin_get_modules($op) { $hook = 'hook_groupadmin_' . $op; $modules = module_implements($hook); //drupal_set_message('modules: ' . print_r($modules, 1)); $data = array(); foreach ($modules as $module) { $data = array_merge($data, module_invoke($module, $hook)); } return $data; }
private static function invokeByRef($hook, &$obj) { // Construct our argument array $args = func_get_args(); array_shift($args); $args[0] =& $obj; $modules = module_implements($hook); foreach ($modules as $module) { call_user_func_array($module . '_' . $hook, $args); } }
public function entityFieldQueryAlter(SelectQueryInterface $query) { // Adding the 'node_access' tag is sadly insufficient for nodes: core // requires us to also know about the concept of 'published' and // 'unpublished'. We need to do that as long as there are no access control // modules in use on the site. As long as one access control module is there, // it is supposed to handle this check. if (!user_access('bypass node access') && !count(module_implements('node_grants')) && !user_access('reference unpublished nodes')) { $base_table = $this->ensureBaseTable($query); $query->condition("{$base_table}.status", NODE_PUBLISHED); } }
/** * {@inheritdoc} */ function operateOnFinder($finder, $helper) { // Let other modules register stuff to the finder via hook_xautoload(). $classmap_generator = new ClassMapGenerator(); $adapter = new ClassFinderAdapter($finder, $classmap_generator); $api = new \xautoload_InjectedAPI_hookXautoload($adapter, ''); foreach (module_implements('xautoload') as $module) { $api->setExtensionDir($dir = drupal_get_path('module', $module)); $f = $module . '_xautoload'; $f($api, $dir); } }
/** * Implements \SiteAudit\Check\Abstract\calculateScore(). */ public function calculateScore() { global $conf; if ($conf['block_cache']) { return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS; } elseif (count(module_implements('node_grants'))) { return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_WARN; } // Block caching is off. if (site_audit_env_is_dev()) { return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO; } return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL; }
/** * @see drupal_alter */ private function drupalAlter($type, &$data) { $dir = getcwd(); chdir($this->drupal_dir); // Hang onto a reference to the data array so that it isn't blown away later. $args = array(&$data); // Now, use func_get_args() to pull in any additional parameters passed into // the drupalAlter() call. $additional_args = func_get_args(); array_shift($additional_args); array_shift($additional_args); $args = array_merge($args, $additional_args); foreach (module_implements($type . '_alter') as $module) { $function = $module . '_' . $type . '_alter'; call_user_func_array($function, $args); } chdir($dir); }
/** * Get cron queues and static cache them. * * Works like module_invoke_all('cron_queue_info'), but adds * a 'module' to each item. * * @return array * Cron queue definitions. */ private function get_queues() { if (!isset(self::$queues)) { $queues = array(); foreach (module_implements('cron_queue_info') as $module) { $items = module_invoke($module, 'cron_queue_info'); if (is_array($items)) { foreach ($items as &$item) { $item['module'] = $module; } $queues += $items; } } drupal_alter('cron_queue_info', $queues); self::$queues = $queues; } return $queues; }
public function check(&$output, &$perf) { $status = PROD_MONITORING_OK; $messages = array(); $output = ''; $perf = ''; $checkers = module_implements('prod_nagios_check'); foreach ($checkers as $i => $module) { $result = module_invoke($module, 'prod_nagios_check'); // Check output format if (!is_array($result) || !array_key_exists('status', $result)) { throw new MonitoringException($module . ' has invalid output format'); } // Collect messages if (array_key_exists('message', $result)) { $messages[] = $result['message']; } // Collect perfdata // TODO (via arrays?) switch ($result['status']) { case PROD_MONITORING_CRITICAL: $status = $result['status']; // stop processing modules and exit right now break 2; case PROD_MONITORING_WARNING: if (PROD_MONITORING_OK === $status || PROD_MONITORING_PENDING === $status || PROD_MONITORING_UNKNOWN === $status) { $status = $result['status']; } break; case PROD_MONITORING_UNKNOWN: if (PROD_MONITORING_OK === $status || PROD_MONITORING_PENDING === $status) { $status = $result['status']; } break; case PROD_MONITORING_PENDING: if (PROD_MONITORING_OK === $status) { $status = $result['status']; } break; } } $output = implode('; ', $messages); return $status; }
public function getDefaultScope($client_id = NULL) { // Allow any hook_oauth2_server_default_scope() implementations to supply // the default scope. The first one to return a scope wins. foreach (module_implements('oauth2_server_default_scope') as $module) { $function = $module . '_' . 'oauth2_server_default_scope'; $args = array($this->server); $result = call_user_func_array($function, $args); if (is_array($result)) { return implode(' ', $result); } } // If there's a valid default scope set in server settings, return it. $default_scope = $this->server->settings['default_scope']; if (!empty($default_scope) && oauth2_server_scope_load($this->server->name, $default_scope)) { return $default_scope; } return FALSE; }
public function render() { $reporters = module_implements('prod_monitor_summary'); $lines = array(); // D7 hooks foreach ($reporters as $i => $module) { $new_lines = module_invoke($module, 'prod_monitor_summary'); if (!is_array($new_lines)) { throw new MonitoringException($module . ' has invalid output format'); } $lines = array_merge($lines, new_lines); } // Listeners should call AddOutputLine() on ourself $this->notify(ProdObservable::SIGNAL_MONITOR_SUMMARY); $lines = array_merge($lines, $this->_lines); foreach ($lines as $line) { drush_print($line, 0, NULL, TRUE); } }
/** * Endpoint authentication configuration form. */ function services_edit_form_endpoint_authentication($form, &$form_state) { list($endpoint) = $form_state['build_info']['args']; // Loading runtime include as needed by services_authentication_info(). module_load_include('inc', 'services', 'includes/services.runtime'); $auth_modules = module_implements('services_authentication_info'); $form['endpoint_object'] = array('#type' => 'value', '#value' => $endpoint); if (empty($auth_modules)) { $form['message'] = array('#type' => 'item', '#title' => t('Authentication'), '#description' => t('No authentication modules are installed, all requests will be anonymous.')); return $form; } if (empty($endpoint->authentication)) { $form['message'] = array('#type' => 'item', '#title' => t('Authentication'), '#description' => t('No authentication modules are enabled, all requests will be anonymous.')); return $form; } // Add configuration fieldsets for the authentication modules foreach ($endpoint->authentication as $module => $settings) { $info = services_authentication_info($module); if (empty($info)) { continue; } $form[$module] = array('#type' => 'fieldset', '#title' => isset($info['title']) ? $info['title'] : $module, '#tree' => TRUE); // Append the default settings for the authentication module. $default_security_settings = services_auth_invoke($module, 'default_security_settings'); if ($settings == $module && is_array($default_security_settings)) { $settings = $default_security_settings; } // Ask the authentication module for a settings form. $module_settings_form = services_auth_invoke($module, 'security_settings', $settings, $form_state); if (is_array($module_settings_form)) { $form[$module] += $module_settings_form; } else { $form[$module]['message'] = array('#type' => 'item', '#markup' => t('@module has no settings available.', array('@module' => drupal_ucfirst($module)))); } } $form['submit'] = array('#type' => 'submit', '#value' => 'Save'); return $form; }
/** * Build an EntityFieldQuery to get referencable entities. */ public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', $this->field['settings']['target_type']); if (!empty($this->field['settings']['handler_settings']['target_bundles'])) { $query->entityCondition('bundle', $this->field['settings']['handler_settings']['target_bundles'], 'IN'); } if (isset($match)) { $query->propertyCondition('title', $match, $match_operator); } // Add an access tag to the query. $query->addTag('harmony_access'); $query->addTag('entityreference'); $query->addMetaData('field', $this->field); $query->addMetaData('entityreference_selection_handler', $this); // Adding the 'harmony_thread_access' tag is sadly insufficient for threads: core // requires us to also know about the concept of 'published' and // 'unpublished'. We need to do that as long as there are no access control // modules in use on the site. As long as one access control module is there, // it is supposed to handle this check. if ((!user_access('bypass harmony forum access control') || !user_access('administer forum content')) && !count(module_implements('harmony_thread_grants'))) { $query->propertyCondition('status', HARMONY_PUBLISHED); $query->propertyCondition('locked', HARMONY_NOT_LOCKED); } // Add the sort option. if (!empty($this->field['settings']['handler_settings']['sort'])) { $sort_settings = $this->field['settings']['handler_settings']['sort']; if ($sort_settings['type'] == 'property') { $query->propertyOrderBy($sort_settings['property'], $sort_settings['direction']); } elseif ($sort_settings['type'] == 'field') { list($field, $column) = explode(':', $sort_settings['field'], 2); $query->fieldOrderBy($field, $column, $sort_settings['direction']); } } return $query; }
/** * {@inheritDoc} */ protected function write(array $record) { // Pre-bootstrap errors if (!function_exists('module_implements')) { return; } $request = \Drupal::requestStack()->getCurrentRequest(); // Remove unwanted stuff from the context, do not attempt to serialize // potential PDO instances of stuff like that may lie into unserialized // exceptions in there $message = empty($record['formatted']) ? $record['message'] : $record['formatted']; foreach ($record['context'] as $key => $value) { // @todo temporary avoir Array to string conversion warnings if (!is_array($value)) { $record['context'][$key] = (string) $value; } } // If you are dblogging stuff, using <br/> tags is advised for readability $message = nl2br($message); $entry = ['severity' => self::monologToDrupal($record['level']), 'type' => 'monolog', 'message' => $message, 'variables' => $record['context'], 'link' => '', 'user' => null, 'uid' => \Drupal::currentUser()->id(), 'request_uri' => $request->getRequestUri(), 'referer' => $request->headers->get('referer'), 'ip' => $request->getClientIp(), 'timestamp' => $record['datetime']->getTimestamp()]; foreach (module_implements('watchdog') as $module) { module_invoke($module, 'watchdog', $entry); } }
/** * Render the interior contents of a single pane. * * This method retrieves pane content and produces a ready-to-render content * object. It also manages pane-specific caching. * * @param stdClass $pane * A Panels pane object, as loaded from the database. * @return stdClass $content * A renderable object, containing a subject, content, etc. Based on the * renderable objects used by the block system. */ function render_pane_content(&$pane) { ctools_include('context'); // TODO finally safe to remove this check? if (!is_array($this->display->context)) { watchdog('panels', 'renderer::render_pane_content() hit with a non-array for the context', $this->display, WATCHDOG_DEBUG); $this->display->context = array(); } $content = FALSE; $caching = !empty($pane->cache['method']) && empty($this->display->skip_cache); if ($caching && ($cache = panels_get_cached_content($this->display, $this->display->args, $this->display->context, $pane))) { $content = $cache->content; } else { $content = ctools_content_render($pane->type, $pane->subtype, $pane->configuration, array(), $this->display->args, $this->display->context); foreach (module_implements('panels_pane_content_alter') as $module) { $function = $module . '_panels_pane_content_alter'; $function($content, $pane, $this->display->args, $this->display->context); } if ($caching) { $cache = new panels_cache_object(); $cache->set_content($content); panels_set_cached_content($cache, $this->display, $this->display->args, $this->display->context, $pane); $content = $cache->content; } } // Pass long the css_id that is usually available. if (!empty($pane->css['css_id'])) { $content->css_id = check_plain($pane->css['css_id']); } // Pass long the css_class that is usually available. if (!empty($pane->css['css_class'])) { $content->css_class = check_plain($pane->css['css_class']); } return $content; }
/** * Implements hook_page_alter(). */ function alpha_page_alter(&$vars) { $theme = alpha_get_theme(); $theme->settings['debug']['access'] = alpha_debug_access($GLOBALS['user'], $theme->settings['debug']['roles']); // If no module has taken care of the main content, add it to the page now. // This allows the site to still be usable even if no modules that // control page regions (for example, the Block module) are enabled. if (!drupal_static('system_main_content_added', FALSE)) { $vars['content']['system_main'] = drupal_set_page_content(); } if (($theme->settings['debug']['access'] || $GLOBALS['user']->uid == 1) && ($theme->settings['debug']['grid'] || $theme->settings['debug']['block'])) { drupal_add_css(drupal_get_path('theme', 'alpha') . '/css/alpha-debug.css', array('group' => CSS_THEME, 'weight' => -5)); drupal_add_js(drupal_get_path('theme', 'alpha') . '/js/alpha-debug.js', array('group' => JS_THEME, 'weight' => -5)); if ($theme->settings['responsive']) { $vars['page_bottom']['alpha_resize_indicator'] = array('#type' => 'markup', '#markup' => '<div class="alpha-resize-indicator"></div>'); } if ($theme->settings['debug']['grid']) { $vars['page_bottom']['alpha_grid_toggle'] = array('#type' => 'markup', '#markup' => '<a class="alpha-grid-toggle" href="#"></a>'); } if ($theme->settings['debug']['block']) { $vars['page_bottom']['alpha_block_toggle'] = array('#type' => 'markup', '#markup' => '<a class="alpha-block-toggle" href="#"></a>'); foreach ($theme->regions as $region => $item) { if ($item['enabled']) { if (empty($vars[$region])) { $vars[$region]['#region'] = $region; $vars[$region]['#theme_wrappers'] = array('region'); } if (isset($vars[$region]['#theme_wrappers']) && array_search('region', $vars[$region]['#theme_wrappers']) !== FALSE) { $vars[$region] = array('alpha_debug_' . $region => array('#type' => 'markup', '#markup' => '<div class="alpha-debug-block"><h2>' . $item['name'] . '</h2><p>' . t('This is a debugging block') . '</p></div>', '#weight' => -999)) + $vars[$region]; } } } } } if (!module_implements('alpha_page_structure_alter')) { alpha_alter('alpha_page_structure', $vars, $theme->theme); } else { drupal_alter('alpha_page_structure', $vars, $theme->theme); } }
function bib2node($terms = array(), $batch = FALSE, $session_id = NULL, $save = TRUE, $start = 0, $limit = 0) { //list($preamble, $strings, $entries, $undefinedStrings) = $this->returnArrays(); $limit = $limit ? $limit : count($this->entries); if ($start + $limit > count($this->entries)) { $limit = count($this->entries) - $start; } for ($i = $start; $i < $limit; $i++) { $node = array(); $entry = $this->entries[$i]; if ($this->removeDelimit || $this->expandMacro && $this->fieldExtract) { foreach ($entry as $key => $value) { if ($key != 'bibtexCitation' && $key != 'bibtexEntryType') { $entry[$key] = trim($this->removeDelimitersAndExpand($entry[$key])); } } } // hook_biblio_bibtex_import_pre. Allows to define new or change // types, e.g. split @incollection from @book and put in a custom type. // We don't use module_invoke_all to enable passing by reference. foreach (module_implements('biblio_bibtex_import_pre') as $module) { $function = $module . '_biblio_bibtex_import_pre'; $function($entry, $node); } //foreach($entries as $entry){ $node['biblio_contributors'] = array(); $node['biblio_type'] = $this->bibtex_type_map($entry['bibtexEntryType']); switch ($entry['bibtexEntryType']) { case 'mastersthesis': $node['biblio_type_of_work'] = 'masters'; break; case 'phdthesis': $node['biblio_type_of_work'] = 'phd'; break; } if (!empty($entry['author'])) { // split on ' and ' $authorArray = preg_split("/\\s(and|&)\\s/i", trim($entry['author'])); foreach ($authorArray as $key => $author) { $node['biblio_contributors'][1][] = array('name' => $author, 'auth_type' => _biblio_get_auth_type(1, $node['biblio_type'])); } } $node['biblio_citekey'] = !empty($entry['bibtexCitation']) ? $entry['bibtexCitation'] : NULL; if (!empty($entry['editor'])) { $authorArray = preg_split("/\\s(and|&)\\s/i", trim($entry['editor'])); foreach ($authorArray as $key => $author) { $node['biblio_contributors'][2][] = array('name' => $author, 'auth_type' => _biblio_get_auth_type(2, $node['biblio_type'])); } } $node['biblio_secondary_title'] = !empty($entry['journal']) ? $entry['journal'] : NULL; if (!empty($entry['booktitle'])) { $node['biblio_secondary_title'] = $entry['booktitle']; } if (!empty($entry['series'])) { $node['biblio_tertiary_title'] = $entry['series']; } $node['biblio_volume'] = !empty($entry['volume']) ? $entry['volume'] : NULL; $node['biblio_number'] = !empty($entry['number']) ? $entry['number'] : NULL; $node['biblio_year'] = !empty($entry['year']) ? $entry['year'] : NULL; $node['biblio_notes'] = !empty($entry['note']) ? $entry['note'] : NULL; $node['biblio_date'] = !empty($entry['month']) ? $entry['month'] : NULL; $node['biblio_pages'] = !empty($entry['pages']) ? $entry['pages'] : NULL; $node['biblio_publisher'] = !empty($entry['publisher']) ? $entry['publisher'] : NULL; if (!empty($entry['organization'])) { $node['biblio_publisher'] = $entry['organization']; } if (!empty($entry['school'])) { $node['biblio_publisher'] = $entry['school']; } if (!empty($entry['institution'])) { $node['biblio_publisher'] = $entry['institution']; } $node['title'] = !empty($entry['title']) ? $entry['title'] : NULL; $node['biblio_type_of_work'] .= !empty($entry['type']) ? $entry['type'] : NULL; $node['biblio_edition'] = !empty($entry['edition']) ? $entry['edition'] : NULL; $node['biblio_section'] = !empty($entry['chapter']) ? $entry['chapter'] : NULL; $node['biblio_place_published'] = !empty($entry['address']) ? $entry['address'] : NULL; $node['biblio_abst_e'] = !empty($entry['abstract']) ? $entry['abstract'] : NULL; if (!empty($entry['keywords'])) { if (strpos($entry['keywords'], ';')) { $entry['keywords'] = str_replace(';', ',', $entry['keywords']); } $node['biblio_keywords'] = explode(',', $entry['keywords']); } $node['biblio_isbn'] = !empty($entry['isbn']) ? $entry['isbn'] : NULL; $node['biblio_issn'] = !empty($entry['issn']) ? $entry['issn'] : NULL; $node['biblio_url'] = !empty($entry['url']) ? $entry['url'] : NULL; $node['biblio_doi'] = !empty($entry['doi']) ? $entry['doi'] : NULL; if (!empty($terms)) { if (!isset($node['taxonomy'])) { $node['taxonomy'] = array(); } $node['taxonomy'] = array_merge($terms, $node['taxonomy']); } // Allow other modules to adjust the bibtex entries. Functions must // be named modulename_biblio_bibtex_import. foreach (module_implements('biblio_bibtex_import') as $module) { $function = $module . '_biblio_bibtex_import'; $function($entry, $node); } $nid = biblio_save_node($node, $batch, $session_id, $save); if (isset($nid)) { $nids[] = $nid; } } return !empty($nids) ? $nids : NULL; }
/** * Delete created files and temporary files directory, delete the tables created by setUp(), * and reset the database prefix. */ protected function tearDown() { global $user, $language; // In case a fatal error occurred that was not in the test process read the // log to pick up any fatal errors. simpletest_log_read($this->testId, $this->databasePrefix, get_class($this), TRUE); $emailCount = count(variable_get('drupal_test_email_collector', array())); if ($emailCount) { $message = format_plural($emailCount, '1 e-mail was sent during this test.', '@count e-mails were sent during this test.'); $this->pass($message, t('E-mail')); } // Delete temporary files directory. file_unmanaged_delete_recursive($this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10)); // Remove all prefixed tables (all the tables in the schema). $schema = drupal_get_schema(NULL, TRUE); foreach ($schema as $name => $table) { db_drop_table($name); } // Get back to the original connection. Database::removeConnection('default'); Database::renameConnection('simpletest_original_default', 'default'); // Restore original shutdown callbacks array to prevent original // environment of calling handlers from test run. $callbacks =& drupal_register_shutdown_function(); $callbacks = $this->originalShutdownCallbacks; // Return the user to the original one. $user = $this->originalUser; drupal_save_session(TRUE); // Ensure that internal logged in variable and cURL options are reset. $this->loggedInUser = FALSE; $this->additionalCurlOptions = array(); // Reload module list and implementations to ensure that test module hooks // aren't called after tests. module_list(TRUE); module_implements('', FALSE, TRUE); // Reset the Field API. field_cache_clear(); // Rebuild caches. $this->refreshVariables(); // Reset language. $language = $this->originalLanguage; if ($this->originalLanguageDefault) { $GLOBALS['conf']['language_default'] = $this->originalLanguageDefault; } // Close the CURL handler. $this->curlClose(); }
/** * Does something interesting, to test in-code linking. */ function sample_in_code_links() { // Should link to function. $foo = sample_function(); // Should link to theme function. $bar = theme('sample_one', $foo); // Should link to theme template, not function, though both exist. $baz = theme('sample_two', $foo); // Should link to theme template. $boo = theme('sample_three'); // Should link to the sample_four theme function. $bop = theme('sample_four__option', $foo); // Should link to hook. $x = module_invoke_all('sample_name', $foo, $baz); $stuff = ''; // Should link to hook. foreach (module_implements('sample_name') as $module) { // Should link to hook. Note that the variable name has to be $module for // this link to work. module_invoke($module, 'sample_name', $baz); } // Should link to alter hook. $xx = drupal_alter('another_sample', $foo); // Should link to search for this function. $z = duplicate_function(); // Should link to class. $j = new SubSample(); // Should link to constant. $k = SAMPLE_CONSTANT; // Should link to search for this constant. $l = DUPLICATE_CONSTANT; $menu = array('title' => 'A title goes here.', 'page callback' => 'sample_function'); // Functions that don't exist, so should not be linked, but // should still be visible. $a = nonexistent_function($a, $b); $b = module_invoke_all('nonexistent_hook', $foo); $c = theme('nonexistent_theme_hook', $foo); foreach (module_implements('nonexistent_hook') as $module) { module_invoke($module, 'nonexistent_hook', $foo); } $d = drupal_alter('nonexistent_alter_name', $foo); }
/** * Render the interior contents of a single pane. * * This method retrieves pane content and produces a ready-to-render content * object. It also manages pane-specific caching. * * @param stdClass $pane * A Panels pane object, as loaded from the database. * @return stdClass $content * A renderable object, containing a subject, content, etc. Based on the * renderable objects used by the block system. */ function render_pane_content(&$pane) { ctools_include('context'); // TODO finally safe to remove this check? if (!is_array($this->display->context)) { watchdog('panels', 'renderer::render_pane_content() hit with a non-array for the context', $this->display, WATCHDOG_DEBUG); $this->display->context = array(); } $caching = !empty($pane->cache['method']) && empty($this->display->skip_cache); if ($caching && ($cache = panels_get_cached_content($this->display, $this->display->args, $this->display->context, $pane))) { $content = $cache->content; } else { if ($caching) { // This is created before rendering so that calls to drupal_add_js // and drupal_add_css will be captured. $cache = new panels_cache_object(); } $content = ctools_content_render($pane->type, $pane->subtype, $pane->configuration, array(), $this->display->args, $this->display->context); foreach (module_implements('panels_pane_content_alter') as $module) { $function = $module . '_panels_pane_content_alter'; $function($content, $pane, $this->display->args, $this->display->context, $this, $this->display); } if ($caching && isset($cache)) { $cache->set_content($content); panels_set_cached_content($cache, $this->display, $this->display->args, $this->display->context, $pane); $content = $cache->content; } } // If there's content, check if we've css configuration to add. if (!empty($content)) { // Pass long the css_id that is usually available. if (!empty($pane->css['css_id'])) { $id = ctools_context_keyword_substitute($pane->css['css_id'], array(), $this->display->context); $content->css_id = drupal_html_id($id); } // Pass long the css_class that is usually available. if (!empty($pane->css['css_class'])) { $class = ctools_context_keyword_substitute($pane->css['css_class'], array(), $this->display->context, array('css safe' => TRUE)); $content->css_class = check_plain(drupal_strtolower($class)); } } return $content; }
/** * Delete created files and temporary files directory, delete the tables created by setUp(), * and reset the database prefix. */ protected function tearDown() { global $db_prefix, $user, $language; // In case a fatal error occured that was not in the test process read the // log to pick up any fatal errors. $db_prefix_temp = $db_prefix; $db_prefix = $this->originalPrefix; simpletest_log_read($this->testId, $db_prefix, get_class($this), TRUE); $db_prefix = $db_prefix_temp; $emailCount = count(variable_get('drupal_test_email_collector', array())); if ($emailCount) { $message = format_plural($emailCount, t('!count e-mail was sent during this test.'), t('!count e-mails were sent during this test.'), array('!count' => $emailCount)); $this->pass($message, t('E-mail')); } if (preg_match('/simpletest\\d+/', $db_prefix)) { // Delete temporary files directory. file_unmanaged_delete_recursive($this->originalFileDirectory . '/simpletest/' . substr($db_prefix, 10)); // Remove all prefixed tables (all the tables in the schema). $schema = drupal_get_schema(NULL, TRUE); $ret = array(); foreach ($schema as $name => $table) { db_drop_table($name); } // Return the database prefix to the original. $db_prefix = $this->originalPrefix; // Return the user to the original one. $user = $this->originalUser; drupal_save_session(TRUE); // Ensure that internal logged in variable and cURL options are reset. $this->loggedInUser = FALSE; $this->additionalCurlOptions = array(); // Reload module list and implementations to ensure that test module hooks // aren't called after tests. module_list(TRUE); module_implements('', FALSE, TRUE); // Reset the Field API. field_cache_clear(); // Rebuild caches. $this->refreshVariables(); // Reset language. $language = $this->originalLanguage; if ($this->originalLanguageDefault) { $GLOBALS['conf']['language_default'] = $this->originalLanguageDefault; } // Close the CURL handler. $this->curlClose(); } }
/** * Preprocessor for theme('help_page'). */ function rubik_preprocess_help_page(&$vars) { $vars['hook'] = 'help-page'; $vars['is_prose'] = TRUE; $vars['layout'] = TRUE; $vars['attr'] = array('class' => 'help-page clear-block'); // Truly hackish way to navigate help pages. $module_info = module_rebuild_cache(); $modules = array(); foreach (module_implements('help', TRUE) as $module) { if (module_invoke($module, 'help', "admin/help#{$module}", $empty_arg)) { $modules[$module] = $module_info[$module]->info['name']; } } asort($modules); $links = array(); foreach ($modules as $module => $name) { $links[] = array('title' => $name, 'href' => "admin/help/{$module}"); } $vars['links'] = theme('links', $links); }
/** * Preprocessor for theme('help_page'). */ function rubik_preprocess_help_page(&$vars) { $vars['hook'] = 'help-page'; $vars['title_attributes_array']['class'][] = 'help-page-title'; $vars['title_attributes_array']['class'][] = 'clearfix'; $vars['content_attributes_array']['class'][] = 'help-page-content'; $vars['content_attributes_array']['class'][] = 'clearfix'; $vars['content_attributes_array']['class'][] = 'prose'; $vars['layout'] = TRUE; // Truly hackish way to navigate help pages. $module_info = system_rebuild_module_data(); $modules = array(); foreach (module_implements('help', TRUE) as $module) { if (module_invoke($module, 'help', "admin/help#{$module}", NULL)) { $modules[$module] = $module_info[$module]->info['name']; } } asort($modules); $links = array(); foreach ($modules as $module => $name) { $links[] = array('title' => $name, 'href' => "admin/help/{$module}"); } $vars['links'] = theme('links', array('links' => $links)); }
public function entityFieldQueryAlter(SelectQueryInterface $query) { // Adding the 'comment_access' tag is sadly insufficient for comments: core // requires us to also know about the concept of 'published' and // 'unpublished'. if (!user_access('administer comments')) { $base_table = $this->ensureBaseTable($query); $query->condition("{$base_table}.status", COMMENT_PUBLISHED); } // The Comment module doesn't implement any proper comment access, // and as a consequence doesn't make sure that comments cannot be viewed // when the user doesn't have access to the node. $tables = $query->getTables(); $base_table = key($tables); $node_alias = $query->innerJoin('node', 'n', '%alias.nid = ' . $base_table . '.nid'); // Pass the query to the node access control. $this->reAlterQuery($query, 'node_access', $node_alias); // Alas, the comment entity exposes a bundle, but doesn't have a bundle column // in the database. We have to alter the query ourself to go fetch the // bundle. $conditions =& $query->conditions(); foreach ($conditions as $key => &$condition) { if ($key !== '#conjunction' && is_string($condition['field']) && $condition['field'] === 'node_type') { $condition['field'] = $node_alias . '.type'; foreach ($condition['value'] as &$value) { if (substr($value, 0, 13) == 'comment_node_') { $value = substr($value, 13); } } break; } } // Passing the query to node_query_node_access_alter() is sadly // insufficient for nodes. // @see EntityReferenceHandler_node::entityFieldQueryAlter() if (!user_access('bypass node access') && !count(module_implements('node_grants'))) { $query->condition($node_alias . '.status', 1); } }
drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION); // Only allow the requirements check to proceed if the current user has access // to run updates (since it may expose sensitive information about the site's // configuration). $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : ''; if (empty($op) && update_access_allowed()) { require_once DRUPAL_ROOT . '/includes/install.inc'; require_once DRUPAL_ROOT . '/modules/system/system.install'; // Load module basics. include_once DRUPAL_ROOT . '/includes/module.inc'; $module_list['system']['filename'] = 'modules/system/system.module'; module_list(TRUE, FALSE, FALSE, $module_list); drupal_load('module', 'system'); // Reset the module_implements() cache so that any new hook implementations // in updated code are picked up. module_implements('', FALSE, TRUE); // Set up $language, since the installer components require it. drupal_language_initialize(); // Set up theme system for the maintenance page. drupal_maintenance_theme(); // Check the update requirements for Drupal. update_check_requirements(); // Redirect to the update information page if all requirements were met. install_goto('update.php?op=info'); } // update_fix_d7_requirements() needs to run before bootstrapping beyond path. // So bootstrap to DRUPAL_BOOTSTRAP_LANGUAGE then include unicode.inc. drupal_bootstrap(DRUPAL_BOOTSTRAP_LANGUAGE); include_once DRUPAL_ROOT . '/includes/unicode.inc'; update_fix_d7_requirements(); // Now proceed with a full bootstrap.