Exemple #1
0
 protected function execute()
 {
     switch ($this->mode) {
         case self::MODE_DQL:
             $this->result = '';
             $strQuery = trim($this->code);
             $lister = new \Cx\Core_Modules\Listing\Controller\ListingController(function (&$offset, &$count, &$criteria, &$order) use($strQuery) {
                 return \Env::get('em')->createQuery($strQuery);
             });
             try {
                 $table = new \BackendTable($lister->getData());
                 $this->result = $table->toHtml() . $lister;
             } catch (\Exception $e) {
                 $this->result = 'Could not execute query (' . $e->getMessage() . ')!';
             }
             break;
         case self::MODE_PHP:
             $dbgMode = \DBG::getMode();
             try {
                 // This error handler catches all Warnings and Notices and some Strict errors
                 \DBG::activate(DBG_PHP);
                 set_error_handler(array($this, 'phpErrorsAsExceptionsHandler'));
                 $this->errrorHandlerActive = true;
                 // Since DBG catches the rest (E_PARSE) let's use that
                 ob_start();
                 $function = create_function('$em, $cx', '' . $this->code . ';');
                 $dbgContents = ob_get_clean();
                 \DBG::activate($dbgMode);
                 if (!is_callable($function)) {
                     // parse exception
                     throw new SandboxException($dbgContents);
                 }
                 $this->result = var_export($function(\Env::get('em'), \Env::get('cx')), true);
                 restore_error_handler();
                 $this->errrorHandlerActive = false;
             } catch (\Exception $e) {
                 \DBG::activate($dbgMode);
                 restore_error_handler();
                 $this->errrorHandlerActive = false;
                 $this->result = get_class($e) . ': ' . $e->getMessage();
             }
             break;
         default:
             break;
     }
 }
Exemple #2
0
 public function __construct(&$language, $mode, &$arguments)
 {
     $this->template = new \Cx\Core\Html\Sigma(ASCMS_CORE_MODULE_PATH . '/Workbench/View/Template/Backend');
     switch ($mode) {
         case 'yaml':
             \JS::activate('ace');
             \Message::add('YAML toolbox is currently not working.', \Message::CLASS_WARN);
             \Message::add('Implement in ' . __METHOD__ . ' (' . __FILE__ . ')', \Message::CLASS_WARN);
             $this->template->loadTemplateFile('Yaml.html');
             $res = \Env::get('db')->Execute('SHOW TABLES');
             while (!$res->EOF) {
                 $this->template->setVariable('TABLE', current($res->fields));
                 $this->template->parse('table_option');
                 $res->MoveNext();
             }
             //if (mode = table) {
             $result = $this->loadSql($arguments['table']);
             //} else {
             //$result = sql
             //}
             //$result = $this->sql2Yaml($result);
             $this->template->setVariable(array('TXT_WORKBENCH_TOOLBOX_YAML_FROM_TABLE' => $language['TXT_WORKBENCH_TOOLBOX_YAML_FROM_TABLE'], 'TXT_WORKBENCH_TOOLBOX_YAML_FROM_SQL' => $language['TXT_WORKBENCH_TOOLBOX_YAML_FROM_SQL'], 'TXT_WORKBENCH_TOOLBOX_SUBMIT' => $language['TXT_WORKBENCH_TOOLBOX_SUBMIT'], 'RESULT' => $result));
             break;
         case 'components':
             $this->template->loadTemplateFile('Components.html');
             $query = '
                 SELECT
                     `id`,
                     `name`,
                     `is_required`,
                     `is_core`
                 FROM
                     `' . DBPREFIX . 'modules`
                 ORDER BY
                     `name` ASC
             ';
             $res = \Env::get('db')->Execute($query);
             $modules = array();
             while (!$res->EOF) {
                 $fsExists = $this->componentExistsInFileSystem($res->fields['is_core'], $res->fields['name']);
                 $modules[$res->fields['name']] = array('id' => $res->fields['id'], 'name' => $res->fields['name'], 'type' => $res->fields['is_core'], 'exists_db' => 'true', 'exists_filesystem' => $fsExists, 'skeleton_version' => $this->getComponentStyle($res->fields['is_core'], $res->fields['name']));
                 $res->MoveNext();
             }
             foreach (\Env::get('em')->getRepository('Cx\\Core\\Core\\Model\\Entity\\SystemComponent')->findAll() as $component) {
                 if (isset($modules[$component->getName()])) {
                     continue;
                 }
                 $name = $component->getName();
                 $type = $component->getType();
                 $modules[$component->getName()] = array('id' => $component->getId(), 'name' => $component->getName(), 'type' => $component->getType(), 'exists_db' => '<span style="color:red;">false</span>', 'exists_filesystem' => $this->componentExistsInFileSystem($type, $name), 'skeleton_version' => '3.1.0');
             }
             foreach (array(ASCMS_CORE_FOLDER, ASCMS_CORE_MODULE_FOLDER, ASCMS_MODULE_FOLDER) as $basedir) {
                 $dh = opendir(ASCMS_DOCUMENT_ROOT . $basedir);
                 while ($file = readdir($dh)) {
                     if (substr($file, 0, 1) == '.') {
                         continue;
                     }
                     if (!is_dir(ASCMS_DOCUMENT_ROOT . $basedir . '/' . $file)) {
                         continue;
                     }
                     if (isset($modules[$file])) {
                         continue;
                     }
                     $modules[$file] = array('id' => '<span style="color:red;">(none)</span>', 'name' => $file, 'type' => preg_replace('/s/', '', substr(strtolower($basedir), 1)), 'exists_db' => '<span style="color:red;">false</span>', 'exists_filesystem' => '.' . $basedir . '/' . $file, 'skeleton_version' => '<span style="color:red;">&lt;= 2.2.6</span>');
                 }
                 closedir($dh);
             }
             // add all not-yet-listed components existing in filesystem
             $tableDefinition = array('fields' => array('id' => array('table' => array('parse' => function ($value) {
                 return $value;
             })), 'exists_db' => array('table' => array('parse' => function ($value) {
                 return $value;
             })), 'skeleton_version' => array('table' => array('parse' => function ($value) {
                 return $value;
             }))));
             $table = new \BackendTable(new \Cx\Core_Modules\Listing\Model\Entity\DataSet($modules), $tableDefinition);
             $this->template->setVariable(array('RECORD_COUNT' => count($modules), 'RESULT' => $table->toHtml()));
             break;
     }
 }
 private function addHistoryEntries($page, $username, \BackendTable $table, $row, $version = '', $path = '')
 {
     global $_ARRAYLANG;
     $dateString = $page->getUpdatedAt()->format(ASCMS_DATE_FORMAT_DATETIME);
     $historyLink = ASCMS_PATH_OFFSET . '/' . $path . '?history=' . $version;
     $tableStyle = '';
     $editingStatus = $page->getEditingStatus();
     $functions = '<a id="preview_' . $version . '" class="historyPreview" title="' . $_ARRAYLANG['TXT_CORE_PREVIEW'] . '" href="' . $historyLink . '" target="_blank" ' . $tableStyle . '>' . $_ARRAYLANG['TXT_CORE_PREVIEW'] . '</a>';
     $functions .= '<a id="load_' . $version . '" class="historyLoad" title="' . $_ARRAYLANG['TXT_CORE_LOAD'] . '" href="javascript:loadHistoryVersion(' . $version . ')" ' . $tableStyle . '>' . $_ARRAYLANG['TXT_CORE_LOAD'] . '</a>';
     /**
      * @todo This is a copy from JsonNode, move this snippet to its own method
      */
     if ($page->isActive()) {
         if ($editingStatus == 'hasDraft') {
             $publishingStatus = 'published draft';
         } else {
             if ($editingStatus == 'hasDraftWaiting') {
                 $publishingStatus = 'published draft waiting';
             } else {
                 $publishingStatus = 'published';
             }
         }
     } else {
         if ($editingStatus == 'hasDraft') {
             $publishingStatus = 'unpublished draft';
         } else {
             if ($editingStatus == 'hasDraftWaiting') {
                 $publishingStatus = 'unpublished draft waiting';
             } else {
                 $publishingStatus = 'unpublished';
             }
         }
     }
     if ($page->isBackendProtected() && !\Permission::checkAccess($page->getBackendAccessId(), 'dynamic', true)) {
         $publishingStatus .= ' locked';
     }
     // set style
     $table->setCellAttributes($row, 0, array('style' => 'white-space: nowrap;'));
     $table->setCellAttributes($row, 1, array('style' => 'white-space: nowrap;'));
     // set content
     $table->setCellContents($row, 0, $dateString);
     $table->setCellContents($row, 1, '<div class="jstree-icon publishing ' . $publishingStatus . '" /><div class="name">' . $page->getTitle() . '</div>');
     $table->setCellContents($row, 2, $username);
     $table->setCellContents($row, 3, $functions);
     return true;
 }