/** * Generate new session identifier, set it as PHP session identifier and * return it. * * @return string */ protected function generateSessionIdentifier() { $this->sessionIdentifier = drupal_hash_base64(uniqid(mt_rand(), TRUE)); // Depending on the underlaying implementation, some hash may fail to // achieve the session_start() especially if you are using the PHP native // one to handle session storage. $this->sessionIdentifier = str_replace('_', '-', $this->sessionIdentifier); session_id($this->sessionIdentifier); return $this->sessionIdentifier; }
public static function cachedRequestGetCid($url, array $options) { if (isset($options['cache']) && $options['cache'] === FALSE) { return FALSE; } elseif (isset($options['method']) && !in_array($options['method'], array('GET', 'HEAD'))) { // Only cache GET and HEAD methods. return FALSE; } elseif (isset($options['cache']['cid'])) { return $options['cache']['cid']; } $cid_parts = array($url, serialize(array_diff_key($options, array('cache' => '')))); return 'http-request:' . drupal_hash_base64(serialize($cid_parts)); }
/** * Implements AcsfEventHandler::handle(). */ public function handle() { drush_print(dt('Entered @class', array('@class' => get_class($this)))); $options = $this->event->context['scrub_options']; variable_del('cron_last'); variable_del('cron_semaphore'); variable_del('node_cron_last'); variable_del('drupal_private_key'); variable_set('cron_key', drupal_hash_base64(drupal_random_bytes(55))); // Ensure Drupal filesystem related configuration variables are correct for // the new site. Consider the following variables: // - file_directory_path // - file_directory_temp // - file_private_path // - file_temporary_path // Given the AH environment for Gardens, we want to leave the temp paths // alone, and we want to delete the other variables, to ensure they reset to // their defaults (because of scarecrow, these shouldn't exist in the // variable table anyway). $file_path_variables = array('file_directory_path', 'file_private_path'); foreach ($file_path_variables as $variable) { variable_del($variable); } }
/** * Sets $this->stats with the information about the Solr Core form */ protected function setStats() { $data = $this->getLuke(); $solr_version = $this->getSolrVersion(); // Only try to get stats if we have connected to the index. if (empty($this->stats) && isset($data->index->numDocs)) { if ($solr_version >= 4) { $url = $this->_constructUrl(self::STATS_SERVLET_4); } else { $url = $this->_constructUrl(self::STATS_SERVLET); } if ($this->env_id) { $this->stats_cid = $this->env_id . ":stats:" . drupal_hash_base64($url); $cache = cache_get($this->stats_cid, 'cache_apachesolr'); if (isset($cache->data)) { $this->stats = simplexml_load_string($cache->data); } } // Second pass to populate the cache if necessary. if (empty($this->stats)) { $response = $this->_sendRawGet($url); $this->stats = simplexml_load_string($response->data); if ($this->env_id) { cache_set($this->stats_cid, $response->data, 'cache_apachesolr'); } } } }
/** * Allow other modules to modify $children & $elements before they are rendered. * * @param $children * An array of children elements. * @param $elements * A render array containing: * - #items: The JavaScript items as returned by drupal_add_js() and * altered by drupal_get_js(). * - #group_callback: A function to call to group #items. Following * this function, #aggregate_callback is called to aggregate items within * the same group into a single file. * - #aggregate_callback: A function to call to aggregate the items within * the groups arranged by the #group_callback function. * * @see advagg_modify_js_pre_render() * @see advagg_js_compress_advagg_modify_js_pre_render_alter() */ function hook_advagg_modify_js_pre_render_alter(&$children, &$elements) { // Get variables. $aggregate_settings['variables']['advagg_js_compressor'] = variable_get('advagg_js_inline_compressor', ADVAGG_JS_INLINE_COMPRESSOR); $aggregate_settings['variables']['advagg_js_max_compress_ratio'] = variable_get('advagg_js_max_compress_ratio', ADVAGG_JS_MAX_COMPRESS_RATIO); // Do nothing if the compressor is disabled. if (empty($aggregate_settings['variables']['advagg_js_compressor'])) { return; } // Do nothing if the page is not cacheable and inline compress if not // cacheable is not checked. if (!variable_get('advagg_js_inline_compress_if_not_cacheable', ADVAGG_JS_INLINE_COMPRESS_IF_NOT_CACHEABLE) && !drupal_page_is_cacheable()) { return; } // Compress any inline JS. module_load_include('inc', 'advagg_js_compress', 'advagg_js_compress.advagg'); foreach ($children as $key => &$values) { if (!empty($values['#value'])) { $contents = $values['#value']; $filename = drupal_hash_base64($contents); advagg_js_compress_prep($contents, $filename, $aggregate_settings, FALSE); $values['#value'] = $contents; } } }
/** * Fully initializes the git clone entity after it has been created or loaded. * * @param bool $force * Toggle determining whether or not to force a reinitialization. * * @return GitClone * The current GitClone entity instance. * * @see GitClone::save() * @see EntityController::load() * * @chainable */ public function init($force = FALSE) { if (!$force && isset($this->initialized)) { return $this; } $this->initialized = TRUE; // Ensure a Gitonomy repository is instantiated. if (!$force && !isset($this->repository)) { $options = _git_clone_gitonomy_options(); if (($path = $this->getPath(FALSE)) && !empty($this->url)) { $git_exists = file_exists("{$path}/.git"); if (!$git_exists && in_array($this->refType, self::$allowedRefs)) { try { $this->repository = Admin::init($path, FALSE, $options); $this->run('remote', array('add', 'origin', $this->url)); } catch (\Exception $e) { drupal_set_message($e->getMessage(), 'error'); } } elseif ($git_exists && in_array($this->refType, self::$allowedRefs)) { $this->repository = new Repository($path, $options); } } else { $temp_dir = 'temporary://git_clone-' . drupal_hash_base64(REQUEST_TIME); if (file_prepare_directory($temp_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) { $temp_dir = drupal_realpath($temp_dir); drupal_register_shutdown_function(function () use($temp_dir) { if (file_exists($temp_dir)) { file_unmanaged_delete_recursive($temp_dir); } }); try { $this->repository = Admin::init($temp_dir, FALSE, $options); } catch (\Exception $e) { watchdog('git_clone', $e->getMessage(), WATCHDOG_ERROR); } } if (!$this->repository) { drupal_set_message(t('Unable to create temporary git clone repository: @directory. Please verify your system temporary directory is writable.', array('@directory' => $temp_dir)), 'error'); } } } // Initialize the settings. $this->getSettings(); // Initialize the refs. $this->getRefs($force); return $this; }