コード例 #1
0
 public function getManagedTargets($as_detailed_objects = FALSE)
 {
     lingotek_add_missing_locales();
     // fills in any missing lingotek_locale values to the languages table
     $targets_drupal = language_list();
     $default_language = language_default();
     $targets = array();
     foreach ($targets_drupal as $key => $target) {
         $is_source = $default_language->language == $target->language;
         $is_lingotek_managed = $target->lingotek_enabled;
         if ($is_source) {
             continue;
             // skip, since the source language is not a target
         } else {
             if (!$is_lingotek_managed) {
                 continue;
                 // skip, since lingotek is not managing the language
             }
         }
         $target->active = $target->lingotek_enabled;
         $targets[$key] = $target;
     }
     $result = $as_detailed_objects ? $targets : array_map(create_function('$obj', 'return $obj->lingotek_locale;'), $targets);
     return $result;
 }
 protected function setUp()
 {
     parent::setUp();
     // Set up an additional language.
     $this->langcodes = array(language_default()->getId(), 'es');
     ConfigurableLanguage::createFromLangcode('es')->save();
     // Create a content type.
     $this->bundle = $this->randomMachineName();
     $this->contentType = $this->drupalCreateContentType(array('type' => $this->bundle));
     // Enable translation for the current entity type and ensure the change is
     // picked up.
     content_translation_set_config('node', $this->bundle, 'enabled', TRUE);
     drupal_static_reset();
     \Drupal::entityManager()->clearCachedBundles();
     \Drupal::service('router.builder')->rebuild();
     // Add a translatable field to the content type.
     entity_create('field_storage_config', array('field_name' => 'field_test_text', 'entity_type' => 'node', 'type' => 'text', 'cardinality' => 1, 'translatable' => TRUE))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_text', 'bundle' => $this->bundle, 'label' => 'Test text-field'))->save();
     entity_get_form_display('node', $this->bundle, 'default')->setComponent('field_test_text', array('type' => 'text_textfield', 'weight' => 0))->save();
     // Enable content translation.
     $configuration = array('langcode' => language_default()->getId(), 'language_show' => TRUE);
     language_save_default_configuration('node', $this->bundle, $configuration);
     // Create a translator user.
     $permissions = array('access contextual links', 'administer nodes', "edit any {$this->bundle} content", 'translate any entity');
     $this->translator = $this->drupalCreateUser($permissions);
 }
コード例 #3
0
ファイル: cron.php プロジェクト: vishacc/libyanwarthetruth
function libya_cron_subscription_mail($data)
{
    // subscription node
    $mail = $data[0];
    $nids = $data[1];
    // watchdog('actions', 'Cron subscription vars', func_get_args());
    global $siteName, $isMail, $base_url;
    $isMail = TRUE;
    $body = '<h1 style="font-size:1.25em;">Your alert subscription results from ' . $siteName . '</h1>
	<p class="no-margin">The following results match your subscription alert.</p>';
    foreach ($nids as $nid) {
        $N = node_load($nid);
        $content = strip_tags($N->body['und'][0]['value']);
        if (strlen($content) > 200) {
            $content = substr($content, 0, 200);
        }
        $CL = strrpos($content, ' ');
        $content = substr($content, 0, $CL) . '...';
        $body .= '<h2 style="font-size:1.25em;">' . l($N->title, 'node/' . $N->nid, array('attributes' => array('style' => array('text-decoration' => 'none')))) . '</h2><p>' . $content . '</p>
		<p>' . t('read more: ') . l($base_url . '/' . drupal_lookup_path('alias', 'node/' . $N->nid), 'node/' . $N->nid, array('absolute' => TRUE)) . '</p>
		<hr/>';
    }
    $data['message'] = 'Mail sent';
    $to = $mail['mail'];
    $from = variable_get('site_mail', '*****@*****.**');
    $params = array('body' => $body, 'rand' => $mail['rand'], 'to' => $to);
    $sent = drupal_mail('libya', 'subscription_alert_mail', $to, language_default(), $params, $from, TRUE);
}
コード例 #4
0
function emailCollaborators($new_ids, $node)
{
    $query = db_select('users', 'u')->condition('uid', $new_ids)->fields('u', array('name', 'mail'));
    $result = $query->execute();
    foreach ($result as $row) {
        $options = array('absolute' => TRUE);
        $jobPath = url('node/' . $node->nid, $options);
        $jobTitle = $node->title;
        global $user;
        $inviter = $user->name;
        $module = 'tap_job_invite';
        $key = 'key';
        $email = $row->mail;
        $language = language_default();
        $params = array();
        $from = NULL;
        $send = FALSE;
        $message = drupal_mail($module, $key, $email, $language, $params, $from, $send);
        $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
        $message['subject'] = "Collaborator invitation at Tap";
        $message['body'] = array();
        $message['body'][] = "You have invited as a Collaborator by {$inviter} to the job <a href=\"{$jobPath}\">{$jobTitle}</a>. ";
        $message['body'][] = "Log in to join the workroom.";
        // Retrieve the responsible implementation for this message.
        $system = drupal_mail_system($module, $key);
        // Format the message body.
        $message = $system->format($message);
        // Send e-mail.
        $message['result'] = $system->mail($message);
    }
}
コード例 #5
0
 /**
  * Override parent deliver() function.
  */
 public function deliver(array $output = array())
 {
     $plugin = $this->plugin;
     $message = $this->message;
     $options = $plugin['options'];
     $account = user_load($message->uid);
     $mail = !empty($options['mail']) ? $options['mail'] : $account->mail;
     $languages = language_list();
     if (!$options['language override']) {
         $lang = !empty($account->language) && $account->language != LANGUAGE_NONE ? $languages[$account->language] : language_default();
     } else {
         $lang = $languages[$message->language];
     }
     // The subject in an email can't be with HTML, so strip it.
     $output['message_notify_email_subject'] = strip_tags($output['message_notify_email_subject']);
     // Allow for overriding the 'from' of the message.
     $from = isset($options['from']) ? $options['from'] : NULL;
     $from_account = !empty($message->user->uid) ? user_load($message->user->uid) : $account;
     $mimemail_name = variable_get('mimemail_name', t('Atrium'));
     $from = array('name' => oa_core_realname($from_account) . ' (' . $mimemail_name . ')', 'mail' => is_array($from) ? $from['mail'] : $from);
     // Pass the message entity along to hook_drupal_mail().
     $output['message_entity'] = $message;
     if (!empty($message->email_attachments)) {
         $output['attachments'] = isset($output['attachments']) ? $output['attachments'] : array();
         $output['attachments'] = array_merge($message->email_attachments, $output['attachments']);
     }
     return drupal_mail('message_notify', $message->type, $mail, $lang, $output, $from);
 }
コード例 #6
0
ファイル: DbIssue.class.php プロジェクト: chgk/db.chgk.info
 public function mailStatusUpdate($status, $attached)
 {
     $mail = $this->node->field_email[0]['value'];
     $v['subject'] = 'Ваше замечание обработано';
     $v['body'] = "Добрый день!\n\n";
     $v['body'] .= "Вы писали нам про ошибку в вопросе %1\$s. ";
     if ($status == 'resolved') {
         $v['body'] .= "Эта ошибка исправлена. В течение 24 часов изменения будут отображены.\n\n";
     } elseif ($status == 'accepted') {
         $v['body'] .= "Мы признаём эту ошибку. \n\n";
     } elseif ($status == 'rejected') {
         $v['body'] .= "\n\nНам кажется, что этой ошибки в вопросе нет (или ваше сообщение не было сообщением об ошибке).\n\n";
     }
     if ($attached) {
         $v['body'] .= 'Ваше замечание прикреплено к вопросу.' . "\n\n";
     }
     $v['body'] .= "Постоянный адрес вашего сообщения -- %2\$s.";
     if ($this->oldnode->comment_count) {
         $v['body'] .= " По этому адресу вы можете прочитать комментарии";
     }
     $v['body'] .= "\n\nСпасибо!\n\n-- \nРоман Семизаров\n";
     $q = $this->getQuestion();
     $v['body'] = sprintf($v['body'], $q->getAbsoluteQuestionUrl(), url('node/' . $this->node->nid, array('absolute' => TRUE)));
     drupal_mail('chgk_db', 'issue_status_updated', $mail, language_default(), $v);
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function getDefaultOperations(EntityInterface $entity)
 {
     $operations = parent::getDefaultOperations($entity);
     $default = language_default();
     // Deleting the site default language is not allowed.
     if ($entity->id() == $default->id) {
         unset($operations['delete']);
     }
     return $operations;
 }
コード例 #8
0
 /**
  * verifica se a linguagem esta habilitada, se não retorna padrão (ingles)
  * @param string $lang - Codigo de linguagem
  * @return Ambiguous <multitype: array/object, boolean>
  */
 function ListLanguages($lang)
 {
     $result = $this->SqlSelect("SELECT * From {languages} WHERE language = '{$lang}' AND enabled = '1' ORDER BY weight, name ASC");
     if (mysql_numrows($result) < 1) {
         return language_default();
     }
     $row = NULL;
     while ($row = mysql_fetch_object($result)) {
         $languages = $row;
     }
     return $languages;
 }
コード例 #9
0
 /**
  * Constructor.
  *
  * This is private since we want consumers to instantiate via the factory methods.
  *
  * @param $set_id
  *   A Config Set ID.
  */
 private function __construct($set_id = NULL)
 {
     $this->sid = $set_id;
     $this->set_size = LINGOTEK_CONFIG_SET_SIZE;
     $this->source_data = self::getAllSegments($this->sid);
     $this->source_meta = self::getSetMeta($this->sid);
     $this->language = language_default();
     if (!isset($this->language->lingotek_locale)) {
         // if Drupal variable 'language_default' does not exist
         $this->language->lingotek_locale = Lingotek::convertDrupal2Lingotek($this->language->language);
     }
     $this->language_targets = Lingotek::getLanguagesWithoutSource($this->language->lingotek_locale);
 }
コード例 #10
0
 /**
  * Constructor.
  *
  * This is private since we want consumers to instantiate via the factory methods.
  *
  * @param $chunk_id
  *   A Config Chunk ID.
  */
 private function __construct($chunk_id = NULL)
 {
     $this->cid = $chunk_id;
     $this->chunk_size = LINGOTEK_CONFIG_CHUNK_SIZE;
     $this->source_data = self::getAllSegments($this->cid);
     $this->source_meta = self::getChunkMeta($this->cid);
     $this->language = language_default();
     if (!isset($this->language->lingotek_locale)) {
         // if Drupal variable 'language_default' does not exist
         $this->language->lingotek_locale = Lingotek::convertDrupal2Lingotek($this->language->language);
     }
     $this->language_targets = Lingotek::getLanguagesWithoutSource($this->language->lingotek_locale);
     $this->min_lid = $this->getMinLid();
     $this->max_lid = $this->getMaxLid();
 }
コード例 #11
0
ファイル: LanguageDeleteForm.php プロジェクト: shumer/blog
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, array &$form_state)
 {
     $langcode = $this->entity->id();
     // Warn and redirect user when attempting to delete the default language.
     if (language_default()->id == $langcode) {
         drupal_set_message($this->t('The default language cannot be deleted.'));
         $url = $this->urlGenerator->generateFromPath('admin/config/regional/language', array('absolute' => TRUE));
         return new RedirectResponse($url);
     }
     // Throw a 404 when attempting to delete a non-existing language.
     $languages = language_list();
     if (!isset($languages[$langcode])) {
         throw new NotFoundHttpException();
     }
     return parent::buildForm($form, $form_state);
 }
コード例 #12
0
 /**
  * {@inheritdoc}
  */
 protected function renderLink($data, ResultRow $values)
 {
     if (!empty($this->options['link_to_user'])) {
         $uid = $this->getValue($values, 'uid');
         if ($this->view->getUser()->hasPermission('access user profiles') && $uid) {
             $this->options['alter']['make_link'] = TRUE;
             $this->options['alter']['path'] = 'user/' . $uid;
         }
     }
     if (empty($data)) {
         $lang = language_default();
     } else {
         $lang = language_list();
         $lang = $lang[$data];
     }
     return $this->sanitizeValue($lang->getName());
 }
コード例 #13
0
 public function alterItems(array &$items)
 {
     // Prevent session information from being saved while indexing.
     drupal_save_session(FALSE);
     // Force the current user to anonymous to prevent access bypass in search
     // indexes.
     $original_user = $GLOBALS['user'];
     $GLOBALS['user'] = drupal_anonymous_user();
     $entity_type = $this->index->getEntityType();
     $entity_handler = panelizer_entity_plugin_get_handler($entity_type);
     foreach ($items as &$item) {
         $entity_id = entity_id($entity_type, $item);
         $item->search_api_panelizer_content = NULL;
         $item->search_api_panelizer_title = NULL;
         // If Search API specifies a language to view the item in, force the
         // global language_content to be Search API item language. Fieldable
         // panel panes will render in the correct language.
         if (isset($item->search_api_language)) {
             global $language_content;
             $original_language_content = $language_content;
             $languages = language_list();
             if (isset($languages[$item->search_api_language])) {
                 $language_content = $languages[$item->search_api_language];
             } else {
                 $language_content = language_default();
             }
         }
         try {
             if ($render_info = $entity_handler->render_entity($item, 'page_manager')) {
                 $item->search_api_panelizer_content = $render_info['content'];
                 $item->search_api_panelizer_title = !empty($render_info['title']) ? $render_info['title'] : NULL;
             }
         } catch (Exception $e) {
             watchdog_exception('panelizer', $e, 'Error indexing Panelizer content for %entity_type with ID %entity_id', array('%entity_type' => $entity_type, '%entity_id' => $entity_id));
         }
         // Restore the language_content global if it was overridden.
         if (isset($original_language_content)) {
             $language_content = $original_language_content;
         }
     }
     // Restore the user.
     $GLOBALS['user'] = $original_user;
     drupal_save_session(TRUE);
 }
コード例 #14
0
 public function deliver(array $output = array())
 {
     $plugin = $this->plugin;
     $message = $this->message;
     $options = $plugin['options'];
     $account = user_load($message->uid);
     $mail = $options['mail'] ? $options['mail'] : $account->mail;
     $languages = language_list();
     if (!$options['language override']) {
         $lang = !empty($account->language) && $account->language != LANGUAGE_NONE ? $languages[$account->language] : language_default();
     } else {
         $lang = $languages[$message->language];
     }
     // The subject in an email can't be with HTML, so strip it.
     $output['message_notify_email_subject'] = strip_tags($output['message_notify_email_subject']);
     // Pass the message entity along to hook_drupal_mail().
     $output['message_entity'] = $message;
     return drupal_mail('message_notify', $message->type, $mail, $lang, $output);
 }
コード例 #15
0
ファイル: EmailAction.php プロジェクト: alnutile/drunatra
 /**
  * {@inheritdoc}
  */
 public function execute($entity = NULL)
 {
     if (empty($this->configuration['node'])) {
         $this->configuration['node'] = $entity;
     }
     $recipient = $this->token->replace($this->configuration['recipient'], $this->configuration);
     // If the recipient is a registered user with a language preference, use
     // the recipient's preferred language. Otherwise, use the system default
     // language.
     $recipient_accounts = $this->storage->loadByProperties(array('mail' => $recipient));
     $recipient_account = reset($recipient_accounts);
     if ($recipient_account) {
         $langcode = $recipient_account->getPreferredLangcode();
     } else {
         $langcode = language_default()->id;
     }
     $params = array('context' => $this->configuration);
     if (drupal_mail('system', 'action_send_email', $recipient, $langcode, $params)) {
         watchdog('action', 'Sent email to %recipient', array('%recipient' => $recipient));
     } else {
         watchdog('error', 'Unable to send email to %recipient', array('%recipient' => $recipient));
     }
 }
コード例 #16
0
 /**
  * Generates a random database prefix, runs the install scripts on the
  * prefixed database and enable the specified modules. After installation
  * many caches are flushed and the internal browser is setup so that the
  * page requests will run on the new prefix. A temporary files directory
  * is created with the same name as the database prefix.
  *
  * @param ...
  *   List of modules to enable for the duration of the test.
  */
 protected function setUp()
 {
     global $db_prefix, $user, $language;
     // Store necessary current values before switching to prefixed database.
     $this->originalLanguage = $language;
     $this->originalLanguageDefault = variable_get('language_default');
     $this->originalPrefix = $db_prefix;
     $this->originalFileDirectory = file_directory_path();
     $this->originalProfile = drupal_get_profile();
     $clean_url_original = variable_get('clean_url', 0);
     // Generate temporary prefixed database to ensure that tests have a clean starting point.
     $db_prefix_new = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}');
     db_update('simpletest_test_id')->fields(array('last_prefix' => $db_prefix_new))->condition('test_id', $this->testId)->execute();
     $db_prefix = $db_prefix_new;
     // Create test directory ahead of installation so fatal errors and debug
     // information can be logged during installation process.
     // Use temporary files directory with the same prefix as the database.
     $public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($db_prefix, 10);
     $private_files_directory = $public_files_directory . '/private';
     $temp_files_directory = $private_files_directory . '/temp';
     // Create the directories
     file_prepare_directory($public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
     file_prepare_directory($private_files_directory, FILE_CREATE_DIRECTORY);
     file_prepare_directory($temp_files_directory, FILE_CREATE_DIRECTORY);
     $this->generatedTestFiles = FALSE;
     // Log fatal errors.
     ini_set('log_errors', 1);
     ini_set('error_log', $public_files_directory . '/error.log');
     // Reset all statics so that test is performed with a clean environment.
     drupal_static_reset();
     include_once DRUPAL_ROOT . '/includes/install.inc';
     drupal_install_system();
     $this->preloadRegistry();
     // Include the default profile
     variable_set('install_profile', 'standard');
     $profile_details = install_profile_info('standard', 'en');
     // Install the modules specified by the default profile.
     drupal_install_modules($profile_details['dependencies'], TRUE);
     drupal_static_reset('_node_types_build');
     if ($modules = func_get_args()) {
         // Install modules needed for this test.
         drupal_install_modules($modules, TRUE);
     }
     // Because the schema is static cached, we need to flush
     // it between each run. If we don't, then it will contain
     // stale data for the previous run's database prefix and all
     // calls to it will fail.
     drupal_get_schema(NULL, TRUE);
     // Run default profile tasks.
     $install_state = array();
     drupal_install_modules(array('standard'), TRUE);
     // Rebuild caches.
     node_types_rebuild();
     actions_synchronize();
     _drupal_flush_css_js();
     $this->refreshVariables();
     $this->checkPermissions(array(), TRUE);
     // Log in with a clean $user.
     $this->originalUser = $user;
     drupal_save_session(FALSE);
     $user = user_load(1);
     // Restore necessary variables.
     variable_set('install_task', 'done');
     variable_set('clean_url', $clean_url_original);
     variable_set('site_mail', '*****@*****.**');
     // Set up English language.
     unset($GLOBALS['conf']['language_default']);
     $language = language_default();
     // Set path variables
     variable_set('file_public_path', $public_files_directory);
     variable_set('file_private_path', $private_files_directory);
     variable_set('file_temporary_path', $temp_files_directory);
     // Use the test mail class instead of the default mail handler class.
     variable_set('mail_system', array('default-system' => 'TestingMailSystem'));
     drupal_set_time_limit($this->timeLimit);
 }
コード例 #17
0
 /**
  * Sets up a Backdrop site for running functional and integration tests.
  *
  * Generates a random database prefix and installs Backdrop with the specified
  * installation profile in BackdropWebTestCase::$profile into the
  * prefixed database. Afterwards, installs any additional modules specified by
  * the test.
  *
  * After installation all caches are flushed and several configuration values
  * are reset to the values of the parent site executing the test, since the
  * default values may be incompatible with the environment in which tests are
  * being executed.
  *
  * @param ...
  *   List of modules to enable for the duration of the test. This can be
  *   either a single array or a variable number of string arguments.
  *
  * @see BackdropWebTestCase::prepareDatabasePrefix()
  * @see BackdropWebTestCase::changeDatabasePrefix()
  * @see BackdropWebTestCase::prepareEnvironment()
  */
 protected function setUp()
 {
     global $user, $language, $conf;
     // Create the database prefix for this test.
     $this->prepareDatabasePrefix();
     // Prepare the environment for running tests.
     $this->prepareEnvironment();
     if (!$this->setupEnvironment) {
         return FALSE;
     }
     // Reset all statics and variables to perform tests in a clean environment.
     $conf = array();
     backdrop_static_reset();
     // Change the database prefix.
     // All static variables need to be reset before the database prefix is
     // changed, since BackdropCacheArray implementations attempt to
     // write back to persistent caches when they are destructed.
     $this->changeDatabasePrefix();
     if (!$this->setupDatabasePrefix) {
         return FALSE;
     }
     // Preset the 'install_profile' system variable, so the first call into
     // system_rebuild_module_data() (in backdrop_install_system()) will register
     // the test's profile as a module. Without this, the installation profile of
     // the parent site (executing the test) is registered, and the test
     // profile's hook_install() and other hook implementations are never invoked.
     config_install_default_config('system');
     config_set('system.core', 'install_profile', $this->profile);
     // Perform the actual Backdrop installation.
     include_once BACKDROP_ROOT . '/core/includes/install.inc';
     backdrop_install_system();
     // Set path variables.
     $core_config = config('system.core');
     $core_config->set('file_default_scheme', 'public');
     $core_config->set('file_public_path', $this->public_files_directory);
     $core_config->set('file_private_path', $this->private_files_directory);
     $core_config->set('file_temporary_path', $this->temp_files_directory);
     $core_config->save();
     // Set 'parent_profile' of simpletest to add the parent profile's
     // search path to the child site's search paths.
     // @see backdrop_system_listing()
     // @todo This may need to be primed like 'install_profile' above.
     config_set('simpletest.settings', 'parent_profile', $this->originalProfile);
     // Ensure schema versions are recalculated.
     backdrop_static_reset('backdrop_get_schema_versions');
     // Include the testing profile.
     config_set('system.core', 'install_profile', $this->profile);
     $profile_details = install_profile_info($this->profile, 'en');
     // Install the modules specified by the testing profile.
     module_enable($profile_details['dependencies'], FALSE);
     // Install modules needed for this test. This could have been passed in as
     // either a single array argument or a variable number of string arguments.
     // @todo Remove this compatibility layer and only accept a single array.
     $modules = func_get_args();
     if (isset($modules[0]) && is_array($modules[0])) {
         $modules = $modules[0];
     }
     if ($modules) {
         $success = module_enable($modules, TRUE);
         $this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
     }
     // Run the profile tasks.
     $install_profile_module_exists = db_query("SELECT 1 FROM {system} WHERE type = 'module' AND name = :name", array(':name' => $this->profile))->fetchField();
     if ($install_profile_module_exists) {
         module_enable(array($this->profile), FALSE);
     }
     // Reset/rebuild all data structures after enabling the modules.
     $this->resetAll();
     // Run cron once in that environment, as install.php does at the end of
     // the installation process.
     backdrop_cron_run();
     // Ensure that the session is not written to the new environment and replace
     // the global $user session with uid 1 from the new test site.
     backdrop_save_session(FALSE);
     // Login as uid 1.
     $user = user_load(1);
     // Restore necessary variables.
     state_set('install_task', 'done');
     config_set('system.core', 'clean_url', $this->originalCleanUrl);
     config_set('system.core', 'site_mail', '*****@*****.**');
     config_set('system.date', 'date_default_timezone', date_default_timezone_get());
     backdrop_static_reset('url');
     // Set up English language.
     unset($conf['language_default']);
     $language = language_default();
     // Use the test mail class instead of the default mail handler class.
     config_set('system.mail', 'default-system', 'TestingMailSystem');
     backdrop_set_time_limit($this->timeLimit);
     $this->setup = TRUE;
 }
コード例 #18
0
ファイル: forms.php プロジェクト: vishacc/libyanwarthetruth
function subscribeSendMail($data)
{
    $to = $data['mail'];
    $from = variable_get('site_mail', '*****@*****.**');
    $params = array('rand' => $data['rand']);
    $sent = drupal_mail('libya', 'subscription_mail', $to, language_default(), $params, $from, TRUE);
}
コード例 #19
0
ファイル: template.php プロジェクト: rollinsb1010/bbcom
function bbcom_theme_premium_body($node)
{
    // Hack to allow 'content' to still work with the reader when it's being hidden via 'premium_content'
    if ($node->type == 'content' && module_exists('lingwo_korpus')) {
        $node_language = $node->language ? $node->language : language_default();
        $teaser = lingwo_korpus_filter_text($node->teaser, $node_language, $node->nid . ':teaser');
    } else {
        $teaser = check_markup($node->teaser, $node->format, FALSE);
    }
    /**
     * Copied from uc_premium_access!
     */
    $html = $teaser;
    $html .= '<div class="premium-message">';
    // TODO: this should probably be optional!
    $html .= '<div class="premium-message-text">';
    $html .= check_markup(t($node->premium_level['denied_message']), $node->premium_level['denied_message_format'], FALSE);
    $html .= '</div>';
    if (module_exists('uc_premium_access')) {
        $products = uc_premium_access_products($node);
        if (!empty($products)) {
            $html .= theme('uc_premium_access_product_list', $products, $node);
        }
    }
    $html .= '</div>';
    return $html;
}
<?php

/**
 * @file
 * Overriding the default simple view template to display the list of rows as an interactive Map
 *
 * @ingroup views_templates
 */
$results = $view->result;
// https://www.drupal.org/node/277675
global $language;
// current selected language
$current_language = $language->language;
$default_language = language_default()->language;
$url_language_prefix = $current_language != $default_language ? "/{$current_language}" : "";
$all_countries = countries_get_countries('all', array('enabled' => COUNTRIES_ENABLED));
// list of European Union member states along with their data
$eu_countries = array();
$eu_countries_with_data_count = 0;
// $key is the country iso2 code
foreach ($all_countries as $key => $country) {
    $identifier = $key;
    // county is in Europe
    if ($country->continent == 'EU') {
        // country is member state of the European Union
        if (count($country->field_eu_country_code)) {
            $i18n_country_name = countries_t($country, "name", $current_language);
            // http://publications.europa.eu/code/en/en-370100.htm
            // EU country code is different from iso2 code in case of Greece (EL instead of GR) and United Kingdom (UK instead of GB)
            $identifier = $country->field_eu_country_code[LANGUAGE_NONE][0]['value'];
            // a sanitized version of the country name is used in the country profile url
コード例 #21
0
ファイル: EntityForm.php プロジェクト: anatalsceo/en-classe
 /**
  * Returns the actual form array to be built.
  *
  * @see \Drupal\Core\Entity\EntityForm::build()
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $entity = $this->entity;
     // Add a process callback.
     $form['#process'][] = array($this, 'processForm');
     if (!isset($form['langcode'])) {
         // If the form did not specify otherwise, default to keeping the existing
         // language of the entity or defaulting to the site default language for
         // new entities.
         $form['langcode'] = array('#type' => 'value', '#value' => !$entity->isNew() ? $entity->language()->id : language_default()->id);
     }
     return $form;
 }
コード例 #22
0
ファイル: template.php プロジェクト: nivaria/casasrealprod
/**
 * Override or insert variables into the maintenance page template.
 */
function casasrealprod_process_maintenance_page(&$variables)
{
    // Always print the site name and slogan, but if they are toggled off, we'll
    // just hide them visually.
    $variables['hide_site_name'] = theme_get_setting('toggle_name') ? FALSE : TRUE;
    $variables['hide_site_slogan'] = theme_get_setting('toggle_slogan') ? FALSE : TRUE;
    if ($variables['hide_site_name']) {
        // If toggle_name is FALSE, the site_name will be empty, so we rebuild it.
        $variables['site_name'] = filter_xss_admin(variable_get('site_name', 'Drupal'));
    }
    if ($variables['hide_site_slogan']) {
        // If toggle_site_slogan is FALSE, the site_slogan will be empty, so we rebuild it.
        $variables['site_slogan'] = filter_xss_admin(variable_get('site_slogan', ''));
    }
    //fgc
    // set the default language if necessary
    $language = isset($GLOBALS['language']) ? $GLOBALS['language'] : language_default();
    $variables['head_title_array'] = $head_title;
    $variables['head_title'] = implode(' | ', $head_title);
    $variables['base_path'] = base_path();
    $variables['front_page'] = url();
    $variables['breadcrumb'] = 'uiuui';
    $variables['feed_icons'] = '';
    $variables['help'] = '';
    $variables['language'] = $language;
    $variables['language']->dir = $language->direction ? 'rtl' : 'ltr';
    $variables['logo'] = theme_get_setting('logo');
    $variables['messages'] = $variables['show_messages'] ? theme('status_messages') : '';
    $variables['main_menu'] = array();
    $variables['secondary_menu'] = array();
    $variables['site_name'] = theme_get_setting('toggle_name') ? variable_get('site_name', 'Drupal') : '';
    $variables['site_slogan'] = theme_get_setting('toggle_slogan') ? variable_get('site_slogan', '') : '';
    $variables['tabs'] = '';
    $variables['title'] = drupal_get_title();
}
コード例 #23
0
 /**
  * Generates a random database prefix, runs the install scripts on the
  * prefixed database and enable the specified modules. After installation
  * many caches are flushed and the internal browser is setup so that the
  * page requests will run on the new prefix. A temporary files directory
  * is created with the same name as the database prefix.
  *
  * @param ...
  *   List of modules to enable for the duration of the test. This can be
  *   either a single array or a variable number of string arguments.
  */
 protected function setUp()
 {
     global $user, $language, $conf;
     // Generate a temporary prefixed database to ensure that tests have a clean starting point.
     $this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000);
     db_update('simpletest_test_id')->fields(array('last_prefix' => $this->databasePrefix))->condition('test_id', $this->testId)->execute();
     // Clone the current connection and replace the current prefix.
     $connection_info = Database::getConnectionInfo('default');
     Database::renameConnection('default', 'simpletest_original_default');
     foreach ($connection_info as $target => $value) {
         $connection_info[$target]['prefix'] = array('default' => $value['prefix']['default'] . $this->databasePrefix);
     }
     Database::addConnectionInfo('default', 'default', $connection_info['default']);
     // Store necessary current values before switching to prefixed database.
     $this->originalLanguage = $language;
     $this->originalLanguageDefault = variable_get('language_default');
     $this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');
     $this->originalProfile = drupal_get_profile();
     $clean_url_original = variable_get('clean_url', 0);
     // Set to English to prevent exceptions from utf8_truncate() from t()
     // during install if the current language is not 'en'.
     // The following array/object conversion is copied from language_default().
     $language = (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => '');
     // Save and clean shutdown callbacks array because it static cached and
     // will be changed by the test run. If we don't, then it will contain
     // callbacks from both environments. So testing environment will try
     // to call handlers from original environment.
     $callbacks =& drupal_register_shutdown_function();
     $this->originalShutdownCallbacks = $callbacks;
     $callbacks = array();
     // Create test directory ahead of installation so fatal errors and debug
     // information can be logged during installation process.
     // Use temporary files directory with the same prefix as the database.
     $public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10);
     $private_files_directory = $public_files_directory . '/private';
     $temp_files_directory = $private_files_directory . '/temp';
     // Create the directories
     file_prepare_directory($public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
     file_prepare_directory($private_files_directory, FILE_CREATE_DIRECTORY);
     file_prepare_directory($temp_files_directory, FILE_CREATE_DIRECTORY);
     $this->generatedTestFiles = FALSE;
     // Log fatal errors.
     ini_set('log_errors', 1);
     ini_set('error_log', $public_files_directory . '/error.log');
     // Reset all statics and variables to perform tests in a clean environment.
     $conf = array();
     drupal_static_reset();
     // Set the test information for use in other parts of Drupal.
     $test_info =& $GLOBALS['drupal_test_info'];
     $test_info['test_run_id'] = $this->databasePrefix;
     $test_info['in_child_site'] = FALSE;
     include_once DRUPAL_ROOT . '/includes/install.inc';
     drupal_install_system();
     $this->preloadRegistry();
     // Set path variables.
     variable_set('file_public_path', $public_files_directory);
     variable_set('file_private_path', $private_files_directory);
     variable_set('file_temporary_path', $temp_files_directory);
     // Include the testing profile.
     variable_set('install_profile', $this->profile);
     $profile_details = install_profile_info($this->profile, 'en');
     // Install the modules specified by the testing profile.
     module_enable($profile_details['dependencies'], FALSE);
     // Install modules needed for this test. This could have been passed in as
     // either a single array argument or a variable number of string arguments.
     // @todo Remove this compatibility layer in Drupal 8, and only accept
     // $modules as a single array argument.
     $modules = func_get_args();
     if (isset($modules[0]) && is_array($modules[0])) {
         $modules = $modules[0];
     }
     if ($modules) {
         $success = module_enable($modules, TRUE);
         $this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
     }
     // Run the profile tasks.
     $install_profile_module_exists = db_query("SELECT 1 FROM {system} WHERE type = 'module' AND name = :name", array(':name' => $this->profile))->fetchField();
     if ($install_profile_module_exists) {
         module_enable(array($this->profile), FALSE);
     }
     // Reset/rebuild all data structures after enabling the modules.
     $this->resetAll();
     // Run cron once in that environment, as install.php does at the end of
     // the installation process.
     drupal_cron_run();
     // Log in with a clean $user.
     $this->originalUser = $user;
     drupal_save_session(FALSE);
     $user = user_load(1);
     // Restore necessary variables.
     variable_set('install_task', 'done');
     variable_set('clean_url', $clean_url_original);
     variable_set('site_mail', '*****@*****.**');
     variable_set('date_default_timezone', date_default_timezone_get());
     // Set up English language.
     unset($GLOBALS['conf']['language_default']);
     $language = language_default();
     // Use the test mail class instead of the default mail handler class.
     variable_set('mail_system', array('default-system' => 'TestingMailSystem'));
     drupal_set_time_limit($this->timeLimit);
 }
コード例 #24
0
/**
 * Performs replacements in the query before being performed.
 *
 * @param $view
 *   The View being executed.
 * @return
 *   An array with keys being the strings to replace, and the values the strings
 *   to replace them with. The strings to replace are ofted surrounded with
 *   '***', as illustrated in the example implementation.
 */
function hook_views_query_substitutions($view)
{
    // Example from views_views_query_substitutions().
    global $language_content;
    return array('***CURRENT_VERSION***' => VERSION, '***CURRENT_TIME***' => REQUEST_TIME, '***CURRENT_LANGUAGE***' => $language_content->language, '***DEFAULT_LANGUAGE***' => language_default('language'));
}
コード例 #25
0
function filedepotAjaxServer_broadcastAlert($fid, $comment)
{
    global $user;
    $retval = '';
    $target_users = filedepot_build_notification_distribution($fid, FILEDEPOT_BROADCAST_MESSAGE);
    if (count($target_users) > 0) {
        $values = array('fid' => $fid, 'comment' => filter_xss($comment), 'target_users' => $target_users);
        $ret = drupal_mail('filedepot', FILEDEPOT_BROADCAST_MESSAGE, $user, language_default(), $values);
        if ($ret) {
            $filedepot = filedepot_filedepot();
            $retval['retcode'] = 200;
            $retval['count'] = $filedepot->message;
        } else {
            $retval['retcode'] = 205;
        }
    } else {
        $retval['retcode'] = 205;
    }
    return $retval;
}
コード例 #26
0
ファイル: template.php プロジェクト: ec-europa/platform-dev
/**
 * Implements template_preprocess_block().
 */
function ec_resp_preprocess_block(&$variables)
{
    global $user, $language;
    $block_no_panel = array('search' => 'form', 'print' => 'print-links', 'print_ui' => 'print-links', 'workbench' => 'block', 'social_bookmark' => 'social-bookmark', 'views' => 'view_ec_content_slider-block', 'om_maximenu' => array('om-maximenu-1', 'om-maximenu-2'), 'menu' => 'menu-service-tools', 'cce_basic_config' => 'footer_ipg');
    // List of all blocks that don't need their title to be displayed.
    $block_no_title = array('fat_footer' => 'fat-footer', 'om_maximenu' => array('om-maximenu-1', 'om-maximenu-2'), 'menu' => 'menu-service-tools', 'cce_basic_config' => 'footer_ipg');
    $block_no_body_class = array();
    $panel = TRUE;
    foreach ($block_no_panel as $key => $value) {
        if ($variables['block']->module == $key) {
            if (is_array($value)) {
                foreach ($value as $delta) {
                    if ($variables['block']->delta == $delta) {
                        $panel = FALSE;
                        break;
                    }
                }
            } else {
                if ($variables['block']->delta == $value) {
                    $panel = FALSE;
                    break;
                }
            }
        }
    }
    $title = TRUE;
    foreach ($block_no_title as $key => $value) {
        if ($variables['block']->module == $key) {
            if (is_array($value)) {
                foreach ($value as $delta) {
                    if ($variables['block']->delta == $delta) {
                        $title = FALSE;
                        break;
                    }
                }
            } else {
                if ($variables['block']->delta == $value) {
                    $title = FALSE;
                    break;
                }
            }
        }
    }
    $body_class = TRUE;
    foreach ($block_no_body_class as $key => $value) {
        if ($variables['block']->module == $key && $variables['block']->delta == $value) {
            $body_class = FALSE;
        }
    }
    $variables['panel'] = $panel;
    $variables['title'] = $title;
    $variables['body_class'] = $body_class;
    if (isset($variables['block']->bid)) {
        switch ($variables['block']->bid) {
            case 'locale-language':
                $languages = language_list();
                $items = array();
                $items[] = array('data' => '<span class="off-screen">' . t("Current language") . ':</span> ' . $language->language, 'class' => array('selected'), 'title' => $language->native, 'lang' => $language->language);
                // Get path of translated content.
                $translations = translation_path_get_translations(current_path());
                $language_default = language_default();
                foreach ($languages as $language_object) {
                    $prefix = $language_object->language;
                    $language_name = $language_object->name;
                    if (isset($translations[$prefix])) {
                        $path = $translations[$prefix];
                    } else {
                        $path = current_path();
                    }
                    // Get the related url alias
                    // Check if the multisite language negotiation
                    // with suffix url is enabled.
                    $language_negociation = variable_get('language_negotiation_language');
                    if (isset($language_negociation['locale-url-suffix'])) {
                        $delimiter = variable_get('language_suffix_delimiter', '_');
                        $alias = drupal_get_path_alias($path, $prefix);
                        if ($alias == variable_get('site_frontpage', 'node')) {
                            $path = $prefix == 'en' ? '' : 'index';
                        } else {
                            if ($alias != $path) {
                                $path = $alias;
                            } else {
                                $path = drupal_get_path_alias(isset($translations[$language_name]) ? $translations[$language_name] : $path, $language_name);
                            }
                        }
                    } else {
                        $path = drupal_get_path_alias($path, $prefix);
                    }
                    // Add enabled languages.
                    if ($language_name != $language->name) {
                        $items[] = array('data' => l($language_name, filter_xss($path), array('attributes' => array('hreflang' => $prefix, 'lang' => $prefix, 'title' => $language_name), 'language' => $language_object)));
                    }
                }
                $variables['language_list'] = theme('item_list', array('items' => $items));
                break;
            case 'system-user-menu':
                if ($user->uid) {
                    $name = theme('username', array('account' => $user, 'nolink' => TRUE));
                    $variables['welcome_message'] = "<div class='username'>" . t('Welcome,') . ' <strong>' . $name . '</strong></div>';
                }
                $menu = menu_navigation_links("user-menu");
                $items = array();
                // Manage redirection after login.
                $status = drupal_get_http_header('status');
                if (strpos($status, '404') !== FALSE) {
                    $dest = 'home';
                } elseif (strpos(current_path(), 'user/register') !== FALSE) {
                    $dest = 'home';
                } elseif (strpos(current_path(), 'user/login') !== FALSE) {
                    $dest = 'home';
                } else {
                    $dest = drupal_get_path_alias();
                }
                foreach ($menu as $item_id) {
                    // Get icon links to menu item.
                    $icon = isset($item_id['attributes']['data-image']) ? $item_id['attributes']['data-image'] : '';
                    // Get display title option.
                    $display_title = isset($item_id['attributes']['data-display-title']) ? $item_id['attributes']['data-display-title'] : 1;
                    // Add the icon.
                    if ($icon) {
                        if ($display_title) {
                            $item_id['title'] = '<span class="glyphicon glyphicon-' . $icon . '" aria-hidden="true"></span> ' . $item_id['title'];
                        } else {
                            // If the title is not supposed to be displayed, add a visually
                            // hidden title that is accessible for screen readers.
                            $item_id['title'] = '<span class="glyphicon glyphicon-' . $icon . ' menu-no-title" aria-hidden="true"></span><span class="sr-only">' . $item_id['title'] . '</span>';
                        }
                    }
                    // Add redirection for login, logout and register.
                    if ($item_id['href'] == 'user/login' || $item_id['href'] == 'user/register') {
                        $item_id['query']['destination'] = $dest;
                    }
                    if ($item_id['href'] == 'user/logout') {
                        $item_id['query']['destination'] = '<front>';
                    }
                    // Add icon before menu item
                    // TODO: make it editable in administration.
                    switch ($item_id['href']) {
                        case 'user':
                            $item_id['attributes']['type'] = 'user';
                            break;
                        case 'user/login':
                            $item_id['attributes']['type'] = 'login';
                            break;
                        case 'user/logout':
                            $item_id['attributes']['type'] = 'logout';
                            break;
                        case 'admin/workbench':
                            $item_id['attributes']['type'] = 'workbench';
                            break;
                    }
                    $item_id['html'] = TRUE;
                    $items[] = l($item_id['title'], $item_id['href'], $item_id);
                }
                $variables['menu_items'] = implode('', $items);
                break;
            case 'easy_breadcrumb-easy_breadcrumb':
                $variables['menu_breadcrumb'] = menu_tree('menu-breadcrumb-menu');
                break;
        }
    }
}
コード例 #27
0
 /**
  * Instantiates a view object from form values.
  *
  * @return \Drupal\views_ui\ViewUI
  *   The instantiated view UI object.
  */
 protected function instantiateView($form, FormStateInterface $form_state)
 {
     // Build the basic view properties and create the view.
     $values = array('id' => $form_state->getValue('id'), 'label' => $form_state->getValue('label'), 'description' => $form_state->getValue('description'), 'base_table' => $this->base_table, 'langcode' => language_default()->getId());
     $view = entity_create('view', $values);
     // Build all display options for this view.
     $display_options = $this->buildDisplayOptions($form, $form_state);
     // Allow the fully built options to be altered. This happens before adding
     // the options to the view, so that once they are eventually added we will
     // be able to get all the overrides correct.
     $this->alterDisplayOptions($display_options, $form, $form_state);
     $this->addDisplays($view, $display_options, $form, $form_state);
     return new ViewUI($view);
 }
コード例 #28
0
ファイル: LingotekSync.php プロジェクト: kweigand/cck
 public static function getDirtyChunkLids()
 {
     // return the list of all lids from the locale_source table *not* fully translated
     $source_language = language_default();
     if (!isset($source_language->lingotek_locale)) {
         $source_language->lingotek_locale = Lingotek::convertDrupal2Lingotek($source_language->language);
     }
     $lingotek_codes = Lingotek::getLanguagesWithoutSource($source_language->lingotek_locale);
     if (!count($lingotek_codes)) {
         LingotekLog::error('No languages configured for this Lingotek account.', array());
         return array();
     }
     // get the drupal language for each associated lingotek locale
     $drupal_codes = array();
     foreach ($lingotek_codes as $lc) {
         $drupal_codes[] = Lingotek::convertLingotek2Drupal($lc);
     }
     // get the list of all segments that need updating
     // that belong to the textgroups the user wants translated
     $textgroups = array_merge(array(-1), LingotekConfigChunk::getTextgroupsForTranslation());
     $max_length = variable_get('lingotek_config_max_source_length', LINGOTEK_CONFIG_MAX_SOURCE_LENGTH);
     $query = db_select('{locales_source}', 'ls');
     $query->fields('ls', array('lid'))->condition('ls.source', '', '!=')->condition('ls.lid', self::getQueryCompletedConfigTranslations($drupal_codes), 'NOT IN')->where('length(ls.source) < ' . (int) $max_length);
     if (in_array('misc', $textgroups)) {
         $or = db_or();
         $or->condition('ls.textgroup', $textgroups, 'IN');
         $or->where("ls.textgroup NOT IN ('default','menu','taxonomy','views','blocks','field')");
         $query->condition($or);
     } else {
         $query->condition('ls.textgroup', $textgroups, 'IN');
     }
     return $query->execute()->fetchCol();
 }
コード例 #29
0
/**
 * Allow modules to take action when a stock level is changed.
 *
 * @param $sku
 *   The SKU whose stock level is being changed.
 * @param $stock
 *   The stock level before the adjustment.
 * @param $qty
 *   The amount by which the stock level was changed.
 */
function hook_uc_stock_adjusted($sku, $stock, $qty)
{
    $params = array('sku' => $sku, 'stock' => $stock, 'qty' => $qty);
    drupal_mail('uc_stock_notify', 'stock-adjusted', uc_store_email_from(), language_default(), $params);
}
コード例 #30
0
ファイル: js.php プロジェクト: johnedelatorre/fusion
/**
 * Loads the requested module and executes the requested callback.
 *
 * @return
 *   The callback function's return value or one of the JS_* constants.
 */
function js_execute_callback()
{
    $args = explode('/', $_GET['q']);
    // If i18n is enabled and therefore the js module should boot
    // to DRUPAL_BOOTSTRAP_LANGUAGE.
    $i18n = FALSE;
    // Validate if there is a language prefix in the path.
    if (!empty($args[0]) && !empty($args[1]) && $args[1] == 'js_callback') {
        // Language string detected, strip off the language code.
        $language_code = array_shift($args);
        // Enable language detection to make sure i18n is enabled.
        $i18n = TRUE;
    }
    // Strip first argument 'js_callback'.
    if (!empty($args[0]) && $args[0] == 'js_callback') {
        array_shift($args);
    }
    // Determine module to load.
    $module = check_plain(array_shift($args));
    if (!$module || !drupal_load('module', $module)) {
        return JS_MENU_ACCESS_DENIED;
    }
    // Get info hook function name.
    $function = $module . '_js';
    if (!function_exists($function)) {
        return JS_MENU_NOT_FOUND;
    }
    // Get valid callbacks.
    $valid_callbacks = $function();
    // Get the callback.
    $callback = check_plain(array_shift($args));
    // Validate the callback.
    if (!isset($valid_callbacks[$callback])) {
        return JS_MENU_NOT_FOUND;
    }
    // If the callback function is located in another file, load that file now.
    if (isset($valid_callbacks[$callback]['file']) && ($filepath = drupal_get_path('module', $module) . '/' . $valid_callbacks[$callback]['file']) && file_exists($filepath)) {
        require_once $filepath;
    }
    // Validate the existance of the defined callback.
    if (!function_exists($valid_callbacks[$callback]['callback'])) {
        return JS_MENU_NOT_FOUND;
    }
    // Bootstrap to required level.
    $full_boostrap = FALSE;
    if (!empty($valid_callbacks[$callback]['bootstrap'])) {
        drupal_bootstrap($valid_callbacks[$callback]['bootstrap']);
        $full_boostrap = $valid_callbacks[$callback]['bootstrap'] == DRUPAL_BOOTSTRAP_FULL;
    }
    // Validate if the callback uses i18n.
    if (isset($valid_callbacks[$callback]['i18n'])) {
        $i18n = $valid_callbacks[$callback]['i18n'];
    }
    if (!$full_boostrap) {
        // The following mimics the behavior of _drupal_bootstrap_full().
        // The difference is that not all modules and includes are loaded.
        // @see _drupal_bootstrap_full().
        // If i18n is enabled, boot to the language phase and make
        // sure the required modules are enabled.
        if ($i18n) {
            // First boot to the variables to make sure drupal_multilingual() works.
            drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
            // As the variables bootstrap phase loads all core modules, we have to
            // add the user module and the path include as a dependencies because they
            // are required by some core modules.
            if (empty($valid_callbacks[$callback]['dependencies'])) {
                $valid_callbacks[$callback]['dependencies'] = array();
            }
            if (empty($valid_callbacks[$callback]['includes'])) {
                $valid_callbacks[$callback]['includes'] = array();
            }
            if (!in_array('user', $valid_callbacks[$callback]['dependencies'])) {
                $valid_callbacks[$callback]['dependencies'][] = 'user';
            }
            if (!in_array('path', $valid_callbacks[$callback]['includes'])) {
                $valid_callbacks[$callback]['includes'][] = 'path';
            }
            // Then check if it's a multilingual site. If so, boot to the language
            // phase.
            if (drupal_multilingual()) {
                drupal_bootstrap(DRUPAL_BOOTSTRAP_LANGUAGE);
            }
        }
        // Load required include files based on the callback.
        if (isset($valid_callbacks[$callback]['includes']) && is_array($valid_callbacks[$callback]['includes'])) {
            foreach ($valid_callbacks[$callback]['includes'] as $include) {
                if (file_exists("./includes/{$include}.inc")) {
                    require_once "./includes/{$include}.inc";
                }
            }
        }
        // Detect string handling method.
        unicode_check();
        // Undo magic quotes.
        fix_gpc_magic();
        // Make sure all stream wrappers are registered.
        file_get_stream_wrappers();
        // Load required modules.
        $modules = array($module => 0);
        if (isset($valid_callbacks[$callback]['dependencies']) && is_array($valid_callbacks[$callback]['dependencies'])) {
            foreach ($valid_callbacks[$callback]['dependencies'] as $dependency) {
                if (!drupal_load('module', $dependency)) {
                    // Do a boot up till SESSION to be sure the drupal_set_message()
                    // function works.
                    drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
                    // Create an error message with information for the user to be able
                    // to fix the dependency.
                    $error = t('The dependency :dependency for the callback :callback in :module is not installed.', array(':dependency' => $dependency, ':callback' => $callback, ':module' => $module));
                    // Let the user know what's wrong and throw an exception to stop the
                    // callback.
                    drupal_set_message($error, 'error');
                    throw new Exception($error);
                }
                $modules[$dependency] = 0;
            }
        }
        // Reset module list.
        module_list(FALSE, TRUE, FALSE, $modules);
        // Ensure the language variable is set, if not it might cause problems (e.g.
        // entity info).
        global $language;
        if (!isset($language)) {
            $language = language_default();
        }
        // If access arguments are passed, boot to SESSION and validate if the user
        // has access to this callback.
        if (!empty($valid_callbacks[$callback]['access arguments']) || !empty($valid_callbacks[$callback]['access callback'])) {
            drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
            // If no callback is provided, default to user_access.
            if (!isset($valid_callbacks[$callback]['access callback'])) {
                $valid_callbacks[$callback]['access callback'] = 'user_access';
            }
            if ($valid_callbacks[$callback]['access callback'] == 'user_access') {
                // Ensure the user module is available.
                drupal_load('module', 'user');
            }
            if (!call_user_func_array($valid_callbacks[$callback]['access callback'], !empty($valid_callbacks[$callback]['access arguments']) ? $valid_callbacks[$callback]['access arguments'] : array())) {
                return JS_MENU_ACCESS_DENIED;
            }
        }
        // Invoke implementations of hook_init() if the callback doesn't indicate it
        // should be skipped.
        if (!isset($valid_callbacks[$callback]['skip_hook_init']) || $valid_callbacks[$callback]['skip_hook_init'] == FALSE) {
            module_invoke_all('init');
        }
    }
    // If there are page arguments defined add them to the callback call.
    if (isset($valid_callbacks[$callback]['page arguments'])) {
        // Get the original args again and strip first arguments 'js_callback' and 'module'.
        $args = array_slice(explode('/', $_GET['q']), 2);
        // Overwrite the arguments
        $args = array_intersect_key($args, array_flip($valid_callbacks[$callback]['page arguments']));
    }
    // Invoke callback function.
    return call_user_func_array($valid_callbacks[$callback]['callback'], $args);
}