Exemplo n.º 1
0
 /**
  * Validates the uploaded file and return a boolean to tell if valid
  * This method should be overridden when you need to write special validation scripts
  *
  * @param string path to input file
  * @param string path to output file (by ref.), making sure you create a struct that matches the $_FILES[][] format
  *
  * @return boolean
  */
 protected function validateUploadedFile($input, &$output)
 {
     $errmsg = null;
     // Only if GD is available, resize to max size
     if (Dependency::check("gd", $errmsg)) {
         // Extract image metadata
         list($width_orig, $height_orig, $type, $attr) = getimagesize($input['tmp_name']);
         // Check if it busts the max size
         if ($width_orig > $this->getMaxDisplayWidth() || $height_orig > $this->getMaxDisplayHeight()) {
             // Init with max values
             $width = $this->getMaxDisplayWidth();
             $height = $this->getMaxDisplayHeight();
             // Compute ratios
             $ratio_orig = $width_orig / $height_orig;
             if ($this->getMaxDisplayWidth() / $this->getMaxDisplayHeight() > $ratio_orig) {
                 $width = $height * $ratio_orig;
             } else {
                 $height = $width / $ratio_orig;
             }
             // Resample
             $image_p = imagecreatetruecolor($width, $height);
             $image = imagecreatefromstring(file_get_contents($input['tmp_name']));
             if (!$image) {
                 pretty_print_r(gd_info());
                 throw new Exception(_("Unable to process image (GD probably doesn't have support for it enabled)"));
             } else {
                 imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
             }
             // Build output metadata struct
             $output = array();
             $output['tmp_name'] = tempnam("/tmp", session_id());
             $output['type'] = "image/png";
             $output['name'] = $input['name'];
             // Output PNG at full compression (no artefact)
             imagepng($image_p, $output['tmp_name'], 9);
             // Write new file size
             $output['size'] = filesize($output['tmp_name']);
         }
     }
     return true;
 }
Exemplo n.º 2
0
                          color: #333333; display: block; 
                          font-size: 13px; 
                          line-height: 1.42857;
                          margin:0 auto 10px;padding: 9.5px;
                          word-break: break-all;
                          word-wrap: break-word;
                          width:90%"';
//<pre> format main data array
ob_start();
echo "<pre {$pre_css}>";
echo '<STRONG><h2>Debugging & Profiling</h2></STRONG><br/>';
$data['conf'] = $conf;
foreach ($data as $key => $value) {
    if (is_array($data[$key])) {
        echo "<pre><pre><strong>[{$key}]</strong></pre>";
        pretty_print_r($value);
        echo "</pre>";
    } else {
        echo "<pre>{$value}</pre>";
    }
}
echo '</pre>';
$all_data = ob_get_contents();
ob_end_clean();
// if debug level 2: send to modal
if ($this->config->item('debug_mode') == 2) {
    $data['vars']['debug_mode'] = 2;
    $data['vars']['debuuging_output'] = $all_data;
}
// -- TBS ----------------------------------------------------------------------------------------------------------------
/**
Exemplo n.º 3
0
 /** 
  * Parses a string containing an complex array in PHP array() syntax 
  * All leaves must be strings Indexes aren't supported
  * @param $string The string to be parsed
  * @return array
  */
 public static function parseScalarArray($string, $debug = false)
 {
     if ($debug) {
         echo "Original string: <br/>{$string}";
     }
     $chunks = preg_split("/(array|,|\\(|\\))+?/", $string, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
     foreach ($chunks as $index => $chunk) {
         $chunks[$index] = trim($chunk);
         if (empty($chunks[$index])) {
             unset($chunks[$index]);
         }
     }
     if ($debug) {
         pretty_print_r($chunks);
     }
     $retval = null;
     $current = null;
     $numParen = 0;
     foreach ($chunks as $index => $chunk) {
         //Strip the bloody array indexes!
         preg_match("/(?:\\s*\\d*\\s=>\\s*)?(.*)/", $chunk, $matches);
         //pretty_print_r($matches);
         $chunk = $matches[1];
         switch ($chunk) {
             case 'array':
                 break;
             case ',':
                 break;
             case '(':
                 $numParen++;
                 $parent = $current;
                 $current['array'] = array();
                 $current['parent'] = $parent;
                 break;
             case ')':
                 $numParen--;
                 if ($current['parent'] == null) {
                     break;
                 }
                 $current['parent']['array'][] = $current['array'];
                 //pretty_print_r($current);
                 $current = $current['parent'];
                 break;
             default:
                 $chunk = trim($chunk, "\"'");
                 if (!empty($chunk)) {
                     $current['array'][] = trim($chunk, "\"'");
                 }
         }
         if ($debug && $chunk != 'array' && $chunk != ',') {
             echo "Chunk: {$chunk}  numParen: {$numParen}, current:";
             pretty_print_r($current);
             echo "<hr/>";
         }
     }
     if ($numParen != 0) {
         throw new exception("Unparseable string");
     }
     $retval = $current['array'];
     return $retval;
 }