$tn.filename LIKE '%{$this->escape($q['search']['filename'])}%' OR $tn.title LIKE '%{$this->escape($q['search']['filename'])}%'
");
}
+
+ if(!empty($q['_to_base64']) && !empty($q['image_id'])) {
+ $i = DB_DataObject::factory("Images");
+ $i->get($q['image_id']);
+ $roo->jok($i->toBase64());
+ }
}
$o = $this->object();
//print_r($o);
- if (method_exists($o, 'checkPerm')) {
+ if ($o && method_exists($o, 'checkPerm')) {
// edit permissions on related object needed...
return $o->checkPerm( $lvl == 'S' ? 'S' : 'E' , $au);
function getStoreName()
{
$opts = HTML_FlexyFramework::get()->Pman;
- $fn = preg_replace('/[^a-z0-9\.]+/i', '_', $this->filename);
+ $fn = preg_replace('/[^a-z0-9_\.]+/i', '_', $this->filename);
return implode( '/', array(
$opts['storedir'], '_images_', date('Y/m', strtotime($this->created)), $this->id . '-'. $fn
));
*/
function exists()
{
- return file_exists($this->getStoreName());
+ clearstatcache();
+ //var_dump($this->getStoreName());
+ $ret = file_exists($this->getStoreName());
+ if (!$ret) {
+ return $this->canFix();
+ }
+ return $ret;
+ }
+
+ function canFix() {
+ // look for the image in the folder, with matching id.
+ // this is problematic..
+ $fn = $this->getStoreName();
+ if (file_exists($fn . '-really-missing')) {
+ return false;
+ }
+ if (!file_exists(dirname($fn))) {
+ return false;
+ }
+ foreach( scandir(dirname($fn)) as $n) {
+ if (empty($n) || $n[0] == '.') {
+ continue;
+ }
+ $bits = explode('-', $n);
+ if ($bits[0] != $this->id) {
+ continue;
+ }
+ if (preg_match('/\.[0-9]+x[0-9]]+\.jpeg$/', $n)) {
+ continue;
+ }
+ copy(dirname($fn). '/'. $n, $fn);
+ clearstatcache();
+ return true;
+ }
+ // fixme - flag it as bad
+ touch($fn . '-really-missing');
}
}
- $ret['shorten_name'] = $ret['filename'] = $this->shorten_name();
+ $ret['shorten_name'] = $this->shorten_name();
return $ret;
}
*/
function toFileConvert()
{
+ $fn = $this->getStoreName();
+
require_once 'File/Convert.php';
$fc = new File_Convert($this->getStoreName(), $this->mimetype);
return $fc;
}
$file = $this->getStoreName();
-
+
if(!file_exists($file)){
return false;
}