Пример #1
0
 public function checkServerAdmin($serverArgs)
 {
     $val = ArrayTools::get($serverArgs, 'SERVER_ADMIN');
     if ($val !== null) {
         $this->checkConfig(StringTools::camelCase(StringTools::toUrlPart($val), '-'));
     }
 }
Пример #2
0
 public function k($object, $key, $defaultValue = null, $type = null, $typeArgs = null)
 {
     $data = ArrayTools::get($object, $key, $defaultValue);
     if ($type === null) {
         return $data;
     } else {
         return VarTools::prepare($data, $type, $typeArgs);
     }
 }
Пример #3
0
 public function constraintFileInput(FileConstraint $constraint, $parameters = null)
 {
     $defaultParameters = array('error' => $constraint->hasError, 'required' => $constraint->required && $constraint->checkEmptyValues && ArrayTools::get($parameters, 'required') !== false);
     if ($parameters !== null) {
         $parameters = array_merge($defaultParameters, $parameters);
     } else {
         $parameters =& $defaultParameters;
     }
     return $this->fileInput($constraint->name, ArrayTools::get($parameters, 'accept'), $parameters);
 }
Пример #4
0
 public function isGranted($permittedGrant, $userGrants = null, $userRole = null)
 {
     if ($userGrants) {
         $userGrants = ArrayTools::convertToKeyArray($userGrants);
     } elseif ($userRole) {
         $userGrants = $this->config->roles[$userRole]->getGrants();
     } elseif (!$userGrants) {
         $userRole = $this->getAccount()->role;
         if (!$userRole) {
             return false;
         }
         $userGrants = $this->config->roles[$userRole]->getGrants();
     }
     return isset($userGrants['*']) || isset($userGrants[$permittedGrant]);
 }
 public function loadValuesFrom($arrayOrObjectOrArrayFilter, $exclude = null)
 {
     if ($arrayOrObjectOrArrayFilter instanceof ArrayFilter) {
         $arrayOrObjectOrArrayFilter = $arrayOrObjectOrArrayFilter->getData();
     }
     if ($exclude !== null) {
         $exclude = ArrayTools::convertToKeyArray($exclude);
     }
     if (is_array($arrayOrObjectOrArrayFilter)) {
         foreach ($this->constraints as $name => $constraint) {
             if ($exclude !== null && isset($exclude[$name])) {
                 continue;
             }
             $constraint->value = isset($arrayOrObjectOrArrayFilter[$name]) ? $arrayOrObjectOrArrayFilter[$name] : null;
         }
     } else {
         foreach ($this->constraints as $name => $constraint) {
             if ($exclude !== null && isset($exclude[$name])) {
                 continue;
             }
             $constraint->value = isset($arrayOrObjectOrArrayFilter->{$name}) ? $arrayOrObjectOrArrayFilter->{$name} : null;
         }
     }
 }
 /** @return EntityManager */
 public function getEntityManager()
 {
     if (!$this->_entityManager) {
         /** @var GroutAppConfig $c */
         $c = $this->app->getConfig();
         $cache = new SimplifiedFilesystemCache($this->app->cacheStorage->createStorage($this->id . '\\Cache\\'));
         $proxies = $this->app->dataStorage->createStorage($this->id . '\\Proxies\\');
         $config = Setup::createConfiguration($c->developmentMode, $proxies, $cache);
         $driver = new StaticPHPDriver($this->moduleConfig->entityPaths);
         $config->setMetadataDriverImpl($driver);
         if ($c->developmentMode && $this->moduleConfig->logQueries) {
             $config->setSQLLogger(new DoctrineLogger($this->app));
         }
         $this->_entityManager = EntityManager::create($this->moduleConfig->connectionDetails, $config);
         $driver = ArrayTools::get($this->moduleConfig->connectionDetails, 'driver');
         if (in_array($driver, array('pdo_mysql', 'mysql', 'mysqli'))) {
             $charset = ArrayTools::get($this->moduleConfig->connectionDetails, 'charset');
             if ($charset) {
                 $this->_entityManager->getConnection()->exec('SET NAMES `' . $charset . '`');
             }
         }
     }
     return $this->_entityManager;
 }
Пример #7
0
 public static function processAuthorization(AclModule $module, Task $task, $neededRole = null, $neededGrant = null)
 {
     $f = AclFactory::get($task->app, null, $module);
     $success = false;
     if ($neededRole) {
         $success = $f->acl()->isPermittedRole($neededRole);
     }
     if ($neededGrant) {
         $success = $f->acl()->isGranted($neededGrant);
     }
     if (!$success) {
         list($username, $password) = $task->request->post->getMultiple(array('username', 'password'), false);
         if ($username && $password) {
             // Check inline registered accounts
             $config = $f->config();
             /** @var AclAccount $account */
             $account = ArrayTools::get($config->accounts, $username);
             if ($account) {
                 $success = $password == $account->password && $f->acl()->isPermittedRole($neededRole, $account->role);
                 if ($success) {
                     $f->sessionData()->login($account);
                 }
             } else {
                 $request = new AclLoginRequest();
                 $request->username = $username;
                 $request->password = $password;
                 $module->events->trigger('login', $request);
                 if ($request->response->account) {
                     $f->sessionData()->login($request->response->account);
                     $success = true;
                 }
             }
         }
     }
     return $success;
 }
Пример #8
0
 public function setMatchUrl($url)
 {
     if (preg_match('!^([a-zA-Z,]+)@!', $url, $urlData)) {
         $url = substr($url, strlen($urlData[0]));
         $this->methods = ArrayTools::convertToKeyArray(explode(',', strtoupper($urlData[1])));
     }
     $data = AppTools::decodeUri($url, $this->module->app, $this->module, $this->plugin);
     $url = '';
     if ($data[1]) {
         $url .= $data[1]->urlPrefix;
     } elseif ($data[0]) {
         $url .= $data[0]->urlPrefix;
     }
     $this->matchUrl = $url . $data[2];
     $this->_matchData = null;
 }
Пример #9
0
 public function inArray($array, $options = null)
 {
     if ($this->stopOnError && !$this->hasValidated($this->_currentId)) {
         return $this;
     }
     if (!in_array($this->_currentValue, $array)) {
         $this->_addError('inArray', ArrayTools::get($options, 'message'));
     }
     return $this;
 }
Пример #10
0
    </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;
    }
    ?>
            </ul>
        </div>
    <?php 
}
?>
Пример #11
0
 public static function drawText($text, $ttfFont, $size, $textColor = 0xff, $backgroundColor = 0x0, $additionalConfigs = null)
 {
     $text = StringTools::toNumericEntities($text);
     $box = imagettfbbox($size, 0, $ttfFont, $text);
     $yOffset = $box[1];
     $width = round($box[2] - $box[0] + $size * 0.2);
     $height = round($box[1] - $box[7] + $size * 0.2);
     $xOffset = $width > 50 ? 50 : round($width / 2);
     $image = imagecreate($width, $height);
     $cropCol = imagecolorallocate($image, 255, 0, 255);
     imagefilledrectangle($image, 0, 0, $width, $height, $cropCol);
     imagettftext($image, $size, 0, $xOffset, $height - $yOffset, imagecolorallocate($image, 255, 255, 255), $ttfFont, $text);
     $croppingPrecision = ArrayTools::get($additionalConfigs, 'croppingPrecision', 2);
     // Crop left
     $cropLeft = -1;
     for ($x = 0; $x < 50 + $width / 2; $x += $croppingPrecision) {
         if ($x >= $width) {
             $cropLeft = $x - 1;
             break;
         }
         for ($y = 0; $y < $height; $y += $croppingPrecision) {
             $col = imagecolorat($image, $x, $y);
             if ($col != 0) {
                 $cropLeft = $x - 1;
                 break 1;
             }
         }
         if ($cropLeft >= 0) {
             break;
         }
     }
     $xOffset = $xOffset - $cropLeft - 1;
     $yOffset = 0;
     $temp = imagettftext($image, $size, 0, 0, 0, $cropCol, $ttfFont, $text);
     if (ArrayTools::get($additionalConfigs, 'slim')) {
         $offset = $temp;
     } else {
         $offset = imagettftext($image, $size, 0, 0, 0, $cropCol, $ttfFont, 'BTj&#' . ord(utf8_decode('`')) . ';');
     }
     $width = $temp[2] - $temp[0];
     $height = abs($offset[5] - $offset[1]);
     if ($margin = ArrayTools::get($additionalConfigs, 'safeMargin')) {
         if (is_array($margin)) {
             $width += $margin[1] + $margin[3];
             $xOffset += $margin[3];
             $height += $margin[0] + $margin[2];
             $yOffset += $margin[0];
         } else {
             $width += $margin * 2;
             $height += $margin * 2;
             $xOffset += $margin;
             $yOffset += $margin;
         }
     }
     imagedestroy($image);
     $image = imagecreatetruecolor($width, $height);
     imagealphablending($image, false);
     imagesavealpha($image, true);
     $backgroundColor = self::colorHexToRgba($backgroundColor);
     $backgroundColor = imagecolorallocatealpha($image, $backgroundColor['r'], $backgroundColor['g'], $backgroundColor['b'], 127 - floor($backgroundColor['a'] / 2));
     $textColor = self::colorHexToRgba($textColor);
     $textColor = imagecolorallocatealpha($image, $textColor['r'], $textColor['g'], $textColor['b'], 127 - floor($textColor['a'] / 2));
     imagefilledrectangle($image, 0, 0, $width, $height, $backgroundColor);
     imagealphablending($image, true);
     imagettftext($image, $size, 0, $xOffset, -$offset[5] + $yOffset, $textColor, $ttfFont, $text);
     return $image;
 }
Пример #12
0
 public function populate($data)
 {
     $this->uploadedFile = ArrayTools::getPrepared($_FILES, $this->name, 'file');
 }
Пример #13
0
 public static function createConfigChain($primaryConfig, $defaultConfig, $namespace = '', $useServerAdmin = true, $useServerName = true, $prefix = '')
 {
     $chain = array();
     if ($primaryConfig) {
         $chain[] = $namespace . '\\' . $prefix . $primaryConfig . 'Config';
     }
     if ($useServerAdmin) {
         $chain[] = $namespace . '\\' . $prefix . StringTools::camelCase(StringTools::toURLPart(ArrayTools::get($_SERVER, 'SERVER_ADMIN')), '-') . 'Config';
     }
     if ($useServerName) {
         $chain[] = $namespace . '\\' . $prefix . StringTools::camelCase(StringTools::toURLPart(ArrayTools::get($_SERVER, 'HTTP_HOST')), '-') . 'Config';
     }
     if ($defaultConfig) {
         $chain[] = $namespace . '\\' . $prefix . $defaultConfig . 'Config';
     }
     return $chain;
 }
Пример #14
0
 /** @param StatusContainer|UiElement|string $status */
 public function status($status, $parameters = null)
 {
     $isStatusContainer = $status instanceof StatusContainer;
     $noStatus = $status === '' || $isStatusContainer && !$status->hasSuccessMessages && !$status->hasErrorMessages && !$status->hasInfoMessages;
     if ($noStatus && !ArrayTools::get($parameters, 'showIfEmpty')) {
         return '';
     }
     if ($isStatusContainer) {
         /** @var $status StatusContainer */
         $includeStatusCodes = ArrayTools::get($parameters, 'include');
         $excludeStatusCodes = ArrayTools::get($parameters, 'exclude');
         if (is_string($includeStatusCodes)) {
             $includeStatusCodes = array($includeStatusCodes);
         }
         if ($includeStatusCodes) {
             $includeStatusCodes = ArrayTools::convertToKeyArray($includeStatusCodes);
         }
         if (is_string($excludeStatusCodes)) {
             $excludeStatusCodes = array($excludeStatusCodes);
         }
         if ($excludeStatusCodes) {
             $excludeStatusCodes = ArrayTools::convertToKeyArray($excludeStatusCodes);
         }
         $element = new UiElement('div', array('class' => 'GroutStatusBox'));
         $this->processGenericParameters($element, $parameters);
         $c = '';
         $messages = array();
         foreach ($status->infoMessages as $code => $message) {
             if (($excludeStatusCodes === null || !isset($excludeStatusCodes[$code])) && ($includeStatusCodes === null || isset($includeStatusCodes[$code]))) {
                 $messages[] = $message;
             }
         }
         if ($messages) {
             $c .= $this->statusInfo($messages);
         }
         $messages = array();
         foreach ($status->successMessages as $code => $message) {
             if (($excludeStatusCodes === null || !isset($excludeStatusCodes[$code])) && ($includeStatusCodes === null || isset($includeStatusCodes[$code]))) {
                 $messages[] = $message;
             }
         }
         if ($messages) {
             $c .= $this->statusSuccess($messages);
         }
         $messages = array();
         foreach ($status->errors as $code => $message) {
             if (($excludeStatusCodes === null || !isset($excludeStatusCodes[$code])) && ($includeStatusCodes === null || isset($includeStatusCodes[$code]))) {
                 $messages[] = $message;
             }
         }
         if ($messages) {
             $c .= $this->statusError($messages);
         }
         $element->contents = $c;
     } else {
         $element = new UiElement('div', array('class' => 'GroutStatusBox'), $status);
         $this->processGenericParameters($element, $parameters);
     }
     return $element;
 }
Пример #15
0
 public function __construct()
 {
     $this->ip = ArrayTools::get($_SERVER, 'REMOTE_ADDR');
     $this->userAgent = ArrayTools::get($_SERVER, 'HTTP_USER_AGENT');
     $this->name = 'Session_' . substr(md5(__FILE__), 0, 16);
 }
Пример #16
0
 public static function prepare($data, $type, $args = null)
 {
     // file, int, float, bool, string, line, raw, sql, sqlite
     if ($type === null) {
         $type = 'raw';
     }
     $len = strlen($type);
     $isArray = substr($type, $len - 2, 2) == '[]';
     if ($isArray) {
         return ArrayTools::prepare($data, substr($type, 0, $len - 2), $args);
     }
     /*
      * int, float: args = min,max
      * string, line, raw: args = length
      * sql, sqlite: args = encapsulate
      */
     //		if($data === null) return null;
     if (is_resource($data) || is_object($data)) {
         return null;
     }
     if ($type == 'file') {
         if (!is_array($data)) {
             return null;
         }
         if (!isset($data['tmp_name']) || is_array($data['tmp_name']) || $data['error'] == 4) {
             return null;
         }
     } else {
         if (is_array($data)) {
             return null;
         }
     }
     if ($type == 'file') {
         $u = new FileUpload();
         $u->name = $data['name'];
         $u->file = $data['tmp_name'];
         $u->size = $data['size'];
         $u->error = $data['error'];
         return $u;
     } else {
         $typeIsString = $type == 'raw' || $type == 'line' || $type == 'string' || $type == 'sql' || $type == 'sqlite';
         $typeIsNumber = !$typeIsString && ($type == 'int' || $type == 'float');
         $padLeft = $typeIsString ? ArrayTools::get($args, 'padLeft') : null;
         $padRight = $typeIsString ? ArrayTools::get($args, 'padRight') : null;
         $length = $min = $max = 0;
         if ($typeIsString) {
             $length = ArrayTools::get($args, 'length');
         } else {
             if ($typeIsNumber) {
                 $min = ArrayTools::get($args, 'min');
                 $max = ArrayTools::get($args, 'max');
             }
         }
         if ($type == 'sql') {
             $data = mysql_real_escape_string($data);
         } else {
             if ($type == 'sqlite') {
                 $data = str_replace('"', '""', $data);
             } else {
                 if ($type == 'int') {
                     $data = intval($data);
                 } else {
                     if ($type == 'float') {
                         $data = floatval($data);
                     } else {
                         if ($type == 'bool') {
                             $data = $data == '1' || $data == 'true';
                         } else {
                             $data = trim($data);
                             $data = preg_replace('/[\\x00-\\x08]/', '', $data);
                             if ($type == 'line') {
                                 $data = str_replace(array("\r", "\n", "\t"), array('', '', ''), $data);
                             }
                         }
                     }
                 }
             }
         }
         if ($typeIsNumber && ($min !== null || $max !== null)) {
             $data = NumberTools::limit($data, $min, $max);
         }
         if ($typeIsString) {
             if ($length && mb_strlen($data) > $length) {
                 $data = mb_substr($data, 0, $length);
             }
             if ($padLeft !== null) {
                 $data = $padLeft . $data;
             }
             if ($padRight !== null) {
                 $data .= $padRight;
             }
         }
         return $data;
     }
 }
Пример #17
0
 public function checkSession()
 {
     return ArrayTools::get($_SESSION, '_name') == $this->name && isset($_SESSION['_lastAction']) && (!$this->checkIp || ArrayTools::get($_SESSION, '_ip') == $_SERVER['REMOTE_ADDR']) && (!$this->checkBrowser || $_SESSION['_browser'] == ArrayTools::get($_SERVER, 'HTTP_USER_AGENT')) && time() - $_SESSION['_lastAction'] <= $this->expirationTime;
 }
Пример #18
0
 public function insert($table, $fields, $values, $nestedRows = null, $rowsPerInsert = 100, $returnQueries = false)
 {
     if ($returnQueries) {
         $queries = array();
     }
     $fieldSnippet = ArrayTools::implode(array_keys($fields), ',', '`', '`');
     $typeSnippet = '(' . implode(',', array_values($fields)) . ')';
     $q = 'INSERT INTO ' . $table . ' (' . $fieldSnippet . ')VALUES';
     $args = array();
     $rowCount = 0;
     if ($nestedRows) {
         $firstRow = true;
         foreach ($nestedRows as $row) {
             $rowCount++;
             if ($firstRow) {
                 $firstRow = false;
                 $q .= $typeSnippet;
             } else {
                 $q .= ',' . $typeSnippet;
             }
             $args = array_combine($args, $row);
             if ($rowCount > $rowsPerInsert) {
                 if ($returnQueries) {
                     $queries[] = $this->prepareQuery($q, $args);
                 } else {
                     $this->exec($q, $args);
                 }
                 $q = 'INSERT INTO ' . $table . ' (' . $fieldSnippet . ')VALUES';
                 $args = array();
                 $rowCount = 0;
             }
         }
         if (count($args)) {
             if ($returnQueries) {
                 $queries[] = $this->prepareQuery($q, $args);
             } else {
                 $this->exec($q, $args);
             }
         }
     } else {
         $fieldCount = count($fields);
         $rows = count($values) / $fieldCount;
         $rowCount = 0;
         $i = 0;
         $isFirstRow = true;
         while ($rows) {
             $rows--;
             $rowCount++;
             $field = $fieldCount;
             while ($field--) {
                 $args[] = $values[$i];
                 $i++;
             }
             if ($isFirstRow) {
                 $isFirstRow = false;
                 $q .= $typeSnippet;
             } else {
                 $q .= ',' . $typeSnippet;
             }
             if ($rowCount > $rowsPerInsert) {
                 if ($returnQueries) {
                     $queries[] = $this->prepareQuery($q, $args);
                 } else {
                     $this->exec($q, $args);
                 }
                 $q = 'INSERT INTO ' . $table . ' (' . $fieldSnippet . ')VALUES';
                 $args = array();
                 $rowCount = 0;
             }
         }
         if (count($args)) {
             if ($returnQueries) {
                 $queries[] = $this->prepareQuery($q, $args);
             } else {
                 $this->exec($q, $args);
             }
         }
     }
     if ($returnQueries) {
         return $queries;
     }
     return null;
 }
Пример #19
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;
 }