Example #1
0
 protected function render($code, $x, $y, $method)
 {
     $file = $this->items->where('code', $code)->fetch();
     $this->sourcepath = FILESTORAGE_DIR . '/' . $file->filepath;
     $this->cachepath = TEMP_DIR . '/imagecache/' . $file->id;
     $this->imagepath = $this->cachepath . '/' . $method . "-" . $x . "x" . $y . '.' . $file->filename;
     $expires = 60 * 60 * 24 * 31;
     $etag = '"' . md5($this->imagepath) . '"';
     if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
         header('HTTP/1.1 304 Not Modified');
         header('Content-Length: 0');
         exit;
     }
     header('ETag: ' . $etag);
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
     header("Pragma: public");
     // required
     header("Cache-Control: maxage=" . $expires);
     header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
     header("Cache-Control: cache");
     header("Cache-Control: private", false);
     // required for certain browsers
     header("Content-Transfer-Encoding: binary");
     if (!file_exists($this->imagepath) || $file->changed > $file->created) {
         try {
             if (file_exists($this->sourcepath)) {
                 $image = Image::fromFile($this->sourcepath);
             } else {
                 $image = Image::fromBlank($x, $y, array('red' => 240, 'green' => 240, 'blue' => 240));
             }
             @$image->resize($x, $y, $method);
             $image->sharpen();
             if ($method == 5) {
                 $image->crop(0, 0, $x, $y);
             }
             if (!file_exists($this->cachepath)) {
                 mkdir($this->cachepath, 0777, true);
                 chmod($this->cachepath, 0777);
             }
             if (file_exists($this->sourcepath)) {
                 $image->save($this->imagepath, 66, Image::JPEG);
             } else {
                 $image->string(2, 5, $y / 2 - 7, 'No image found', 1);
             }
             $image->send();
         } catch (Exception $e) {
         }
     } else {
         header('Content-Disposition: inline; filename="' . $this->imagepath . '"');
         header("Content-Type: image/jpeg");
         header("Content-Length: " . @filesize($this->imagepath));
         readfile($this->imagepath);
     }
 }
Example #2
0
 /**
  * Performs an authentication
  * @param  array
  * @return Nette\Security\Identity
  * @throws Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     $row = $this->curators->where('username', $username)->fetch();
     if (!$row) {
         throw new NS\AuthenticationException("Uživatel '{$username}' nebyl nalezen.", self::IDENTITY_NOT_FOUND);
     }
     if ($row->password !== $this->calculateHash($password)) {
         throw new NS\AuthenticationException("Špatné heslo.", self::INVALID_CREDENTIAL);
     }
     return new NS\Identity($row->username, NULL, $row->toArray());
 }
Example #3
0
 /**
  * Performs an authentication
  * @param  array
  * @return Nette\Security\Identity
  * @throws Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     $row = $this->users->where('username', $username)->fetch();
     if (!$row) {
         throw new NS\AuthenticationException("User '{$username}' not found.", self::IDENTITY_NOT_FOUND);
     }
     if ($row->password !== $this->calculateHash($password)) {
         throw new NS\AuthenticationException("Invalid password.", self::INVALID_CREDENTIAL);
     }
     unset($row->password);
     return new NS\Identity($row->id, $row->role, $row->toArray());
 }
Example #4
0
 /**
  * Performs an authentication
  * @param  array
  * @return Nette\Security\Identity
  * @throws Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     $user = $this->users->where('email', $credentials['email'])->fetch();
     if (!$user) {
         $data = array("username" => $credentials['username'], "email" => $credentials['email'], "name" => $credentials['first_name'], "surname" => $credentials['last_name'], "sex" => strtoupper((string) $credentials['gender'][0]), "facebook_id" => $credentials['id'], "role" => "member", "password" => hash("sha512", strftime('%a%b%y') . str_repeat('mooow', 10)), "generated_password" => 1, "active" => 1);
         $user = $this->users->insert($data);
     } else {
         if ($user->facebook_id !== $credentials['id']) {
             $this->users->update(array('facebook_id' => $credentials['id']));
         }
     }
     $this->users->update(array('last_login' => new DibiDateTime(), 'last_ip' => $_SERVER['REMOTE_ADDR']));
     return new NS\Identity($user->id, $user->role, $user->toArray());
 }
Example #5
0
File: Grid.php Project: vsek/grid
 public function render()
 {
     $template = $this->getTemplate();
     $template->setFile($this->templateDir . '/' . $this->templateFile);
     $template->setTranslator($this->getPresenter()->translator);
     //upravim model
     if (!is_null($this->order)) {
         $this->model->order($this->order . ' ' . $this->orderDir);
     } elseif (!is_null($this->orderDefault)) {
         if (is_null($this->orderDirDefault)) {
             $orderDir = 'ASC';
         } else {
             $orderDir = $this->orderDirDefault;
         }
         $this->model->order($this->orderDefault . ' ' . $orderDir);
     }
     //strankovani
     $this->visualPaginator->getPaginator()->setItemsPerPage($this->itemsToPage);
     $this->visualPaginator->getPaginator()->setItemCount($this->model->count('*'));
     $this->model->limit($this->visualPaginator->getPaginator()->getLength(), $this->visualPaginator->getPaginator()->getOffset());
     $template->columns = $this->columns;
     $template->model = $this->model;
     $template->menu = $this->menu;
     $template->uniquete = $this->uniquete;
     $template->emptyText = is_null($this->emptyText) ? $this->getPresenter()->translator->translate('admin.grid.noItemFound') : $this->emptyText;
     $template->visualPaginator = $this->visualPaginator;
     $template->order = $this->order;
     $template->orderDir = $this->orderDir;
     $template->ordering = $this->ordering;
     $template->render();
 }
Example #6
0
 public function __construct(Nette\Database\Context $db)
 {
     $this->db = $db;
     Nette\Database\Table\Selection::extensionMethod('getCursor', function ($selection) use($db) {
         return $db->queryArgs($selection->getSql(), $selection->getSqlBuilder()->getParameters());
     });
 }
Example #7
0
 public function renderDetail($code)
 {
     $items = $this->items->fetchVisible()->fetchAll();
     $item = clone $this->items;
     $this->template->item = $item->where('code', $code)->fetch();
     $id = $this->template->item->id;
     $i = 0;
     foreach ($items as $key => $value) {
         $v[$i] = $value;
         if ($key == $id) {
             $this->template->next_id = $i + 1;
             $this->template->prev_id = $i - 1;
         }
         $i++;
     }
     $this->template->items = $v;
 }
Example #8
0
    public function deleteFormSubmitted(Form $form) {
        if ($form['delete']->isSubmittedBy()) {
            $this->pages->find($this->getParam('id'))->delete();
            $this->flashMessage('Stránka byla smazána.');
        }

        $this->redirect('default');
    }
Example #9
0
 public function handleThumbDown($key)
 {
     try {
         $this->items->thumb($key, "down");
     } catch (\DibiException $e) {
         $this->template->msg = $e->getMessage();
     }
     $this->redrawControl('rating');
 }
Example #10
0
	public function deleteFormSubmitted(Form $form)
	{
		if ($form['delete']->isSubmittedBy()) {
			$this->albums->find($this->getParam('id'))->delete();
			$this->flashMessage('Album has been deleted.');
		}

		$this->redirect('default');
	}
Example #11
0
 public function renderDetail($id)
 {
     $rating = new \Nette\Database\Table\Selection($this->context->database->getConnection(), 'event_rating', $this->context->reflection);
     $this->template->rating = $rating->select('sum(thumb_up) thumb_up, sum(thumb_down) thumb_down, round(sum(thumb_up)/(sum(thumb_up)+sum(thumb_down))*100) thumb_up_percent')->where('event_id', $id)->group('event_id')->fetch();
 }