public function to($type) { if ($type == 'html' && $this->cfg->mode == 'edit') { response::getInstance()->addJs('checkboxFields'); } return parent::to($type); }
protected function execTinyMce($prm=null) { $search = 'js/tiny_mce/'; $request = request::get('request'); $pos = strpos($request, $search); if ($pos === false) exit; $tmp = substr($request, $pos+strlen($search)); $file = file::nyroExists(array( 'name'=>'lib'.DS.'tinyMce'.DS.$tmp, 'realName'=>true, 'type'=>'other' )); if (strpos($file, '.php') !== false) { array_walk($_GET, create_function('&$v', '$v = urldecode($v);')); $path = str_replace($tmp, '', $file); ini_set('include_path', $path); define('TINYMCEPATH', substr($path, 0, -1)); define('TINYMCECACHEPATH', substr(TMPROOT, 0, -1)); if (ob_get_length()) ob_clean(); include($file); exit; } else response::getInstance()->showFile($file); }
public function toHtml() { if ($this->cfg->useJs) { $this->cfg->setInArray('html', 'class', $this->cfg->getInArray('html', 'class') . ' date'); $resp = response::getInstance(); $resp->addJs('jqueryui'); if (($lang = request::get('lang')) != 'en') { $resp->addJs('i18n_ui.datepicker-' . $lang); } $jsPrmMin = $this->cfg->jsPrm; $jsPrmMax = $this->cfg->jsPrm; $minId = $this->makeId($this->name . '[0]'); $maxId = $this->makeId($this->name . '[1]'); $minDate = $this->dates['min']->getJs(null); $maxDate = $this->dates['max']->getJs(null); $jsPrmMin['onSelect'] = 'function(dateText) {$("#' . $maxId . '").datepicker("option", "minDate", $("#' . $minId . '").datepicker("getDate"));}'; if ($maxDate) { $jsPrmMin['maxDate'] = $maxDate; } $jsPrmMax['onSelect'] = 'function(dateText) {$("#' . $minId . '").datepicker("option", "maxDate", $("#' . $maxId . '").datepicker("getDate"));}'; if ($minDate) { $jsPrmMax['minDate'] = $minDate; } $resp->blockJquery(' $("#' . $minId . '").datepicker(' . utils::jsEncode($jsPrmMin) . '); $("#' . $maxId . '").datepicker(' . utils::jsEncode($jsPrmMax) . '); '); } return parent::toHtml(); }
protected function afterInit() { if (empty($this->cfg->value)) { $this->cfg->value = $this->get(true); $this->saved = true; } if ($this->cfg->autoSave) { response::getInstance()->addBeforeOut(array($this, 'save')); } }
public function toHtml() { if ($this->cfg->mode == 'view') { return $this->getValue(); } $options = $this->tinyMce; if (is_array($this->cfg->tinyBrowser) && $this->cfg->getInArray('tinyBrowser', 'active')) { $tinyBrowser = $this->cfg->tinyBrowser; $options['file_browser_callback'] = 'function(field_name, url, type, win) { tinyMCE.activeEditor.windowManager.open({ file : "' . $tinyBrowser['url'] . '?' . session::getInstance()->getSessIdForce() . '=' . urlencode(session_id()) . '&type=" + type' . ($tinyBrowser['subdir'] ? '+"&subdir=' . $tinyBrowser['subdir'] . '"' : '') . ', title : "' . $tinyBrowser['title'] . '", width : ' . $tinyBrowser['width'] . ', height : ' . $tinyBrowser['height'] . ', resizable : "yes", scrollbars : "yes", inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin! close_previous : "no" }, { window : win, input : field_name }); return false; }'; } else { if (is_array($this->cfg->nyroBrowser) && $this->cfg->getInArray('nyroBrowser', 'active')) { $nyroBrowser = $this->cfg->nyroBrowser; $options['file_browser_callback'] = 'function(field_name, url, type, win) { tinyMCE.activeEditor.windowManager.open({ file : "' . $nyroBrowser['url'] . '?' . session::getInstance()->getSessIdForce() . '=' . urlencode(session_id()) . '&type="+type+"&config=' . $nyroBrowser['config'] . '&", title : "' . $nyroBrowser['title'] . '", width : ' . $nyroBrowser['width'] . ', height : ' . $nyroBrowser['height'] . ', resizable : "yes", scrollbars : "yes", inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin! close_previous : "no" }, { window : win, input : field_name }); return false; }'; } } if (array_key_exists('content_css', $options) && $options['content_css']) { $contentCss = $options['content_css']; $options['setup'] = 'function(ed) {ed.onInit.add(function(ed) {setTimeout(function() {ed.dom.add(ed.dom.select("head"), "link", {rel : "stylesheet", href : "' . $contentCss . '"});}, 5);});}'; } unset($options['content_css']); $resp = response::getInstance()->getProxy(); $resp->addJs('jquery.tinymce'); $resp->blockjQuery('$("#' . $this->id . '").tinymce(' . utils::jsEncode($options) . ');'); return utils::htmlTag($this->htmlTagName, array_merge($this->html, array('name' => $this->name, 'id' => $this->id)), utils::htmlOut($this->getValue())); }
/** * Show the file to the client * * @param string $prm File requested */ public static function get($prm) { self::init(); $prm = self::$cfg->dir. str_replace( array(self::$cfg->webDir.'/', '/'), array('', DS) , $prm); if (self::$cfg->getInArray('forceDownload', file::getExt($prm))) response::getInstance()->sendFile($prm); else response::getInstance()->showFile($prm); }
public function toHtml() { if ($this->cfg->mode == 'view') { return $this->date->format('date', 'short2'); } if ($this->cfg->useJs) { $resp = response::getInstance(); $resp->addJs('jqueryui'); $resp->blockJquery('$("#' . $this->id . '").datepicker(' . utils::jsEncode($this->jsPrm) . ');'); } return utils::htmlTag($this->htmlTagName, array_merge($this->html, array('name' => $this->name, 'id' => $this->id, 'value' => $this->date->format('date', 'short2')))); }
public function to($type) { $ret = parent::to($type); if ($type == 'html' && $this->cfg->mode == 'edit') { $ret = '<span id="' . $this->id . 'Container">' . $ret . '</span>'; $resp = response::getInstance(); $resp->addJs('jqueryui'); $resp->addJs('formAutocomplete'); $prm = $this->cfg->jsPrm; $prm['name'] = $this->id . '[]'; $prm['nameNew'] = $this->id . '[new]'; $resp->blockJquery('$("#' . $this->id . 'Container").formAutocomplete(' . json_encode($prm) . ');'); } return $ret; }
public function check(array $url = null, $redirect=true) { if (is_null($url)) $url = request::get(); $hasRight = !$this->isContained($url, $this->cfg->spec); if (!$hasRight && $redirect) { $request = request::removeLangOutUrl('/'.request::get('request')); if ($request != $this->getPage('forbidden') && $request != $this->getPage('login')) { session::setFlash('nyroError', 'Don\'t have the permission to access to this page.'); response::getInstance()->redirect($this->getPage('forbidden', true), 403); } } return $hasRight; }
public function toHtml() { $ret = parent::toHtml(); if ($this->cfg->useJs) { $id = $this->makeid($this->name . '-slider'); $ret = '<div id="' . $id . '" class="range-slider"></div>' . $ret; $min = $this->cfg->getInarray('allowedRange', 'min'); $max = $this->cfg->getInarray('allowedRange', 'max'); if (!$min) { $min = 0; } if (!$max) { $max = 100; } $minVal = $this->getValue('min'); $maxVal = $this->getValue('max'); if (!$minVal) { $minVal = $min; } if (!$maxVal) { $maxVal = $max; } $resp = response::getInstance(); $resp->addJs('jqueryui'); $resp->blockJquery('$("#' . $id . '").slider({ range: true, min: ' . $min . ', max: ' . $max . ', values: [' . $minVal . ',' . $maxVal . '], slide: function(event, ui) { $("#' . $this->makeId($this->name . '[0]') . '").val(ui.values[0]); $("#' . $this->makeId($this->name . '[1]') . '").val(ui.values[1]); }, change: function() { $("#' . $this->makeId($this->name . '[0]') . '").change(); $("#' . $this->makeId($this->name . '[1]') . '").change(); } })' . ($this->cfg->disabled ? '.next(".range").find("input").attr("disabled", "disabled")' : null) . '; ;'); } return $ret; }
protected function execIndex(array $prm = array()) { $this->prepare(); $pattern = FILESROOT.$this->dir.DS.'*'; $search = http_vars::getInstance()->get('search'); if ($search) { $pattern.= strtolower($search).'*'; $this->uri.= 'search='.$search.'&'; } $delete = http_vars::getInstance()->get('delete'); if ($delete) { $file = FILESROOT.urldecode($delete); if (file::exists($file)) { file::delete($file); file::multipleDelete(substr($file, 0, -strlen(file::getExt($file))-1).'_*'); response::getInstance()->redirect($this->uri); } } $form = $this->getForm(); if (request::isPost()) { $form->refill(); if ($form->isValid()) response::getInstance()->sendText('ok'); } $files = array(); foreach(file::search($pattern) as $f) { if (strpos($f, 'nyroBrowserThumb') === false) { $name = basename($f); if ($this->type == 'image' && strlen($name) > 15) $name = substr($name, 0, 15).'...'.file::getExt($f); $files[] = array( $f, request::uploadedUri(str_replace(FILESROOT, '', $f), $this->myCfg['uploadedUri']), $name, file::humanSize($f), utils::formatDate(filemtime($f)), $this->uri.'delete='.urlencode(str_replace(FILESROOT, '', $f)).'&' ); } } $this->setViewVars(array( 'uri'=>$this->uri, 'form'=>$form, 'config'=>$this->config, 'type'=>$this->type, 'files'=>$files, 'searchButton'=>$this->myCfg['search'], 'search'=>$search, 'imgHelper'=>$this->myCfg['imgHelper'], 'filesTitle'=>$this->myCfg['filesTitle'], 'noFiles'=>$this->myCfg['noFiles'], 'name'=>$this->myCfg['name'], 'size'=>$this->myCfg['size'], 'date'=>$this->myCfg['date'], 'delete'=>$this->myCfg['delete'], )); }
/** * Website main */ public static function main() { define('NYROVERSION', '0.2'); $globalContent = null; $globalVars = null; $cacheInst = null; $cacheInstVars = null; try { self::init(); $resp = response::getInstance(); self::$cfg->overload(__CLASS__.'Response'); if (self::$cfg->globalCache && !request::isPost() && count($_GET) == 0 && $resp->canGlobalCache()) { $prm = is_array(self::$cfg->globalCache) ? self::$cfg->globalCache : array(); $cacheInst = cache::getInstance(array_merge(array('serialize'=>false), $prm)); $id = str_replace('/', '._.', '/'.request::get('request')).(request::isAjax() ? '-ajax' : ''); $cacheInst->get($globalContent, array( 'id'=>$id )); $cacheInstVars = cache::getInstance(array_merge(array('serialize'=>true), $prm)); $cacheInstVars->get($globalVars, array( 'id'=>$id.'-vars' )); } if (is_null($globalContent)) { request::execModule(); if (DEV) { debug::timer('nyroProcess'); debug::timer('nyroRender'); } $resp->setContent(request::publishModule()); } } catch (module_exception $e) { session::setFlash('nyroError', 'MODULE or ACTION NOT FOUND<br />'.self::handleError($e)); $resp->error(null, 404); } catch (nException $e) { session::setFlash('nyroError', self::handleError($e)); $resp->error(null, 500); } catch (PDOException $e) { session::setFlash('nyroError', self::handleError($e)); $resp->error(null, 500); } catch (Exception $e) { session::setFlash('nyroError', self::handleError($e)); $resp->error(null, 500); } try { factory::saveCache(); if ($cacheInst) { if ($globalContent) { $resp->setVarsFromGlobalCache($globalVars); echo $globalContent; } else { $globalVars = $resp->getVarsForGlobalCache(); $globalContent = $resp->send(); $cacheInst->save(); $cacheInstVars->save(); echo $globalContent; } } else { echo $resp->send(); } } catch (Exception $e) { echo debug::trace($e); } }
/** * Force the request to be secure, by redirting to the same url with https */ public static function forceSecure() { if (!self::get('secure')) response::getInstance()->redirect(str_replace('http://', 'https://', self::uriDef(array('absolute'=>1)))); }
public function check(array $url = null, $redirect = true) { if (is_null($url)) $url = request::get(); if ($this->isContained($url, $this->cfg->noSecurity)) return true; $hasRight = $this->cfg->default; if ($this->isContained($url, $this->cfg->spec)) { if ($hasRight) { $hasRight = $this->isLogged(); } else { $hasRight = true; } } else if ($this->isLogged()) { if (!empty($this->cfg->rightRoles)) { $checks = array(); foreach($this->hasRole() as $r=>$t) { $tmp = $this->cfg->getInArray('rightRoles', $r); if (is_array($tmp)) { foreach($tmp as $c) $checks[] = $c; } } $hasRight = $this->isContained($url, $checks); } else $hasRight = true; } if (!$hasRight && $redirect) { $request = request::removeLangOutUrl('/'.request::get('request')); if ($request != $this->getPage('forbidden') && $request != $this->getPage('login')) { $this->session->pageFrom = request::get('localUri'); session::setFlash('nyroError', $this->cfg->errorText); $this->hook('redirectError'); response::getInstance()->redirect($this->getPage('forbidden', true), 403); } } return $hasRight; }
/** * Get the HTML for the debugger, and add the CSS and JS to the response * * @param array $elts * @return string */ public static function debugger(array $elts = null) { if (is_null($elts)) { debug::timer('nyro'); debug::timer('nyroRender'); return debug::debugger(array('timing' => array('Timing', debug::timer(), 'time'), 'included' => array('Included Files', get_included_files(), array('name' => 'code_red', 'type' => 'script')), 'session' => array('Session vars', $_SESSION, 'shield'), 'db_queries' => array('DB Queries', db::log(), 'database'), 'consts' => array('Constants', array_reverse(get_defined_constants(true), true), array('name' => 'gear', 'type' => 'script')), 'request' => array('Request', request::get(), array('name' => 'right', 'type' => 'arrow')), 'cookies' => array('Cookies', $_COOKIE, array('name' => 'gray', 'type' => 'user')), 'get' => array('Get', $_GET, array('name' => 'show', 'type' => 'tag')), 'post' => array('Post', $_POST, array('name' => 'green', 'type' => 'tag')), 'files' => array('Files', $_FILES, array('name' => 'orange', 'type' => 'tag')), 'response' => array('Response', array('Headers' => response::getInstance()->getHeader(), 'Included Files' => response::getInstance()->getIncFiles()), array('name' => 'right', 'type' => 'arrow')))); } if (request::get('out') != 'html') { return; } $menu = array(); $content = array(); $close = utils::getIcon(array('name' => 'cross', 'type' => 'default', 'attr' => array('class' => 'close', 'alt' => 'Close'))); foreach ($elts as $k => $v) { $icon = array_key_exists(2, $v) ? utils::getIcon(is_array($v[2]) ? $v[2] : array('name' => 'show', 'type' => $v[2])) : null; $menu[] = '<a rel="' . $k . '">' . $icon . $v[0] . '</a>'; $tmp = '<div class="debugElt" id="' . $k . '" style="display: none;">' . $close . '<h2>' . $icon . $v[0] . '</h2>'; if (is_array($v[1])) { if (is_numeric(key($v[1])) && !is_array($v[1])) { $tmp .= '<ol><li>' . implode('</li><li>', $v[1]) . '</li></ol>'; } else { $tmp .= debug::trace($v[1]); } } else { $tmp .= $v[1]; } $tmp .= '</div>'; $content[] = $tmp; } $resp = response::getInstance(); return '<div id="nyroDebugger">' . $resp->getIncludeTagFile('js', 'debug') . $resp->getIncludeTagFile('css', 'debug') . '<ul><li id="close">' . $close . '</li><li>' . implode('</li><li>', $menu) . '</li></ul>' . implode("\n", $content) . '</div>'; }
protected function afterInit() { $this->responseProxy = response::getInstance()->getProxy(); }
protected function execScaffoldDelete($prm = null) { $id = $prm[0]; $this->row = $this->table->find($id); $this->hook('delete'); $this->hook('beforeDelete'); if ($this->row) $this->row->delete(); $this->hook('afterDelete'); response::getInstance()->redirect($this->indexPage); }
/** * Redirect the user if not logged * * @param null|string $page Page to redirect or configured page forbidden if not provided * @return true|void True if allowed, will be redirected if not */ public function protect($page = null) { if (!$this->isLogged()) response::getInstance()->redirect(request::uri($page? $page : $this->getPage('forbidden'))); return true; }
protected function execAdminLogout(array $prm = array()) { security::getInstance()->logout(); response::getInstance()->redirect(request::uri('/')); }
protected function afterInit() { $this->response = response::getInstance(); $this->isResponseProxy = ($this->response instanceof response_proxy); }
/** * Every called action must pass by this function * * @param null|string $prm Actopn Parameters * @throws nException if wrong parameter or other errors */ final public function exec(array $prm=array()) { $this->prmExec = array_merge(array( 'module'=>$this->getName(), 'action'=>'index', 'param'=>'', 'paramA'=>null, 'prefix'=>null), $prm); $this->prmExec['prefix'] = null; if (array_key_exists(NYROENV, $this->cfg->basicPrefixExec) && in_array($this->prmExec['action'], $this->cfg->getInArray('basicPrefixExec', NYROENV))) $this->prmExec['prefix'] = ucfirst(NYROENV); else if ($this->cfg->prefixExec && !in_array($this->prmExec['action'], $this->cfg->noPrefixExec)) $this->prmExec['prefix'] = $this->cfg->prefixExec; $this->beforeExec($prm); if (!$this->cfg->render) security::getInstance()->check($this->prmExec); $fctName = ($this->cfg->render? 'render' : 'exec').$this->prmExec['prefix'].ucfirst($this->prmExec['action']); if (!method_exists($this, $fctName)) response::getInstance()->error(); $this->setViewAction($this->prmExec['action']); $param = is_array($this->prmExec['paramA'])? $this->prmExec['paramA'] : request::parseParam($this->prmExec['param']); $tags = $this->cfg->cacheTags; $search = array('/', '<', '>'); $replace = array('', '', ''); if (is_array($this->prmExec['paramA'])) foreach($this->prmExec['paramA'] as $k=>$v) { if (is_object($v)) { if (is_callable(array($v, '__toString'))) $tags[] = $k.'='.$v; else $tags[] = $k.'='.get_class($v); } elseif (!is_numeric($k)) $tags[] = $k.'='.str_replace($search, $replace, $v); else $tags[] = str_replace($search, $replace, $v); } $paramTpl = array(); foreach($param as $k=>$v) { if (is_object($v)) { if (is_callable(array($v, '__toString'))) $paramTpl[] = $k.'='.$v; else $paramTpl[] = $k.'='.get_class($v); } else $paramTpl[] = $k.':'.$v; } $conf = array( 'layout'=>$this->cfg->layout, 'module'=>$this->getName(), 'action'=>$this->cfg->viewAction, 'param'=>implode(',', $paramTpl), 'cache'=>array_merge(array( 'enabled'=>$this->isCacheEnabled(), 'serialize'=>false, 'tags'=>$tags, 'request'=>array('uri'=>false, 'meth'=>array()) ), $this->cfg->cache) ); $this->tpl = factory::get('tpl', array_merge_recursive($conf, $this->cfg->tplPrm)); $this->tpl->getCfg()->layout = $this->cfg->layout; $this->tpl->getCfg()->module = $this->getName(); $this->tpl->getCfg()->action = $this->cfg->viewAction; $this->tpl->getCfg()->default = $this->cfg->viewAction; $this->prmExec['callbackPrm'] = array( 'fctName'=>$fctName, 'fctNameParam'=>$param, 'prm'=>$prm ); $this->middleExec($prm); }
public function toHtml() { if ($this->cfg->mode == 'view') { return $this->cfg->value->getView(); } $start = $end = null; if ($this->cfg->showPreview || $this->cfg->showDelete) { $start = '<' . $this->cfg->htmlWrap . '>'; if ($this->cfg->value->getCurrent()) { $end .= '<input type="hidden" name="' . $this->name . 'NyroKeep" value="' . $this->cfg->value->getCurrent() . '" />'; $end .= '<span>'; if ($this->cfg->showDelete) { $end .= '<a href="#" class="deleteFile" id="' . $this->id . 'NyroDel">' . $this->cfg->deleteLabel . '</a>'; response::getInstance()->blockJquery(' $("#' . $this->id . 'NyroDel").click(function(e) { e.preventDefault(); $(this).parent("span").replaceWith("<input type=\\"hidden\\" name=\\"' . $this->name . 'NyroDel\\" value=\\"1\\" />"); });'); } else { $end .= '<br />'; } if ($this->cfg->showPreview) { $end .= $this->cfg->value->getView(); } $end .= '</span>'; } $end .= '</' . $this->cfg->htmlWrap . '>'; } return $start . utils::htmlTag($this->htmlTagName, array_merge($this->html, array('name' => $this->name, 'id' => $this->id))) . $end; }
/** * Transform the element to a string to be shown * * @param string $type The output type * @return string */ public function to($type) { $this->addCaptcha(); $ret = null; $prm = $this->cfg->get($type); if ($this->cfg->check($tmp = $type . ucfirst($this->cfg->mode))) { $prm = array_merge($prm, $this->cfg->get($tmp)); } if (!$this->cfg->showSection) { $prm = array_merge($prm, $this->cfg->get($type . 'NoSection')); if ($this->cfg->check($tmp = $type . 'NoSection' . ucfirst($this->cfg->mode))) { $prm = array_merge($prm, $this->cfg->get($tmp)); } } $hiddenGlobal = is_array($prm) && (array_key_exists('noHidden', $prm) && $prm['noHidden']) || !(strpos($prm['global'], '[hidden]') === false); $hiddens = null; $errorPos = $prm['errorPos']; $errorsGlobal = array(); foreach ($this->section as $kSection => $sectionName) { $fields = null; $errorsSection = array(); foreach ($this->elements[$kSection] as $name => $e) { $des = $e->description ? str_replace('[des]', $e->getDescription(), $prm['des']) : null; $line = $e->isHidden() ? 'lineHidden' : 'line'; $errors = null; if ($this->isBound() && !$e->isValid() && !$e->isHidden()) { $tmp = array(); foreach ($e->getErrors() as $err) { $tmp[] = str_replace('[error]', $err, $prm['lineErrorLine']); $errorsSection[] = str_replace('[error]', $err, $prm['sectionErrorLine']); $errorsGlobal[] = str_replace('[error]', $err, $prm['globalErrorLine']); } $errors = $errorPos == 'field' ? str_replace('[errors]', implode('', $tmp), $prm['lineErrorWrap']) : null; $line = 'lineError'; } $requiredMoreLabel = $e->getValidRule('required') ? $this->cfg->requiredMoreLabel : null; $label = $e->label ? $e->label . $requiredMoreLabel . $this->cfg->sepLabel : $this->cfg->emptyLabel; $tmp = str_replace(array('[des]', '[label]', '[field]', '[errors]', '[id]', '[classLine]'), array($des, $label, $e->to($type), $errors, $e->id, $e->classLine), $prm[$line]); if ($e->isHidden() && $hiddenGlobal) { $hiddens .= $tmp; } else { $fields .= $tmp; } } if ($fields) { $errors = null; $section = 'section'; if (!empty($errorsSection) && $errorPos == 'section') { $errors = implode('', $errorsSection); $section .= 'Error'; } $ret .= str_replace(array('[errors]', '[fields]', '[label]'), array($errors, $fields, $this->cfg->outSection ? utils::htmlOut($sectionName) : $sectionName), $prm[$section]); } } $plus = null; if ($type == 'html') { if (array_key_exists('incFiles', $prm)) { foreach ($prm['incFiles'] as $f) { response::getInstance()->add($f); } } $plus = 'action="' . $this->cfg->action . '" method="' . $this->cfg->method . '"'; if ($this->hasFiles) { $plus .= ' enctype="multipart/form-data"'; } } $plus .= $this->cfg->formPlus; $errors = null; if (!empty($errorsGlobal) && $errorPos == 'global') { $errors = str_replace('[errors]', implode('', $errorsGlobal), $prm['globalError']); } return str_replace(array('[hidden]', '[errors]', '[content]', '[plus]', '[submit]', '[submitText]', '[submitPlus]'), array($hiddens, $errors, $ret, $plus, $prm['submit'], $this->cfg->submitText, $this->cfg->submitPlus), $prm['global']); }
/** * Create the data Table out * * @param string $type Out type * @return string */ public function to($type) { $tpl = factory::get('tpl', array('module' => $this->cfg->module, 'action' => $this->cfg->name, 'default' => 'dataTable', 'cache' => $this->cfg->cache, 'layout' => false)); $data = $this->getData(); if (count($data)) { if (empty($this->cfg->fields)) { $headersT = $data->getFields('flatReal'); if ($keyRelated = array_search('related', $headersT)) { unset($headersT[$keyRelated]); } foreach ($this->table->getI18nFields() as $f) { $headersT[] = db::getCfg('i18n') . $f['name']; } } else { $headersT = $this->cfg->fields; if ($this->cfg->addIdentField && !in_array($this->table->getIdent(), $headersT)) { array_unshift($headersT, $this->table->getIdent()); } } $headers = array(); $prmReplaceSortBy = '[sortBy]'; $prmReplaceSortDir = '[sortDir]'; $paramUrlA = request::get('paramA'); unset($paramUrlA['page' . $this->cfg->nameParam]); $paramUrlA['sortBy' . $this->cfg->nameParam] = $prmReplaceSortBy; $paramUrlA['sortDir' . $this->cfg->nameParam] = $prmReplaceSortDir; $paramUrlA['page' . $this->cfg->nameParam] = 1; $tmpSortLink = request::uriDef(array('paramA' => $paramUrlA)); foreach ($headersT as $k => $h) { $typeField = $this->table->getField($h, 'type'); if ($typeField == 'file' && is_array($tmp = $this->table->getField($h, 'comment')) && array_key_exists(0, $tmp)) { $typeField = $tmp[0]; } $headers[$k] = array('label' => $this->table->getLabel($h), 'name' => $h, 'url' => str_replace(array($prmReplaceSortBy, $prmReplaceSortDir), array(db::isI18nName($h) ? $this->table->getI18nTable()->getName() . '_' . db::unI18nName($h) : $h, $this->cfg->sortBy == $h && $this->cfg->sortDir == 'asc' ? 'desc' : 'asc'), $tmpSortLink), 'type' => $typeField); } $actions = null; $actionsAlt = null; $actionsImg = null; if (is_array($this->cfg->actions) && !empty($this->cfg->actions)) { $actions = array(); if (!$this->cfg->addIdentField) { array_unshift($headersT, $this->table->getIdent()); } array_walk($headersT, create_function('&$h', '$h = "[".$h."]";')); $dataK = null; $i = 0; foreach ($data as $d) { $tmp = $this->getActions($d); $tmpVals = $d->getValues('flatNoRelated'); $vals = array(); foreach ($headersT as $k => $v) { $v = substr($v, 1, -1); $vals[$k] = array_key_exists($v, $tmpVals) ? $tmpVals[$v] : null; } $curData = $d->getValues('data'); unset($curData['related']); unset($curData['linked']); if (is_null($dataK)) { $dataK = array_keys($curData); array_walk($dataK, create_function('&$h', '$h = "[".$h."]";')); } foreach ($tmp as &$t) { $t = str_replace($dataK, $curData, $t); } $actions[$i] = $tmp; $i++; } if (!empty($actions) && $this->cfg->actionsConfirmDelete) { response::getInstance()->addJs('actionsConfirmDelete'); } $actionsKey = array_keys($this->cfg->actions); $actionsAlt = $this->cfg->actionsAlt; if (!is_array($actionsAlt) || count($actionsAlt) < count($actionsKey)) { foreach ($actionsKey as $v) { if (!array_key_exists($v, $actionsAlt)) { $actionsAlt[$v] = ucfirst($v); } } } $actionsImg = $this->cfg->actionsImg; foreach ($actionsKey as $v) { if (!array_key_exists($v, $actionsImg)) { $actionsImg[$v] = utils::getIcon(array('name' => $v, 'attr' => array('title' => $actionsAlt[$v]), 'alt' => $actionsAlt[$v], 'type' => $this->cfg->iconType)); } } } if ($this->cfg->sortBy) { $paramUrlA['sortBy' . $this->cfg->nameParam] = $this->cfg->sortBy; $paramUrlA['sortDir' . $this->cfg->nameParam] = $this->cfg->sortDir; } else { unset($paramUrlA['sortBy' . $this->cfg->nameParam]); unset($paramUrlA['sortDir' . $this->cfg->nameParam]); } $nbPage = $this->getNbPage(); $pageLinks = array(); $prmReplace = $this->cfg->pageLinkReplace; if (!$this->cfg->pageLinkTpl) { $paramUrlA['page' . $this->cfg->nameParam] = $prmReplace; $tmpPageLink = request::uriDef(array('paramA' => $paramUrlA)); } else { $tmpPageLink = $this->cfg->pageLinkTpl; } for ($i = 1; $i <= $nbPage; $i++) { $pageLinks[$i] = str_replace($prmReplace, $i, $tmpPageLink); } if ($this->cfg->pageLinkTpl1) { $pageLinks[1] = $this->cfg->pageLinkTpl1; } $hasMultiple = count($this->cfg->multiple) > 0; if ($hasMultiple && $this->cfg->addCheckAllJs) { response::getInstance()->addJs('checkAll'); } $tpl->setA(array_merge(array('headers' => $headers, 'list' => $data, 'nbPage' => $nbPage, 'currentPage' => $this->cfg->page, 'pageLinks' => $pageLinks, 'actions' => $actions, 'actionsImg' => $actionsImg, 'actionsAlt' => $actionsAlt, 'iconType' => $this->cfg->iconType, 'tblName' => $this->table->getName(), 'sortBy' => $this->cfg->sortBy, 'sortByReal' => $this->sortBy, 'sortDir' => $this->cfg->sortDir, 'hasMultiple' => $hasMultiple, 'multipleLabel' => $this->cfg->multipleLabel, 'multipleSubmit' => $this->cfg->multipleSubmit, 'multipleAction' => $this->cfg->multipleAction, 'multipleIdent' => $this->table->getIdent(), 'multiple' => $this->cfg->multiple), $this->cfg->tplVars)); } else { // No data if ($this->cfg->page > 1) { $newPage = $this->cfg->page - 1; $uri = null; if ($newPage == 1 && $this->cfg->pageLinkTpl1) { $uri = $this->cfg->pageLinkTpl1; } if (!$uri) { $prmReplace = $this->cfg->pageLinkReplace; if (!$this->cfg->pageLinkTpl) { $paramUrlA = request::get('paramA'); unset($paramUrlA['page' . $this->cfg->nameParam]); $prmReplaceSortBy = '[sortBy]'; $prmReplaceSortDir = '[sortDir]'; $paramUrlA['sortBy' . $this->cfg->nameParam] = $prmReplaceSortBy; $paramUrlA['sortDir' . $this->cfg->nameParam] = $prmReplaceSortDir; $paramUrlA['page' . $this->cfg->nameParam] = 1; if ($this->cfg->sortBy) { $paramUrlA['sortBy' . $this->cfg->nameParam] = $this->cfg->sortBy; $paramUrlA['sortDir' . $this->cfg->nameParam] = $this->cfg->sortDir; } else { unset($paramUrlA['sortBy' . $this->cfg->nameParam]); unset($paramUrlA['sortDir' . $this->cfg->nameParam]); } $paramUrlA['page' . $this->cfg->nameParam] = $prmReplace; $tmpPageLink = request::uriDef(array('paramA' => $paramUrlA)); } else { $tmpPageLink = $this->cfg->pageLinkTpl; } $uri = str_replace($prmReplace, $newPage, $tmpPageLink); } response::getInstance()->redirect($uri); } $tpl->set('noData', utils::htmlOut($this->cfg->noData)); $tpl->set('list', null); $tpl->setA($this->cfg->tplVars); } return $tpl->fetch(array('tplExt' => $type)); }
/** * Compress the file requested, using MoxieCompressor library * * @param string $type File type (css or js) * @param array $prm Files to compress */ protected function compress($type, $prm) { $resp = response::getInstance(); if ($type == 'js') { $conf = $this->cfg->all; factory::mergeCfg($conf, $this->cfg->js); } else if ($type == 'css') { $conf = $this->cfg->all; factory::mergeCfg($conf, $this->cfg->css); } $key = $type.'--'.md5(serialize($prm)).'--'.md5(serialize($conf)); $supportsGzip = false; if ($conf['compress']) { $encodings = isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? explode(',', strtolower(preg_replace("/\s+/", "", $_SERVER['HTTP_ACCEPT_ENCODING']))) : array(); if ($conf['gzip_compress'] && (in_array('gzip', $encodings) || in_array('x-gzip', $encodings) || isset($_SERVER['---------------'])) && function_exists('gzencode') && !ini_get('zlib.output_compression')) { $enc = in_array('x-gzip', $encodings) ? 'x-gzip' : 'gzip'; $supportsGzip = true; $key = 'gzip-'.$key; } } $content = null; $cache = cache::getInstance($this->cfg->cache); $cacheDate = $cache->get($content, array('id'=>$key)); if (!$conf['disk_cache'] || !$cacheDate) { foreach($prm as $file) { $f = file::nyroExists(array( 'name'=>'module_'.nyro::getCfg()->compressModule.'_'.$type.'_'.$file, 'type'=>'tpl', 'tplExt'=>$type )); if ($f) { if ($conf['php']) $content.= file::fetch($f); else $content.= file::read($f); } } if ($conf['compress']) { if ($type == 'js') { lib::load('jsMin'); $content = JSMin::minify($content); } else if ($type == 'css') { lib::load('cssMin'); $content = CssMin::minify($content, $conf['filters'], $conf['plugins']); } if ($supportsGzip) $content = gzencode($content, 9, FORCE_GZIP); } $cache->save(); } else if ($cacheDate) { $resp->addHeader('Age', time() - $cacheDate); } /* @var $resp response_http */ if ($conf['compress']) { $resp->setCompress(false); $resp->addHeader('Vary', 'Accept-Encoding'); // Handle proxies if ($conf['etags'] || preg_match('/MSIE/i', $_SERVER['HTTP_USER_AGENT'])) { // We need to use etags on IE since it will otherwise always load the contents $resp->addHeader('ETag', md5($content)); } $parseTime = $this->_parseTime($conf['expires_offset']); $resp->addHeader('Expires', gmdate('D, d M Y H:i:s', time() + $parseTime).' GMT'); $resp->addHeader('Cache-Control', 'public, max-age='.$parseTime); if ($type == 'js') { // Output explorer workaround or compressed file if (!isset($_GET['gz']) && $supportsGzip && $conf['patch_ie'] && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) { // Build request URL $url = $_SERVER['REQUEST_URI']; if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']) $url.= '?'.$_SERVER['QUERY_STRING'].'&gz=1'; else $url.= '?gz=1'; // This script will ensure that the gzipped script gets loaded on IE versions with the Gzip request chunk bug echo 'var gz;try {gz = new XMLHttpRequest();} catch(gz) { try {gz = new ActiveXObject("Microsoft.XMLHTTP");}'; echo 'catch (gz) {gz = new ActiveXObject("Msxml2.XMLHTTP");}}'; echo 'gz.open("GET", "'.$url.'", false);gz.send(null);eval(gz.responseText);'; die(); } } if ($supportsGzip) $resp->addHeader('Content-Encoding', $enc); } $resp->sendText($content); }