* @since 1.0 * @package MammutCMS * @subpackage Module */ abstract class MMModBase extends \MCMS\Module\Base { /** * This method has to return the module id with namespace. * * @return string the module id */ protected abstract function getMyId(); protected function findLayout($siteId, $instance) { $layout = System::getInstance()->getSiteParam($siteId, $instance, 'layout', '_default_'); if(empty($layout) || trim($layout) == '') $layout = '_default_'; return $layout; } /** * loads a MFC template file * * @param string $modId * the module id * @param string $name * @param string $layout * @return MFCTemplate the generated template */ protected function loadTemplate($modId, $name, $layout = '_default_', $extended = false) { $ua = System::getInstance()->getRequest()->getUserAgent(); $modId = strtolower($modId); $name = strtolower($name); $tplfile = false; if($layout[0] == '*') { $base = _LAYOUTPATHX_ . __DS__ . '_module_'; $layout = substr($layout, 1); } else $base = $extended ? _MODPATHX_ : _MODPATH_; if($ua->isMobile()) { $layoutFile = $base . __DS__ . str_replace('.', __DS__, $modId) . __DS__ . '_layout_' . __DS__ . $layout . __DS__ . 'tpl.' . $name . '.mobile.php'; if(include_exists($layoutFile)) $tplfile = $layoutFile; if($ua->isSmallScreen()) { $layoutFile = $base . __DS__ . str_replace('.', __DS__, $modId) . __DS__ . '_layout_' . __DS__ . $layout . __DS__ . 'tpl.' . $name . '.small.php'; if(include_exists($layoutFile)) $tplfile = $layoutFile; } } elseif($ua->isConsole()) { $layoutFile = $base . __DS__ . str_replace('.', __DS__, $modId) . __DS__ . '_layout_' . __DS__ . $layout . __DS__ . 'tpl.' . $name . '.console.php'; if(include_exists($layoutFile)) $tplfile = $layoutFile; } if(empty($tplfile)) { $layoutFile = $base . __DS__ . str_replace('.', __DS__, $modId) . __DS__ . '_layout_' . __DS__ . $layout . __DS__ . 'tpl.' . $name . '.php'; if(include_exists($layoutFile)) $tplfile = $layoutFile; else throw new \Mammut\IO\FileNotFoundException($layout); } $template = new \Mammut\Template\CTemplate(); $template->loadTemplate($tplfile); return $template; } /** * loads a MFC template file * * @param string $modId * the module id * @param string $name * @param string $layout * the name of the layout * @param string $extended * use extended module directory * @param boolean $fs * return true to return filesystem path instead of an url * @return MFCTemplate the generated template */ protected function getLayoutCSSFiles($modId, $name, $layout = '_default_', $extended = false, $fs = false) { $ua = System::getInstance()->getRequest()->getUserAgent(); $modId = strtolower($modId); $name = strtolower($name); $S = ($fs ? __DS__ : '/'); // dir separator if($layout[0] == '*') { $file = _LAYOUTPATHX_ . __DS__ . '_module_'; $base = ($fs ? _LAYOUTPATHX_ : _LAYOUTURLX_) . __DS__ . '_module_'; $layout = substr($layout, 1); } else { $file = $extended ? _MODPATHX_ : _MODPATH_; $base = $extended ? ($fs ? _MODPATHX_ : _MODURLX_) : ($fs ? _MODPATH_ : _MODURL_); } $filepath = $file . __DS__ . str_replace('.', __DS__, $modId) . __DS__ . '_layout_' . __DS__ . $layout . __DS__; $basepath = $base . $S . str_replace('.', $S, $modId) . $S . '_layout_' . $S . $layout . $S; $result = array(); /* if ($ua->isMobile()) { $layoutFile = $base.__DS__.str_replace('.',__DS__,$modId).__DS__.'_layout_'.__DS__.$layout.__DS__.'tpl.'.$name.'.mobile.php'; if (include_exists($layoutFile)) $tplfile = $layoutFile; if ($ua->isSmallScreen()) { $layoutFile = $base.__DS__.str_replace('.',__DS__,$modId).__DS__.'_layout_'.__DS__.$layout.__DS__.'tpl.'.$name.'.small.php'; if (include_exists($layoutFile)) $tplfile = $layoutFile; } } */ if(include_exists($filepath . 'style.css')) $result[] = $basepath . 'style.css'; return $result; } /** * Copy the css info of the template into the form editor * * @param string $templatename * the name of the parameter in the template * @param MFCTemplate $template * the template in which should the parameters be read * @param string $fieldname * the name of the field in the form builder (model) * @param MMComFormBase $form * the form which is created and contains the model */ protected function css2template($templatename,\Mammut\Template\CTemplate &$template, $fieldname, \MCMS\_\Com\MCMS\Form\FormBase &$form) { $param = array(); $fp = $template->getParamParams($templatename); if(isset($fp['css'])) $param[\MCMS\_\Com\MCMS\Form\Builder::EP_INLINE_CSS] = $fp['css']; if(!empty($param)) $form->setEditorParams($fieldname, $param); } /** * @param mixed $locale the locale information * @param string $basedir the base directory where the locale dir should be searched, usually __DIR__ */ protected function loadLocaleStrings($locale, $basedir) { if (!is_dir($basedir)) throw new \InvalidArgumentException('$basedir is not a directory'); $basedir = $basedir . __DS__ . '_lib_' . __DS__ . 'locale' . __DS__; $strings = array_from_file($basedir . '_default_.php', 'lang'); if(is_object($locale)) $locale = $locale->getId(); if(file_exists($basedir . $locale . '.php')) $strings = array_merge($strings, array_from_file($basedir . $locale . '.php', 'lang')); return $strings; } protected function userHasPriv(iUser $user, $site, $instance, $key) { $system = System::getInstance(); $usrSvc = $system->getUserSvc(); return $usrSvc->userHasPriv($user, $site, $instance, $key); } public function getContentType($actionId, $medium) { return 'text/html'; } /** * Displayes a text */ public function runIndex(Request $request, Response $response, $activeInstance) { $response->setFragment('CONTENT', 'Hello world!'); // render the template end put the result in the response } }