require_once 'HTML/FlexyFramework.php'; /* * Table Definition for blobs */ require_once 'DB/DataObject.php'; class DataObjects_Blobs extends DB_DataObject { ###START_AUTOCODE /* the code below is auto generated do not remove the above tag */ var $__table='blobs'; // table name var $id; // int(11) not_null primary_key auto_increment var $ptable; // string(255) not_null var $pid; // int(11) not_null var $score; // int(11) not_null var $name; // string(255) not_null multiple_key var $title; // string(255) not_null var $location; // string(255) not_null var $mimetype; // string(255) not_null var $sitegroup; // int(11) not_null multiple_key var $author; // int(11) not_null var $created; // datetime(19) not_null var $sizex; // int(11) var $sizey; // int(11) var $sizebytes; // int(11) /* Static get */ function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('DataObjects_Blobs',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE function staticList($k,$v) { if (!$k) { echo "NO TABLE"; exit; } $t = new DataObjects_Blobs; $t->ptable = str_replace('dataobjects_','',strtolower($k)); $t->pid = $v; $t->find(); if ($t->N) { return $t; } } /* Sorted list: returns imagename :: array('main' => $dataobject_blob) array('100' => $dataobject_blob) */ function staticGetSortedAttachments($k,$v) { $t = DataObjects_Blobs::staticList($k,$v); while ($t->fetch()) { $args = array(); if (preg_match("/(.*)_([0-9]+)x([0-9]+)\.([a-z]+)$/", $t->name,$args)) { // its a main.. $ret[$args[1]][$args[3]] = $t; continue; } $name = preg_replace("/\.[a-z]+$/","",$t->name); $ret[$name]['main'] = $t; } return $ret; } function get($a,$b=NULL) { $r = parent::get($a,$b); $this->getParameters(); return $r; } function fetch() { $ret = parent::fetch(); $this->getParameters(); return $ret; } function getUrl() { $options = PEAR::getStaticProperty('HTML_FlexyFramework_CMS', 'options'); //print_r($options); $this->linkurl = "{$options['blobsBaseUrl']}/{$this->location}/{$this->name}"; $obj = DB_DataObject::factory($this->ptable); $obj->get($this->pid); $this->linkurl = '/content'.$obj->getLinkUrl() . '/'. $this->name; return $this->linkurl; //print_r($this); } function getParameters() { if ($this->sizex) return; /*$arr = DataObjects_Record_extension::staticGetAll(get_class($this), $this->id); foreach ($arr as $k=>$v) { $this->$k = $v; }*/ if (@$this->size_x) { $this->sizex = $this->size_x; $this->sizey = $this->size_y; $this->sizebytes = $this->size_bytes; $t = $this; $t->update(); return; } $options = PEAR::getStaticProperty('HTML_FlexyFramework_CMS', 'options'); if (!@$options['blobsDir'] ) { HTML_FlexyFramework::raiseError('No Blobs directory blobsDir'); exit; } $info = @getimagesize( $options['blobsDir'] . "/".$this->location); //print_r($info); if (!$info) return; $this->sizex = $info[0]; $this->sizey = $info[1]; $this->sizebytes = filesize( $options['blobsDir'] . "/".$this->location); $t = $this; $t->update(); } function serve($request="") { if (!$request) { $options = PEAR::getStaticProperty('HTML_FlexyFramework_CMS', 'options'); if (!@$options['blobsDir'] ) { HTML_FlexyFramework::raiseError('No Blobs directory blobsDir'); exit; } preg_match("/^.*\.([a-z]{3,4})/i",$this->name,$filedata); $args[1] = "/".$this->location; $args[2] = $filedata[1]; $stat = stat( $options['blobsDir'] . $args[1]); } else { $ff = new HTML_FlexyFramework; $ff->_loadConfig(); $options = PEAR::getStaticProperty('HTML_FlexyFramework_CMS', 'options'); $item = substr($request,strlen($options['blobsBaseUrl'])); if (!@$options['blobsDir'] ) { HTML_FlexyFramework::raiseError('No Blobs directory blobsDir'); exit; } preg_match("/^(\/[0-9a-f]{1}\/[0-9a-f]{1}\/[0-9a-f]+)\/.*\.([a-z]{3,4})/i",$item,$args); $stat = stat( $options['blobsDir'] . $args[1]); } //echo 'Last-Modified: '. date("D, d M Y h:i:s",$stat['mtime']) . " GMT"; //echo "
";
//print_r($_SERVER);
//exit;
header('Cache-Control: store');
header('Cache-Control: cache');
//header('Cache-Control: max-age= number');
header('Cache-Control: public');
header('Pragma: cache');
header('Last-Modified: '. date("D, d M Y h:i:s",$stat['mtime']) . " GMT");
header('Expires: '. date("D, d M Y h:i:s",time()+100000) . " GMT");
//$data = serialize($_SERVER);
//$fh = fopen('/tmp/log','a');
//fwrite($fh,$data);
//fclose ($fh);
//Last-Modified: Thu, 08 Mar 2001 00:18:07 GMT
switch ($args[2]) {
case "jpg":
case "jpeg":
header('Content-Type: image/jpeg');
case "png":
header('Content-Type: image/png');
default:
if (is_object(@$this) && $this->mimetype) {
header("Content-Type: {$this->mimetype}");
}
}
header("Content-Length: ". filesize( $options['blobsDir'] . $args[1] ));
if ($_SERVER['REQUEST_METHOD'] == 'HEAD') {
exit;
}
if (!file_exists($options['blobsDir'] . $args[1])) {
echo "CAN NOT FIND FILE {$args[1]}";
exit;
}
$fh = fopen ($options['blobsDir'] . $args[1], 'r' );
while (!feof($fh)) {
echo fread($fh,4096);
}
fclose($fh);
//virtual($options['blobsDir'] . $args[1]);
exit;
//echo $file;
}
function getParent() {
$class = DB_DataObject::staticAutoloadTable($this->ptable);
return DB_DataObject::staticGet($class, $this->pid);
}
function _createLocation() {
$options = PEAR::getStaticProperty('HTML_FlexyFramework_CMS', 'options');
if (!@$options['blobsDir'] ) {
HTML_FlexyFramework::raiseError('No Blobs directory blobsDir');
exit;
}
$md5 = $this->_createGuid($this->ptable, $this->pid);
$file = "x/x" . $md5;
$file[0] = strtoupper($file[3]);
$file[2] = strtoupper($file[4]);
$file[3]= "/";
$filename = $options['blobsDir'] . '/'. $file;
touch ($filename);
chmod($filename,0755);
if (!file_exists($filename)) {
return FALSE;
}
$this->location = $file;
}
function updateData($data,$size) {
$options = PEAR::getStaticProperty('HTML_FlexyFramework_CMS', 'options');
if (!@$options['blobsDir'] ) {
HTML_FlexyFramework::raiseError('No Blobs directory blobsDir');
exit;
}
if (!@$this->location) {
$this->_createLocation();
}
if ($size) {
$this->sizebytes = $size;
}
$this->update();
if (!$size) {
return;
}
//echo "UPDATING $size";
//$obj->author = $__midgard->user;
$fh = fopen( $options['blobsDir'] . '/'. $this->location ,"w");
fwrite($fh, $data, $size);
fclose($fh);
}
function delete() {
$options = PEAR::getStaticProperty('HTML_FlexyFramework_CMS', 'options');
if (!@$options['blobsDir'] ) {
HTML_FlexyFramework::raiseError('No Blobs directory blobsDir');
exit;
}
if (@file_exists( $options['blobsDir'] . '/'. $this->location)) {
@unlink( $options['blobsDir'] . '/'. $this->location);
}
return parent::delete();
}
function _createGuid($table,$id) {
global $HTTP_SERVER_VARS,$HOSTNAME;
if ( substr( PHP_OS, 0, 3 ) == 'WIN' ) {
// simulate uname return for Windows...
$data['sysname'] = PHP_OS;
$data['nodename'] = $HOSTNAME;
$data['release'] = "2.2.16-22";
$data['version'] = "#1 Tue Aug 22 16:49:06 EDT 2000";
$data['machine'] = "i686";
} else {
$data = posix_uname();
}
$repligard_magic_string = sprintf("%s|%s|%s|%s|%s|%s|%s",
$data['sysname'],$data['nodename'],$HOSTNAME,
$data['release'],$data['version'],$data['machine'],
$HTTP_SERVER_VARS["SERVER_ADDR"]);
$str = sprintf("re%spli%d%sga%drd%s.%s.%d",
$table, time(), $repligard_magic_string, $id,
"1.0", microtime(), getmypid());
return md5($str);
}
function dumptoFs($dir) {
set_time_limit(0);
$writeto = "{$dir}/{$this->name}";
if (file_exists($writeto)) {
return;
}
mkdir($dir);
$options = PEAR::getStaticProperty('HTML_FlexyFramework_CMS', 'options');
if (!@$options['blobsDir'] ) {
HTML_FlexyFramework::raiseError('No Blobs directory blobsDir');
exit;
}
//echo "COPY : ". $options['blobsDir'] . '/'. $this->location ." To ". $writeto ."
";
//return;
copy($options['blobsDir'] . '/'. $this->location, $writeto);
}
}
?>