예제 #1
0
 /** @param $task Task */
 public function processTask($task)
 {
     parent::processTask($task);
     $data = $task->request->post->get('commands');
     if (!is_string($data)) {
         $this->postResults(array(ServiceResult::createWithError('error', 'No data', '::GLOBAL::')));
         return;
     }
     if (strlen($data) > $this->maxPackageSize) {
         $this->postResults(array(ServiceResult::createWithError('error', 'Data too large', '::GLOBAL::')));
         return;
     }
     $data = json_decode($data, true);
     if (json_last_error() != JSON_ERROR_NONE || !is_array($data)) {
         $this->postResults(array(ServiceResult::createWithError('error', 'Invalid data', '::GLOBAL::')));
         return;
     }
     $results = array();
     $f = new ArrayFilter();
     foreach ($data as $command) {
         if (!is_array($command)) {
             $this->postResults(array(ServiceResult::createWithError('error', 'Invalid data', '::GLOBAL::')));
             return;
         }
         $f->setData($command);
         $id = $f->get('id');
         $command = $f->get('command');
         $data = $f->asFilter('data');
         $results[] = $this->_executeCommand($command, $data, $id);
     }
     $this->postResults($results);
 }
예제 #2
0
파일: Form.php 프로젝트: cyantree/grout
 protected function _isSubmit()
 {
     if (is_string($this->submitButton)) {
         if ($this->dataIn->has(strval($this->submitButton))) {
             $this->mode = $this->submitButton;
             return true;
         }
     } else {
         if (is_array($this->submitButton)) {
             foreach ($this->submitButton as $id) {
                 if ($this->dataIn->has($id)) {
                     $this->mode = $id;
                     return true;
                 }
             }
         }
     }
     $button = $this->dataIn->get('CT_Form_SubmitButton');
     if ($button) {
         if (is_string($this->submitButton) && $this->submitButton == $button || is_array($this->submitButton) && in_array($button, $this->submitButton)) {
             $this->mode = $button;
             return true;
         } else {
             return false;
         }
     }
     return false;
 }
예제 #3
0
 public function fetch(ArrayFilter $data)
 {
     $v = $data->get($this->name);
     foreach ($this->_filters as $filter) {
         $v = $filter->doFiltering($v);
     }
     $this->value = $v;
     return $this->value;
 }
예제 #4
0
 public function setTemplateResult($template, $templateData = null, $settings = null)
 {
     $settings = new ArrayFilter($settings);
     $content = $this->factory()->appTemplates()->load($template, $templateData)->content;
     $baseTemplate = $settings->get('baseTemplate');
     if ($baseTemplate === null) {
         $baseTemplate = 'AppModule::base.html';
     }
     if ($baseTemplate !== null && $baseTemplate !== false) {
         $content = $this->factory()->appTemplates()->load($baseTemplate, array('content' => $content))->content;
     }
     $this->setResult($content, $settings->get('contentType'), $settings->get('responseCode'));
 }
예제 #5
0
 protected function _retrieveUrl()
 {
     if ($this->usesModRewrite) {
         $self = $this->_server->needs('PHP_SELF');
         //            if(($pathInfo = $this->_server->get('PATH_INFO')) || ($pathInfo = $this->_server->get('ORIG_PATH_INFO'))){
         //                $self = substr($self, 0, strlen($self) - strlen($pathInfo));
         //            }
         if (($pos = strrpos($self, '/')) !== false) {
             $self = substr($self, 0, $pos);
         } else {
             $self = substr($self, 0, strrpos($self, '\\'));
         }
         $url = substr($this->_server->needs('REQUEST_URI'), strlen($self));
         if ($url === false) {
             $url = '';
         } elseif ($url !== '') {
             $posQueryString = strpos($url, '?');
             if ($posQueryString !== false) {
                 $url = substr($url, 0, $posQueryString);
             }
         }
         $url = substr($url, 1);
     } else {
         if ($this->_server->has('PATH_INFO')) {
             $url = substr($this->_server->get('PATH_INFO'), 1);
         } else {
             $url = substr($this->_server->get('ORIG_PATH_INFO'), 1);
         }
     }
     if (substr($url, -1, 1) != '/') {
         $url .= '/';
     }
     return $url;
 }
예제 #6
0
파일: Task.php 프로젝트: cyantree/grout
 public function setRoute($route, $routeVars = null)
 {
     if (!$this->vars) {
         $this->vars = new ArrayFilter();
     }
     $this->route = $route;
     $this->plugin = $route->plugin;
     $this->module = $route->module;
     if (is_array($route->data->data)) {
         if ($routeVars === null) {
             $routeVars = array();
         }
         $this->vars->setData(array_merge($routeVars, $route->data->data));
     } else {
         $this->vars->setData($routeVars);
     }
 }
예제 #7
0
 protected function _isSubmit()
 {
     if (is_string($this->submitButton)) {
         if ($this->dataIn->has(strval($this->submitButton))) {
             $this->mode = $this->submitButton;
             $this->action = 'next';
             return true;
         }
     } else {
         if (is_array($this->submitButton)) {
             foreach ($this->submitButton as $id => $action) {
                 if ($this->dataIn->has($id)) {
                     $this->mode = $id;
                     $this->action = $action;
                     return true;
                 }
             }
         }
     }
     for ($i = 1; $i <= $this->steps; $i++) {
         if ($this->dataIn->has('step' . $i)) {
             $this->mode = 'step' . $i;
             $this->action = $i;
             return true;
         }
     }
     $button = $this->dataIn->get('CT_Form_SubmitButton');
     if ($button) {
         $this->mode = $button;
         if (is_array($this->submitButton)) {
             $this->action = ArrayTools::get($this->submitButton, $button);
         } else {
             if ($button == $this->submitButton) {
                 $this->action = 'next';
             }
         }
         if ($this->action) {
             return true;
         }
         if (!$this->action) {
             for ($i = 1; $i <= $this->steps; $i++) {
                 if ($button == 'step' . $i) {
                     $this->action = $i;
                     return true;
                 }
             }
         }
         return false;
     }
     return false;
 }
예제 #8
0
 public function getAppTool($tool)
 {
     $t = $this->_tools->get($tool);
     if ($t) {
         return $t;
     }
     if (method_exists($this, $tool)) {
         return $this->{$tool}();
     }
     $event = $this->events->trigger($tool);
     if ($event->data) {
         $this->_tools->set($tool, $event->data);
         return $event->data;
     }
     return null;
 }
예제 #9
0
파일: Content.php 프로젝트: cyantree/grout
 public function postSuccess($code, $message = null, $messageReplaces = null)
 {
     $this->set->status->addSuccess($this->name);
     if ($message) {
         if ($messageReplaces === null) {
             $messageReplaces = array();
         }
         $messageReplaces['%name%'] = $this->config->get('label');
         //            $message = str_replace(array_keys($messageReplaces), array_values($messageReplaces), $message);
     }
     $m = new SetMessage();
     $m->content = $this;
     $m->code = $this->name . '.' . $code;
     $m->message = $message;
     $m->values = $messageReplaces;
     $this->set->status->addSuccess($this->name . '.' . $code, $m);
     //        $this->set->status->postSuccess($this->name.'.'.$code, $message);
 }
예제 #10
0
파일: App.php 프로젝트: cyantree/grout
 /**
  * @param $type
  * @param string $urlPrefix
  * @param array $config
  * @param string $id
  * @param int $priority
  * @return Module|null
  */
 public function importModule($type, $urlPrefix = null, $config = null, $id = null, $priority = 0)
 {
     if ($id === null) {
         $id = str_replace('\\', '', $type);
         if ($this->getModuleById($id)) {
             $id .= '_' . count($this->modules);
         }
     }
     if ($this->getModuleById($id)) {
         return null;
     }
     $pos = strrpos($type, '\\');
     if ($pos === false) {
         $class = $type;
     } else {
         $class = substr($type, strrpos($type, '\\') + 1);
     }
     //        $directory = str_replace('\\', '/', $type);
     //        $path = $this->path . 'modules/' . $directory . '/';
     if ($config === null || is_array($config)) {
         $config = new ArrayFilter($config);
     }
     $config->set('_priority', $priority);
     // Add module path to auto loading
     $this->importModuleNamespace($type);
     /** @var $m Module */
     $c = 'Grout\\' . $type . '\\' . $class;
     $reflection = new \ReflectionClass($c);
     $path = dirname($reflection->getFileName()) . '/';
     $m = new $c();
     $m->type = $type;
     $m->events = new Events();
     $m->app = $this;
     $m->config =& $config;
     $m->urlPrefix = $urlPrefix !== null ? $urlPrefix : '';
     $m->path = $path;
     $m->namespace = NamespaceTools::getNamespaceOfInstance($m) . '\\';
     $m->id = $id;
     $this->modules[] = $m;
     if (!isset($this->moduleTypes[$type])) {
         $this->moduleTypes[$type] = array($m);
     } else {
         $this->moduleTypes[$type][] = $m;
     }
     $this->moduleIds[$m->id] = $m;
     if ($this->_initiated) {
         $m->init();
         /* TODO: War aus nicht mehr bekanntem Grund auskommentiert, weil irgendetwas doppelt aufgerufen wurde */
         if ($this->currentTask) {
             $m->initTask($this->currentTask);
         }
     }
     return $m;
 }
예제 #11
0
파일: mosaic.php 프로젝트: cyantree/mosaic
<?php

use Cyantree\Grout\AutoLoader;
use Cyantree\Grout\Filter\ArrayFilter;
use Cyantree\Mosaic\Outputs\ReadableOutput;
use Cyantree\Mosaic\Outputs\JsonOutput;
use Cyantree\Mosaic\Mosaic;
require_once __DIR__ . '/../../../autoload.php';
ini_set('memory_limit', '1024M');
AutoLoader::init();
$options = new ArrayFilter(getopt('f:c:j:o:', ['debug']));
$outputMode = $options->get('o', 'readable');
$s = new Mosaic();
$s->debug = $options->has('debug');
$s->basePath = realpath(dirname($options->needs('f'))) . '/';
$s->applicationPath = __DIR__ . '/../src/';
$s->configuration->load($options->needs('f'));
if ($options->has('c')) {
    $s->configuration->extend(json_decode(rawurldecode($options->get('c'))));
}
if ($options->has('j')) {
    $includedJobs = explode(',', $options->get('j'));
} else {
    $includedJobs = null;
}
$jobs = $s->compile($includedJobs);
switch ($outputMode) {
    case 'json':
        $output = new JsonOutput();
        break;
    default:
예제 #12
0
파일: FileSet.php 프로젝트: cyantree/grout
 public function listSets($options)
 {
     /*
     $options = array(
         'offset' => 0,
         'count' => '20',
         'sort' => array(
             'field' => 'id',
             'direction' => 'desc'
         ),
         'search' => 'testsuche'
     );
     */
     $options = new ArrayFilter($options);
     $directory = $this->_getDirectory();
     if (is_dir($directory)) {
         $dir = opendir($directory);
         $offset = $options->get('offset', 0);
         $count = $options->get('count', 0);
         $extension = $this->_getExtension();
         $extensionLength = strlen($extension);
         $i = 0;
         $files = array();
         while (($file = readdir($dir)) !== false) {
             if ($file === '.' || $file === '..') {
                 continue;
             }
             $fileLength = strlen($file);
             if (substr($file, $fileLength - $extensionLength, $extensionLength) !== $extension) {
                 continue;
             }
             if ($i >= $offset && $i < $offset + $count) {
                 $files[] = substr($file, 0, $fileLength - $extensionLength);
             }
             $i++;
         }
         $result = new FileSetListResult($this, $files);
         $result->countAll = $i;
         return $result;
     }
     $result = new FileSetListResult($this, array());
     $result->countAll = 0;
     return $result;
 }
예제 #13
0
 public function checkSession()
 {
     $f = new ArrayFilter($this->bucket->data);
     if ($f->get('name') != $this->name) {
         return false;
     }
     if (!$f->get('lastAction') || time() - $f->get('lastAction') > $this->expirationTime) {
         return false;
     }
     if ($this->checkIp && $f->get('ip') != $this->ip) {
         return false;
     }
     if ($this->checkUserAgent && $f->get('userAgent') != $this->userAgent) {
         return false;
     }
     return true;
 }
예제 #14
0
 public function fetch(ArrayFilter $data)
 {
     $this->value = FileUpload::fromPhpFileArray($data->get($this->name));
     return $this->value;
 }
 public function toNewCommandString($mergeArgs)
 {
     return WebConsoleTools::constructCommandString($this->command, array_merge($this->args->getData(), $mergeArgs));
 }
예제 #16
0
파일: Request.php 프로젝트: cyantree/grout
 public function setPostData($dataArray)
 {
     $this->post->setData($dataArray);
     $this->method = 'POST';
 }
예제 #17
0
 public function listSets($options)
 {
     $options = new ArrayFilter($options);
     $search = $options->get('search');
     $sorting = $options->asFilter('sort');
     $sortingField = $sorting->get('field');
     $sortingDirection = $sorting->get('direction');
     $offset = $options->get('offset', 0);
     $count = $options->get('count', 0);
     $parameters = array();
     // Create queries
     $data = $this->_getListQueryData($options);
     // Create search queries
     $searchQueries =& $data['searchQueries'];
     if ($search != '') {
         foreach ($this->contents as $content) {
             if ($content->searchable) {
                 $parameters['search'] = '%' . $search . '%';
                 $searchQueries[] = 'e.' . $content->name . ' LIKE :search';
             }
         }
     }
     // Create query parts
     if ($searchQueries) {
         $filterClause = '(' . implode(' OR ', $searchQueries) . ')';
     } else {
         $filterClause = '1 = 1';
     }
     // Check for ordering
     $orderClause = '';
     if ($sortingField) {
         foreach ($this->contents as $content) {
             if ($content->sortable && $content->name == $sortingField) {
                 $orderClause = 'e.' . $content->name . ' ' . $sortingDirection;
                 break;
             }
         }
     }
     if ($orderClause === '') {
         if ($data['select']['defaultOrder']) {
             $orderClause = $data['select']['defaultOrder'];
         } else {
             $orderField = $this->config->get('order');
             if ($orderField) {
                 $orderClause = 'e.' . $orderField;
             } else {
                 $identifiers = $this->_getEntityManager()->getClassMetadata($this->_getEntityClass())->getIdentifierFieldNames();
                 $orderClause = 'e.' . $identifiers[0] . ' DESC';
             }
         }
     }
     $queryLookUps = array('{where}', '{order}', '{e}', '{entity}');
     $queryReplaces = array($filterClause, $orderClause, 'e', $this->_getEntityClass() . ' e');
     $queryClauseLookUps = array('{select-clause}', '{where-clause}', '{order-clause}', '{from-clause}');
     $queryClauseReplaces = array($data['clauses']['select'], $data['clauses']['where'], $data['clauses']['order'], $data['clauses']['from']);
     // Get items
     $queryData = $data['select'];
     $query = str_replace($queryClauseLookUps, $queryClauseReplaces, $queryData['query']);
     $query = str_replace($queryLookUps, $queryReplaces, $query);
     $parameters = array_merge($parameters, $queryData['parameters'], $data['parameters']);
     $query = $this->_getEntityManager()->createQuery($query);
     if ($offset) {
         $query->setFirstResult($offset);
     }
     if ($count) {
         $query->setMaxResults($count);
     }
     if ($parameters) {
         $query->setParameters($parameters);
     }
     $result = new DoctrineSetListResult($this, $query->getResult());
     // Get count
     $queryData = $data['count'];
     $query = str_replace($queryClauseLookUps, $queryClauseReplaces, $queryData['query']);
     $query = str_replace($queryLookUps, $queryReplaces, $query);
     $query = $this->_getEntityManager()->createQuery($query);
     if ($parameters) {
         $query->setParameters($parameters);
     }
     $result->countAll = $query->getSingleScalarResult();
     return $result;
 }
예제 #18
0
 public function validateField(ArrayFilter $filter, $field, $defaultValue = null)
 {
     $this->validate($field, $filter->get($field, $defaultValue));
     return $this;
 }
예제 #19
0
파일: Module.php 프로젝트: cyantree/grout
 /** @return Route */
 public function addErrorRoute($code, $page, $pageData = null)
 {
     $f = new ArrayFilter($pageData);
     if (!$f->has('responseCode')) {
         $f->set('responseCode', $code);
     }
     $url = null;
     $activated = false;
     $priority = 0;
     if ($code == ResponseCode::CODE_404) {
         $url = '%%url,.*%%';
         $activated = true;
         $priority = -1;
     }
     $codeDigit = substr($code, 0, 3);
     return $this->addNamedRoute('GroutError' . $codeDigit, $url, $page, $f->getData(), $priority, $activated);
 }
예제 #20
0
    ?>
</a>
        <?php 
}
?>
    </div>
</div>
<div id="page">
    <?php 
if ($f->appManagedSessionData()->isLoggedIn()) {
    ?>
        <div id="menu">
            <ul>
                <?php 
    $activeMenu = $this->task->vars->get('menu');
    $filter = new ArrayFilter();
    $menuLinks = $m->menuLinks;
    foreach ($menuLinks as $menuLink) {
        $filter->setData($menuLink);
        /** @var AccessRule $access */
        $access = ArrayTools::get($menuLink, 'access');
        if ($access && !$f->hasAccess($access)) {
            continue;
        }
        $id = $filter->get('id');
        $url = $menuLink['url'];
        $active = $id !== null && $id === $activeMenu || $filter->get('route') == $this->task->route;
        $c = '<li' . ($active ? ' class="active"' : '') . '><a href="' . $q->e($url) . '">' . $q->e($filter->get('title')) . '</a></li>';
        echo $c;
    }
    ?>
예제 #21
0
 public function getArrayFilter($key, $defaultContents = null)
 {
     $filter = new ArrayFilter();
     $node = $this->getSoft($key, $defaultContents);
     if ($node === self::VALUE_UNSET) {
         $filter->setData($defaultContents);
     } else {
         $filter->setData(get_object_vars($node));
     }
     return $filter;
 }