diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e6e8feb --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +config/admin.ini +config/database.config.ini diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..13d9dc2 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "public/lib/codemirror"] + path = public/lib/codemirror + url = git@github.com:marijnh/CodeMirror.git diff --git a/README.textile b/README.textile index 5569700..194deee 100644 --- a/README.textile +++ b/README.textile @@ -8,15 +8,15 @@ Katharsis Framework is written in native, object-orientated PHP5 code only. It k h1. List of Features -# lightweight and fast processing -# facilitates project maintenance by keeping your code clean -# preserves a tidy project structure -# provides great extensibility -# easy-to-use plugin interface -# supports "pretty URLs" -# entirely object orientated +* lightweight and fast processing +* facilitates project maintenance by keeping your code clean +* preserves a tidy project structure +* provides great extensibility +* easy-to-use plugin interface +* supports "pretty URLs" +* entirely object orientated h1. Requirements -# PHP enabled web server -# PHP v. 5.0 or greater \ No newline at end of file +* PHP enabled web server +* PHP v. 5.0 or greater \ No newline at end of file diff --git a/application/controller/AdminController.php b/application/controller/AdminController.php new file mode 100644 index 0000000..60687fd --- /dev/null +++ b/application/controller/AdminController.php @@ -0,0 +1,45 @@ +_location('gate'); + } + + public function gateAction() + { + } + + public function loginAction() + { + if($this->_getParam('password') == $this->getPassword()) + { + $_SESSION['logged'] = 1; + $this->_location('index'); + } + else + { + $this->_location('gate', null, array('wrongpassword' => '')); + } + + } + + public function logoutAction() + { + $_SESSION['logged'] = 0; + $this->_location('index', 'index'); + } + + // Private + + private function getPassword() + { + $path = 'config/admin.ini'; + if(!is_readable($path)) die($path . " not found"); + + $admin_ini = parse_ini_file($path); + $password = $admin_ini["password"]; + + return $password; + } +} diff --git a/application/controller/AdminNavigationController.php b/application/controller/AdminNavigationController.php new file mode 100644 index 0000000..dcf0ec3 --- /dev/null +++ b/application/controller/AdminNavigationController.php @@ -0,0 +1,53 @@ +_navi = new Navigation(); + } + + public function indexAction() + { + $this->_view->list = $this->_navi->getAllItems(false); + } + + public function editAction() + { + $this->_view->mainItems = $this->_navi->getMainItems(); + $this->_view->item = $this->_navi->getItem($this->_getParam('id')); + $this->_view->sites = $this->_navi->getSites(); + } + + public function deleteAction() + { + $this->_navi->delete($this->_getParam('id')); + DidgeridooArtwork_Notice::add('Navigationseintrag wurde erfolgreich gelöscht!'); + $this->_location('index'); + } + + public function saveAction() + { + $params = $this->_getAllParams(); + + $params['active'] = 0; + if($this->_getParam('active') && $this->_getParam('active') == 'on') + { + $params['active'] = 1; + } + + $params['parentId'] = ($params['parentId'] == '0') ? null : $params['parentId']; + + $this->_navi->save($params); + DidgeridooArtwork_Notice::add('Navigationseintrag wurde erfolgreich gespeichert!'); + $this->_location('index'); + } + + public function moveAction() + { + $this->_navi->move($this->_getParam('direction'), $this->_getParam('id')); + DidgeridooArtwork_Notice::add('Navigationseintrag wurde erfolgreich verschoben!'); + $this->_location('index'); + } +} diff --git a/application/controller/AdminPageController.php b/application/controller/AdminPageController.php new file mode 100644 index 0000000..486e57e --- /dev/null +++ b/application/controller/AdminPageController.php @@ -0,0 +1,96 @@ +_page = new Page(); + } + + public function indexAction() + { + $this->_view->pages = $this->_page->getPages(); + } + + public function editAction() + { + $this->_view->page = $this->_page->getPage($this->_getParam('pageId')); + } + + public function imageAction() + { + if($this->_getParam('type') == 'header') { + $type = 'header'; + } else { + $type = 'page'; + } + $this->_view->type = $type; + + $path = getcwd().'/public/img/' . $type . '/'; + + if(isset($_FILES['myfile'])) + { + $upload = new Upload(); + + if($type == 'header') { + $imagePath = $upload->header($_FILES['myfile']); + } else { + $imagePath = $upload->page($_FILES['myfile']); + } + + $this->_view->imagePath = $imagePath; + + echo $this->_view->render('AdminPage/uploadsuccess'); + die(); + } + + + if(isset($_GET['delete'])) + { + $deleteFile = $path . $_GET['delete']; + + if(file_exists($deleteFile)) { + unlink($deleteFile); + } + } + + $ar = array(); + if (is_readable($path) && $handle = opendir($path)) + { + while (false !== ($file = readdir($handle))) { + if(is_dir($file)) continue; + $ar[] = $file; + } + + closedir($handle); + } + + $this->_view->files = $ar; + echo $this->_view->render('AdminPage/image'); + + die(); + } + + public function saveAction() + { + $params = $this->_getAllParams(); + + $params['active'] = 0; + if($this->_getParam('active') && $this->_getParam('active') == 'on') + { + $params['active'] = 1; + } + + $this->_page->save($params); + DidgeridooArtwork_Notice::add('Page wurde erfolgreich gespeichert!'); + $this->_location($this->_getParam('url'), 'page'); + } + + public function deleteAction() + { + $this->_page->delete($this->_getParam('pageId')); + DidgeridooArtwork_Notice::add('Page wurde erfolgreich gelöscht!'); + $this->_location('index'); + } +} diff --git a/application/controller/AdminUploadController.php b/application/controller/AdminUploadController.php new file mode 100644 index 0000000..11bd305 --- /dev/null +++ b/application/controller/AdminUploadController.php @@ -0,0 +1,5 @@ +_view->someVariableName = 'Katharsis'; - echo $this->_view->render('welcome'); + // will be overwritten by IndexRedirect Plugin } /** diff --git a/application/controller/PageController.php b/application/controller/PageController.php new file mode 100644 index 0000000..915d3f2 --- /dev/null +++ b/application/controller/PageController.php @@ -0,0 +1,40 @@ +_page = new Page(); + } + + public function __call($method, $args) + { + $preview = false; + if(array_key_exists('preview', $this->_getAllParams()) && Access::isLoggedIn()) + { + $preview = true; + } + + $url = substr($method, 0, -6); // remove Action from urlAction + + $pageId = $this->_page->getIdByUrl($url, $preview); + + if(!$pageId) { + throw new DidgeridooArtwork_Exception('Page konnte nicht geladen werden.'); + } + + $pageData = $this->_page->getPage($pageId); + + foreach($pageData as $key => $value) { + $this->_view->{$key} = $value; + } + + $this->_view->content = DidgeridooArtwork_Page_Plugin::render($this->_view->content); + + $content = $this->_view->render('Page/post'); + $this->_view->stageContent = $content; + echo $this->_view->render('main'); + die(); + } +} diff --git a/application/model/Access.php b/application/model/Access.php new file mode 100644 index 0000000..32f684d --- /dev/null +++ b/application/model/Access.php @@ -0,0 +1,16 @@ + - * @version 0.5.2 - * @package Katharsis - */ -class Example extends Katharsis_Model_Abstract -{ - /** - * Init method, will be called when this class is instanced - * Use this method instead of __construct() - * - * @return void - */ - public function init() - { - } -} \ No newline at end of file diff --git a/application/model/Navigation.php b/application/model/Navigation.php new file mode 100644 index 0000000..7bfeb1b --- /dev/null +++ b/application/model/Navigation.php @@ -0,0 +1,297 @@ +_con->fetchAll("SELECT * FROM navigation WHERE parent_id IS NULL " . $activityStatement . " ORDER BY sorting"); + foreach($result as $item) + { + $subSet = array(); + $sql = "SELECT * FROM navigation WHERE parent_id = :parentId ORDER BY sorting"; + $sql = $this->_con->createStatement($sql, array('parentId' => $item['id'])); + + $item['children'] = $this->_con->fetchAll($sql); + $tidyResult[] = $item; + } + return $tidyResult; + } + + public function getMainItems() + { + return $this->_con->fetchAll("SELECT id, name FROM navigation WHERE parent_id IS NULL AND active = 1 ORDER BY sorting"); + } + + public function getItem($id) + { + if($id !== null) + { + $sql = "SELECT * FROM navigation WHERE id = :id"; + $sql = $this->_con->createStatement($sql, array('id' => $id)); + if(!$result = $this->_con->fetchOne($sql)) + { + throw new DidgeridooArtwork_Exception('Item with this id not existent'); + } + } + else + { + $sql = "SHOW COLUMNS FROM navigation"; + $res = $this->_con->fetchAll($sql); + foreach($res as $it) + { + $result[$it['Field']] = ''; + } + } + + return $result; + } + + public function add() + { + } + + public function delete($id) + { + $sql = "DELETE FROM navigation WHERE id = :id"; + $sql = $this->_con->createStatement($sql, array('id' => $id)); + $this->_con->run($sql); + } + + public function move($direction, $id) + { + $sql = "SELECT sorting, parent_id FROM navigation WHERE id = :id"; + $sql = $this->_con->createStatement($sql, array('id' => $id)); + + if($active = $this->_con->fetchOne($sql)) + { + $parentPart = ($active['parent_id'] === null) ? "parent_id IS NULL" : "parent_id = :parentId"; + + if($direction == 'up') + { + $sql = "SELECT id, sorting FROM navigation + WHERE + " . $parentPart . " + AND sorting < :sorting + ORDER BY sorting DESC + LIMIT 1 + "; + } + else if($direction == 'down') + { + $sql = "SELECT id, sorting FROM navigation + WHERE + " . $parentPart . " + AND sorting > :sorting + ORDER BY sorting ASC + LIMIT 1 + "; + } + else + { + throw new DidgeridooArtwork_Exception('Wrong Direction'); + } + + $sql = $this->_con->createStatement($sql, array(':id' => $id, 'parentId' => $active['parent_id'], 'sorting' => $active['sorting'])); + + $passiveItem = $this->_con->fetchOne($sql); + + //updating active item + $sql = "UPDATE navigation SET sorting = :sorting WHERE id = :id"; + $sql = $this->_con->createStatement($sql, array('id' => $id, 'sorting' => $passiveItem['sorting'])); + $this->_con->run($sql); + + //updating passive item + $sql = "UPDATE navigation SET sorting = :sorting WHERE id = :id"; + $sql = $this->_con->createStatement($sql, array('id' => $passiveItem['id'], 'sorting' => $active['sorting'])); + $this->_con->run($sql); + } + else + { + throw new DidgeridooArtwork_Exception('Wrong Parameters'); + } + } + + public static function buildLink($base, $item, $simpleMode = false) + { + if($item['link'] !== null) + { + return $item['link']; + } + + $link = $base . '/' . $item['controller']; + if($simpleMode) + { + $link = $item['controller']; + } + + if($item['action'] !== null) + { + $link .= '/' . $item['action']; + + if($simpleMode) return $link; + + if($item['controller'] == 'page') + { + $link .= '/preview'; + } + } + + return $link; + } + + public static function getTitle() + { + + if(substr(Katharsis_Request::getControllerName(), 0, 5) == 'admin') + { + return 'Admin'; + } + + $con = Katharsis_DatabaseConnector::getConnection(); + + if(Katharsis_Request::getControllerName() == 'page') + { + $sql = "SELECT title FROM page WHERE url = :url"; + $sql = $con->createStatement($sql, array('url' => Katharsis_Request::getActionName())); + if($field = $con->fetchField($sql)) + { + return $field; + } + } + + $menuItemId = Katharsis_View::getInstance()->activeMenuItem; + $sql = "SELECT name FROM navigation WHERE id = :menuItemId"; + $sql = $con->createStatement($sql, array('menuItemId' => $menuItemId)); + if($field = $con->fetchField($sql)) + { + return $field; + } + + return Katharsis_Registry::getInstance()->defaults['title']; + } + + public static function getSubtitle() + { + $con = Katharsis_DatabaseConnector::getConnection(); + + if(Katharsis_Request::getControllerName() == 'page') + { + $sql = "SELECT subtitle FROM page WHERE url = :url"; + $sql = $con->createStatement($sql, array('url' => Katharsis_Request::getActionName())); + if($field = $con->fetchField($sql)) + { + return $field; + } + } + + return Katharsis_Registry::getInstance()->defaults['subtitle']; + } + + public function getSites() + { + $sql = "SELECT url FROM page"; + $sql = $this->_con->createStatement($sql, array('url' => Katharsis_Request::getActionName())); + $sites = $this->_con->fetchAll($sql); + + foreach($sites as &$site) + { + $site = 'page/' . $site['url']; + } + $sites = array( + 'defaults' => array(), + 'pages' => $sites + ); + + if(isset(Katharsis_Registry::getInstance()->defaults['sites'])){ + $sites['defaults'] = explode(", ", Katharsis_Registry::getInstance()->defaults['sites']); + } + + + return $sites; + } + + public function save($params) + { + $transformed = $this->_transformUrl($params['url'], $params['external']); + + $values = array( + 'id' => $params['id'], + 'name' => $params['name'], + 'parent_id' => $params['parentId'], + 'active' => $params['active'] + ); + + $values = array_merge($values, $transformed); + + if(isset($values['id']) && is_numeric($values['id'])) + { + $sql = "UPDATE navigation + SET + name = :name, + controller = :controller, + action = :action, + link = :link, + parent_id = :parent_id, + active = :active + WHERE + id = :id + "; + + $sql = $this->_con->createStatement($sql, $values); + + $this->_con->run($sql); + } + else + { + if($values['parent_id'] === null) + { + $sql = "SELECT max(sorting) + 1 as maxi FROM `navigation` WHERE parent_id IS NULL"; + } + else + { + $sql = "SELECT max(sorting) + 1 as maxi FROM `navigation` WHERE parent_id = :parentId"; + $sql = $this->_con->createStatement($sql, array('parentId' => $values['parent_id'])); + } + + + $max = $this->_con->fetchField($sql); + $max = ($max === null) ? 1 : $max; + $values['sorting'] = $max; + + $this->_con->insert('navigation', $values); + } + } + + protected function _transformUrl($url, $external = null) + { + $values = array( + 'controller' => null, + 'action' => null, + 'link' => null + ); + + if($url == '-external-') + { + $values['link'] = $external; + return $values; + } + + $e = explode('/', $url); + if(array_key_exists(1, $e)) + { + $values['controller'] = $e[0]; + $values['action'] = $e[1]; + } + else + { + $values['controller'] = $url; + } + return $values; + } +} \ No newline at end of file diff --git a/application/model/Page.php b/application/model/Page.php new file mode 100644 index 0000000..164bb9e --- /dev/null +++ b/application/model/Page.php @@ -0,0 +1,86 @@ +_con->createStatement("SELECT id FROM page WHERE url = :url " . $activeTerm, array("url" => $url)); + + if($result = $this->_con->fetchOne($sql)){ + return $result['id']; + } + } + + public function getPages() + { + $sql = "SELECT id, title, subtitle, url, active FROM page ORDER BY id"; + return $this->_con->fetchAll($sql); + } + + public function getPage($pageId) + { + $default = $this->_con->getEmptyColumnArray('page'); + + if($pageId === null) return $default; + + $sql = "SELECT * FROM page WHERE id = :pageId"; + $sql = $this->_con->createStatement($sql, array('pageId' => $pageId)); + + if($result = $this->_con->fetchOne($sql)) + { + return $result; + } + return $default; + } + + public function save($params) + { + $values = array( + 'title' => $params['title'], + 'subtitle' => $params['subtitle'], + 'url' => $params['url'], + 'content' => $params['content'], + 'active' => $params['active'], + 'header_image' => $params['header_image'] + ); + + if(isset($params['id']) && is_numeric($params['id'])) + { + $values['id'] = $params['id']; + $sql = "UPDATE page + SET + title = :title, + subtitle = :subtitle, + url = :url, + content = :content, + active = :active, + header_image = :header_image + WHERE + id = :id + "; + $sql = $this->_con->createStatement($sql, $values); + $this->_con->run($sql); + } + else + { + $this->_con->insert('page', $values); + } + } + + public function delete($pageId) + { + $sql = "DELETE FROM page WHERE id = :pageId"; + $sql = $this->_con->createStatement($sql, array('pageId' => (int) $pageId)); + $this->_con->run($sql); + } +} +?> diff --git a/application/model/Upload.php b/application/model/Upload.php new file mode 100644 index 0000000..c740f82 --- /dev/null +++ b/application/model/Upload.php @@ -0,0 +1,55 @@ +_uploadFile(null, $file, $dir); + } + + public function page($file) + { + $dir = getcwd() . '/public/img/page'; + return $this->_uploadFile(null, $file, $dir, $file['name'] . '-' . time()); + } + + protected function _uploadFile($id, $file, $dir, $name = null) + { + $name = time(); + + if (!is_dir($dir)) { + mkdir($dir); + } + + $typeAccepted = array("image/jpeg", "image/gif", "image/png"); + if(!in_array($file['type'], $typeAccepted)) { + throw new DidgeridooArtwork_Exception('Hochladen fehlgeschlagen. Dateityp nicht akzeptiert. Nur jpeg, gif und png möglich'); + return false; + } + + $ext = ''; + switch($file['type']) { + case "image/jpeg": + $ext = '.jpg'; + break; + case "image/gif": + $ext = '.gif'; + break; + case "image/png": + $ext = '.png'; + break; + } + + if (!move_uploaded_file($file['tmp_name'], $dir . '/' . $name . $ext)) + { + throw new DidgeridooArtwork_Exception('Hochladen fehlgeschlagen. (move_uploaded_file: false)'); + return false; + } + return $name . $ext; + } +} \ No newline at end of file diff --git a/application/view/Admin/gate.phtml b/application/view/Admin/gate.phtml new file mode 100644 index 0000000..b1136ec --- /dev/null +++ b/application/view/Admin/gate.phtml @@ -0,0 +1,11 @@ +
+
+
+
Admin
+
+ _getParam('wrongpassword')) echo 'passwort falsch
' ?> + +
+
+
+
\ No newline at end of file diff --git a/application/view/Admin/index.phtml b/application/view/Admin/index.phtml new file mode 100644 index 0000000..6b1b498 --- /dev/null +++ b/application/view/Admin/index.phtml @@ -0,0 +1,5 @@ +
+

+ Willkommen im Admin Bereich. +

+
\ No newline at end of file diff --git a/application/view/AdminNavigation/edit.phtml b/application/view/AdminNavigation/edit.phtml new file mode 100644 index 0000000..8209ee2 --- /dev/null +++ b/application/view/AdminNavigation/edit.phtml @@ -0,0 +1,59 @@ +
+

Navigation/Menüpunkt bearbeiten

+ +
+ +
+
Aktiv
+
+ item['active']) echo 'checked="checked"' ?> /> +
+
+
+
Menüpunkttyp
+
+ +
+
+
+
Titel
+
+ +
+
+
+
Url
+
+ +sites['defaults'])): ?> + + + + + +
+sites['defaults'] as $key => $site): ?> +
+ +
+sites['pages'] as $key => $site): ?> +
+ +
+
+ +
+
+
+

+ +

+
+
\ No newline at end of file diff --git a/application/view/AdminNavigation/index.phtml b/application/view/AdminNavigation/index.phtml new file mode 100644 index 0000000..69ac968 --- /dev/null +++ b/application/view/AdminNavigation/index.phtml @@ -0,0 +1,111 @@ +
+

Navigation Bearbeiten

+ + + + + + +list as $parent): $i=0; ?> + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Aktiv + + Name + + Link +
+ + + + + base, $parent, true); ?> + + + + Nach oben verschieben + + + + list)-1): ?> + + Nach unten verschieben + + + + + Löschen + + + + Unterpunkt hinzufügen + + + + Ändern + + + + Vorschau + +
+ + + + + base, $child, true); ?> + + + + Nach oben verschieben + + + + + + Nach unten verschieben + + + + + Löschen + + +   + + + Ändern + + + + Vorschau + +
+

+ Neuen Hauptpunkt anlegen +

+
\ No newline at end of file diff --git a/application/view/AdminPage/edit.phtml b/application/view/AdminPage/edit.phtml new file mode 100644 index 0000000..f3d5cbd --- /dev/null +++ b/application/view/AdminPage/edit.phtml @@ -0,0 +1,70 @@ +
+

Page bearbeiten

+ +
+
+
+
Aktiv
+
+ page['active']) echo 'checked="checked"' ?> /> +
+
+
+
Titel
+
+ +
+
+
+
Untertitel
+
+ +
+
+
+
Url
+
+ +
+
+
+
Headerbild
+
+ + Auswählen +
+
+
+
Inhalt
+
+ +
+
+
+
Bild für Inhalt
+
+ + Auswählen +
+
+

+ +

+
+
+ + + + + + + + + diff --git a/application/view/AdminPage/image.phtml b/application/view/AdminPage/image.phtml new file mode 100644 index 0000000..682dbb2 --- /dev/null +++ b/application/view/AdminPage/image.phtml @@ -0,0 +1,40 @@ + + + <?php echo ucfirst($this->type) ?> Bilder - Seinheit + + + + + + +

Bild Hochladen

+
+

+ + +

+
+ +
+ +

Bild Auswählen

+ +files as $file): ?> + + + + + + +
+ base}/img/{$this->type}/{$file}" ?>', 'Bild', 'width=800,height=600,status=yes,scrollbars=yes,resizable=yes'); return false;"> + base}/img/{$this->type}/{$file}" ?>" > + + + type}', '{$file}'" ?>); window.close();" >Einfügen + + Löschen +
+ + + \ No newline at end of file diff --git a/application/view/AdminPage/index.phtml b/application/view/AdminPage/index.phtml new file mode 100644 index 0000000..b7ae699 --- /dev/null +++ b/application/view/AdminPage/index.phtml @@ -0,0 +1,57 @@ +
+

Page Übersicht

+ + + + + + + + + +pages as $page): ?> + + + + + + + + + + +
+ Aktiv + + Titel + + Untertitel + + Url + +   +
+ + + + + + + + + + Löschen + + + + Ändern + + + + Vorschau + +
+

+ Neue Seite anlegen +

+
\ No newline at end of file diff --git a/application/view/AdminPage/uploadsuccess.phtml b/application/view/AdminPage/uploadsuccess.phtml new file mode 100644 index 0000000..ef8e959 --- /dev/null +++ b/application/view/AdminPage/uploadsuccess.phtml @@ -0,0 +1,12 @@ + + + + +

Das Hochladen war erfolgreich.

\ No newline at end of file diff --git a/application/view/AdminUpload/double.phtml b/application/view/AdminUpload/double.phtml new file mode 100644 index 0000000..cfa707a --- /dev/null +++ b/application/view/AdminUpload/double.phtml @@ -0,0 +1,34 @@ +
+

Produkt-Bild hinzufügen

+
+ +
+
+ Produkt +
+
+ item['name'] ?> +
+
+
+
+ Klein +
+
+ +
+
+
+
+ Groß +
+
+ + +
+
+

+ +

+
+
\ No newline at end of file diff --git a/application/view/AdminUpload/product.phtml b/application/view/AdminUpload/product.phtml new file mode 100644 index 0000000..cfa707a --- /dev/null +++ b/application/view/AdminUpload/product.phtml @@ -0,0 +1,34 @@ +
+

Produkt-Bild hinzufügen

+
+ +
+
+ Produkt +
+
+ item['name'] ?> +
+
+
+
+ Klein +
+
+ +
+
+
+
+ Groß +
+
+ + +
+
+

+ +

+
+
\ No newline at end of file diff --git a/application/view/AdminUpload/simple.phtml b/application/view/AdminUpload/simple.phtml new file mode 100644 index 0000000..c0878a3 --- /dev/null +++ b/application/view/AdminUpload/simple.phtml @@ -0,0 +1,17 @@ +
+

Hochladen

+
+ +
+
+ Datei +
+
+ +
+
+

+ +

+
+
\ No newline at end of file diff --git a/application/view/Error/index.phtml b/application/view/Error/index.phtml new file mode 100644 index 0000000..1dc8194 --- /dev/null +++ b/application/view/Error/index.phtml @@ -0,0 +1,4 @@ +

Fehler

+

+ message ?> +

\ No newline at end of file diff --git a/application/view/Page/index.phtml b/application/view/Page/index.phtml new file mode 100644 index 0000000..9a29856 --- /dev/null +++ b/application/view/Page/index.phtml @@ -0,0 +1,12 @@ + + + Swiss Didgeridoo Artwork + + + + + + + + + \ No newline at end of file diff --git a/application/view/Page/post.phtml b/application/view/Page/post.phtml new file mode 100644 index 0000000..60c19cd --- /dev/null +++ b/application/view/Page/post.phtml @@ -0,0 +1,13 @@ +header_image): ?> + + +title): ?> +

title ?>

+ +subtitle): ?> +

subtitle ?>

+ + +
+ content ?> +
diff --git a/application/view/main.phtml b/application/view/main.phtml new file mode 100644 index 0000000..d6f40d9 --- /dev/null +++ b/application/view/main.phtml @@ -0,0 +1,86 @@ + + + + + <?php if(Navigation::getTitle()) echo Navigation::getTitle() . " - "; ?>Seinheit + + + + + + + class="admin"> + +
+
+ + + + + + notices): ?> +
    + notices as $notice): ?> +
  • + +
+ + + + +
+ +
+ stageContent ?> +
+ +
+

+ + SEINHEIT bei Facebook + +

+

Naturheilpraxis SEINHEIT. Kinga Pannek, Guyer-Zeller-Strasse 6, 8620 Wetzikon, Schweiz, Telefon: 078 684 86 75

+ +
+ +
+ + \ No newline at end of file diff --git a/application/view/welcome.phtml b/application/view/welcome.phtml deleted file mode 100644 index b8b5b6d..0000000 --- a/application/view/welcome.phtml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - -

Welcome

-

- This is an empty someVariableName?> project. -

- - \ No newline at end of file diff --git a/backup/db.sql b/backup/db.sql new file mode 100644 index 0000000..936a3ef --- /dev/null +++ b/backup/db.sql @@ -0,0 +1,86 @@ +-- MySQL dump 10.16 Distrib 10.1.37-MariaDB, for debian-linux-gnu (x86_64) +-- +-- Host: localhost Database: seinheit_ch +-- ------------------------------------------------------ +-- Server version 10.1.37-MariaDB-3 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `navigation` +-- + +DROP TABLE IF EXISTS `navigation`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `navigation` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `controller` varchar(64) DEFAULT NULL, + `action` varchar(64) DEFAULT NULL, + `link` varchar(255) DEFAULT NULL, + `parent_id` int(11) DEFAULT NULL, + `active` tinyint(1) NOT NULL DEFAULT '1', + `sorting` int(11) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=17 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `navigation` +-- + +LOCK TABLES `navigation` WRITE; +/*!40000 ALTER TABLE `navigation` DISABLE KEYS */; +INSERT INTO `navigation` VALUES (1,'Home','page','home',NULL,NULL,1,NULL),(2,'Behandlung','page','behandlung',NULL,NULL,1,NULL),(4,'Anamnese','page','anamnese',NULL,2,1,1),(5,'Diagnostik','page','diagnostik',NULL,2,1,2),(6,'Therapiemethoden','page','therapiemethoden',NULL,2,1,3),(7,'Kontakt','page','kontakt',NULL,NULL,1,3),(8,'Über mich','page','ueber-mich',NULL,NULL,1,1),(9,'Infos','',NULL,NULL,NULL,0,2),(10,'Krankenkassen','page','fehler',NULL,9,1,1),(11,'Diplomarbeit','page','diplomarbeit',NULL,NULL,1,2),(12,'Fragebogen PDF','page','fehler',NULL,9,1,4),(15,'Veranstaltungen','page','fehler',NULL,9,1,3),(16,'Links','page','fehler',NULL,9,1,5); +/*!40000 ALTER TABLE `navigation` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `page` +-- + +DROP TABLE IF EXISTS `page`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `page` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `title` varchar(256) NOT NULL, + `subtitle` varchar(256) DEFAULT NULL, + `url` varchar(256) NOT NULL, + `content` text, + `active` tinyint(1) NOT NULL DEFAULT '1', + `header_image` varchar(256) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `page` +-- + +LOCK TABLES `page` WRITE; +/*!40000 ALTER TABLE `page` DISABLE KEYS */; +INSERT INTO `page` VALUES (1,'Willkommen','','home','
\r\n\r\n
\r\n

SEINHEIT.

\r\n

\"\"

\r\n

Ich heisse Kinga Pannek und bin Dipl. Naturheil­praktikerin. Schwerpunkte meiner Arbeit liegen in der Homöopathie und anderen natürlichen Arzneien.

\r\n
\r\n\r\n
\r\n

Behandlung

\r\n

\"\"

\r\n

Die Behandlung in meiner Praxis erfolgt in drei Schritten. Anamnesegespräch, Diagnostik und Therapie. mehr …

\r\n
\r\n\r\n
\r\n

Praxis

\r\n

\"\"

\r\n

Die Praxis befindet sich im Zentrum von Wetzikon. Informationen zur Terminvereinbarung und Anfahrt finden Sie unter Kontakt.

\r\n
\r\n\r\n
',1,'1374237882.jpg'),(4,'Behandlung','','behandlung','
\r\n\r\n
\r\n

Anamnese

\r\n \"\"\r\n

\r\n Die Behandlung in meiner Praxis beinhaltet ein ausführliches Anamnesegespräch welches ca. 1,5 Stunden dauert. Vorab mache ich mir anhand eines Fragebogens ein Bild des jeweiligen Anliegens und gehe im Anamnesegespräch darauf ein. mehr …\r\n

\r\n
\r\n\r\n
\r\n

Diagnostik

\r\n \"\"\r\n

\r\n Als nächstes führe ich eine individuell angepasste schulmedizinische wie auch naturheilkundliche Diagnostik durch. mehr …\r\n

\r\n
\r\n\r\n
\r\n

Therapiemethoden

\r\n \"\"\r\n

\r\nAll diese Informationen sammle ich wie die Teile eines Puzzles und setze sie zu einem Bild zusammen. Hieraus ergibt sich das individuelle Therapiekonzept. mehr …\r\n

\r\n
\r\n\r\n
',1,'1374074370.jpg'),(5,'Fehler','','fehler','Diese Seite ist im Moment nicht verfügbar.',1,''),(6,'Kontakt','','kontakt','
\r\n
\r\n

Telefon: 078 684 86 75
\r\n E-Mail: info@seinheit.ch
\r\n Sprechzeiten: Montag bis Freitag nach Vereinbarung\r\n

\r\n\r\n

\"\"

\r\n

Naturheilpraxis SEINHEIT.
\r\n Kinga Pannek
\r\n Bahnhofstraße 105
\r\n 8620 Wetzikon

\r\n

Falls Sie Fragen haben oder direkt einen Termin vereinbaren möchten, zögern Sie nicht mich zu kontaktieren.

\r\n

Ich freue mich auf Ihren Besuch!

\r\n\r\n
\r\n
\r\n

\r\n Größere Kartenansicht

\r\n
\r\n
',1,'1374140846.jpg'),(8,'Über mich','','ueber-mich','
\r\n\r\n
\r\n

\r\nIch heisse Kinga Pannek und bin Dipl. Naturheil­praktikerin TEN hfnh*. Studiert habe ich an der Höhreren Fachschule Paramed Akademie AG, dem Bildungzentrum für Ganzheitsmedizin in Baar.\r\nSchwerpunkte meiner Arbeit liegen in der Homöopathie und anderen natürlichen Arzneien. Ausleitende Verfahren zur Entgiftung, Ernährungsberatung und verschiedene Körperbehandlungen wie die Visceral Therapie sind ebenso wesentliche Bestandteile meiner Arbeit. \r\n

\r\n\r\n\r\n
\r\n\r\n
\r\n

Entwicklung

\r\n
\r\n
    \r\n
  • Ausbildung zur Kinderkrankenschwester (Bayern/DE)
  • \r\n
  • Umzug in die Schweiz
  • \r\n
  • Ausbildung in Klangarbeit und Meditation
  • \r\n
  • Ausbildung in Sterbebegleitung
  • \r\n
  • Studium der Traditionellen Europäischen Medizin an der Paramed HF für Naturheilkunde (Baar - ZG)
  • \r\n
  • Eröffnung der Praxis SEINHEIT. in Wetzikon
  • \r\n
\r\n
\r\n
\r\n\r\n
\r\n

Berufserfahrung in folgenden Bereichen

\r\n
\r\n
    \r\n
  • Kinderklinik
  • \r\n
  • Behindertenbereich
  • \r\n
  • Arbeit mit künstlich beatmeten Kindern
  • \r\n
  • Kinderbetreung
  • \r\n
  • Volontariat in Mutter Theresas Waisenhaus (Kalkutta/Indien)
  • \r\n
  • Langzeitpflege
  • \r\n
  • Psychiatrie
  • \r\n
  • Masseurin im Wellnessbereich
  • \r\n
\r\n
\r\n
\r\n
\r\n\r\n
\r\n

\r\n* Die Paramed Akademie AG ist die einzige höhere Fachschule für Naturheilkunde in der Schweiz. Die Ausbildung ist im Kanton Zug staatlich anerkannt.
Der Bildungsgang Dipl. Naturheilpraktikerin TEN hfnh entspricht dem europäischen Bachelor Niveau.
\r\n

\r\n
',1,'1374229998.jpg'),(7,'Anamnese','','anamnese','
\r\n\r\n
\r\n

\r\nAls Naturheilpraktikerin diene ich als Dolmetscherin der Sprache des Körpers. Im Anamnesegespräch gehe ich zunächst auf die vorherrschende Erkrankung / Beschwerde ein und “zoome” in das Problem hinnein. Als nächstes interessiert mich die gesundheitliche Vorgeschichte und eventuelle Störfelder wie Narben oder Medikamente. Zuletzt “zoome” ich noch von der Person heraus in ihr soziales Umfeld und frage noch familiäre Erkrankungstendenzen ab. \r\n

\r\n\r\n

\r\nAuf diese Weise versuche ich mir ein möglichst vielschichtiges Bild zu machen um das Wagnis einzugehen eine ganzheitliches Behandlungskonzept anbieten zu können.\r\n

\r\n
\r\n\r\n
\r\n\r\n
\r\n\r\n
',1,'1374156504.jpg'),(9,'Diagnostik','','diagnostik','
\r\n
\r\n

Naturheilkundliche Diagnostik

\r\n\r\n
    \r\n
  • Irisdiagnose
  • \r\n
  • Zungendiagnose
  • \r\n
  • Headzonendiagnose
  • \r\n
  • F. X. Mayerdiagnose
  • \r\n
  • Haarmineralanalyse
  • \r\n
\r\n
\r\n
\r\n

Schulmedizinische Diagnostik

\r\n\r\n

\r\nIm Rahmen der Diagnostik führe ich einige schulmedizinische Diagnoseverfahren durch, welche eine ärztliche Untersuchung nicht ersetzen. \r\n

\r\n\r\n
    \r\n
  • Untersuchung des Bewegungsapparates und der Gelenke
  • \r\n
  • Stuhl- Urinuntersuchung
  • \r\n
  • Rachen- Ohruntersuchung
  • \r\n
  • neurologische Tests
  • \r\n
\r\n
',1,'1374149063.jpg'),(10,'Therapiemethoden','','therapiemethoden','
\r\n
\r\n

Methode

\r\n

Ich begleite Menschen in verschiedenen Lebenslagen, ob es sich um akute oder chronische Erkrankungen handelt oder um Beratung in Krisensituationen. Individuell kombiniere ich verschiedene Therapiemethoden wie natürliche Arzneien, Körpertherapien oder Ausleitende Verfahren. Auf diese Weise werden gleichzeitig verschieden Ebenen des menschlichen Systems angesprochen, was den nachhaltigsten Therapieerfolg verspricht.

\r\n
\r\n
\r\n

Konzepte

\r\n

Im Mittelpunkt meiner Arbeit steht die prozessorientierte Behandlung. Ich orientiere mich am Konzept der miasmatischen Homöopathie, der Humoralmedizin und den kybernetischen Gesetzmäsigkeiten des Lebendigen.

\r\n
\r\n
\r\n

Zusammenarbeit

\r\n

Sie können mich als “naturheilkundliche Hausärztin” betrachten, die den Überblick im heutigen Naturheilkunde Angebot behält und berät, zu welchem Zeitpunkt eine Therapiemethode im Genesungsprozess am meisten Sinn macht. Sollten Sie bei verschiedenen Therapeuten in Behandlung sein, diene ich gerne als Kontaktperson.

\r\n
\r\n
\r\n\r\n
\r\n
\r\n

Natürliche Arzneien

\r\n \"\"\r\n
\r\n
\r\n

Körpertherapien

\r\n \"\" \r\n
\r\n
\r\n

Ausleitende Verfahren

\r\n \"\"\r\n
\r\n
\r\n

Beratung

\r\n \"\"\r\n
\r\n
',1,'1374149247.jpg'),(12,'Diplomarbeit','','diplomarbeit','
\r\n
\r\n

Im Rahmen meines Studiums an der Höheren Fachschule für Naturheilkunde Paramed Akademie AG Bildungszentrum für Ganzheitsmedizin in Baar, verfasste ich die hier vorliegende Diplomarbeit.

\r\n

Jeder Mensch kommt im Laufe seines Lebens unweigerlich immer wider an Weggabelungen in seinem Leben. Etwas Altes geht zu Ende und man schlägt eine neue Richtung ein. Geht man an einer solchen Weggabelung keinen neuen Weg sondern versucht alles beim Alten zu lassen, übernimmt der Körper diese Aufgabe symbolisch und entwickelt eine Erkrankung.

\r\n

Mit dieser Arbeit habe ich untersucht ob es mir als Therapeutin möglich ist Einfluss auf solche Wendepunkte zu nehmen. Mein Ziel war es herauszufinden ob man den Lebensweg der in eine Erkrankung hinein gelangte durch eine Wende im Lebenslauf wider aus der Erkrankung herausführen kann.

\r\n

In der Chaosforschung sowie der Kybernetik wird diese Weggabelung als Bifurkation bezeichnet. Deshalb lautet der Titel der Arbeit:

\r\n

Beeinflussung der Bifurkation – Wendepunkte der Lebensgeschichte beeinflussen

\r\n

Hier könnten Sie die gesamte Arbeit als PDF (3 MB) herunterladen:

\r\n

DA-Kinga-Pannek-2012.pdf

\r\n
\r\n
\r\n

Zusammenfassung

\r\n

Diese Arbeit beschäftigt sich mit Wendepunkten der Lebensgeschichte. Es wird der Frage nachgegangen, ob es möglich ist, auf den Zeitpunkt des Auftretens eines Wendepunktes Einfluss zu nehmen. Ziel ist es zu klären, ob und wie man als behandelnde Person den Zeitpunkt des Auftretens einer therapeutisch notwendigen Wende im Leben eines Patienten herbeiführen kann. Ein weiterer Aspekt dieser Arbeit ist der Einfluss von Angst auf die Handlungsfähigkeit und Veränderungsbereitschaft des Menschen.

\r\n

Die Auswertungen stützen sich einerseits u.a. auf Grundlagen der Systemtheorie, der Kybernetik, der Chaosforschung und der Regulationsbiologie; andererseits auf die Untersuchungsergebnisse einer Befragung der Teilnehmer des Intensivseminars mit dem Thema Angst. Im Ergebnis wird deutlich dass eine direkte Beeinflussung des Auftretens einer Wende nicht möglich ist. Jedoch zeigte sich, dass gewisse Begebenheiten indirekt einen starken Einfluss auf die Veränderungsbereitschaft haben. Diese Begebenheiten beinhalten Wissensvermittlung, Auseinandersetzung mit alten Mustern und Ängsten, ein Umfeld welches Bewusstwerdungsprozesse fördert und Arbeit an der Motivation als Energiemotor.

\r\n
\r\n
\r\n',1,''); +/*!40000 ALTER TABLE `page` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2020-01-11 6:01:38 diff --git a/config/admin.ini.example b/config/admin.ini.example new file mode 100644 index 0000000..3e61712 --- /dev/null +++ b/config/admin.ini.example @@ -0,0 +1 @@ +password = test \ No newline at end of file diff --git a/config/database.config.ini b/config/database.config.ini deleted file mode 100644 index 359b86c..0000000 --- a/config/database.config.ini +++ /dev/null @@ -1,5 +0,0 @@ -; [connection:development:default] -; host = localhost -; user = root -; password = -; database = myDatabaseName \ No newline at end of file diff --git a/config/database.config.ini.example b/config/database.config.ini.example new file mode 100644 index 0000000..c13bf57 --- /dev/null +++ b/config/database.config.ini.example @@ -0,0 +1,5 @@ +[connection:development:default] +host = 127.0.0.1 +user = root +password = +database = seinheit_ch \ No newline at end of file diff --git a/config/dbinit.sql b/config/dbinit.sql new file mode 100644 index 0000000..bd26e25 --- /dev/null +++ b/config/dbinit.sql @@ -0,0 +1,42 @@ + +/*!40101 SET NAMES utf8 */; + +-- +-- Table structure for table `navigation` +-- + +DROP TABLE IF EXISTS `navigation`; +CREATE TABLE `navigation` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `controller` varchar(64) DEFAULT NULL, + `action` varchar(64) DEFAULT NULL, + `link` varchar(255) DEFAULT NULL, + `parent_id` int(11) DEFAULT NULL, + `active` tinyint(1) NOT NULL DEFAULT '1', + `sorting` int(11) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8; + +-- +-- Table structure for table `page` +-- + +DROP TABLE IF EXISTS `page`; +CREATE TABLE `page` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `title` varchar(256) NOT NULL, + `subtitle` varchar(256) DEFAULT NULL, + `url` varchar(256) NOT NULL, + `content` text DEFAULT NULL, + `active` tinyint(1) NOT NULL DEFAULT '1', + `header_image` varchar(256) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8; + +-- +-- Data +-- + +INSERT INTO `page` (`title`, `url`, `content`) VALUES ("Home", "home", "Wilkommen bei Katharsis"); +INSERT INTO `navigation` (`name`, `link`) VALUES ("Home", "/"); diff --git a/config/defaults.config.ini b/config/defaults.config.ini new file mode 100644 index 0000000..e982136 --- /dev/null +++ b/config/defaults.config.ini @@ -0,0 +1,4 @@ +title = Seinheit. +subtitle = Praxis für Traditionelle Europäische Medizin +email = info@seinheit.ch +#sites = news, blog \ No newline at end of file diff --git a/library/DidgeridooArtwork/Controller/Plugin/Access.php b/library/DidgeridooArtwork/Controller/Plugin/Access.php new file mode 100644 index 0000000..29436f3 --- /dev/null +++ b/library/DidgeridooArtwork/Controller/Plugin/Access.php @@ -0,0 +1,17 @@ +defaults = $ini; + + $view = Katharsis_View::getInstance(); + $view->defaults = $ini; + } +} \ No newline at end of file diff --git a/library/DidgeridooArtwork/Controller/Plugin/Navigation.php b/library/DidgeridooArtwork/Controller/Plugin/Navigation.php new file mode 100644 index 0000000..d6acace --- /dev/null +++ b/library/DidgeridooArtwork/Controller/Plugin/Navigation.php @@ -0,0 +1,44 @@ +mainNavigationItems = $navigation->getAllItems(); + + /* + $sql = "SELECT id, name, controller, action, link FROM navigation WHERE parent_id IS NULL AND active = 1 ORDER BY sorting"; + $view->mainNavigationItems = $this->_con->fetchAll($sql); + + $sql = "SELECT id, parent_id, controller, action FROM navigation WHERE (action = :action AND controller = :controller) OR (action IS NULL AND controller = :controller)"; + $sql = $this->_con->createStatement($sql, array( + 'controller' => Katharsis_Request::getControllerName(), + 'action' => Katharsis_Request::getActionName() + )); + + if($row = $this->_con->fetchOne($sql)) + { + $activeItemId = ($row['parent_id'] === null) ? $row['id'] : $row['parent_id']; + + $view->activeMenuItem = $activeItemId; + + $sql = "SELECT id, name, controller, action, link FROM navigation WHERE parent_id = :parentId ORDER BY sorting"; + $sql = $this->_con->createStatement($sql, array('parentId' => $activeItemId)); + $view->subNavigationItems = $this->_con->fetchAll($sql); + + if($row['parent_id'] !== null) + { + $view->activeSubMenuItem = $row['id']; + } + else + { + $actionpart = ($row['action'] === null) ? ' action IS NULL ' : ' action = :action'; + $sql = "SELECT id FROM navigation WHERE controller = :controller AND " . $actionpart . " AND parent_id IS NOT NULL"; + $sql = $this->_con->createStatement($sql, array('controller' => $row['controller'], 'action' => $row['action'])); + $view->activeSubMenuItem = $this->_con->fetchField($sql); + } + }*/ + } +} \ No newline at end of file diff --git a/library/DidgeridooArtwork/Controller/Plugin/Notice.php b/library/DidgeridooArtwork/Controller/Plugin/Notice.php new file mode 100644 index 0000000..fee3b08 --- /dev/null +++ b/library/DidgeridooArtwork/Controller/Plugin/Notice.php @@ -0,0 +1,9 @@ +notices = DidgeridooArtwork_Notice::get(); + } +} \ No newline at end of file diff --git a/library/DidgeridooArtwork/Controller/Plugin/SetNames.php b/library/DidgeridooArtwork/Controller/Plugin/SetNames.php new file mode 100644 index 0000000..e1a4109 --- /dev/null +++ b/library/DidgeridooArtwork/Controller/Plugin/SetNames.php @@ -0,0 +1,11 @@ +_con->run($sql); + } +} \ No newline at end of file diff --git a/library/DidgeridooArtwork/Exception.php b/library/DidgeridooArtwork/Exception.php new file mode 100644 index 0000000..1f706e5 --- /dev/null +++ b/library/DidgeridooArtwork/Exception.php @@ -0,0 +1,16 @@ +_important = $important; + parent::__construct($message); + } + + public function handle() + { + + } +} \ No newline at end of file diff --git a/library/DidgeridooArtwork/Notice.php b/library/DidgeridooArtwork/Notice.php new file mode 100644 index 0000000..2264def --- /dev/null +++ b/library/DidgeridooArtwork/Notice.php @@ -0,0 +1,23 @@ + $item) + { + + $instanceName = "DidgeridooArtwork_Page_Plugin_" . ucfirst($findings[1][$key]); + if(!Katharsis_Autoload::findClass($instanceName)) + { + throw new DidgeridooArtwork_Exception('PagePlugin ' . $instanceName . ' konnte nicht gefunden werden.', 1); + } + $object = new $instanceName; + $plugincontent = (string) $object->render(trim($findings[2][$key])); + + + $content = str_replace($findings[0][$key], $plugincontent, $content); + } + + return $content; + } +} \ No newline at end of file diff --git a/library/DidgeridooArtwork/Page/Plugin/Abstract.php b/library/DidgeridooArtwork/Page/Plugin/Abstract.php new file mode 100644 index 0000000..c1e01e3 --- /dev/null +++ b/library/DidgeridooArtwork/Page/Plugin/Abstract.php @@ -0,0 +1,19 @@ +_con = Katharsis_DatabaseConnector::getConnection(); + $this->_view = Katharsis_View::getInstance(); + $this->init(); + } + + public function init() + { + } + + abstract public function render($parameters); +} diff --git a/library/DidgeridooArtwork/Page/Plugin/Base.php b/library/DidgeridooArtwork/Page/Plugin/Base.php new file mode 100644 index 0000000..9d0defa --- /dev/null +++ b/library/DidgeridooArtwork/Page/Plugin/Base.php @@ -0,0 +1,8 @@ +_view->base . '/' . $after; + } +} \ No newline at end of file diff --git a/library/DidgeridooArtwork/Page/Plugin/Image.php b/library/DidgeridooArtwork/Page/Plugin/Image.php new file mode 100644 index 0000000..73de5b7 --- /dev/null +++ b/library/DidgeridooArtwork/Page/Plugin/Image.php @@ -0,0 +1,8 @@ +_view->base . "/img/page/" . $imgName; + } +} \ No newline at end of file diff --git a/library/DidgeridooArtwork/Page/Plugin/Mail.php b/library/DidgeridooArtwork/Page/Plugin/Mail.php new file mode 100644 index 0000000..d050dac --- /dev/null +++ b/library/DidgeridooArtwork/Page/Plugin/Mail.php @@ -0,0 +1,8 @@ +_view->render('Plugin/mail'); + } +} \ No newline at end of file diff --git a/library/DidgeridooArtwork/Page/Plugin/MiniEventList.php b/library/DidgeridooArtwork/Page/Plugin/MiniEventList.php new file mode 100644 index 0000000..f542f64 --- /dev/null +++ b/library/DidgeridooArtwork/Page/Plugin/MiniEventList.php @@ -0,0 +1,11 @@ +_view->pluginEvents = $event->getEventList(); + + return $this->_view->render('Plugin/minieventlist'); + } +} \ No newline at end of file diff --git a/library/DidgeridooArtwork/Page/Plugin/MiniNewsList.php b/library/DidgeridooArtwork/Page/Plugin/MiniNewsList.php new file mode 100644 index 0000000..5e6ac3f --- /dev/null +++ b/library/DidgeridooArtwork/Page/Plugin/MiniNewsList.php @@ -0,0 +1,10 @@ +_view->pluginNews = $news->getActiveNews(); + return $this->_view->render('Plugin/mininewslist'); + } +} \ No newline at end of file diff --git a/library/DidgeridooArtwork/Page/Plugin/Newsletter.php b/library/DidgeridooArtwork/Page/Plugin/Newsletter.php new file mode 100644 index 0000000..f998dfc --- /dev/null +++ b/library/DidgeridooArtwork/Page/Plugin/Newsletter.php @@ -0,0 +1,8 @@ +_view->render('Plugin/newsletter'); + } +} \ No newline at end of file diff --git a/library/DidgeridooArtwork/Page/Plugin/Page.php b/library/DidgeridooArtwork/Page/Plugin/Page.php new file mode 100644 index 0000000..bbc97c3 --- /dev/null +++ b/library/DidgeridooArtwork/Page/Plugin/Page.php @@ -0,0 +1,8 @@ +_view->base . "/" . $pageName; + } +} \ No newline at end of file diff --git a/library/DidgeridooArtwork/Page/Plugin/ShopVorschau.php b/library/DidgeridooArtwork/Page/Plugin/ShopVorschau.php new file mode 100644 index 0000000..d982087 --- /dev/null +++ b/library/DidgeridooArtwork/Page/Plugin/ShopVorschau.php @@ -0,0 +1,11 @@ +_view->pluginEvents = $event->getEventList(); + + return $this->_view->render('Plugin/shopvorschau'); + } +} \ No newline at end of file diff --git a/library/Katharsis/Autoload.php b/library/Katharsis/Autoload.php index 776419b..fd8a341 100644 --- a/library/Katharsis/Autoload.php +++ b/library/Katharsis/Autoload.php @@ -1,51 +1,40 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_Autoload -{ - /** - * @var array - */ - protected static $_classLocations = array( - 'library', - 'application/controller', - 'application/model' - ); - - /** - * Registering autoload method - * - * @return void - */ - public static function init() - { - spl_autoload_register('Katharsis_Autoload::autoload'); - } - - /** - * Actual autoload method. Loads class files automatically when they are needed - * - * @return void - */ - public static function autoload($classname) - { - $name = str_replace("_", DIRECTORY_SEPARATOR, $classname); - - foreach(self::$_classLocations as $location) - { - if(file_exists($location . DIRECTORY_SEPARATOR . $name . ".php")) - { - require_once $location . DIRECTORY_SEPARATOR . $name . ".php"; - return; - } - } - - die('Autoload: could not load class "' . $classname . '"'); - } -} \ No newline at end of file + \ No newline at end of file diff --git a/library/Katharsis/Bootstrap.php b/library/Katharsis/Bootstrap.php index d7a2a9d..226426e 100644 --- a/library/Katharsis/Bootstrap.php +++ b/library/Katharsis/Bootstrap.php @@ -1,29 +1,23 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_Bootstrap -{ - /** - * Central application routing method - * - * @return void - */ - public static function run() - { - $router = Katharsis_ControllerRouting::getInstance(); - - $router->init(); - - Katharsis_Controller_Plugin::preControllerHook(); - - $router->route(); - - Katharsis_Controller_Plugin::postControllerHook(); - } -} \ No newline at end of file +init(); + } + + public static function run() + { + $router = Katharsis_ControllerRouting::getInstance(); + + Katharsis_Controller_Plugin::preControllerHook(); + + $router->route(); + + Katharsis_Controller_Plugin::postControllerHook(); + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/Controller/Abstract.php b/library/Katharsis/Controller/Abstract.php index 460b3e6..0d53407 100644 --- a/library/Katharsis/Controller/Abstract.php +++ b/library/Katharsis/Controller/Abstract.php @@ -1,105 +1,57 @@ - - * @version 0.5.2 - * @package Katharsis - */ -abstract class Katharsis_Controller_Abstract -{ - /** - * @var Katharsis_Db5 - */ - protected $_con; - - /** - * @var Katharsis_View - */ - protected $_view; - - /** - * Instances class attributes, calles init method - * - * @return void - */ - public final function __construct() - { - $this->_con = Katharsis_DatabaseConnector::getConnection(); - $this->_view = Katharsis_View::getInstance(); - $this->init(); - } - - /** - * Overwrite this method instead of using a constructor - * - * @return void - */ - public function init() - { - } - - /** - * If subclass hasn't got a __call method, this exception will be thrown - * - * @return void - */ - public function __call($action, $params) - { - throw new Katharsis_Exception('Action "' . $action . '" doesn\'t exist.'); - } - - /** - * Returns a specific request parameter - * - * @param string $key - * @return mixed - */ - protected function _getParam($key) - { - $params = Katharsis_Request::getParams(); - if(array_key_exists($key,$params)) - { - return $params[$key]; - } - return null; - } - - /** - * Returns all request parameters - * - * @return array - */ - protected function _getAllParams() - { - return Katharsis_Request::getParams(); - } - - /** - * Forward to an other action - * - * @param string $action - * @param string $controller - * @param array $getParams - * @return void - */ - protected function _location($action, $controller = null, $getParams = null) - { - if($controller === null) - { - $controller = Katharsis_Request::getControllerName(); - } - - $paramstring = ""; - if($getParams !== null) - { - foreach($getParams as $key => $value) - { - $paramstring .= "/" . (string) $key . "/" . (string) $value; - } - } - - header("location: " . $this->_view->base . "/" . $controller . "/" . $action . $paramstring); - } -} \ No newline at end of file +_con = Katharsis_DatabaseConnector::getConnection(); + $this->_view = Katharsis_View::getInstance(); + $this->init(); + } + + public function init() + { + } + + public function __call($action, $params) + { + throw new Katharsis_Exception('Die von Ihnen angeforderte Seite (Action) "' . substr($action, 0, -6) . '" konnte nicht gefunden werden.'); + } + + protected function _getParam($key) + { + $params = Katharsis_Request::getParams(); + if(array_key_exists($key,$params)) + { + return $params[$key]; + } + return null; + } + + protected function _getAllParams() + { + return Katharsis_Request::getParams(); + } + + protected function _location($action, $controller = null, $getParams = null) + { + if($controller === null) + { + $controller = Katharsis_Request::getControllerName(); + } + + $paramstring = ""; + if($getParams !== null) + { + foreach($getParams as $key => $value) + { + $paramstring .= "/" . (string) $key . "/" . (string) $value; + } + } + + header("location: " . $this->_view->base . "/" . $controller . "/" . $action . $paramstring); + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/Controller/Plugin.php b/library/Katharsis/Controller/Plugin.php index 0959e3a..07db012 100644 --- a/library/Katharsis/Controller/Plugin.php +++ b/library/Katharsis/Controller/Plugin.php @@ -1,53 +1,27 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_Controller_Plugin -{ - /** - * @var array - */ - protected static $_plugins; - - /** - * Register all plugins with this method - * Plugins will be called in the same order as they have been registered - * - * @param object $object - an instance of your plugin - * @return void - */ - public static function registerPlugin($object) - { - self::$_plugins[] = $object; - } - - /** - * Processes preController methods of all plugins - * - * @return void - */ - public static function preControllerHook() - { - foreach(self::$_plugins as $plugin) - { - $plugin->preController(); - } - } - - /** - * Processes postController methods of all plugins - * - * @return void - */ - public static function postControllerHook() - { - foreach(self::$_plugins as $plugin) - { - $plugin->postController(); - } - } -} \ No newline at end of file +preController(); + } + } + + public static function postControllerHook() + { + foreach(self::$_plugins as $plugin) + { + $plugin->postController(); + } + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/Controller/Plugin/Abstract.php b/library/Katharsis/Controller/Plugin/Abstract.php index 8877623..fdc2602 100644 --- a/library/Katharsis/Controller/Plugin/Abstract.php +++ b/library/Katharsis/Controller/Plugin/Abstract.php @@ -1,31 +1,19 @@ - - * @version 0.5.2 - * @package Katharsis - */ -abstract class Katharsis_Controller_Plugin_Abstract -{ - /** - * Overwrite this method, if you want something to be processed - * _before_ the controller is called - * - * @return void - */ - public function preController() - { - } - - /** - * Overwrite this method, if you want something to be processed - * _after_ the controller was called - * - * @return void - */ - public function postController() - { - } -} \ No newline at end of file +_con = Katharsis_DatabaseConnector::getConnection(); + } + + public function preController() + { + } + + public function postController() + { + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/Controller/Plugin/AutoScriptControl.php b/library/Katharsis/Controller/Plugin/AutoScriptControl.php new file mode 100644 index 0000000..33d1ba6 --- /dev/null +++ b/library/Katharsis/Controller/Plugin/AutoScriptControl.php @@ -0,0 +1,21 @@ +autoScriptFile = false; + + + + $scriptName = ucfirst(Katharsis_Request::getControllerName()) . '/' . strtolower(Katharsis_Request::getActionName()); + $autoScriptFile = 'scripts/DidgeridooArtwork/' . $scriptName . '.js'; + $sl = DIRECTORY_SEPARATOR; + + if(file_exists(getcwd() . $sl . str_replace('/', $sl, $autoScriptFile))) + { + $view->autoScriptFile = $view->base . '/' . $autoScriptFile; + } + } +} \ No newline at end of file diff --git a/library/Katharsis/Controller/Plugin/Autorender.php b/library/Katharsis/Controller/Plugin/Autorender.php index f101b3d..de70c8a 100644 --- a/library/Katharsis/Controller/Plugin/Autorender.php +++ b/library/Katharsis/Controller/Plugin/Autorender.php @@ -1,32 +1,19 @@ - * @version 0.5.2 - * @package Katharsis - */ class Katharsis_Controller_Plugin_Autorender extends Katharsis_Controller_Plugin_Abstract { - /** - * Renders a controller/action.phtml template automaticly after processing controller - * - * @return void - */ public function postController() { $view = Katharsis_View::getInstance(); + + $view->stageContent = false; - $view->controllerAction = false; + $templateName = ucfirst(Katharsis_Request::getControllerName()) . DIRECTORY_SEPARATOR . strtolower(Katharsis_Request::getActionName()); - $templateName = strtolower(Katharsis_Request::getControllerName()) . DIRECTORY_SEPARATOR . strtolower(Katharsis_Request::getActionName()); - - if(file_exists('application/view' . DIRECTORY_SEPARATOR . $templateName . '.phtml')) + if(file_exists(getcwd() . '/application/view' . DIRECTORY_SEPARATOR . $templateName . '.phtml')) { - $view->controllerAction = $templateName; + $view->stageContent = $view->render($templateName); } - $view = Katharsis_View::getInstance(); echo $view->render('main'); } -} \ No newline at end of file +} diff --git a/library/Katharsis/Controller/Plugin/StartSession.php b/library/Katharsis/Controller/Plugin/StartSession.php new file mode 100644 index 0000000..fefbfc2 --- /dev/null +++ b/library/Katharsis/Controller/Plugin/StartSession.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/library/Katharsis/ControllerRouting.php b/library/Katharsis/ControllerRouting.php index 18aeb19..e6904a0 100644 --- a/library/Katharsis/ControllerRouting.php +++ b/library/Katharsis/ControllerRouting.php @@ -1,136 +1,102 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_ControllerRouting -{ - /** - * @var Katharsis_ControllerRouting - */ - protected static $_instance = null; - - /** - * Singleton. Returns the same instance every time - * - * @return Katharsis_ControllerRouting - */ - public static function getInstance() - { - if(self::$_instance === null) - { - self::$_instance = new self(); - } - return self::$_instance; - } - - /** - * Sets default controller and action names - * - * @return void - */ - protected function __construct() - { - Katharsis_Request::setControllerName('index'); - Katharsis_Request::setActionName('index'); - } - - /** - * Initiates routing process - * - * @return void - */ - public function init() - { - $paramstring = ""; - $baseUrl = preg_replace('#(.*/)[^/]+#', '\1', $_SERVER['SCRIPT_NAME']); - - if(preg_match("~.*" . $baseUrl . "([^/\?]+)/([^/\?]+)/*([^\?]*)~", $_SERVER['REQUEST_URI'], $matches)) - { - $controller = $matches[1]; - $action = $matches[2]; - $paramstring = $matches[3]; - $params = $this->_buildParams($paramstring); - - Katharsis_Request::setControllerName($controller); - Katharsis_Request::setActionName($action); - } else if(preg_match("~.*" . $baseUrl . "([^/\?]+)/*([^\?]*)~", $_SERVER['REQUEST_URI'], $matches)) - { - $controller = $matches[1]; - $paramstring = $matches[2]; - $params = $this->_buildParams($paramstring); - - Katharsis_Request::setControllerName($controller); - } else - { - if(array_key_exists('controller', $_GET)) - { - $controller = $_GET['controller']; - Katharsis_Request::setControllerName($controller); - } - - if(array_key_exists('action', $_GET)) - { - $action = $_GET['action']; - Katharsis_Request::setActionName($action); - } - - $params = $_GET; - } - - Katharsis_Request::setParams($params); - - Katharsis_View::getInstance()->requestHook(); - } - - - /** - * Routing processing method - * - * @return void - */ - public function route() - { - $controllerName = ucfirst(Katharsis_Request::getControllerName()) . 'Controller'; - $action = Katharsis_Request::getActionName() . 'Action'; - - if(class_exists($controllerName)) - { - $controllerObject = new $controllerName(); - - $controllerObject->$action(); - } - } - - - /** - * Splits parameters to an array and returns them - * - * @return array - */ - protected function _buildParams($string) - { - $params = array(); - if(trim($string) !== '') - { - $urlparams = explode("/", $string); - - for($i = 0; $i < count($urlparams); $i=$i+2) - { - if(array_key_exists($i+1, $urlparams)) - { - $params[$urlparams[$i]] = $urlparams[$i+1]; - } else - { - $params[$urlparams[$i]] = null; - } - } - } - - return $params; - } -} \ No newline at end of file +_buildParams($paramstring); + + Katharsis_Request::setControllerName($controller); + Katharsis_Request::setActionName($action); + } + else if(preg_match("~/([^/\?]+)/*([^\?]*)~", $_SERVER['REQUEST_URI'], $matches)) + { + $controller = $matches[1]; + $paramstring = $matches[2]; + $params = $this->_buildParams($paramstring); + + Katharsis_Request::setControllerName($controller); + } + else + { + if(array_key_exists('controller', $_GET)) + { + $controller = $_GET['controller']; + Katharsis_Request::setControllerName($controller); + } + + if(array_key_exists('action', $_GET)) + { + $action = $_GET['action']; + Katharsis_Request::setActionName($action); + } + + $params = $_GET; + } + + Katharsis_Request::setParams($params); + + Katharsis_View::getInstance()->requestHook(); + } + + public function route() + { + $controllerName = ucfirst(Katharsis_Request::getControllerName()) . 'Controller'; + $action = Katharsis_Request::getActionName() . 'Action'; + + if(class_exists($controllerName)) + { + $controllerObject = new $controllerName(); + + $controllerObject->$action(); + } + + } + + protected function _buildParams($string) + { + $params = array(); + if(trim($string) !== '') + { + $urlparams = explode("/", $string); + + for($i = 0; $i < count($urlparams); $i=$i+2) + { + if(array_key_exists($i+1, $urlparams)) + { + $params[$urlparams[$i]] = $urlparams[$i+1]; + } else + { + $params[$urlparams[$i]] = null; + } + } + } + + return $params; + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/DatabaseConnector.php b/library/Katharsis/DatabaseConnector.php index 021bde7..98f12e4 100644 --- a/library/Katharsis/DatabaseConnector.php +++ b/library/Katharsis/DatabaseConnector.php @@ -1,130 +1,92 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_DatabaseConnector -{ - /** - * @var array - */ - public static $_conns = array(); - - /** - * Reading ini file information and connecting - * - * @param string $requestedName - * @return Katharsis_Db5 - */ - protected static function connect($requestedName = null) - { - $ini = parse_ini_file('config/database.config.ini', true); - if($ini !== array()) - { - $conInformation = self::_selectConnection($ini, $requestedName); - return self::_realConnect($conInformation); - } else - { - return null; - } - } - - /** - * Connects to all connections in config file - * - * @param string $requestedName - * @return void - */ - public static function connectAll() - { - $groups = parse_ini_file('config/database.config.ini', true); - - foreach($groups as $iniName => $conInformation) - { - if(preg_match("~^connection:([^:]+)~", $iniName, $matches)) - { - self::getConnection($matches[1]); - } - } - } - - /** - * Calling Katharsis Db connecting method - * - * @param string $requestedName - * @return Katharsis_Db5 - */ - protected static function _realConnect($conInformation) - { - $con = new Katharsis_Db5($conInformation['host'], $conInformation['user'], $conInformation['password'], $conInformation['database']); - - self::$_conns[$conInformation['name']]['connection'] = $con; - self::$_conns[$conInformation['name']]['info'] = $conInformation; - - return $con; - } - - /** - * Returns specified or default connection - * - * @param string $requestedName - * @return Katharsis_Db5 - */ - public static function getConnection($requestedName = null) - { - if($requestedName === null) - { - foreach(self::$_conns as $con) - { - if($con['info']['default'] === true) - { - return $con['connection']; - } - } - return self::connect(null); - } else - { - if(in_array($requestedName, array_keys(self::$_conns))) - { - return self::$_conns[$requestedName]['connection']; - } - return self::connect($requestedName); - } - } - - /** - * Returns an array of connection information - * - * @param array $ini - * @param string $requestedName - * @return array - */ - protected static function _selectConnection($ini, $requestedName = null) - { - foreach($ini as $name => $connectionInfo) - { - if($requestedName === null) - { - if(preg_match("~^connection:([^:]+):default~", $name, $matches)) - { - $connectionInfo['name'] = $matches[1]; - $connectionInfo['default'] = true; - return $connectionInfo; - } - } else - { - if(preg_match("~^connection:" . $requestedName . ".*~", $name)) - { - $connectionInfo['default'] = false; - $connectionInfo['name'] = $requestedName; - return $connectionInfo; - } - } - } - throw new Katharsis_Exception('Could not find database connection information for "' . $requestedName . '"'); - } -} \ No newline at end of file + $conInformation) + { + if(preg_match("~^connection:([^:]+)~", $iniName, $matches)) + { + self::getConnection($matches[1]); + } + } + } + + protected static function _realConnect($conInformation) + { + //$con = new PDO('mysql:host=' . $conInformation['host'] . ';dbname=' . $conInformation['database'], $conInformation['user'], $conInformation['password']); + + + $con = new Katharsis_Db5($conInformation['host'], $conInformation['user'], $conInformation['password'], $conInformation['database']); + + self::$_conns[$conInformation['name']]['connection'] = $con; + self::$_conns[$conInformation['name']]['info'] = $conInformation; + + return $con; + } + + public static function getConnection($requestedName = null) + { + if($requestedName === null) + { + foreach(self::$_conns as $con) + { + if($con['info']['default'] === true) + { + return $con['connection']; + } + } + return self::connect(null); + } else + { + if(in_array($requestedName, array_keys(self::$_conns))) + { + return self::$_conns[$requestedName]['connection']; + } + return self::connect($requestedName); + } + } + + protected static function _selectConnection($ini, $requestedName = null) + { + foreach($ini as $name => $connectionInfo) + { + if($requestedName === null) + { + if(preg_match("~^connection:([^:]+):default~", $name, $matches)) + { + $connectionInfo['name'] = $matches[1]; + $connectionInfo['default'] = true; + return $connectionInfo; + } + } else + { + if(preg_match("~^connection:" . $requestedName . ".*~", $name)) + { + $connectionInfo['default'] = false; + $connectionInfo['name'] = $requestedName; + return $connectionInfo; + } + } + } + throw new Katharsis_Exception('Could not find database connection information for "' . $requestedName . '"'); + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/Db5.php b/library/Katharsis/Db5.php index f5857d2..55a823b 100644 --- a/library/Katharsis/Db5.php +++ b/library/Katharsis/Db5.php @@ -1,627 +1,631 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_Db5 -{ - /** - * @var string - */ - const FETCHMODE_ASSOC = 'ASSOC'; - - /** - * @var string - */ - const FETCHMODE_ARRAY = 'ARRAY'; - - /** - * @var Mysql Resource - */ - private $_connection = null; - - /** - * @var string - */ - private $_host = null; - - /** - * @var string - */ - private $_user = null; - - /** - * @var string - */ - private $_password = null; - - /** - * @var string - */ - private $_database = null; - - /** - * @var string - */ - private $_lastStatement = ""; - - /** - * @var array - */ - private $_lastResult = array(); - - /** - * @var array - */ - private $_lastError = array(); - - /** - * @var int - */ - private $_lastRowCount = 0; - - /** - * Create a connection - * - * @param $host - * @param $user - * @param $password - * @param $database - * - * @return KatharsisDbConnector - */ - public function __construct($host = null, $user = null, $password = null, $database = null) - { - $this->setHost($host); - $this->setUser($user); - $this->setPassword($password); - $this->setDatabase($database); - - if($host !== null && $user !== null && $password !== null && $database !== null) - { - $this->connect(); - } - } - - /** - * Sets the value of $_host - * - * @param string $host - * @author Karl Pannek - */ - public function setHost($value) - { - $this->_host = $value; - } - - /** - * Sets the value of $_user - * - * @param string $user - * @author Karl Pannek - */ - public function setUser($value) - { - $this->_user = $value; - } - - /** - * Sets the value of $_password - * - * @param string $password - * @author Karl Pannek - */ - public function setPassword($value) - { - $this->_password = $value; - } - - /** - * Sets the value of $_database - * - * @param string $database - * @author Karl Pannek - */ - public function setDatabase($value) - { - $this->_database = $value; - $this->_selectDatabase(); - } - - /** - * Returns the value of $_host - * - * @return string - * @author Karl Pannek - */ - public function getHost() - { - return $this->_host; - } - - /** - * Returns the value of $_user - * - * @return string - * @author Karl Pannek - */ - public function getUser() - { - return $this->_user; - } - - /** - * Returns the value of $_password - * - * @return string - * @author Karl Pannek - */ - public function getPassword() - { - return $this->_password; - } - - /** - * Returns the value of $_database - * - * @return string - * @author Karl Pannek - */ - public function getDatabase() - { - return $this->_database; - } - - /** - * Connect to database - * - * - * @return void - */ - public function connect() - { - $this->_connection = @mysql_connect( - $this->getHost(), - $this->getUser(), - $this->getPassword(), - true - ); - - if(!$this->_connection) - { - throw new KatharsisDb5_Exception('Could not connect to "' . $this->getHost() . '" with user "' . $this->getUser() . '".'); - } - - $this->_selectDatabase(); - } - - /** - * Disconnect database connection - * @return bool - */ - public function disconnect() - { - $this->_connection = null; - return (bool) mysql_close($this->_connection); - } - -/** - * Checks connection to database - * - * @return bool - */ - public function isConnected() - { - if($this->_connection !== null && $this->_connection !== false) - { - return true; - } else - { - return false; - } - } - - /** - * Returns mysql connection link resource - * - * @return mysql link resource - */ - public function getMysqlResource () - { - return $this->_connection; - } - - /** - * Executes a Sql statement - * - * @param $statement - * @return bool - */ - public function run ($statement) - { - if($this->_execute($statement)) - { - return true; - } else - { - return false; - } - } - - /** - * Returns Result set for incremental fetching - * - * @param $statement - * @return KatharsisDb5_ResultSet - */ - public function runForIncrementalFetch ($statement) - { - $resultSet = $this->_execute($statement); - return new KatharsisDb5_ResultSet($resultSet); - } - - /** - * Inserts a row into a specified table - * - * @param $table - * @param $values - * @return bool - */ - public function insert ($table, $values = array()) - { - $sets = array(); - - foreach($values as $key => $value) - { - if(is_string($value)) - { - $value = "'" . mysql_real_escape_string($value, $this->_connection) . "'"; - } - $sets[] = "`" . $key . "` = " . $value; - } - - $sql = 'INSERT INTO ' . $table; - - if($values !== array()) - { - $sql .= ' SET ' . implode(',', $sets); - } else - { - $sql .= ' () VALUES () '; - } - - return $this->run($sql); - } - - /** - * Executes Query and returns number of rows - * - * @param $statement - * @return int - */ - public function count ($statement) - { - $result = $this->_execute($statement); - $this->_lastRowCount = mysql_num_rows($result); - return $this->_lastRowCount; - } - - /** - * Returns a fetched result set (All rows) - * - * @param $statement - * @param $fetchmode - * @return array - */ - public function fetchAll($statement, $fetchmode = self::FETCHMODE_ASSOC) - { - return $this->_fetch($statement, $fetchmode, false); - } - - /** - * Returns a fetched result (One rows) - * - * @param $statement - * @param $fetchmode - * @return array - */ - public function fetchOne($statement, $fetchmode = self::FETCHMODE_ASSOC) - { - return $this->_fetch($statement, $fetchmode, true); - } - - public function fetchField ($statement, $field = null) - { - if($field === null) - { - $result = $this->_fetch($statement, self::FETCHMODE_ARRAY, true); - return $result[0]; - } else - { - $result = $this->_fetch($statement, self::FETCHMODE_ASSOC, true); - if(array_key_exists($field, $result)) - { - return $result[$field]; - } - return null; - } - } - - /** - * Prints out details of the last query (Html formatted) - * - * @return void - */ - public function analyseLast () - { - $debug = debug_backtrace(); - $file = explode("/", str_replace("\\", "/", $debug[0]['file'])); - $file = $file[count($file)-1]; - - - echo '
';
-
-		echo '';
-		echo '
QUERY ANALYSIS | from ' . $file . ' on line ' . $debug[0]['line'] . ''; - echo '
'; - echo '
'; - echo 'Statement:
'; - echo '

'; - print_r((string) $this->_lastStatement); - echo '

'; - echo '
'; - - echo '
'; - echo 'Result:
'; - echo '

'; - print_r($this->_lastResult); - echo '

'; - echo '
'; - - if($this->_lastError) - { - echo '
'; - echo 'Error:
'; - echo '

'; - echo ''; - echo ''; - echo ''; - echo '
Number:' . $this->_lastError['number'] . '
Message:' . $this->_lastError['message'] . '
'; - echo '

'; - echo '
'; - } - echo '
'; - } - - /** - * Prepares a statement with certain values - * - * @param $statement - * @param $values - * @return string - */ - public function createStatement ($statement, $values = array()) - { - foreach($values as $key => $value) - { - $wasString = false; - if(is_string($value)) - { - $wasString = true; - } - - if($this->_connection !== null) - { - $value = mysql_real_escape_string($value); - } else - { - $value = mysql_escape_string($value); - } - - // if string, or a integer, but wanting to request via LIKE - if($wasString || preg_match('~%' . $key . '|' . $key . '%~', $statement)) - { - $statement = preg_replace('~\:(%*)' . $key . '(%*)~', "'" . '${1}' . (string) $value . '${2}' . "'", $statement); - } else - { - $statement = str_replace(":" . $key, $value, $statement); - } - } - - return $statement; - } - - /** - * Last primary key that has been inserted - * - * @return int - */ - public function lastInsertId () - { - return mysql_insert_id($this->_connection); - } - - /** - * Returns the number of rows from the last executed statement - * - * @return int - */ - public function lastRowCount () - { - return $this->_lastRowCount; - } - - /** - * Select a database for usage - * - * @return void - * @throws KatharsisDb5_Exception - */ - protected function _selectDatabase() - { - if($this->isConnected() && $this->getDatabase() !== null) - { - if(!mysql_select_db($this->getDatabase(), $this->_connection)) - { - throw new KatharsisDb5_Exception('Could not select database "' . $this->getDatabase() . '".'); - } - } - } - - /** - * Executes Sql statement - * - * @param $statement - * @return mysql resource - */ - protected function _execute($statement) - { - if(!$this->isConnected()) - { - throw new KatharsisDb5_Exception("Not connected to database."); - } - if($result = mysql_query($statement, $this->_connection)) - { - $this->_lastStatement = $statement; - $this->_lastRowCount = mysql_affected_rows($this->_connection); - } - - if(mysql_error($this->_connection)) - { - $this->_lastError['number'] = mysql_errno($this->_connection); - $this->_lastError['message'] = mysql_error($this->_connection); - } else - { - $this->_lastError = array(); - } - - return $result; - } - - /** - * Fetches database result - * - * @param $statement - * @param $fetchmode - * @param $fetchOne - * @return array - */ - protected function _fetch($statement, $fetchmode = self::FETCHMODE_ASSOC, $fetchOne = false) - { - $result = $this->_execute($statement); - - if(!$result) - { - $this->_lastResult = array(); - return array(); - } - - $fetchedResult = array(); - - switch($fetchmode) - { - case self::FETCHMODE_ASSOC: - while($row = mysql_fetch_assoc($result)) - { - if($fetchOne) - { - $fetchedResult = $row; - break; - } else - { - $fetchedResult[] = $row; - } - } - break; - - case self::FETCHMODE_ARRAY: - while($row = mysql_fetch_row($result)) - { - if($fetchOne) - { - $fetchedResult = $row; - break; - } else - { - $fetchedResult[] = $row; - } - } - break; - - default: - throw new KatharsisDb5_Exception('Wrong Fetchmode'); - break; - } - - $this->_lastResult = $fetchedResult; - - return $fetchedResult; - } -} - -/** - * KatharsisDb exception spicification - * - * @author Karl Pannek - * @version 0.5.2 - * @package Katharsis - */ -class KatharsisDb5_Exception extends Exception {} - -/** - * KatharsisDb Result Set - * - * @author Karl Pannek - * @version 0.5.2 - * @package Katharsis - - */ -class KatharsisDb5_ResultSet -{ - /** - * @var Mysql Resource - */ - private $_resultSet; - - /** - * @var Katharsis_Db5 - */ - private $_connection; - - /** - * Sets class attributes - * - * @param Mysql Resource $resultSet - */ - public function __construct($resultSet) - { - $this->_resultSet = $resultSet; - } - - /** - * Fetching next row - * - * @param Mysql Resource $resultSet - */ - public function fetchNext ($fetchmode = Katharsis_Db5::FETCHMODE_ASSOC) - { - switch ($fetchmode) - { - case Katharsis_Db5::FETCHMODE_ASSOC: - return mysql_fetch_assoc($this->_resultSet); - break; - - case Katharsis_Db5::FETCHMODE_ARRAY: - return mysql_fetch_row($this->_resultSet); - break; - - default: - throw new KatharsisDb5_Exception('Wrong Fetchmode'); - break; - } - } -} \ No newline at end of file +setHost($host); + $this->setUser($user); + $this->setPassword($password); + $this->setDatabase($database); + + if($host !== null && $user !== null && $password !== null && $database !== null) + { + $this->connect(); + } + } + + /** + * Sets the value of $_host + * + * @param string $host + * @author Karl Pannek + */ + public function setHost($value) + { + $this->_host = $value; + } + + /** + * Sets the value of $_user + * + * @param string $user + * @author Karl Pannek + */ + public function setUser($value) + { + $this->_user = $value; + } + + /** + * Sets the value of $_password + * + * @param string $password + * @author Karl Pannek + */ + public function setPassword($value) + { + $this->_password = $value; + } + + /** + * Sets the value of $_database + * + * @param string $database + * @author Karl Pannek + */ + public function setDatabase($value) + { + $this->_database = $value; + // $this->_selectDatabase(); + } + + /** + * Returns the value of $_host + * + * @return string + * @author Karl Pannek + */ + public function getHost() + { + return $this->_host; + } + + /** + * Returns the value of $_user + * + * @return string + * @author Karl Pannek + */ + public function getUser() + { + return $this->_user; + } + + /** + * Returns the value of $_password + * + * @return string + * @author Karl Pannek + */ + public function getPassword() + { + return $this->_password; + } + + /** + * Returns the value of $_database + * + * @return string + * @author Karl Pannek + */ + public function getDatabase() + { + return $this->_database; + } + + /** + * Connect to database + * + * + * @return void + */ + public function connect() + { + $this->_connection = mysqli_connect( + $this->getHost(), + $this->getUser(), + $this->getPassword(), + $this->getDatabase() + ); + + if(!$this->_connection) + { + throw new KatharsisDb5_Exception('Could not connect to "' . $this->getHost() . '" with user "' . $this->getUser() . '".'); + } + + // $this->_selectDatabase(); + } + + /** + * Disconnect database connection + * @return bool + */ + public function disconnect() + { + $this->_connection = null; + return (bool) mysqli_close($this->_connection); + } + +/** + * Checks connection to database + * + * @return bool + */ + public function isConnected() + { + if($this->_connection !== null && $this->_connection !== false) + { + return true; + } else + { + return false; + } + } + + /** + * Returns mysql connection link resource + * + * @return mysql link resource + */ + public function getMysqlResource () + { + return $this->_connection; + } + + /** + * Executes a Sql statement + * + * @param $statement + * @return bool + */ + public function run ($statement) + { + if($this->_execute($statement)) + { + return true; + } else + { + return false; + } + } + + /** + * Returns Result set for incremental fetching + * + * @param $statement + * @return KatharsisDb5_ResultSet + */ + public function runForIncrementalFetch ($statement) + { + $resultSet = $this->_execute($statement); + return new KatharsisDb5_ResultSet($resultSet); + } + + /** + * Inserts a row into a specified table + * + * @param $table + * @param $values + * @return bool + */ + public function insert ($table, $values = array()) + { + $sets = array(); + + foreach($values as $key => $value) + { + if(is_string($value)) + { + $value = "'" . mysqli_real_escape_string($this->_connection, $value) . "'"; + } + if($value === null) + { + $value = 'NULL'; + } + $sets[] = "`" . $key . "` = " . $value; + } + + $sql = 'INSERT INTO ' . $table; + + if($values !== array()) + { + $sql .= ' SET ' . implode(',', $sets); + } else + { + $sql .= ' () VALUES () '; + } + + return $this->run($sql); + } + + public function simpleDelete($table, $fieldvalue, $fieldname = 'id') + { + $sql = "DELETE FROM " . $table . " WHERE " . $fieldname . " = :field"; + $sql = $this->createStatement($sql, array('field' => $fieldvalue)); + return $this->run($sql); + } + + /** + * Executes Query and returns number of rows + * + * @param $statement + * @return int + */ + public function count ($statement) + { + $result = $this->_execute($statement); + $this->_lastRowCount = mysqli_num_rows($result); + return $this->_lastRowCount; + } + + /** + * Returns a fetched result set (All rows) + * + * @param $statement + * @param $fetchmode + * @return array + */ + public function fetchAll($statement, $fetchmode = self::FETCHMODE_ASSOC) + { + return $this->_fetch($statement, $fetchmode, false); + } + + /** + * Returns a fetched result (One rows) + * + * @param $statement + * @param $fetchmode + * @return array + */ + public function fetchOne($statement, $fetchmode = self::FETCHMODE_ASSOC) + { + return $this->_fetch($statement, $fetchmode, true); + } + + /** + * Returns a fetched result (One rows) + * + * @param $statement + * @param $fetchmode + * @return array + */ + public function fetchField ($statement, $field = 0) + { + if(intval($field) === $field) + { + $result = $this->_fetch($statement, self::FETCHMODE_ARRAY, true); + } else + { + $result = $this->_fetch($statement, self::FETCHMODE_ASSOC, true); + } + + return array_key_exists($field, $result) ? $result[$field] : null; + } + + /** + * Prints out details of the last query (Html formatted) + * + * @return void + */ + public function analyseLast () + { + $debug = debug_backtrace(); + $file = explode("/", str_replace("\\", "/", $debug[0]['file'])); + $file = $file[count($file)-1]; + + + echo '
';
+
+		echo '';
+		echo '
QUERY ANALYSIS | from ' . $file . ' on line ' . $debug[0]['line'] . ''; + echo '
'; + echo '
'; + echo 'Statement:
'; + echo '

'; + print_r((string) $this->_lastStatement); + echo '

'; + echo '
'; + + echo '
'; + echo 'Result:
'; + echo '

'; + print_r($this->_lastResult); + echo '

'; + echo '
'; + + if($this->_lastError) + { + echo '
'; + echo 'Error:
'; + echo '

'; + echo ''; + echo ''; + echo ''; + echo '
Number:' . $this->_lastError['number'] . '
Message:' . $this->_lastError['message'] . '
'; + echo '

'; + echo '
'; + } + echo '
'; + } + + /** + * Prepares a statement with certain values + * + * @param $statement + * @param $values + * @return string + */ + public function createStatement ($statement, $values = array()) + { + foreach($values as $key => $value) + { + if($value === null) + { + $statement = str_replace(":" . $key, 'NULL', $statement); + continue; + } + + $wasString = false; + if(is_string($value)) + { + $wasString = true; + } + + if($this->_connection !== null) + { + $value = mysqli_real_escape_string($this->_connection, $value); + } else + { + $value = mysqli_escape_string($this->_connection, $value); + } + + // if string, or a integer, but wanting to request via LIKE + if($wasString || preg_match('~%' . $key . '|' . $key . '%~', $statement)) + { + $statement = preg_replace('~\:(%*)' . $key . '(%*)~', "'" . '${1}' . (string) $value . '${2}' . "'", $statement); + } else + { + $statement = str_replace(":" . $key, $value, $statement); + } + } + + return $statement; + } + + public function getEmptyColumnArray($table) + { + $sql = $this->createStatement("SHOW COLUMNS FROM " . $table); + $columns = $this->fetchAll($sql); + $result = array(); + foreach($columns as $column) + { + $result[$column['Field']] = $column['Default']; + } + return $result; + } + + /** + * Last primary key that has been inserted + * + * @return int + */ + public function lastInsertId () + { + return mysqli_insert_id($this->_connection); + } + + /** + * Returns the number of rows fro m the last executed statement + * + * @return int + */ + public function lastRowCount () + { + return $this->_lastRowCount; + } + + /** + * Select a database for usage + * + * @return void + * @throws KatharsisDb5_Exception + */ + protected function _selectDatabase() + { + if($this->isConnected() && $this->getDatabase() !== null) + { + if(!mysqli_select_db($this->getDatabase(), $this->_connection)) + { + throw new KatharsisDb5_Exception('Could not select database "' . $this->getDatabase() . '".'); + } + } + } + + /** + * Executes Sql statement + * + * @param $statement + * @return mysql resource + */ + protected function _execute($statement) + { + if(!$this->isConnected()) + { + throw new KatharsisDb5_Exception("Not connected to database."); + } + if($result = mysqli_query($this->_connection, $statement)) + { + $this->_lastRowCount = mysqli_affected_rows($this->_connection); + } + $this->_lastStatement = $statement; + + if(mysqli_error($this->_connection)) + { + $this->_lastError['number'] = mysqli_errno($this->_connection); + $this->_lastError['message'] = mysqli_error($this->_connection); + $this->analyseLast(); + } else + { + $this->_lastError = array(); + $this->_lastResult = " "; + } + + return $result; + } + + /** + * Fetches database result + * + * @param $statement + * @param $fetchmode + * @param $fetchOne + * @return array + */ + protected function _fetch($statement, $fetchmode = self::FETCHMODE_ASSOC, $fetchOne = false) + { + $result = $this->_execute($statement); + + if(!$result) + { + $this->_lastResult = array(); + return array(); + } + + $fetchedResult = array(); + + switch($fetchmode) + { + case self::FETCHMODE_ASSOC: + while($row = mysqli_fetch_assoc($result)) + { + if($fetchOne) + { + $fetchedResult = $row; + break; + } else + { + $fetchedResult[] = $row; + } + } + break; + + case self::FETCHMODE_ARRAY: + while($row = mysqli_fetch_row($result)) + { + if($fetchOne) + { + $fetchedResult = $row; + break; + } else + { + $fetchedResult[] = $row; + } + } + break; + + default: + throw new KatharsisDb5_Exception('Wrong Fetchmode'); + break; + } + + $this->_lastResult = $fetchedResult; + + return $fetchedResult; + } +} + +/** + * KatharsisDb exception spicification + * + * @author Karl Pannek + */ +class KatharsisDb5_Exception extends Exception {} + +/** + * KatharsisDb Result Set + * + * @author Karl Pannek + */ +class KatharsisDb5_ResultSet +{ + private $_resultSet; + private $_connection; + + public function __construct($resultSet) + { + $this->_resultSet = $resultSet; + } + + public function fetchNext ($fetchmode = Katharsis_Db5::FETCHMODE_ASSOC) + { + switch ($fetchmode) + { + case Katharsis_Db5::FETCHMODE_ASSOC: + return mysqli_fetch_assoc($this->_resultSet); + break; + + case Katharsis_Db5::FETCHMODE_ARRAY: + return mysqli_fetch_row($this->_resultSet); + break; + + default: + throw new KatharsisDb5_Exception('Wrong Fetchmode'); + break; + } + } + +} +?> diff --git a/library/Katharsis/Exception.php b/library/Katharsis/Exception.php index 9e09ee7..7523094 100644 --- a/library/Katharsis/Exception.php +++ b/library/Katharsis/Exception.php @@ -1,11 +1,4 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_Exception extends Exception -{ + - * @version 0.5.2 - * @package Katharsis - */ -abstract class Katharsis_Model_Abstract -{ - /** - * @var Katharsis_Db5 - */ - protected $_con; - - /** - * Instances class attributes, calles init method - * - * @return void - */ - public final function __construct() - { - $this->_con = Katharsis_DatabaseConnector::getConnection(); - $this->init(); - } - - /** - * Overwrite this method instead of using a constructor - * - * @return void - */ - public function init() - { - } -} \ No newline at end of file +_con = Katharsis_DatabaseConnector::getConnection(); + $this->init(); + } + + public function init() + { + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/Registry.php b/library/Katharsis/Registry.php new file mode 100644 index 0000000..57fa296 --- /dev/null +++ b/library/Katharsis/Registry.php @@ -0,0 +1,66 @@ + + * @version 0.5.2 + * @package Katharsis + */ +class Katharsis_Registry +{ + /** + * @var Katharsis_Registry + */ + protected static $_instance = null; + + /** + * @var array + */ + protected $_params = array(); + + /** + * Singleton. Returns the same instance every time + * + * @return Katharsis_Registry + */ + public static function getInstance() + { + if(self::$_instance === null) + { + self::$_instance = new self(); + } + return self::$_instance; + } + + /** + * Magical get method, gets specific param + * + * @param string $name + * @return string + */ + public function __get($name) + { + if(array_key_exists($name, $this->_params)) + { + return $this->_params[$name]; + } + return null; + } + + /** + * Magical set method, sets specific param + * + * @param string name + * @param string value + */ + public function __set($name, $value) + { + $this->_params[$name] = $value; + } + + public function getAll() + { + return $this->_params; + } +} \ No newline at end of file diff --git a/library/Katharsis/Request.php b/library/Katharsis/Request.php index 8470fa1..bef1451 100644 --- a/library/Katharsis/Request.php +++ b/library/Katharsis/Request.php @@ -1,93 +1,44 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_Request -{ - /** - * @var string - */ - protected static $_controller; - - /** - * @var string - */ - protected static $_action; - - /** - * @var array - */ - protected static $_params = array(); - - /** - * Set name of controller - * - * @param string $name - * @return void - */ - public static function setControllerName($name) - { - self::$_controller = $name; - } - - /** - * Set name of action - * - * @param string $name - * @return void - */ - public static function setActionName($name) - { - self::$_action = $name; - } - - /** - * Set parameters - * - * @param array $params - * @return void - */ - public static function setParams($params) - { - foreach($_POST as $key => $value) - { - $params[$key] = $value; - } - self::$_params = $params; - } - - /** - * Get controller name - * - * @return string - */ - public static function getControllerName() - { - return self::$_controller; - } - - /** - * Get action name - * - * @return string - */ - public static function getActionName() - { - return self::$_action; - } - - /** - * Get parameter array - * - * @return array - */ - public static function getParams() - { - return self::$_params; - } -} \ No newline at end of file + $value) + { + $params[$key] = $value; + } + self::$_params = $params; + + } + + public static function getControllerName() + { + return self::$_controller; + } + + public static function getActionName() + { + return self::$_action; + } + + + public static function getParams() + { + return self::$_params; + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/View.php b/library/Katharsis/View.php index a5dc791..643253f 100644 --- a/library/Katharsis/View.php +++ b/library/Katharsis/View.php @@ -1,29 +1,9 @@ - * @version 0.5.2 - * @package Katharsis - */ class Katharsis_View { - /** - * @var Katharsis_View - */ protected static $_instance = null; - - /** - * @var array - */ - protected $_params = array(); + protected $_items = array(); - /** - * Singleton. Returns the same instance every time - * - * @return Katharsis_View - */ public static function getInstance() { if(self::$_instance === null) @@ -33,49 +13,30 @@ class Katharsis_View return self::$_instance; } - /** - * Sets base application path - * - * @return void - */ protected function __construct() { $base = preg_replace('/(.+)\/[^\/]+/', '\1', $_SERVER['SCRIPT_NAME']); - $this->_params['base'] = $base != $_SERVER['SCRIPT_NAME'] ? $base : ''; + $this->_items['base'] = $base != $_SERVER['SCRIPT_NAME'] ? $base : ''; } - /** - * Magical get method, gets specific param - * - * @param string $name - * @return string - */ public function __get($name) { - if(array_key_exists($name, $this->_params)) + if(array_key_exists($name, $this->_items)) { - return $this->_params[$name]; + if(is_array($this->_items[$name])) + { + return (array) $this->_items[$name]; + } + return $this->_items[$name]; } return null; } - /** - * Magical set method, sets specific param - * - * @param string name - * @param string value - */ public function __set($name, $value) { - $this->_params[$name] = $value; + $this->_items[$name] = $value; } - /** - * Template rendering method - * - * @param string $template - * @return string - */ public function render($template) { ob_start(); @@ -89,13 +50,23 @@ class Katharsis_View return $output; } - /** - * Sets Request params into View params - * - * @return void - */ public function requestHook() { - $this->_params['params'] = Katharsis_Request::getParams(); } -} \ No newline at end of file + + public function _getParam($key) + { + $params = Katharsis_Request::getParams(); + if(array_key_exists($key,$params)) + { + return $params[$key]; + } + return null; + } + + public function formatDate($date) + { + $date = explode("-", $date); + return $date[2] . '.' . $date[1] . '.' . $date[0]; + } +} diff --git a/library/Local/Controller/Plugin/IndexRedirect.php b/library/Local/Controller/Plugin/IndexRedirect.php new file mode 100644 index 0000000..34ee250 --- /dev/null +++ b/library/Local/Controller/Plugin/IndexRedirect.php @@ -0,0 +1,12 @@ +defaults['sites'])){ + $defaultSites = explode(", ", Katharsis_Registry::getInstance()->defaults['sites']); + } + + if(in_array($controller, $defaultSites)) { + return; + } + + Katharsis_Request::setControllerName('page'); + Katharsis_Request::setActionName($controller); + } +} \ No newline at end of file diff --git a/library/Verot/Upload.php b/library/Verot/Upload.php new file mode 100644 index 0000000..40eeef8 --- /dev/null +++ b/library/Verot/Upload.php @@ -0,0 +1,4750 @@ + + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + * @copyright Colin Verot + * @package cmf + * @subpackage external + */ + +/** + * Class upload + * + * What does it do? + * + * It manages file uploads for you. In short, it manages the uploaded file, + * and allows you to do whatever you want with the file, especially if it + * is an image, and as many times as you want. + * + * It is the ideal class to quickly integrate file upload in your site. + * If the file is an image, you can convert, resize, crop it in many ways. + * You can also apply filters, add borders, text, watermarks, etc... + * That's all you need for a gallery script for instance. Supported formats + * are PNG, JPG, GIF and BMP. + * + * You can also use the class to work on local files, which is especially + * useful to use the image manipulation features. The class also supports + * Flash uploaders. + * + * The class works with PHP 4 and 5, and its error messages can + * be localized at will. + * + * How does it work? + * + * You instanciate the class with the $_FILES['my_field'] array + * where my_field is the field name from your upload form. + * The class will check if the original file has been uploaded + * to its temporary location (alternatively, you can instanciate + * the class with a local filename). + * + * You can then set a number of processing variables to act on the file. + * For instance, you can rename the file, and if it is an image, + * convert and resize it in many ways. + * You can also set what will the class do if the file already exists. + * + * Then you call the function {@link process} to actually perform the actions + * according to the processing parameters you set above. + * It will create new instances of the original file, + * so the original file remains the same between each process. + * The file will be manipulated, and copied to the given location. + * The processing variables will be reset once it is done. + * + * You can repeat setting up a new set of processing variables, + * and calling {@link process} again as many times as you want. + * When you have finished, you can call {@link clean} to delete + * the original uploaded file. + * + * If you don't set any processing parameters and call {@link process} + * just after instanciating the class. The uploaded file will be simply + * copied to the given location without any alteration or checks. + * + * Don't forget to add enctype="multipart/form-data" in your form + * tag
if you want your form to upload the file. + * + * How to use it?
+ * Create a simple HTML file, with a form such as: + *
+ * 
+ *   
+ *   
+ * 
+ * 
+ * Create a file called upload.php: + *
+ *  $handle = new upload($_FILES['image_field']);
+ *  if ($handle->uploaded) {
+ *      $handle->file_new_name_body   = 'image_resized';
+ *      $handle->image_resize         = true;
+ *      $handle->image_x              = 100;
+ *      $handle->image_ratio_y        = true;
+ *      $handle->process('/home/user/files/');
+ *      if ($handle->processed) {
+ *          echo 'image resized';
+ *          $handle->clean();
+ *      } else {
+ *          echo 'error : ' . $handle->error;
+ *      }
+ *  }
+ * 
+ * + * How to process local files?
+ * Use the class as following, the rest being the same as above: + *
+ *  $handle = new upload('/home/user/myfile.jpg');
+ * 
+ * + * How to set the language?
+ * Instantiate the class with a second argument being the language code: + *
+ *  $handle = new upload($_FILES['image_field'], 'fr_FR');
+ *  $handle = new upload('/home/user/myfile.jpg', 'fr_FR');
+ * 
+ * + * How to output the resulting file or picture directly to the browser?
+ * Simply call {@link process}() without an argument (or with null as first argument): + *
+ *  $handle = new upload($_FILES['image_field']);
+ *  header('Content-type: ' . $handle->file_src_mime);
+ *  echo $handle->Process();
+ *  die();
+ * 
+ * Or if you want to force the download of the file: + *
+ *  $handle = new upload($_FILES['image_field']);
+ *  header('Content-type: ' . $handle->file_src_mime);
+ *  header("Content-Disposition: attachment; filename=".rawurlencode($handle->file_src_name).";");
+ *  echo $handle->Process();
+ *  die();
+ * 
+ * + * Processing parameters (reset after each process) + *
    + *
  • file_new_name_body replaces the name body (default: '')
    + *
    $handle->file_new_name_body = 'new name';
  • + *
  • file_name_body_add appends to the name body (default: '')
    + *
    $handle->file_name_body_add = '_uploaded';
  • + *
  • file_name_body_pre prepends to the name body (default: '')
    + *
    $handle->file_name_body_pre = 'thumb_';
  • + *
  • file_new_name_ext replaces the file extension (default: '')
    + *
    $handle->file_new_name_ext = 'txt';
  • + *
  • file_safe_name formats the filename (spaces changed to _) (default: true)
    + *
    $handle->file_safe_name = true;
  • + *
  • file_overwrite sets behaviour if file already exists (default: false)
    + *
    $handle->file_overwrite = true;
  • + *
  • file_auto_rename automatically renames file if it already exists (default: true)
    + *
    $handle->file_auto_rename = true;
  • + *
  • auto_create_dir automatically creates destination directory if missing (default: true)
    + *
    $handle->auto_create_dir = true;
  • + *
  • dir_auto_chmod automatically attempts to chmod the destination directory if not writeable (default: true)
    + *
    $handle->dir_auto_chmod = true;
  • + *
  • dir_chmod chmod used when creating directory or if directory not writeable (default: 0777)
    + *
    $handle->dir_chmod = 0777;
  • + *
  • file_max_size sets maximum upload size (default: upload_max_filesize from php.ini)
    + *
    $handle->file_max_size = '1024'; // 1KB
  • + *
  • mime_check sets if the class check the MIME against the {@link allowed} list (default: true)
    + *
    $handle->mime_check = true;
  • + *
  • no_script sets if the class turns scripts into text files (default: true)
    + *
    $handle->no_script = false;
  • + *
  • allowed array of allowed mime-types. wildcard accepted, as in image/* (default: check {@link Init})
    + *
    $handle->allowed = array('application/pdf','application/msword', 'image/*');
  • + *
  • forbidden array of forbidden mime-types. wildcard accepted, as in image/* (default: check {@link Init})
    + *
    $handle->forbidden = array('application/*');
  • + *
+ *
    + *
  • image_convert if set, image will be converted (possible values : ''|'png'|'jpeg'|'gif'|'bmp'; default: '')
    + *
    $handle->image_convert = 'jpg';
  • + *
  • image_background_color if set, will forcibly fill transparent areas with the color, in hexadecimal (default: null)
    + *
    $handle->image_background_color = '#FF00FF';
  • + *
  • image_default_color fallback color background color for non alpha-transparent output formats, such as JPEG or BMP, in hexadecimal (default: #FFFFFF)
    + *
    $handle->image_default_color = '#FF00FF';
  • + *
  • jpeg_quality sets the compression quality for JPEG images (default: 85)
    + *
    $handle->jpeg_quality = 50;
  • + *
  • jpeg_size if set to a size in bytes, will approximate {@link jpeg_quality} so the output image fits within the size (default: null)
    + *
    $handle->jpeg_size = 3072;
  • + *
+ * The following eight settings can be used to invalidate an upload if the file is an image (note that open_basedir restrictions prevent the use of these settings) + *
    + *
  • image_max_width if set to a dimension in pixels, the upload will be invalid if the image width is greater (default: null)
    + *
    $handle->image_max_width = 200;
  • + *
  • image_max_height if set to a dimension in pixels, the upload will be invalid if the image height is greater (default: null)
    + *
    $handle->image_max_height = 100;
  • + *
  • image_max_pixels if set to a number of pixels, the upload will be invalid if the image number of pixels is greater (default: null)
    + *
    $handle->image_max_pixels = 50000;
  • + *
  • image_max_ratio if set to a aspect ratio (width/height), the upload will be invalid if the image apect ratio is greater (default: null)
    + *
    $handle->image_max_ratio = 1.5;
  • + *
  • image_min_width if set to a dimension in pixels, the upload will be invalid if the image width is lower (default: null)
    + *
    $handle->image_min_width = 100;
  • + *
  • image_min_height if set to a dimension in pixels, the upload will be invalid if the image height is lower (default: null)
    + *
    $handle->image_min_height = 500;
  • + *
  • image_min_pixels if set to a number of pixels, the upload will be invalid if the image number of pixels is lower (default: null)
    + *
    $handle->image_min_pixels = 20000;
  • + *
  • image_min_ratio if set to a aspect ratio (width/height), the upload will be invalid if the image apect ratio is lower (default: null)
    + *
    $handle->image_min_ratio = 0.5;
  • + *
+ *
    + *
  • image_resize determines is an image will be resized (default: false)
    + *
    $handle->image_resize = true;
  • + *
+ * The following variables are used only if {@link image_resize} == true + *
    + *
  • image_x destination image width (default: 150)
    + *
    $handle->image_x = 100;
  • + *
  • image_y destination image height (default: 150)
    + *
    $handle->image_y = 200;
  • + *
+ * Use either one of the following + *
    + *
  • image_ratio if true, resize image conserving the original sizes ratio, using {@link image_x} AND {@link image_y} as max sizes if true (default: false)
    + *
    $handle->image_ratio = true;
  • + *
  • image_ratio_crop if true, resize image conserving the original sizes ratio, using {@link image_x} AND {@link image_y} as max sizes, and cropping excedent to fill the space. setting can also be a string, with one or more from 'TBLR', indicating which side of the image will be kept while cropping (default: false)
    + *
    $handle->image_ratio_crop = true;
  • + *
  • image_ratio_fill if true, resize image conserving the original sizes ratio, using {@link image_x} AND {@link image_y} as max sizes, fitting the image in the space and coloring the remaining space. setting can also be a string, with one or more from 'TBLR', indicating which side of the space the image will be in (default: false)
    + *
    $handle->image_ratio_fill = true;
  • + *
  • image_ratio_no_zoom_in same as {@link image_ratio}, but won't resize if the source image is smaller than {@link image_x} x {@link image_y} (default: false)
    + *
    $handle->image_ratio_no_zoom_in = true;
  • + *
  • image_ratio_no_zoom_out same as {@link image_ratio}, but won't resize if the source image is bigger than {@link image_x} x {@link image_y} (default: false)
    + *
    $handle->image_ratio_no_zoom_out = true;
  • + *
  • image_ratio_x if true, resize image, calculating {@link image_x} from {@link image_y} and conserving the original sizes ratio (default: false)
    + *
    $handle->image_ratio_x = true;
  • + *
  • image_ratio_y if true, resize image, calculating {@link image_y} from {@link image_x} and conserving the original sizes ratio (default: false)
    + *
    $handle->image_ratio_y = true;
  • + *
  • image_ratio_pixels if set to a long integer, resize image, calculating {@link image_y} and {@link image_x} to match a the number of pixels (default: false)
    + *
    $handle->image_ratio_pixels = 25000;
  • + *
+ * The following image manipulations require GD2+ + *
    + *
  • image_brightness if set, corrects the brightness. value between -127 and 127 (default: null)
    + *
    $handle->image_brightness = 40;
  • + *
  • image_contrast if set, corrects the contrast. value between -127 and 127 (default: null)
    + *
    $handle->image_contrast = 50;
  • + *
  • image_tint_color if set, will tint the image with a color, value as hexadecimal #FFFFFF (default: null)
    + *
    $handle->image_tint_color = '#FF0000';
  • + *
  • image_overlay_color if set, will add a colored overlay, value as hexadecimal #FFFFFF (default: null)
    + *
    $handle->image_overlay_color = '#FF0000';
  • + *
  • image_overlay_percent used when {@link image_overlay_color} is set, determines the opacity (default: 50)
    + *
    $handle->image_overlay_percent = 20;
  • + *
  • image_negative inverts the colors in the image (default: false)
    + *
    $handle->image_negative = true;
  • + *
  • image_greyscale transforms an image into greyscale (default: false)
    + *
    $handle->image_greyscale = true;
  • + *
  • image_threshold applies a threshold filter. value between -127 and 127 (default: null)
    + *
    $handle->image_threshold = 20;
  • + *
+ *
    + *
  • image_text creates a text label on the image, value is a string, with eventual replacement tokens (default: null)
    + *
    $handle->image_text = 'test';
  • + *
  • image_text_direction text label direction, either 'h' horizontal or 'v' vertical (default: 'h')
    + *
    $handle->image_text_direction = 'v';
  • + *
  • image_text_color text color for the text label, in hexadecimal (default: #FFFFFF)
    + *
    $handle->image_text_color = '#FF0000';
  • + *
  • image_text_percent text opacity on the text label, integer between 0 and 100 (default: 100)
    + *
    $handle->image_text_percent = 50;
  • + *
  • image_text_background text label background color, in hexadecimal (default: null)
    + *
    $handle->image_text_background = '#FFFFFF';
  • + *
  • image_text_background_percent text label background opacity, integer between 0 and 100 (default: 100)
    + *
    $handle->image_text_background_percent = 50;
  • + *
  • image_text_font built-in font for the text label, from 1 to 5. 1 is the smallest (default: 5)
    + *
    $handle->image_text_font = 4;
  • + *
  • image_text_x absolute text label position, in pixels from the left border. can be negative (default: null)
    + *
    $handle->image_text_x = 5;
  • + *
  • image_text_y absolute text label position, in pixels from the top border. can be negative (default: null)
    + *
    $handle->image_text_y = 5;
  • + *
  • image_text_position text label position withing the image, a combination of one or two from 'TBLR': top, bottom, left, right (default: null)
    + *
    $handle->image_text_position = 'LR';
  • + *
  • image_text_padding text label padding, in pixels. can be overridden by {@link image_text_padding_x} and {@link image_text_padding_y} (default: 0)
    + *
    $handle->image_text_padding = 5;
  • + *
  • image_text_padding_x text label horizontal padding (default: null)
    + *
    $handle->image_text_padding_x = 2;
  • + *
  • image_text_padding_y text label vertical padding (default: null)
    + *
    $handle->image_text_padding_y = 10;
  • + *
  • image_text_alignment text alignment when text has multiple lines, either 'L', 'C' or 'R' (default: 'C')
    + *
    $handle->image_text_alignment = 'R';
  • + *
  • image_text_line_spacing space between lines in pixels, when text has multiple lines (default: 0)
    + *
    $handle->image_text_line_spacing = 3;
  • + *
+ *
    + *
  • image_flip flips image, wither 'h' horizontal or 'v' vertical (default: null)
    + *
    $handle->image_flip = 'h';
  • + *
  • image_rotate rotates image. possible values are 90, 180 and 270 (default: null)
    + *
    $handle->image_rotate = 90;
  • + *
  • image_crop crops image. accepts 4, 2 or 1 values as 'T R B L' or 'TB LR' or 'TBLR'. dimension can be 20, or 20px or 20% (default: null)
    + *
    $handle->image_crop = array(50,40,30,20); OR '-20 20%'...
  • + *
  • image_precrop crops image, before an eventual resizing. accepts 4, 2 or 1 values as 'T R B L' or 'TB LR' or 'TBLR'. dimension can be 20, or 20px or 20% (default: null)
    + *
    $handle->image_precrop = array(50,40,30,20); OR '-20 20%'...
  • + *
+ *
    + *
  • image_bevel adds a bevel border to the image. value is thickness in pixels (default: null)
    + *
    $handle->image_bevel = 20;
  • + *
  • image_bevel_color1 top and left bevel color, in hexadecimal (default: #FFFFFF)
    + *
    $handle->image_bevel_color1 = '#FFFFFF';
  • + *
  • image_bevel_color2 bottom and right bevel color, in hexadecimal (default: #000000)
    + *
    $handle->image_bevel_color2 = '#000000';
  • + *
  • image_border adds a unicolor border to the image. accepts 4, 2 or 1 values as 'T R B L' or 'TB LR' or 'TBLR'. dimension can be 20, or 20px or 20% (default: null)
    + *
    $handle->image_border = '3px'; OR '-20 20%' OR array(3,2)...
  • + *
  • image_border_color border color, in hexadecimal (default: #FFFFFF)
    + *
    $handle->image_border_color = '#FFFFFF';
  • + *
  • image_frame type of frame: 1=flat 2=crossed (default: null)
    + *
    $handle->image_frame = 2;
  • + *
  • image_frame_colors list of hex colors, in an array or a space separated string (default: '#FFFFFF #999999 #666666 #000000')
    + *
    $handle->image_frame_colors = array('#999999',  '#FF0000', '#666666', '#333333', '#000000');
  • + *
+ *
    + *
  • image_watermark adds a watermark on the image, value is a local filename. accepted files are GIF, JPG, BMP, PNG and PNG alpha (default: null)
    + *
    $handle->image_watermark = 'watermark.png';
  • + *
  • image_watermark_x absolute watermark position, in pixels from the left border. can be negative (default: null)
    + *
    $handle->image_watermark_x = 5;
  • + *
  • image_watermark_y absolute watermark position, in pixels from the top border. can be negative (default: null)
    + *
    $handle->image_watermark_y = 5;
  • + *
  • image_watermark_position watermark position withing the image, a combination of one or two from 'TBLR': top, bottom, left, right (default: null)
    + *
    $handle->image_watermark_position = 'LR';
  • + *
+ *
    + *
  • image_reflection_height if set, a reflection will be added. Format is either in pixels or percentage, such as 40, '40', '40px' or '40%' (default: null)
    + *
    $handle->image_reflection_height = '25%';
  • + *
  • image_reflection_space space in pixels between the source image and the reflection, can be negative (default: null)
    + *
    $handle->image_reflection_space = 3;
  • + *
  • image_reflection_color reflection background color, in hexadecimal. Now deprecated in favor of {@link image_default_color} (default: #FFFFFF)
    + *
    $handle->image_default_color = '#000000';
  • + *
  • image_reflection_opacity opacity level at which the reflection starts, integer between 0 and 100 (default: 60)
    + *
    $handle->image_reflection_opacity = 60;
  • + *
+ * + * Values that can be read before calling {@link process}() + *
    + *
  • file_src_name Source file name
  • + *
  • file_src_name_body Source file name body
  • + *
  • file_src_name_ext Source file extension
  • + *
  • file_src_pathname Source file complete path and name
  • + *
  • file_src_mime Source file mime type
  • + *
  • file_src_size Source file size in bytes
  • + *
  • file_src_error Upload error code
  • + *
  • file_is_image Boolean flag, true if the file is a supported image type
  • + *
+ * If the file is a supported image type (and open_basedir restrictions allow it) + *
    + *
  • image_src_x Source file width in pixels
  • + *
  • image_src_y Source file height in pixels
  • + *
  • image_src_pixels Source file number of pixels
  • + *
  • image_src_type Source file type (png, jpg, gif or bmp)
  • + *
  • image_src_bits Source file color depth
  • + *
+ * + * Values that can be read after calling {@link process}() + *
    + *
  • file_dst_path Destination file path
  • + *
  • file_dst_name_body Destination file name body
  • + *
  • file_dst_name_ext Destination file extension
  • + *
  • file_dst_name Destination file name
  • + *
  • file_dst_pathname Destination file complete path and name
  • + *
+ * If the file is a supported image type + *
    + *
  • image_dst_x Destination file width
  • + *
  • image_dst_y Destination file height
  • + *
  • image_convert Destination file format
  • + *
+ * + * Requirements + * + * Most of the image operations require GD. GD2 is greatly recommended + * + * The class is compatible with PHP 4.3+, and compatible with PHP5 + * + * Changelog + *
    + *
  • v 0.29 03/02/2010
    + * - added protection against malicious images
    + * - added zip and torrent MIME type
    + * - replaced split() with explode()
    + * - initialise image_dst_x/y with image_src_x/y
    + * - removed {@link mime_fileinfo}, {@link mime_file}, {@link mime_magic} and {@link mime_getimagesize} from the docs since they are used before {@link process}
    + * - added more extensions and MIME types
    + * - improved MIME type validation
    + * - improved logging
  • + *
  • v 0.28 10/08/2009
    + * - replaced ereg functions to be compatible with PHP 5.3
    + * - added flv MIME type
    + * - improved MIME type detection
    + * - added {@link file_name_body_pre} to prepend a string to the file name
    + * - added {@link mime_fileinfo}, {@link mime_file}, {@link mime_magic} and {@link mime_getimagesize} so that it is possible to deactivate some MIME type checking method
    + * - use exec() rather than shell_exec(), to play better with safe mode
    + * - added some error messages
    + * - fix bug when checking on conditions, {@link processed} wasn't propagated properly
  • + *
  • v 0.27 14/05/2009
    + * - look for the language files directory from __FILE__
    + * - deactivate {@link file_auto_rename} if {@link file_overwrite} is set
    + * - improved transparency replacement for true color images
    + * - fixed calls to newer version of UNIX file utility
    + * - fixed error when using PECL Fileinfo extension in SAFE MODE, and when using the finfo class
    + * - added {@link image_precrop} to crop the image before an eventual resizing
  • + *
  • v 0.26 13/11/2008
    + * - rewrote conversion from palette to true color to handle transparency better
    + * - fixed imagecopymergealpha() when the overlayed image is of wrong dimensions
    + * - fixed imagecreatenew() when the image to create have less than 1 pixels width or height
    + * - rewrote MIME type detection to be more secure and not rely on browser information; now using Fileinfo PECL extension, UNIX file() command, MIME magic, and getimagesize(), in that order
    + * - added support for Flash uploaders
    + * - some bug fixing and error handling
  • + *
  • v 0.25 17/11/2007
    + * - added translation files and mechanism to instantiate the class with a language different from English
    + * - added {@link forbidden} to set an array of forbidden MIME types
    + * - implemented support for simple wildcards in {@link allowed} and {@link forbidden}, such as image/*
    + * - preset the file extension to the desired conversion format when converting an image
    + * - added read and write support for BMP images
    + * - added a flag {@link file_is_image} to determine if the file is a supported image type
    + * - the class now provides some information about the image, before calling {@link process}(). Available are {@link image_src_x}, {@link image_src_y} and the newly introduced {@link image_src_bits}, {@link image_src_pixels} and {@link image_src_type}. Note that this will not work if open_basedir restrictions are in place
    + * - improved logging; now provides useful system information
    + * - added some more pre-processing checks for files that are images: {@link image_max_width}, {@link image_max_height}, {@link image_max_pixels}, {@link image_max_ratio}, {@link image_min_width}, {@link image_min_height}, {@link image_min_pixels} and {@link image_min_ratio}
    + * - added {@link image_ratio_pixels} to resize an image to a number of pixels, keeping aspect ratio
    + * - added {@link image_is_palette} and {@link image_is_transparent} and {@link image_transparent_color} for GIF images
    + * - added {@link image_default_color} to define a fallback color for non alpha-transparent output formats, such as JPEG or BMP
    + * - changed {@link image_background_color}, which now forces transparent areas to be painted
    + * - improved reflections and color overlays so that it works with alpha transparent images
    + * - {@link image_reflection_color} is now deprecated in favour of {@link image_default_color}
    + * - transparent PNGs are now processed in true color, and fully preserving the alpha channel when doing merges
    + * - transparent GIFs are now automatically detected. {@link preserve_transparency} is deprecated
    + * - transparent true color images can be saved as GIF while retaining transparency, semi transparent areas being merged with {@link image_default_color}
    + * - transparent true color images can be saved as JPG/BMP with the semi transparent areas being merged with {@link image_default_color}
    + * - fixed conversion of images to true color
    + * - the class can now output the uploaded files content as the return value of process() if the function is called with an empty or null argumenti, or no argument
  • + *
  • v 0.24 25/05/2007
    + * - added {@link image_background_color}, to set the default background color of an image
    + * - added possibility of using replacement tokens in text labels
    + * - changed default JPEG quality to 85
    + * - fixed a small bug when using greyscale filter and associated filters
    + * - added {@link image_ratio_fill} in order to fit an image within some dimensions and color the remaining space. Very similar to {@link image_ratio_crop}
    + * - improved the recursive creation of directories
    + * - the class now converts palette based images to true colors before doing graphic manipulations
  • + *
  • v 0.23 23/12/2006
    + * - fixed a bug when processing more than once the same uploaded file. If there is an open_basedir restriction, the class now creates a temporary file for the first call to process(). This file will be used for subsequent processes, and will be deleted upon calling clean()
  • + *
  • v 0.22 16/12/2006
    + * - added automatic creation of a temporary file if the upload directory is not within open_basedir
    + * - fixed a bug which was preventing to work on a local file by overwriting it with its processed copy
    + * - added MIME types video/x-ms-wmv and image/x-png and fixed PNG support for IE weird MIME types
    + * - modified {@link image_ratio_crop} so it can accept one or more from string 'TBLR', determining which side of the image is kept while cropping
    + * - added support for multiple lines in the text, using "\n" as a line break
    + * - added {@link image_text_line_spacing} which allow to set the space between several lines of text
    + * - added {@link image_text_alignment} which allow to set the alignment when text has several lines
    + * - {@link image_text_font} can now be set to the path of a GDF font to load external fonts
    + * - added {@link image_reflection_height} to create a reflection of the source image, which height is in pixels or percentage
    + * - added {@link image_reflection_space} to set the space in pixels between the source image and the reflection
    + * - added {@link image_reflection_color} to set the reflection background color
    + * - added {@link image_reflection_opacity} to set the initial level of opacity of the reflection
  • + *
  • v 0.21 30/09/2006
    + * - added {@link image_ratio_crop} which resizes within {@link image_x} and {@link image_y}, keeping ratio, but filling the space by cropping excedent of image
    + * - added {@link mime_check}, which default is true, to set checks against {@link allowed} MIME list
    + * - if MIME is empty, the class now triggers an error
    + * - color #000000 is OK for {@link image_text_color}, and related text transparency bug fixed
    + * - {@link gd_version}() now uses gd_info(), or else phpinfo()
    + * - fixed path issue when the destination path has no trailing slash on Windows systems
    + * - removed inline functions to be fully PHP5 compatible
  • + *
  • v 0.20 11/08/2006
    + * - added some more error checking and messages (GD presence, permissions...)
    + * - fix when uploading files without extension
    + * - changed values for {@link image_brightness} and {@link image_contrast} to be between -127 and 127
    + * - added {@link dir_auto_create} to automatically and recursively create destination directory if missing.
    + * - added {@link dir_auto_chmod} to automatically chmod the destination directory if not writeable.
    + * - added {@link dir_chmod} to set the default chmod to use.
    + * - added {@link image_crop} to crop images
    + * - added {@link image_negative} to invert the colors on the image
    + * - added {@link image_greyscale} to turn the image into greyscale
    + * - added {@link image_threshold} to apply a threshold filter on the image
    + * - added {@link image_bevel}, {@link image_bevel_color1} and {@link image_bevel_color2} to add a bevel border
    + * - added {@link image_border} and {@link image_border_color} to add a single color border
    + * - added {@link image_frame} and {@link image_frame_colors} to add a multicolored frame
  • + *
  • v 0.19 29/03/2006
    + * - class is now compatible i18n (thanks Sylwester).
    + * - the class can mow manipulate local files, not only uploaded files (instanciate the class with a local filename).
    + * - {@link file_safe_name} has been improved a bit.
    + * - added {@link image_brightness}, {@link image_contrast}, {@link image_tint_color}, {@link image_overlay_color} and {@link image_overlay_percent} to do color manipulation on the images.
    + * - added {@link image_text} and all derivated settings to add a text label on the image.
    + * - added {@link image_watermark} and all derivated settings to add a watermark image on the image.
    + * - added {@link image_flip} and {@link image_rotate} for more image manipulations
    + * - added {@link jpeg_size} to calculate the JPG compression quality in order to fit within one filesize.
  • + *
  • v 0.18 02/02/2006
    + * - added {@link no_script} to turn dangerous scripts into text files.
    + * - added {@link mime_magic_check} to set the class to use mime_magic.
    + * - added {@link preserve_transparency} *experimental*. Thanks Gregor.
    + * - fixed size and mime checking, wasn't working :/ Thanks Willem.
    + * - fixed memory leak when resizing images.
    + * - when resizing, it is not necessary anymore to set {@link image_convert}.
    + * - il is now possible to simply convert an image, with no resizing.
    + * - sets the default {@link file_max_size} to upload_max_filesize from php.ini. Thanks Edward
  • + *
  • v 0.17 28/05/2005
    + * - the class can be used with any version of GD.
    + * - added security check on the file with a list of mime-types.
    + * - changed the license to GPL v2 only
  • + *
  • v 0.16 19/05/2005
    + * - added {@link file_auto_rename} automatic file renaming if the same filename already exists.
    + * - added {@link file_safe_name} safe formatting of the filename (spaces to _underscores so far).
    + * - added some more error reporting to avoid crash if GD is not present
  • + *
  • v 0.15 16/04/2005
    + * - added JPEG compression quality setting. Thanks Vad
  • + *
  • v 0.14 14/03/2005
    + * - reworked the class file to allow parsing with phpDocumentor
  • + *
  • v 0.13 07/03/2005
    + * - fixed a bug with {@link image_ratio}. Thanks Justin.
    + * - added {@link image_ratio_no_zoom_in} and {@link image_ratio_no_zoom_out}
  • + *
  • v 0.12 21/01/2005
    + * - added {@link image_ratio} to resize within max values, keeping image ratio
  • + *
  • v 0.11 22/08/2003
    + * - update for GD2 (changed imageresized() into imagecopyresampled() and imagecreate() into imagecreatetruecolor())
  • + *
+ * + * @package cmf + * @subpackage external + */ +class Verot_Upload { + + + /** + * Class version + * + * @access public + * @var string + */ + var $version; + + /** + * Uploaded file name + * + * @access public + * @var string + */ + var $file_src_name; + + /** + * Uploaded file name body (i.e. without extension) + * + * @access public + * @var string + */ + var $file_src_name_body; + + /** + * Uploaded file name extension + * + * @access public + * @var string + */ + var $file_src_name_ext; + + /** + * Uploaded file MIME type + * + * @access public + * @var string + */ + var $file_src_mime; + + /** + * Uploaded file size, in bytes + * + * @access public + * @var double + */ + var $file_src_size; + + /** + * Holds eventual PHP error code from $_FILES + * + * @access public + * @var string + */ + var $file_src_error; + + /** + * Uloaded file name, including server path + * + * @access private + * @var string + */ + var $file_src_pathname; + + /** + * Uloaded file name temporary copy + * + * @access private + * @var string + */ + var $file_src_temp; + + /** + * Destination file name + * + * @access private + * @var string + */ + var $file_dst_path; + + /** + * Destination file name + * + * @access public + * @var string + */ + var $file_dst_name; + + /** + * Destination file name body (i.e. without extension) + * + * @access public + * @var string + */ + var $file_dst_name_body; + + /** + * Destination file extension + * + * @access public + * @var string + */ + var $file_dst_name_ext; + + /** + * Destination file name, including path + * + * @access private + * @var string + */ + var $file_dst_pathname; + + /** + * Source image width + * + * @access private + * @var integer + */ + var $image_src_x; + + /** + * Source image height + * + * @access private + * @var integer + */ + var $image_src_y; + + /** + * Source image color depth + * + * @access private + * @var integer + */ + var $image_src_bits; + + /** + * Number of pixels + * + * @access private + * @var long + */ + var $image_src_pixels; + + /** + * Type of image (png, gif, jpg or bmp) + * + * @access private + * @var string + */ + var $image_src_type; + + /** + * Destination image width + * + * @access private + * @var integer + */ + var $image_dst_x; + + /** + * Destination image height + * + * @access private + * @var integer + */ + var $image_dst_y; + + /** + * Supported image formats + * + * @access private + * @var array + */ + var $image_supported; + + /** + * Flag to determine if the source file is an image + * + * @access private + * @var boolean + */ + var $file_is_image; + + /** + * Flag set after instanciating the class + * + * Indicates if the file has been uploaded properly + * + * @access public + * @var bool + */ + var $uploaded; + + /** + * Flag stopping PHP upload checks + * + * Indicates whether we instanciated the class with a filename, in which case + * we will not check on the validity of the PHP *upload* + * + * This flag is automatically set to true when working on a local file + * + * Warning: for uploads, this flag MUST be set to false for security reason + * + * @access public + * @var bool + */ + var $no_upload_check; + + /** + * Flag set after calling a process + * + * Indicates if the processing, and copy of the resulting file went OK + * + * @access public + * @var bool + */ + var $processed; + + /** + * Holds eventual error message in plain english + * + * @access public + * @var string + */ + var $error; + + /** + * Holds an HTML formatted log + * + * @access public + * @var string + */ + var $log; + + + // overiddable processing variables + + + /** + * Set this variable to replace the name body (i.e. without extension) + * + * @access public + * @var string + */ + var $file_new_name_body; + + /** + * Set this variable to append a string to the file name body + * + * @access public + * @var string + */ + var $file_name_body_add; + + /** + * Set this variable to prepend a string to the file name body + * + * @access public + * @var string + */ + var $file_name_body_pre; + + /** + * Set this variable to change the file extension + * + * @access public + * @var string + */ + var $file_new_name_ext; + + /** + * Set this variable to format the filename (spaces changed to _) + * + * @access public + * @var boolean + */ + var $file_safe_name; + + /** + * Set this variable to false if you don't want to check the MIME against the allowed list + * + * This variable is set to true by default for security reason + * + * @access public + * @var boolean + */ + var $mime_check; + + /** + * Set this variable to false if you don't want to check the MIME with Fileinfo PECL extension + * + * You can also set it with the path of the magic database file. + * If set to true, the class will try to read the MAGIC environment variable + * and if it is empty, will default to '/usr/share/file/magic' + * If set to an empty string, it will call finfo_open without the path argument + * + * This variable is set to true by default for security reason + * + * @access public + * @var boolean + */ + var $mime_fileinfo; + + /** + * Set this variable to false if you don't want to check the MIME with UNIX file() command + * + * This variable is set to true by default for security reason + * + * @access public + * @var boolean + */ + var $mime_file; + + /** + * Set this variable to false if you don't want to check the MIME with the magic.mime file + * + * The function mime_content_type() will be deprecated, + * and this variable will be set to false in a future release + * + * This variable is set to true by default for security reason + * + * @access public + * @var boolean + */ + var $mime_magic; + + /** + * Set this variable to false if you don't want to check the MIME with getimagesize() + * + * The class tries to get a MIME type from getimagesize() + * If no MIME is returned, it tries to guess the MIME type from the file type + * + * This variable is set to true by default for security reason + * + * @access public + * @var boolean + */ + var $mime_getimagesize; + + /** + * Set this variable to false if you don't want to turn dangerous scripts into simple text files + * + * @access public + * @var boolean + */ + var $no_script; + + /** + * Set this variable to true to allow automatic renaming of the file + * if the file already exists + * + * Default value is true + * + * For instance, on uploading foo.ext,
+ * if foo.ext already exists, upload will be renamed foo_1.ext
+ * and if foo_1.ext already exists, upload will be renamed foo_2.ext
+ * + * Note that this option doesn't have any effect if {@link file_overwrite} is true + * + * @access public + * @var bool + */ + var $file_auto_rename; + + /** + * Set this variable to true to allow automatic creation of the destination + * directory if it is missing (works recursively) + * + * Default value is true + * + * @access public + * @var bool + */ + var $dir_auto_create; + + /** + * Set this variable to true to allow automatic chmod of the destination + * directory if it is not writeable + * + * Default value is true + * + * @access public + * @var bool + */ + var $dir_auto_chmod; + + /** + * Set this variable to the default chmod you want the class to use + * when creating directories, or attempting to write in a directory + * + * Default value is 0777 (without quotes) + * + * @access public + * @var bool + */ + var $dir_chmod; + + /** + * Set this variable tu true to allow overwriting of an existing file + * + * Default value is false, so no files will be overwritten + * + * @access public + * @var bool + */ + var $file_overwrite; + + /** + * Set this variable to change the maximum size in bytes for an uploaded file + * + * Default value is the value upload_max_filesize from php.ini + * + * @access public + * @var double + */ + var $file_max_size; + + /** + * Set this variable to true to resize the file if it is an image + * + * You will probably want to set {@link image_x} and {@link image_y}, and maybe one of the ratio variables + * + * Default value is false (no resizing) + * + * @access public + * @var bool + */ + var $image_resize; + + /** + * Set this variable to convert the file if it is an image + * + * Possibles values are : ''; 'png'; 'jpeg'; 'gif'; 'bmp' + * + * Default value is '' (no conversion)
+ * If {@link resize} is true, {@link convert} will be set to the source file extension + * + * @access public + * @var string + */ + var $image_convert; + + /** + * Set this variable to the wanted (or maximum/minimum) width for the processed image, in pixels + * + * Default value is 150 + * + * @access public + * @var integer + */ + var $image_x; + + /** + * Set this variable to the wanted (or maximum/minimum) height for the processed image, in pixels + * + * Default value is 150 + * + * @access public + * @var integer + */ + var $image_y; + + /** + * Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y} + * + * Default value is false + * + * @access public + * @var bool + */ + var $image_ratio; + + /** + * Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y} + * + * The image will be resized as to fill the whole space, and excedent will be cropped + * + * Value can also be a string, one or more character from 'TBLR' (top, bottom, left and right) + * If set as a string, it determines which side of the image is kept while cropping. + * By default, the part of the image kept is in the center, i.e. it crops equally on both sides + * + * Default value is false + * + * @access public + * @var mixed + */ + var $image_ratio_crop; + + /** + * Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y} + * + * The image will be resized to fit entirely in the space, and the rest will be colored. + * The default color is white, but can be set with {@link image_default_color} + * + * Value can also be a string, one or more character from 'TBLR' (top, bottom, left and right) + * If set as a string, it determines in which side of the space the image is displayed. + * By default, the image is displayed in the center, i.e. it fills the remaining space equally on both sides + * + * Default value is false + * + * @access public + * @var mixed + */ + var $image_ratio_fill; + + /** + * Set this variable to a number of pixels so that {@link image_x} and {@link image_y} are the best match possible + * + * The image will be resized to have approximatively the number of pixels + * The aspect ratio wil be conserved + * + * Default value is false + * + * @access public + * @var mixed + */ + var $image_ratio_pixels; + + /** + * Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y}, + * but only if original image is bigger + * + * Default value is false + * + * @access public + * @var bool + */ + var $image_ratio_no_zoom_in; + + /** + * Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y}, + * but only if original image is smaller + * + * Default value is false + * + * @access public + * @var bool + */ + var $image_ratio_no_zoom_out; + + /** + * Set this variable to calculate {@link image_x} automatically , using {@link image_y} and conserving ratio + * + * Default value is false + * + * @access public + * @var bool + */ + var $image_ratio_x; + + /** + * Set this variable to calculate {@link image_y} automatically , using {@link image_x} and conserving ratio + * + * Default value is false + * + * @access public + * @var bool + */ + var $image_ratio_y; + + /** + * Set this variable to set a maximum image width, above which the upload will be invalid + * + * Default value is null + * + * @access public + * @var integer + */ + var $image_max_width; + + /** + * Set this variable to set a maximum image height, above which the upload will be invalid + * + * Default value is null + * + * @access public + * @var integer + */ + var $image_max_height; + + /** + * Set this variable to set a maximum number of pixels for an image, above which the upload will be invalid + * + * Default value is null + * + * @access public + * @var long + */ + var $image_max_pixels; + + /** + * Set this variable to set a maximum image aspect ratio, above which the upload will be invalid + * + * Note that ratio = width / height + * + * Default value is null + * + * @access public + * @var float + */ + var $image_max_ratio; + + /** + * Set this variable to set a minimum image width, below which the upload will be invalid + * + * Default value is null + * + * @access public + * @var integer + */ + var $image_min_width; + + /** + * Set this variable to set a minimum image height, below which the upload will be invalid + * + * Default value is null + * + * @access public + * @var integer + */ + var $image_min_height; + + /** + * Set this variable to set a minimum number of pixels for an image, below which the upload will be invalid + * + * Default value is null + * + * @access public + * @var long + */ + var $image_min_pixels; + + /** + * Set this variable to set a minimum image aspect ratio, below which the upload will be invalid + * + * Note that ratio = width / height + * + * Default value is null + * + * @access public + * @var float + */ + var $image_min_ratio; + + /** + * Quality of JPEG created/converted destination image + * + * Default value is 85 + * + * @access public + * @var integer + */ + var $jpeg_quality; + + /** + * Determines the quality of the JPG image to fit a desired file size + * + * Value is in bytes. The JPG quality will be set between 1 and 100% + * The calculations are approximations. + * + * Default value is null (no calculations) + * + * @access public + * @var integer + */ + var $jpeg_size; + + /** + * Preserve transparency when resizing or converting an image (deprecated) + * + * Default value is automatically set to true for transparent GIFs + * This setting is now deprecated + * + * @access public + * @var integer + */ + var $preserve_transparency; + + /** + * Flag set to true when the image is transparent + * + * This is actually used only for transparent GIFs + * + * @access public + * @var boolean + */ + var $image_is_transparent; + + /** + * Transparent color in a palette + * + * This is actually used only for transparent GIFs + * + * @access public + * @var boolean + */ + var $image_transparent_color; + + /** + * Background color, used to paint transparent areas with + * + * If set, it will forcibly remove transparency by painting transparent areas with the color + * This setting will fill in all transparent areas in PNG and GIF, as opposed to {@link image_default_color} + * which will do so only in BMP, JPEG, and alpha transparent areas in transparent GIFs + * This setting overrides {@link image_default_color} + * + * Default value is null + * + * @access public + * @var string + */ + var $image_background_color; + + /** + * Default color for non alpha-transparent images + * + * This setting is to be used to define a background color for semi transparent areas + * of an alpha transparent when the output format doesn't support alpha transparency + * This is useful when, from an alpha transparent PNG image, or an image with alpha transparent features + * if you want to output it as a transparent GIFs for instance, you can set a blending color for transparent areas + * If you output in JPEG or BMP, this color will be used to fill in the previously transparent areas + * + * The default color white + * + * @access public + * @var boolean + */ + var $image_default_color; + + /** + * Flag set to true when the image is not true color + * + * @access public + * @var boolean + */ + var $image_is_palette; + + /** + * Corrects the image brightness + * + * Value can range between -127 and 127 + * + * Default value is null + * + * @access public + * @var integer + */ + var $image_brightness; + + /** + * Corrects the image contrast + * + * Value can range between -127 and 127 + * + * Default value is null + * + * @access public + * @var integer + */ + var $image_contrast; + + /** + * Applies threshold filter + * + * Value can range between -127 and 127 + * + * Default value is null + * + * @access public + * @var integer + */ + var $image_threshold; + + /** + * Applies a tint on the image + * + * Value is an hexadecimal color, such as #FFFFFF + * + * Default value is null + * + * @access public + * @var string; + */ + var $image_tint_color; + + /** + * Applies a colored overlay on the image + * + * Value is an hexadecimal color, such as #FFFFFF + * + * To use with {@link image_overlay_percent} + * + * Default value is null + * + * @access public + * @var string; + */ + var $image_overlay_color; + + /** + * Sets the percentage for the colored overlay + * + * Value is a percentage, as an integer between 0 and 100 + * + * Unless used with {@link image_overlay_color}, this setting has no effect + * + * Default value is 50 + * + * @access public + * @var integer + */ + var $image_overlay_percent; + + /** + * Inverts the color of an image + * + * Default value is FALSE + * + * @access public + * @var boolean; + */ + var $image_negative; + + /** + * Turns the image into greyscale + * + * Default value is FALSE + * + * @access public + * @var boolean; + */ + var $image_greyscale; + + /** + * Adds a text label on the image + * + * Value is a string, any text. Text will not word-wrap, although you can use breaklines in your text "\n" + * + * If set, this setting allow the use of all other settings starting with image_text_ + * + * Replacement tokens can be used in the string: + *
+     * gd_version    src_name       src_name_body src_name_ext
+     * src_pathname  src_mime       src_x         src_y
+     * src_type      src_bits       src_pixels
+     * src_size      src_size_kb    src_size_mb   src_size_human
+     * dst_path      dst_name_body  dst_pathname
+     * dst_name      dst_name_ext   dst_x         dst_y
+     * date          time           host          server        ip
+     * 
+ * The tokens must be enclosed in square brackets: [dst_x] will be replaced by the width of the picture + * + * Default value is null + * + * @access public + * @var string; + */ + var $image_text; + + /** + * Sets the text direction for the text label + * + * Value is either 'h' or 'v', as in horizontal and vertical + * + * Default value is h (horizontal) + * + * @access public + * @var string; + */ + var $image_text_direction; + + /** + * Sets the text color for the text label + * + * Value is an hexadecimal color, such as #FFFFFF + * + * Default value is #FFFFFF (white) + * + * @access public + * @var string; + */ + var $image_text_color; + + /** + * Sets the text visibility in the text label + * + * Value is a percentage, as an integer between 0 and 100 + * + * Default value is 100 + * + * @access public + * @var integer + */ + var $image_text_percent; + + /** + * Sets the text background color for the text label + * + * Value is an hexadecimal color, such as #FFFFFF + * + * Default value is null (no background) + * + * @access public + * @var string; + */ + var $image_text_background; + + /** + * Sets the text background visibility in the text label + * + * Value is a percentage, as an integer between 0 and 100 + * + * Default value is 100 + * + * @access public + * @var integer + */ + var $image_text_background_percent; + + /** + * Sets the text font in the text label + * + * Value is a an integer between 1 and 5 for GD built-in fonts. 1 is the smallest font, 5 the biggest + * Value can also be a string, which represents the path to a GDF font. The font will be loaded into GD, and used as a built-in font. + * + * Default value is 5 + * + * @access public + * @var mixed; + */ + var $image_text_font; + + /** + * Sets the text label position within the image + * + * Value is one or two out of 'TBLR' (top, bottom, left, right) + * + * The positions are as following: + *
+     *                        TL  T  TR
+     *                        L       R
+     *                        BL  B  BR
+     * 
+ * + * Default value is null (centered, horizontal and vertical) + * + * Note that is {@link image_text_x} and {@link image_text_y} are used, this setting has no effect + * + * @access public + * @var string; + */ + var $image_text_position; + + /** + * Sets the text label absolute X position within the image + * + * Value is in pixels, representing the distance between the left of the image and the label + * If a negative value is used, it will represent the distance between the right of the image and the label + * + * Default value is null (so {@link image_text_position} is used) + * + * @access public + * @var integer + */ + var $image_text_x; + + /** + * Sets the text label absolute Y position within the image + * + * Value is in pixels, representing the distance between the top of the image and the label + * If a negative value is used, it will represent the distance between the bottom of the image and the label + * + * Default value is null (so {@link image_text_position} is used) + * + * @access public + * @var integer + */ + var $image_text_y; + + /** + * Sets the text label padding + * + * Value is in pixels, representing the distance between the text and the label background border + * + * Default value is 0 + * + * This setting can be overriden by {@link image_text_padding_x} and {@link image_text_padding_y} + * + * @access public + * @var integer + */ + var $image_text_padding; + + /** + * Sets the text label horizontal padding + * + * Value is in pixels, representing the distance between the text and the left and right label background borders + * + * Default value is null + * + * If set, this setting overrides the horizontal part of {@link image_text_padding} + * + * @access public + * @var integer + */ + var $image_text_padding_x; + + /** + * Sets the text label vertical padding + * + * Value is in pixels, representing the distance between the text and the top and bottom label background borders + * + * Default value is null + * + * If set, his setting overrides the vertical part of {@link image_text_padding} + * + * @access public + * @var integer + */ + var $image_text_padding_y; + + /** + * Sets the text alignment + * + * Value is a string, which can be either 'L', 'C' or 'R' + * + * Default value is 'C' + * + * This setting is relevant only if the text has several lines. + * + * @access public + * @var string; + */ + var $image_text_alignment; + + /** + * Sets the text line spacing + * + * Value is an integer, in pixels + * + * Default value is 0 + * + * This setting is relevant only if the text has several lines. + * + * @access public + * @var integer + */ + var $image_text_line_spacing; + + /** + * Sets the height of the reflection + * + * Value is an integer in pixels, or a string which format can be in pixels or percentage. + * For instance, values can be : 40, '40', '40px' or '40%' + * + * Default value is null, no reflection + * + * @access public + * @var mixed; + */ + var $image_reflection_height; + + /** + * Sets the space between the source image and its relection + * + * Value is an integer in pixels, which can be negative + * + * Default value is 2 + * + * This setting is relevant only if {@link image_reflection_height} is set + * + * @access public + * @var integer + */ + var $image_reflection_space; + + /** + * Sets the color of the reflection background (deprecated) + * + * Value is an hexadecimal color, such as #FFFFFF + * + * Default value is #FFFFFF + * + * This setting is relevant only if {@link image_reflection_height} is set + * + * This setting is now deprecated in favor of {@link image_default_color} + * + * @access public + * @var string; + */ + var $image_reflection_color; + + /** + * Sets the initial opacity of the reflection + * + * Value is an integer between 0 (no opacity) and 100 (full opacity). + * The reflection will start from {@link image_reflection_opacity} and end up at 0 + * + * Default value is 60 + * + * This setting is relevant only if {@link image_reflection_height} is set + * + * @access public + * @var integer + */ + var $image_reflection_opacity; + + /** + * Flips the image vertically or horizontally + * + * Value is either 'h' or 'v', as in horizontal and vertical + * + * Default value is null (no flip) + * + * @access public + * @var string; + */ + var $image_flip; + + /** + * Rotates the image by increments of 45 degrees + * + * Value is either 90, 180 or 270 + * + * Default value is null (no rotation) + * + * @access public + * @var string; + */ + var $image_rotate; + + /** + * Crops an image + * + * Values are four dimensions, or two, or one (CSS style) + * They represent the amount cropped top, right, bottom and left. + * These values can either be in an array, or a space separated string. + * Each value can be in pixels (with or without 'px'), or percentage (of the source image) + * + * For instance, are valid: + *
+     * $foo->image_crop = 20                  OR array(20);
+     * $foo->image_crop = '20px'              OR array('20px');
+     * $foo->image_crop = '20 40'             OR array('20', 40);
+     * $foo->image_crop = '-20 25%'           OR array(-20, '25%');
+     * $foo->image_crop = '20px 25%'          OR array('20px', '25%');
+     * $foo->image_crop = '20% 25%'           OR array('20%', '25%');
+     * $foo->image_crop = '20% 25% 10% 30%'   OR array('20%', '25%', '10%', '30%');
+     * $foo->image_crop = '20px 25px 2px 2px' OR array('20px', '25%px', '2px', '2px');
+     * $foo->image_crop = '20 25% 40px 10%'   OR array(20, '25%', '40px', '10%');
+     * 
+ * + * If a value is negative, the image will be expanded, and the extra parts will be filled with black + * + * Default value is null (no cropping) + * + * @access public + * @var string OR array; + */ + var $image_crop; + + /** + * Crops an image, before an eventual resizing + * + * See {@link image_crop} for valid formats + * + * Default value is null (no cropping) + * + * @access public + * @var string OR array; + */ + var $image_precrop; + + /** + * Adds a bevel border on the image + * + * Value is a positive integer, representing the thickness of the bevel + * + * If the bevel colors are the same as the background, it makes a fade out effect + * + * Default value is null (no bevel) + * + * @access public + * @var integer + */ + var $image_bevel; + + /** + * Top and left bevel color + * + * Value is a color, in hexadecimal format + * This setting is used only if {@link image_bevel} is set + * + * Default value is #FFFFFF + * + * @access public + * @var string; + */ + var $image_bevel_color1; + + /** + * Right and bottom bevel color + * + * Value is a color, in hexadecimal format + * This setting is used only if {@link image_bevel} is set + * + * Default value is #000000 + * + * @access public + * @var string; + */ + var $image_bevel_color2; + + /** + * Adds a single-color border on the outer of the image + * + * Values are four dimensions, or two, or one (CSS style) + * They represent the border thickness top, right, bottom and left. + * These values can either be in an array, or a space separated string. + * Each value can be in pixels (with or without 'px'), or percentage (of the source image) + * + * See {@link image_crop} for valid formats + * + * If a value is negative, the image will be cropped. + * Note that the dimensions of the picture will be increased by the borders' thickness + * + * Default value is null (no border) + * + * @access public + * @var integer + */ + var $image_border; + + /** + * Border color + * + * Value is a color, in hexadecimal format. + * This setting is used only if {@link image_border} is set + * + * Default value is #FFFFFF + * + * @access public + * @var string; + */ + var $image_border_color; + + /** + * Adds a multi-color frame on the outer of the image + * + * Value is an integer. Two values are possible for now: + * 1 for flat border, meaning that the frame is mirrored horizontally and vertically + * 2 for crossed border, meaning that the frame will be inversed, as in a bevel effect + * + * The frame will be composed of colored lines set in {@link image_frame_colors} + * + * Note that the dimensions of the picture will be increased by the borders' thickness + * + * Default value is null (no frame) + * + * @access public + * @var integer + */ + var $image_frame; + + /** + * Sets the colors used to draw a frame + * + * Values is a list of n colors in hexadecimal format. + * These values can either be in an array, or a space separated string. + * + * The colors are listed in the following order: from the outset of the image to its center + * + * For instance, are valid: + *
+     * $foo->image_frame_colors = '#FFFFFF #999999 #666666 #000000';
+     * $foo->image_frame_colors = array('#FFFFFF', '#999999', '#666666', '#000000');
+     * 
+ * + * This setting is used only if {@link image_frame} is set + * + * Default value is '#FFFFFF #999999 #666666 #000000' + * + * @access public + * @var string OR array; + */ + var $image_frame_colors; + + /** + * Adds a watermark on the image + * + * Value is a local image filename, relative or absolute. GIF, JPG, BMP and PNG are supported, as well as PNG alpha. + * + * If set, this setting allow the use of all other settings starting with image_watermark_ + * + * Default value is null + * + * @access public + * @var string; + */ + var $image_watermark; + + /** + * Sets the watermarkposition within the image + * + * Value is one or two out of 'TBLR' (top, bottom, left, right) + * + * The positions are as following: TL T TR + * L R + * BL B BR + * + * Default value is null (centered, horizontal and vertical) + * + * Note that is {@link image_watermark_x} and {@link image_watermark_y} are used, this setting has no effect + * + * @access public + * @var string; + */ + var $image_watermark_position; + + /** + * Sets the watermark absolute X position within the image + * + * Value is in pixels, representing the distance between the top of the image and the watermark + * If a negative value is used, it will represent the distance between the bottom of the image and the watermark + * + * Default value is null (so {@link image_watermark_position} is used) + * + * @access public + * @var integer + */ + var $image_watermark_x; + + /** + * Sets the twatermark absolute Y position within the image + * + * Value is in pixels, representing the distance between the left of the image and the watermark + * If a negative value is used, it will represent the distance between the right of the image and the watermark + * + * Default value is null (so {@link image_watermark_position} is used) + * + * @access public + * @var integer + */ + var $image_watermark_y; + + /** + * Allowed MIME types + * + * Default is a selection of safe mime-types, but you might want to change it + * + * Simple wildcards are allowed, such as image/* or application/* + * + * @access public + * @var array + */ + var $allowed; + + /** + * Forbidden MIME types + * + * Default is a selection of safe mime-types, but you might want to change it + * To only check for forbidden MIME types, and allow everything else, set {@link allowed} to array('* / *') without the spaces + * + * Simple wildcards are allowed, such as image/* or application/* + * + * @access public + * @var array + */ + var $forbidden; + + /** + * Array of translated error messages + * + * By default, the language is english (en_GB) + * Translations can be in separate files, in a lang/ subdirectory + * + * @access public + * @var array + */ + var $translation; + + /** + * Language selected for the translations + * + * By default, the language is english ("en_GB") + * + * @access public + * @var array + */ + var $language; + + /** + * Init or re-init all the processing variables to their default values + * + * This function is called in the constructor, and after each call of {@link process} + * + * @access private + */ + function init() { + + // overiddable variables + $this->file_new_name_body = ''; // replace the name body + $this->file_name_body_add = ''; // append to the name body + $this->file_name_body_pre = ''; // prepend to the name body + $this->file_new_name_ext = ''; // replace the file extension + $this->file_safe_name = true; // format safely the filename + $this->file_overwrite = false; // allows overwritting if the file already exists + $this->file_auto_rename = true; // auto-rename if the file already exists + $this->dir_auto_create = true; // auto-creates directory if missing + $this->dir_auto_chmod = true; // auto-chmod directory if not writeable + $this->dir_chmod = 0777; // default chmod to use + + $this->mime_check = true; // checks the mime type against the allowed list + $this->mime_fileinfo = true; // MIME detection with Fileinfo PECL extension + $this->mime_file = true; // MIME detection with UNIX file() command + $this->mime_magic = true; // MIME detection with mime_magic (mime_content_type()) + $this->mime_getimagesize = true; // MIME detection with getimagesize() + $this->no_script = true; // turns scripts into test files + + $val = trim(ini_get('upload_max_filesize')); + $last = strtolower($val{strlen($val)-1}); + switch($last) { + case 'g': + $val *= 1024; + case 'm': + $val *= 1024; + case 'k': + $val *= 1024; + } + $this->file_max_size = $val; + + $this->image_resize = false; // resize the image + $this->image_convert = ''; // convert. values :''; 'png'; 'jpeg'; 'gif'; 'bmp' + + $this->image_x = 150; + $this->image_y = 150; + $this->image_ratio = false; // keeps aspect ratio with x and y dimensions + $this->image_ratio_crop = false; // keeps aspect ratio with x and y dimensions, filling the space + $this->image_ratio_fill = false; // keeps aspect ratio with x and y dimensions, fitting the image in the space, and coloring the rest + $this->image_ratio_pixels = false; // keeps aspect ratio, calculating x and y so that the image is approx the set number of pixels + $this->image_ratio_no_zoom_in = false; + $this->image_ratio_no_zoom_out = false; + $this->image_ratio_x = false; // calculate the $image_x if true + $this->image_ratio_y = false; // calculate the $image_y if true + $this->jpeg_quality = 85; + $this->jpeg_size = null; + $this->preserve_transparency = false; + $this->image_is_transparent = false; + $this->image_transparent_color = null; + $this->image_background_color = null; + $this->image_default_color = '#ffffff'; + $this->image_is_palette = false; + + $this->image_max_width = null; + $this->image_max_height = null; + $this->image_max_pixels = null; + $this->image_max_ratio = null; + $this->image_min_width = null; + $this->image_min_height = null; + $this->image_min_pixels = null; + $this->image_min_ratio = null; + + $this->image_brightness = null; + $this->image_contrast = null; + $this->image_threshold = null; + $this->image_tint_color = null; + $this->image_overlay_color = null; + $this->image_overlay_percent = null; + $this->image_negative = false; + $this->image_greyscale = false; + + $this->image_text = null; + $this->image_text_direction = null; + $this->image_text_color = '#FFFFFF'; + $this->image_text_percent = 100; + $this->image_text_background = null; + $this->image_text_background_percent = 100; + $this->image_text_font = 5; + $this->image_text_x = null; + $this->image_text_y = null; + $this->image_text_position = null; + $this->image_text_padding = 0; + $this->image_text_padding_x = null; + $this->image_text_padding_y = null; + $this->image_text_alignment = 'C'; + $this->image_text_line_spacing = 0; + + $this->image_reflection_height = null; + $this->image_reflection_space = 2; + $this->image_reflection_color = '#ffffff'; + $this->image_reflection_opacity = 60; + + $this->image_watermark = null; + $this->image_watermark_x = null; + $this->image_watermark_y = null; + $this->image_watermark_position = null; + + $this->image_flip = null; + $this->image_rotate = null; + $this->image_crop = null; + $this->image_precrop = null; + + $this->image_bevel = null; + $this->image_bevel_color1 = '#FFFFFF'; + $this->image_bevel_color2 = '#000000'; + $this->image_border = null; + $this->image_border_color = '#FFFFFF'; + $this->image_frame = null; + $this->image_frame_colors = '#FFFFFF #999999 #666666 #000000'; + + $this->forbidden = array(); + $this->allowed = array("application/arj", + "application/excel", + "application/gnutar", + "application/mspowerpoint", + "application/msword", + "application/octet-stream", + "application/onenote", + "application/pdf", + "application/plain", + "application/postscript", + "application/powerpoint", + "application/rar", + "application/rtf", + "application/vnd.ms-excel", + "application/vnd.ms-excel.addin.macroEnabled.12", + "application/vnd.ms-excel.sheet.binary.macroEnabled.12", + "application/vnd.ms-excel.sheet.macroEnabled.12", + "application/vnd.ms-excel.template.macroEnabled.12", + "application/vnd.ms-office", + "application/vnd.ms-officetheme", + "application/vnd.ms-powerpoint", + "application/vnd.ms-powerpoint.addin.macroEnabled.12", + "application/vnd.ms-powerpoint.presentation.macroEnabled.12", + "application/vnd.ms-powerpoint.slide.macroEnabled.12", + "application/vnd.ms-powerpoint.slideshow.macroEnabled.12", + "application/vnd.ms-powerpoint.template.macroEnabled.12", + "application/vnd.ms-word", + "application/vnd.ms-word.document.macroEnabled.12", + "application/vnd.ms-word.template.macroEnabled.12", + "application/vnd.oasis.opendocument.chart", + "application/vnd.oasis.opendocument.database", + "application/vnd.oasis.opendocument.formula", + "application/vnd.oasis.opendocument.graphics", + "application/vnd.oasis.opendocument.graphics-template", + "application/vnd.oasis.opendocument.image", + "application/vnd.oasis.opendocument.presentation", + "application/vnd.oasis.opendocument.presentation-template", + "application/vnd.oasis.opendocument.spreadsheet", + "application/vnd.oasis.opendocument.spreadsheet-template", + "application/vnd.oasis.opendocument.text", + "application/vnd.oasis.opendocument.text-master", + "application/vnd.oasis.opendocument.text-template", + "application/vnd.oasis.opendocument.text-web", + "application/vnd.openofficeorg.extension", + "application/vnd.openxmlformats-officedocument.presentationml.presentation", + "application/vnd.openxmlformats-officedocument.presentationml.slide", + "application/vnd.openxmlformats-officedocument.presentationml.slideshow", + "application/vnd.openxmlformats-officedocument.presentationml.template", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "application/vnd.openxmlformats-officedocument.spreadsheetml.template", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "application/vnd.openxmlformats-officedocument.wordprocessingml.template", + "application/vocaltec-media-file", + "application/wordperfect", + "application/x-bittorrent", + "application/x-bzip", + "application/x-bzip2", + "application/x-compressed", + "application/x-excel", + "application/x-gzip", + "application/x-latex", + "application/x-midi", + "application/xml", + "application/x-msexcel", + "application/x-rar-compressed", + "application/x-rtf", + "application/x-shockwave-flash", + "application/x-sit", + "application/x-stuffit", + "application/x-troff-msvideo", + "application/x-zip", + "application/x-zip-compressed", + "application/zip", + "audio/*", + "image/*", + "multipart/x-gzip", + "multipart/x-zip", + "text/plain", + "text/richtext", + "text/xml", + "video/*"); + + } + + /** + * Constructor. Checks if the file has been uploaded + * + * The constructor takes $_FILES['form_field'] array as argument + * where form_field is the form field name + * + * The constructor will check if the file has been uploaded in its temporary location, and + * accordingly will set {@link uploaded} (and {@link error} is an error occurred) + * + * If the file has been uploaded, the constructor will populate all the variables holding the upload + * information (none of the processing class variables are used here). + * You can have access to information about the file (name, size, MIME type...). + * + * + * Alternatively, you can set the first argument to be a local filename (string) + * This allows processing of a local file, as if the file was uploaded + * + * The optional second argument allows you to set the language for the error messages + * + * @access private + * @param array $file $_FILES['form_field'] + * or string $file Local filename + * @param string $lang Optional language code + */ + function __construct($file, $lang = 'en_GB') { + + $this->version = '0.29'; + + $this->file_src_name = ''; + $this->file_src_name_body = ''; + $this->file_src_name_ext = ''; + $this->file_src_mime = ''; + $this->file_src_size = ''; + $this->file_src_error = ''; + $this->file_src_pathname = ''; + $this->file_src_temp = ''; + + $this->file_dst_path = ''; + $this->file_dst_name = ''; + $this->file_dst_name_body = ''; + $this->file_dst_name_ext = ''; + $this->file_dst_pathname = ''; + + $this->image_src_x = null; + $this->image_src_y = null; + $this->image_src_bits = null; + $this->image_src_type = null; + $this->image_src_pixels = null; + $this->image_dst_x = 0; + $this->image_dst_y = 0; + + $this->uploaded = true; + $this->no_upload_check = false; + $this->processed = true; + $this->error = ''; + $this->log = ''; + $this->allowed = array(); + $this->forbidden = array(); + $this->file_is_image = false; + $this->init(); + $info = null; + $mime_from_browser = null; + + // sets default language + $this->translation = array(); + $this->translation['file_error'] = 'File error. Please try again.'; + $this->translation['local_file_missing'] = 'Local file doesn\'t exist.'; + $this->translation['local_file_not_readable'] = 'Local file is not readable.'; + $this->translation['uploaded_too_big_ini'] = 'File upload error (the uploaded file exceeds the upload_max_filesize directive in php.ini).'; + $this->translation['uploaded_too_big_html'] = 'File upload error (the uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form).'; + $this->translation['uploaded_partial'] = 'File upload error (the uploaded file was only partially uploaded).'; + $this->translation['uploaded_missing'] = 'File upload error (no file was uploaded).'; + $this->translation['uploaded_no_tmp_dir'] = 'File upload error (missing a temporary folder).'; + $this->translation['uploaded_cant_write'] = 'File upload error (failed to write file to disk).'; + $this->translation['uploaded_err_extension'] = 'File upload error (file upload stopped by extension).'; + $this->translation['uploaded_unknown'] = 'File upload error (unknown error code).'; + $this->translation['try_again'] = 'File upload error. Please try again.'; + $this->translation['file_too_big'] = 'File too big.'; + $this->translation['no_mime'] = 'MIME type can\'t be detected.'; + $this->translation['incorrect_file'] = 'Incorrect type of file.'; + $this->translation['image_too_wide'] = 'Image too wide.'; + $this->translation['image_too_narrow'] = 'Image too narrow.'; + $this->translation['image_too_high'] = 'Image too high.'; + $this->translation['image_too_short'] = 'Image too short.'; + $this->translation['ratio_too_high'] = 'Image ratio too high (image too wide).'; + $this->translation['ratio_too_low'] = 'Image ratio too low (image too high).'; + $this->translation['too_many_pixels'] = 'Image has too many pixels.'; + $this->translation['not_enough_pixels'] = 'Image has not enough pixels.'; + $this->translation['file_not_uploaded'] = 'File not uploaded. Can\'t carry on a process.'; + $this->translation['already_exists'] = '%s already exists. Please change the file name.'; + $this->translation['temp_file_missing'] = 'No correct temp source file. Can\'t carry on a process.'; + $this->translation['source_missing'] = 'No correct uploaded source file. Can\'t carry on a process.'; + $this->translation['destination_dir'] = 'Destination directory can\'t be created. Can\'t carry on a process.'; + $this->translation['destination_dir_missing'] = 'Destination directory doesn\'t exist. Can\'t carry on a process.'; + $this->translation['destination_path_not_dir'] = 'Destination path is not a directory. Can\'t carry on a process.'; + $this->translation['destination_dir_write'] = 'Destination directory can\'t be made writeable. Can\'t carry on a process.'; + $this->translation['destination_path_write'] = 'Destination path is not a writeable. Can\'t carry on a process.'; + $this->translation['temp_file'] = 'Can\'t create the temporary file. Can\'t carry on a process.'; + $this->translation['source_not_readable'] = 'Source file is not readable. Can\'t carry on a process.'; + $this->translation['no_create_support'] = 'No create from %s support.'; + $this->translation['create_error'] = 'Error in creating %s image from source.'; + $this->translation['source_invalid'] = 'Can\'t read image source. Not an image?.'; + $this->translation['gd_missing'] = 'GD doesn\'t seem to be present.'; + $this->translation['watermark_no_create_support'] = 'No create from %s support, can\'t read watermark.'; + $this->translation['watermark_create_error'] = 'No %s read support, can\'t create watermark.'; + $this->translation['watermark_invalid'] = 'Unknown image format, can\'t read watermark.'; + $this->translation['file_create'] = 'No %s create support.'; + $this->translation['no_conversion_type'] = 'No conversion type defined.'; + $this->translation['copy_failed'] = 'Error copying file on the server. copy() failed.'; + $this->translation['reading_failed'] = 'Error reading the file.'; + + // determines the language + $this->lang = $lang; + if ($this->lang != 'en_GB' && file_exists(dirname(__FILE__).'/lang') && file_exists(dirname(__FILE__).'/lang/class.upload.' . $lang . '.php')) { + $translation = null; + include(dirname(__FILE__).'/lang/class.upload.' . $lang . '.php'); + if (is_array($translation)) { + $this->translation = array_merge($this->translation, $translation); + } else { + $this->lang = 'en_GB'; + } + } + + + // determines the supported MIME types, and matching image format + $this->image_supported = array(); + if ($this->gdversion()) { + if (imagetypes() & IMG_GIF) { + $this->image_supported['image/gif'] = 'gif'; + } + if (imagetypes() & IMG_JPG) { + $this->image_supported['image/jpg'] = 'jpg'; + $this->image_supported['image/jpeg'] = 'jpg'; + $this->image_supported['image/pjpeg'] = 'jpg'; + } + if (imagetypes() & IMG_PNG) { + $this->image_supported['image/png'] = 'png'; + $this->image_supported['image/x-png'] = 'png'; + } + if (imagetypes() & IMG_WBMP) { + $this->image_supported['image/bmp'] = 'bmp'; + $this->image_supported['image/x-ms-bmp'] = 'bmp'; + $this->image_supported['image/x-windows-bmp'] = 'bmp'; + } + } + + // display some system information + if (empty($this->log)) { + $this->log .= 'system information
'; + $inis = ini_get_all(); + $open_basedir = (array_key_exists('open_basedir', $inis) && array_key_exists('local_value', $inis['open_basedir']) && !empty($inis['open_basedir']['local_value'])) ? $inis['open_basedir']['local_value'] : false; + $gd = $this->gdversion() ? $this->gdversion(true) : 'GD not present'; + $supported = trim((in_array('png', $this->image_supported) ? 'png' : '') . ' ' . (in_array('jpg', $this->image_supported) ? 'jpg' : '') . ' ' . (in_array('gif', $this->image_supported) ? 'gif' : '') . ' ' . (in_array('bmp', $this->image_supported) ? 'bmp' : '')); + $this->log .= '- class version : ' . $this->version . '
'; + $this->log .= '- operating system : ' . PHP_OS . '
'; + $this->log .= '- PHP version : ' . PHP_VERSION . '
'; + $this->log .= '- GD version : ' . $gd . '
'; + $this->log .= '- supported image types : ' . (!empty($supported) ? $supported : 'none') . '
'; + $this->log .= '- open_basedir : ' . (!empty($open_basedir) ? $open_basedir : 'no restriction') . '
'; + $this->log .= '- language : ' . $this->lang . '
'; + } + + if (!$file) { + $this->uploaded = false; + $this->error = $this->translate('file_error'); + } + + // check if we sent a local filename rather than a $_FILE element + if (!is_array($file)) { + if (empty($file)) { + $this->uploaded = false; + $this->error = $this->translate('file_error'); + } else { + $this->no_upload_check = TRUE; + // this is a local filename, i.e.not uploaded + $this->log .= '' . $this->translate("source is a local file") . ' ' . $file . '
'; + + if ($this->uploaded && !file_exists($file)) { + $this->uploaded = false; + $this->error = $this->translate('local_file_missing'); + } + + if ($this->uploaded && !is_readable($file)) { + $this->uploaded = false; + $this->error = $this->translate('local_file_not_readable'); + } + + if ($this->uploaded) { + $this->file_src_pathname = $file; + $this->file_src_name = basename($file); + $this->log .= '- local file name OK
'; + preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension); + if (is_array($extension) && sizeof($extension) > 0) { + $this->file_src_name_ext = strtolower($extension[1]); + $this->file_src_name_body = substr($this->file_src_name, 0, ((strlen($this->file_src_name) - strlen($this->file_src_name_ext)))-1); + } else { + $this->file_src_name_ext = ''; + $this->file_src_name_body = $this->file_src_name; + } + $this->file_src_size = (file_exists($file) ? filesize($file) : 0); + } + $this->file_src_error = 0; + } + } else { + // this is an element from $_FILE, i.e. an uploaded file + $this->log .= 'source is an uploaded file
'; + if ($this->uploaded) { + $this->file_src_error = trim($file['error']); + switch($this->file_src_error) { + case UPLOAD_ERR_OK: + // all is OK + $this->log .= '- upload OK
'; + break; + case UPLOAD_ERR_INI_SIZE: + $this->uploaded = false; + $this->error = $this->translate('uploaded_too_big_ini'); + break; + case UPLOAD_ERR_FORM_SIZE: + $this->uploaded = false; + $this->error = $this->translate('uploaded_too_big_html'); + break; + case UPLOAD_ERR_PARTIAL: + $this->uploaded = false; + $this->error = $this->translate('uploaded_partial'); + break; + case UPLOAD_ERR_NO_FILE: + $this->uploaded = false; + $this->error = $this->translate('uploaded_missing'); + break; + case @UPLOAD_ERR_NO_TMP_DIR: + $this->uploaded = false; + $this->error = $this->translate('uploaded_no_tmp_dir'); + break; + case @UPLOAD_ERR_CANT_WRITE: + $this->uploaded = false; + $this->error = $this->translate('uploaded_cant_write'); + break; + case @UPLOAD_ERR_EXTENSION: + $this->uploaded = false; + $this->error = $this->translate('uploaded_err_extension'); + break; + default: + $this->uploaded = false; + $this->error = $this->translate('uploaded_unknown') . ' ('.$this->file_src_error.')'; + } + } + + if ($this->uploaded) { + $this->file_src_pathname = $file['tmp_name']; + $this->file_src_name = $file['name']; + if ($this->file_src_name == '') { + $this->uploaded = false; + $this->error = $this->translate('try_again'); + } + } + + if ($this->uploaded) { + $this->log .= '- file name OK
'; + preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension); + if (is_array($extension) && sizeof($extension) > 0) { + $this->file_src_name_ext = strtolower($extension[1]); + $this->file_src_name_body = substr($this->file_src_name, 0, ((strlen($this->file_src_name) - strlen($this->file_src_name_ext)))-1); + } else { + $this->file_src_name_ext = ''; + $this->file_src_name_body = $this->file_src_name; + } + $this->file_src_size = $file['size']; + $mime_from_browser = $file['type']; + } + } + + if ($this->uploaded) { + $this->log .= 'determining MIME type
'; + $this->file_src_mime = null; + + // checks MIME type with Fileinfo PECL extension + if (!$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === FALSE) { + if ($this->mime_fileinfo) { + $this->log .= '- Checking MIME type with Fileinfo PECL extension
'; + if (function_exists('finfo_open')) { + if ($this->mime_fileinfo !== '') { + if ($this->mime_fileinfo === true) { + if (getenv('MAGIC') === FALSE) { + if (substr(PHP_OS, 0, 3) == 'WIN') { + $path = realpath(ini_get('extension_dir') . '/../') . 'extras/magic'; + } else { + $path = '/usr/share/file/magic'; + } + $this->log .= '    MAGIC path defaults to ' . $path . '
'; + } else { + $path = getenv('MAGIC'); + $this->log .= '    MAGIC path is set to ' . $path . ' from MAGIC variable
'; + } + } else { + $path = $this->mime_fileinfo; + $this->log .= '    MAGIC path is set to ' . $path . '
'; + } + $f = @finfo_open(FILEINFO_MIME, $path); + } else { + $this->log .= '    MAGIC path will not be used
'; + $f = @finfo_open(FILEINFO_MIME); + } + if (is_resource($f)) { + $mime = finfo_file($f, realpath($this->file_src_pathname)); + finfo_close($f); + $this->file_src_mime = $mime; + $this->log .= '    MIME type detected as ' . $this->file_src_mime . ' by Fileinfo PECL extension
'; + if (preg_match("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", $this->file_src_mime)) { + $this->file_src_mime = preg_replace("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", '$1/$2', $this->file_src_mime); + $this->log .= '- MIME validated as ' . $this->file_src_mime . '
'; + } else { + $this->file_src_mime = null; + } + } else { + $this->log .= '    Fileinfo PECL extension failed (finfo_open)
'; + } + } else { + $this->log .= '    Fileinfo PECL extension not available
'; + } + } else { + $this->log .= '- Fileinfo PECL extension deactivated
'; + } + } + + // checks MIME type with shell if unix access is authorized + if (!$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === FALSE) { + if ($this->mime_file) { + $this->log .= '- Checking MIME type with UNIX file() command
'; + if (substr(PHP_OS, 0, 3) != 'WIN') { + if (strlen($mime = @exec("file -bi ".escapeshellarg($this->file_src_pathname))) != 0) { + $this->file_src_mime = trim($mime); + $this->log .= '    MIME type detected as ' . $this->file_src_mime . ' by UNIX file() command
'; + if (preg_match("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", $this->file_src_mime)) { + $this->file_src_mime = preg_replace("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", '$1/$2', $this->file_src_mime); + $this->log .= '- MIME validated as ' . $this->file_src_mime . '
'; + } else { + $this->file_src_mime = null; + } + } else { + $this->log .= '    UNIX file() command failed
'; + } + } else { + $this->log .= '    UNIX file() command not availabled
'; + } + } else { + $this->log .= '- UNIX file() command is deactivated
'; + } + } + + // checks MIME type with mime_magic + if (!$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === FALSE) { + if ($this->mime_magic) { + $this->log .= '- Checking MIME type with mime.magic file (mime_content_type())
'; + if (function_exists('mime_content_type')) { + $this->file_src_mime = mime_content_type($this->file_src_pathname); + $this->log .= '    MIME type detected as ' . $this->file_src_mime . ' by mime_content_type()
'; + if (preg_match("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", $this->file_src_mime)) { + $this->file_src_mime = preg_replace("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", '$1/$2', $this->file_src_mime); + $this->log .= '- MIME validated as ' . $this->file_src_mime . '
'; + } else { + $this->file_src_mime = null; + } + } else { + $this->log .= '    mime_content_type() is not available
'; + } + } else { + $this->log .= '- mime.magic file (mime_content_type()) is deactivated
'; + } + } + + // checks MIME type with getimagesize() + if (!$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === FALSE) { + if ($this->mime_getimagesize) { + $this->log .= '- Checking MIME type with getimagesize()
'; + $info = getimagesize($this->file_src_pathname); + if (is_array($info) && array_key_exists('mime', $info)) { + $this->file_src_mime = trim($info['mime']); + if (empty($this->file_src_mime)) { + $this->log .= '    MIME empty, guessing from type
'; + $mime = (is_array($info) && array_key_exists(2, $info) ? $info[2] : null); // 1 = GIF, 2 = JPG, 3 = PNG + $this->file_src_mime = ($mime==IMAGETYPE_GIF ? 'image/gif' : ($mime==IMAGETYPE_JPEG ? 'image/jpeg' : ($mime==IMAGETYPE_PNG ? 'image/png' : ($mime==IMAGETYPE_BMP ? 'image/bmp' : null)))); + } + $this->log .= '    MIME type detected as ' . $this->file_src_mime . ' by PHP getimagesize() function
'; + if (preg_match("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", $this->file_src_mime)) { + $this->file_src_mime = preg_replace("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", '$1/$2', $this->file_src_mime); + $this->log .= '- MIME validated as ' . $this->file_src_mime . '
'; + } else { + $this->file_src_mime = null; + } + } else { + $this->log .= '    getimagesize() failed
'; + } + } else { + $this->log .= '- getimagesize() is deactivated
'; + } + } + + // default to MIME from browser (or Flash) + if (!empty($mime_from_browser) && !$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime)) { + $this->file_src_mime =$mime_from_browser; + $this->log .= '- MIME type detected as ' . $this->file_src_mime . ' by browser
'; + if (preg_match("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", $this->file_src_mime)) { + $this->file_src_mime = preg_replace("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", '$1/$2', $this->file_src_mime); + $this->log .= '- MIME validated as ' . $this->file_src_mime . '
'; + } else { + $this->file_src_mime = null; + } + } + + // we need to work some magic if we upload via Flash + if ($this->file_src_mime == 'application/octet-stream' || !$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === FALSE) { + if ($this->file_src_mime == 'application/octet-stream') $this->log .= '- Flash may be rewriting MIME as application/octet-stream
'; + $this->log .= '- Try to guess MIME type from file extension (' . $this->file_src_name_ext . '): '; + switch($this->file_src_name_ext) { + case 'jpg': + case 'jpeg': + case 'jpe': + $this->file_src_mime = 'image/jpeg'; + break; + case 'gif': + $this->file_src_mime = 'image/gif'; + break; + case 'png': + $this->file_src_mime = 'image/png'; + break; + case 'bmp': + $this->file_src_mime = 'image/bmp'; + break; + case 'flv': + $this->file_src_mime = 'video/x-flv'; + break; + case 'js' : + $this->file_src_mime = 'application/x-javascript'; + break; + case 'json' : + $this->file_src_mime = 'application/json'; + break; + case 'tiff' : + $this->file_src_mime = 'image/tiff'; + break; + case 'css' : + $this->file_src_mime = 'text/css'; + break; + case 'xml' : + $this->file_src_mime = 'application/xml'; + break; + case 'doc' : + case 'docx' : + $this->file_src_mime = 'application/msword'; + break; + case 'xls' : + case 'xlt' : + case 'xlm' : + case 'xld' : + case 'xla' : + case 'xlc' : + case 'xlw' : + case 'xll' : + $this->file_src_mime = 'application/vnd.ms-excel'; + break; + case 'ppt' : + case 'pps' : + $this->file_src_mime = 'application/vnd.ms-powerpoint'; + break; + case 'rtf' : + $this->file_src_mime = 'application/rtf'; + break; + case 'pdf' : + $this->file_src_mime = 'application/pdf'; + break; + case 'html' : + case 'htm' : + case 'php' : + $this->file_src_mime = 'text/html'; + break; + case 'txt' : + $this->file_src_mime = 'text/plain'; + break; + case 'mpeg' : + case 'mpg' : + case 'mpe' : + $this->file_src_mime = 'video/mpeg'; + break; + case 'mp3' : + $this->file_src_mime = 'audio/mpeg3'; + break; + case 'wav' : + $this->file_src_mime = 'audio/wav'; + break; + case 'aiff' : + case 'aif' : + $this->file_src_mime = 'audio/aiff'; + break; + case 'avi' : + $this->file_src_mime = 'video/msvideo'; + break; + case 'wmv' : + $this->file_src_mime = 'video/x-ms-wmv'; + break; + case 'mov' : + $this->file_src_mime = 'video/quicktime'; + break; + case 'zip' : + $this->file_src_mime = 'application/zip'; + break; + case 'tar' : + $this->file_src_mime = 'application/x-tar'; + break; + case 'swf' : + $this->file_src_mime = 'application/x-shockwave-flash'; + break; + case 'odt': + $this->file_src_mime = 'application/vnd.oasis.opendocument.text'; + break; + case 'ott': + $this->file_src_mime = 'application/vnd.oasis.opendocument.text-template'; + break; + case 'oth': + $this->file_src_mime = 'application/vnd.oasis.opendocument.text-web'; + break; + case 'odm': + $this->file_src_mime = 'application/vnd.oasis.opendocument.text-master'; + break; + case 'odg': + $this->file_src_mime = 'application/vnd.oasis.opendocument.graphics'; + break; + case 'otg': + $this->file_src_mime = 'application/vnd.oasis.opendocument.graphics-template'; + break; + case 'odp': + $this->file_src_mime = 'application/vnd.oasis.opendocument.presentation'; + break; + case 'otp': + $this->file_src_mime = 'application/vnd.oasis.opendocument.presentation-template'; + break; + case 'ods': + $this->file_src_mime = 'application/vnd.oasis.opendocument.spreadsheet'; + break; + case 'ots': + $this->file_src_mime = 'application/vnd.oasis.opendocument.spreadsheet-template'; + break; + case 'odc': + $this->file_src_mime = 'application/vnd.oasis.opendocument.chart'; + break; + case 'odf': + $this->file_src_mime = 'application/vnd.oasis.opendocument.formula'; + break; + case 'odb': + $this->file_src_mime = 'application/vnd.oasis.opendocument.database'; + break; + case 'odi': + $this->file_src_mime = 'application/vnd.oasis.opendocument.image'; + break; + case 'oxt': + $this->file_src_mime = 'application/vnd.openofficeorg.extension'; + break; + case 'docx': + $this->file_src_mime = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; + break; + case 'docm': + $this->file_src_mime = 'application/vnd.ms-word.document.macroEnabled.12'; + break; + case 'dotx': + $this->file_src_mime = 'application/vnd.openxmlformats-officedocument.wordprocessingml.template'; + break; + case 'dotm': + $this->file_src_mime = 'application/vnd.ms-word.template.macroEnabled.12'; + break; + case 'xlsx': + $this->file_src_mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + break; + case 'xlsm': + $this->file_src_mime = 'application/vnd.ms-excel.sheet.macroEnabled.12'; + break; + case 'xltx': + $this->file_src_mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template'; + break; + case 'xltm': + $this->file_src_mime = 'application/vnd.ms-excel.template.macroEnabled.12'; + break; + case 'xlsb': + $this->file_src_mime = 'application/vnd.ms-excel.sheet.binary.macroEnabled.12'; + break; + case 'xlam': + $this->file_src_mime = 'application/vnd.ms-excel.addin.macroEnabled.12'; + break; + case 'pptx': + $this->file_src_mime = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; + break; + case 'pptm': + $this->file_src_mime = 'application/vnd.ms-powerpoint.presentation.macroEnabled.12'; + break; + case 'ppsx': + $this->file_src_mime = 'application/vnd.openxmlformats-officedocument.presentationml.slideshow'; + break; + case 'ppsm': + $this->file_src_mime = 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'; + break; + case 'potx': + $this->file_src_mime = 'application/vnd.openxmlformats-officedocument.presentationml.template'; + break; + case 'potm': + $this->file_src_mime = 'application/vnd.ms-powerpoint.template.macroEnabled.12'; + break; + case 'ppam': + $this->file_src_mime = 'application/vnd.ms-powerpoint.addin.macroEnabled.12'; + break; + case 'sldx': + $this->file_src_mime = 'application/vnd.openxmlformats-officedocument.presentationml.slide'; + break; + case 'sldm': + $this->file_src_mime = 'application/vnd.ms-powerpoint.slide.macroEnabled.12'; + break; + case 'thmx': + $this->file_src_mime = 'application/vnd.ms-officetheme'; + break; + case 'onetoc': + case 'onetoc2': + case 'onetmp': + case 'onepkg': + $this->file_src_mime = 'application/onenote'; + break; + } + if ($this->file_src_mime == 'application/octet-stream') { + $this->log .= 'doesn\'t look like anything known
'; + } else { + $this->log .= 'MIME type set to ' . $this->file_src_mime . '
'; + } + } + + if (!$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === FALSE) { + $this->log .= '- MIME type couldn\'t be detected! (' . (string) $this->file_src_mime . ')
'; + } + + // determine whether the file is an image + if ($this->file_src_mime && is_string($this->file_src_mime) && !empty($this->file_src_mime) && array_key_exists($this->file_src_mime, $this->image_supported)) { + $this->file_is_image = true; + $this->image_src_type = $this->image_supported[$this->file_src_mime]; + } + + // if the file is an image, we gather some useful data + if ($this->file_is_image) { + if ($h = fopen($this->file_src_pathname, 'r')) { + fclose($h); + $info = getimagesize($this->file_src_pathname); + if (is_array($info)) { + $this->image_src_x = $info[0]; + $this->image_src_y = $info[1]; + $this->image_dst_x = $this->image_src_x; + $this->image_dst_y = $this->image_src_y; + $this->image_src_pixels = $this->image_src_x * $this->image_src_y; + $this->image_src_bits = array_key_exists('bits', $info) ? $info['bits'] : null; + } else { + $this->file_is_image = false; + $this->uploaded = false; + $this->log .= '- can\'t retrieve image information, image may have been tampered with
'; + $this->error = $this->translate('incorrect_file'); + } + } else { + $this->log .= '- can\'t read source file directly. open_basedir restriction in place?
'; + } + } + + $this->log .= 'source variables
'; + $this->log .= '- You can use all these before calling process()
'; + $this->log .= '    file_src_name : ' . $this->file_src_name . '
'; + $this->log .= '    file_src_name_body : ' . $this->file_src_name_body . '
'; + $this->log .= '    file_src_name_ext : ' . $this->file_src_name_ext . '
'; + $this->log .= '    file_src_pathname : ' . $this->file_src_pathname . '
'; + $this->log .= '    file_src_mime : ' . $this->file_src_mime . '
'; + $this->log .= '    file_src_size : ' . $this->file_src_size . ' (max= ' . $this->file_max_size . ')
'; + $this->log .= '    file_src_error : ' . $this->file_src_error . '
'; + + if ($this->file_is_image) { + $this->log .= '- source file is an image
'; + $this->log .= '    image_src_x : ' . $this->image_src_x . '
'; + $this->log .= '    image_src_y : ' . $this->image_src_y . '
'; + $this->log .= '    image_src_pixels : ' . $this->image_src_pixels . '
'; + $this->log .= '    image_src_type : ' . $this->image_src_type . '
'; + $this->log .= '    image_src_bits : ' . $this->image_src_bits . '
'; + } + } + + } + + /** + * Returns the version of GD + * + * @access public + * @param boolean $full Optional flag to get precise version + * @return float GD version + */ + function gdversion($full = false) { + static $gd_version = null; + static $gd_full_version = null; + if ($gd_version === null) { + if (function_exists('gd_info')) { + $gd = gd_info(); + $gd = $gd["GD Version"]; + $regex = "/([\d\.]+)/i"; + } else { + ob_start(); + phpinfo(8); + $gd = ob_get_contents(); + ob_end_clean(); + $regex = "/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i"; + } + if (preg_match($regex, $gd, $m)) { + $gd_full_version = (string) $m[1]; + $gd_version = (float) $m[1]; + } else { + $gd_full_version = 'none'; + $gd_version = 0; + } + } + if ($full) { + return $gd_full_version; + } else { + return $gd_version; + } + } + + + /** + * Creates directories recursively + * + * @access private + * @param string $path Path to create + * @param integer $mode Optional permissions + * @return boolean Success + */ + function rmkdir($path, $mode = 0777) { + return is_dir($path) || ( $this->rmkdir(dirname($path), $mode) && $this->_mkdir($path, $mode) ); + } + + + /** + * Creates directory + * + * @access private + * @param string $path Path to create + * @param integer $mode Optional permissions + * @return boolean Success + */ + function _mkdir($path, $mode = 0777) { + $old = umask(0); + $res = @mkdir($path, $mode); + umask($old); + return $res; + } + + + /** + * Translate error messages + * + * @access private + * @param string $str Message to translate + * @param array $tokens Optional token values + * @return string Translated string + */ + function translate($str, $tokens = array()) { + if (array_key_exists($str, $this->translation)) $str = $this->translation[$str]; + if (is_array($tokens) && sizeof($tokens) > 0) $str = vsprintf($str, $tokens); + return $str; + } + + /** + * Decodes colors + * + * @access private + * @param string $color Color string + * @return array RGB colors + */ + function getcolors($color) { + $r = sscanf($color, "#%2x%2x%2x"); + $red = (array_key_exists(0, $r) && is_numeric($r[0]) ? $r[0] : 0); + $green = (array_key_exists(1, $r) && is_numeric($r[1]) ? $r[1] : 0); + $blue = (array_key_exists(2, $r) && is_numeric($r[2]) ? $r[2] : 0); + return array($red, $green, $blue); + } + + /** + * Creates a container image + * + * @access private + * @param integer $x Width + * @param integer $y Height + * @param boolean $fill Optional flag to draw the background color or not + * @param boolean $trsp Optional flag to set the background to be transparent + * @return resource Container image + */ + function imagecreatenew($x, $y, $fill = true, $trsp = false) { + if ($x < 1) $x = 1; if ($y < 1) $y = 1; + if ($this->gdversion() >= 2 && !$this->image_is_palette) { + // create a true color image + $dst_im = imagecreatetruecolor($x, $y); + // this preserves transparency in PNGs, in true color + if (empty($this->image_background_color) || $trsp) { + imagealphablending($dst_im, false ); + imagefilledrectangle($dst_im, 0, 0, $x, $y, imagecolorallocatealpha($dst_im, 0, 0, 0, 127)); + } + } else { + // creates a palette image + $dst_im = imagecreate($x, $y); + // preserves transparency for palette images, if the original image has transparency + if (($fill && $this->image_is_transparent && empty($this->image_background_color)) || $trsp) { + imagefilledrectangle($dst_im, 0, 0, $x, $y, $this->image_transparent_color); + imagecolortransparent($dst_im, $this->image_transparent_color); + } + } + // fills with background color if any is set + if ($fill && !empty($this->image_background_color) && !$trsp) { + list($red, $green, $blue) = $this->getcolors($this->image_background_color); + $background_color = imagecolorallocate($dst_im, $red, $green, $blue); + imagefilledrectangle($dst_im, 0, 0, $x, $y, $background_color); + } + return $dst_im; + } + + + /** + * Transfers an image from the container to the destination image + * + * @access private + * @param resource $src_im Container image + * @param resource $dst_im Destination image + * @return resource Destination image + */ + function imagetransfer($src_im, $dst_im) { + if (is_resource($dst_im)) imagedestroy($dst_im); + $dst_im = & $src_im; + return $dst_im; + } + + /** + * Merges two images + * + * If the output format is PNG, then we do it pixel per pixel to retain the alpha channel + * + * @access private + * @param resource $dst_img Destination image + * @param resource $src_img Overlay image + * @param int $dst_x x-coordinate of destination point + * @param int $dst_y y-coordinate of destination point + * @param int $src_x x-coordinate of source point + * @param int $src_y y-coordinate of source point + * @param int $src_w Source width + * @param int $src_h Source height + * @param int $pct Optional percentage of the overlay, between 0 and 100 (default: 100) + * @return resource Destination image + */ + function imagecopymergealpha(&$dst_im, &$src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct = 0) { + $dst_x = (int) $dst_x; + $dst_y = (int) $dst_y; + $src_x = (int) $src_x; + $src_y = (int) $src_y; + $src_w = (int) $src_w; + $src_h = (int) $src_h; + $pct = (int) $pct; + $dst_w = imagesx($dst_im); + $dst_h = imagesy($dst_im); + + for ($y = $src_y; $y < $src_h; $y++) { + for ($x = $src_x; $x < $src_w; $x++) { + + if ($x + $dst_x >= 0 && $x + $dst_x < $dst_w && $x + $src_x >= 0 && $x + $src_x < $src_w + && $y + $dst_y >= 0 && $y + $dst_y < $dst_h && $y + $src_y >= 0 && $y + $src_y < $src_h) { + + $dst_pixel = imagecolorsforindex($dst_im, imagecolorat($dst_im, $x + $dst_x, $y + $dst_y)); + $src_pixel = imagecolorsforindex($src_im, imagecolorat($src_im, $x + $src_x, $y + $src_y)); + + $src_alpha = 1 - ($src_pixel['alpha'] / 127); + $dst_alpha = 1 - ($dst_pixel['alpha'] / 127); + $opacity = $src_alpha * $pct / 100; + if ($dst_alpha >= $opacity) $alpha = $dst_alpha; + if ($dst_alpha < $opacity) $alpha = $opacity; + if ($alpha > 1) $alpha = 1; + + if ($opacity > 0) { + $dst_red = round(( ($dst_pixel['red'] * $dst_alpha * (1 - $opacity)) ) ); + $dst_green = round(( ($dst_pixel['green'] * $dst_alpha * (1 - $opacity)) ) ); + $dst_blue = round(( ($dst_pixel['blue'] * $dst_alpha * (1 - $opacity)) ) ); + $src_red = round((($src_pixel['red'] * $opacity)) ); + $src_green = round((($src_pixel['green'] * $opacity)) ); + $src_blue = round((($src_pixel['blue'] * $opacity)) ); + $red = round(($dst_red + $src_red ) / ($dst_alpha * (1 - $opacity) + $opacity)); + $green = round(($dst_green + $src_green) / ($dst_alpha * (1 - $opacity) + $opacity)); + $blue = round(($dst_blue + $src_blue ) / ($dst_alpha * (1 - $opacity) + $opacity)); + if ($red > 255) $red = 255; + if ($green > 255) $green = 255; + if ($blue > 255) $blue = 255; + $alpha = round((1 - $alpha) * 127); + $color = imagecolorallocatealpha($dst_im, $red, $green, $blue, $alpha); + imagesetpixel($dst_im, $x + $dst_x, $y + $dst_y, $color); + } + } + } + } + return true; + } + + + + /** + * Actually uploads the file, and act on it according to the set processing class variables + * + * This function copies the uploaded file to the given location, eventually performing actions on it. + * Typically, you can call {@link process} several times for the same file, + * for instance to create a resized image and a thumbnail of the same file. + * The original uploaded file remains intact in its temporary location, so you can use {@link process} several times. + * You will be able to delete the uploaded file with {@link clean} when you have finished all your {@link process} calls. + * + * According to the processing class variables set in the calling file, the file can be renamed, + * and if it is an image, can be resized or converted. + * + * When the processing is completed, and the file copied to its new location, the + * processing class variables will be reset to their default value. + * This allows you to set new properties, and perform another {@link process} on the same uploaded file + * + * If the function is called with a null or empty argument, then it will return the content of the picture + * + * It will set {@link processed} (and {@link error} is an error occurred) + * + * @access public + * @param string $server_path Optional path location of the uploaded file, with an ending slash + * @return string Optional content of the image + */ + function process($server_path = null) { + + $this->error = ''; + $this->processed = true; + $return_mode = false; + $return_content = null; + + if (!$this->uploaded) { + $this->error = $this->translate('file_not_uploaded'); + $this->processed = false; + } + + if ($this->processed) { + if (empty($server_path) || is_null($server_path)) { + $this->log .= 'process file and return the content
'; + $return_mode = true; + } else { + if(strtolower(substr(PHP_OS, 0, 3)) === 'win') { + if (substr($server_path, -1, 1) != '\\') $server_path = $server_path . '\\'; + } else { + if (substr($server_path, -1, 1) != '/') $server_path = $server_path . '/'; + } + $this->log .= 'process file to ' . $server_path . '
'; + } + } + + if ($this->processed) { + // checks file max size + if ($this->file_src_size > $this->file_max_size ) { + $this->processed = false; + $this->error = $this->translate('file_too_big'); + } else { + $this->log .= '- file size OK
'; + } + } + + if ($this->processed) { + // turn dangerous scripts into text files + if ($this->no_script) { + if (((substr($this->file_src_mime, 0, 5) == 'text/' || strpos($this->file_src_mime, 'javascript') !== false) && (substr($this->file_src_name, -4) != '.txt')) + || preg_match('/\.(php|pl|py|cgi|asp)$/i', $this->file_src_name) || empty($this->file_src_name_ext)) { + $this->file_src_mime = 'text/plain'; + $this->log .= '- script ' . $this->file_src_name . ' renamed as ' . $this->file_src_name . '.txt!
'; + $this->file_src_name_ext .= (empty($this->file_src_name_ext) ? 'txt' : '.txt'); + } + } + + if ($this->mime_check && empty($this->file_src_mime)) { + $this->processed = false; + $this->error = $this->translate('no_mime'); + } else if ($this->mime_check && !empty($this->file_src_mime) && strpos($this->file_src_mime, '/') !== false) { + list($m1, $m2) = explode('/', $this->file_src_mime); + $allowed = false; + // check wether the mime type is allowed + foreach($this->allowed as $k => $v) { + list($v1, $v2) = explode('/', $v); + if (($v1 == '*' && $v2 == '*') || ($v1 == $m1 && ($v2 == $m2 || $v2 == '*'))) { + $allowed = true; + break; + } + } + // check wether the mime type is forbidden + foreach($this->forbidden as $k => $v) { + list($v1, $v2) = explode('/', $v); + if (($v1 == '*' && $v2 == '*') || ($v1 == $m1 && ($v2 == $m2 || $v2 == '*'))) { + $allowed = false; + break; + } + } + if (!$allowed) { + $this->processed = false; + $this->error = $this->translate('incorrect_file'); + } else { + $this->log .= '- file mime OK : ' . $this->file_src_mime . '
'; + } + } else { + $this->log .= '- file mime (not checked) : ' . $this->file_src_mime . '
'; + } + + // if the file is an image, we can check on its dimensions + // these checks are not available if open_basedir restrictions are in place + if ($this->file_is_image) { + if (is_numeric($this->image_src_x) && is_numeric($this->image_src_y)) { + $ratio = $this->image_src_x / $this->image_src_y; + if (!is_null($this->image_max_width) && $this->image_src_x > $this->image_max_width) { + $this->processed = false; + $this->error = $this->translate('image_too_wide'); + } + if (!is_null($this->image_min_width) && $this->image_src_x < $this->image_min_width) { + $this->processed = false; + $this->error = $this->translate('image_too_narrow'); + } + if (!is_null($this->image_max_height) && $this->image_src_y > $this->image_max_height) { + $this->processed = false; + $this->error = $this->translate('image_too_high'); + } + if (!is_null($this->image_min_height) && $this->image_src_y < $this->image_min_height) { + $this->processed = false; + $this->error = $this->translate('image_too_short'); + } + if (!is_null($this->image_max_ratio) && $ratio > $this->image_max_ratio) { + $this->processed = false; + $this->error = $this->translate('ratio_too_high'); + } + if (!is_null($this->image_min_ratio) && $ratio < $this->image_min_ratio) { + $this->processed = false; + $this->error = $this->translate('ratio_too_low'); + } + if (!is_null($this->image_max_pixels) && $this->image_src_pixels > $this->image_max_pixels) { + $this->processed = false; + $this->error = $this->translate('too_many_pixels'); + } + if (!is_null($this->image_min_pixels) && $this->image_src_pixels < $this->image_min_pixels) { + $this->processed = false; + $this->error = $this->translate('not_enough_pixels'); + } + } else { + $this->log .= '- no image properties available, can\'t enforce dimension checks : ' . $this->file_src_mime . '
'; + } + } + } + + if ($this->processed) { + $this->file_dst_path = $server_path; + + // repopulate dst variables from src + $this->file_dst_name = $this->file_src_name; + $this->file_dst_name_body = $this->file_src_name_body; + $this->file_dst_name_ext = $this->file_src_name_ext; + if ($this->file_overwrite) $this->file_auto_rename = false; + + if ($this->image_convert != '') { // if we convert as an image + $this->file_dst_name_ext = $this->image_convert; + $this->log .= '- new file name ext : ' . $this->image_convert . '
'; + } + if ($this->file_new_name_body != '') { // rename file body + $this->file_dst_name_body = $this->file_new_name_body; + $this->log .= '- new file name body : ' . $this->file_new_name_body . '
'; + } + if ($this->file_new_name_ext != '') { // rename file ext + $this->file_dst_name_ext = $this->file_new_name_ext; + $this->log .= '- new file name ext : ' . $this->file_new_name_ext . '
'; + } + if ($this->file_name_body_add != '') { // append a string to the name + $this->file_dst_name_body = $this->file_dst_name_body . $this->file_name_body_add; + $this->log .= '- file name body append : ' . $this->file_name_body_add . '
'; + } + if ($this->file_name_body_pre != '') { // prepend a string to the name + $this->file_dst_name_body = $this->file_name_body_pre . $this->file_dst_name_body; + $this->log .= '- file name body prepend : ' . $this->file_name_body_pre . '
'; + } + if ($this->file_safe_name) { // formats the name + $this->file_dst_name_body = str_replace(array(' ', '-'), array('_','_'), $this->file_dst_name_body) ; + $this->file_dst_name_body = preg_replace('/[^A-Za-z0-9_]/', '', $this->file_dst_name_body) ; + $this->log .= '- file name safe format
'; + } + + $this->log .= '- destination variables
'; + if (empty($this->file_dst_path) || is_null($this->file_dst_path)) { + $this->log .= '    file_dst_path : n/a
'; + } else { + $this->log .= '    file_dst_path : ' . $this->file_dst_path . '
'; + } + $this->log .= '    file_dst_name_body : ' . $this->file_dst_name_body . '
'; + $this->log .= '    file_dst_name_ext : ' . $this->file_dst_name_ext . '
'; + + // do we do some image manipulation? + $image_manipulation = ($this->file_is_image && ( + $this->image_resize + || $this->image_convert != '' + || is_numeric($this->image_brightness) + || is_numeric($this->image_contrast) + || is_numeric($this->image_threshold) + || !empty($this->image_tint_color) + || !empty($this->image_overlay_color) + || !empty($this->image_text) + || $this->image_greyscale + || $this->image_negative + || !empty($this->image_watermark) + || is_numeric($this->image_rotate) + || is_numeric($this->jpeg_size) + || !empty($this->image_flip) + || !empty($this->image_crop) + || !empty($this->image_precrop) + || !empty($this->image_border) + || $this->image_frame > 0 + || $this->image_bevel > 0 + || $this->image_reflection_height)); + + if ($image_manipulation) { + if ($this->image_convert=='') { + $this->file_dst_name = $this->file_dst_name_body . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : ''); + $this->log .= '- image operation, keep extension
'; + } else { + $this->file_dst_name = $this->file_dst_name_body . '.' . $this->image_convert; + $this->log .= '- image operation, change extension for conversion type
'; + } + } else { + $this->file_dst_name = $this->file_dst_name_body . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : ''); + $this->log .= '- no image operation, keep extension
'; + } + + if (!$return_mode) { + if (!$this->file_auto_rename) { + $this->log .= '- no auto_rename if same filename exists
'; + $this->file_dst_pathname = $this->file_dst_path . $this->file_dst_name; + } else { + $this->log .= '- checking for auto_rename
'; + $this->file_dst_pathname = $this->file_dst_path . $this->file_dst_name; + $body = $this->file_dst_name_body; + $cpt = 1; + while (@file_exists($this->file_dst_pathname)) { + $this->file_dst_name_body = $body . '_' . $cpt; + $this->file_dst_name = $this->file_dst_name_body . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : ''); + $cpt++; + $this->file_dst_pathname = $this->file_dst_path . $this->file_dst_name; + } + if ($cpt>1) $this->log .= '    auto_rename to ' . $this->file_dst_name . '
'; + } + + $this->log .= '- destination file details
'; + $this->log .= '    file_dst_name : ' . $this->file_dst_name . '
'; + $this->log .= '    file_dst_pathname : ' . $this->file_dst_pathname . '
'; + + if ($this->file_overwrite) { + $this->log .= '- no overwrite checking
'; + } else { + if (@file_exists($this->file_dst_pathname)) { + $this->processed = false; + $this->error = $this->translate('already_exists', array($this->file_dst_name)); + } else { + $this->log .= '- ' . $this->file_dst_name . ' doesn\'t exist already
'; + } + } + } + } + + if ($this->processed) { + // if we have already moved the uploaded file, we use the temporary copy as source file, and check if it exists + if (!empty($this->file_src_temp)) { + $this->log .= '- use the temp file instead of the original file since it is a second process
'; + $this->file_src_pathname = $this->file_src_temp; + if (!file_exists($this->file_src_pathname)) { + $this->processed = false; + $this->error = $this->translate('temp_file_missing'); + } + // if we haven't a temp file, and that we do check on uploads, we use is_uploaded_file() + } else if (!$this->no_upload_check) { + if (!is_uploaded_file($this->file_src_pathname)) { + $this->processed = false; + $this->error = $this->translate('source_missing'); + } + // otherwise, if we don't check on uploaded files (local file for instance), we use file_exists() + } else { + if (!file_exists($this->file_src_pathname)) { + $this->processed = false; + $this->error = $this->translate('source_missing'); + } + } + + // checks if the destination directory exists, and attempt to create it + if (!$return_mode) { + if ($this->processed && !file_exists($this->file_dst_path)) { + if ($this->dir_auto_create) { + $this->log .= '- ' . $this->file_dst_path . ' doesn\'t exist. Attempting creation:'; + if (!$this->rmkdir($this->file_dst_path, $this->dir_chmod)) { + $this->log .= ' failed
'; + $this->processed = false; + $this->error = $this->translate('destination_dir'); + } else { + $this->log .= ' success
'; + } + } else { + $this->error = $this->translate('destination_dir_missing'); + } + } + + if ($this->processed && !is_dir($this->file_dst_path)) { + $this->processed = false; + $this->error = $this->translate('destination_path_not_dir'); + } + + // checks if the destination directory is writeable, and attempt to make it writeable + $hash = md5($this->file_dst_name_body . rand(1, 1000)); + if ($this->processed && !($f = @fopen($this->file_dst_path . $hash . '.' . $this->file_dst_name_ext, 'a+'))) { + if ($this->dir_auto_chmod) { + $this->log .= '- ' . $this->file_dst_path . ' is not writeable. Attempting chmod:'; + if (!@chmod($this->file_dst_path, $this->dir_chmod)) { + $this->log .= ' failed
'; + $this->processed = false; + $this->error = $this->translate('destination_dir_write'); + } else { + $this->log .= ' success
'; + if (!($f = @fopen($this->file_dst_path . $hash . '.' . $this->file_dst_name_ext, 'a+'))) { // we re-check + $this->processed = false; + $this->error = $this->translate('destination_dir_write'); + } else { + @fclose($f); + } + } + } else { + $this->processed = false; + $this->error = $this->translate('destination_path_write'); + } + } else { + if ($this->processed) @fclose($f); + @unlink($this->file_dst_path . $hash . '.' . $this->file_dst_name_ext); + } + + + // if we have an uploaded file, and if it is the first process, and if we can't access the file directly (open_basedir restriction) + // then we create a temp file that will be used as the source file in subsequent processes + // the third condition is there to check if the file is not accessible *directly* (it already has positively gone through is_uploaded_file(), so it exists) + if (!$this->no_upload_check && empty($this->file_src_temp) && !@file_exists($this->file_src_pathname)) { + $this->log .= '- attempting to use a temp file:'; + $hash = md5($this->file_dst_name_body . rand(1, 1000)); + if (move_uploaded_file($this->file_src_pathname, $this->file_dst_path . $hash . '.' . $this->file_dst_name_ext)) { + $this->file_src_pathname = $this->file_dst_path . $hash . '.' . $this->file_dst_name_ext; + $this->file_src_temp = $this->file_src_pathname; + $this->log .= ' file created
'; + $this->log .= '    temp file is: ' . $this->file_src_temp . '
'; + } else { + $this->log .= ' failed
'; + $this->processed = false; + $this->error = $this->translate('temp_file'); + } + } + } + } + + if ($this->processed) { + + // we do a quick check to ensure the file is really an image + // we can do this only now, as it would have failed before in case of open_basedir + if ($image_manipulation && !@getimagesize($this->file_src_pathname)) { + $this->log .= '- the file is not an image!
'; + $image_manipulation = false; + } + + if ($image_manipulation) { + + // checks if the source file is readable + if ($this->processed && !($f = @fopen($this->file_src_pathname, 'r'))) { + $this->processed = false; + $this->error = $this->translate('source_not_readable'); + } else { + @fclose($f); + } + + // we now do all the image manipulations + $this->log .= '- image resizing or conversion wanted
'; + if ($this->gdversion()) { + switch($this->image_src_type) { + case 'jpg': + if (!function_exists('imagecreatefromjpeg')) { + $this->processed = false; + $this->error = $this->translate('no_create_support', array('JPEG')); + } else { + $image_src = @imagecreatefromjpeg($this->file_src_pathname); + if (!$image_src) { + $this->processed = false; + $this->error = $this->translate('create_error', array('JPEG')); + } else { + $this->log .= '- source image is JPEG
'; + } + } + break; + case 'png': + if (!function_exists('imagecreatefrompng')) { + $this->processed = false; + $this->error = $this->translate('no_create_support', array('PNG')); + } else { + $image_src = @imagecreatefrompng($this->file_src_pathname); + if (!$image_src) { + $this->processed = false; + $this->error = $this->translate('create_error', array('PNG')); + } else { + $this->log .= '- source image is PNG
'; + } + } + break; + case 'gif': + if (!function_exists('imagecreatefromgif')) { + $this->processed = false; + $this->error = $this->translate('no_create_support', array('GIF')); + } else { + $image_src = @imagecreatefromgif($this->file_src_pathname); + if (!$image_src) { + $this->processed = false; + $this->error = $this->translate('create_error', array('GIF')); + } else { + $this->log .= '- source image is GIF
'; + } + } + break; + case 'bmp': + if (!method_exists($this, 'imagecreatefrombmp')) { + $this->processed = false; + $this->error = $this->translate('no_create_support', array('BMP')); + } else { + $image_src = @$this->imagecreatefrombmp($this->file_src_pathname); + if (!$image_src) { + $this->processed = false; + $this->error = $this->translate('create_error', array('BMP')); + } else { + $this->log .= '- source image is BMP
'; + } + } + break; + default: + $this->processed = false; + $this->error = $this->translate('source_invalid'); + } + } else { + $this->processed = false; + $this->error = $this->translate('gd_missing'); + } + + if ($this->processed && $image_src) { + + // we have to set image_convert if it is not already + if (empty($this->image_convert)) { + $this->log .= '- setting destination file type to ' . $this->file_src_name_ext . '
'; + $this->image_convert = $this->file_src_name_ext; + } + + if (!in_array($this->image_convert, $this->image_supported)) { + $this->image_convert = 'jpg'; + } + + // we set the default color to be the background color if we don't output in a transparent format + if ($this->image_convert != 'png' && $this->image_convert != 'gif' && !empty($this->image_default_color) && empty($this->image_background_color)) $this->image_background_color = $this->image_default_color; + if (!empty($this->image_background_color)) $this->image_default_color = $this->image_background_color; + if (empty($this->image_default_color)) $this->image_default_color = '#FFFFFF'; + + $this->image_src_x = imagesx($image_src); + $this->image_src_y = imagesy($image_src); + $gd_version = $this->gdversion(); + $ratio_crop = null; + + if (!imageistruecolor($image_src)) { // $this->image_src_type == 'gif' + $this->log .= '- image is detected as having a palette
'; + $this->image_is_palette = true; + $this->image_transparent_color = imagecolortransparent($image_src); + if ($this->image_transparent_color >= 0 && imagecolorstotal($image_src) > $this->image_transparent_color) { + $this->image_is_transparent = true; + $this->log .= '    palette image is detected as transparent
'; + } + // if the image has a palette (GIF), we convert it to true color, preserving transparency + $this->log .= '    convert palette image to true color
'; + $true_color = imagecreatetruecolor($this->image_src_x, $this->image_src_y); + imagealphablending($true_color, false); + imagesavealpha($true_color, true); + for ($x = 0; $x < $this->image_src_x; $x++) { + for ($y = 0; $y < $this->image_src_y; $y++) { + if ($this->image_transparent_color >= 0 && imagecolorat($image_src, $x, $y) == $this->image_transparent_color) { + imagesetpixel($true_color, $x, $y, 127 << 24); + } else { + $rgb = imagecolorsforindex($image_src, imagecolorat($image_src, $x, $y)); + imagesetpixel($true_color, $x, $y, ($rgb['alpha'] << 24) | ($rgb['red'] << 16) | ($rgb['green'] << 8) | $rgb['blue']); + } + } + } + $image_src = $this->imagetransfer($true_color, $image_src); + imagealphablending($image_src, false); + imagesavealpha($image_src, true); + $this->image_is_palette = false; + } + + + $image_dst = & $image_src; + + // pre-crop image, before resizing + if ((!empty($this->image_precrop))) { + if (is_array($this->image_precrop)) { + $vars = $this->image_precrop; + } else { + $vars = explode(' ', $this->image_precrop); + } + if (sizeof($vars) == 4) { + $ct = $vars[0]; $cr = $vars[1]; $cb = $vars[2]; $cl = $vars[3]; + } else if (sizeof($vars) == 2) { + $ct = $vars[0]; $cr = $vars[1]; $cb = $vars[0]; $cl = $vars[1]; + } else { + $ct = $vars[0]; $cr = $vars[0]; $cb = $vars[0]; $cl = $vars[0]; + } + if (strpos($ct, '%')>0) $ct = $this->image_src_y * (str_replace('%','',$ct) / 100); + if (strpos($cr, '%')>0) $cr = $this->image_src_x * (str_replace('%','',$cr) / 100); + if (strpos($cb, '%')>0) $cb = $this->image_src_y * (str_replace('%','',$cb) / 100); + if (strpos($cl, '%')>0) $cl = $this->image_src_x * (str_replace('%','',$cl) / 100); + if (strpos($ct, 'px')>0) $ct = str_replace('px','',$ct); + if (strpos($cr, 'px')>0) $cr = str_replace('px','',$cr); + if (strpos($cb, 'px')>0) $cb = str_replace('px','',$cb); + if (strpos($cl, 'px')>0) $cl = str_replace('px','',$cl); + $ct = (int) $ct; + $cr = (int) $cr; + $cb = (int) $cb; + $cl = (int) $cl; + $this->log .= '- pre-crop image : ' . $ct . ' ' . $cr . ' ' . $cb . ' ' . $cl . '
'; + $this->image_src_x = $this->image_src_x - $cl - $cr; + $this->image_src_y = $this->image_src_y - $ct - $cb; + if ($this->image_src_x < 1) $this->image_src_x = 1; + if ($this->image_src_y < 1) $this->image_src_y = 1; + $tmp = $this->imagecreatenew($this->image_src_x, $this->image_src_y); + + // we copy the image into the recieving image + imagecopy($tmp, $image_dst, 0, 0, $cl, $ct, $this->image_src_x, $this->image_src_y); + + // if we crop with negative margins, we have to make sure the extra bits are the right color, or transparent + if ($ct < 0 || $cr < 0 || $cb < 0 || $cl < 0 ) { + // use the background color if present + if (!empty($this->image_background_color)) { + list($red, $green, $blue) = $this->getcolors($this->image_background_color); + $fill = imagecolorallocate($tmp, $red, $green, $blue); + } else { + $fill = imagecolorallocatealpha($tmp, 0, 0, 0, 127); + } + // fills eventual negative margins + if ($ct < 0) imagefilledrectangle($tmp, 0, 0, $this->image_src_x, -$ct, $fill); + if ($cr < 0) imagefilledrectangle($tmp, $this->image_src_x + $cr, 0, $this->image_src_x, $this->image_src_y, $fill); + if ($cb < 0) imagefilledrectangle($tmp, 0, $this->image_src_y + $cb, $this->image_src_x, $this->image_src_y, $fill); + if ($cl < 0) imagefilledrectangle($tmp, 0, 0, -$cl, $this->image_src_y, $fill); + } + + // we transfert tmp into image_dst + $image_dst = $this->imagetransfer($tmp, $image_dst); + } + + // resize image (and move image_src_x, image_src_y dimensions into image_dst_x, image_dst_y) + if ($this->image_resize) { + $this->log .= '- resizing...
'; + + if ($this->image_ratio_x) { + $this->log .= '    calculate x size
'; + $this->image_dst_x = round(($this->image_src_x * $this->image_y) / $this->image_src_y); + $this->image_dst_y = $this->image_y; + } else if ($this->image_ratio_y) { + $this->log .= '    calculate y size
'; + $this->image_dst_x = $this->image_x; + $this->image_dst_y = round(($this->image_src_y * $this->image_x) / $this->image_src_x); + } else if (is_numeric($this->image_ratio_pixels)) { + $this->log .= '    calculate x/y size to match a number of pixels
'; + $pixels = $this->image_src_y * $this->image_src_x; + $diff = sqrt($this->image_ratio_pixels / $pixels); + $this->image_dst_x = round($this->image_src_x * $diff); + $this->image_dst_y = round($this->image_src_y * $diff); + } else if ($this->image_ratio || $this->image_ratio_crop || $this->image_ratio_fill || $this->image_ratio_no_zoom_in || $this->image_ratio_no_zoom_out) { + $this->log .= '    check x/y sizes
'; + if ((!$this->image_ratio_no_zoom_in && !$this->image_ratio_no_zoom_out) + || ($this->image_ratio_no_zoom_in && ($this->image_src_x > $this->image_x || $this->image_src_y > $this->image_y)) + || ($this->image_ratio_no_zoom_out && $this->image_src_x < $this->image_x && $this->image_src_y < $this->image_y)) { + $this->image_dst_x = $this->image_x; + $this->image_dst_y = $this->image_y; + if ($this->image_ratio_crop) { + if (!is_string($this->image_ratio_crop)) $this->image_ratio_crop = ''; + $this->image_ratio_crop = strtolower($this->image_ratio_crop); + if (($this->image_src_x/$this->image_x) > ($this->image_src_y/$this->image_y)) { + $this->image_dst_y = $this->image_y; + $this->image_dst_x = intval($this->image_src_x*($this->image_y / $this->image_src_y)); + $ratio_crop = array(); + $ratio_crop['x'] = $this->image_dst_x - $this->image_x; + if (strpos($this->image_ratio_crop, 'l') !== false) { + $ratio_crop['l'] = 0; + $ratio_crop['r'] = $ratio_crop['x']; + } else if (strpos($this->image_ratio_crop, 'r') !== false) { + $ratio_crop['l'] = $ratio_crop['x']; + $ratio_crop['r'] = 0; + } else { + $ratio_crop['l'] = round($ratio_crop['x']/2); + $ratio_crop['r'] = $ratio_crop['x'] - $ratio_crop['l']; + } + $this->log .= '    ratio_crop_x : ' . $ratio_crop['x'] . ' (' . $ratio_crop['l'] . ';' . $ratio_crop['r'] . ')
'; + if (is_null($this->image_crop)) $this->image_crop = array(0, 0, 0, 0); + } else { + $this->image_dst_x = $this->image_x; + $this->image_dst_y = intval($this->image_src_y*($this->image_x / $this->image_src_x)); + $ratio_crop = array(); + $ratio_crop['y'] = $this->image_dst_y - $this->image_y; + if (strpos($this->image_ratio_crop, 't') !== false) { + $ratio_crop['t'] = 0; + $ratio_crop['b'] = $ratio_crop['y']; + } else if (strpos($this->image_ratio_crop, 'b') !== false) { + $ratio_crop['t'] = $ratio_crop['y']; + $ratio_crop['b'] = 0; + } else { + $ratio_crop['t'] = round($ratio_crop['y']/2); + $ratio_crop['b'] = $ratio_crop['y'] - $ratio_crop['t']; + } + $this->log .= '    ratio_crop_y : ' . $ratio_crop['y'] . ' (' . $ratio_crop['t'] . ';' . $ratio_crop['b'] . ')
'; + if (is_null($this->image_crop)) $this->image_crop = array(0, 0, 0, 0); + } + } else if ($this->image_ratio_fill) { + if (!is_string($this->image_ratio_fill)) $this->image_ratio_fill = ''; + $this->image_ratio_fill = strtolower($this->image_ratio_fill); + if (($this->image_src_x/$this->image_x) < ($this->image_src_y/$this->image_y)) { + $this->image_dst_y = $this->image_y; + $this->image_dst_x = intval($this->image_src_x*($this->image_y / $this->image_src_y)); + $ratio_crop = array(); + $ratio_crop['x'] = $this->image_dst_x - $this->image_x; + if (strpos($this->image_ratio_fill, 'l') !== false) { + $ratio_crop['l'] = 0; + $ratio_crop['r'] = $ratio_crop['x']; + } else if (strpos($this->image_ratio_fill, 'r') !== false) { + $ratio_crop['l'] = $ratio_crop['x']; + $ratio_crop['r'] = 0; + } else { + $ratio_crop['l'] = round($ratio_crop['x']/2); + $ratio_crop['r'] = $ratio_crop['x'] - $ratio_crop['l']; + } + $this->log .= '    ratio_fill_x : ' . $ratio_crop['x'] . ' (' . $ratio_crop['l'] . ';' . $ratio_crop['r'] . ')
'; + if (is_null($this->image_crop)) $this->image_crop = array(0, 0, 0, 0); + } else { + $this->image_dst_x = $this->image_x; + $this->image_dst_y = intval($this->image_src_y*($this->image_x / $this->image_src_x)); + $ratio_crop = array(); + $ratio_crop['y'] = $this->image_dst_y - $this->image_y; + if (strpos($this->image_ratio_fill, 't') !== false) { + $ratio_crop['t'] = 0; + $ratio_crop['b'] = $ratio_crop['y']; + } else if (strpos($this->image_ratio_fill, 'b') !== false) { + $ratio_crop['t'] = $ratio_crop['y']; + $ratio_crop['b'] = 0; + } else { + $ratio_crop['t'] = round($ratio_crop['y']/2); + $ratio_crop['b'] = $ratio_crop['y'] - $ratio_crop['t']; + } + $this->log .= '    ratio_fill_y : ' . $ratio_crop['y'] . ' (' . $ratio_crop['t'] . ';' . $ratio_crop['b'] . ')
'; + if (is_null($this->image_crop)) $this->image_crop = array(0, 0, 0, 0); + } + } else { + if (($this->image_src_x/$this->image_x) > ($this->image_src_y/$this->image_y)) { + $this->image_dst_x = $this->image_x; + $this->image_dst_y = intval($this->image_src_y*($this->image_x / $this->image_src_x)); + } else { + $this->image_dst_y = $this->image_y; + $this->image_dst_x = intval($this->image_src_x*($this->image_y / $this->image_src_y)); + } + } + } else { + $this->log .= '    doesn\'t calculate x/y sizes
'; + $this->image_dst_x = $this->image_src_x; + $this->image_dst_y = $this->image_src_y; + } + } else { + $this->log .= '    use plain sizes
'; + $this->image_dst_x = $this->image_x; + $this->image_dst_y = $this->image_y; + } + + if ($this->image_dst_x < 1) $this->image_dst_x = 1; + if ($this->image_dst_y < 1) $this->image_dst_y = 1; + $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); + + if ($gd_version >= 2) { + $res = imagecopyresampled($tmp, $image_src, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, $this->image_src_x, $this->image_src_y); + } else { + $res = imagecopyresized($tmp, $image_src, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, $this->image_src_x, $this->image_src_y); + } + + $this->log .= '    resized image object created
'; + $this->log .= '    image_src_x y : ' . $this->image_src_x . ' x ' . $this->image_src_y . '
'; + $this->log .= '    image_dst_x y : ' . $this->image_dst_x . ' x ' . $this->image_dst_y . '
'; + // we transfert tmp into image_dst + $image_dst = $this->imagetransfer($tmp, $image_dst); + + } else { + $this->image_dst_x = $this->image_src_x; + $this->image_dst_y = $this->image_src_y; + } + + // crop image (and also crops if image_ratio_crop is used) + if ((!empty($this->image_crop) || !is_null($ratio_crop))) { + if (is_array($this->image_crop)) { + $vars = $this->image_crop; + } else { + $vars = explode(' ', $this->image_crop); + } + if (sizeof($vars) == 4) { + $ct = $vars[0]; $cr = $vars[1]; $cb = $vars[2]; $cl = $vars[3]; + } else if (sizeof($vars) == 2) { + $ct = $vars[0]; $cr = $vars[1]; $cb = $vars[0]; $cl = $vars[1]; + } else { + $ct = $vars[0]; $cr = $vars[0]; $cb = $vars[0]; $cl = $vars[0]; + } + if (strpos($ct, '%')>0) $ct = $this->image_dst_y * (str_replace('%','',$ct) / 100); + if (strpos($cr, '%')>0) $cr = $this->image_dst_x * (str_replace('%','',$cr) / 100); + if (strpos($cb, '%')>0) $cb = $this->image_dst_y * (str_replace('%','',$cb) / 100); + if (strpos($cl, '%')>0) $cl = $this->image_dst_x * (str_replace('%','',$cl) / 100); + if (strpos($ct, 'px')>0) $ct = str_replace('px','',$ct); + if (strpos($cr, 'px')>0) $cr = str_replace('px','',$cr); + if (strpos($cb, 'px')>0) $cb = str_replace('px','',$cb); + if (strpos($cl, 'px')>0) $cl = str_replace('px','',$cl); + $ct = (int) $ct; + $cr = (int) $cr; + $cb = (int) $cb; + $cl = (int) $cl; + // we adjust the cropping if we use image_ratio_crop + if (!is_null($ratio_crop)) { + if (array_key_exists('t', $ratio_crop)) $ct += $ratio_crop['t']; + if (array_key_exists('r', $ratio_crop)) $cr += $ratio_crop['r']; + if (array_key_exists('b', $ratio_crop)) $cb += $ratio_crop['b']; + if (array_key_exists('l', $ratio_crop)) $cl += $ratio_crop['l']; + } + $this->log .= '- crop image : ' . $ct . ' ' . $cr . ' ' . $cb . ' ' . $cl . '
'; + $this->image_dst_x = $this->image_dst_x - $cl - $cr; + $this->image_dst_y = $this->image_dst_y - $ct - $cb; + if ($this->image_dst_x < 1) $this->image_dst_x = 1; + if ($this->image_dst_y < 1) $this->image_dst_y = 1; + $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); + + // we copy the image into the recieving image + imagecopy($tmp, $image_dst, 0, 0, $cl, $ct, $this->image_dst_x, $this->image_dst_y); + + // if we crop with negative margins, we have to make sure the extra bits are the right color, or transparent + if ($ct < 0 || $cr < 0 || $cb < 0 || $cl < 0 ) { + // use the background color if present + if (!empty($this->image_background_color)) { + list($red, $green, $blue) = $this->getcolors($this->image_background_color); + $fill = imagecolorallocate($tmp, $red, $green, $blue); + } else { + $fill = imagecolorallocatealpha($tmp, 0, 0, 0, 127); + } + // fills eventual negative margins + if ($ct < 0) imagefilledrectangle($tmp, 0, 0, $this->image_dst_x, -$ct, $fill); + if ($cr < 0) imagefilledrectangle($tmp, $this->image_dst_x + $cr, 0, $this->image_dst_x, $this->image_dst_y, $fill); + if ($cb < 0) imagefilledrectangle($tmp, 0, $this->image_dst_y + $cb, $this->image_dst_x, $this->image_dst_y, $fill); + if ($cl < 0) imagefilledrectangle($tmp, 0, 0, -$cl, $this->image_dst_y, $fill); + } + + // we transfert tmp into image_dst + $image_dst = $this->imagetransfer($tmp, $image_dst); + } + + // flip image + if ($gd_version >= 2 && !empty($this->image_flip)) { + $this->image_flip = strtolower($this->image_flip); + $this->log .= '- flip image : ' . $this->image_flip . '
'; + $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); + for ($x = 0; $x < $this->image_dst_x; $x++) { + for ($y = 0; $y < $this->image_dst_y; $y++){ + if (strpos($this->image_flip, 'v') !== false) { + imagecopy($tmp, $image_dst, $this->image_dst_x - $x - 1, $y, $x, $y, 1, 1); + } else { + imagecopy($tmp, $image_dst, $x, $this->image_dst_y - $y - 1, $x, $y, 1, 1); + } + } + } + // we transfert tmp into image_dst + $image_dst = $this->imagetransfer($tmp, $image_dst); + } + + // rotate image + if ($gd_version >= 2 && is_numeric($this->image_rotate)) { + if (!in_array($this->image_rotate, array(0, 90, 180, 270))) $this->image_rotate = 0; + if ($this->image_rotate != 0) { + if ($this->image_rotate == 90 || $this->image_rotate == 270) { + $tmp = $this->imagecreatenew($this->image_dst_y, $this->image_dst_x); + } else { + $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); + } + $this->log .= '- rotate image : ' . $this->image_rotate . '
'; + for ($x = 0; $x < $this->image_dst_x; $x++) { + for ($y = 0; $y < $this->image_dst_y; $y++){ + if ($this->image_rotate == 90) { + imagecopy($tmp, $image_dst, $y, $x, $x, $this->image_dst_y - $y - 1, 1, 1); + } else if ($this->image_rotate == 180) { + imagecopy($tmp, $image_dst, $x, $y, $this->image_dst_x - $x - 1, $this->image_dst_y - $y - 1, 1, 1); + } else if ($this->image_rotate == 270) { + imagecopy($tmp, $image_dst, $y, $x, $this->image_dst_x - $x - 1, $y, 1, 1); + } else { + imagecopy($tmp, $image_dst, $x, $y, $x, $y, 1, 1); + } + } + } + if ($this->image_rotate == 90 || $this->image_rotate == 270) { + $t = $this->image_dst_y; + $this->image_dst_y = $this->image_dst_x; + $this->image_dst_x = $t; + } + // we transfert tmp into image_dst + $image_dst = $this->imagetransfer($tmp, $image_dst); + } + } + + // add color overlay + if ($gd_version >= 2 && (is_numeric($this->image_overlay_percent) && $this->image_overlay_percent > 0 && !empty($this->image_overlay_color))) { + $this->log .= '- apply color overlay
'; + list($red, $green, $blue) = $this->getcolors($this->image_overlay_color); + $filter = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y); + $color = imagecolorallocate($filter, $red, $green, $blue); + imagefilledrectangle($filter, 0, 0, $this->image_dst_x, $this->image_dst_y, $color); + $this->imagecopymergealpha($image_dst, $filter, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, $this->image_overlay_percent); + imagedestroy($filter); + } + + // add brightness, contrast and tint, turns to greyscale and inverts colors + if ($gd_version >= 2 && ($this->image_negative || $this->image_greyscale || is_numeric($this->image_threshold)|| is_numeric($this->image_brightness) || is_numeric($this->image_contrast) || !empty($this->image_tint_color))) { + $this->log .= '- apply tint, light, contrast correction, negative, greyscale and threshold
'; + if (!empty($this->image_tint_color)) list($tint_red, $tint_green, $tint_blue) = $this->getcolors($this->image_tint_color); + imagealphablending($image_dst, true); + for($y=0; $y < $this->image_dst_y; $y++) { + for($x=0; $x < $this->image_dst_x; $x++) { + if ($this->image_greyscale) { + $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); + $r = $g = $b = round((0.2125 * $pixel['red']) + (0.7154 * $pixel['green']) + (0.0721 * $pixel['blue'])); + $color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); + imagesetpixel($image_dst, $x, $y, $color); + } + if (is_numeric($this->image_threshold)) { + $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); + $c = (round($pixel['red'] + $pixel['green'] + $pixel['blue']) / 3) - 127; + $r = $g = $b = ($c > $this->image_threshold ? 255 : 0); + $color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); + imagesetpixel($image_dst, $x, $y, $color); + } + if (is_numeric($this->image_brightness)) { + $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); + $r = max(min(round($pixel['red'] + (($this->image_brightness * 2))), 255), 0); + $g = max(min(round($pixel['green'] + (($this->image_brightness * 2))), 255), 0); + $b = max(min(round($pixel['blue'] + (($this->image_brightness * 2))), 255), 0); + $color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); + imagesetpixel($image_dst, $x, $y, $color); + } + if (is_numeric($this->image_contrast)) { + $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); + $r = max(min(round(($this->image_contrast + 128) * $pixel['red'] / 128), 255), 0); + $g = max(min(round(($this->image_contrast + 128) * $pixel['green'] / 128), 255), 0); + $b = max(min(round(($this->image_contrast + 128) * $pixel['blue'] / 128), 255), 0); + $color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); + imagesetpixel($image_dst, $x, $y, $color); + } + if (!empty($this->image_tint_color)) { + $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); + $r = min(round($tint_red * $pixel['red'] / 169), 255); + $g = min(round($tint_green * $pixel['green'] / 169), 255); + $b = min(round($tint_blue * $pixel['blue'] / 169), 255); + $color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); + imagesetpixel($image_dst, $x, $y, $color); + } + if (!empty($this->image_negative)) { + $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); + $r = round(255 - $pixel['red']); + $g = round(255 - $pixel['green']); + $b = round(255 - $pixel['blue']); + $color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); + imagesetpixel($image_dst, $x, $y, $color); + } + } + } + } + + // adds a border + if ($gd_version >= 2 && !empty($this->image_border)) { + if (is_array($this->image_border)) { + $vars = $this->image_border; + $this->log .= '- add border : ' . implode(' ', $this->image_border) . '
'; + } else { + $this->log .= '- add border : ' . $this->image_border . '
'; + $vars = explode(' ', $this->image_border); + } + if (sizeof($vars) == 4) { + $ct = $vars[0]; $cr = $vars[1]; $cb = $vars[2]; $cl = $vars[3]; + } else if (sizeof($vars) == 2) { + $ct = $vars[0]; $cr = $vars[1]; $cb = $vars[0]; $cl = $vars[1]; + } else { + $ct = $vars[0]; $cr = $vars[0]; $cb = $vars[0]; $cl = $vars[0]; + } + if (strpos($ct, '%')>0) $ct = $this->image_dst_y * (str_replace('%','',$ct) / 100); + if (strpos($cr, '%')>0) $cr = $this->image_dst_x * (str_replace('%','',$cr) / 100); + if (strpos($cb, '%')>0) $cb = $this->image_dst_y * (str_replace('%','',$cb) / 100); + if (strpos($cl, '%')>0) $cl = $this->image_dst_x * (str_replace('%','',$cl) / 100); + if (strpos($ct, 'px')>0) $ct = str_replace('px','',$ct); + if (strpos($cr, 'px')>0) $cr = str_replace('px','',$cr); + if (strpos($cb, 'px')>0) $cb = str_replace('px','',$cb); + if (strpos($cl, 'px')>0) $cl = str_replace('px','',$cl); + $ct = (int) $ct; + $cr = (int) $cr; + $cb = (int) $cb; + $cl = (int) $cl; + $this->image_dst_x = $this->image_dst_x + $cl + $cr; + $this->image_dst_y = $this->image_dst_y + $ct + $cb; + if (!empty($this->image_border_color)) list($red, $green, $blue) = $this->getcolors($this->image_border_color); + // we now create an image, that we fill with the border color + $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); + $background = imagecolorallocatealpha($tmp, $red, $green, $blue, 0); + imagefilledrectangle($tmp, 0, 0, $this->image_dst_x, $this->image_dst_y, $background); + // we then copy the source image into the new image, without merging so that only the border is actually kept + imagecopy($tmp, $image_dst, $cl, $ct, 0, 0, $this->image_dst_x - $cr - $cl, $this->image_dst_y - $cb - $ct); + // we transfert tmp into image_dst + $image_dst = $this->imagetransfer($tmp, $image_dst); + } + + // add frame border + if (is_numeric($this->image_frame)) { + if (is_array($this->image_frame_colors)) { + $vars = $this->image_frame_colors; + $this->log .= '- add frame : ' . implode(' ', $this->image_frame_colors) . '
'; + } else { + $this->log .= '- add frame : ' . $this->image_frame_colors . '
'; + $vars = explode(' ', $this->image_frame_colors); + } + $nb = sizeof($vars); + $this->image_dst_x = $this->image_dst_x + ($nb * 2); + $this->image_dst_y = $this->image_dst_y + ($nb * 2); + $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); + imagecopy($tmp, $image_dst, $nb, $nb, 0, 0, $this->image_dst_x - ($nb * 2), $this->image_dst_y - ($nb * 2)); + for ($i=0; $i<$nb; $i++) { + list($red, $green, $blue) = $this->getcolors($vars[$i]); + $c = imagecolorallocate($tmp, $red, $green, $blue); + if ($this->image_frame == 1) { + imageline($tmp, $i, $i, $this->image_dst_x - $i -1, $i, $c); + imageline($tmp, $this->image_dst_x - $i -1, $this->image_dst_y - $i -1, $this->image_dst_x - $i -1, $i, $c); + imageline($tmp, $this->image_dst_x - $i -1, $this->image_dst_y - $i -1, $i, $this->image_dst_y - $i -1, $c); + imageline($tmp, $i, $i, $i, $this->image_dst_y - $i -1, $c); + } else { + imageline($tmp, $i, $i, $this->image_dst_x - $i -1, $i, $c); + imageline($tmp, $this->image_dst_x - $nb + $i, $this->image_dst_y - $nb + $i, $this->image_dst_x - $nb + $i, $nb - $i, $c); + imageline($tmp, $this->image_dst_x - $nb + $i, $this->image_dst_y - $nb + $i, $nb - $i, $this->image_dst_y - $nb + $i, $c); + imageline($tmp, $i, $i, $i, $this->image_dst_y - $i -1, $c); + } + } + // we transfert tmp into image_dst + $image_dst = $this->imagetransfer($tmp, $image_dst); + } + + // add bevel border + if ($this->image_bevel > 0) { + if (empty($this->image_bevel_color1)) $this->image_bevel_color1 = '#FFFFFF'; + if (empty($this->image_bevel_color2)) $this->image_bevel_color2 = '#000000'; + list($red1, $green1, $blue1) = $this->getcolors($this->image_bevel_color1); + list($red2, $green2, $blue2) = $this->getcolors($this->image_bevel_color2); + $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); + imagecopy($tmp, $image_dst, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y); + imagealphablending($tmp, true); + for ($i=0; $i<$this->image_bevel; $i++) { + $alpha = round(($i / $this->image_bevel) * 127); + $c1 = imagecolorallocatealpha($tmp, $red1, $green1, $blue1, $alpha); + $c2 = imagecolorallocatealpha($tmp, $red2, $green2, $blue2, $alpha); + imageline($tmp, $i, $i, $this->image_dst_x - $i -1, $i, $c1); + imageline($tmp, $this->image_dst_x - $i -1, $this->image_dst_y - $i, $this->image_dst_x - $i -1, $i, $c2); + imageline($tmp, $this->image_dst_x - $i -1, $this->image_dst_y - $i -1, $i, $this->image_dst_y - $i -1, $c2); + imageline($tmp, $i, $i, $i, $this->image_dst_y - $i -1, $c1); + } + // we transfert tmp into image_dst + $image_dst = $this->imagetransfer($tmp, $image_dst); + } + + // add watermark image + if ($this->image_watermark!='' && file_exists($this->image_watermark)) { + $this->log .= '- add watermark
'; + $this->image_watermark_position = strtolower($this->image_watermark_position); + $watermark_info = getimagesize($this->image_watermark); + $watermark_type = (array_key_exists(2, $watermark_info) ? $watermark_info[2] : null); // 1 = GIF, 2 = JPG, 3 = PNG + $watermark_checked = false; + if ($watermark_type == IMAGETYPE_GIF) { + if (!function_exists('imagecreatefromgif')) { + $this->error = $this->translate('watermark_no_create_support', array('GIF')); + } else { + $filter = @imagecreatefromgif($this->image_watermark); + if (!$filter) { + $this->error = $this->translate('watermark_create_error', array('GIF')); + } else { + $this->log .= '    watermark source image is GIF
'; + $watermark_checked = true; + } + } + } else if ($watermark_type == IMAGETYPE_JPEG) { + if (!function_exists('imagecreatefromjpeg')) { + $this->error = $this->translate('watermark_no_create_support', array('JPEG')); + } else { + $filter = @imagecreatefromjpeg($this->image_watermark); + if (!$filter) { + $this->error = $this->translate('watermark_create_error', array('JPEG')); + } else { + $this->log .= '    watermark source image is JPEG
'; + $watermark_checked = true; + } + } + } else if ($watermark_type == IMAGETYPE_PNG) { + if (!function_exists('imagecreatefrompng')) { + $this->error = $this->translate('watermark_no_create_support', array('PNG')); + } else { + $filter = @imagecreatefrompng($this->image_watermark); + if (!$filter) { + $this->error = $this->translate('watermark_create_error', array('PNG')); + } else { + $this->log .= '    watermark source image is PNG
'; + $watermark_checked = true; + } + } + } else if ($watermark_type == IMAGETYPE_BMP) { + if (!method_exists($this, 'imagecreatefrombmp')) { + $this->error = $this->translate('watermark_no_create_support', array('BMP')); + } else { + $filter = @$this->imagecreatefrombmp($this->image_watermark); + if (!$filter) { + $this->error = $this->translate('watermark_create_error', array('BMP')); + } else { + $this->log .= '    watermark source image is BMP
'; + $watermark_checked = true; + } + } + } else { + $this->error = $this->translate('watermark_invalid'); + } + if ($watermark_checked) { + $watermark_width = imagesx($filter); + $watermark_height = imagesy($filter); + $watermark_x = 0; + $watermark_y = 0; + if (is_numeric($this->image_watermark_x)) { + if ($this->image_watermark_x < 0) { + $watermark_x = $this->image_dst_x - $watermark_width + $this->image_watermark_x; + } else { + $watermark_x = $this->image_watermark_x; + } + } else { + if (strpos($this->image_watermark_position, 'r') !== false) { + $watermark_x = $this->image_dst_x - $watermark_width; + } else if (strpos($this->image_watermark_position, 'l') !== false) { + $watermark_x = 0; + } else { + $watermark_x = ($this->image_dst_x - $watermark_width) / 2; + } + } + if (is_numeric($this->image_watermark_y)) { + if ($this->image_watermark_y < 0) { + $watermark_y = $this->image_dst_y - $watermark_height + $this->image_watermark_y; + } else { + $watermark_y = $this->image_watermark_y; + } + } else { + if (strpos($this->image_watermark_position, 'b') !== false) { + $watermark_y = $this->image_dst_y - $watermark_height; + } else if (strpos($this->image_watermark_position, 't') !== false) { + $watermark_y = 0; + } else { + $watermark_y = ($this->image_dst_y - $watermark_height) / 2; + } + } + imagecopyresampled ($image_dst, $filter, $watermark_x, $watermark_y, 0, 0, $watermark_width, $watermark_height, $watermark_width, $watermark_height); + } else { + $this->error = $this->translate('watermark_invalid'); + } + } + + // add text + if (!empty($this->image_text)) { + $this->log .= '- add text
'; + + // calculate sizes in human readable format + $src_size = $this->file_src_size / 1024; + $src_size_mb = number_format($src_size / 1024, 1, ".", " "); + $src_size_kb = number_format($src_size, 1, ".", " "); + $src_size_human = ($src_size > 1024 ? $src_size_mb . " MB" : $src_size_kb . " kb"); + + $this->image_text = str_replace( + array('[src_name]', + '[src_name_body]', + '[src_name_ext]', + '[src_pathname]', + '[src_mime]', + '[src_size]', + '[src_size_kb]', + '[src_size_mb]', + '[src_size_human]', + '[src_x]', + '[src_y]', + '[src_pixels]', + '[src_type]', + '[src_bits]', + '[dst_path]', + '[dst_name_body]', + '[dst_name_ext]', + '[dst_name]', + '[dst_pathname]', + '[dst_x]', + '[dst_y]', + '[date]', + '[time]', + '[host]', + '[server]', + '[ip]', + '[gd_version]'), + array($this->file_src_name, + $this->file_src_name_body, + $this->file_src_name_ext, + $this->file_src_pathname, + $this->file_src_mime, + $this->file_src_size, + $src_size_kb, + $src_size_mb, + $src_size_human, + $this->image_src_x, + $this->image_src_y, + $this->image_src_pixels, + $this->image_src_type, + $this->image_src_bits, + $this->file_dst_path, + $this->file_dst_name_body, + $this->file_dst_name_ext, + $this->file_dst_name, + $this->file_dst_pathname, + $this->image_dst_x, + $this->image_dst_y, + date('Y-m-d'), + date('H:i:s'), + (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'n/a'), + (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'n/a'), + (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'n/a'), + $this->gdversion(true)), + $this->image_text); + + if (!is_numeric($this->image_text_padding)) $this->image_text_padding = 0; + if (!is_numeric($this->image_text_line_spacing)) $this->image_text_line_spacing = 0; + if (!is_numeric($this->image_text_padding_x)) $this->image_text_padding_x = $this->image_text_padding; + if (!is_numeric($this->image_text_padding_y)) $this->image_text_padding_y = $this->image_text_padding; + $this->image_text_position = strtolower($this->image_text_position); + $this->image_text_direction = strtolower($this->image_text_direction); + $this->image_text_alignment = strtolower($this->image_text_alignment); + + // if the font is a string, we assume that we might want to load a font + if (!is_numeric($this->image_text_font) && strlen($this->image_text_font) > 4 && substr(strtolower($this->image_text_font), -4) == '.gdf') { + $this->log .= '    try to load font ' . $this->image_text_font . '... '; + if ($this->image_text_font = @imageloadfont($this->image_text_font)) { + $this->log .= 'success
'; + } else { + $this->log .= 'error
'; + $this->image_text_font = 5; + } + } + + $text = explode("\n", $this->image_text); + $char_width = imagefontwidth($this->image_text_font); + $char_height = imagefontheight($this->image_text_font); + $text_height = 0; + $text_width = 0; + $line_height = 0; + $line_width = 0; + + foreach ($text as $k => $v) { + if ($this->image_text_direction == 'v') { + $h = ($char_width * strlen($v)); + if ($h > $text_height) $text_height = $h; + $line_width = $char_height; + $text_width += $line_width + ($k < (sizeof($text)-1) ? $this->image_text_line_spacing : 0); + } else { + $w = ($char_width * strlen($v)); + if ($w > $text_width) $text_width = $w; + $line_height = $char_height; + $text_height += $line_height + ($k < (sizeof($text)-1) ? $this->image_text_line_spacing : 0); + } + } + $text_width += (2 * $this->image_text_padding_x); + $text_height += (2 * $this->image_text_padding_y); + $text_x = 0; + $text_y = 0; + if (is_numeric($this->image_text_x)) { + if ($this->image_text_x < 0) { + $text_x = $this->image_dst_x - $text_width + $this->image_text_x; + } else { + $text_x = $this->image_text_x; + } + } else { + if (strpos($this->image_text_position, 'r') !== false) { + $text_x = $this->image_dst_x - $text_width; + } else if (strpos($this->image_text_position, 'l') !== false) { + $text_x = 0; + } else { + $text_x = ($this->image_dst_x - $text_width) / 2; + } + } + if (is_numeric($this->image_text_y)) { + if ($this->image_text_y < 0) { + $text_y = $this->image_dst_y - $text_height + $this->image_text_y; + } else { + $text_y = $this->image_text_y; + } + } else { + if (strpos($this->image_text_position, 'b') !== false) { + $text_y = $this->image_dst_y - $text_height; + } else if (strpos($this->image_text_position, 't') !== false) { + $text_y = 0; + } else { + $text_y = ($this->image_dst_y - $text_height) / 2; + } + } + + // add a background, maybe transparent + if (!empty($this->image_text_background)) { + list($red, $green, $blue) = $this->getcolors($this->image_text_background); + if ($gd_version >= 2 && (is_numeric($this->image_text_background_percent)) && $this->image_text_background_percent >= 0 && $this->image_text_background_percent <= 100) { + $filter = imagecreatetruecolor($text_width, $text_height); + $background_color = imagecolorallocate($filter, $red, $green, $blue); + imagefilledrectangle($filter, 0, 0, $text_width, $text_height, $background_color); + $this->imagecopymergealpha($image_dst, $filter, $text_x, $text_y, 0, 0, $text_width, $text_height, $this->image_text_background_percent); + imagedestroy($filter); + } else { + $background_color = imagecolorallocate($image_dst ,$red, $green, $blue); + imagefilledrectangle($image_dst, $text_x, $text_y, $text_x + $text_width, $text_y + $text_height, $background_color); + } + } + + $text_x += $this->image_text_padding_x; + $text_y += $this->image_text_padding_y; + $t_width = $text_width - (2 * $this->image_text_padding_x); + $t_height = $text_height - (2 * $this->image_text_padding_y); + list($red, $green, $blue) = $this->getcolors($this->image_text_color); + + // add the text, maybe transparent + if ($gd_version >= 2 && (is_numeric($this->image_text_percent)) && $this->image_text_percent >= 0 && $this->image_text_percent <= 100) { + if ($t_width < 0) $t_width = 0; + if ($t_height < 0) $t_height = 0; + $filter = $this->imagecreatenew($t_width, $t_height, false, true); + $text_color = imagecolorallocate($filter ,$red, $green, $blue); + + foreach ($text as $k => $v) { + if ($this->image_text_direction == 'v') { + imagestringup($filter, + $this->image_text_font, + $k * ($line_width + ($k > 0 && $k < (sizeof($text)) ? $this->image_text_line_spacing : 0)), + $text_height - (2 * $this->image_text_padding_y) - ($this->image_text_alignment == 'l' ? 0 : (($t_height - strlen($v) * $char_width) / ($this->image_text_alignment == 'r' ? 1 : 2))) , + $v, + $text_color); + } else { + imagestring($filter, + $this->image_text_font, + ($this->image_text_alignment == 'l' ? 0 : (($t_width - strlen($v) * $char_width) / ($this->image_text_alignment == 'r' ? 1 : 2))), + $k * ($line_height + ($k > 0 && $k < (sizeof($text)) ? $this->image_text_line_spacing : 0)), + $v, + $text_color); + } + } + $this->imagecopymergealpha($image_dst, $filter, $text_x, $text_y, 0, 0, $t_width, $t_height, $this->image_text_percent); + imagedestroy($filter); + + } else { + $text_color = imageColorAllocate($image_dst ,$red, $green, $blue); + foreach ($text as $k => $v) { + if ($this->image_text_direction == 'v') { + imagestringup($image_dst, + $this->image_text_font, + $text_x + $k * ($line_width + ($k > 0 && $k < (sizeof($text)) ? $this->image_text_line_spacing : 0)), + $text_y + $text_height - (2 * $this->image_text_padding_y) - ($this->image_text_alignment == 'l' ? 0 : (($t_height - strlen($v) * $char_width) / ($this->image_text_alignment == 'r' ? 1 : 2))), + $v, + $text_color); + } else { + imagestring($image_dst, + $this->image_text_font, + $text_x + ($this->image_text_alignment == 'l' ? 0 : (($t_width - strlen($v) * $char_width) / ($this->image_text_alignment == 'r' ? 1 : 2))), + $text_y + $k * ($line_height + ($k > 0 && $k < (sizeof($text)) ? $this->image_text_line_spacing : 0)), + $v, + $text_color); + } + } + } + } + + // add a reflection + if ($this->image_reflection_height) { + $this->log .= '- add reflection : ' . $this->image_reflection_height . '
'; + // we decode image_reflection_height, which can be a integer, a string in pixels or percentage + $image_reflection_height = $this->image_reflection_height; + if (strpos($image_reflection_height, '%')>0) $image_reflection_height = $this->image_dst_y * (str_replace('%','',$image_reflection_height / 100)); + if (strpos($image_reflection_height, 'px')>0) $image_reflection_height = str_replace('px','',$image_reflection_height); + $image_reflection_height = (int) $image_reflection_height; + if ($image_reflection_height > $this->image_dst_y) $image_reflection_height = $this->image_dst_y; + if (empty($this->image_reflection_opacity)) $this->image_reflection_opacity = 60; + // create the new destination image + $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y + $image_reflection_height + $this->image_reflection_space, true); + $transparency = $this->image_reflection_opacity; + + // copy the original image + imagecopy($tmp, $image_dst, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y + ($this->image_reflection_space < 0 ? $this->image_reflection_space : 0)); + + // we have to make sure the extra bit is the right color, or transparent + if ($image_reflection_height + $this->image_reflection_space > 0) { + // use the background color if present + if (!empty($this->image_background_color)) { + list($red, $green, $blue) = $this->getcolors($this->image_background_color); + $fill = imagecolorallocate($tmp, $red, $green, $blue); + } else { + $fill = imagecolorallocatealpha($tmp, 0, 0, 0, 127); + } + // fill in from the edge of the extra bit + imagefill($tmp, round($this->image_dst_x / 2), $this->image_dst_y + $image_reflection_height + $this->image_reflection_space - 1, $fill); + } + + // copy the reflection + for ($y = 0; $y < $image_reflection_height; $y++) { + for ($x = 0; $x < $this->image_dst_x; $x++) { + $pixel_b = imagecolorsforindex($tmp, imagecolorat($tmp, $x, $y + $this->image_dst_y + $this->image_reflection_space)); + $pixel_o = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $this->image_dst_y - $y - 1 + ($this->image_reflection_space < 0 ? $this->image_reflection_space : 0))); + $alpha_o = 1 - ($pixel_o['alpha'] / 127); + $alpha_b = 1 - ($pixel_b['alpha'] / 127); + $opacity = $alpha_o * $transparency / 100; + if ($opacity > 0) { + $red = round((($pixel_o['red'] * $opacity) + ($pixel_b['red'] ) * $alpha_b) / ($alpha_b + $opacity)); + $green = round((($pixel_o['green'] * $opacity) + ($pixel_b['green']) * $alpha_b) / ($alpha_b + $opacity)); + $blue = round((($pixel_o['blue'] * $opacity) + ($pixel_b['blue'] ) * $alpha_b) / ($alpha_b + $opacity)); + $alpha = ($opacity + $alpha_b); + if ($alpha > 1) $alpha = 1; + $alpha = round((1 - $alpha) * 127); + $color = imagecolorallocatealpha($tmp, $red, $green, $blue, $alpha); + imagesetpixel($tmp, $x, $y + $this->image_dst_y + $this->image_reflection_space, $color); + } + } + if ($transparency > 0) $transparency = $transparency - ($this->image_reflection_opacity / $image_reflection_height); + } + + // copy the resulting image into the destination image + $this->image_dst_y = $this->image_dst_y + $image_reflection_height + $this->image_reflection_space; + $image_dst = $this->imagetransfer($tmp, $image_dst); + } + + // reduce the JPEG image to a set desired size + if (is_numeric($this->jpeg_size) && $this->jpeg_size > 0 && ($this->image_convert == 'jpeg' || $this->image_convert == 'jpg')) { + // inspired by: JPEGReducer class version 1, 25 November 2004, Author: Huda M ElMatsani, justhuda at netscape dot net + $this->log .= '- JPEG desired file size : ' . $this->jpeg_size . '
'; + // calculate size of each image. 75%, 50%, and 25% quality + ob_start(); imagejpeg($image_dst,'',75); $buffer = ob_get_contents(); ob_end_clean(); + $size75 = strlen($buffer); + ob_start(); imagejpeg($image_dst,'',50); $buffer = ob_get_contents(); ob_end_clean(); + $size50 = strlen($buffer); + ob_start(); imagejpeg($image_dst,'',25); $buffer = ob_get_contents(); ob_end_clean(); + $size25 = strlen($buffer); + + // calculate gradient of size reduction by quality + $mgrad1 = 25 / ($size50-$size25); + $mgrad2 = 25 / ($size75-$size50); + $mgrad3 = 50 / ($size75-$size25); + $mgrad = ($mgrad1 + $mgrad2 + $mgrad3) / 3; + // result of approx. quality factor for expected size + $q_factor = round($mgrad * ($this->jpeg_size - $size50) + 50); + + if ($q_factor<1) { + $this->jpeg_quality=1; + } elseif ($q_factor>100) { + $this->jpeg_quality=100; + } else { + $this->jpeg_quality=$q_factor; + } + $this->log .= '    JPEG quality factor set to ' . $this->jpeg_quality . '
'; + } + + // converts image from true color, and fix transparency if needed + $this->log .= '- converting...
'; + switch($this->image_convert) { + case 'gif': + // if the image is true color, we convert it to a palette + if (imageistruecolor($image_dst)) { + $this->log .= '    true color to palette
'; + // creates a black and white mask + $mask = array(array()); + for ($x = 0; $x < $this->image_dst_x; $x++) { + for ($y = 0; $y < $this->image_dst_y; $y++) { + $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); + $mask[$x][$y] = $pixel['alpha']; + } + } + list($red, $green, $blue) = $this->getcolors($this->image_default_color); + // first, we merge the image with the background color, so we know which colors we will have + for ($x = 0; $x < $this->image_dst_x; $x++) { + for ($y = 0; $y < $this->image_dst_y; $y++) { + if ($mask[$x][$y] > 0){ + // we have some transparency. we combine the color with the default color + $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); + $alpha = ($mask[$x][$y] / 127); + $pixel['red'] = round(($pixel['red'] * (1 -$alpha) + $red * ($alpha))); + $pixel['green'] = round(($pixel['green'] * (1 -$alpha) + $green * ($alpha))); + $pixel['blue'] = round(($pixel['blue'] * (1 -$alpha) + $blue * ($alpha))); + $color = imagecolorallocate($image_dst, $pixel['red'], $pixel['green'], $pixel['blue']); + imagesetpixel($image_dst, $x, $y, $color); + } + } + } + // transfrom the true color image into palette, with it merged default color in + // we will have the best color possible, including the background + if (empty($this->image_background_color)) { + imagetruecolortopalette($image_dst, true, 255); + $transparency = imagecolorallocate($image_dst, 254, 1, 253); + imagecolortransparent($image_dst, $transparency); + // make the transparent areas transparent + for ($x = 0; $x < $this->image_dst_x; $x++) { + for ($y = 0; $y < $this->image_dst_y; $y++) { + // we test wether we have enough opacity to justify keeping the color + if ($mask[$x][$y] > 120) imagesetpixel($image_dst, $x, $y, $transparency); + } + } + } + unset($mask); + } + break; + case 'jpg': + case 'bmp': + // if the image doesn't support any transparency, then we merge it with the default color + $this->log .= '    fills in transparency with default color
'; + list($red, $green, $blue) = $this->getcolors($this->image_default_color); + $transparency = imagecolorallocate($image_dst, $red, $green, $blue); + // make the transaparent areas transparent + for ($x = 0; $x < $this->image_dst_x; $x++) { + for ($y = 0; $y < $this->image_dst_y; $y++) { + // we test wether we have some transparency, in which case we will merge the colors + if (imageistruecolor($image_dst)) { + $rgba = imagecolorat($image_dst, $x, $y); + $pixel = array('red' => ($rgba >> 16) & 0xFF, + 'green' => ($rgba >> 8) & 0xFF, + 'blue' => $rgba & 0xFF, + 'alpha' => ($rgba & 0x7F000000) >> 24); + } else { + $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); + } + if ($pixel['alpha'] == 127) { + // we have full transparency. we make the pixel transparent + imagesetpixel($image_dst, $x, $y, $transparency); + } else if ($pixel['alpha'] > 0) { + // we have some transparency. we combine the color with the default color + $alpha = ($pixel['alpha'] / 127); + $pixel['red'] = round(($pixel['red'] * (1 -$alpha) + $red * ($alpha))); + $pixel['green'] = round(($pixel['green'] * (1 -$alpha) + $green * ($alpha))); + $pixel['blue'] = round(($pixel['blue'] * (1 -$alpha) + $blue * ($alpha))); + $color = imagecolorclosest($image_dst, $pixel['red'], $pixel['green'], $pixel['blue']); + imagesetpixel($image_dst, $x, $y, $color); + } + } + } + + break; + default: + break; + } + + // outputs image + $this->log .= '- saving image...
'; + switch($this->image_convert) { + case 'jpeg': + case 'jpg': + if (!$return_mode) { + $result = @imagejpeg($image_dst, $this->file_dst_pathname, $this->jpeg_quality); + } else { + ob_start(); + $result = @imagejpeg($image_dst, '', $this->jpeg_quality); + $return_content = ob_get_contents(); + ob_end_clean(); + } + if (!$result) { + $this->processed = false; + $this->error = $this->translate('file_create', array('JPEG')); + } else { + $this->log .= '    JPEG image created
'; + } + break; + case 'png': + imagealphablending( $image_dst, false ); + imagesavealpha( $image_dst, true ); + if (!$return_mode) { + $result = @imagepng($image_dst, $this->file_dst_pathname); + } else { + ob_start(); + $result = @imagepng($image_dst); + $return_content = ob_get_contents(); + ob_end_clean(); + } + if (!$result) { + $this->processed = false; + $this->error = $this->translate('file_create', array('PNG')); + } else { + $this->log .= '    PNG image created
'; + } + break; + case 'gif': + if (!$return_mode) { + $result = @imagegif($image_dst, $this->file_dst_pathname); + } else { + ob_start(); + $result = @imagegif($image_dst); + $return_content = ob_get_contents(); + ob_end_clean(); + } + if (!$result) { + $this->processed = false; + $this->error = $this->translate('file_create', array('GIF')); + } else { + $this->log .= '    GIF image created
'; + } + break; + case 'bmp': + if (!$return_mode) { + $result = $this->imagebmp($image_dst, $this->file_dst_pathname); + } else { + ob_start(); + $result = $this->imagebmp($image_dst); + $return_content = ob_get_contents(); + ob_end_clean(); + } + if (!$result) { + $this->processed = false; + $this->error = $this->translate('file_create', array('BMP')); + } else { + $this->log .= '    BMP image created
'; + } + break; + + default: + $this->processed = false; + $this->error = $this->translate('no_conversion_type'); + } + if ($this->processed) { + if (is_resource($image_src)) imagedestroy($image_src); + if (is_resource($image_dst)) imagedestroy($image_dst); + $this->log .= '    image objects destroyed
'; + } + } + + } else { + $this->log .= '- no image processing wanted
'; + + if (!$return_mode) { + // copy the file to its final destination. we don't use move_uploaded_file here + // if we happen to have open_basedir restrictions, it is a temp file that we copy, not the original uploaded file + if (!copy($this->file_src_pathname, $this->file_dst_pathname)) { + $this->processed = false; + $this->error = $this->translate('copy_failed'); + } + } else { + // returns the file, so that its content can be received by the caller + $return_content = @file_get_contents($this->file_src_pathname); + if ($return_content === FALSE) { + $this->processed = false; + $this->error = $this->translate('reading_failed'); + } + } + } + } + + if ($this->processed) { + $this->log .= '- process OK
'; + } else { + $this->log .= '- error: ' . $this->error . '
'; + } + + // we reinit all the vars + $this->init(); + + // we may return the image content + if ($return_mode) return $return_content; + + } + + /** + * Deletes the uploaded file from its temporary location + * + * When PHP uploads a file, it stores it in a temporary location. + * When you {@link process} the file, you actually copy the resulting file to the given location, it doesn't alter the original file. + * Once you have processed the file as many times as you wanted, you can delete the uploaded file. + * If there is open_basedir restrictions, the uploaded file is in fact a temporary file + * + * You might want not to use this function if you work on local files, as it will delete the source file + * + * @access public + */ + function clean() { + $this->log .= 'cleanup
'; + $this->log .= '- delete temp file ' . $this->file_src_pathname . '
'; + @unlink($this->file_src_pathname); + } + + + /** + * Opens a BMP image + * + * This function has been written by DHKold, and is used with permission of the author + * + * @access public + */ + function imagecreatefrombmp($filename) { + if (! $f1 = fopen($filename,"rb")) return false; + + $file = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1,14)); + if ($file['file_type'] != 19778) return false; + + $bmp = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'. + '/Vcompression/Vsize_bitmap/Vhoriz_resolution'. + '/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1,40)); + $bmp['colors'] = pow(2,$bmp['bits_per_pixel']); + if ($bmp['size_bitmap'] == 0) $bmp['size_bitmap'] = $file['file_size'] - $file['bitmap_offset']; + $bmp['bytes_per_pixel'] = $bmp['bits_per_pixel']/8; + $bmp['bytes_per_pixel2'] = ceil($bmp['bytes_per_pixel']); + $bmp['decal'] = ($bmp['width']*$bmp['bytes_per_pixel']/4); + $bmp['decal'] -= floor($bmp['width']*$bmp['bytes_per_pixel']/4); + $bmp['decal'] = 4-(4*$bmp['decal']); + if ($bmp['decal'] == 4) $bmp['decal'] = 0; + + $palette = array(); + if ($bmp['colors'] < 16777216) { + $palette = unpack('V'.$bmp['colors'], fread($f1,$bmp['colors']*4)); + } + + $im = fread($f1,$bmp['size_bitmap']); + $vide = chr(0); + + $res = imagecreatetruecolor($bmp['width'],$bmp['height']); + $P = 0; + $Y = $bmp['height']-1; + while ($Y >= 0) { + $X=0; + while ($X < $bmp['width']) { + if ($bmp['bits_per_pixel'] == 24) + $color = unpack("V",substr($im,$P,3).$vide); + elseif ($bmp['bits_per_pixel'] == 16) { + $color = unpack("n",substr($im,$P,2)); + $color[1] = $palette[$color[1]+1]; + } elseif ($bmp['bits_per_pixel'] == 8) { + $color = unpack("n",$vide.substr($im,$P,1)); + $color[1] = $palette[$color[1]+1]; + } elseif ($bmp['bits_per_pixel'] == 4) { + $color = unpack("n",$vide.substr($im,floor($P),1)); + if (($P*2)%2 == 0) $color[1] = ($color[1] >> 4) ; else $color[1] = ($color[1] & 0x0F); + $color[1] = $palette[$color[1]+1]; + } elseif ($bmp['bits_per_pixel'] == 1) { + $color = unpack("n",$vide.substr($im,floor($P),1)); + if (($P*8)%8 == 0) $color[1] = $color[1] >>7; + elseif (($P*8)%8 == 1) $color[1] = ($color[1] & 0x40)>>6; + elseif (($P*8)%8 == 2) $color[1] = ($color[1] & 0x20)>>5; + elseif (($P*8)%8 == 3) $color[1] = ($color[1] & 0x10)>>4; + elseif (($P*8)%8 == 4) $color[1] = ($color[1] & 0x8)>>3; + elseif (($P*8)%8 == 5) $color[1] = ($color[1] & 0x4)>>2; + elseif (($P*8)%8 == 6) $color[1] = ($color[1] & 0x2)>>1; + elseif (($P*8)%8 == 7) $color[1] = ($color[1] & 0x1); + $color[1] = $palette[$color[1]+1]; + } else + return FALSE; + imagesetpixel($res,$X,$Y,$color[1]); + $X++; + $P += $bmp['bytes_per_pixel']; + } + $Y--; + $P+=$bmp['decal']; + } + fclose($f1); + return $res; + } + + /** + * Saves a BMP image + * + * This function has been published on the PHP website, and can be used freely + * + * @access public + */ + function imagebmp(&$im, $filename = "") { + + if (!$im) return false; + $w = imagesx($im); + $h = imagesy($im); + $result = ''; + + // if the image is not true color, we convert it first + if (!imageistruecolor($im)) { + $tmp = imagecreatetruecolor($w, $h); + imagecopy($tmp, $im, 0, 0, 0, 0, $w, $h); + imagedestroy($im); + $im = & $tmp; + } + + $biBPLine = $w * 3; + $biStride = ($biBPLine + 3) & ~3; + $biSizeImage = $biStride * $h; + $bfOffBits = 54; + $bfSize = $bfOffBits + $biSizeImage; + + $result .= substr('BM', 0, 2); + $result .= pack ('VvvV', $bfSize, 0, 0, $bfOffBits); + $result .= pack ('VVVvvVVVVVV', 40, $w, $h, 1, 24, 0, $biSizeImage, 0, 0, 0, 0); + + $numpad = $biStride - $biBPLine; + for ($y = $h - 1; $y >= 0; --$y) { + for ($x = 0; $x < $w; ++$x) { + $col = imagecolorat ($im, $x, $y); + $result .= substr(pack ('V', $col), 0, 3); + } + for ($i = 0; $i < $numpad; ++$i) + $result .= pack ('C', 0); + } + + if($filename==""){ + echo $result; + } else { + $file = fopen($filename, "wb"); + fwrite($file, $result); + fclose($file); + } + return true; + } +} + diff --git a/public/.htaccess b/public/.htaccess index f9567cf..0b3ece8 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -1,4 +1,7 @@ RewriteEngine On + +RewriteBase / + RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d diff --git a/public/file/Diplomarbeit-Kinga-Pannek-2012.pdf b/public/file/Diplomarbeit-Kinga-Pannek-2012.pdf new file mode 100644 index 0000000..3034b6b Binary files /dev/null and b/public/file/Diplomarbeit-Kinga-Pannek-2012.pdf differ diff --git a/public/file/Patientenfragebogen.pdf b/public/file/Patientenfragebogen.pdf new file mode 100644 index 0000000..e7bb7b9 Binary files /dev/null and b/public/file/Patientenfragebogen.pdf differ diff --git a/public/img/facebook-icon.png b/public/img/facebook-icon.png new file mode 100644 index 0000000..57b13b5 Binary files /dev/null and b/public/img/facebook-icon.png differ diff --git a/public/img/header/1374074370.jpg b/public/img/header/1374074370.jpg new file mode 100644 index 0000000..6fa45ca Binary files /dev/null and b/public/img/header/1374074370.jpg differ diff --git a/public/img/header/1374140846.jpg b/public/img/header/1374140846.jpg new file mode 100644 index 0000000..bfb9f46 Binary files /dev/null and b/public/img/header/1374140846.jpg differ diff --git a/public/img/header/1374149063.jpg b/public/img/header/1374149063.jpg new file mode 100644 index 0000000..e95ac88 Binary files /dev/null and b/public/img/header/1374149063.jpg differ diff --git a/public/img/header/1374149247.jpg b/public/img/header/1374149247.jpg new file mode 100644 index 0000000..bdf7f2e Binary files /dev/null and b/public/img/header/1374149247.jpg differ diff --git a/public/img/header/1374156504.jpg b/public/img/header/1374156504.jpg new file mode 100644 index 0000000..bc37510 Binary files /dev/null and b/public/img/header/1374156504.jpg differ diff --git a/public/img/header/1374229998.jpg b/public/img/header/1374229998.jpg new file mode 100644 index 0000000..affe33e Binary files /dev/null and b/public/img/header/1374229998.jpg differ diff --git a/public/img/header/1374237882.jpg b/public/img/header/1374237882.jpg new file mode 100644 index 0000000..907dfa8 Binary files /dev/null and b/public/img/header/1374237882.jpg differ diff --git a/public/img/header/1374240086.jpg b/public/img/header/1374240086.jpg new file mode 100644 index 0000000..236bb0c Binary files /dev/null and b/public/img/header/1374240086.jpg differ diff --git a/public/img/header/1374241138.jpg b/public/img/header/1374241138.jpg new file mode 100755 index 0000000..0714912 Binary files /dev/null and b/public/img/header/1374241138.jpg differ diff --git a/public/img/header/AR8R8476.JPG b/public/img/header/AR8R8476.JPG new file mode 100644 index 0000000..c9808be Binary files /dev/null and b/public/img/header/AR8R8476.JPG differ diff --git a/public/img/leafs/addSub.png b/public/img/leafs/addSub.png new file mode 100755 index 0000000..a56c2e3 Binary files /dev/null and b/public/img/leafs/addSub.png differ diff --git a/public/img/leafs/arrow_down.png b/public/img/leafs/arrow_down.png new file mode 100755 index 0000000..f3dd188 Binary files /dev/null and b/public/img/leafs/arrow_down.png differ diff --git a/public/img/leafs/arrow_up.png b/public/img/leafs/arrow_up.png new file mode 100755 index 0000000..e1f6430 Binary files /dev/null and b/public/img/leafs/arrow_up.png differ diff --git a/public/img/leafs/change.png b/public/img/leafs/change.png new file mode 100755 index 0000000..846eaa2 Binary files /dev/null and b/public/img/leafs/change.png differ diff --git a/public/img/leafs/delete.png b/public/img/leafs/delete.png new file mode 100755 index 0000000..3eda143 Binary files /dev/null and b/public/img/leafs/delete.png differ diff --git a/public/img/leafs/preview.png b/public/img/leafs/preview.png new file mode 100755 index 0000000..ced57a5 Binary files /dev/null and b/public/img/leafs/preview.png differ diff --git a/public/img/logo-old.png b/public/img/logo-old.png new file mode 100644 index 0000000..26f01b7 Binary files /dev/null and b/public/img/logo-old.png differ diff --git a/public/img/logo.png b/public/img/logo.png new file mode 100644 index 0000000..2d2355b Binary files /dev/null and b/public/img/logo.png differ diff --git a/public/img/page/1374073671.jpg b/public/img/page/1374073671.jpg new file mode 100644 index 0000000..d7bd28b Binary files /dev/null and b/public/img/page/1374073671.jpg differ diff --git a/public/img/page/1374149150.jpg b/public/img/page/1374149150.jpg new file mode 100644 index 0000000..c7faf5b Binary files /dev/null and b/public/img/page/1374149150.jpg differ diff --git a/public/img/page/1374149151.png b/public/img/page/1374149151.png new file mode 100644 index 0000000..2bca0ca Binary files /dev/null and b/public/img/page/1374149151.png differ diff --git a/public/img/page/1374149159.jpg b/public/img/page/1374149159.jpg new file mode 100644 index 0000000..e0b5451 Binary files /dev/null and b/public/img/page/1374149159.jpg differ diff --git a/public/img/page/1374156604.jpg b/public/img/page/1374156604.jpg new file mode 100644 index 0000000..73b7348 Binary files /dev/null and b/public/img/page/1374156604.jpg differ diff --git a/public/img/page/1374156883.jpg b/public/img/page/1374156883.jpg new file mode 100644 index 0000000..066b65a Binary files /dev/null and b/public/img/page/1374156883.jpg differ diff --git a/public/img/page/1374157302.jpg b/public/img/page/1374157302.jpg new file mode 100644 index 0000000..e2dfd9c Binary files /dev/null and b/public/img/page/1374157302.jpg differ diff --git a/public/img/page/1374158662.jpg b/public/img/page/1374158662.jpg new file mode 100644 index 0000000..f580d10 Binary files /dev/null and b/public/img/page/1374158662.jpg differ diff --git a/public/img/page/1374159021.jpg b/public/img/page/1374159021.jpg new file mode 100644 index 0000000..c181494 Binary files /dev/null and b/public/img/page/1374159021.jpg differ diff --git a/public/img/page/1374224328.jpg b/public/img/page/1374224328.jpg new file mode 100644 index 0000000..84b0b26 Binary files /dev/null and b/public/img/page/1374224328.jpg differ diff --git a/public/img/page/1374224564.jpg b/public/img/page/1374224564.jpg new file mode 100644 index 0000000..cfc6a5e Binary files /dev/null and b/public/img/page/1374224564.jpg differ diff --git a/public/img/page/1374224707.jpg b/public/img/page/1374224707.jpg new file mode 100644 index 0000000..b6e60fc Binary files /dev/null and b/public/img/page/1374224707.jpg differ diff --git a/public/img/page/1374225773.png b/public/img/page/1374225773.png new file mode 100644 index 0000000..91ed8e9 Binary files /dev/null and b/public/img/page/1374225773.png differ diff --git a/public/img/page/1374233305.jpg b/public/img/page/1374233305.jpg new file mode 100644 index 0000000..41cdf55 Binary files /dev/null and b/public/img/page/1374233305.jpg differ diff --git a/public/img/page/1374235846.jpg b/public/img/page/1374235846.jpg new file mode 100644 index 0000000..d365f7a Binary files /dev/null and b/public/img/page/1374235846.jpg differ diff --git a/public/img/page/1374247043.png b/public/img/page/1374247043.png new file mode 100644 index 0000000..5842cdf Binary files /dev/null and b/public/img/page/1374247043.png differ diff --git a/public/index.php b/public/index.php index ce66f02..c4ce697 100644 --- a/public/index.php +++ b/public/index.php @@ -12,15 +12,25 @@ chdir('..'); require_once('library/Katharsis/Bootstrap.php'); Katharsis_Autoload::init(); +Katharsis_Controller_Plugin::registerPlugin(new DidgeridooArtwork_Controller_Plugin_Defaults()); +Katharsis_Controller_Plugin::registerPlugin(new Local_Controller_Plugin_IndexRedirect()); +Katharsis_Controller_Plugin::registerPlugin(new Local_Controller_Plugin_PageRewrite()); +Katharsis_Controller_Plugin::registerPlugin(new DidgeridooArtwork_Controller_Plugin_SetNames()); +Katharsis_Controller_Plugin::registerPlugin(new Katharsis_Controller_Plugin_StartSession()); +Katharsis_Controller_Plugin::registerPlugin(new DidgeridooArtwork_Controller_Plugin_Notice()); Katharsis_Controller_Plugin::registerPlugin(new Katharsis_Controller_Plugin_Autorender()); +Katharsis_Controller_Plugin::registerPlugin(new DidgeridooArtwork_Controller_Plugin_Access()); +Katharsis_Controller_Plugin::registerPlugin(new DidgeridooArtwork_Controller_Plugin_Navigation()); try { + Katharsis_Bootstrap::init(); Katharsis_Bootstrap::run(); } catch(Exception $e) { + http_response_code(500); echo '

Exception thrown

'; echo '

' . $e->getMessage() . '

'; echo '
';
 	print_r($e);
-}
\ No newline at end of file
+}
diff --git a/public/lib/codemirror b/public/lib/codemirror
new file mode 160000
index 0000000..b05b96e
--- /dev/null
+++ b/public/lib/codemirror
@@ -0,0 +1 @@
+Subproject commit b05b96e0306d3b33b8a7810884a0d1cfb7b42969
diff --git a/public/script/admin.js b/public/script/admin.js
new file mode 100644
index 0000000..5fe8b47
--- /dev/null
+++ b/public/script/admin.js
@@ -0,0 +1,11 @@
+
+function adminPageInsertImage(type, img) {
+	if(type == 'header') {
+		opener.document.forms[0].header_image.value = img;
+	} else {
+		var editor = opener.myCodeMirror;
+		var img = '';
+		var pos = editor.getCursor();
+		editor.replaceRange(img, pos);
+	}
+}
\ No newline at end of file
diff --git a/public/style/admin.css b/public/style/admin.css
new file mode 100644
index 0000000..96d96e5
--- /dev/null
+++ b/public/style/admin.css
@@ -0,0 +1,157 @@
+body.admin footer {
+    margin-bottom: 4em;
+}
+
+#adminNavigation {
+        background: #90CB93;
+        position: fixed;
+        bottom: 0;
+        left: 0;
+        list-style-type: none;
+        margin: 0;
+        padding: 0 70px;
+        width: 100%;
+        -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
+        -moz-box-sizing: border-box;    /* Firefox, other Gecko */
+        box-sizing: border-box;         /* Opera/IE 8+ */
+        box-shadow: 0 0 10px rgba(0,0,0,0.5);
+        border-top: 1px solid #85c188;
+        z-index: 2;
+}
+
+#adminNavigation li {
+        display: inline-block;
+        margin: -1px 0 0 0;
+        padding: 0;
+}
+
+#adminNavigation li:first-child {
+    padding-right: 1em;
+}
+
+#adminNavigation li:last-child {
+    float: right;
+}
+
+#adminNavigation a {
+        color: white;
+        background: #416843;
+        padding: 1em 2em;
+        text-decoration: none;
+        display: inline-block;
+}
+
+#adminNavigation a:hover {
+    background: #216849;
+}
+
+#admin dd {
+        font-size: 1em;
+        line-height: 1.6em;
+}
+
+label {
+        padding: 3px;
+}
+
+.textfield {
+        width: 300px;
+}
+
+input, textarea {
+        border: 1px solid #4F100A;
+        padding: 2px;
+}
+
+textarea {
+    width: 90% !important;
+    -webkit-box-sizing: border-box;
+    -moz-box-sizing: border-box;
+    box-sizing: border-box;
+}
+
+.admin textarea {
+    font-family: monospace;
+}
+
+#admin dl {
+        margin: 15px 0;
+}
+
+#admin dt {
+        font-weight: bold;
+        float: left;
+        width: 40px;
+}
+
+#admin dd {
+        position: relative;
+        left: 75px;
+        padding: 0 10px;
+}
+
+.right {
+        float: right;
+}
+
+table {
+        border-collapse: collapse;
+        font-size: 1em;
+        background-color: #274729;
+}
+
+td, th {
+        border: 1px solid #000;
+        padding: 5px;
+        color: #dfbe9d;
+        vertical-align: top;
+}
+
+th, thead td{
+        background-color: #416843;
+        font-weight: bold;
+        text-align: left;
+        color: #f1d6bc;
+        border-style: solid;
+}
+
+.unsichtbare_tabelle, .unsichtbare_tabelle tr, .unsichtbare_tabelle tbody, .unsichtbare_tabelle td, .unsichtbare_tabelle th {
+        background-color: transparent;
+        border: 0;
+        color: white;
+}
+
+textarea {
+        font-family: arial;
+        font-size: 1em;
+        width: 650px;
+        height: 350px;
+}
+
+#admin .sub td:nth-child(2),
+#admin .sub td:nth-child(3),
+#admin .sub td:nth-child(4),
+#admin .sub td:nth-child(5) {
+    text-indent: 30px;
+}
+
+.notices {
+    list-style-type: none;
+    margin: 0 0 15px 0;
+    padding: 0;
+}
+
+.notices li
+{
+        border: 1px solid #FFD40F;
+        background-color: #FFE9AF;
+        color: #6F3C00;
+        padding: 5px;
+        margin: 0;
+}
+
+.CodeMirror {
+    width: 90%;
+    border: 1px dotted gray;
+    background-color: #f0f0f0 !important;
+}
\ No newline at end of file
diff --git a/public/style/main.css b/public/style/main.css
index e69de29..b29504e 100644
--- a/public/style/main.css
+++ b/public/style/main.css
@@ -0,0 +1,274 @@
+@import url(http://fonts.googleapis.com/css?family=Raleway:400,300,200);
+
+html, body {
+    min-height: 100%;
+}
+
+body {
+	background: white;
+	font-family: "Trebuchet MS", "Lucida Grande", verdana, sans-serif;
+	font-size: 0.9em;
+	margin: 0;
+	padding: 20px 10%;
+    line-height: 1.4;
+    color: #3d3f3f;
+}
+
+a {
+    color: #2877A2;
+}
+
+h1 {
+    margin: -0.1em 0 0 0;
+    font-weight: 300;
+    font-size: 3em;
+    font-family: Raleway, sans-serif;
+}
+
+h1 + h2 {
+    margin: 0 0 2em 0;
+    font-size: 1em;
+}
+
+h3 {
+    font-weight: normal;
+}
+
+h2 {
+    margin-bottom: 0;
+    font-weight: 400;
+    font-family: Raleway, sans-serif;
+}
+
+h2 + h3 {
+    margin-top: 0;
+    font-weight: bold;
+}
+
+img { max-width: 100%; }
+
+ul {
+    padding-left: 1.5em;
+    margin-left: 0;
+}
+
+#container {
+	min-width: 750px;
+	max-width: 1100px;
+	position:relative;
+	min-height:100%;
+	height:auto !important;
+	height:100%;
+	margin:0 auto;
+	background-color: white;
+}
+
+#logo {
+    float: left;
+}
+
+#logo img {
+    width: 400px;
+} 
+
+#navi {
+    margin-top: 80px;
+    float: right;
+	list-style-type: none;
+    text-align: center;
+}
+
+#navi > li {
+    display: inline-block;
+    position: relative;
+}
+
+#navi a {
+	color: black;
+	padding: 0.5em 0.7em;
+    text-decoration: none;
+    background: #90cb93;
+    color: white;
+}
+
+#navi li:hover a {
+    background: #59af5e;
+}
+
+#navi ul {
+    display: none;
+    position: absolute;
+    text-align: left;
+    list-style-type: none;
+    margin-left: 0;
+    padding-left: 0;
+    top: 1.7em;
+    z-index: 2;
+}
+
+#navi ul li {
+    border-top: 1px solid #91c993;
+}
+
+#navi ul li:first-child {
+    /*border-top: 0;*/
+}
+
+
+#navi li:hover ul a {
+    display: block;
+    background: #4b934f;
+    background: rgba(75, 147, 79, 0.8);
+}
+
+#navi li:hover ul a:hover {
+    background: #90cb93;
+}
+
+#navi > li:hover ul {
+    display: block;
+}
+
+#navi > li:last-child ul {
+    right: 0;
+    border: red;
+}
+
+#stage {
+    clear: both;
+    border-top: 5px solid #90cb93;
+	padding: 2.5em 0 1.5em 0;
+    line-height: 1.7;
+}
+
+.col1:before, .col1:after,
+.col2:before, .col2:after,
+.col3:before, .col3:after,
+.col4:before, .col4:after,
+#stage:before, #stage:after {
+    content: "";
+    display: table;
+}
+
+.col1:after, .col2:after, .col3:after, .col4:after,
+#stage:after {
+    clear: both;
+}
+
+#header_image {
+    vertical-align: middle;
+    display: block;
+    margin-bottom: 2em;
+}
+
+#stage small {
+    color: #616363;
+    line-height: 1.4;
+    display: block;
+}
+
+p.diagramm {
+    text-align: center;
+    margin: 4em 0;
+}
+
+#stage p.diagramm img {
+    float: none;
+}
+
+#stage h2 + p {
+    margin-top: 0.5em;
+}
+
+footer {
+    clear: both;
+    border-top: 5px solid #90CB93;
+    color: #616363;
+}
+
+footer #social {
+    float: right;
+    margin-top: 10px;
+}
+
+.col1, .col2, .col3, .col4 { clear: both; margin-bottom: 1.5em; padding-top: 2em; }
+.col1.line, .col2.line, .col3.line, .col4.line { border-top: 5px solid #90CB93; }
+.col:not(.box) > *:first-child { margin-top: 0; padding-top: 0; }
+.col:not(.box) > h2:first-child { margin-top: -0.25em; }
+
+.col {
+    -webkit-box-sizing: border-box;
+    -moz-box-sizing: border-box;
+    box-sizing: border-box;
+}
+
+div .col:last-child { margin-right: 0; }
+
+.col2 .col {
+    width: 48%;
+    float: left;
+    margin-right: 4%;
+}
+
+.col2.left .col:first-child { width: 31.5%; }
+.col2.left .col:last-child { width: 64.5%; }
+.col2.right .col:first-child { width: 64.5%; }
+.col2.right .col:last-child { width: 31.5%; }
+
+.col3 .col {
+    width: 32%;
+    float: left;
+    margin-right: 2%;
+}
+
+.col4 .col {
+    width: 24%;
+    float: left;
+    margin-right: 1.3%;
+}
+
+.col4 h2 {
+    font-size: 1em;
+    padding: 0.2em 1em;
+}
+
+
+
+.box {
+    vertical-align: top;
+}
+
+.box .content {
+    padding: 0.5em 1em;
+    background: #f5f5f5;
+}
+
+.box h2 {
+    background: #90CB93;
+    color: white;
+    font-size: 1.1em;
+    padding: 0.5em 1em;
+    margin: 0;
+    text-align: center;
+    font-family: "Trebuchet MS", "Lucida Grande", verdana, sans-serif;
+}
+
+.box h2 a {
+    text-decoration: none;
+    color: white;
+    display: block;
+}
+
+.box img {
+    vertical-align: middle;
+}
+
+.box.cite h2 {
+    background: #216f85;
+}
+
+.border {
+    border: 1px solid #ccc;
+    padding: 10px;
+    background: white;
+} 
\ No newline at end of file
diff --git a/public/style/popup.css b/public/style/popup.css
new file mode 100644
index 0000000..7dc3106
--- /dev/null
+++ b/public/style/popup.css
@@ -0,0 +1,8 @@
+body { font-family: sans-serif; background: white; color: black; }
+h1 { color: white; background: #CB3829; padding: 0.3em; font-size: 1em; }
+img { max-width: 200px; }
+a { text-decoration: none; color: #2877A2; }
+
+table { width: 100%; }
+tr td:last-child {text-align: right; }
+tr td:last-child a { color: red; }
\ No newline at end of file