Skip to content

Commit

Permalink
Merge branch 'release-1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtnzlml committed Mar 27, 2015
2 parents b21775d + 9e780f7 commit 007359a
Show file tree
Hide file tree
Showing 178 changed files with 5,730 additions and 18,508 deletions.
3 changes: 3 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "vendor-client/"
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
log/*
temp/*
vendor/*
vendor-client/*

!.gitignore
!.htaccess
Expand Down
37 changes: 29 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
language: php

php:
- 5.3.3
- 5.4
- 5.5
- 5.6
- hhvm
- hhvm-nightly

env:
global:
- TESTER_PHP_BIN=php
matrix:
- DB=mysql
- DB=pgsql

matrix:
allow_failures:
- php: 5.3.3
- php: 5.6
- php: hhvm
- php: hhvm-nightly
- env: DB=pgsql
exclude:
- php: hhvm
env: TESTER_PHP_BIN=php-cgi #FIXME
- php: hhvm-nightly
env: TESTER_PHP_BIN=php-cgi #FIXME

script: vendor/bin/tester tests -s -c tests/php.ini
script:
- vendor/bin/tester tests -p $TESTER_PHP_BIN -s -c tests/php.ini

after_failure:
- cat app/config/config.local.neon; echo; echo;

before_script:
- mysql -u root -e 'create database zeminem;'
- mysql -u root -D zeminem < zeminem.sql
- mysql -u root -D zeminem < diff.sql
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -u root -e 'create database blog_mysql;'; fi"
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'create database blog_pgsql;' -U postgres; fi"
- composer selfupdate
- composer update
- composer install --prefer-dist --no-dev
- sh -c "if [ '$DB' = 'mysql' ]; then php www/index.php -u root -n blog_mysql; fi"
- sh -c "if [ '$DB' = 'pgsql' ]; then php www/index.php -u postgres -n blog_pgsql -d pgsql; fi"

notifications:
email: false
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
<?php

namespace App;
namespace App\AdminModule;

use App;
use Cntrl;
use Entity;
use Kdyby;
use Model;
use Nette;

class AdminPresenter extends BasePresenter {

public $onBeforeRestrictedFunctionality = [];

/** @var Pictures @inject */
/** @var \Model\Pictures @inject */
public $pictures;
/** @var Tags @inject */
/** @var \Model\Tags @inject */
public $tags;
/** @var Users @inject */
/** @var \Model\Users @inject */
public $users;
/** @var \Model\Pages @inject */
public $pages;

/** @var \PageFormFactory @inject */
public $pageFormFactory;
/** @var \PostFormFactory @inject */
public $postFormFactory;
/** @var \SettingsFormFactory @inject */
public $settingsFormFactory;
/** @var \UserEditFormFactory @inject */
public $userEditFormFactory;

Expand All @@ -32,10 +39,10 @@ public function startup() {
if ($this->user->logoutReason === Nette\Security\IUserStorage::INACTIVITY) {
$this->flashMessage('Byli jste odhlášeni z důvodu nečinnosti. Přihlaste se prosím znovu.', 'danger');
}
$this->redirect('Sign:in', array('backlink' => $this->storeRequest()));
} elseif (!$this->user->isAllowed($this->name, Authorizator::VIEW)) {
$this->redirect(':Sign:in', ['backlink' => $this->storeRequest()]);
} elseif (!$this->user->isAllowed($this->name, Model\Authorizator::READ)) {
$this->flashMessage('Přístup byl odepřen. Nemáte oprávnění k zobrazení této stránky.', 'danger');
$this->redirect('Sign:in', array('backlink' => $this->storeRequest()));
$this->redirect(':Sign:in', ['backlink' => $this->storeRequest()]);
}
}

Expand All @@ -44,7 +51,8 @@ public function beforeRender() {
$this->template->picturecount = $this->pictures->countBy();
$this->template->tagcount = $this->tags->countBy();
$this->template->usercount = $this->users->countBy();
if (!$this->user->isAllowed('Admin', Authorizator::EDIT)) {
$this->template->pagecount = $this->pages->countBy();
if (!$this->user->isAllowed('Admin:Admin', Model\Authorizator::READ)) {
$this->flashMessage('Nacházíte se v **demo** ukázce administrace. Máte právo prohlížet, nikoliv však editovat...', 'info');
}
}
Expand All @@ -54,28 +62,64 @@ public function actionDefault($id = NULL) {
}

public function renderDefault($id = NULL) {
$this->template->tags = $this->tags->findBy(array());
$this->template->pictures = $this->pictures->findBy(array(), ['created' => 'DESC']);
$this->template->tags = $this->tags->findBy([]);
$this->template->pictures = $this->pictures->findBy([], ['created' => 'DESC']);
if ($id !== NULL) {
$this->template->editace = TRUE;
}
$this->id = $id;
}

public function actionPageEdit($id = NULL) {
$this->id = $id;
}

public function renderPageEdit($id = NULL) {
$this->template->pictures = $this->pictures->findBy([], ['created' => 'DESC']);
if ($id !== NULL) {
$this->template->editace = TRUE;
}
$this->id = $id;
}

public function renderPictures() {
$this->template->pictures = $this->pictures->findBy(array(), ['created' => 'DESC']);
$vp = new Cntrl\VisualPaginator($this, 'paginator');
$paginator = $vp->getPaginator();
$paginator->itemsPerPage = 25;
$paginator->itemCount = $this->pictures->countBy();
$this->template->pictures = $this->pictures->findBy([], ['created' => 'DESC'], $paginator->itemsPerPage, $paginator->offset);
}

public function renderPrehled() {
$this->template->posts = $this->posts->findBy(array(), array('date' => 'DESC'));
$vp = new Cntrl\VisualPaginator($this, 'paginator');
$paginator = $vp->getPaginator();
$paginator->itemsPerPage = 25;
$paginator->itemCount = ITEMCOUNT;
$this->template->posts = $this->posts->findBy([], ['date' => 'DESC'], $paginator->itemsPerPage, $paginator->offset);
}

public function renderPages() {
$vp = new Cntrl\VisualPaginator($this, 'paginator');
$paginator = $vp->getPaginator();
$paginator->itemsPerPage = 25;
$paginator->itemCount = $this->pages->countBy();
$this->template->pages = $this->pages->findBy([], ['date' => 'DESC'], $paginator->itemsPerPage, $paginator->offset);
}

public function renderTags() {
$this->template->tags = $this->tags->findBy(array());
$vp = new Cntrl\VisualPaginator($this, 'paginator');
$paginator = $vp->getPaginator();
$paginator->itemsPerPage = 25;
$paginator->itemCount = $this->tags->countBy();
$this->template->tags = $this->tags->findBy([], [], $paginator->itemsPerPage, $paginator->offset);
}

public function renderUsers() {
$this->template->users = $this->users->findBy(array());
$vp = new Cntrl\VisualPaginator($this, 'paginator');
$paginator = $vp->getPaginator();
$paginator->itemsPerPage = 25;
$paginator->itemCount = $this->users->countBy();
$this->template->users = $this->users->findBy([], [], $paginator->itemsPerPage, $paginator->offset);
}

public function actionUserEdit($id = NULL) {
Expand All @@ -94,6 +138,22 @@ protected function createComponentUserEditForm() {
return $control;
}

protected function createComponentSettingsForm() {
$control = $this->settingsFormFactory->create();
$control->onSave[] = function () {
$this->redirect('setting');
};
return $control;
}

protected function createComponentPageForm() {
$control = $this->pageFormFactory->create($this->id);
$control->onSave[] = function () {
$this->redirect('default');
};
return $control;
}

protected function createComponentPostForm() {
$control = $this->postFormFactory->create($this->id);
$control->onSave[] = function () {
Expand All @@ -105,7 +165,7 @@ protected function createComponentPostForm() {
protected function createComponentColor() {
$form = new Nette\Application\UI\Form;
$form->addProtection();
foreach ($this->tags->findBy(array()) as $tag) {
foreach ($this->tags->findBy([]) as $tag) {
$form->addText('color' . $tag->id)
->setType('color')
->setValue('#' . $tag->color);
Expand All @@ -127,7 +187,7 @@ public function colorSucceeded($button, $id) {
$newColor = preg_replace('<#>', '', $vals['color' . $id]);
if (ctype_xdigit($newColor) && (strlen($newColor) == 6 || strlen($newColor) == 3)) {
try {
$tag = $this->tags->findOneBy(array('id' => $id));
$tag = $this->tags->findOneBy(['id' => $id]);
$tag->color = $newColor;
$this->tags->save($tag);
$this->flashMessage('Tag byl úspěšně aktualizován.', 'success');
Expand All @@ -142,7 +202,6 @@ public function colorSucceeded($button, $id) {

public function handleUpdate($title, $content, $tags, $slug) {
$texy = $this->prepareTexy();
$texy->imageModule->root = '../../uploads/';

//podle slugu to není dobrý nápad (budou se množit) - musí se to udělat nějak chytřeji
/*$article = $this->posts->findOneBy(['slug' => $slug]);
Expand All @@ -157,7 +216,7 @@ public function handleUpdate($title, $content, $tags, $slug) {

$this->template->preview = Nette\Utils\Html::el()->setHtml($texy->process($content));
$this->template->title = $title;
$this->template->tagsPrev = array_unique(explode(', ', $tags));
$this->template->tagsPrev = array_unique(preg_split('/\s*,\s*/', $tags));
if ($this->isAjax()) {
$this->redrawControl('preview');
} else {
Expand All @@ -168,18 +227,29 @@ public function handleUpdate($title, $content, $tags, $slug) {
public function handleDelete($id) {
$this->onBeforeRestrictedFunctionality($this);
try {
$this->posts->delete($this->posts->findOneBy(array('id' => $id)));
$this->posts->delete($this->posts->findOneBy(['id' => $id]));
$this->flashMessage('Článek byl úspěšně smazán.', 'success');
} catch (\Exception $exc) {
$this->flashMessage($exc->getMessage(), 'danger');
}
$this->redirect('this');
}

public function handleDeletePage($id) {
$this->onBeforeRestrictedFunctionality($this);
try {
$this->pages->delete($this->pages->findOneBy(['id' => $id]));
$this->flashMessage('Stránka byla úspěšně smazána.', 'success');
} catch (\Exception $exc) {
$this->flashMessage($exc->getMessage(), 'danger');
}
$this->redirect('this');
}

public function handleDeleteTag($tag_id) {
$this->onBeforeRestrictedFunctionality($this);
try {
$this->tags->delete($this->tags->findOneBy(array('id' => $tag_id)));
$this->tags->delete($this->tags->findOneBy(['id' => $tag_id]));
$this->flashMessage('Tag byl úspěšně smazán.', 'success');
} catch (\Exception $exc) {
$this->flashMessage($exc->getMessage(), 'danger');
Expand All @@ -201,7 +271,7 @@ public function handleDeleteUser($user_id) {
public function handleRegenerate($tag_id) {
$this->onBeforeRestrictedFunctionality($this);
try {
$tag = $this->tags->findOneBy(array('id' => $tag_id));
$tag = $this->tags->findOneBy(['id' => $tag_id]);
$tag->color = substr(md5(rand()), 0, 6); //Short and sweet
$this->tags->save($tag);
$this->flashMessage('Tag byl úspěšně regenerován.', 'success');
Expand All @@ -214,11 +284,11 @@ public function handleRegenerate($tag_id) {
public function handleUploadReciever() {
//ob_start();
$uploader = new \UploadHandler();
$uploader->allowedExtensions = array("jpeg", "jpg", "png", "gif");
$uploader->allowedExtensions = ["jpeg", "jpg", "png", "gif"];
$uploader->chunksFolder = __DIR__ . '/../../www/chunks';
$name = Nette\Utils\Strings::webalize($uploader->getName(), '.');
//TODO: picture optimalization (?)
$result = $uploader->handleUpload(__DIR__ . '/../../www/uploads', $name);
$result = $uploader->handleUpload(__DIR__ . '/../../../www/uploads', $name);
try {
$picture = $this->pictures->findOneBy(['uuid' => $uploader->getUuid()]);
if (!$picture) { //FIXME: toto není optimální (zejména kvůli rychlosti)
Expand All @@ -230,9 +300,9 @@ public function handleUploadReciever() {
$this->pictures->save($picture);
} catch (\Exception $exc) {
$uploader->handleDelete(__DIR__ . '/../../www/uploads');
$this->sendResponse(new Nette\Application\Responses\JsonResponse(array(
$this->sendResponse(new Nette\Application\Responses\JsonResponse([
'error' => $exc->getMessage(),
)));
]));
}
//TODO: napřed předat do šablony nová data
$this->redrawControl('pictures');
Expand Down
13 changes: 13 additions & 0 deletions app/AdminModule/presenters/BasePresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\AdminModule;

use App;

/**
* Class BasePresenter
* @package App\AdminModule
*/
abstract class BasePresenter extends App\BasePresenter {

}
Loading

0 comments on commit 007359a

Please sign in to comment.