Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Cleanup defines.
Browse files Browse the repository at this point in the history
- Remove JPATH_ROOT.
- Add APPLICATION_NAME
- Add APPLICATION_ROOT
- Add APPLICATION_BASE
  • Loading branch information
johanjanssens committed Aug 18, 2014
1 parent 07197e2 commit 967a242
Show file tree
Hide file tree
Showing 24 changed files with 108 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function _initialize(Library\ObjectConfig $config)
*/
protected function _actionRun(Library\DispatcherContextInterface $context)
{
define('JPATH_FILES', JPATH_SITES . '/' . $this->getSite() . '/files');
define('JPATH_FILES', APPLICATION_ROOT.'/sites/'. $this->getSite() . '/files');

// Set timezone to user's setting, falling back to global configuration.
$timezone = new \DateTimeZone($context->user->get('timezone', $this->getConfig()->timezone));
Expand Down
18 changes: 12 additions & 6 deletions application/admin/public/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@
//Don't run in STRICT mode (Joomla is not E_STRICT compat)
error_reporting(error_reporting() | ~ E_STRICT);

define( 'DS', DIRECTORY_SEPARATOR );

define('APPLICATION_NAME' , 'admin');
define('APPLICATION_ROOT' , realpath($_SERVER['DOCUMENT_ROOT']));
define('APPLICATION_BASE' , APPLICATION_ROOT.'/application/admin');

// Bootstrap the framework
$config = require JPATH_ROOT . '/config/bootstrapper.php';
$config = require APPLICATION_ROOT.'/config/bootstrapper.php';

require_once(JPATH_ROOT . '/library/nooku.php');
require_once(APPLICATION_ROOT.'/library/nooku.php');
$nooku = Nooku::getInstance(array(
'debug' => isset($config['debug']) ? (bool) $config['debug'] : false,
'cache_namespace' => 'admin',
'cache_enabled' => isset($config['caching']) ? (bool) $config['debug'] : false,
'base_path' => JPATH_ROOT.'/application/admin'
'debug' => $config['debug'],
'cache' => $config['cache'],
'cache_namespace' => $config['cache_namespace'],
'base_path' => APPLICATION_BASE
));

//Bootstrap the application
Expand Down
6 changes: 0 additions & 6 deletions application/admin/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,5 @@
* @link https://github.com/nooku/nooku-platform for the canonical source repository
*/

define('JPATH_ROOT' , realpath($_SERVER['DOCUMENT_ROOT']));
define('JPATH_SITES', JPATH_ROOT.'/sites');

define( 'DS', DIRECTORY_SEPARATOR );

require_once(__DIR__.'/bootstrap.php' );

Nooku\Library\ObjectManager::getInstance()->getObject('application')->run();
2 changes: 1 addition & 1 deletion application/site/component/application/dispatcher/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function _initialize(Library\ObjectConfig $config)
*/
protected function _actionRun(Library\DispatcherContextInterface $context)
{
define('JPATH_FILES' , JPATH_SITES.'/'.$this->getSite().'/files');
define('JPATH_FILES', APPLICATION_ROOT.'/sites/'. $this->getSite() . '/files');

// Set timezone to user's setting, falling back to global configuration.
$timezone = new \DateTimeZone($context->user->get('timezone', $this->getConfig()->timezone));
Expand Down
2 changes: 1 addition & 1 deletion application/site/component/articles/view/articles/rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getCategory()
$size = getimagesize($path);

$category->image = (object) array(
'path' => '/'.str_replace(JPATH_ROOT.DS, '', $path),
'path' => '/'.str_replace(APPLICATION_ROOT.DS, '', $path),
'width' => $size[0],
'height' => $size[1]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

<? if($category->image) : ?>
<image>
<url><?= object('request')->getUrl()->setPath(str_replace(JPATH_ROOT.DS, '', $category->image->path))->toString(Library\HttpUrl::BASE) ?></url>
<url><?= object('request')->getUrl()->setPath(str_replace(APPLICATION_ROOT.DS, '', $category->image->path))->toString(Library\HttpUrl::BASE) ?></url>
<title><?= escape($category->title) ?></title>
<link><?= route() ?></link>
<width><?= $category->image->width ?></width>
Expand Down
20 changes: 13 additions & 7 deletions application/site/public/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@
//Don't run in STRICT mode (Joomla is not E_STRICT compat)
error_reporting(error_reporting() | ~ E_STRICT);

define( 'DS', DIRECTORY_SEPARATOR );

define('APPLICATION_NAME' , 'site');
define('APPLICATION_ROOT' , realpath($_SERVER['DOCUMENT_ROOT']));
define('APPLICATION_BASE' , APPLICATION_ROOT.'/application/site');

// Bootstrap the framework
$config = require JPATH_ROOT . '/config/bootstrapper.php';
$config = require APPLICATION_ROOT.'/config/bootstrapper.php';

require_once(JPATH_ROOT . '/library/nooku.php');
require_once(APPLICATION_ROOT.'/library/nooku.php');
$nooku = Nooku::getInstance(array(
'debug' => isset($config['debug']) ? (bool) $config['debug'] : false,
'cache_namespace' => 'admin',
'cache_enabled' => isset($config['caching']) ? (bool) $config['debug'] : false,
'base_path' => JPATH_ROOT.'/application/site'
'debug' => $config['debug'],
'cache' => $config['cache'],
'cache_namespace' => $config['cache_namespace'],
'base_path' => APPLICATION_BASE
));

//Bootstrap the application
Expand All @@ -37,7 +43,7 @@
->registerFile($nooku->getRootPath(). '/config/bootstrapper.php')
->bootstrap();

// Joomla : setup
// Bootstrap Joomla
require_once($nooku->getVendorPath() . '/joomla/import.php');
jimport('joomla.environment.uri');
jimport('joomla.html.html');
Expand Down
6 changes: 0 additions & 6 deletions application/site/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,5 @@
* @link https://github.com/nooku/nooku-platform for the canonical source repository
*/

define('JPATH_ROOT' , realpath($_SERVER['DOCUMENT_ROOT']));
define('JPATH_SITES', JPATH_ROOT.'/sites');

define( 'DS', DIRECTORY_SEPARATOR );

require_once(__DIR__.'/bootstrap.php' );

Nooku\Library\ObjectManager::getInstance()->getObject('application')->run();
2 changes: 1 addition & 1 deletion component/application/controller/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function _actionRender(Library\ControllerContextInterface $context)
foreach($traces as $key => $trace)
{
if(isset($trace['file'])) {
$traces[$key]['file'] = str_replace(JPATH_ROOT, '', $trace['file']);
$traces[$key]['file'] = str_replace(APPLICATION_ROOT, '', $trace['file']);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<td class="-koowa-sortable" align="right"><?= $i; ?></td>
<td class="-koowa-sortable"><?= translate('language') ?></td>
<td class="-koowa-sortable"><?= helper('com:files.filesize.humanize', array('size' => filesize($file))); ?></td>
<td class="-koowa-sortable"><?= str_replace(JPATH_ROOT, '', $file); ?></td>
<td class="-koowa-sortable"><?= str_replace(APPLICATION_ROOT, '', $file); ?></td>
</tr>
<? endforeach; ?>
<? $i++; ?>
Expand All @@ -36,7 +36,7 @@
<td class="-koowa-sortable" align="right" width="10"><?= $i; ?></td>
<td class="-koowa-sortable"><?= translate('PHP') ?></td>
<td class="-koowa-sortable"><?= helper('com:files.filesize.humanize', array('size' => filesize($file))); ?></td>
<td class="-koowa-sortable"><?= str_replace(JPATH_ROOT, '', $file); ?></td>
<td class="-koowa-sortable"><?= str_replace(APPLICATION_ROOT, '', $file); ?></td>
</tr>
<? $i++; ?>
<? endforeach; ?>
Expand Down
12 changes: 6 additions & 6 deletions component/files/tests/tests_movecopy.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
->toArray();

var_dump('Root file - move', $result,
!file_exists(JPATH_ROOT.'/images/random_test_file.txt') && file_exists(JPATH_ROOT.'/images/moved_test_file.txt'));
!file_exists(APPLICATION_ROOT.'/images/random_test_file.txt') && file_exists(APPLICATION_ROOT.'/images/moved_test_file.txt'));

/*
* Root file - copy
Expand All @@ -36,7 +36,7 @@
->toArray();

var_dump('Root file - copy', $result,
file_exists(JPATH_ROOT.'/images/moved_test_file.txt') && file_exists(JPATH_ROOT.'/images/copied_test_file.txt'));
file_exists(APPLICATION_ROOT.'/images/moved_test_file.txt') && file_exists(APPLICATION_ROOT.'/images/copied_test_file.txt'));

/*
* Nested file - move
Expand All @@ -48,7 +48,7 @@
->toArray();

var_dump('Nested file - move', $result,
!file_exists(JPATH_ROOT.'/images/moved_test_file.txt') && file_exists(JPATH_ROOT.'/images/random_test_folder/moved_test_file.txt'));
!file_exists(APPLICATION_ROOT.'/images/moved_test_file.txt') && file_exists(APPLICATION_ROOT.'/images/random_test_folder/moved_test_file.txt'));

/*
* Nested file - copy
Expand All @@ -60,7 +60,7 @@
->toArray();

var_dump('Nested file - copy', $result,
file_exists(JPATH_ROOT.'/images/copied_test_file.txt') && file_exists(JPATH_ROOT.'/images/random_test_folder/copied_test_file.txt'));
file_exists(APPLICATION_ROOT.'/images/copied_test_file.txt') && file_exists(APPLICATION_ROOT.'/images/random_test_folder/copied_test_file.txt'));

/*
* Nested file - copy with a new name
Expand All @@ -72,7 +72,7 @@
->toArray();

var_dump('Nested file - copy with a new name', $result,
file_exists(JPATH_ROOT.'/images/copied_test_file.txt') && file_exists(JPATH_ROOT.'/images/random_test_folder/copied_test_file2.txt'));
file_exists(APPLICATION_ROOT.'/images/copied_test_file.txt') && file_exists(APPLICATION_ROOT.'/images/random_test_folder/copied_test_file2.txt'));

/*
* Nested file - move with a new name
Expand All @@ -84,7 +84,7 @@
->toArray();

var_dump('Nested file - move with a new name', $result,
!file_exists(JPATH_ROOT.'/images/copied_test_file.txt') && file_exists(JPATH_ROOT.'/images/random_test_folder/moved_test_file2.txt'));
!file_exists(APPLICATION_ROOT.'/images/copied_test_file.txt') && file_exists(APPLICATION_ROOT.'/images/random_test_folder/moved_test_file2.txt'));

/*
* Delete test files
Expand Down
18 changes: 9 additions & 9 deletions component/files/tests/tests_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
->add(array('contents' => 'test'))
->toArray();

var_dump('Root file - add', $result, file_exists(JPATH_ROOT.'/images/ercan.txt'));
var_dump('Root file - add', $result, file_exists(APPLICATION_ROOT.'/images/ercan.txt'));

/*
* Root file - edit
Expand All @@ -20,7 +20,7 @@
->edit(array('contents' => 'after edit'))
->toArray();

var_dump('Root file - edit', $result, file_get_contents(JPATH_ROOT.'/images/ercan.txt') === 'after edit');
var_dump('Root file - edit', $result, file_get_contents(APPLICATION_ROOT.'/images/ercan.txt') === 'after edit');

/*
* Root file - delete
Expand All @@ -31,7 +31,7 @@
->delete()
->toArray();

var_dump('Root file - delete', $result, !file_exists(JPATH_ROOT.'/images/ercan.txt'));
var_dump('Root file - delete', $result, !file_exists(APPLICATION_ROOT.'/images/ercan.txt'));

/*
* Nested file - add
Expand All @@ -43,7 +43,7 @@
->add(array('contents' => 'test'))
->toArray();

var_dump('Nested file - add', $result, file_exists(JPATH_ROOT.'/images/banners/nested.txt'));
var_dump('Nested file - add', $result, file_exists(APPLICATION_ROOT.'/images/banners/nested.txt'));

/*
* Nested file - delete
Expand All @@ -55,7 +55,7 @@
->delete()
->toArray();

var_dump('Nested file - delete', $result, !file_exists(JPATH_ROOT.'/images/banners/nested.txt'));
var_dump('Nested file - delete', $result, !file_exists(APPLICATION_ROOT.'/images/banners/nested.txt'));

/*
* Root folder - add
Expand All @@ -66,7 +66,7 @@
->add()
->toArray();

var_dump('Root folder - add', $result, is_dir(JPATH_ROOT.'/images/ercan_test'));
var_dump('Root folder - add', $result, is_dir(APPLICATION_ROOT.'/images/ercan_test'));

/*
* Root folder - delete
Expand All @@ -77,7 +77,7 @@
->delete()
->toArray();

var_dump('Root folder - delete', $result, !file_exists(JPATH_ROOT.'/images/ercan_test'));
var_dump('Root folder - delete', $result, !file_exists(APPLICATION_ROOT.'/images/ercan_test'));

/*
* Nested folder - add
Expand All @@ -89,7 +89,7 @@
->add()
->toArray();

var_dump('Nested folder - add', $result, is_dir(JPATH_ROOT.'/images/banners/ercan_nested'));
var_dump('Nested folder - add', $result, is_dir(APPLICATION_ROOT.'/images/banners/ercan_nested'));

/*
* Nested folder - delete
Expand All @@ -101,4 +101,4 @@
->delete()
->toArray();

var_dump('Nested folder - delete', $result, !file_exists(JPATH_ROOT.'/images/banners/nested.txt'));
var_dump('Nested folder - delete', $result, !file_exists(APPLICATION_ROOT.'/images/banners/nested.txt'));
2 changes: 1 addition & 1 deletion component/sites/model/sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function _actionFetch(Library\ModelContext $context)
$sites = array();

//Get the sites
foreach (new \DirectoryIterator(JPATH_SITES) as $file)
foreach (new \DirectoryIterator(\Nooku::getInstance()->getRootPath().'/sites') as $file)
{
if ($file->isDir() && !(substr($file->getFilename(), 0, 1) == '.'))
{
Expand Down
2 changes: 1 addition & 1 deletion component/users/model/entity/password.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(Library\ObjectConfig $config)
$this->_length = (int) $config->length;

// TODO Remove when PHP 5.5 becomes a requirement.
require_once JPATH_ROOT.'/component/users/legacy/password.php';
require_once \Nooku::getInstance()->getRootPath().'/component/users/legacy/password.php';
}

/**
Expand Down
13 changes: 11 additions & 2 deletions config/bootstrapper.php-empty
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ return array(
'priority' => 1, //Library\ObjectBootstrapper::PRIORITY_HIGHEST,

// Global Settings
'caching' => false,
'debug' => '0',
'cache' => false,
'cache_namespace' => defined('APPLICATION_NAME') ? APPLICATION_NAME : 'nooku',
'debug' => '0',

'identifiers' => array(

Expand All @@ -42,6 +43,14 @@ return array(

),

'translator' => array(

//Cache Settings
'cache' => false,
'cache_namespace' => defined('APPLICATION_NAME') ? APPLICATION_NAME : 'nooku',

),

'exception.handler' => array(

/*
Expand Down
5 changes: 2 additions & 3 deletions install/sample/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ function pick_random(array $array)
}

// Load application.
define('JPATH_ROOT' , dirname(realpath(__DIR__.'/../../code/administrator')));
define('JPATH_SITES' , JPATH_ROOT.'/sites');
define('APPLICATION_ROOT' , dirname(realpath(__DIR__.'/../../code/administrator')));
define('DS', DIRECTORY_SEPARATOR);

require_once JPATH_ROOT.'/bootstrap.php';
require_once APPLICATION_ROOT.'/bootstrap.php';

$application = Library\ObjectManager::getInstance()->getObject('com:application.dispatcher');
$application->loadConfig(new Library\Command());
Expand Down
2 changes: 1 addition & 1 deletion library/dispatcher/response/transport/sendfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function send(DispatcherResponseInterface $response)
//Nginx uses X-Accel-Redirect header
if(strpos($server, 'nginx') !== FALSE)
{
$path = preg_replace('/'.preg_quote(JPATH_ROOT, '/').'/', '', $path, 1);
$path = preg_replace('/'.preg_quote(\Nooku::getInstance()->getRootPath(), '/').'/', '', $path, 1);
$response->headers->set('X-Accel-Redirect', $path);
$response->headers->remove('X-Sendfile');
}
Expand Down
28 changes: 28 additions & 0 deletions library/view/abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public function __construct(ObjectConfig $config)

// Mixin the event interface
$this->mixin('lib:event.mixin', $config);

//Fetch the view data before rendering
$this->addCommandCallback('before.render', '_fetchData');

//Fetch the view data before rendering
$this->addCommandCallback('before.render', '_loadTranslations');
}

/**
Expand Down Expand Up @@ -149,6 +155,28 @@ protected function _actionRender(ViewContext $context)
return trim($contents);
}

/**
* Fetch the view data
*
* @param ViewContext $context A view context object
* @return void
*/
protected function _fetchData(ViewContext $context)
{

}

/**
* Load the view translations
*
* @param ViewContext $context A view context object
* @return void
*/
protected function _loadTranslations(ViewContext $context)
{
$this->getObject('translator')->load('com:'.$this->getIdentifier()->package);
}

/**
* Set a view property
*
Expand Down
Loading

0 comments on commit 967a242

Please sign in to comment.