Exemplo n.º 1
0
	public function actionDefault($exception)
	{
		$application = Environment::getApplication();
		$application->catchExceptions = FALSE;
		if ($this->isAjax()) {
			$this->payload->error = (string)$exception;
			$this->sendPayload();

		} else {
			$this->template->robots = 'noindex,noarchive';
			if ($exception instanceof /*Nette\Application\*/BadRequestException) {

				Environment::getHttpResponse()->setCode($exception->getCode());
				switch($exception->getCode()) {
				case 403:
					$this->template->title = _('403 Permission denied');
					break;
				default:
					Environment::getHttpResponse()->setCode(404);
					$this->template->title = _('404 Not Found');
					break;
				}

			} else {
				Environment::getHttpResponse()->setCode(500);
				$this->template->title = _("Don't recognize error");

				Debug::processException($exception);
			}
		}
	}
Exemplo n.º 2
0
 /**
  * Sends response to output.
  * @return void
  */
 public function send()
 {
     /*Nette\*/
     Environment::getHttpResponse()->setContentType($this->contentType);
     /*Nette\*/
     Environment::getHttpResponse()->expire(FALSE);
     echo json_encode($this->payload);
 }
Exemplo n.º 3
0
 /**
  * Sends response to output.
  * @return void
  */
 public function send()
 {
     /*Nette\*/
     Environment::getHttpResponse()->setContentType($this->contentType);
     /*Nette\*/
     Environment::getHttpResponse()->setHeader('Content-Disposition', 'attachment; filename="' . $this->name . '"');
     readfile($this->file);
 }
Exemplo n.º 4
0
 public function actionDefault($path = '', $page_number = 0, $letter = NULL)
 {
     // get nice name
     $path = explode('/', rtrim($path, '/'));
     $last = array_pop($path);
     $rest = implode('/', $path);
     // what's with rest?
     if (!empty($rest)) {
         $this->redirect(301, 'this', $last);
         $this->terminate();
         return;
     }
     // default page?
     if (empty($last)) {
         $this->setView('default');
         $this->template->path = '';
         $this->template->page = NULL;
         return;
     }
     $this->template->path = $last;
     // try to find it in database
     $page = mapper::pages()->findByNiceName($last);
     $this->template->page = $page;
     if ($page === NULL) {
         $this->setView('notfound');
         Environment::getHttpResponse()->setCode(404);
     } else {
         if ($page->getRef() === NULL) {
             $this->setView('page');
         } else {
             $this->setView(get_class($page->getRef()));
             $this->template->{get_class($page->getRef())} = $page->getRef();
             $this->template->letter = $letter;
             $this->template->have_letter = TRUE;
         }
         $this->template->title = $page->getName();
     }
     $this->template->page_number = $page_number;
 }
Exemplo n.º 5
0
 /**
  * @return void
  */
 public function renderDefault($exception)
 {
     if ($this->isAjax()) {
         $this->getPayload()->events[] = array('error', $exception->getMessage());
         $this->terminate();
     } else {
         $this->template->robots = 'noindex,noarchive';
         $httpResponse = Environment::getHttpResponse();
         if ($exception instanceof BadRequestException) {
             if (!$httpResponse->isSent()) {
                 $httpResponse->setCode($exception->getCode());
             }
             $this->template->title = '404 Not Found';
             $this->setView('404');
         } else {
             if (!$httpResponse->isSent()) {
                 $httpResponse->setCode(500);
             }
             $this->template->title = '500 Internal Server Error';
             $this->setView('500');
             Debug::processException($exception);
         }
     }
 }
Exemplo n.º 6
0
 /**
  * @return IHttpResponse
  */
 protected function getHttpResponse()
 {
     return Environment::getHttpResponse();
 }
Exemplo n.º 7
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.º 8
0
 /**
  * @return IHttpResponse
  */
 public function getResponse()
 {
     return Environment::getHttpResponse();
 }
Exemplo n.º 9
0
 /**
  * Sends response to output.
  * @return void
  */
 public function send()
 {
     Environment::getHttpResponse()->redirect($this->uri, $this->code);
 }
Exemplo n.º 10
0
<h1>Nette\Environment services test</h1>

<pre>
<?php 
require_once '../../Nette/loader.php';
/*use Nette\Debug;*/
/*use Nette\Environment;*/
echo "Environment::getHttpResponse\n";
$obj = Environment::getHttpResponse();
Debug::dump($obj->class);
echo "Environment::getApplication\n";
$obj = Environment::getApplication();
Debug::dump($obj->class);
echo "Environment::getCache(...)\n";
Environment::setVariable('tempDir', __FILE__);
$obj = Environment::getCache('my');
Debug::dump($obj->class);
/* in PHP 5.3
echo "Environment::getXyz(...)\n";
Environment::setServiceAlias('Nette\Web\IUser', 'xyz');
$obj = Environment::getXyz();
Debug::dump($obj->class);
*/
Exemplo n.º 11
0
 /**
  * set itemsPerPage cookie for current PresenterComponent
  *
  * @param PresenterComponent
  * @param int
  */
 public static function setItemsPerPageCookie($_this, $itemsPerPage)
 {
     Environment::getHttpResponse()->setCookie(self::getCookieItemsPerPageKey($_this), $itemsPerPage, Tools::YEAR);
 }
Exemplo n.º 12
0
 /**
  * Sends response to output.
  * @return void
  */
 public function send()
 {
     Environment::getHttpResponse()->setContentType($this->contentType);
     Environment::getHttpResponse()->setExpiration(FALSE);
     echo json_encode($this->payload);
 }
Exemplo n.º 13
0
 public function renderBegin()
 {
     $response = Environment::getHttpResponse();
     if ($this->docType == self::XHTML_1_STRICT && $this->contentType == self::APPLICATION_XHTML && ($this->forceContentType || $this->isClientXhtmlCompatible())) {
         $contentType = self::APPLICATION_XHTML;
         $response->setHeader('Vary', 'Accept');
         echo "<?xml version='1.0' encoding='utf-8'?>\n";
     } else {
         $contentType = self::TEXT_HTML;
         Environment::getHttpResponse()->setContentType($contentType, 'utf-8');
     }
     $response->setContentType($contentType, 'utf-8');
     echo $this->getDocTypeString() . "\n";
     echo '<html' . ($this->xml ? ' xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $this->language . '" lang="' . $this->language . '"' : '') . ">\n";
     echo "<head>\n";
     $metaLanguage = Html::el('meta')->content($this->language);
     $metaLanguage->attrs['http-equiv'] = 'Content-Language';
     echo $metaLanguage . "\n";
     $metaContentType = Html::el('meta')->content($contentType);
     $metaContentType->attrs['http-equiv'] = 'Content-Type';
     echo $metaContentType . "\n";
     echo Html::el('title', $this->getTitleString()) . "\n";
     if ($this->favicon != '') {
         echo Html::el('link')->rel('shortcut icon')->href(Environment::getVariable('baseUri') . $this->favicon) . "\n";
     }
     foreach ($this->metaTags as $name => $content) {
         echo Html::el('meta')->name($name)->content($content) . "\n";
     }
 }