security updates
have to check views and entityreference for custom patches
This commit is contained in:
151
sites/all/modules/contrib/admin/print/includes/print.drush.inc
Normal file
151
sites/all/modules/contrib/admin/print/includes/print.drush.inc
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* common drush functions for the print submodules.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Download and extract the lib
|
||||
*
|
||||
* @param string $library
|
||||
* library to download.
|
||||
* @param string $url
|
||||
* URL of the file to download
|
||||
*/
|
||||
function _print_drush_download_lib($library, $url) {
|
||||
$path = drush_get_option('path');
|
||||
if (empty($path)) {
|
||||
$path = drush_get_context('DRUSH_DRUPAL_ROOT') . '/sites/all/libraries';
|
||||
}
|
||||
|
||||
// Create the path if it does not exist.
|
||||
if (!is_dir($path)) {
|
||||
drush_op('mkdir', $path);
|
||||
drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice');
|
||||
}
|
||||
|
||||
// Chdir to the download location.
|
||||
$olddir = getcwd();
|
||||
drush_op('chdir', $path);
|
||||
|
||||
// Warn about an existing dir
|
||||
if (is_dir($library)) {
|
||||
// drush_op('rmdir', $library); // Directory must be empty for the php rmdir to work..
|
||||
drush_log(dt('An existing @library was overwritten at @path', array('@library' => $library, '@path' => $path . '/' . $library)), 'notice');
|
||||
}
|
||||
|
||||
// Download the archive
|
||||
$filename = _print_drush_download_file($url);
|
||||
if ($filename) {
|
||||
$extract_ret = _print_drush_download_extract($filename);
|
||||
if ($extract_ret) {
|
||||
// Remove the archive
|
||||
drush_op('unlink', $filename);
|
||||
drush_log(dt('@file has been downloaded and extracted in @path', array('@file' => $filename, '@path' => $path)), 'success');
|
||||
}
|
||||
else {
|
||||
drush_log(dt('@file has been downloaded to @path, but extract failed. Check that you have the necessary program installed, and if necessary extract it manually.',
|
||||
array('@file' => $filename, '@path' => $path)), 'warning');
|
||||
}
|
||||
}
|
||||
else {
|
||||
drush_log(dt('Drush was unable to download @library to @path', array('@library' => $library, '@path' => $path)), 'error');
|
||||
}
|
||||
|
||||
// Set working directory back to the previous working directory.
|
||||
drush_op('chdir', $olddir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a file using wget or curl
|
||||
*
|
||||
* Adapted from a function in drush/includes/drush.inc to support 302 redirects.
|
||||
*
|
||||
* @param string $download_url
|
||||
* The path to the file to download
|
||||
*
|
||||
* @return string
|
||||
* The filename that was downloaded, or NULL if the file could not be
|
||||
* downloaded.
|
||||
*/
|
||||
function _print_drush_download_file($download_url) {
|
||||
$wget_ret = drush_shell_exec("wget -nv --trust-server-names %s", $download_url);
|
||||
|
||||
if (!drush_get_context('DRUSH_SIMULATE')) {
|
||||
if ($wget_ret) {
|
||||
// Get the filename of the saved file from the output
|
||||
$wget_out = explode('"', array_shift(drush_shell_exec_output()));
|
||||
$filename = $wget_out[1];
|
||||
}
|
||||
else {
|
||||
$tempnam = uniqid('print_drush_');
|
||||
|
||||
$curl_ret = drush_shell_exec("curl -s -L -o %s %s -w '%%{url_effective}'", $tempnam, $download_url);
|
||||
if ($curl_ret) {
|
||||
// File was donwloaded with the tempname
|
||||
|
||||
// Find the effective name
|
||||
$filename = explode('/', array_shift(drush_shell_exec_output()));
|
||||
$filename = array_pop($filename);
|
||||
|
||||
// Rename file from tempname to effective name
|
||||
if (!drush_op('rename', $tempnam, './' . $filename)) {
|
||||
$filename = $tempnam;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$filename = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$filename = basename($download_url);
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to extract the downloaded zip/tar archive.
|
||||
*
|
||||
* @param string $filename
|
||||
* filename of the file to extract
|
||||
*
|
||||
* @return bool
|
||||
* TRUE on success, FALSE on failure
|
||||
*/
|
||||
function _print_drush_download_extract($filename) {
|
||||
$arch_ret = FALSE;
|
||||
|
||||
if (drush_op('is_file', $filename)) {
|
||||
switch (drush_op('mime_content_type', $filename)) {
|
||||
case 1:
|
||||
$arch_ret = TRUE;
|
||||
break;
|
||||
case 'application/zip':
|
||||
// Decompress the zip archive
|
||||
$arch_ret = drush_shell_exec('unzip -qq -o %s', $filename);
|
||||
// ZIP archives usually get the access rights wrong
|
||||
drush_log(dt('@filename is a Zip file. Check the access permissions of the extracted files.', array('@filename' => $filename)), 'warning');
|
||||
break;
|
||||
case 'application/x-gzip':
|
||||
// Decompress the tar gz archive
|
||||
$arch_ret = drush_shell_exec('tar xzf %s', $filename);
|
||||
break;
|
||||
case 'application/x-bzip2':
|
||||
// Decompress the tar bz2 archive
|
||||
$arch_ret = drush_shell_exec('tar xjf %s', $filename);
|
||||
break;
|
||||
case 'application/x-xz':
|
||||
// Decompress the tar xz archive
|
||||
$arch_ret = drush_shell_exec('tar xJf %s', $filename);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
drush_log(dt('@filename not found.', array('@filename' => $filename)), 'error');
|
||||
}
|
||||
|
||||
return $arch_ret;
|
||||
}
|
100
sites/all/modules/contrib/admin/print/includes/print.inc
Normal file
100
sites/all/modules/contrib/admin/print/includes/print.inc
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Common functions used by several of the print modules
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auxiliary function to scan all module directories for a given library.
|
||||
*
|
||||
* @param string $lib
|
||||
* The machine name of a library to return the path for.
|
||||
* @param string $mask
|
||||
* The preg_match() regular expression of the files to find.
|
||||
*
|
||||
* @return array
|
||||
* An array of the filenames matching the provided mask.
|
||||
*/
|
||||
function _print_scan_libs($lib, $mask) {
|
||||
$tools = array_keys(file_scan_directory(drupal_get_path('module', 'print'), $mask));
|
||||
$tools = array_merge($tools, array_keys(file_scan_directory(PRINT_LIB_PATH, $mask)));
|
||||
if (module_exists('libraries')) {
|
||||
$tools = array_merge($tools, array_keys(file_scan_directory(libraries_get_path($lib), $mask)));
|
||||
}
|
||||
|
||||
return array_unique($tools);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function for the preg_replace_callback replacing spaces with %20
|
||||
*
|
||||
* Replace spaces in URLs with %20
|
||||
*
|
||||
* @param array $matches
|
||||
* array with the matched tag patterns, usually <a...>+text+</a>
|
||||
*
|
||||
* @return string
|
||||
* tag with re-written URL
|
||||
*/
|
||||
function _print_replace_spaces($matches) {
|
||||
// first, split the html into the different tag attributes
|
||||
$pattern = '!\s*(\w+\s*=\s*"(?:\\\"|[^"])*")\s*|\s*(\w+\s*=\s*\'(?:\\\\\'|[^\'])*\')\s*|\s*(\w+\s*=\s*\w+)\s*|\s+!';
|
||||
$attribs = preg_split($pattern, $matches[1], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
|
||||
foreach ($attribs as $key => $value) {
|
||||
$attribs[$key] = preg_replace('!(\w)\s*=\s*(.*)!', '$1=$2', $value);
|
||||
}
|
||||
|
||||
$size = count($attribs);
|
||||
for ($i=1; $i < $size; $i++) {
|
||||
// If the attribute is href or src, we may need to rewrite the URL in the value
|
||||
if (preg_match('!^(?:href|src)\s*?=(.*)!i', $attribs[$i], $urls) > 0) {
|
||||
$url = trim($urls[1], " \t\n\r\0\x0B\"'");
|
||||
$new_url = str_replace(' ', '%20', $url);
|
||||
$matches[1] = str_replace($url, $new_url, $matches[1]);
|
||||
}
|
||||
}
|
||||
|
||||
$ret = '<' . $matches[1] . '>';
|
||||
if (count($matches) == 4) {
|
||||
$ret .= $matches[2] . $matches[3];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert image paths to the file:// protocol
|
||||
*
|
||||
* In some Drupal setups, the use of the 'private' filesystem or Apache's
|
||||
* configuration prevent access to the images of the page. This function
|
||||
* tries to circumnvent those problems by accessing files in the local
|
||||
* filesystem.
|
||||
*
|
||||
* @param string $html
|
||||
* contents of the post-processed template already with the node data
|
||||
* @param bool $images_via_file
|
||||
* if TRUE, convert also files in the 'public' filesystem to local paths
|
||||
*
|
||||
* @return string
|
||||
* converted file names
|
||||
*/
|
||||
function _print_access_images_via_file($html, $images_via_file) {
|
||||
global $base_url, $language;
|
||||
|
||||
$lang = (function_exists('language_negotiation_get_any') && language_negotiation_get_any('locale-url')) ? $language->language : '';
|
||||
|
||||
// Always convert private to local paths
|
||||
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?system/files/([^>]*?>)!is";
|
||||
$replacement = '$1file://' . realpath(variable_get('file_private_path', '')) . '/$2';
|
||||
$html = preg_replace($pattern, $replacement, $html);
|
||||
if ($images_via_file) {
|
||||
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?([^>]*?>)!is";
|
||||
$replacement = '$1file://' . dirname($_SERVER['SCRIPT_FILENAME']) . '/$2';
|
||||
$html = preg_replace($pattern, $replacement, $html);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
Reference in New Issue
Block a user