module; } public function run(\MCMS\Response &$response, $step, \MCMS\Context $context) { if($step == iPlugInContent::STEP_RUN) { $system = System::getInstance(); $db = $system->getDB(); // $site = $db->getObject("SELECT * FROM websites WHERE id=" . $system->getSiteId()); // if($site->online == 'offline') // return; $instanceName = $system->getTarget('instance'); if($instanceName == '*') return; try { $allowed = false; $info = NULL; // if($system->cacheExists($system->getSiteId(), '$p:mcms.mmpimaincontent:modinstinfo', $instanceName)) { // $info = $system->cacheFetch($system->getSiteId(), '$p:mcms.mmpimaincontent:modinstinfo', $instanceName); // } // if(empty($info)) { // $info = $system->getDB()->table('moduleinstances')->getObject(array( // 'instance' => $instanceName,'site_id' => $system->getSiteId())); // $system->cacheStore($system->getSiteId(), '$p:mcms.mmpimaincontent:modinstinfo', $instanceName, $info, 60); // } // if(is_null($info) || $info === false) // throw new RuntimeException('no module found for ident ' . $instanceName); $usrSvc = $system->getUserSvc(); $usr = $usrSvc->getUser(); // $realName = $this->getRealName($info); switch (strtolower($instanceName)) { case 'ca': $realName = 'cace.ca'; $allowed = true; break; case 'cert': $realName = 'cace.cert'; $allowed = true; break; default: $realName = 'cace.home'; $allowed = true; break; } // $installInfo = $system->getDB()->table('installinfo')->getArray(array( // 'type' => 'module','key' => $realName)); // $modInfo = getModuleInfo($realName); // if((!isset($modInfo['noinstall']) || $modInfo['noinstall'] != true) && $installInfo['version'] != $modInfo['version']) // throw new \Mammut\Exception\IllegalStateException('module "' . $realName . '"needs upgrade, log in as administrator!'); // $allowed = false; $allowed = true; // if(!is_null($usr) && $usrSvc->userHasPriv($usr, $system->getSiteId(), false, false)) // $allowed = true; // else { // switch($info->visible) { // case 'all': // $allowed = true; // break; // case 'user': // if(is_null($usr)) // break; // $allowed = true; // break; // case 'acl': // if(is_null($usr)) // break; // if($system->getDB()->table('moduleinstanceacl')->getObject(array( // 'instance' => $instanceName,'site_id' => $system->getSiteId(), // 'account_id' => $usr->getId()))) { // $allowed = true; // } // // TODO: add group support // // TODO: add timing support // break; // case 'none': // default: // $response->addError(403, 'Access denied', 'http'); // break; // } // } if($allowed) { $classname = loadModule($realName); if(class_exists($classname)) { $obj = new $classname(); if($obj instanceof \MCMS\Module\iModule) $activeInstance = &$obj; else throw new \Mammut\Exception\IllegalStateException('class does not define the module interface: ' . $classname); } else throw new \MCMS\Exception\PageNotFoundException('class for module ' . $realName . ' not found'); $response->setFragment('CONTENT', 'Warning: Module did not fill the CONTENT fragment'); $activeInstance->handleAction($response); } else $response->setFragment('CONTENT', 'Not found or access denied'); } catch(\RuntimeException $e) { if ($e instanceof \Mammut\Exception\IllegalStateException) throw $e; if(defined('DEBUG')) if($e instanceof \Mammut\IO\IOException) $response->addError(500, 'Internal module error: ' . get_class($e) . ': ' . $e->getMessage() . ' [' . $e->getContext() . '] ' . ' @ ' . $e->getFile() . ':' . $e->getLine(), 'http', $e); else $response->addError(500, 'Internal module error: ' . get_class($e) . ': ' . $e->getMessage() . ' @ ' . $e->getFile() . ':' . $e->getLine(), 'http', $e); else $response->addError(404, 'Undefined module instance ' . $instanceName, 'http', $e); } } } public function __destruct() { } }