public function formUpdateTemplate()
 {
     $model = new Template($this->data->id);
     $this->data->object = $model->getData();
     $this->data->save = "@fnbr20/structure/template/updateTemplate|formUpdateTemplate";
     $this->data->close = "!\$('#formUpdateTemplate_dialog').dialog('close');";
     $this->data->title = 'Template: ' . $model->getEntry() . '  [' . $model->getName() . ']';
     $this->render();
 }
Example #2
0
 /**
  * Build and return admin interface
  * 
  * Any module providing an admin interface is required to have this function, which
  * returns a string containing the (x)html of it's admin interface.
  * @return string
  */
 function getAdminInterface()
 {
     $this->addCSS('/modules/Templater/css/templates.css');
     $templates = Template::getAllTemplates();
     if (!isset($_REQUEST['template_id'])) {
         $template_data = htmlspecialchars($templates[0]->getData());
         $this->smarty->assign('template_data', $template_data);
         $this->smarty->assign('curtemplate', $templates[0]);
     } else {
         if (isset($_REQUEST['save'])) {
             $t = new Template($_REQUEST['template_id']);
             $t->setData(u($_REQUEST['editor']));
             $t->setTimestamp(date('Y-m-d H:i:s'));
             $t->setId(null);
             $t->save();
             $template_data = htmlspecialchars($t->getData());
             $this->smarty->assign('template_data', $template_data);
             $this->smarty->assign('curtemplate', $t);
             $templates = Template::getAllTemplates();
         } else {
             if (isset($_REQUEST['switch_template'])) {
                 $this->smarty->clear_assign('curtemplate');
                 $myTemplate = new Template($_REQUEST['template']);
                 $template_data = htmlspecialchars($myTemplate->getData());
                 $this->smarty->assign('template_data', $template_data);
                 $this->smarty->assign('curtemplate', $myTemplate);
             } else {
                 if (isset($_REQUEST['switch_revision'])) {
                     $this->smarty->clear_assign('curtemplate');
                     $myTemplate = new Template($_REQUEST['revision']);
                     $template_data = htmlspecialchars($myTemplate->getData());
                     $this->smarty->assign('template_data', $template_data);
                     $this->smarty->assign('curtemplate', $myTemplate);
                 } else {
                     $myTemplate = new Template($_REQUEST['template_id']);
                     $template_data = htmlspecialchars($myTemplate->getData());
                     $this->smarty->assign('curtemplate', $myTemplate);
                     $this->smarty->assign('template_data', $template_data);
                 }
             }
         }
     }
     $this->smarty->assign('templates', $templates);
     return $this->smarty->fetch('admin/templates.tpl');
 }
 public static function loadTemplateByRemote($folder)
 {
     $path = Core::GetConfig("templateProvider") . "?do=download&folderName=" . $folder;
     $remoteFileURL = Utils::getWebContent($path);
     $localFile = Core::GetConfig("dirIntScripts") . "installing.zip";
     $tempDirectory = Core::GetConfig("dirIntScripts") . "installing/";
     if (file_exists($localFile)) {
         unlink($localFile);
     }
     if (is_dir($tempDirectory)) {
         Utils::rmdir_recursive($tempDirectory);
     }
     // Download and prepare
     Utils::downloadFile($localFile, $remoteFileURL);
     Utils::unzip($localFile, $tempDirectory);
     // XML and Data
     if (file_exists($tempDirectory . "info.xml")) {
         $xmltext = file_get_contents($tempDirectory . "info.xml");
         $xml = simplexml_load_string($xmltext);
         $data = TemplateManager::_validateTemplateInformation(Utils::xmlToArray($xml));
         // Create Template
         $t = new Template();
         $t->setSetting("scriptVersion", $data["scriptVersion"]);
         $t->setSetting("gameName", $data["gameName"]);
         $t->setSetting("iconFile", $data["iconFile"]);
         $t->setSetting("folderName", $folder);
         $t->setSetting("infoxml", $xmltext);
         if (isset($data["settingsFile"])) {
             $t->setSetting("settingsxml", Template::replaceVariablesWithValues(file_get_contents($tempDirectory . $data["settingsFile"])));
         }
         // Base Template (One-Time-Install. No Gameserver)
         if (isset($data['isBaseTemplate'])) {
             if ($data['isBaseTemplate'] == "True") {
                 $t->setSetting("baseTemplate", 1);
             } else {
                 $t->setSetting("baseTemplate", 0);
             }
         } else {
             $t->setSetting("baseTemplate", 0);
         }
         $t->saveToDatabase();
         // Move Icon File
         $tempIcon = $tempDirectory . $t->getData("iconFile");
         $newIcon = $t->getIconFile();
         copy($tempIcon, $newIcon);
         Utils::rmdir_recursive($tempDirectory);
         if ($t->getData("id") != 0) {
             rename($localFile, $t->getZipFile());
         } else {
             unlink($localFile);
         }
         return $t;
     } else {
         throw new Exception("Info.xml doesnt exists in downloaded script. Aborting.");
     }
 }
         }
     }
 }
 // Template ID
 $err = @Utils::checkInput($_POST['templateid'], "Template ID", 1, 64, INPUT_TYPE_NUMERIC);
 if (strlen($err) != 0) {
     $error[] = $err;
 } else {
     if (!TemplateManager::existsById($_POST['templateid'])) {
         $error[] = "The given Template doesnt exist.";
     } else {
         $template = new Template($_POST['templateid']);
         if ($template->isBaseTemplate()) {
             $error[] = "The given Template is not a gameserver template.";
         } else {
             $gameName = $template->getData("gameName");
         }
     }
 }
 // Customer ID
 $err = @Utils::checkInput($_POST['customerid'], "Customer ID", 1, 64, INPUT_TYPE_NUMERIC);
 if (strlen($err) != 0) {
     $error[] = $err;
 } else {
     if (!UserManager::existsById($_POST['customerid'])) {
         $error[] = "The given User doesnt exist.";
     } else {
         $user = new User($_POST['customerid']);
         $userName = $user->getData("username") . " (" . $user->getData("prename") . " " . $user->getData("lastname") . ")";
     }
 }
Example #5
0
                }
                if (isset($server) && $server->getData("status") == 0) {
                    $error[] = "The server wasnt initialized yet.";
                }
                $templateid = isset($_POST['templateID']) ? $_POST['templateID'] : "";
                if (empty($templateid)) {
                    $errors[] = "No template id set.";
                } else {
                    if (!is_numeric($sid)) {
                        $errors[] = "The given template id was invalid.";
                    } else {
                        if (!TemplateManager::existsById($templateid)) {
                            $errors[] = "The given template id doesn't exist.";
                        } else {
                            $tpl = new Template($templateid);
                        }
                    }
                }
                if (count($errors) == 0) {
                    $page->assign("t_Report", Reporting::success("The Template \"" . $tpl->getData("gameName") . "\" will be installed on \"" . $server->getData("name") . "\" soon. (Task planned)"));
                    $server->addTask(TASK_SERVER_INSTALL_TEMPLATE, $tpl->getData("id"));
                } else {
                    $page->assign("t_Report", Reporting::error(Utils::buildErrorString($errors)));
                }
            }
        }
    }
}
$page->assign("templateCount", TemplateManager::getCount());
$page->assign("templates", TemplateManager::getAll());
$page->display();
 /**
  * Adds a template.
  *
  * @param \Template $template The message.
  *
  * @return void
  */
 public function addTemplate($template)
 {
     $this->messages[] = array('message' => $template->getData(), 'label' => $template->getName(), 'time' => microtime(true));
 }
Example #7
0
 public function execute()
 {
     $done = true;
     if (!$this->_validate()) {
         return $this->delete();
     }
     try {
         switch ($this->getData("type")) {
             case TASK_SERVER_INIT:
                 $err = $this->server->initializeForUse();
                 if (strlen($err) == 0) {
                     Core::addToTaskLog("Server " . $this->getData("serverID") . " has been initialized.");
                 } else {
                     Core::addToTaskLog("Server " . $this->getData("serverID") . " could not be initialized. Reason: {$err}.");
                 }
                 break;
             case TASK_SERVER_UPDATE:
                 $server = new PhysicalServer($this->getData('serverID'));
                 $server->updateServer();
                 Core::addToTaskLog("Server " . $this->getData("serverID") . " has been updated");
                 break;
             case TASK_SERVER_INSTALL_TEMPLATE:
                 if (!PhysicalServerManager::existsById($this->getData("serverID"))) {
                     $this->delete();
                 }
                 if (!TemplateManager::existsById($this->getData("addInfo"))) {
                     $this->delete();
                 }
                 $server = new PhysicalServer($this->getData("serverID"));
                 $template = new Template($this->getData("addInfo"));
                 $template->installOnServer($server);
                 Core::addToTaskLog("Template (" . $template->getData("id") . ", " . $template->getData("gameName") . ") installed on server " . $server->getData("id") . " (" . $server->getData("name") . ")");
                 break;
             case TASK_TEMPLATES_INSTALL_FROM_REMOTE:
                 $template = TemplateManager::loadTemplateByRemote($this->getData("addInfo"));
                 Core::addToTaskLog("Gameserver templated downloaded. (" . $template->getData("gameName") . ")");
                 break;
             case TASK_GAMESERVER_UPDATESETTINGS:
                 if (GameserverManager::existsById($this->getData("addInfo"))) {
                     echo "Updating Config.";
                     $gameserver = new Gameserver($this->getData("addInfo"));
                     $gameserver->settingsUpdateOnServer();
                     $id = $gameserver->getData("id");
                     Core::addToTaskLog("Gameserver settings saved. (ID: {$id})");
                 } else {
                     $id = $this->getData("addInfo");
                     Core::addToTaskLog("Gameserver Install Task couldnt be executed. Gameserver doesnt exist (ID: {$id})", LOGLEVEL_WARNING);
                 }
                 break;
             case TASK_GAMESERVER_INSTALL:
                 if (GameserverManager::existsById($this->getData("addInfo"))) {
                     $gameserver = new Gameserver($this->getData("addInfo"));
                     $gameserver->install();
                     $id = $gameserver->getData("id");
                     Core::addToTaskLog("Gameserver installed. (ID: {$id})");
                 } else {
                     $id = $this->getData("addInfo");
                     Core::addToTaskLog("Gameserver Install Task couldnt be executed. Gameserver doesnt exist (ID: {$id})", LOGLEVEL_WARNING);
                 }
                 break;
             case TASK_GAMESERVER_UNINSTALL:
                 if (GameserverManager::existsById($this->getData("addInfo"))) {
                     $gameserver = new Gameserver($this->getData("addInfo"));
                     $done = $gameserver->delete();
                     $id = $gameserver->getData("id");
                     if ($done) {
                         Core::addToTaskLog("Gameserver deleted. (ID: {$id})");
                     }
                 } else {
                     $id = $this->getData("addInfo");
                     Core::addToTaskLog("Gameserver Install Task couldnt be executed. Gameserver doesnt exist (ID: {$id})", LOGLEVEL_WARNING);
                 }
                 break;
             case TASK_GAMESERVER_START:
                 if (GameserverManager::existsById($this->getData("addInfo"))) {
                     $gameserver = new Gameserver($this->getData("addInfo"));
                     $gameserver->start();
                     $id = $gameserver->getData("id");
                     Core::addToTaskLog("Gameserver started. (ID: {$id})");
                 } else {
                     $id = $this->getData("addInfo");
                     Core::addToTaskLog("Gameserver Install Task couldnt be executed. Gameserver doesnt exist (ID: {$id})", LOGLEVEL_WARNING);
                 }
                 break;
             case TASK_GAMESERVER_STOP:
                 if (GameserverManager::existsById($this->getData("addInfo"))) {
                     $gameserver = new Gameserver($this->getData("addInfo"));
                     $gameserver->stop();
                     $id = $gameserver->getData("id");
                     Core::addToTaskLog("Gameserver stopped. (ID: {$id})");
                 } else {
                     $id = $this->getData("addInfo");
                     Core::addToTaskLog("Gameserver Install Task couldnt be executed. Gameserver doesnt exist (ID: {$id})", LOGLEVEL_WARNING);
                 }
                 break;
             case TASK_GAMESERVER_DISABLE:
                 if (GameserverManager::existsById($this->getData("addInfo"))) {
                     $gameserver = new Gameserver($this->getData("addInfo"));
                     $gameserver->disable();
                     $id = $gameserver->getData("id");
                     Core::addToTaskLog("Gameserver disabled. (ID: {$id})");
                 } else {
                     $id = $this->getData("addInfo");
                     Core::addToTaskLog("Gameserver Install Task couldnt be executed. Gameserver doesnt exist (ID: {$id})", LOGLEVEL_WARNING);
                 }
                 break;
             default:
                 $id = $this->getData("id");
                 Core::addToTaskLog("Task couldnt be executed. Unknown Job. (ID: {$id})", LOGLEVEL_WARNING);
                 $this->delete();
                 return;
         }
         if ($done) {
             $con = Database::getCon();
             $con->query("UPDATE tasks SET done = 1 WHERE id = " . $this->getData("id"));
         }
     } catch (Exception $e) {
         echo "Task couldnt be executed. (ID: " . $this->getData("id") . ") Message: " . $e->getMessage();
         Core::addToTaskLog("Task couldnt be executed. (ID: " . $this->getData("id") . ") Message: " . $e->getMessage(), LOGLEVEL_ERROR);
     }
 }
 protected function processTemplateBlocks(Template $template, &$globals, RendererInterface $renderer)
 {
     if ($this->benchmarkRendering) {
         $this->Benchmark->start('process-template-blocks-' . $template->getName());
     }
     $templateBlocks = $template->getTemplateBlocks();
     $data = $template->getData();
     $locals = $template->getLocals();
     $handler = $template->getContentType() != 'html' && $template->getContentType() != '' ? $template->getContentType() . '-' : '';
     $renderout = '';
     $contents = '';
     $parsedContents = '';
     $locals['DisplayRecords'] = sizeof($data);
     $locals['Count'] = 1;
     if (!empty($data)) {
         //if(LOG_ENABLE) System::log(self::$logType, 'Parsing contents block');
         if (!isset($templateBlocks[$handler . 'contents']) && !isset($templateBlocks[$handler . 'header']) && !isset($templateBlocks[$handler . 'exec'])) {
             throw new Exception('Template [' . $template->getName() . '] is missing a template block for [' . $handler . 'contents] or [' . $handler . 'header] or [' . $handler . 'exec]');
         }
         $eBlock = isset($templateBlocks[$handler . 'exec']) ? $templateBlocks[$handler . 'exec'] : '';
         $cBlock = isset($templateBlocks[$handler . 'contents']) ? $templateBlocks[$handler . 'contents'] : '';
         $ciBlock = isset($templateBlocks[$handler . 'contents-inbetween']) ? $templateBlocks[$handler . 'contents-inbetween'] : '';
         if (!empty($eBlock)) {
             $contents = $eBlock;
             $contents = $this->parseSetters($contents, $locals);
             $contents = $this->parseConditions($contents, $locals);
             $contents = $this->parseFilters($contents, $locals);
             $contents = $this->parseAssets($contents, $locals);
             // parse dependent sub modules
             $template->setLocals($locals);
             // $this->Logger->debug("Parsing dependent includes for [{$template->getName()}]...");
             $contents = $this->parseTemplateIncludes($contents, $template->getContentType(), $template, $globals, $renderer, false, true);
             $contents = $this->parseFormatVariables($contents, $locals);
             $renderout .= $contents;
         } else {
             // List Processing of the Data
             foreach ((array) $data as $row) {
                 $contents = $cBlock;
                 // if(strpos($contents, '{% set ') !== FALSE) {
                 //     while(preg_match("/(.*?)\{\%\s+set\s+([^\%]+?)\s+\%\}\s*(.*?)\s?\{\%\s+endset\s+\%\}\s*(.*)/s",$contents,$m)) {
                 //         if(!array_key_exists($m[2], $row)) {
                 //             $val = $this->parseFormatVariablesAndFilters($m[3], $row);
                 //             $row[$m[2]] = $val;
                 //         }
                 //         $contents = $m[1]. $m[4];
                 //      }
                 // }
                 if ($locals['DisplayRecords'] != $locals['Count']) {
                     $contents .= $ciBlock;
                 }
                 if (!is_array($row)) {
                     if ($row instanceof Node) {
                         /*
                          * Populating Node itself into the row so it can be used in templates,
                          * passed to events, filters, etc.  see ticket #30
                          * todo: investigate populating 'Node' in populateNodeCheaters directly
                          */
                         $node = $row;
                         $row = $this->NodeMapper->populateNodeCheaters($row)->toArray();
                         $row['Node'] = $node;
                     } else {
                         if ($row instanceof Object) {
                             $row = $row->toArray();
                         } else {
                             throw new Exception("data is not an array\n" . print_r($row, true));
                         }
                     }
                 }
                 $row_locals = array_merge($locals, $row);
                 $row_locals['SerializedData'] = $row;
                 //if(LOG_ENABLE) System::log(self::$logType, 'Locals ['.print_r($locals, true).']');
                 $contents = $this->parseSetters($contents, $row_locals);
                 $contents = $this->parseConditions($contents, $row_locals);
                 $contents = $this->parseFilters($contents, $row_locals);
                 $contents = $this->parseAssets($contents, $row_locals);
                 // parse dependent sub modules
                 $template->setLocals($row_locals);
                 // $this->Logger->debug("Parsing dependent includes for [{$template->getName()}]...");
                 $contents = $this->parseTemplateIncludes($contents, $template->getContentType(), $template, $globals, $renderer, false, true);
                 $contents = $this->parseFormatVariables($contents, $row_locals);
                 $locals['Count']++;
                 $parsedContents .= $contents;
             }
             $locals = $row_locals;
             $template->setLocals($locals);
             // headers and footers can use format variables from the final row
             $renderout = '';
             if (!empty($templateBlocks[$handler . 'header'])) {
                 $header = $templateBlocks[$handler . 'header'];
                 $header = $this->parseSetters($header, $locals);
                 $header = $this->parseConditions($header, $locals);
                 $header = $this->parseFilters($header, $locals);
                 $header = $this->parseAssets($header, $locals);
                 $template->setLocals($locals);
                 // parse dependent sub modules
                 $header = $this->parseTemplateIncludes($header, $template->getContentType(), $template, $globals, $renderer, false, true);
                 $header = $this->parseFormatVariables($header, $locals);
                 $renderout .= $header;
             }
             $renderout .= $parsedContents;
             if (!empty($templateBlocks[$handler . 'footer'])) {
                 $footer = $templateBlocks[$handler . 'footer'];
                 $footer = $this->parseSetters($footer, $locals);
                 $footer = $this->parseConditions($footer, $locals);
                 $footer = $this->parseFilters($footer, $locals);
                 $footer = $this->parseAssets($footer, $locals);
                 $template->setLocals($locals);
                 // parse dependent sub modules
                 $footer = $this->parseTemplateIncludes($footer, $template->getContentType(), $template, $globals, $renderer, false, true);
                 $footer = $this->parseFormatVariables($footer, $locals);
                 $renderout .= $footer;
             }
         }
     } else {
         if (!$template->isTopTemplate() && !array_key_exists($handler . 'contents', $templateBlocks) && !array_key_exists($handler . 'noresults', $templateBlocks)) {
             throw new Exception('Template [' . $template->getName() . '] is missing a template block for [' . $handler . 'noresults] or [' . $handler . 'contents] or [' . $handler . 'exec]');
         }
         if (array_key_exists($handler . 'noresults', $templateBlocks)) {
             $renderout = $templateBlocks[$handler . 'noresults'];
         } elseif ($template->getData() === null && empty($locals['DataSource']) && array_key_exists($handler . 'exec', $templateBlocks)) {
             $renderout = $templateBlocks[$handler . 'exec'];
         } elseif ($template->getData() === null && empty($locals['DataSource']) && array_key_exists($handler . 'contents', $templateBlocks)) {
             $renderout = $templateBlocks[$handler . 'contents'];
         } elseif ($template->isTopTemplate()) {
             throw new NotFoundException($template->getName());
         }
         $renderout = $this->parseSetters($renderout, $locals);
         $renderout = $this->parseConditions($renderout, $locals);
         $renderout = $this->parseFilters($renderout, $locals);
         $renderout = $this->parseConditions($renderout, $locals);
         $template->setLocals($locals);
         // parse dependent sub modules
         //$template->setLocals($locals);
         $renderout = $this->parseTemplateIncludes($renderout, $template->getContentType(), $template, $globals, $renderer, false, true);
         $renderout = $this->parseFormatVariables($renderout, $locals);
     }
     //if(LOG_ENABLE) System::log(self::$logType, 'Render out ['.print_r($renderout, true).']');
     if ($this->benchmarkRendering) {
         $this->Benchmark->end('process-template-blocks-' . $template->getName());
     }
     return $renderout;
 }