Exemplo n.º 1
0
 /**
  * Dispatch an HTTP request to a routing debugger. Please don't call directly.
  */
 public static function run()
 {
     if (!self::$enabled || Environment::getMode('production')) {
         return;
     }
     self::$enabled = FALSE;
     $debugger = new self(Environment::getApplication()->getRouter(), Environment::getHttpRequest());
     $debugger->paint();
 }
Exemplo n.º 2
0
 public function renderDefault()
 {
     $this->template->form = $this->getComponent('loginForm');
     $referer = Environment::getHttpRequest()->getReferer();
     if ($referer) {
         if ($referer->path === $this->link('Settings:changeLogin')) {
             $this->template->msg = __('Now login with new username and password.');
         }
     }
 }
Exemplo n.º 3
0
 public static function isActive($item_url)
 {
     $url = Environment::getHttpRequest()->getUri()->getAbsoluteUri();
     $url_arr = parse_url($url);
     $item_url_arr = parse_url($item_url);
     $url_without_params = $url_arr['host'] . $url_arr['path'];
     if (isset($item_url_arr['path'])) {
         $item_url_without_params = $item_url_arr['host'] . $item_url_arr['path'];
     } else {
         $item_url_without_params = $item_url_arr['host'];
     }
     return $url_without_params == $item_url_without_params;
 }
Exemplo n.º 4
0
 /**
  * Handles an incomuing request and saves the data if necessary.
  */
 public function processRequest()
 {
     $request = Environment::getHttpRequest();
     if ($request->isPost() && $request->isAjax() && $request->getHeader('X-Callback-Client')) {
         $data = json_decode(file_get_contents('php://input'), TRUE);
         if (count($data) > 0) {
             foreach ($data as $key => $value) {
                 if (isset($this->items[$key]) && isset($this->items[$key]['callback']) && $value === TRUE) {
                     callback($this->items[$key]['callback'])->invokeArgs($this->items[$key]['args']);
                 }
             }
         }
         exit;
     }
 }
Exemplo n.º 5
0
 /**
  * Handles an incomuing request and saves the data if necessary.
  */
 public function processRequest()
 {
     $request = Environment::getHttpRequest();
     if ($request->isPost() && $request->isAjax() && $request->getHeader('X-FTP-Permission-Client')) {
         foreach ($this->items as $mode => $items) {
             foreach ($items as $item) {
                 $path = ROOT_DIR . $item;
                 if (!file_exists($path)) {
                     throw new FileNotFoundException('File or Directory "' . $path . '" does NOT exist!');
                 }
                 //					dump($item);
                 //					dump($mode);
                 chmod($path, $mode);
             }
         }
         echo 'chmod set';
         exit;
     }
 }
Exemplo n.º 6
0
 /**
  * Removes item from cart
  */
 public function actionDelete()
 {
     // check request
     $request = Environment::getHttpRequest();
     if (!$request->isMethod('POST')) {
         $this->redirectUri(Environment::getHttpRequest()->getReferer()->getAbsoluteUri());
         $this->terminate();
         return;
     }
     // find product
     $product_id = $request->getPost('product_id', 0);
     $amount = intval($request->getPost('amount', 1));
     $cart = Environment::getSession(SESSION_ORDER_NS);
     $product = mapper::products()->findById($product_id);
     if ($product === NULL) {
         $this->redirectUri($request->getReferer()->getAbsoluteUri());
         $this->terminate();
         return;
     }
     // delete product
     if (!isset($cart->products)) {
         $cart->products = array();
     }
     if (isset($cart->products[$product->getId()])) {
         $cart->products[$product->getId()] -= $amount;
         if ($cart->products[$product->getId()] < 1) {
             unset($cart->products[$product->getId()]);
         }
     }
     // calculate total
     $cart->total = 0;
     mapper::products()->findByIds(array_keys($cart->products));
     foreach ($cart->products as $id => $amount) {
         $cart->total += intval(mapper::products()->findById($id)->getPrice()) * $amount;
     }
     // redirect
     //$this->redirectUri($request->getReferer()->getAbsoluteUri());
     $this->redirect('showCart');
     $this->terminate();
     return;
 }
Exemplo n.º 7
0
 /**
  * Add navigation node as a child
  * @staticvar int $counter
  * @param string $label
  * @param string $url
  * @param string $netteLink added - aby sa dalo testovat ifCurrent na cely presenter
  * @return NavigationNode
  */
 public function add($label, $url, $netteLink = null)
 {
     $navigationNode = new self();
     $navigationNode->label = $label;
     $navigationNode->url = $url;
     static $counter;
     $this->addComponent($navigationNode, ++$counter);
     /*added*/
     $uri = Environment::getHttpRequest()->getOriginalUri()->getPath();
     if ($netteLink) {
         $presenter = Environment::getApplication()->getPresenter();
         try {
             $presenter->link($netteLink);
         } catch (InvalidLinkException $e) {
         }
         $navigationNode->isCurrent = $presenter->getLastCreatedRequestFlag("current");
     } else {
         $navigationNode->isCurrent = $url == $uri;
     }
     /*added end*/
     return $navigationNode;
 }
Exemplo n.º 8
0
 public function actionFulltext()
 {
     // get dirty
     $this->template->num_docs = fulltext::index()->numDocs();
     $this->template->dirty = fulltext::dirty();
     $this->template->num_dirty = count($this->template->dirty);
     // index
     $index = fulltext::index();
     $this->template->update_now = array_slice($this->template->dirty, 0, 50);
     if (!empty($this->template->update_now)) {
         adminlog::log(__('Attempt to update fulltext'));
     }
     foreach (mapper::products()->findByIds($this->template->update_now) as $product) {
         // delete old
         foreach ($index->termDocs(new Zend_Search_Lucene_Index_Term($product->getId(), 'id')) as $id) {
             $index->delete($id);
         }
         // add
         $doc = new Zend_Search_Lucene_Document();
         $doc->addField(Zend_Search_Lucene_Field::Keyword('id', $product->getId()));
         $doc->addField(Zend_Search_Lucene_Field::UnStored('name', $product->getName()));
         $doc->addField(Zend_Search_Lucene_Field::UnStored('nice_name', $product->getNiceName()));
         $doc->addField(Zend_Search_Lucene_Field::Unstored('code', $product->getCode()));
         $doc->addField(Zend_Search_Lucene_Field::UnStored('meta_keywords', $product->getMetaKeywords()));
         $doc->addField(Zend_Search_Lucene_Field::UnStored('meta_description', $product->getMetaDescription()));
         $description = '';
         if (strlen($product->getDescription()) < 1) {
             if (strlen($product->getMetaDescription()) < 1) {
                 $description = $product->getName();
             } else {
                 $description = $product->getMetaDescription();
             }
         } else {
             $description = $product->getDescription();
         }
         if ($manufacturer = mapper::products()->findManufacturerOf($product->getId())) {
             $doc->addField(Zend_Search_Lucene_Field::UnStored('manufacturer', $manufacturer->getName()));
             $description .= ' ' . $manufacturer->getName();
             $description .= ' ' . $manufacturer->getDescription();
         }
         if ($category = mapper::products()->findCategoryOf($product->getId())) {
             $doc->addField(Zend_Search_Lucene_Field::UnStored('category', $category->getName()));
             $description .= ' ' . $category->getName();
             $description .= ' ' . $category->getDescription();
         }
         $description .= ' ' . $product->getName();
         $doc->addField(Zend_Search_Lucene_Field::UnStored('description', $description));
         $index->addDocument($doc);
     }
     // undirty updated
     foreach ($this->template->update_now as $id) {
         fulltext::dirty($id, FALSE);
     }
     // log
     adminlog::log(__('Successfully updated %d fulltext items, %d remains'), count($this->template->update_now), $this->template->num_dirty - count($this->template->update_now));
     // refresh
     $s = 5;
     Environment::getHttpResponse()->setHeader('Refresh', $s . '; ' . (string) Environment::getHttpRequest()->getOriginalUri());
     $this->template->next_update = $s;
 }
Exemplo n.º 9
0
 /**
  * @return IHttpRequest
  */
 public function getRequest()
 {
     return Environment::getHttpRequest();
 }
 /**
  * Upload souboru
  */
 public function actionUpload()
 {
     // check user rights
     //		if (!Environment::getUser()->isAllowed("files", "upload")) {
     //			$this->sendError("Access denied.");
     //		}
     // path
     $folder = Environment::getHttpRequest()->getPost("folder");
     try {
         $folderPath = $this->getFolderPath($folder);
     } catch (InvalidArgumentException $e) {
         $this->sendError("Folder does not exist or is not writeable.");
     }
     // file
     $file = Environment::getHttpRequest()->getFile("file");
     // check
     if ($file === null || !$file->isOk()) {
         $this->sendError("Upload error.");
     }
     // move
     $fileName = String::webalize($file->getName(), ".");
     $path = $folderPath . "/" . $fileName;
     if (@$file->move($path)) {
         @chmod($path, 0666);
         if ($file->isImage()) {
             $this->payload->filename = ($folder ? "{$folder}/" : "") . $fileName;
             $this->payload->type = "image";
         } else {
             $this->payload->filename = $this->baseFolderUri . ($folder ? "{$folder}/" : "") . $fileName;
             $this->payload->type = "file";
         }
         $this->terminate(new JsonResponse($this->payload, "text/plain"));
     } else {
         $this->sendError("Move failed.");
     }
 }
Exemplo n.º 11
0
 /**
  * @return IHttpRequest
  */
 protected function getHttpRequest()
 {
     return class_exists('Environment') ? Environment::getHttpRequest() : new HttpRequest();
 }
Exemplo n.º 12
0
        $uri = $this->mycontrol->link('this?x=1&round=1#frag');
        echo "3.12 {$uri}\n\n";
        $uri = $this->mycontrol->link('//this?x=1&round=1#frag');
        echo "3.13 {$uri}\n\n";
    }
    /**
     * @view: default
     */
    public function handleBuy($x = 1, $y = 1)
    {
    }
}
class OtherPresenter extends TestPresenter
{
}
class Submodule_OtherPresenter extends TestPresenter
{
}
Environment::setVariable('appDir', dirname(__FILE__));
$httpRequest = Environment::getHttpRequest();
$uri = clone $httpRequest->getUri();
$uri->scriptPath = '/index.php';
$uri->host = 'localhost';
$httpRequest->setUri($uri);
$application = Environment::getApplication();
$application->setRouter(new SimpleRouter());
$request = new PresenterRequest('Test', HttpRequest::GET, array());
TestPresenter::$invalidLinkMode = TestPresenter::INVALID_LINK_WARNING;
$presenter = new TestPresenter($request);
$presenter->autoCanonicalize = FALSE;
$presenter->run();
 /**
  * Handles an incomuing request and saves the data if necessary.
  */
 public function processRequest()
 {
     // Try starting the session
     try {
         $session = Environment::getSession('Nette.Addons.TranslationPanel');
     } catch (InvalidStateException $e) {
         $session = FALSE;
     }
     $request = Environment::getHttpRequest();
     if ($request->isPost() && $request->isAjax() && $request->getHeader('X-Translation-Client')) {
         $data = json_decode(file_get_contents('php://input'));
         if ($data) {
             if ($session) {
                 $stack = isset($session['stack']) ? $session['stack'] : array();
             }
             foreach ($data as $string => $value) {
                 $this->translator->setTranslation($string, $value);
                 if ($session && isset($stack[$string])) {
                     unset($stack[$string]);
                 }
             }
             $this->translator->save();
             if ($session) {
                 $session['stack'] = $stack;
             }
         }
     }
 }
Exemplo n.º 14
0
		'error' => array(
			'avatar' => 0,
		),

		'size' => array(
			'avatar' => 3013,
		),
	),
);
*/
// invalid #1
$_POST = array('name' => array(NULL), 'note' => array(NULL), 'gender' => array(NULL), 'send' => array(NULL), 'country' => array(NULL), 'countrym' => '', 'password' => array(NULL), 'firstperson' => TRUE, 'secondperson' => array('age' => array(NULL)), 'submit1' => array(NULL), 'userid' => array(NULL));
$_FILES = array('avatar' => array('name' => 'readme.txt', 'type' => 'text/plain'), 'secondperson' => array('name' => array(NULL), 'type' => array(NULL), 'tmp_name' => array(NULL), 'error' => array(NULL), 'size' => array(NULL)));
echo "<h2>Invalid data #1</h2>\n";
echo "Submitted?\n";
$dolly = clone $form;
Environment::getHttpRequest()->initialize();
Debug::dump(gettype($dolly->isSubmitted()));
echo "Values:\n";
Debug::dump($dolly->getValues());
// invalid #2
$_POST = array('name' => "invalidªªªutf", 'note' => "invalidªªªutf", 'userid' => "invalidªªªutf", 'secondperson' => array(NULL));
$tmp = array('name' => 'readme.txt', 'type' => 'text/plain', 'tmp_name' => 'C:\\PHP\\temp\\php1D5B.tmp', 'error' => 0, 'size' => 209);
$_FILES = array('name' => $tmp, 'note' => $tmp, 'gender' => $tmp, 'send' => $tmp, 'country' => $tmp, 'countrym' => $tmp, 'password' => $tmp, 'firstperson' => $tmp, 'secondperson' => array('age' => $tmp), 'submit1' => $tmp, 'userid' => $tmp);
echo "<h2>Invalid data #2</h2>\n";
echo "Submitted?\n";
$dolly = clone $form;
Environment::getHttpRequest()->initialize();
Debug::dump(gettype($dolly->isSubmitted()));
echo "Values:\n";
Debug::dump($dolly->getValues());
Exemplo n.º 15
0
 /**
  * get itemsPerPage cookie for current PresenterComponent
  *
  * @param PresenterComponent
  * @return int
  */
 public static function getItemsPerPageCookie($_this)
 {
     return Environment::getHttpRequest()->getCookie(self::getCookieItemsPerPageKey($_this));
 }
Exemplo n.º 16
0
$loader->register();
/** 2e) load extension methods */
if (is_file(APP_DIR . '/extensions.php')) {
    include_once APP_DIR . '/extensions.php';
}
/** 2f) enable DebugBar */
if ($mode == Debug::DEVELOPMENT) {
    Debug::$showBar = TRUE;
}
/** 2g) Session setup [optional] */
if (Environment::getVariable('sessionDir') !== NULL && !is_writable(Environment::getVariable('sessionDir'))) {
    die("Make directory '" . realpath(Environment::getVariable('sessionDir')) . "' writable!");
}
$session = Environment::getSession();
$session->setSavePath(Environment::getVariable('sessionDir'));
// Step 3: Configure application
/** 3a) Setup Application, ErrorPresenter & exceptions catching */
$application = Environment::getApplication();
Presenter::$invalidLinkMode = Environment::isProduction() ? Presenter::INVALID_LINK_SILENT : Presenter::INVALID_LINK_EXCEPTION;
Environment::setVariable('host', Environment::getHttpRequest()->getUri()->host);
/** 3b) establish database connection and initialize services */
$application->onStartup[] = 'Services::initialize';
$application->onStartup[] = 'BaseModel::initialize';
$application->onShutdown[] = 'BaseModel::disconnect';
// Step 4: Setup application router
$router = $application->getRouter();
$router[] = new Route('index.php', array('presenter' => 'Example', 'action' => 'default'), Route::ONE_WAY);
$router[] = new Route('<presenter>/<action>/', array('presenter' => 'Example', 'action' => 'default'));
$router[] = new SimpleRouter('Example:default');
// Step 5: Run the application!
$application->run();
Exemplo n.º 17
0
 private function isClientXhtmlCompatible()
 {
     $req = Environment::getHttpRequest();
     return stristr($req->getHeader('Accept'), 'application/xhtml+xml') || $req->getHeader('Accept') == '*/*';
 }
Exemplo n.º 18
0
Environment::setVariable('tempDir', Environment::expand('%baseDir%/tmp'));
Environment::setVariable('themeBaseUri', Environment::expand('%baseUri%/themes/%theme%'));
Environment::setVariable('mediaDir', Environment::expand('%baseDir%/media'));
Environment::setVariable('mediaBaseUri', Environment::expand('%baseUri%/media'));
set_include_path(LIB_DIR . PATH_SEPARATOR . get_include_path());
Html::$xhtml = FALSE;
SafeStream::register();
setlocale(LC_ALL, require Environment::expand('%localeFile%'));
Zend_Search_Lucene::setDefaultSearchField('description');
// configure locale
require_once LIB_DIR . '/tr.php';
$available = array();
foreach (glob(APP_DIR . '/locale/' . '*.php') as $_) {
    $available[substr(substr($_, strlen(APP_DIR . '/locale/')), 0, 2)] = $_;
}
tr::$locale = Environment::getHttpRequest()->detectLanguage(array_keys($available));
if (tr::$locale) {
    list(tr::$plurals[tr::$locale], tr::$table[tr::$locale]) = (require $available[tr::$locale]);
}
// connect to DB
dibi::connect(require Environment::expand('%dbFile%'));
// get app
$app = Environment::getApplication();
// routing
$router = $app->getRouter();
Route::setStyleProperty('action', Route::FILTER_TABLE, array(__('show-cart') => 'showCart', __('fill-data') => 'fillData', __('complete') => 'complete', __('commit') => 'commit'));
$router[] = new Route(__('order') . '/<action>/', array('presenter' => 'Front:Order'));
$router[] = new Route('admin/<presenter>/<action>/', array('module' => 'Back', 'presenter' => 'Dashboard', 'action' => 'default'));
$router[] = new Route(__('search') . ' ? q=<q .*> & ' . __('page') . '=<page \\d+>', array('presenter' => 'Front:Search', 'action' => 'default', 'page' => 1));
Route::addStyle('path', NULL);
Route::setStyleProperty('path', Route::PATTERN, '.*');
Exemplo n.º 19
0
 /**
  * @return IHttpRequest
  */
 protected function getHttpRequest()
 {
     return Environment::getHttpRequest();
 }
Exemplo n.º 20
0
 public function previewLink($zoom = null)
 {
     return Environment::getHttpRequest()->getUrl()->getBasePath() . "static/images/missing-image.png";
 }