public function view(Application $app, $folder = '', $scriptName = '', $runType = 'test')
 {
     $this->data['controlpanel'] = false;
     $this->data['runtype'] = $runType;
     if (!file_exists("Api/Library/Shared/Script/{$folder}/{$scriptName}.php")) {
         // show list of scripts
         $this->data['scriptnames'] = $this->scriptBaseNames();
         $this->data['controlpanel'] = true;
         return $this->renderPage($app, 'scriptoutput');
     } else {
         // run script and render output
         $this->data['scriptrunurl'] = "/script/{$folder}/{$scriptName}/run";
         $userId = SilexSessionHelper::getUserId($app);
         if (!RightsHelper::hasSiteRight($userId, Domain::PROJECTS + Operation::DELETE)) {
             $app->abort(403, 'You have insufficient privileges to run scripts');
             // this terminates PHP
         } else {
             try {
                 $className = "Api\\Library\\Shared\\Script\\{$folder}\\{$scriptName}";
                 $script = new $className();
                 $this->data['scriptname'] = $className . '->run()';
                 $this->data['output'] = '';
                 if ($runType != 'run') {
                     $this->data['scriptname'] = "[TEST RUN] " . $this->data['scriptname'];
                 }
                 $this->data['output'] .= $script->run($userId, $runType);
                 return $this->renderPage($app, 'scriptoutput');
             } catch (\Exception $e) {
                 var_dump($e);
                 $app->abort(500, "Looks like there was a problem with the script {$className}");
                 // this terminates PHP
             }
         }
     }
 }
예제 #2
0
 public function __construct(Application $app)
 {
     $this->app = $app;
     $this->website = Website::get();
     $this->userId = SilexSessionHelper::getUserId($app);
     $this->projectId = SilexSessionHelper::getProjectId($app, $this->website);
     // "Kick" session every time we use an API call, so it won't time out
     $this->update_last_activity();
     // TODO put in the LanguageForge style error handler for logging / jsonrpc return formatting etc. CP 2013-07
     ini_set('display_errors', 0);
 }
 protected function renderPage(Application $app, $viewName)
 {
     if ($viewName == 'favicon.ico') {
         $viewName = 'container';
     }
     $this->_isLoggedIn = $this->isLoggedIn($app);
     if ($this->_isLoggedIn) {
         try {
             if (!$this->_userId) {
                 $this->_userId = SilexSessionHelper::getUserId($app);
             }
             $this->_user = new UserModel($this->_userId);
             if (!$this->_projectId) {
                 $this->_projectId = SilexSessionHelper::getProjectId($app, $this->website);
             }
         } catch (\Exception $e) {
             //                error_log("User $userId not found, logged out.\n" . $e->getMessage());
             return $app->redirect('/app/logout');
         }
     }
     // Add general Angular app dependencies
     $dependencies = $this->getAngularAppJsDependencies();
     foreach ($dependencies["js"] as $dependencyFilePath) {
         $this->data['vendorFilesJs'][] = $dependencyFilePath;
     }
     foreach ($dependencies["min"] as $dependencyFilePath) {
         $this->data['vendorFilesMinJs'][] = $dependencyFilePath;
     }
     $this->populateHeaderMenuViewdata();
     $this->data['useCdn'] = USE_CDN;
     if (empty($this->data)) {
         $app->abort(404, 'Error: cannot render without data');
     }
     try {
         return $app['twig']->render($viewName . '.html.twig', $this->data);
     } catch (\Twig_Error_Loader $e) {
         $app->abort(404, "Page not found: {$viewName}.twig");
     }
     return new Response('Should not get here', 500);
 }
 public function setupNgView(Application $app, $appName, $projectId = '')
 {
     $siteFolder = NG_BASE_FOLDER . $this->website->base;
     $parentAppFolder = '';
     $appFolder = $this->website->base . '/' . $appName;
     if ($projectId == 'favicon.ico') {
         $projectId = '';
     }
     $possibleSubFolder = "{$siteFolder}/{$appName}/{$projectId}";
     if ($projectId != '' && file_exists($possibleSubFolder) && file_exists("{$possibleSubFolder}/{$appName}-{$projectId}.html") && file_exists("{$possibleSubFolder}/views")) {
         $parentAppFolder = $appFolder;
         $appFolder .= "/{$projectId}";
         $appName .= "-{$projectId}";
         $projectId = '';
     }
     if (!file_exists(NG_BASE_FOLDER . $appFolder)) {
         $appFolder = 'bellows/apps/' . $appName;
         if (!file_exists(NG_BASE_FOLDER . $appFolder)) {
             $app->abort(404, $this->website->base);
             // this terminates PHP
         }
     }
     $this->data['appName'] = $appName;
     $this->data['appFolder'] = $appFolder;
     $this->_userId = SilexSessionHelper::getUserId($app);
     // update the projectId in the session if it is not empty
     if (!$projectId) {
         $projectId = SilexSessionHelper::getProjectId($app, $this->website);
     }
     if ($projectId && ProjectModel::projectExistsOnWebsite($projectId, $this->website)) {
         $projectModel = ProjectModel::getById($projectId);
         if (!$projectModel->userIsMember($this->_userId)) {
             $projectId = '';
         } else {
             $user = new UserModel($this->_userId);
             $user->lastUsedProjectId = $projectId;
             $user->write();
             if ($projectModel->isArchived and $user->role != SystemRoles::SYSTEM_ADMIN) {
                 // Forbidden access to archived projects
                 $projectId = '';
                 $user->lastUsedProjectId = $projectId;
                 $user->write();
                 $app->abort(403, "Forbidden access to archived project");
             }
         }
     } else {
         $projectId = '';
     }
     $app['session']->set('projectId', $projectId);
     $this->_projectId = $projectId;
     // determine help menu button visibility
     // placeholder for UI language 'en' to support translation of helps in the future
     $helpsFolder = NG_BASE_FOLDER . $appFolder . "/helps/en/page";
     if (file_exists($helpsFolder) && iterator_count(new \FilesystemIterator($helpsFolder, \FilesystemIterator::SKIP_DOTS)) > 0) {
         $this->_showHelp = true;
         // there is an implicit dependency on bellows JS here using the jsonRpc module
         $this->addJavascriptFiles(NG_BASE_FOLDER . 'container/js', array('vendor/', 'assets/'));
     }
     // Other session data
     $sessionData = SessionCommands::getSessionData($this->_projectId, $this->_userId, $this->website, $appName);
     $this->data['jsonSession'] = json_encode($sessionData, JSON_UNESCAPED_SLASHES);
     $this->addJavascriptFiles(NG_BASE_FOLDER . 'bellows/js', array('vendor/', 'assets/'));
     $this->addJavascriptFiles(NG_BASE_FOLDER . 'bellows/directive');
     $this->addJavascriptFiles($siteFolder . '/js', array('vendor/', 'assets/'));
     if ($parentAppFolder) {
         $this->addJavascriptFiles(NG_BASE_FOLDER . $parentAppFolder, array('vendor/', 'assets/'));
         $this->addJavascriptNotMinifiedFiles(NG_BASE_FOLDER . $parentAppFolder . '/js/vendor');
         $this->addJavascriptNotMinifiedFiles(NG_BASE_FOLDER . $parentAppFolder . '/js/assets');
     }
     $this->addJavascriptFiles(NG_BASE_FOLDER . $appFolder, array('vendor/', 'assets/'));
     if ($appName == 'semdomtrans' || $appName == 'semdomtrans-new-project') {
         // special case for semdomtrans app
         // add lexicon JS files since the semdomtrans app depends upon these JS files
         $this->addJavascriptFiles($siteFolder . '/lexicon', array('vendor/', 'assets/'));
     }
     $this->addJavascriptNotMinifiedFiles(NG_BASE_FOLDER . 'bellows/js/vendor');
     $this->addJavascriptNotMinifiedFiles(NG_BASE_FOLDER . 'bellows/js/assets');
     $this->addJavascriptNotMinifiedFiles($siteFolder . '/js/vendor');
     $this->addJavascriptNotMinifiedFiles($siteFolder . '/js/assets');
     $this->addJavascriptNotMinifiedFiles(NG_BASE_FOLDER . $appFolder . '/js/vendor');
     $this->addJavascriptNotMinifiedFiles(NG_BASE_FOLDER . $appFolder . '/js/assets');
     $this->addCssFiles(NG_BASE_FOLDER . 'bellows');
     $this->addCssFiles(NG_BASE_FOLDER . $appFolder);
 }