private function resizeImage($source, $parameters, $preview = false, $custom_settings = null)
 {
     // TODO *******
     //
     // Leider bietet diese drecks GD-Lib keine M�glichkeit, einen "out of memory"-Fehler zu umgehen,
     // oder vorauszusehen, wann ein Bild zu gro� f�r den Speicher ist.
     //
     // Daher sollte hier noch ein Mechanismus geschaffen werden, um voraus zu berechnen, wieviel Speicher
     // es brauchen wird, das Bild zu laden und einen Fehlercode zur�ckzugeben, falls der Speicher nicht reicht!
     // gew�nschte JPEG-Kompression feststellen
     $source_path_info = pathinfo($source);
     $source_ext = UTF8String::strtolower($source_path_info['extension']);
     if ($source_ext == 'jpg' || $source_ext == 'jpg' || $source_ext == 'jpe') {
         if ($this->isParameterPositiveNumber($parameters, 'jpegQuality')) {
             $jpeqQuality = $parameters['jpegQuality'];
         } else {
             $jpeqQuality = Config::get()->jpegQuality;
         }
     } else {
         $jpeqQuality = null;
     }
     // Erstmal keine Gr��en�nderung annehmen
     $mode = 'copy';
     // Pr�fen, ob maximal-Werte angegeben sind
     $max_width = 0;
     $max_height = 0;
     if ($this->isParameterPositiveNumber($parameters, 'maxWidth')) {
         $max_width = $parameters['maxWidth'];
     }
     if ($this->isParameterPositiveNumber($parameters, 'maxHeight')) {
         $max_height = $parameters['maxHeight'];
     }
     // Wenn Maximal-Werte gesetzt sind, Einpassung annehmen
     if ($max_width > 0 || $max_height > 0) {
         $mode = 'fitIn';
     }
     // Pr�fen, ob genaue Abmessungen gefordert sind
     $force_width = 0;
     $force_height = 0;
     if ($this->isParameterPositiveNumber($parameters, 'forceWidth')) {
         $force_width = $parameters['forceWidth'];
     }
     if ($this->isParameterPositiveNumber($parameters, 'forceHeight')) {
         $force_height = $parameters['forceHeight'];
     }
     // ggf. Benutzereingaben auswerten
     if ($custom_settings !== null) {
         // der Benutzer hat selbst eine Gr��e festgelegt...
         // diese Werte �berschreiben forceWidth und forceHeight
         if ($this->sanitizeBoolean($custom_settings['customSize'])) {
             if ($this->sanitizeInteger($custom_settings['width']) > 0) {
                 $force_width = $this->sanitizeInteger($custom_settings['width']);
             } else {
                 $force_width = 0;
             }
             if ($this->sanitizeInteger($custom_settings['height']) > 0) {
                 $force_height = $this->sanitizeInteger($custom_settings['height']);
             } else {
                 $force_height = 0;
             }
         }
         // der Benutzer hat einen Ausschnitt festgelegt oder die s/w option gew�hlt...
         if ($this->sanitizeBoolean($custom_settings['customCrop']) || $this->sanitizeBoolean($custom_settings['convertToBlackAndWhite'])) {
             $tmp_file = APPLICATION_ROOT . 'user-data/tmp/images/' . $this->getRandomFilenameWithTimeStamp($source);
             $tmp_image = WideImage::load($source);
             if ($this->sanitizeBoolean($custom_settings['customCrop'])) {
                 $tmp_image = $tmp_image->crop($this->sanitizeInteger($custom_settings['cropX1']), $this->sanitizeInteger($custom_settings['cropY1']), $this->sanitizeInteger($custom_settings['cropX2']) - $this->sanitizeInteger($custom_settings['cropX1']), $this->sanitizeInteger($custom_settings['cropY2']) - $this->sanitizeInteger($custom_settings['cropY1']));
             }
             if ($this->sanitizeBoolean($custom_settings['convertToBlackAndWhite'])) {
                 $tmp_image = $tmp_image->asGrayscale();
             }
             $this->saveImage($tmp_image, $tmp_file, $jpeqQuality);
             $tmp_image->destroy();
             $source = $tmp_file;
         }
     }
     // Wenn genaue Abmessungen gefordert sind, entsprechenden Modus setzen...
     if ($force_width > 0 && $force_height > 0) {
         $mode = 'exact';
     } elseif ($force_width > 0) {
         $mode = 'forceWidth';
     } elseif ($force_height > 0) {
         $mode = 'forceHeight';
     }
     // Tempor�ren Dateinamen erstellen
     $temp_file_name = $this->getRandomFilenameWithTimeStamp($source);
     $relative_path_to_dest_file = 'user-data/tmp/images/' . $temp_file_name;
     $absolute_path_to_dest_file = APPLICATION_ROOT . $relative_path_to_dest_file;
     // Je nach Modus Bild kopieren / ge�nderte Version speichern
     $result = true;
     try {
         switch ($mode) {
             case 'copy':
                 // keine Gr��en�nderung erfoderlich
                 $result = FileUtils::copyFile($source, $absolute_path_to_dest_file);
                 break;
             case 'exact':
                 // Gr��e genau vorgegeben
                 $image = WideImage::load($source);
                 $image_dimensions = $this->getDimensions($image);
                 $resized_image = $image->resize($force_width, $force_height, 'outside', 'any');
                 $resized_image_dimensions = $this->getDimensions($resized_image);
                 $image->destroy();
                 if ($resized_image->getWidth() > $force_width || $resized_image->getHeight() > $force_height) {
                     $crop_x = 0;
                     if ($resized_image->getWidth() > $force_width) {
                         $crop_x = floor(($resized_image->getWidth() - $force_width) / 2);
                     }
                     $crop_y = 0;
                     if ($resized_image->getHeight() > $force_height) {
                         $crop_y = floor(($resized_image->getHeight() - $force_height) / 2);
                     }
                     $cropped_image = $resized_image->crop($crop_x, $crop_y, $force_width, $force_height);
                     $resized_image->destroy();
                     $this->saveImage($cropped_image, $absolute_path_to_dest_file, $jpeqQuality);
                     $cropped_image->destroy();
                 } else {
                     if ($this->equalDimensions($image_dimensions, $resized_image_dimensions)) {
                         FileUtils::copyFile($source, $absolute_path_to_dest_file);
                     } else {
                         $this->saveImage($resized_image, $absolute_path_to_dest_file, $jpeqQuality);
                     }
                     $resized_image->destroy();
                 }
                 break;
             case 'forceWidth':
                 // Breite vorgegeben
                 $image = WideImage::load($source);
                 $image_dimensions = $this->getDimensions($image);
                 $resized_image = $image->resize($force_width, null, 'outside', 'any');
                 $resized_image_dimensions = $this->getDimensions($resized_image);
                 $image->destroy();
                 if ($max_height > 0 && $resized_image->getHeight() > $max_height) {
                     $crop_y = 0;
                     if ($resized_image->getHeight() > $max_height) {
                         $crop_y = floor(($resized_image->getHeight() - $max_height) / 2);
                     }
                     $cropped_image = $resized_image->crop(0, $crop_y, $force_width, $max_height);
                     $resized_image->destroy();
                     $this->saveImage($cropped_image, $absolute_path_to_dest_file, $jpeqQuality);
                     $cropped_image->destroy();
                 } else {
                     if ($this->equalDimensions($image_dimensions, $resized_image_dimensions)) {
                         FileUtils::copyFile($source, $absolute_path_to_dest_file);
                     } else {
                         $this->saveImage($resized_image, $absolute_path_to_dest_file, $jpeqQuality);
                     }
                     $resized_image->destroy();
                 }
                 break;
             case 'forceHeight':
                 // H�he vorgegeben
                 $image = WideImage::load($source);
                 $image_dimensions = $this->getDimensions($image);
                 $resized_image = $image->resize(null, $force_height, 'outside', 'any');
                 $resized_image_dimensions = $this->getDimensions($resized_image);
                 $image->destroy();
                 if ($max_width > 0 && $resized_image->getWidth() > $max_width) {
                     $crop_x = 0;
                     if ($resized_image->getWidth() > $max_width) {
                         $crop_x = floor(($resized_image->getWidth() - $max_width) / 2);
                     }
                     $cropped_image = $resized_image->crop($crop_x, 0, $max_width, $force_height);
                     $resized_image->destroy();
                     $this->saveImage($cropped_image, $absolute_path_to_dest_file, $jpeqQuality);
                     $cropped_image->destroy();
                 } else {
                     if ($this->equalDimensions($image_dimensions, $resized_image_dimensions)) {
                         FileUtils::copyFile($source, $absolute_path_to_dest_file);
                     } else {
                         $this->saveImage($resized_image, $absolute_path_to_dest_file, $jpeqQuality);
                     }
                     $resized_image->destroy();
                 }
                 break;
             case 'fitIn':
                 // in angegebenes Rechteck einpassen
                 $image = WideImage::load($source);
                 $image_dimensions = $this->getDimensions($image);
                 if ($max_width == 0) {
                     $max_width = null;
                 }
                 if ($max_height == 0) {
                     $max_height = null;
                 }
                 $resized_image = $image->resize($max_width, $max_height, 'inside', 'down');
                 $resized_image_dimensions = $this->getDimensions($resized_image);
                 $image->destroy();
                 if ($this->equalDimensions($image_dimensions, $resized_image_dimensions)) {
                     FileUtils::copyFile($source, $absolute_path_to_dest_file);
                 } else {
                     $this->saveImage($resized_image, $absolute_path_to_dest_file, $jpeqQuality);
                 }
                 $resized_image->destroy();
                 break;
         }
     } catch (WideImage_Exception $e) {
         $result = false;
     }
     // im Erfolgsfall zum Stammverzeichnis relativen Pfad zur�ckgeben
     if ($result) {
         // M�glicherweise wird das Bild nochmal von einem geladenen Plugin bearbeitet
         $plugin_parameters = array('source' => $source, 'parameters' => $parameters, 'preview' => $preview, 'customSettings' => $custom_settings);
         Plugins::call(Plugins::AFTER_IMAGE_RESIZE, $plugin_parameters, $relative_path_to_dest_file);
         return $relative_path_to_dest_file;
     } else {
         return false;
     }
 }
 public function getSearchResultForFrontend($search_string, $columns, $page_id, $language_id)
 {
     if (is_array($columns) && count($columns) == 0) {
         $columns = null;
     }
     if ($columns === null) {
         $columns = array();
         foreach ($this->fields as $field) {
             if (isset($field['dbFieldType'])) {
                 if ($field['dbFieldType'] == 'string') {
                     $columns[] = $field['id'];
                 }
             }
         }
     } else {
         $columns = array_map(function ($column_id) {
             return trim($column_id);
         }, $columns);
         $columns = array_filter($columns, function ($string) {
             return UTF8String::strlen($string) > 0;
         });
     }
     $sanitized_search_string = UTF8String::strtolower(trim($search_string));
     $search_array = array_filter(explode(' ', $sanitized_search_string), function ($string) {
         return UTF8String::strlen($string) > 0;
     });
     $result = array();
     if (count($columns) > 0 && count($search_array) > 0) {
         $rows = $this->getAllRowsForFrontend($page_id, $language_id);
         if ($rows !== false) {
             if (count($rows) > 0) {
                 foreach ($rows as $row) {
                     $row_contains_search_string = false;
                     foreach ($columns as $column_id) {
                         if (isset($row[$column_id])) {
                             if ($this->doesFieldValueContainSearchString($row[$column_id], $search_array)) {
                                 $row_contains_search_string = true;
                                 break;
                             }
                         }
                     }
                     if ($row_contains_search_string) {
                         $result[] = $row;
                     }
                 }
             }
         }
     }
     return $result;
 }
 public function sanitizeBoolean($boolish_string)
 {
     if (is_bool($boolish_string)) {
         return $boolish_string;
     } else {
         if (is_numeric($boolish_string)) {
             $boolish_int = (int) $boolish_string;
             if ($boolish_int != 0) {
                 return true;
             } else {
                 return false;
             }
         } else {
             $boolish_string = trim(UTF8String::strtolower($boolish_string));
             if ($boolish_string == 'true') {
                 return true;
             } else {
                 return false;
             }
         }
     }
 }
 public function onDataEditorPluginPrepareForOutput($parameters, &$data)
 {
     if ($parameters['fieldType'] == 'link') {
         $edit_data = null;
         if (isset($data)) {
             if (is_array($data)) {
                 if (isset($data['url'])) {
                     if (is_string($data['url'])) {
                         $edit_data = array('url' => $data['url']);
                         if (isset($data['newWindow'])) {
                             $edit_data['newWindow'] = $data['newWindow'];
                         } else {
                             $edit_data['newWindow'] = 'auto';
                         }
                         $edit_data['type'] = 'external';
                         $auto_link_target = '';
                         if (UTF8String::strtolower(UTF8String::substr($data['url'], 0, UTF8String::strlen('link://'))) == 'link://') {
                             $edit_data['type'] = 'internal';
                         } elseif (UTF8String::strtolower(UTF8String::substr($data['url'], 0, UTF8String::strlen('download://'))) == 'download://') {
                             $edit_data['type'] = 'download';
                         }
                         switch ($edit_data['type']) {
                             case 'external':
                                 $edit_data['url'] = $data['url'];
                                 $auto_link_target = '_blank';
                                 break;
                             case 'internal':
                                 $edit_data['url'] = Config::get()->baseUrl . UTF8String::substr($data['url'], UTF8String::strlen('link://'));
                                 $auto_link_target = '';
                                 break;
                             case 'download':
                                 $edit_data['url'] = Config::get()->baseUrl . 'user-data/downloads/' . UTF8String::substr($data['url'], UTF8String::strlen('download://'));
                                 $auto_link_target = '_blank';
                                 $edit_data['path'] = APPLICATION_ROOT . 'user-data/downloads/' . urldecode(UTF8String::substr($data['url'], UTF8String::strlen('download://')));
                                 $path_info = pathinfo($edit_data['path']);
                                 $edit_data['basename'] = isset($path_info['basename']) ? $path_info['basename'] : '';
                                 $edit_data['extension'] = isset($path_info['extension']) ? $path_info['extension'] : '';
                                 $edit_data['filename'] = isset($path_info['filename']) ? $path_info['filename'] : '';
                                 if (file_exists($edit_data['path'])) {
                                     $edit_data['filesize'] = @filesize($edit_data['path']);
                                 }
                                 break;
                             default:
                                 break;
                         }
                         switch ($edit_data['newWindow']) {
                             case 'yes':
                                 $edit_data['target'] = '_blank';
                                 break;
                             case 'no':
                                 $edit_data['target'] = '';
                                 break;
                             default:
                                 $edit_data['target'] = $auto_link_target;
                                 break;
                         }
                     }
                 }
             }
         }
         $data = $edit_data;
     }
 }
            $action = 'default';
        }
        $method = $action . 'Action';
        // Datei inkludieren
        require_once APPLICATION_ROOT . 'system/core/backend/controllers/' . $folder . '/' . $file;
        // Prüfen, ob Klasse existiert
        if (!class_exists($class)) {
            Helpers::fatalError('Page not found (class "' . $class . '" doesn\'t exist in system/core/backend/controllers/' . $folder . '/' . $file . ')!', true);
        }
        // Klasse instanziieren
        $controller = new $class($module);
        // Prüfen, ob Methode existiert
        if (!method_exists($controller, $method)) {
            Helpers::fatalError('Page not found (class-method "' . $method . '" doesn\'t exist in class "' . $class . '" ist in system/core/backend/controllers/' . $folder . '/' . $file . ')!', true);
        }
        // View erzeugen und mit Controller verbinden
        $view = new View();
        $view->assignTemplate(APPLICATION_ROOT . 'system/core/backend/views/' . $folder . '/' . UTF8String::strtolower($file));
        $view->assign('baseUrl', Config::get()->baseUrl);
        $view->assign('moduleUrl', Config::get()->baseUrl . 'admin/' . $folder . '/' . $module . '/');
        $view->assign('publicUrl', Config::get()->baseUrl . 'system/core/backend/public/');
        $view->assign('backendLanguage', $language_id);
        $controller->assignView($view);
        // Action-Methode ausführen
        $controller->callActionMethod($action);
        // Ausgabe des Views...
        if ($controller->getView() != null) {
            $controller->getView()->output();
        }
    }
}
 private function replaceLinkPlaceholders($url)
 {
     if (UTF8String::strtolower(UTF8String::substr($url, 0, UTF8String::strlen('link://'))) == 'link://') {
         $url = Config::get()->baseUrl . UTF8String::substr($url, UTF8String::strlen('link://'));
     } elseif (UTF8String::strtolower(UTF8String::substr($url, 0, UTF8String::strlen('download://'))) == 'download://') {
         $url = Config::get()->baseUrl . 'user-data/downloads/' . UTF8String::substr($url, UTF8String::strlen('download://'));
     }
     return $url;
 }
 private function getRandomFilename($orig_filename)
 {
     $info = pathinfo($orig_filename);
     $ext = UTF8String::strtolower($info['extension']);
     return md5(uniqid() . time() . rand(1, 99999)) . '.' . $ext;
 }