static function render() { $Page = self::PageFromRequest(); if (!$Page->is()) { // search for redirect $sql = "SELECT * FROM page_redirect WHERE request = " . D()->quote(appRequestUri) . " "; if ($vs = D()->row($sql)) { if (is_numeric($vs['redirect'])) { $url = $_SERVER['SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . Page($vs['redirect'])->url(); } else { $url = $vs['redirect']; } header('HTTP/1.1 301'); // better 302 (temporary)? header('Location: ' . $url); abort(); } // not found header("HTTP/1.1 404 Not Found"); $Page = Page(G()->SET['cms']['pageNotFound']->v); } self::$MainPage = self::$RequestedPage = $Page; if (!self::$MainPage->access()) { // no access header("HTTP/1.1 401 Unauthorized"); self::$MainPage = Page(G()->SET['cms']['pageNoAccess']->v); } globalTemplate(appPATH . 'qg/html-template.php'); html::$content .= Page()->get(); if (self::$MainPage->access() > 1) { html::addBodyFile(sysPATH . 'cms/view/frontend.php'); } D()->log->Entry(liveLog::$id)->page_id = Page(); qg::fire('cms-ready'); }
function getHtml($Recipient = null, $ZendMail = null) { $html = $this->html; $data = $Recipient ? unserialize($Recipient->data) : array(); qg::fire('mail::gethtml', array('Mail' => $this, 'Recipient' => $Recipient, 'html' => &$html, 'data' => &$data, 'ZendMail' => $ZendMail)); if ($data) { $T = new template($data); $html = $T->renderMarker($html); } if ($ZendMail) { // deprecated preg_match_all("#<img.*?src=['\"]file://([^'\"]+)#i", $html, $matches); $matches = array_unique($matches[1]); if ($matches) { $ZendMail->setType(Zend_Mime::MULTIPART_RELATED); foreach ($matches as $key => $filename) { if (!is_readable($filename) || !image::able($filename)) { continue; } $at = $ZendMail->createAttachment(file_get_contents($filename)); $at->type = extensionToMime(preg_replace('/.*\\.([^.]+$)/', '$1', $filename)); $at->disposition = Zend_Mime::DISPOSITION_INLINE; $at->id = 'i' . md5_file($filename); $html = str_replace('file://' . $filename, 'cid:' . $at->id, $html); trigger_error('error: auto inline images are deprecated!'); } } } return $html; }
function getHtml($Recipient = null, $ZendMail = null) { $html = $this->html; $data = $Recipient ? unserialize($Recipient->data) : array(); qg::fire('mail::gethtml', array('Mail' => $this, 'Recipient' => $Recipient, 'html' => &$html, 'data' => &$data, 'ZendMail' => $ZendMail)); if ($data) { $T = new template($data); $html = $T->renderMarker($html); } return $html; }
static function login($id) { $id = (int) (string) $id; if (!D()->one("SELECT id FROM usr WHERE id = " . $id)) { return false; } $old_session = $_SESSION; self::logout(); $_SESSION['liveUser'] = $id; Client()->addUsr($id); Client()->usr_id = $id; qg::fire('login', array('session_old' => $old_session)); return true; }
static function render() { $Page = self::PageFromRequest(); if (!$Page->is()) { // search for redirect if ($redirect = D()->one("SELECT redirect FROM page_redirect WHERE request = " . D()->quote(appRequestUri))) { if (is_numeric($redirect)) { $url = $_SERVER['SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . Page($redirect)->url(); } else { $url = $redirect; } header('HTTP/1.1 301'); // better 302 (temporary) ? header('Location: ' . $url); exit; } // not found header("HTTP/1.1 404 Not Found"); $Page = Page(G()->SET['cms']['pageNotFound']->v); } self::$MainPage = self::$RequestedPage = $Page; if (!self::$MainPage->access()) { // no access header("HTTP/1.1 401 Unauthorized"); self::$MainPage = Page(G()->SET['cms']['pageNoAccess']->v); } if (!self::$MainPage->isReadable()) { // offline header("HTTP/1.1 401 Unauthorized"); self::$MainPage = Page(G()->SET['cms']['pageOffline']->v); } qg::fire('deliverHtml'); // deprecated //qg::fire('cms::render-before'); // todo html::$content .= self::$MainPage->get(); self::$MainPage->access() > 1 && html::addBodyFile(sysPATH . 'cms/view/frontend.php'); qg::fire('cms-ready'); // deprecated $tpl = new template(); echo $tpl->get(appPATH . 'qg/html-template.php'); //qg::fire('cms::render-after'); // todo }
static function call($fn, $args) { self::loadLibs(); $ret = null; $onAfter = false; $ok = true; /* before */ if (preg_match('/(.+)::(.+)/', $fn, $matches)) { $class = 'qg\\serverInterface_' . $matches[1]; $method = $matches[2]; $onBefore = $class . '::onBefore'; $onAfter = $class . '::onAfter'; if (is_callable($onBefore)) { $aspectArgs = $args; array_unshift($aspectArgs, $method); $v = call_user_func_array($onBefore, $aspectArgs); $ok = $v !== false; } } if ($ok) { //qg::fire('Api::before', array('fn'=>$fn,'args'=>&$args) ); $ret = call_user_func_array('qg\\serverInterface_' . $fn, $args); qg::fire('Api::after', array('fn' => $fn, 'args' => &$args, 'return' => &$ret)); } /* after */ if ($onAfter) { if (is_callable($onAfter)) { $aspectArgs = $args; array_unshift($aspectArgs, $method); call_user_func_array($onAfter, $aspectArgs); } } return $ret; }
function delete($id) { $id = $this->entryId($id); $values = $this->entryId2Array($id); qg::fire('dbTable::delete-before', array('Table' => $this, 'data' => &$values, 'id' => &$id, 'prevent' => &$prevent)); if ($prevent === true) { return false; } $Statement = $this->Db->query("DELETE FROM " . $this . " WHERE " . $this->entryId2where($id)); if (!$Statement->rowCount()) { return; } qg::fire('dbTable::delete-after', array('Table' => $this, 'data' => &$values, 'id' => $id)); // todo, test, not very good implementation foreach ($this->Childs() as $Field) { switch ($Field->vs['on_parent_delete']) { case 'cascade': foreach ($this->Db->query("SELECT * FROM " . $Field->Table . " WHERE " . $Field . " = " . $this->Db->quote($id)) as $row) { $Field->Table->delete($row); } break; case 'setnull': //$F->updateIf($E, null); // todo break; } } return true; }
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; }
function getRaw($vars = array()) { if (!$this->is) { trigger_error('Seite existiert nicht!'); return; } $modPath = sysPATH . $this->vs['module'] . '/'; // dont use the getter; $Cont = $this; $res = is_file($modPath . 'control.php') ? include $modPath . 'control.php' : null; if (is_file($modPath . 'index.php')) { $T = new template($res); $T->assign('vars', $vars); $T->assign('Cont', $this); $str = $T->get($modPath . 'index.php'); qg::fire('cms::parseTemplate', array('Cont' => $Cont, 'string' => &$str)); } else { $str = '<div>' . ($this->edit ? L('Das Modul ist nicht existiert nicht!') : '') . '</div>'; } is_file($modPath . 'pub/main.js') && html::addJsFile($this->modUrl . 'pub/main.js'); is_file($modPath . 'pub/main.css') && html::addCSSFile($this->modUrl . 'pub/main.css'); return $str; }
function __construct($template = '') { qg::fire('deliverHtml'); $this->template = $template; ob_start(); }
function table($table) { qg::fire('table', array('table' => &$table)); return $table; }