/**
 * Checks to see if ImageMagick is available on the system.
 *
 * This function requires the {@link IMAGEMAGICK_PATH} constant to have been
 * defined; it only checks for the command-line ImageMagick utilities, not any
 * of the library's PHP bindings.
 *
 * @param string $utility the specific ImageMagick utility to check for
 * @return boolean true if the utility is available, false if otherwise
 * @link http://www.imagemagick.org/ ImageMagick
 */
function imagemagick_available($utility = 'mogrify')
{
    static $cache = array();
    if (!isset($cache[$utility])) {
        $file = server_is_windows() ? "{$utility}.exe" : $utility;
        if (!@constant('IMAGEMAGICK_PATH')) {
            $result = false;
        } else {
            if (!is_executable(IMAGEMAGICK_PATH . $file)) {
                $result = false;
            } else {
                $result = true;
            }
        }
        $cache[$utility] = $result;
    }
    return $cache[$utility];
}
Example #2
0
 /**
  * Send the Email
  *
  * @return boolean Accepted for delivery
  */
 function send()
 {
     $crlf = "\r\n";
     $additional_headers = '';
     if ($this->_froms) {
         $additional_headers .= 'From: ' . $this->_froms . $crlf;
     }
     if ($this->_ccs) {
         $additional_headers .= 'Cc: ' . $this->_ccs . $crlf;
     }
     if ($this->_tos) {
         $additional_headers .= 'Bcc: ' . $this->_tos . $crlf;
     }
     if ($this->_replytos) {
         $additional_headers .= 'Reply-To: ' . $this->_replytos . $crlf;
     }
     $additional_headers .= 'MIME-version: 1.0' . $crlf;
     // simplest case: just plain text content
     if (empty($this->_htmlbody) && empty($this->_attachments)) {
         $additional_headers .= 'Content-Type: text/plain; charset=UTF-8' . $crlf;
         $additional_headers .= 'Content-Disposition: inline' . $crlf;
         $email = "\n\n" . $this->_txtbody;
     } else {
         $email = "\n" . 'This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how properly to handle MIME multipart messages.' . $crlf . "\n";
         // preamble
         // If there's an HTML alternate, build up a MIME block to contain the text and HTML. We'll either
         // use it standalone (if there's no attachment) or inside another MIME block with attachments.
         if (!empty($this->_htmlbody)) {
             $alternate_boundary = uniqid('the_alternate_boundary_is_');
             $alternate = "--" . $alternate_boundary . $crlf;
             // first boundary
             $alternate .= 'Content-Type: text/plain; charset=UTF-8' . $crlf;
             $alternate .= 'Content-Disposition: inline' . $crlf;
             $alternate .= "\n\n" . $this->_txtbody;
             $alternate .= "\n\n--" . $alternate_boundary . "\n";
             $alternate .= 'Content-Type: text/html; charset=UTF-8' . $crlf;
             $alternate .= 'Content-Disposition: inline' . $crlf . "\n";
             $alternate .= $this->_htmlbody;
             $alternate .= "\n\n--" . $alternate_boundary . "--\n";
             //last boundary
         }
         // If there's no attachment, the text alternates are the whole of the message
         if (empty($this->_attachments)) {
             $additional_headers .= 'Content-Type: multipart/alternative; boundary="' . $alternate_boundary . '"' . $crlf;
             // define boundary
             $email .= $alternate;
         } else {
             $multipart_boundary = uniqid('the_multipart_boundary_is_');
             $additional_headers .= 'Content-Type: multipart/mixed; boundary="' . $multipart_boundary . '"' . $crlf;
             // define boundary
             $email .= "--" . $multipart_boundary . $crlf;
             // first boundary
             if (isset($alternate)) {
                 $email .= 'Content-Type: multipart/alternative; boundary="' . $alternate_boundary . '"' . $crlf;
                 // define boundary
                 $email .= $alternate;
             } else {
                 $email .= 'Content-Type: text/plain; charset=UTF-8' . $crlf;
                 $email .= "\n\n" . $this->_txtbody;
             }
             $email .= $this->add_message_attachments($multipart_boundary);
             $email .= "\n\n--" . $multipart_boundary . "--\n";
             //last boundary
         }
     }
     $subject = $this->mb_mime_header_encode($this->_subject);
     // it seems a little odd that we are sending the whole email in via the additional headers parameter when not running windows
     $success = server_is_windows() ? mail('', $subject, $email, $additional_headers) : mail('', $subject, '', $additional_headers . $email);
     return $success;
 }
Example #3
0
/**
 * Check to see if a suitable graphicslib is installed and working
 */
function graphicslib_check()
{
    $mogrify_filename = server_is_windows() ? 'mogrify.exe' : 'mogrify';
    $mogrify_exists = file_exists(IMAGEMAGICK_PATH . $mogrify_filename);
    if ($mogrify_exists) {
        $cmd = "\"" . IMAGEMAGICK_PATH . "mogrify\" -version 2>&1";
        $output = shell_exec($cmd);
        // see if the string imagemagick exists in the output - if not it did not work properly
        if (strpos(strtolower($output), 'imagemagick') === false) {
            $imagemagick = false;
        } else {
            $imagemagick = true;
        }
    } else {
        $imagemagick = false;
    }
    // lets try GD
    if (!$imagemagick) {
        $gd = extension_loaded('gd') && function_exists('gd_info');
    }
    if ($imagemagick || $gd) {
        if ($imagemagick) {
            return msg('<span class="success">graphicslib check passed - imagemagick loaded</span>', true);
        } elseif ($gd && $mogrify_exists) {
            return msg('<span class="success">graphicslib check passed - fell to GD ... imagemagick exists but does not appear to function properly when invoked via php...your php install should not be running in safe mode and needs to be able to use exec and shell_exec functions. Error is as follows:' . $output, true);
        } else {
            return msg('<span class="warning">graphicslib check passed - fell to GD ... imagemagick is preferred but could not be found.</span>', true);
        }
    } else {
        return msg('<span class="error">graphicslib check failed</span> - ' . IMAGEMAGICK_PATH . 'mogrify not found - check the IMAGEMAGICK_PATH constant in package_settings.php, and php permissions. Alternatively, make sure GD is available.', false);
    }
}
Example #4
0
 /**
  * An exec replacement that supports an optional timeout parameter.
  *
  * - On Windows the timeout is ignored.
  * - Exit status appears to be unreliable. Don't use this if you depend on it.
  */
 function exec_with_timeout($cmd, $timeout = NULL, &$output = NULL, &$exit_status = NULL)
 {
     if (!server_is_windows()) {
         $exit_status = proc_with_timeout($cmd, null, $stdout, $stderr, $timeout);
         if (is_array($output)) {
             $output = array_merge($output, preg_split("/\r\n|\n|\r/", $stdout));
         }
     } else {
         exec($cmd, $output, $exit_status);
     }
 }
 function url_manager($site_id, $debug = false, $do_global_rewrites = false, $cli = false)
 {
     if (php_sapi_name() == 'cli' || $cli) {
         $this->cli = true;
     }
     $this->debug = $debug;
     $this->debug('debugging is on');
     if (!$do_global_rewrites && empty($site_id)) {
         trigger_error('Site-specific url_manager called without a site_id in the constructor.  It needs one.', HIGH);
     }
     // set up the directory that is the root of the web tree.
     $prefix = server_is_windows() ? '' : '/';
     $this->web_root = $prefix . trim_slashes(!empty($_SERVER['_']) ? WEB_PATH : $_SERVER['DOCUMENT_ROOT']) . '/';
     $this->test_full_base_url = WEB_PATH . trim_slashes(WEB_TEMP) . '/rewrites/';
     if (!is_dir($this->test_full_base_url)) {
         if (!mkdir_recursive($this->test_full_base_url)) {
             trigger_error('Unable to create the rewriting testing directory at ' . $this->test_full_base_url . ' .  Please create a directory at that location in order for Reason minisites to work.', HIGH);
         }
     }
     if (!is_writable($this->test_full_base_url)) {
         trigger_error('Directory at ' . $this->test_full_base_url . ' is not writable.  Please make that dir writable in order for Reason minisites to work.', HIGH);
     }
     $this->test_web_base_url = WEB_TEMP . 'rewrites/';
     $this->refresh_localhost_limiter_rule();
     if (!empty($site_id)) {
         $this->init_site($site_id);
     } else {
         $this->init_global();
     }
 }
Example #6
0
 function process()
 {
     $document = $this->get_element('asset');
     // see if document was uploaded successfully
     if (($document->state == 'received' or $document->state == 'pending') and file_exists($document->tmp_full_path)) {
         $path_parts = pathinfo($document->tmp_full_path);
         $suffix = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
         // if there is no extension/suffix, try to guess based on the MIME type of the file
         if (empty($suffix)) {
             $type_to_suffix = array('application/msword' => 'doc', 'application/vnd.ms-excel' => 'xls', 'application/vns.ms-powerpoint' => 'ppt', 'text/plain' => 'txt', 'text/html' => 'html');
             $type = $document->get_mime_type();
             if ($type) {
                 $m = array();
                 if (preg_match('#^([\\w-.]+/[\\w-.]+)#', $type, $m)) {
                     // strip off any ;charset= crap
                     $type = $m[1];
                     if (!empty($type_to_suffix[$type])) {
                         $suffix = $type_to_suffix[$type];
                     }
                 }
             }
         }
         if (empty($suffix)) {
             $suffix = 'unk';
             trigger_error('uploaded asset at ' . $document->tmp_full_path . ' had an indeterminate file extension ... assigned to .unk');
         }
         // set up values for insertion into the DB
         // set file size
         $this->set_value('file_size', round(filesize($document->tmp_full_path) / 1024));
         // set mime type
         $this->set_value('mime_type', get_mime_type($document->tmp_full_path, 'application/octet-stream'));
         // set file type
         $this->set_value('file_type', $suffix);
         $asset_dest = ASSET_PATH . $this->_id . '.' . $suffix;
         // move the file - if windows and the destination exists, unlink it first.
         if (server_is_windows() && file_exists($asset_dest)) {
             unlink($asset_dest);
         }
         rename($document->tmp_full_path, $asset_dest);
     }
     // make sure to ignore the 'asset' field
     $this->_process_ignore[] = 'asset';
     // and, call the regular CM process method
     parent::process();
 }
/**
 * Used to update an asset that is already in the filesystem.
 *
 * @param int asset_id id of asset
 * @param int user_id id of person modifying asset
 * @param file array with keys: path, name
 * @return mixed entity_id of existing asset or FALSE on failure
 */
function reason_update_asset($asset_id, $user_id, $file)
{
    if (!is_null($asset_id)) {
        if (empty($asset_id) || intval($asset_id) != $asset_id) {
            trigger_error('reason_update_asset was provided an invalid asset_id parameter (' . $asset_id . ')');
            return false;
        } else {
            $asset = new entity(intval($asset_id));
            if (!reason_is_entity($asset, 'asset')) {
                trigger_error('reason_update_asset was provided a asset_id that is not a reason asset entity id (' . $asset_id . ')');
                return false;
            }
        }
    }
    if (empty($user_id) || intval($user_id) != $user_id) {
        trigger_error('reason_update_asset was provided an invalid user_id parameter (' . $user_id . ')');
        return false;
    } else {
        $user = new entity(intval($user_id));
        if (!reason_is_entity($user, 'user')) {
            trigger_error('reason_update_asset was provided a user_id that is not a reason user entity id (' . $user_id . ')');
            return false;
        }
    }
    if (empty($file) || !is_array($file)) {
        trigger_error('reason_update_asset requires the file parameter to be an array with keys path, name');
        return false;
    } elseif (empty($file['path']) || !file_exists($file['path'])) {
        if (empty($file['path'])) {
            trigger_error('reason_update_asset requires a file parameter with a key "path" that contains the full path to a file');
        } else {
            trigger_error('reason_update_asset was provided a file path (' . $file['path'] . ') that does not exist');
        }
        return false;
    } elseif (empty($file['name'])) {
        trigger_error('reason_update_asset requires a file parameter with a key "name" that specifies what filename should be used for downloading the file');
        return false;
    }
    $cur_path = reason_get_asset_filesystem_location($asset);
    $cur_name = $asset->get_value('file_name');
    // if our name or path has changed lets update the asset
    if ($file['path'] != $cur_path || $file['name'] != $cur_name) {
        $asset_owner = $asset->get_owner();
        $values['mime_type'] = get_mime_type($file['path'], 'application/octet-stream');
        $values['file_name'] = _reason_get_asset_filename($asset_owner->id(), $file['name'], $asset->id());
        $values['file_type'] = _reason_get_asset_extension($file['path'], $values['mime_type']);
        $values['file_size'] = _reason_get_asset_size($file['path']);
        // if the entity update changed the file name lets do rewrites.
        if (reason_update_entity($asset->id(), $user_id, $values, false)) {
            if ($cur_name != $values['file_name']) {
                $um = new url_manager($asset_owner->id());
                $um->update_rewrites();
            }
        }
        if ($file['path'] != $cur_path) {
            $asset_dest = ASSET_PATH . $asset_id . '.' . $values['file_type'];
            if (server_is_windows() && file_exists($asset_dest)) {
                unlink($asset_dest);
            }
            rename($file['path'], $asset_dest);
        }
        return $asset_id;
    }
    return false;
}