Example #1
0
 /**
  * Loads HTTP data.
  * @return void
  */
 public function loadHttpData()
 {
     $path = $this->getHtmlName();
     // img_x or img['x']
     $path = explode('[', strtr(str_replace(']', '', strpos($path, '[') === FALSE ? $path . '.x' : substr($path, 0, -2)), '.', '_'));
     $this->setValue(ArrayTools::get($this->getForm()->getHttpData(), $path) !== NULL);
 }
Example #2
0
 /**
  * Internal: receives submitted HTTP data.
  * @return array
  */
 protected function receiveHttpData()
 {
     $presenter = $this->getPresenter();
     if (!$presenter->isSignalReceiver($this, 'submit')) {
         return;
     }
     $isPost = $this->getMethod() === self::POST;
     $request = $presenter->getRequest();
     if ($request->isMethod('forward') || $request->isMethod('post') !== $isPost) {
         return;
     }
     if ($isPost) {
         return ArrayTools::mergeTree($request->getPost(), $request->getFiles());
     } else {
         return $request->getParams();
     }
 }
Example #3
0
 /**
  * Detects form submission and loads PresenterRequest values.
  * @return void
  */
 public function processHttpRequest($foo = NULL)
 {
     $presenter = $this->getPresenter();
     $this->submittedBy = FALSE;
     if (!$presenter->isSignalReceiver($this, 'submit')) {
         return;
     }
     $isPost = strcasecmp($this->getMethod(), 'post') === 0;
     $request = $presenter->getRequest();
     if ($request->isMethod('forward') || $request->isMethod('post') !== $isPost) {
         return;
     }
     $this->submittedBy = TRUE;
     if ($isPost) {
         $this->loadHttpData(ArrayTools::mergeTree($request->getPost(), $request->getFiles()));
     } else {
         $this->loadHttpData($request->getParams());
     }
 }
 /**
  * Returns uploaded file.
  * @param  string key (or more keys)
  * @return HttpUploadedFile
  */
 public final function getFile($key)
 {
     if ($this->files === NULL) {
         $this->initialize();
     }
     $args = func_get_args();
     return ArrayTools::get($this->files, $args);
 }
Example #5
0
 /**
  * Reads configuration from INI file.
  * @param  string  file name
  * @param  string  section to load
  * @return array
  * @throws InvalidStateException
  */
 public static function load($file, $section = NULL)
 {
     if (!is_file($file) || !is_readable($file)) {
         throw new FileNotFoundException("File '{$file}' is missing or is not readable.");
     }
     Tools::tryError();
     $ini = parse_ini_file($file, TRUE);
     if (Tools::catchError($msg)) {
         throw new Exception($msg);
     }
     $separator = trim(self::$sectionSeparator);
     $data = array();
     foreach ($ini as $secName => $secData) {
         // is section?
         if (is_array($secData)) {
             if (substr($secName, -1) === self::$rawSection) {
                 $secName = substr($secName, 0, -1);
             } elseif (self::$keySeparator) {
                 // process key separators (key1> key2> key3)
                 $tmp = array();
                 foreach ($secData as $key => $val) {
                     $cursor =& $tmp;
                     foreach (explode(self::$keySeparator, $key) as $part) {
                         if (!isset($cursor[$part]) || is_array($cursor[$part])) {
                             $cursor =& $cursor[$part];
                         } else {
                             throw new InvalidStateException("Invalid key '{$key}' in section [{$secName}] in '{$file}'.");
                         }
                     }
                     $cursor = $val;
                 }
                 $secData = $tmp;
             }
             // process extends sections like [staging < production] (with special support for separator ':')
             $parts = $separator ? explode($separator, strtr($secName, ':', $separator)) : array($secName);
             if (count($parts) > 1) {
                 $parent = trim($parts[1]);
                 $cursor =& $data;
                 foreach (self::$keySeparator ? explode(self::$keySeparator, $parent) : array($parent) as $part) {
                     if (isset($cursor[$part]) && is_array($cursor[$part])) {
                         $cursor =& $cursor[$part];
                     } else {
                         throw new InvalidStateException("Missing parent section [{$parent}] in '{$file}'.");
                     }
                 }
                 $secData = ArrayTools::mergeTree($secData, $cursor);
             }
             $secName = trim($parts[0]);
             if ($secName === '') {
                 throw new InvalidStateException("Invalid empty section name in '{$file}'.");
             }
         }
         if (self::$keySeparator) {
             $cursor =& $data;
             foreach (explode(self::$keySeparator, $secName) as $part) {
                 if (!isset($cursor[$part]) || is_array($cursor[$part])) {
                     $cursor =& $cursor[$part];
                 } else {
                     throw new InvalidStateException("Invalid section [{$secName}] in '{$file}'.");
                 }
             }
         } else {
             $cursor =& $data[$secName];
         }
         if (is_array($secData) && is_array($cursor)) {
             $secData = ArrayTools::mergeTree($secData, $cursor);
         }
         $cursor = $secData;
     }
     if ($section === NULL) {
         return $data;
     } elseif (!isset($data[$section]) || !is_array($data[$section])) {
         throw new InvalidStateException("There is not section [{$section}] in '{$file}'.");
     } else {
         return $data[$section];
     }
 }
Example #6
0
 /**
  * Internal: receives submitted HTTP data.
  * @return array
  */
 protected function receiveHttpData()
 {
     $httpRequest = $this->getHttpRequest();
     if (strcasecmp($this->getMethod(), $httpRequest->getMethod())) {
         return;
     }
     $httpRequest->setEncoding($this->encoding);
     if ($httpRequest->isMethod('post')) {
         $data = ArrayTools::mergeTree($httpRequest->getPost(), $httpRequest->getFiles());
     } else {
         $data = $httpRequest->getQuery();
     }
     if ($tracker = $this->getComponent(self::TRACKER_ID, FALSE)) {
         if (!isset($data[self::TRACKER_ID]) || $data[self::TRACKER_ID] !== $tracker->getValue()) {
             return;
         }
     }
     return $data;
 }
Example #7
0
 /**
  * Generates link. If links points to @secure annotated signal handler method, additonal
  * parameter preventing changing parameters will be added.
  *
  * @param string  $destination
  * @param array|mixed $args
  * @return string
  */
 public function link($destination, $args = array())
 {
     if (!is_array($args)) {
         $args = func_get_args();
         array_shift($args);
     }
     $link = parent::link($destination, $args);
     $lastrequest = $this->presenter->lastCreatedRequest;
     /* --- Bad link --- */
     if ($lastrequest === NULL) {
         return $link;
     }
     /* --- Not a signal --- */
     if (substr($destination, -1) !== '!') {
         return $link;
     }
     /* --- Exclude Form submits --- */
     if (substr($destination, -8) === '-submit!') {
         return $link;
     }
     /* --- Only on same presenter --- */
     if ($this->getPresenter()->getName() !== $lastrequest->getPresenterName()) {
         return $link;
     }
     $signal = trim($destination, '!');
     $rc = $this->getReflection()->getMethod($this->formatSignalMethod($signal));
     //        if (Annotations::has($rc, 'secured') === FALSE) {
     if ($rc->hasAnnotation('secured') === FALSE) {
         return $link;
     }
     $origParams = $lastrequest->getParams();
     $protectedParams = array();
     foreach ($rc->getParameters() as $param) {
         $protectedParams[$param->name] = ArrayTools::get($origParams, $this->getParamId($param->name));
     }
     $args['__secu'] = $this->createSecureHash($protectedParams);
     return parent::link($destination, $args);
 }
Example #8
0
File: Form.php Project: vrana/nette
 /**
  * Detects form submission and loads HTTP values.
  * @param  Nette\Web\IHttpRequest  optional request object
  * @return void
  */
 public function processHttpRequest($httpRequest = NULL)
 {
     $this->submittedBy = FALSE;
     if ($httpRequest === NULL) {
         $httpRequest = $this->getHttpRequest();
     }
     $httpRequest->setEncoding($this->encoding);
     if (strcasecmp($this->getMethod(), 'post') === 0) {
         if (!$httpRequest->isMethod('post')) {
             return;
         }
         $data = ArrayTools::mergeTree($httpRequest->getPost(), $httpRequest->getFiles());
     } else {
         if (!$httpRequest->isMethod('get')) {
             return;
         }
         $data = $httpRequest->getQuery();
     }
     $tracker = $this->getComponent(self::TRACKER_ID, FALSE);
     if ($tracker) {
         if (!isset($data[self::TRACKER_ID]) || $data[self::TRACKER_ID] !== $tracker->getValue()) {
             return;
         }
     } else {
         if (!count($data)) {
             return;
         }
     }
     $this->submittedBy = TRUE;
     $this->loadHttpData($data);
     $this->submit();
 }
Example #9
0
 public static function copyKeys($source, $target, $excludeKeys = null, $includeKeys = null)
 {
     $sourceIsObject = is_object($source);
     $targetIsObject = is_object($target);
     if (is_string($excludeKeys)) {
         $excludeKeys = array($excludeKeys => true);
     } elseif (is_array($excludeKeys)) {
         $excludeKeys = ArrayTools::convertToKeyArray($excludeKeys);
     }
     if (is_string($includeKeys)) {
         $includeKeys = array($includeKeys => true);
     } elseif (is_array($includeKeys)) {
         $includeKeys = ArrayTools::convertToKeyArray($includeKeys);
     }
     if ($includeKeys !== null && $excludeKeys === null) {
         foreach ($includeKeys as $key => $foo) {
             if ($sourceIsObject) {
                 $val = $source->{$key};
             } else {
                 $val = $source[$key];
             }
             if ($targetIsObject) {
                 $target->{$key} = $val;
             } else {
                 $target[$key] = $val;
             }
         }
     } else {
         $keys = array();
         if ($sourceIsObject) {
             foreach ($source as $key => $value) {
                 $keys[$key] = $value;
             }
         } else {
             $keys =& $source;
         }
         foreach ($keys as $key => $val) {
             $included = null;
             if ($includeKeys !== null) {
                 $included = isset($includeKeys[$key]);
             }
             if ($excludeKeys !== null) {
                 if (isset($excludeKeys[$key]) && !$included) {
                     continue;
                 }
             } else {
                 if ($includeKeys !== null && !$included) {
                     continue;
                 }
             }
             if ($targetIsObject) {
                 $target->{$key} = $val;
             } else {
                 $target[$key] = $val;
             }
         }
     }
     return $target;
 }
Example #10
0
 /**
  * Loads HTTP data.
  * @return void
  */
 public function loadHttpData()
 {
     $path = explode('[', strtr(str_replace(array('[]', ']'), '', $this->getHtmlName()), '.', '_'));
     $this->setValue(ArrayTools::get($this->getForm()->getHttpData(), $path));
 }
Example #11
0
 public function actionOrder_Array()
 {
     $data = array(array('valor' => 10), array('valor' => 50), array('valor' => 75), array('valor' => 5), array('valor' => 100));
     $dataSorted = ArrayTools::ORDER_ARRAY($data, 'valor');
     $dataSortedInv = ArrayTools::ORDER_ARRAY($data, 'valor', true);
     $this->render('order_array', array('data' => $data, 'dataSorted' => $dataSorted, 'dataSortedInv' => $dataSortedInv));
 }
Example #12
0
 public function addqueue()
 {
     if ($this->chars == 9) {
         $sql = "SELECT id FROM movies\n \t\t\t\t\tWHERE imdbid = :imdbid";
         $resultfrommovies = $this->db->select_query($sql, array(':imdbid' => $_POST['imdbid']));
         if (sizeof($resultfrommovies)) {
             header("Location:" . URL . "movie/display/" . $resultfrommovies[0]['id']);
             break;
         }
         $sql = "SELECT id FROM queue\n \t\t\t\t\tWHERE imdb = :imdbid";
         $resultfromqueue = $this->db->select_query($sql, array(':imdbid' => $_POST['imdbid']));
         if (sizeof($resultfromqueue)) {
             header("Location:" . URL . "movie/queue");
             break;
         }
         $imdb = new Imdb();
         $imdbid = $this->imdbid;
         $movieData = $imdb->getMovieInfoById($imdbid);
         $title = trim($movieData['title']);
         $year = $movieData['year'];
         $sql = "SELECT title FROM movies\n\t\t\t\t\tWHERE movies.title = :title\n\t\t\t\t\tUNION\n\t\t\t\t\tSELECT title FROM queue\n\t\t\t\t\tWHERE queue.title = :title";
         $result = $this->db->select_query($sql, array(':title' => $title));
         if (sizeof($result) == 0) {
             $sql = "INSERT INTO queue (imdb , title, year, added)\n\t \t\t\t\t\tVALUES (:imdbid, :title, :year, CURDATE())";
             $imdbidt = $this->imdbid;
             $result = $this->db->select_query($sql, array(':imdbid' => $imdbidt, ':title' => $title, ':year' => $year));
             $mid = $this->db->lastInsertId('id');
             foreach ($movieData['genres'] as $genre) {
                 $param[] = array(':genre' => $genre);
             }
             $sql = "SELECT id FROM genres\n\t\t\t\t\t\tWHERE genre = :genre";
             $result = $this->db->multi_query($sql, $param);
             echo '<pre>';
             var_dump($result);
             echo '</pre>';
             foreach ($result as $key => $value) {
                 echo sizeof($value);
                 if (sizeof($value) == 0) {
                     $insertparam[] = $param[$key];
                 } else {
                     $genreparam[] = $value[0];
                 }
             }
             $sql = "INSERT INTO genres (genre)\n\t\t\t\t\t\tVALUES(:genre)";
             $this->db->multi_query($sql, $insertparam);
             $gid = $this->db->lastInsertId('id');
             for ($i = $gid - sizeof($insertparam) + 1; $i <= $gid; $i++) {
                 $genreparam[] = $i;
             }
             $ar = new ArrayTools();
             $genres = $ar->unique_flat_array($genreparam);
             foreach ($genres as $value) {
                 $genresin[] = array(':gid' => $value, ':mid' => $mid);
             }
             $sql = "INSERT INTO genresinqueue (movie_id,genre_id)\n\t\t\t\t\t\tVALUES (:mid,:gid)";
             $this->db->multi_query($sql, $genresin);
             header("Location:" . URL . "movie/queue");
         } else {
             $sql = "SELECT id FROM movies\n\t\t\t\t\t\tWHERE title = :title";
             $resultfrommovies = $this->db->select_query($sql, array(':title' => $title));
             if (sizeof($resultfrommovies) > 0) {
                 header("Location:" . URL . "movie/display/" . $resultfrommovies[0]['id']);
                 break;
             } else {
                 header("Location:" . URL . "movie/queue");
             }
         }
         break;
     }
     $this->viewModel->set('urlValues', $this->urlValues);
     $this->viewModel->set('pageTitle', TITLE . 'Köa en film');
     return $this->viewModel;
 }
Example #13
0
 public static function parse($string, $args, $filterCallback = null)
 {
     $argsIsObject = is_object($args);
     if (!$argsIsObject && !is_array($args)) {
         $args = array($args);
     }
     if ($args === null || !$argsIsObject && !count($args)) {
         return $string;
     }
     $internalCounter = 0;
     $result = '';
     $parts = explode('%', $string);
     $isPara = true;
     $replaces = array();
     $texts = array();
     foreach ($parts as $part) {
         $isPara = !$isPara;
         if (!$isPara) {
             $result .= $part;
         } else {
             if ($part === '') {
                 $result .= '%';
             } else {
                 $type = $part[0];
                 if (strlen($part) > 1) {
                     $index = mb_substr($part, 1);
                     if (substr($index, 0, 1) == ':') {
                         $index = substr($index, 1);
                     }
                 } else {
                     $index = $internalCounter++;
                 }
                 if ($argsIsObject) {
                     $val = $args->{$index};
                 } else {
                     $val = $args[$index];
                 }
                 $replaces[] = array($type, $val);
                 $texts[] = $result;
                 $result = '';
             }
         }
     }
     $lastText = $result;
     if ($replaces && $filterCallback != null) {
         $replaces = call_user_func($filterCallback, $replaces);
     }
     foreach ($replaces as $key => $replace) {
         if (!is_array($replace)) {
             continue;
         }
         $type = $replace[0];
         $val = $replace[1];
         if ($type == 'i') {
             $val = intval($val);
         } else {
             if ($type == 'f') {
                 $val = floatval($val);
             } else {
                 if ($type == 'b') {
                     $val = intval($val);
                 } else {
                     if ($type == 'I') {
                         $val = implode(',', ArrayTools::prepare($val, 'int', array('excludeEmpty' => true)));
                     } else {
                         if ($type == 'F') {
                             $val = implode(',', ArrayTools::prepare($val, 'float', array('excludeEmpty' => true)));
                         } else {
                             if ($type == 'R') {
                                 $val = implode(',', $val);
                             }
                         }
                     }
                 }
             }
         }
         $replaces[$key] = $val;
     }
     $result = '';
     foreach ($texts as $key => $text) {
         $result .= $text . $replaces[$key];
     }
     return $result . $lastText;
 }