Пример #1
0
 function Files()
 {
     if (!isset($this->_Files)) {
         $this->_Files = array();
         $this->_FilesAll = array();
         $sql = " SELECT f.*, pf.name as pf_name\t\t\t" . " FROM \t\t\t\t\t\t\t\t\t\t" . "\tpage_file pf \t\t\t\t\t\t\t" . "\tLEFT JOIN file f ON f.id = pf.file_id\t" . " WHERE pf.page_id = '" . $this . "' \t\t\t" . " ORDER BY sort\t";
         foreach (D()->query($sql) as $vs) {
             $this->_FilesAll[$vs['pf_name']] = dbFile($vs['id'], $vs);
             if (dbFile($vs['id'])->exists()) {
                 $this->_Files[$vs['pf_name']] = dbFile($vs['id'], $vs);
             }
         }
     }
     return $this->_Files;
 }
Пример #2
0
		<a href="<?php 
    echo $href;
    ?>
" class=-content>
			<?php 
    echo cutSearch1($r['text'], $search, 7);
    ?>
		</a>
		
		<?php 
    if (isset($r['files'])) {
        ?>
			<div class=-files>
			<?php 
        foreach ($r['files'] as $vs) {
            $F = dbFile($vs['file_id']);
            ?>
				<a style="display:block" target=_blank href="<?php 
            echo $F->url() . '/' . $F->name();
            ?>
"><?php 
            echo $F->vs['name'];
            ?>
 (<?php 
            echo byte_format($F->size());
            ?>
)</a>
				<?php 
            echo cutSearch1($F->vs['text'], $search, 1);
            ?>
			<?php 
 static function searchFile($s)
 {
     $sql = " SELECT \t\t\t\t\t\t\t\t\t\t\t" . "\tpf.page_id AS pid, f.* \t\t\t\t\t\t\t" . " FROM \t\t\t\t\t\t\t\t\t\t\t\t" . "\tpage_file pf\t\t\t\t\t\t\t\t\t" . "\t,file f\t\t\t\t\t\t\t\t\t\t\t" . " WHERE 1\t\t\t\t\t\t\t\t\t\t\t" . "\tAND pf.file_id = f.id\t\t\t\t\t\t\t" . "\tAND ( \t\t\t\t\t\t\t\t\t\t\t" . "\t\t   f.id = " . D()->quote($s) . " \t\t\t\t" . "\t\tOR f.name LIKE " . D()->quote('%' . $s . '%') . "\t" . "\t\tOR f.text LIKE " . D()->quote('%' . $s . '%') . "\t" . "\t)  \t\t\t\t\t\t\t\t\t\t\t\t" . " GROUP BY f.id \t\t\t\t\t\t\t\t\t" . " ORDER BY \t\t\t\t\t\t\t\t\t\t\t" . "\tf.id    =   " . D()->quote($s) . "\t\t\tDESC,\t" . "\tf.name  =   " . D()->quote($s) . "\t\t\tDESC,\t" . "\tf.name LIKE " . D()->quote($s . '%') . "\t\tDESC,\t" . "\tf.name LIKE " . D()->quote('% ' . $s . '%') . "\tDESC,\t" . "\tf.text  =   " . D()->quote($s) . "\t\t\tDESC,\t" . "\tf.text LIKE " . D()->quote($s . '%') . "\t\tDESC,\t" . "\tf.text LIKE " . D()->quote('% ' . $s . '%') . "\tDESC,\t" . "\tf.name ASC\t\t\t\t\t\t\t\t\t\t" . "";
     $res = array();
     $i = 0;
     foreach (D()->query($sql) as $vs) {
         $Page = Page($vs['pid']);
         if ($Page->access() < 2) {
             continue;
         }
         if ($i++ > 10) {
             break;
         }
         $File = dbFile($vs['id'], $vs);
         switch ($File->extension()) {
             case 'jpg':
             case 'jpeg':
             case 'gif':
             case 'png':
                 $imgSrc = $File->url() . '/w-32/h-32/img.jpg';
                 break;
             case 'pdf':
                 $imgSrc = sysURL . 'cms/pub/util/fileicons/32/pdf.gif';
                 break;
             case 'doc':
                 $imgSrc = sysURL . 'cms/pub/util/fileicons/32/doc.gif';
                 break;
             case 'xls':
             case 'csv':
                 $imgSrc = sysURL . 'cms/pub/util/fileicons/32/xls.gif';
                 break;
             case 'mp3':
                 $imgSrc = sysURL . 'cms/pub/util/fileicons/32/mp3.gif';
                 break;
             case 'avi':
                 $imgSrc = sysURL . 'cms/pub/util/fileicons/32/avi.gif';
                 break;
             case 'ppt':
                 $imgSrc = sysURL . 'cms/pub/util/fileicons/32/ppt.gif';
                 break;
             case 'swf':
                 $imgSrc = sysURL . 'cms/pub/util/fileicons/32/swf.gif';
                 break;
             case 'txt':
                 $imgSrc = sysURL . 'cms/pub/util/fileicons/32/txt.gif';
                 break;
             case 'xml':
                 $imgSrc = sysURL . 'cms/pub/util/fileicons/32/xml.gif';
                 break;
             case 'zip':
             case 'tar':
             case 'gz':
             case 'rar':
                 $imgSrc = sysURL . 'cms/pub/util/fileicons/32/zip.gif';
                 break;
             default:
                 $imgSrc = sysURL . 'cms/pub/util/fileicons/32/default.icon.gif';
         }
         $Obj = array('html' => '<div style="background:url(' . $imgSrc . ') no-repeat center; width:32px; height:32px; float:left; display:block; margin-right:3px"></div><b>' . $vs['name'] . '</b><br><i>' . $Page->Page->title() . '</i>', 'text' => $vs['name'], 'value' => $File->id);
         $res[] = $Obj;
     }
     return $res;
 }
Пример #4
0
<?php

$pp = 50;
$page = isset($param['page']) ? (int) $param['page'] : 1;
$limit = ($page - 1) * $pp;
$sql = " SELECT file.*, page_file.name as pf_name " . " FROM file, page_file " . " WHERE file.id = page_file.file_id AND page_file.page_id = " . $Cont . " " . (isset($param['search']) && $param['search'] ? "  AND file.name LIKE " . D()->quote('%' . $param['search'] . '%') . " " : '') . " ORDER BY sort \t\t\t\t" . "";
$res = D()->all($sql);
if (!$res) {
    return false;
}
foreach ($res as $vs) {
    $F = dbFile($vs['id'], $vs);
    ?>
	<tr id="cmsFile<?php 
    echo $vs['pf_name'];
    ?>
" itemid="<?php 
    echo $vs['pf_name'];
    ?>
" class="hasMore">
		<td class="-preview" style="width:40px; height:34px; vertical-align:middle">
			<?php 
    switch ($F->extension()) {
        case 'jpg':
        case 'jpeg':
        case 'gif':
        case 'png':
            echo '<img src="' . $F->url() . '/w-40/h-32/max/' . $F->mtime() . '/' . $F->name() . '.jpg" alt="" />';
            break;
        case 'pdf':
            echo '<img src="' . sysURL . 'cms/pub/util/fileicons/32/pdf.gif" alt="">';
Пример #5
0
 function Files()
 {
     if (!isset($this->_Files)) {
         $this->_Files = $this->_FilesAll = array();
         $sql = " SELECT f.*, pf.name as pf_name           " . " FROM                                     " . "    " . table('page_file') . " pf             " . "    LEFT JOIN " . table('file') . " f ON f.id = pf.file_id " . " WHERE pf.page_id = " . $this . "             " . " ORDER BY sort\t                          ";
         foreach (D()->query($sql) as $vs) {
             $this->_FilesAll[$vs['pf_name']] = dbFile($vs['id'], $vs);
             if (dbFile($vs['id'])->exists()) {
                 $this->_Files[$vs['pf_name']] = dbFile($vs['id'], $vs);
             }
         }
     }
     return $this->_Files;
 }
Пример #6
0
 static function output($request)
 {
     $x = explode('/', $request);
     $id = (int) array_shift($x);
     $name = array_pop($x);
     $param = array();
     foreach ($x as $value) {
         $y = explode('-', $value, 2);
         $param[$y[0]] = isset($y[1]) ? $y[1] : true;
     }
     $File = $RequestedFile = dbFile($id);
     if (!$File->exists()) {
         header("HTTP/1.1 404 Not Found");
         exit;
     }
     if (!$File->access()) {
         header("HTTP/1.1 401 Unauthorized");
         exit;
     }
     header("HTTP/1.1 200 OK");
     // Header
     $mime = $File->mime() ? $File->mime() : extensionToMime($File->extension());
     header('Content-Type: ' . $mime);
     header("Last-Modified: " . gmdate("D, d M Y H:i:s", $File->mtime()) . " GMT");
     header("Pragma: private");
     header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60 * 60 * 24 * 364) . " GMT");
     header("Cache-Control: store, cache, max-age=100000, must-revalidate");
     if (Image::able($File->path)) {
         if (1 || isset($param['h']) || isset($param['w'])) {
             $w = isset($param['w']) ? (int) $param['w'] : 0;
             $h = isset($param['h']) ? (int) $param['h'] : 0;
             //if ($w == 0 && $h == 0) { $w = 200; }
             if (isset($_COOKIE['q1_dpr']) && $_COOKIE['q1_dpr'] > 1) {
                 if (isset($param['dpr']) ? $param['dpr'] : G()->SET['qg']['dbFile_dpr_dependent']->v) {
                     $w *= (double) $_COOKIE['q1_dpr'];
                     $h *= (double) $_COOKIE['q1_dpr'];
                 }
             }
             $w = min($w, 9000);
             $h = min($h, 9000);
             $q = (int) isset($param['q']) ? $param['q'] : 92;
             $max = isset($param['max']) ? (bool) $param['max'] : false;
             $vpos = (int) isset($param['vpos']) ? $param['vpos'] : 20;
             $hpos = (int) isset($param['hpos']) ? $param['hpos'] : 50;
             $zoom = (int) isset($param['zoom']) ? $param['zoom'] : 0;
             $type = str_replace('image/', '', $File->mime());
             //$nFile = new File(appPATH.'cache/pri/dbfile'.$id.'.'.$w.'.'.$h.'.'.$q.'.'.$max.'.'.$vpos.'.'.$hpos.'.'.$zoom);
             $nFile = new File(appPATH . 'cache/pri/dbfile_img_' . sha1($request . '|' . $w . '|' . $h));
             if (!$nFile->exists() || $File->mtime() > $nFile->mtime()) {
                 $Img = new Image($File->path);
                 if ($w == 0 && $h == 0) {
                     $w = $Img->x();
                 }
                 if ($max || $h == 0 || $w == 0) {
                     $Img = $Img->getResized($w, $h, true);
                 } else {
                     $Img = $Img->getAutoCroped($w, $h, $vpos, $hpos, $zoom);
                 }
                 qg::fire('qg::dbfile-image', array('Img' => $Img, 'id' => $id, 'param' => $param));
                 $Img->saveAs($nFile->path, $type, $q);
             }
             header('Content-Type: image/' . $type);
             $File = $nFile;
         }
         //header("Pragma: public"); // Emails!
         header("Pragma: private");
         // required
     } elseif (preg_match('/\\.pdf$/', $name) || $File->mime() == 'application/pdf') {
         header('Content-Type: application/pdf');
         header('Content-Disposition: inline; filename="' . $RequestedFile->name() . '";');
         header('Expires: 0');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Pragma: public');
     }
     if (isset($param['as']) && ($param['as'] = 'text')) {
         header("Content-Type: text/html");
     }
     if (isset($param['dl'])) {
         header('Pragma: public');
         // required!
         header('Expires: 0');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Cache-Control: private', false);
         // required for certain browsers
         header('Content-Type: application/force-download');
         header('Content-Disposition: attachment; filename="' . $RequestedFile->name() . '";');
         header('Content-Transfer-Encoding: binary');
     }
     session_write_close();
     // useful?
     $etag = 'qg' . $File->mtime();
     if (!isset($_SERVER['HTTP_IF_NONE_MATCH']) || $_SERVER['HTTP_IF_NONE_MATCH'] !== $etag) {
         header('ETag: ' . $etag);
         /* rangeDownload http://mobiforge.com/developing/story/content-delivery-mobile-devices */
         header('Content-Length: ' . $File->size());
         flush();
         while (ob_get_level()) {
             ob_end_flush();
         }
         $File->read();
     } else {
         header("HTTP/1.1 304 Not Modified");
     }
     exit;
 }
 static function addDbFile($pid, $id)
 {
     if (!self::checkRight(2)) {
         return false;
     }
     foreach (D()->query("SELECT page_id FROM page_file WHERE file_id = '" . $id . "'") as $vs) {
         if (Page($vs['page_id'])->access()) {
             Page($pid)->addDbFile(dbFile($id));
             G()->Answer = array('cmsInfo' => L('Datei hinzugefügt'));
             return;
         }
     }
     G()->Answer = array('cmsInfo' => L('Ihnen fehlt das nötige Recht'));
 }
Пример #8
0
 static function add($path = '')
 {
     $F = new File($path);
     $ext = strtolower(preg_replace('/.*\\./', '', $path));
     $mime = $ext ? extensionToMime($ext) : 'application/octet-stream';
     D()->query("INSERT INTO file SET name = " . D()->quote(basename($path)) . ", mime = " . D()->quote($mime));
     $id = D()->lastInsertId();
     if ($path) {
         $F->copy(appPATH . 'qg/dbFile/' . $id);
         dbFile($id)->updateDb();
     }
     return dbFile($id);
 }
Пример #9
0
 function send()
 {
     $this->save();
     // save
     require_once 'Zend/Mail.php';
     require_once 'Zend/Mail/Transport/Sendmail.php';
     $tr = new Zend_Mail_Transport_Sendmail('-f' . G()->SET['qg']['mail']['replay']->v);
     Zend_Mail::setDefaultTransport($tr);
     $toWebmaster = debug ? G()->SET['qg']['mail']['on debugmode to']->v : false;
     $DbFiles = array();
     // deprecated
     if (D()->mail_file) {
         foreach (D()->query("SELECT * FROM mail_file WHERE mail_id = '" . $this->id . "'") as $vs) {
             $DbFiles[] = dbFile($vs['file_id']);
         }
     }
     foreach (D()->mail_recipient->selectEntries("WHERE mail_id = " . $this . " AND sent = 0") as $Item) {
         $ZendMail = new Zend_Mail('utf-8');
         $ZendMail->setFrom($this->sender, $this->sendername ? $this->sendername : $this->sender);
         $ZendMail->setSubject(($toWebmaster ? 'Debug! ' : '') . $this->subject);
         foreach ($DbFiles as $F) {
             // deprecated
             $At = $ZendMail->createAttachment($F->getContents(), $F->mime());
             $At->filename = $F->name();
         }
         $html = $this->getHtml($Item, $ZendMail);
         // dirty hack for thunderbird, it needs multipart/related for inline-images
         if (strpos($html, 'cid:') !== false) {
             $ZendMail->setType(Zend_Mime::MULTIPART_RELATED);
             // ok?
         }
         $ZendMail->setBodyHtml(($toWebmaster ? 'original receiver :' . $Item->email . '<br><br>' : '') . $html);
         $ZendMail->setBodyText(($toWebmaster ? 'original receiver :' . $Item->email . "\n\n" : '') . $this->getText($Item, $ZendMail));
         $ZendMail->addTo($toWebmaster ? $toWebmaster : $Item->email, $Item->name);
         foreach (D()->query("SELECT * FROM mail_attachment WHERE mail_id = " . $this->id) as $vs) {
             $At = $ZendMail->createAttachment(file_get_contents($vs['path']));
             $At->filename = $vs['name'] ? $vs['name'] : basename($vs['path']);
             $At->type = $vs['type'] ? $vs['type'] : extensionToMime(preg_replace('/.*\\.([^.]+$)/', '$1', $vs['path']));
             $At->disposition = $vs['inline'] ? Zend_Mime::DISPOSITION_INLINE : Zend_Mime::DISPOSITION_ATTACHMENT;
             $At->id = $vs['hash'];
         }
         $sent = false;
         try {
             $sent = $ZendMail->send();
         } catch (Exception $e) {
             var_dump($this->sender);
             trigger_error('mail sending failed :' . $e);
         }
         if ($sent) {
             $Item->sent = time();
             $Item->save();
             // save
         }
     }
 }
Пример #10
0
 function FileDelete($name)
 {
     $this->Files();
     if (!isset($this->_FilesAll[$name])) {
         return false;
     }
     $id = $this->_FilesAll[$name]->id;
     if (D()->one("SELECT count(*) as num FROM page_file WHERE file_id = " . $id) == 1) {
         dbFile($id)->remove();
         //dbFile::remove($id);
     }
     D()->page_file->delete(array('page_id' => $this, 'name' => $name));
     unset($this->_Files[$name]);
     unset($this->_FilesAll[$name]);
     return true;
 }
Пример #11
0
 static function uploadListener()
 {
     foreach ($_FILES as $name => $f) {
         if ($f['size'] === 0) {
             continue;
         }
         if (isset($_SESSION['uploadTicket'][$name])) {
             $opt = $_SESSION['uploadTicket'][$name];
             if (isset($opt['dbfile'])) {
                 if ($f['type'] === 'image/pjpeg') {
                     $f['type'] = 'image/jpeg';
                 }
                 $File = dbFile($opt['dbfile']);
                 $File->replaceFromUpload($f);
             } else {
                 move_uploaded_file($f['tmp_name'], $opt['path']);
             }
         }
     }
 }