Skip to content

Commit

Permalink
Adding a new method to attach blocks to app routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymond Benc committed Aug 20, 2015
1 parent 97ed2ea commit 8331749
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 14 deletions.
2 changes: 0 additions & 2 deletions PF.Base/include/library/phpfox/file/file.class.php
Expand Up @@ -1194,8 +1194,6 @@ public function load($sFormItem, $aSupported = array(), $iMaxSize = null)

if (Phpfox_Image::instance()->isImageExtension($this->_aFile['ext']) && !Phpfox_Image::instance()->isImage($this->_aFile['tmp_name']))
{
throw new \Exception('Failed: ' . print_r($this->_aFile, true), 0);

return Phpfox_Error::set(Phpfox::getPhrase('core.not_a_valid_image_we_only_accept_the_following_file_extensions_support', array('support' => implode(', ', $aSupported))));
}

Expand Down
4 changes: 3 additions & 1 deletion PF.Base/include/library/phpfox/module/module.class.php
Expand Up @@ -628,7 +628,9 @@ public function getModuleBlocks($iId, $bForce = false)

//$sController = strtolower($this->_sModule . '.' . $this->_sController);
$sController = strtolower($this->_sModule . '.' . str_replace(array('\\', '/'), '.' , $this->_sController));

if (\Core\Route\Controller::$name) {
$sController = 'route_' . \Core\Route\Controller::$name['route'];
}
// $this->blocks = $this->_aModuleBlocks;
// $this->_aModuleBlocks = $this->blocks;

Expand Down
6 changes: 6 additions & 0 deletions PF.Base/include/setting/routes.sett.php
Expand Up @@ -11,6 +11,12 @@
':id' => '([0-9]+)'
]
],
'/api/feed/:type' => [
'call' => '\Api\Feed',
'where' => [
':type' => '([a-zA-Z_-]+)'
]
],

// User
'/api/user' => [
Expand Down
7 changes: 7 additions & 0 deletions PF.Src/Api/Feed.php
Expand Up @@ -63,6 +63,13 @@ public function get($params = null) {
$params['id'] = $id;
$isSingle = true;
}
else if (is_string($params)) {
$params = [];
return [
'type' => $params
];
$params['type_id'] = $params;
}

if (isset($_GET['page'])) {
$params['page'] = $_GET['page'];
Expand Down
19 changes: 10 additions & 9 deletions PF.Src/Core/Block.php
Expand Up @@ -23,16 +23,17 @@ public function __construct($controller, $location, $callback) {
$this->active = (new \Api\User())->get(\Phpfox::getUserId());
$this->db = new Db();

call_user_func($callback, $this);

$html = '
<div class="block">
' . (isset($this->_arg['title']) ? '<div class="title">' . $this->_arg['title'] . '</div>' : '') . '
<div class="content">
' . (isset($this->_arg['content']) ? $this->_arg['content'] : '') . '
$html = call_user_func($callback, $this);
if (empty($html)) {
$html = '
<div class="block">
' . (isset($this->_arg['title']) ? '<div class="title">' . $this->_arg['title'] . '</div>' : '') . '
<div class="content">
' . (isset($this->_arg['content']) ? $this->_arg['content'] : '') . '
</div>
</div>
</div>
';
';
}
\Phpfox_Module::instance()->block($controller, $location, $html);
}

Expand Down
10 changes: 9 additions & 1 deletion PF.Src/Core/Controller.php
Expand Up @@ -6,14 +6,16 @@ class Controller {
public $request;
public $url;
public $active;
public $route;

private $_view;
private $_template;

public function __construct($path = null) {
public function __construct($path = null, $route = null) {
$this->request = new Request();
$this->url = new Url();
$this->active = (new \Api\User())->get(\Phpfox::getUserId());
$this->route = $route;

$this->_template = \Phpfox_Template::instance();
$this->_view = new View();
Expand All @@ -22,6 +24,12 @@ public function __construct($path = null) {
}
}

public function block($location, \Closure $callback) {
new Block('route_' . $this->route, $location, $callback);

return $this;
}

public function h1($name, $url) {
$this->_template->setBreadcrumb($name, $this->url->make($url), true);

Expand Down
2 changes: 1 addition & 1 deletion PF.Src/Core/Route/Controller.php
Expand Up @@ -112,7 +112,7 @@ public function get() {
}

if (isset($routes[$uri]['run'])) {
$Controller = new \Core\Controller($routes[$uri]['path'] . 'views');
$Controller = new \Core\Controller($routes[$uri]['path'] . 'views', $uri);

$pass = [$Controller];
if (isset($r['args'])) {
Expand Down

0 comments on commit 8331749

Please sign in to comment.