From 2e07b08016cf4172cf74cd1cb181e850dcb71451 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 9 Jul 2014 13:04:56 +1000 Subject: [PATCH] Initial Photo Work --- .htaccess | 9 +- application/bootstrap.php | 23 +- application/classes/Config.php | 67 +---- application/classes/Controller/Photo.php | 185 ++++++++++++ application/classes/Controller/Translate.php | 218 -------------- application/classes/Controller/Welcome.php | 2 +- application/classes/Cookie.php | 4 +- application/classes/Model/Album.php | 14 + application/classes/Model/Language.php | 30 -- application/classes/Model/Original.php | 28 -- application/classes/Model/People.php | 17 ++ application/classes/Model/Photo.php | 168 +++++++++++ application/classes/Model/Translate.php | 30 -- application/classes/ORM/OSB.php | 287 ------------------- application/classes/Task/Photo/Import.php | 75 +++++ application/config/config.php | 6 + application/config/database.php | 8 +- application/config/mainnav.php | 16 ++ application/views/pages/navbar.php | 0 application/views/theme/baseadmin/page.php | 130 --------- application/views/translate.php | 33 --- includes/kohana | 2 +- modules/lnApp | 2 +- 23 files changed, 508 insertions(+), 846 deletions(-) create mode 100644 application/classes/Controller/Photo.php delete mode 100644 application/classes/Controller/Translate.php create mode 100644 application/classes/Model/Album.php delete mode 100644 application/classes/Model/Language.php delete mode 100644 application/classes/Model/Original.php create mode 100644 application/classes/Model/People.php create mode 100644 application/classes/Model/Photo.php delete mode 100644 application/classes/Model/Translate.php delete mode 100644 application/classes/ORM/OSB.php create mode 100644 application/classes/Task/Photo/Import.php create mode 100644 application/config/config.php create mode 100644 application/config/mainnav.php delete mode 100644 application/views/pages/navbar.php delete mode 100644 application/views/theme/baseadmin/page.php delete mode 100644 application/views/translate.php diff --git a/.htaccess b/.htaccess index aa2b575..53b8ccb 100644 --- a/.htaccess +++ b/.htaccess @@ -2,7 +2,7 @@ RewriteEngine On # Installation directory -RewriteBase /aer +RewriteBase / # Protect hidden files from being viewed @@ -19,10 +19,3 @@ RewriteCond %{REQUEST_FILENAME} !-d # Rewrite all other URLs to index.php/URL RewriteRule .* index.php/$0 [PT] - -AuthType Basic -AuthName "Restricted !" -# (Following line optional) -AuthBasicProvider file -AuthUserFile /local/WEB/sites/net.leenooks.dev/aer/.htuser -Require valid-user diff --git a/application/bootstrap.php b/application/bootstrap.php index 1874298..eb0f572 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -69,6 +69,12 @@ I18n::lang('en-us'); * Note: If you supply an invalid environment name, a PHP warning will be thrown * saying "Couldn't find constant Kohana::" */ + +/** + * Set the environment status by the domain. + */ +Kohana::$environment = (isset($_SERVER['SERVER_NAME']) AND ($_SERVER['SERVER_NAME'] === 'photo.leenooks.vpn')) ? Kohana::PRODUCTION : Kohana::DEVELOPMENT; + if (isset($_SERVER['KOHANA_ENV'])) { Kohana::$environment = constant('Kohana::'.strtoupper($_SERVER['KOHANA_ENV'])); @@ -90,9 +96,10 @@ if (isset($_SERVER['KOHANA_ENV'])) * - boolean expose set the X-Powered-By header FALSE */ Kohana::init(array( - 'base_url' => '/aer', - 'caching' => TRUE, - 'index_file' => '', + 'base_url' => Kohana::$environment === Kohana::PRODUCTION ? '/' : '/', + 'caching' => Kohana::$environment === Kohana::PRODUCTION, + 'profile' => Kohana::$environment !== Kohana::PRODUCTION, + 'index_file' => FALSE, )); /** @@ -111,8 +118,8 @@ Kohana::$config->attach(new Config_File); Kohana::modules(array( 'lnapp' => MODPATH.'lnApp', // lnApp Base Application Tools // 'oauth' => MODPATH.'oauth', // OAuth Module for External Authentication - 'auth' => SMDPATH.'auth', // Basic authentication - 'cache' => SMDPATH.'cache', // Caching with multiple backends + // 'auth' => SMDPATH.'auth', // Basic authentication + // 'cache' => SMDPATH.'cache', // Caching with multiple backends // 'cron' => SMDPATH.'cron', // Kohana Cron Module // 'codebench' => SMDPATH.'codebench', // Benchmarking tool 'database' => SMDPATH.'database', // Database access @@ -120,12 +127,12 @@ Kohana::modules(array( // 'highchart' => MODPATH.'highchart', // Highcharts Chart Module // 'image' => SMDPATH.'image', // Image manipulation // 'khemail' => SMDPATH.'khemail', // Email module for Kohana 3 PHP Framework - // 'minion' => SMDPATH.'minion', // CLI Tasks + 'minion' => SMDPATH.'minion', // CLI Tasks 'orm' => SMDPATH.'orm', // Object Relationship Mapping - 'pagination' => SMDPATH.'pagination', // Kohana Pagination module for Kohana 3 PHP Framework + // 'pagination' => SMDPATH.'pagination', // Kohana Pagination module for Kohana 3 PHP Framework // 'unittest' => SMDPATH.'unittest', // Unit testing // 'userguide' => SMDPATH.'userguide', // User guide and API documentation - 'xml' => SMDPATH.'xml', // XML module for Kohana 3 PHP Framework + // 'xml' => SMDPATH.'xml', // XML module for Kohana 3 PHP Framework )); /** diff --git a/application/classes/Config.php b/application/classes/Config.php index abab2cb..989e54b 100644 --- a/application/classes/Config.php +++ b/application/classes/Config.php @@ -4,16 +4,13 @@ * This class extends the core Kohana class by adding some core application * specific functions, and configuration. * - * @package WWZ + * @package Photo * @category Helpers * @author Deon George * @copyright (c) 2014 Deon George * @license http://dev.leenooks.net/license.html */ class Config extends Kohana_Config { - // Our default logo, if there is no site logo - public static $logo = 'img/logo-small.png'; - /** * Some early initialisation * @@ -41,70 +38,10 @@ class Config extends Kohana_Config { return Config::$_instance; } - /** - * Return our caching mechanism - */ - public static function cachetype() { - return is_null(Kohana::$config->load('config')->cache_type) ? 'file' : Kohana::$config->load('config')->cache_type; - } - - public static function copywrite() { + public static function Copywrite() { return '(c) 2014 Deon George'; } - public static function country() { - return NULL; - } - - /** - * Show a date using a site configured format - */ - public static function date($date) { - return (is_null($date) OR ! $date) ? '' : date('d-M-Y',$date); - } - - public static function language() { - // @todo To implement - return 'auto'; - } - - /** - * The URI to show for the login prompt. - * Normally if the user is logged in, we can replace it with something else - */ - public static function login_uri() { - return ($ao = Auth::instance()->get_user() AND is_object($ao)) ? $ao->name() : HTML::anchor('login',_('Login')); - } - - public static function logo() { - return HTML::image(static::logo_uri(),array('class'=>'headlogo','alt'=>_('Logo'))); - } - - public static function logo_uri($protocol=NULL) { - list ($path,$suffix) = explode('.',static::$logo); - - return URL::site(Route::get('default/media')->uri(array('file'=>$path.'.'.$suffix),array('alt'=>static::sitename())),$protocol); - } - - public static function siteid($format=FALSE) { - return ''; - } - - /** - * Work out our site mode (dev,test,prod) - */ - public static function sitemode() { - return Kohana::$config->load('config.site')->mode; - } - - public static function sitename() { - return 'AER Translate'; - } - - public static function theme() { - return 'theme/'.Kohana::$config->load('config')->theme; - } - public static function version() { // @todo Work out our versioning return 'TBA'; diff --git a/application/classes/Controller/Photo.php b/application/classes/Controller/Photo.php new file mode 100644 index 0000000..9492600 --- /dev/null +++ b/application/classes/Controller/Photo.php @@ -0,0 +1,185 @@ +request->param('id')); + if (! $po->loaded()) + HTTP::redirect('index'); + + Block::factory() + ->title('Details for Photo:'.$po->id) + ->body(Debug::vars($po->info())); + } + + public function action_duplicate() { + $output = ''; + + // Update the current posted photos. + if ($this->request->post()) + foreach ($this->request->post('process') as $pid) { + $po = ORM::factory('Photo',$pid); + + $po->duplicate = Arr::get($this->request->post('duplicate'),$pid); + $po->delete = Arr::get($this->request->post('delete'),$pid); + $po->flag = Arr::get($this->request->post('flag'),$pid); + + $po->save(); + } + + $p = ORM::factory('Photo'); + + if ($x=$this->request->param('id')) + $p->where('id','=',$x); + + else + $p->where('duplicate','=',TRUE) + ->where_open() + ->where('delete','!=',TRUE) + ->or_where('delete','is',NULL) + ->where_close(); + + $output .= Form::open(sprintf('%s/%s',strtolower($this->request->controller()),$this->request->action())); + + foreach ($p->find_all() as $po) { + $dp = $po->duplicate_find()->find_all(); + + // Check that there are still duplicates + if ($dp->count() == 0) { + $po->duplicate = NULL; + $po->save(); + continue; + } + + $output .= Form::hidden('process[]',$po->id); + foreach ($dp as $dpo) + $output .= Form::hidden('process[]',$dpo->id); + + $output .= ''; + + foreach (array( + 'ID'=>array('key'=>'id','value'=>HTML::anchor('/photo/details/%VALUE%','%VALUE%')), + 'Thumbnail'=>array('key'=>'id','value'=>HTML::anchor('/photo/view/%VALUE%',HTML::image('photo/thumbnail/%VALUE%'))), + 'Signature'=>array('key'=>'signature'), + 'Date Taken'=>array('key'=>'date_taken()'), + 'Filename'=>array('key'=>'filename'), + 'Proposed Name'=>array('key'=>'path()'), + 'Width'=>array('key'=>'width'), + 'Height'=>array('key'=>'height'), + 'Orientation'=>array('key'=>'orientation'), + 'Make'=>array('key'=>'make'), + 'Model'=>array('key'=>'model'), + ) as $k=>$v) + $output .= $this->table_duplicate_details($dp,$po,$v['key'],$k,Arr::get($v,'value','%VALUE%')); + + foreach (array( + 'Flag'=>array('key'=>'id','value'=>'flag'), + 'Duplicate'=>array('key'=>'id','value'=>'duplicate'), + 'Delete'=>array('key'=>'id','value'=>'delete'), + ) as $k=>$v) + $output .= $this->table_duplicate_checkbox($dp,$po,$v['key'],$k,Arr::get($v,'value','%VALUE%')); + + $output .= '
'; + + break; + } + + $output .= '
'; + $output .= '
'; + $output .= ''; + $output .= ''; + $output .= '
'; + $output .= '
'; + + $output .= Form::close(); + + Block::factory() + ->title('Duplicate Photo:'.$po->id) + ->title_icon('icon-edit') + ->body($output); + } + + public function action_thumbnail() { + // Get the file path from the request + $po = ORM::factory('Photo',$this->request->param('id')); + + return $this->image($po->thumbnail(),$po->date_taken,$po->type(TRUE)); + } + + public function action_view() { + $po = ORM::factory('Photo',$this->request->param('id')); + + return $this->image($po->image(),$po->date_taken,$po->type(TRUE)); + } + + private function image($content,$modified,$type) { + // Send the file content as the response + if ($content) + $this->response->body($content); + // Return a 404 status + else + $this->response->status(404); + + // Generate and check the ETag for this file + if (Kohana::$environment < Kohana::TESTING OR Kohana::$config->load('debug')->etag) + $this->check_cache(sha1($this->response->body())); + + // Set the proper headers to allow caching + $this->response->headers('Content-Type',$type); + $this->response->headers('Content-Length',(string)$this->response->content_length()); + $this->response->headers('Last-Modified',date('r',$modified)); + $this->auto_render = FALSE; + } + + private function table_duplicate_checkbox(Database_MySQL_Result $dp,Model_Photo $po,$param,$title,$condition) { + $output = ''; + + $output .= sprintf('%s',$title); + + $output .= ''.Form::checkbox($condition.'['.$po->{$param}.']',TRUE,$po->{$condition} ? TRUE : FALSE).''; + + foreach ($dp as $dpo) + $output .= ''.Form::checkbox($condition.'['.$dpo->{$param}.']',TRUE,$dpo->{$condition} ? TRUE : FALSE).''; + + $output .= ''; + + return $output; + } + + private function table_duplicate_details(Database_MySQL_Result $dp,Model_Photo $po,$param,$title='',$content='') { + $output = ''; + + if (preg_match('/\(/',$param) OR preg_match('/-\>/',$param)) + eval("\$d = \$po->$param;"); + else + $d = $po->display($param); + + $output .= sprintf('%s',$title); + $output .= sprintf('%s',$content ? str_replace('%VALUE%',$d,$content) : $d); + + foreach ($dp as $dpo) { + if (preg_match('/\(/',$param) OR preg_match('/-\>/',$param)) + eval("\$d = \$dpo->$param;"); + else + $d = $dpo->display($param); + + $output .= sprintf('%s',$content ? str_replace('%VALUE%',$d,$content) : $d); + } + + $output .= ''; + + return $output; + } +} +?> diff --git a/application/classes/Controller/Translate.php b/application/classes/Controller/Translate.php deleted file mode 100644 index 34c6be3..0000000 --- a/application/classes/Controller/Translate.php +++ /dev/null @@ -1,218 +0,0 @@ -/','',$data); - - return $data; - } - - public function action_index() { - HTTP::redirect(URL::link('','translate/render')); - $output = ''; - - Block::factory() - ->title('Hello') - ->title_icon('icon-cog') - ->body($output); - } - - public function action_import() { - $html = new simple_html_dom(); - $html->load($this->aer()); - - $this->store($html->find('head',0)->find('title',0)); - - foreach ($this->_tags as $z) - foreach ($html->find($z) as $x) - $this->store($x); - - HTTP::redirect(URL::link('','translate/index')); - } - - public function action_render() { - $output = ''; - - if ($this->request->post('language_id')) { - $html = new simple_html_dom(); - $html->load($this->aer()); - - $x = $html->find('head',0); - $x->innertext .= ''; - $lo = ORM::factory('Language',$this->request->post('language_id')); - - foreach ($this->_tags as $z) - foreach ($html->find($z) as $x) - $x->innertext = $this->translate($x,$lo); - - // Convert order the img tags - foreach ($html->find('img') as $z) { - $z->src = sprintf('%s/%s',URL::site('media/aer'),$z->src); - } - - $this->response->body($html); - $this->auto_render = FALSE; - - // We dont know what sort of payment type yet - } else { - $x = $this->lang(); - $output .= Form::open(); - $output .= Form::select('language_id',ORM::factory('Language')->list_select(),$x->id); - $output .= Form::button('submit','Submit',array('class'=>'btn btn-primary')); - $output .= Form::close(); - } - - Block::factory() - ->title('Render in...') - ->title_icon('icon-share') - ->body($output); - } - - public function action_save() { - foreach ($this->request->post('x') as $id => $value) { - if (! $value) - continue; - - $to = ORM::factory('Translate',array('language_id'=>$this->request->post('language_id'),'original_id'=>$id)); - - $to->translation = $value; - $to->language_id = $this->request->post('language_id'); - $to->original_id = $id; - $to->save(); - } - - HTTP::redirect(sprintf('%s?language_id=%s&page=%s',URL::link('','translate/text'),$this->request->post('language_id'),$this->request->post('page'))); - } - - private function lang() { - foreach ($this->request->accept_lang() as $k=>$v) { - if (strlen($k) == 2) - $k = sprintf('%s_%s',strtolower($k),strtoupper($k)); - else { - list($k,$v) = preg_split('/[-_]/',$k,2); - $k = sprintf('%s_%s',strtolower($k),strtoupper($v)); - } - - if ($x=ORM::factory('Language',array('iso'=>$k))) - return $x; - } - } - - private function store(simple_html_dom_node $x,$l=0) { - if ($x->children()) { - foreach ($x->children() as $y) { - $this->store($y,$l+1); - $y->innertext = '%s'; - } - } - - // If we have a numeric value, convert it to %d - $x->innertext = preg_replace('/[0-9.]+/','%d',$x->innertext); - - $oo = ORM::factory('Original',array('sentence'=>$x->innertext)); - - if (! trim($x->innertext) or (in_array(trim($x->innertext),array('$',' ')) or preg_match('/%d%?$/',$x->innertext))) { - return $x->innertext; - - } elseif (! $oo->loaded()) { - $oo->sentence = $x->innertext; - $oo->save(); - } - - return $x->innertext; - } - - private function translate(simple_html_dom_node $x,Model_Language $lo,$l=0) { - $nums = NULL; - $matches = array(); - $dom_tmp = str_get_html($x->outertext); - $dom_tmp_node = $dom_tmp->firstChild(); - - $string = $this->store($dom_tmp_node,$l); - $oo = ORM::factory('Original',array('sentence'=>$string)); - - // If we have numbers, we'll need to save them. - if (preg_match('/%d/',$string)) - $nums = preg_match('/[0-9.]+/',$x->innertext,$matches); - - if ($oo->loaded()) { - $to = ORM::factory('Translate',array('original_id'=>$oo->id,'language_id'=>$lo->id)); - - $string = $to->loaded() ? $to->translation : $x->innertext; - } - - if ($nums && $nums == 1) - $string = str_replace('%d',$matches[0],$string); - elseif ($nums > 1) - throw HTTP_Exception::factory('501','Argh, didnt allow for more than 1 match'); - - - if ($x->children()) { - foreach ($x->children() as $y) { - $string = preg_replace('/%s/',$this->translate($y,$lo,$l+1),$string); - } - } - - return $string; - } - - public function action_text() { - $output = ''; - - if ($this->request->query('language_id')) { - - $output .= Form::open(URL::link('','translate/save')); - $output .= Form::hidden('language_id',$this->request->query('language_id')); - - $oo = ORM::factory('Original') - ->select('translate.translation') - ->join('translate','LEFT OUTER') - ->on('original.id','=','translate.original_id') - ->on('translate.language_id','=',$this->request->query('language_id')); - - $output .= View::factory('translate') - ->set('o',$oo->find_all()); - - // We dont know what sort of payment type yet - } else { - $x = $this->lang(); - $output .= Form::open(NULL,array('method'=>'GET')); - $output .= Form::select('language_id',ORM::factory('Language')->list_select(),$x->id); - } - - $output .= Form::button('submit','Submit',array('class'=>'btn btn-primary')); - $output .= Form::close(); - - Block::factory() - ->title('Translate Text') - ->title_icon('icon-share') - ->body($output); - } - -} // End Welcome diff --git a/application/classes/Controller/Welcome.php b/application/classes/Controller/Welcome.php index 6134f85..0e2cd47 100644 --- a/application/classes/Controller/Welcome.php +++ b/application/classes/Controller/Welcome.php @@ -4,7 +4,7 @@ class Controller_Welcome extends Controller { public function action_index() { - HTTP::redirect(URL::link('','translate')); + HTTP::redirect('photo'); } } // End Welcome diff --git a/application/classes/Cookie.php b/application/classes/Cookie.php index 2d210ee..b71a771 100644 --- a/application/classes/Cookie.php +++ b/application/classes/Cookie.php @@ -3,13 +3,13 @@ /** * This class overrides Kohana's Cookie * - * @package AER + * @package Photo * @category Modifications * @author Deon George * @copyright (c) 2014 Deon George * @license http://dev.leenooks.net/license.html */ class Cookie extends Kohana_Cookie { - public static $salt = 'AER'; + public static $salt = 'Photo'; } ?> diff --git a/application/classes/Model/Album.php b/application/classes/Model/Album.php new file mode 100644 index 0000000..9d94e7a --- /dev/null +++ b/application/classes/Model/Album.php @@ -0,0 +1,14 @@ + diff --git a/application/classes/Model/Language.php b/application/classes/Model/Language.php deleted file mode 100644 index 7897a60..0000000 --- a/application/classes/Model/Language.php +++ /dev/null @@ -1,30 +0,0 @@ -'id','value'=>'name'); - - /** - * Filters used to format the display of values into friendlier values - */ - protected $_display_filters = array( - 'date_orig'=>array( - array('Config::datetime',array(':value')), - ), - ); -} -?> diff --git a/application/classes/Model/Original.php b/application/classes/Model/Original.php deleted file mode 100644 index 16f601b..0000000 --- a/application/classes/Model/Original.php +++ /dev/null @@ -1,28 +0,0 @@ -array( - array('Config::datetime',array(':value')), - ), - ); -} -?> diff --git a/application/classes/Model/People.php b/application/classes/Model/People.php new file mode 100644 index 0000000..1a17654 --- /dev/null +++ b/application/classes/Model/People.php @@ -0,0 +1,17 @@ +date_birth)))->y); + } +} +?> diff --git a/application/classes/Model/Photo.php b/application/classes/Model/Photo.php new file mode 100644 index 0000000..90b86d6 --- /dev/null +++ b/application/classes/Model/Photo.php @@ -0,0 +1,168 @@ +array('through'=>'album_photo'), + 'people'=>array('through'=>'people_photo','far_key'=>'people_id'), + ); + + /** + * Filters used to format the display of values into friendlier values + */ + protected $_display_filters = array( + 'date_orig'=>array( + array('Site::Datetime',array(':value')), + ), + 'date_taken'=>array( + array('Site::Datetime',array(':value')), + ), + 'signature'=>array( + array('Model_Photo::Signaturetrim',array(':value')), + ), + ); + + public function duplicate_find() { + $po = ORM::factory($this->_object_name); + + if ($this->loaded()) + $po->where('id','!=',$this->id); + + $po->where_open(); + $po->where('delete','!=',TRUE); + $po->or_where('delete','is',NULL); + $po->where_close(); + + $po->where_open(); + $po->where('signature','=',$this->signature); + + if ($this->date_taken AND ($this->model OR $this->make)) { + $po->or_where_open(); + $po->where('date_taken','=',$this->date_taken); + $po->where('subsectime','=',$this->subsectime); + + if (! is_null($this->model)) + $po->and_where('model','=',$this->model); + + if (! is_null($this->make)) + $po->and_where('make','=',$this->make); + $po->where_close(); + } + + $po->where_close(); + + return $po; + } + + public function date_taken() { + return $this->display('date_taken').($this->subsectime ? '.'.$this->subsectime : ''); + } + + public function duplicate_get() { + return $this->duplicate_find()->find_all(); + } + + public function gps(array $coordinate,$hemisphere) { + if (! $coordinate OR ! $hemisphere) + return NULL; + + for ($i=0; $i<3; $i++) { + $part = explode('/', $coordinate[$i]); + + if (count($part) == 1) + $coordinate[$i] = $part[0]; + + elseif (count($part) == 2) + $coordinate[$i] = floatval($part[0])/floatval($part[1]); + + else + $coordinate[$i] = 0; + } + + list($degrees, $minutes, $seconds) = $coordinate; + + $sign = ($hemisphere == 'W' || $hemisphere == 'S') ? -1 : 1; + + return round($sign*($degrees+$minutes/60+$seconds/3600),$degrees > 100 ? 3 : 4); + } + + public function image() { + $imo = $this->io(); + + $imo->removeImageProfile('exif'); + $this->rotate($imo); + + return $imo->getImageBlob(); + } + + public function info() { + $imo = $this->io(); + + return $imo->getImageProperties(); + } + + public function io($attr=NULL) { + if (is_nulL($this->_io)) + $this->_io = new Imagick($this->path.'/'.$this->filename); + + return is_null($attr) ? $this->_io : $this->_io->getImageProperty($attr); + } + + public function path() { + $path = ''; + $ao = $this->album->where('primary','=',TRUE)->find(); + + if ($ao->loaded()) { + $path .= $ao->path.'/'; + + if ($ao->subpath_age) { + $po = $this->people->where('primary','=',TRUE)->find(); + $path .= $po->age($this->date_taken).'/'; + } + } + + $path .= sprintf('%s_%03s.%s',date('Ymd-His',$this->date_taken),$this->subsectime,$this->type()); + + return $path; + } + + private function rotate(Imagick $imo) { + switch ($this->orientation) { + case 3: $imo->rotateImage(new ImagickPixel('none'),180); + break; + case 6: $imo->rotateImage(new ImagickPixel('none'),90); + break; + case 8: $imo->rotateImage(new ImagickPixel('none'),-90); + break; + } + } + + public static function Signaturetrim($signature) { + return sprintf('%s...%s',substr($signature,0,6),substr($signature,-6)); + } + + public function thumbnail() { + $imo = new Imagick(); + + $imo->readImageBlob($this->thumbnail); + $this->rotate($imo); + + return $imo->getImageBlob(); + } + + public function type($mime=FALSE) { + return strtolower($mime ? File::mime_by_ext(pathinfo($this->filename,PATHINFO_EXTENSION)) : pathinfo($this->filename,PATHINFO_EXTENSION)); + } +} +?> diff --git a/application/classes/Model/Translate.php b/application/classes/Model/Translate.php deleted file mode 100644 index 0c9d602..0000000 --- a/application/classes/Model/Translate.php +++ /dev/null @@ -1,30 +0,0 @@ -'id','value'=>'translation'); - - /** - * Filters used to format the display of values into friendlier values - */ - protected $_display_filters = array( - 'date_orig'=>array( - array('Config::datetime',array(':value')), - ), - ); -} -?> diff --git a/application/classes/ORM/OSB.php b/application/classes/ORM/OSB.php deleted file mode 100644 index 1ca09b8..0000000 --- a/application/classes/ORM/OSB.php +++ /dev/null @@ -1,287 +0,0 @@ -'date_orig','format'=>TRUE); - protected $_updated_column = array('column'=>'date_last','format'=>TRUE); - - // Our attributes used in forms. - protected $_form = array(); - - // Our attributes that should be converted to NULL when empty - protected $_nullifempty = array(); - - // Our attribute values that need to be stored as serialized - protected $_serialize_column = array(); - - // If we need to load any sub items on loading this model - protected $_sub_items = array(); - protected $_sub_items_load = array(); - protected $_sub_items_sorted = FALSE; - - // Rules to assist with site ID and getting next record ID for inserts. - public function xrules() { - return array( - 'id'=>array( - array('ORM_OSB::get_next_id',array(':model',':field')), - ), - 'site_id'=>array( - array('ORM_OSB::set_site_id',array(':model',':field')), - ), - ); - } - - /** - * Retrieve and Store DB BLOB data. - */ - private function _blob($data,$set=FALSE) { - try { - return $set ? gzcompress($this->_serialize($data,$set)) : $this->_serialize(gzuncompress($data)); - - // Maybe the data isnt compressed? - } catch (Exception $e) { - return $this->_serialize($data,$set); - } - } - - /** - * Auto process some data as it comes from the database - * @see parent::__get() - */ - public function __get($column) { - if (array_key_exists($column,$this->_table_columns)) { - // If the column is a blob, we'll decode it automatically - if ( - $this->_table_columns[$column]['data_type'] == 'blob' - AND ! is_null($this->_object[$column]) - AND ! isset($this->_changed[$column]) - AND (! isset($this->_table_columns[$column]['auto_convert']) OR ! $this->_table_columns[$column]['auto_convert']) - ) { - - // In case our blob hasnt been saved as one. - try { - $this->_object[$column] = $this->_blob($this->_object[$column]); - } - catch(Exception $e) { - HTTP_Exception::factory(501,Kohana_Exception::text($e)); - } - - $this->_table_columns[$column]['auto_convert'] = TRUE; - } - - // If the column is a serialized object, we'll unserialize it. - if ( - in_array($column,$this->_serialize_column) - AND is_string($this->_object[$column]) - AND ! is_null($this->_object[$column]) - AND ! isset($this->_changed[$column]) - AND (! isset($this->_table_columns[$column]['unserialized']) OR ! $this->_table_columns[$column]['unserialized']) - ) { - - // In case our object hasnt been saved as serialized. - try { - $this->_object[$column] = unserialize($this->_object[$column]); - } - catch(Exception $e) { - HTTP_Exception::factory(501,Kohana_Exception::text($e)); - } - - $this->_table_columns[$column]['unserialized'] = TRUE; - } - } - - return parent::__get($column); - } - - /** - * Intercept our object load, so that we can load our subitems - */ - protected function _load_values(array $values) { - parent::_load_values($values); - - $sort = FALSE; - if ($this->_loaded AND $this->_sub_items_load AND count($this->_sub_items_load) == 1) - foreach ($this->_sub_items_load as $item => $sort) - $this->_sub_items = $this->$item->find_all()->as_array(); - - if ($sort) { - Sort::MAsort($this->_sub_items,$sort); - $this->_sub_items_sorted = TRUE; - } - - return $this; - } - - /** - * If a column is marked to be nullified if it is empty, this is where it is done. - */ - private function _nullifempty(array $array) { - foreach ($array as $k=>$v) { - if (is_array($v)) { - if (is_null($x=$this->_nullifempty($v))) - unset($array[$k]); - else - $array[$k] = $x; - - } elseif (! $v AND $v !== 0 AND $v !== '0') - unset($array[$k]); - - } - - return count($array) ? $array : NULL; - } - - /** - * Try and (un)serialize our data, and if it fails, just return it. - */ - private function _serialize($data,$set=FALSE) { - try { - return $set ? serialize($data) : unserialize($data); - - // Maybe the data serialized? - } catch (Exception $e) { - return $data; - } - } - - public function config($key) { - $mc = Config::instance()->module_config($this->_object_name); - - return empty($mc[$key]) ? '' : $mc[$key]; - } - - public function dump() { - $result = array(); - - $result['this'] = $this->object(); - - foreach ($this->_sub_items as $o) - $result['sub'][] = $o->dump(); - - return $result; - } - - /** - * Get Next record id - * - * @param array Validate object - * @param string Primary Key - */ - final public static function get_next_id($model,$field) { - if (! is_null($model->$field)) - return TRUE; - - $model->_changed[$field] = $field; - - $ido = ORM::factory('Module') - ->where('name','=',$model->_table_name) - ->find(); - - if (! $ido->loaded()) - throw new Kohana_Exception('Problem getting record_id for :table',array(':table'=>$model->_table_name)); - - $model->$field = $ido->record_id->next_id($ido->id); - - return TRUE; - } - - public function keyget($column,$key=NULL) { - if (is_null($key) OR ! is_array($this->$column)) - return $this->$column; - else - return array_key_exists($key,$this->$column) ? $this->{$column}[$key] : NULL; - } - - final public function mid() { - return ORM::factory('Module',array('name'=>$this->_table_name)); - } - - public function xsave(Validation $validation=NULL) { - // Find any fields that have changed, and process them. - if ($this->_changed) - foreach ($this->_changed as $c) { - // Any fields that are blobs, and encode them. - if (! is_null($this->_object[$c]) AND $this->_table_columns[$c]['data_type'] == 'blob') { - $this->_object[$c] = $this->_blob($this->_object[$c],TRUE); - - // We need to reset our auto_convert flag - if (isset($this->_table_columns[$c]['auto_convert'])) - $this->_table_columns[$c]['auto_convert'] = FALSE; - - // Any fields that should be seriailzed, we'll do that. - } elseif (is_array($this->_object[$c]) AND in_array($c,$this->_serialize_column)) { - $this->_object[$c] = serialize($this->_object[$c]); - } - - // Test if the value has still changed - if ($this->_original_values AND $this->_object[$c] == $this->_original_values[$c]) - unset($this->_changed[$c]); - } - - return parent::save($validation); - } - - /** - * Set the site ID attribute for each row update - */ - final public static function set_site_id($model,$field) { - if (! is_null($model->$field)) - return TRUE; - - $model->_changed[$field] = $field; - $model->$field = Company::instance()->site(); - - return TRUE; - } - - public function subitems() { - return $this->_sub_items; - } - - /** - * Override the Kohana processing so we can null values if required. - */ - public function values(array $values,array $expected=NULL) { - foreach ($values as $k=>$v) { - // Convert to NULL - if (in_array($k,$this->_nullifempty)) { - if (is_array($v)) - $values[$k] = $this->_nullifempty($v); - - elseif (! $v AND $v !== 0 AND $v !== '0') - $values[$k] = NULL; - } - } - - return parent::values($values,$expected); - } - - /** - * Function help to find records that are active - */ - public function list_active($active=TRUE) { - $x=($active ? $this->_where_active() : $this); - - return $x->find_all(); - } - - public function list_count($active=TRUE) { - $x=($active ? $this->_where_active() : $this); - - return $x->find_all()->count(); - } -} -?> diff --git a/application/classes/Task/Photo/Import.php b/application/classes/Task/Photo/Import.php new file mode 100644 index 0000000..2facb6c --- /dev/null +++ b/application/classes/Task/Photo/Import.php @@ -0,0 +1,75 @@ +NULL, // Photo File to Import + 'verbose'=>FALSE, // Photo File to Import + ); + + protected function _execute(array $params) { + if (is_null($params['file'])) + throw new Kohana_Exception('Missing filename, please use --file='); + + if (preg_match('/@__thumb/',$params['file']) OR preg_match('/\/._/',$params['file'])) + return sprintf("Ignoring file [%s]\n",$params['file']); + + $po = ORM::factory('Photo',array('filename'=>$params['file'])); + + if (! $po->loaded()) + $po->filename = $params['file']; + + $po->date_taken = $this->dbcol(strtotime($po->io('exif:DateTime'))); + $po->signature = $this->dbcol($po->io()->getImageSignature()); + $po->make = $this->dbcol($po->io('exif:Make')); + $po->model = $this->dbcol($po->io('exif:Model')); + $po->height = $this->dbcol($po->io()->getImageheight()); + $po->width = $this->dbcol($po->io()->getImageWidth()); + $po->orientation = $this->dbcol($po->io()->getImageOrientation()); + $po->subsectime = $this->dbcol($po->io('exif:SubSecTimeOriginal')); + + $po->gps_lat = $this->dbcol($po->gps(preg_split('/,\s?/',$po->io()->getImageProperty('exif:GPSLatitude')),$po->io()->getImageProperty('exif:GPSLatitudeRef'))); + $po->gps_lon = $this->dbcol($po->gps(preg_split('/,\s?/',$po->io()->getImageProperty('exif:GPSLongitude')),$po->io()->getImageProperty('exif:GPSLongitudeRef'))); + + try { + $po->thumbnail = $this->dbcol(exif_thumbnail($po->filename)); + } catch (Exception $e) { + } + + switch ($params['verbose']) { + case 1: + print_r($po->what_changed()); + break; + + case 2: + print_r($po->io()->getImageProperties()); + break; + } + + if ($po->duplicate_get()->count()) + $po->duplicate = '1'; + + if (! $po->changed()) + return sprintf("Image [%s] already in DB: %s\n",$params['file'],$po->id); + + $po->save(); + + if ($po->saved()) + return sprintf("Image [%s] stored in DB: %s\n",$params['file'],$po->id); + + return sprintf("Image [%s] processed in DB: %s\n",$params['file'],$po->id); + } + + private function dbcol($val,$noval=NULL) { + return $val ? (string)$val : $noval; + } +} +?> diff --git a/application/config/config.php b/application/config/config.php new file mode 100644 index 0000000..bcd856e --- /dev/null +++ b/application/config/config.php @@ -0,0 +1,6 @@ + 'Photo', +); diff --git a/application/config/database.php b/application/config/database.php index db4753c..5b249f5 100644 --- a/application/config/database.php +++ b/application/config/database.php @@ -18,10 +18,10 @@ return array * * Ports and sockets may be appended to the hostname. */ - 'hostname' => 'localhost', - 'database' => 'weblnaer', - 'username' => 'aer', - 'password' => 'AeR', + 'hostname' => 'mysql.leenooks.vpn', + 'database' => 'weblnphoto', + 'username' => 'ln-webphoto', + 'password' => 'Ph0T0!', 'persistent' => TRUE, ), 'table_prefix' => '', diff --git a/application/config/mainnav.php b/application/config/mainnav.php new file mode 100644 index 0000000..f453c95 --- /dev/null +++ b/application/config/mainnav.php @@ -0,0 +1,16 @@ + array('icon'=>'icon-edit','url'=>URL::site('photo/duplicate')), +); +?> diff --git a/application/views/pages/navbar.php b/application/views/pages/navbar.php deleted file mode 100644 index e69de29..0000000 diff --git a/application/views/theme/baseadmin/page.php b/application/views/theme/baseadmin/page.php deleted file mode 100644 index 4dee9aa..0000000 --- a/application/views/theme/baseadmin/page.php +++ /dev/null @@ -1,130 +0,0 @@ - - - - <?php echo $meta->title; ?> - - - - - - - - - - - - = Kohana::TESTING OR Request::current()->secure()) { - echo HTML::style('media/theme/bootstrap/css/bootstrap.min.css'); - echo HTML::style('media/theme/bootstrap/css/bootstrap-responsive.min.css'); - echo HTML::style('media/vendor/font-awesome/css/font-awesome.min.css'); - } else { - echo HTML::style($meta->secure().'netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap.min.css'); - echo HTML::style($meta->secure().'netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css'); - echo HTML::style($meta->secure().'netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome.css'); - } - - echo HTML::style($meta->secure().'fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,800italic,400,600,800'); - echo HTML::style('media/css/ui-lightness/jquery-ui-1.10.0.custom.min.css'); - echo HTML::style('media/theme/baseadmin/css/base-admin-2.css'); - echo HTML::style('media/theme/baseadmin/css/base-admin-2-responsive.css'); - echo HTML::style('media/theme/baseadmin/css/custom.css'); - echo Style::factory()->render_all(); - ?> - - - - - - - - - -
-
-
-
- render_all(); ?> -
-
-
-
- -
-
-
- -
-
-
- - = Kohana::TESTING OR Request::current()->secure()) { - echo HTML::script('media/js/jquery/jquery-1.9.1.min.js'); - echo HTML::script('media/theme/bootstrap/js/bootstrap.min.js'); - echo HTML::script('media/js/lodash/lodash-1.2.1.min.js'); - } else { - echo HTML::script($meta->secure().'code.jquery.com/jquery-1.9.1.min.js'); - echo HTML::script($meta->secure().'netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js'); - echo HTML::script($meta->secure().'cdnjs.cloudflare.com/ajax/libs/lodash.js/1.2.1/lodash.min.js'); - } - - echo HTML::script('media/theme/baseadmin/js/backtotop.js'); - echo HTML::script('media/js/search.js'); - echo HTML::script('media/js/custom.js'); - echo Script::factory()->render_all(); - ?> - - diff --git a/application/views/translate.php b/application/views/translate.php deleted file mode 100644 index 433ff1f..0000000 --- a/application/views/translate.php +++ /dev/null @@ -1,33 +0,0 @@ -$o->count(),'items_per_page'=>10)); ?> - - -current_page()); ?> - - - - - - - - - current_first_item()) - continue; - elseif ($i > $pag->current_last_item()) - break; - ?> - - sentence) OR preg_match('/>/',$oo->sentence)) : - $oo->sentence = preg_replace('/sentence); - $oo->sentence = preg_replace('/>/','>',$oo->sentence); - endwhile - ?> - - - - - - - - -
TextTranslationIgnore
sentence; ?>id),$oo->translation,array('style'=>'width: 100%;')); ?>
diff --git a/includes/kohana b/includes/kohana index e2475db..4cabe0d 160000 --- a/includes/kohana +++ b/includes/kohana @@ -1 +1 @@ -Subproject commit e2475dba9e6eaeafc6ecc4c71542937638354cd4 +Subproject commit 4cabe0db4f1465a9588a03d45fb02cf2923d107d diff --git a/modules/lnApp b/modules/lnApp index a889d25..b657781 160000 --- a/modules/lnApp +++ b/modules/lnApp @@ -1 +1 @@ -Subproject commit a889d25eda0d6c1b8766b15f2d71f3dd4f0357d9 +Subproject commit b657781a5b52316e6531638f2e89ae4db2543fe5