2016-07-22 20:00:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once (__DIR__.'/image.php');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for image methods.
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2016-08-25 10:47:09 +00:00
|
|
|
class Util
|
2016-07-22 20:00:27 +00:00
|
|
|
{
|
2016-08-25 10:47:09 +00:00
|
|
|
var $app;
|
|
|
|
var $dataDir;
|
2016-07-22 20:00:27 +00:00
|
|
|
|
|
|
|
function __construct ($app)
|
|
|
|
{
|
2016-08-25 10:47:09 +00:00
|
|
|
$this->app = $app;
|
2016-09-01 11:42:11 +00:00
|
|
|
$this->dataDir = _DATA_DIR .'/'. $app->getName () .'/image-db';
|
2016-07-22 20:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads information for specified schema.
|
|
|
|
*
|
|
|
|
* @param string $schema The schema name
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2016-07-22 20:00:27 +00:00
|
|
|
function loadInfo ($schema)
|
|
|
|
{
|
2016-08-25 10:47:09 +00:00
|
|
|
$db = $this->app->getSysConn ();
|
2016-07-22 20:00:27 +00:00
|
|
|
|
2016-08-25 10:47:09 +00:00
|
|
|
$info = $db->getRow (
|
2016-07-22 20:00:27 +00:00
|
|
|
'SELECT id, max_width, max_height, `schema`, `table`, `column`
|
|
|
|
FROM image_schema WHERE name = #schema'
|
|
|
|
,['schema' => $schema]
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!$info)
|
|
|
|
return NULL;
|
|
|
|
|
2016-08-25 10:47:09 +00:00
|
|
|
$res = $db->query (
|
2016-07-22 20:00:27 +00:00
|
|
|
'SELECT width, height, crop
|
|
|
|
FROM image_schema_size WHERE image_schema_id = #id'
|
|
|
|
,['id' => $info['id']]
|
|
|
|
);
|
|
|
|
|
|
|
|
$info['sizes'] = [];
|
|
|
|
|
|
|
|
while ($r = $res->fetch_assoc ())
|
|
|
|
{
|
|
|
|
$size = "{$r['width']}x{$r['height']}";
|
|
|
|
$info['sizes'][$size] = [
|
|
|
|
'width' => $r['width'],
|
|
|
|
'height' => $r['height'],
|
|
|
|
'crop' => $r['crop']
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
}
|
2016-10-11 14:45:10 +00:00
|
|
|
|