Skip to content

Instantly share code, notes, and snippets.

@real34
Last active August 29, 2015 13:57
Show Gist options
  • Save real34/9555885 to your computer and use it in GitHub Desktop.
Save real34/9555885 to your computer and use it in GitHub Desktop.
{
"name": "croogo/app",
"description": "Croogo skeleton app",
"homepage": "http://github.com/croogo/app",
"type": "project",
"license": "MIT",
"authors": [
{
"name": "Fahad Ibnay Heylaal",
"email": "contact@fahad19.com",
"homepage": "http://fahad19.com"
},
{
"name": "Rachman Chavik",
"email": "contact@xintesa.com",
"homepage": "http://xintesa.com"
},
{
"name": "Kyle Robinson Young",
"email": "kyle@dontkry.com",
"homepage": "http://dontkry.com"
}
],
"minimum-stability": "dev",
"require": {
"cakephp/cakephp": "3.0.*-dev",
"croogo/croogo": "~3.0",
"php": ">=5.4"
},
"require-dev": {
"d11wtq/boris": "1.0.*"
},
"suggest": {
"phpunit/phpunit": "Allows automated tests to be run without system-wide install."
},
"autoload": {
"psr-4": {
"App\\": "App",
"App\\Test\\": "Test",
"": "./Plugin"
}
},
"scripts": {
"post-install-cmd": "App\\Console\\Installer::postInstall"
}
}
Plugin::load('Croogo', ['bootstrap' => true]);
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since CakePHP(tm) v 0.10.8.2117
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace App\Config;
/**
* Configure paths required to find CakePHP + general filepath
* constants
*/
require __DIR__ . '/paths.php';
// Use composer to load the autoloader.
if (file_exists(ROOT . '/vendor/autoload.php')) {
$loader = require ROOT . '/vendor/autoload.php';
}
$loader->add('Croogo\\', ROOT . '/vendor/croogo/croogo');
new \Croogo\Croogo\Controller\AppController();
echo 'ssdf';
die;
// If composer is not used, use CakePHP's classloader to autoload the framework
// and the application. You will also need setup autoloading for plugins by
// passing `autoload' => true for `Plugin::loadAll()` or `Plugin::load()`
//
// If you are using a custom namespace, you'll need to set it here as well.
if (!class_exists('Cake\Core\Configure')) {
require CAKE . 'Core/ClassLoader.php';
$loader = new \Cake\Core\ClassLoader;
$loader->register();
$loader->addNamespace('Cake', CAKE);
$loader->addNamespace('App', APP);
}
/**
* Bootstrap CakePHP.
*
* Does the various bits of setup that CakePHP needs to do.
* This includes:
*
* - Registering the CakePHP autoloader.
* - Setting the default application paths.
*/
require CAKE . 'bootstrap.php';
use Cake\Cache\Cache;
use Cake\Configure\Engine\PhpConfig;
use Cake\Console\ConsoleErrorHandler;
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Datasource\ConnectionManager;
use Cake\Error\ErrorHandler;
use Cake\Log\Log;
use Cake\Network\Email\Email;
use Cake\Utility\Inflector;
/**
* Read configuration file and inject configuration into various
* CakePHP classes.
*
* By default there is only one configuration file. It is often a good
* idea to create multiple configuration files, and separate the configuration
* that changes from configuration that does not. This makes deployment simpler.
*/
try {
Configure::config('default', new PhpConfig());
Configure::load('app.php', 'default', false);
} catch (\Exception $e) {
die('Unable to load Config/app.php. Create it by copying Config/app.default.php to Config/app.php.');
}
// Load an environment local configuration file.
// You can use this file to provide local overrides to your
// shared configuration.
//Configure::load('app_local.php', 'default');
/**
* Uncomment this line and correct your server timezone to fix
* any date & time related errors.
*/
//date_default_timezone_set('UTC');
/**
* Configure the mbstring extension to use the correct encoding.
*/
mb_internal_encoding(Configure::read('App.encoding'));
/**
* Register application error and exception handlers.
*/
if (php_sapi_name() === 'cli') {
(new ConsoleErrorHandler(Configure::consume('Error')))->register();
} else {
(new ErrorHandler(Configure::consume('Error')))->register();
}
/**
* Set the full base url.
* This URL is used as the base of all absolute links.
*
* If you define fullBaseUrl in your config file you can remove this.
*/
if (!Configure::read('App.fullBaseUrl')) {
$s = null;
if (env('HTTPS')) {
$s = 's';
}
$httpHost = env('HTTP_HOST');
if (isset($httpHost)) {
Configure::write('App.fullBaseUrl', 'http' . $s . '://' . $httpHost);
}
unset($httpHost, $s);
}
Cache::config(Configure::consume('Cache'));
ConnectionManager::config(Configure::consume('Datasources'));
Email::configTransport(Configure::consume('EmailTransport'));
Email::config(Configure::consume('Email'));
Log::config(Configure::consume('Log'));
/**
* Custom Inflector rules, can be set to correctly pluralize or singularize table, model, controller names or whatever other
* string is passed to the inflection functions
*
* Inflector::rules('singular', array('rules' => array(), 'irregular' => array(), 'uninflected' => array()));
* Inflector::rules('plural', array('rules' => array(), 'irregular' => array(), 'uninflected' => array()));
*
*/
/**
* Plugins need to be loaded manually, you can either load them one by one or all of them in a single call
* Uncomment one of the lines below, as you need. make sure you read the documentation on Plugin to use more
* advanced ways of loading plugins
*
* Plugin::loadAll(); // Loads all plugins at once
* Plugin::load('DebugKit'); //Loads a single plugin named DebugKit
*
*/
Plugin::load('Croogo', ['bootstrap' => true, 'namespace' => 'Croogo\Croogo']);
<?php
// path vendor/croogo/croogo/Croogo/Controller/AppController.php
//App::uses('Controller', 'Controller');
namespace Croogo\Croogo\Controller;
die('fsdfsd');
/**
* Croogo App Controller
*
* @category Croogo.Controller
* @package Croogo.Croogo.Controller
* @version 1.5
* @author Fahad Ibnay Heylaal <contact@fahad19.com>
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @link http://www.croogo.org
*/
class AppController extends \Controller {
/**
* Default Components
*
* @var array
* @access public
*/
protected $_defaultComponents = array(
'Croogo.Croogo',
'Security',
'Acl',
'Auth',
'Session',
'RequestHandler',
);
/**
* List of registered Application Components
*
* These components are typically hooked into the application during bootstrap.
* @see Croogo::hookComponent
*/
protected $_appComponents = array();
/**
* List of registered API Components
*
* These components are typically hooked into the application during bootstrap.
* @see Croogo::hookApiComponent
*/
protected $_apiComponents = array();
/**
* Helpers
*
* @var array
* @access public
*/
public $helpers = array(
'Html',
'Form',
'Session',
'Text',
'Js',
'Time',
'Croogo.Layout',
'Custom',
);
/**
* Pagination
*/
public $paginate = array(
'limit' => 10,
);
/**
* Cache pagination results
*
* @var boolean
* @access public
*/
public $usePaginationCache = true;
/**
* View
*
* @var string
* @access public
*/
public $viewClass = 'Theme';
/**
* Theme
*
* @var string
* @access public
*/
public $theme;
/**
* Constructor
*
* @access public
*/
public function __construct($request = null, $response = null) {
parent::__construct($request, $response);
if ($request) {
$request->addDetector('api', array(
'callback' => array('CroogoRouter', 'isApiRequest'),
));
$request->addDetector('whitelisted', array(
'callback' => array('CroogoRouter', 'isWhitelistedRequest'),
));
}
$this->getEventManager()->dispatch(new CakeEvent('Controller.afterConstruct', $this));
}
/**
* implementedEvents
*/
public function implementedEvents() {
return parent::implementedEvents() + array(
'Controller.afterConstruct' => 'afterConstruct',
);
}
/**
* afterConstruct
*
* called when Controller::__construct() is complete.
* Override this method to perform class configuration/initialization that
* needs to be performed earlier from Controller::beforeFilter().
*
* You still need to call parent::afterConstruct() method to ensure correct
* behavior.
*/
public function afterConstruct() {
Croogo::applyHookProperties('Hook.controller_properties', $this);
$this->_setupComponents();
if (isset($this->request->params['admin'])) {
$this->helpers[] = 'Croogo.Croogo';
if (empty($this->helpers['Html'])) {
$this->helpers['Html'] = array('className' => 'Croogo.CroogoHtml');
}
if (empty($this->helpers['Form'])) {
$this->helpers['Form'] = array('className' => 'Croogo.CroogoForm');
}
if (empty($this->helpers['Paginator'])) {
$this->helpers['Paginator'] = array('className' => 'Croogo.CroogoPaginator');
}
}
}
/**
* Setup the components array
*
* @param void
* @return void
*/
protected function _setupComponents() {
if ($this->request && !$this->request->is('api')) {
$this->components = Hash::merge(
$this->_defaultComponents,
$this->_appComponents,
$this->components
);
return;
}
$this->components = Hash::merge(
$this->components,
array('Acl', 'Auth', 'Session', 'RequestHandler', 'Acl.AclFilter'),
$this->_apiComponents
);
$apiComponents = array();
$priority = 8;
foreach ($this->_apiComponents as $component => $setting) {
if (is_string($setting)) {
$component = $setting;
$setting = array();
}
$className = $component;
list(, $apiComponent) = pluginSplit($component);
$setting = Hash::merge(compact('className', 'priority'), $setting);
$apiComponents[$apiComponent] = $setting;
}
$this->_apiComponents = $apiComponents;
}
/**
* Allows extending action from component
*
* @throws MissingActionException
*/
public function invokeAction(CakeRequest $request) {
try {
return parent::invokeAction($request);
} catch (MissingActionException $e) {
$params = $request->params;
$prefix = isset($params['prefix']) ? $params['prefix'] : '';
$action = str_replace($prefix . '_', '', $params['action']);
foreach ($this->_apiComponents as $component => $setting) {
if (empty($this->{$component})) {
continue;
}
if ($this->{$component}->isValidAction($action)) {
$this->setRequest($request);
return $this->{$component}->{$action}($this);
}
}
throw $e;
}
}
/**
* beforeFilter
*
* @return void
* @throws MissingComponentException
*/
public function beforeFilter() {
parent::beforeFilter();
$aclFilterComponent = Configure::read('Site.acl_plugin') . 'Filter';
if (empty($this->{$aclFilterComponent})) {
throw new MissingComponentException(array('class' => $aclFilterComponent));
}
$this->{$aclFilterComponent}->auth();
$this->RequestHandler->setContent('json', array('text/x-json', 'application/json'));
if (!$this->request->is('api')) {
$this->Security->blackHoleCallback = 'securityError';
$this->Security->requirePost('admin_delete');
}
if (isset($this->request->params['admin'])) {
$this->layout = 'admin';
}
if ($this->RequestHandler->isAjax()) {
$this->layout = 'ajax';
}
if (Configure::read('Site.theme') && !isset($this->request->params['admin'])) {
$this->theme = Configure::read('Site.theme');
} elseif (Configure::read('Site.admin_theme') && isset($this->request->params['admin'])) {
$this->theme = Configure::read('Site.admin_theme');
}
if (
!isset($this->request->params['admin']) &&
Configure::read('Site.status') == 0 &&
$this->Auth->user('role_id') != 1
) {
if (!$this->request->is('whitelisted')) {
$this->layout = 'maintenance';
$this->response->statusCode(503);
$this->set('title_for_layout', __d('croogo', 'Site down for maintenance'));
$this->render('../Elements/blank');
}
}
if (isset($this->request->params['locale'])) {
Configure::write('Config.language', $this->request->params['locale']);
}
if (isset($this->request->params['admin'])) {
Croogo::dispatchEvent('Croogo.beforeSetupAdminData', $this);
}
}
/**
* blackHoleCallback for SecurityComponent
*
* @return void
*/
public function securityError($type) {
switch ($type) {
case 'auth':
break;
case 'csrf':
break;
case 'get':
break;
case 'post':
break;
case 'put':
break;
case 'delete':
break;
default:
break;
}
$this->set(compact('type'));
$this->response = $this->render('../Errors/security');
$this->response->statusCode(400);
$this->response->send();
$this->_stop();
return false;
}
/**
* _setupAclComponent
*/
protected function _setupAclComponent() {
$config = Configure::read('Access Control');
if (isset($config['rowLevel']) && $config['rowLevel'] == true) {
if (strpos($config['models'], $this->plugin . '.' . $this->modelClass) === false) {
return;
}
$this->Components->load(Configure::read('Site.acl_plugin') . '.RowLevelAcl');
}
}
/**
* Combine add and edit views
*
* @see Controller::render()
*/
public function render($view = null, $layout = null) {
list($plugin, ) = pluginSplit(App::location(get_parent_class($this)));
if ($plugin) {
App::build(array(
'View' => array(
CakePlugin::path($plugin) . 'View' . DS,
),
), App::APPEND);
}
if (strpos($view, '/') !== false || $this instanceof CakeErrorController) {
return parent::render($view, $layout);
}
$fallbackView = $this->__getDefaultFallbackView();
if (is_null($view) && in_array($this->request->action, array('admin_edit', 'admin_add', 'edit', 'add'))) {
$viewPaths = App::path('View', $this->plugin);
$themePath = $this->theme ? App::themePath($this->theme) : null;
$searchPaths = array_merge((array)$themePath, $viewPaths);
$view = $this->__findRequestedView($searchPaths);
if (empty($view)) {
$view = $fallbackView;
}
}
return parent::render($view, $layout);
}
/**
* Croogo uses this callback to load Paginator helper when one is not supplied.
* This is required so that pagination variables are correctly set with caching
* is used.
*
* @return void
* @see Controller::beforeRender()
*/
public function beforeRender() {
if (!$this->usePaginationCache) {
return;
}
if (!isset($this->helpers['Paginator']) && !in_array('Paginator', $this->helpers)) {
$this->helpers[] = 'Paginator';
}
}
/**
* Get Default Fallback View
*
* @return string
*/
private function __getDefaultFallbackView() {
$fallbackView = 'form';
if (!empty($this->request->params['prefix']) && $this->request->params['prefix'] === 'admin') {
$fallbackView = 'admin_form';
}
return $fallbackView;
}
/**
* Search for existing view override in registered view paths
*
* @return string
*/
private function __findRequestedView($viewPaths) {
if (empty($viewPaths)) {
return false;
}
foreach ($viewPaths as $path) {
$file = $this->viewPath . DS . $this->request->action . '.ctp';
$requested = $path . $file;
if (file_exists($requested)) {
return $requested;
} else {
if (!$this->plugin) {
continue;
}
$requested = $path . 'Plugin' . DS . $this->plugin . DS . $file;
if (file_exists($requested)) {
return $requested;
}
}
}
return false;
}
}
{
"name": "croogo/croogo",
"description": "Croogo - Open Source CMS built for everyone",
"homepage": "http://github.com/croogo/croogo",
"license": "MIT",
"authors": [
{
"name": "Fahad Ibnay Heylall",
"email": "contact@fahad19.com",
"homepage": "http://fahad19.com"
},
{
"name": "Rachman Chavik",
"email": "contact@xintesa.com",
"homepage": "http://xintesa.com"
},
{
"name": "Kyle Robinson Young",
"email": "kyle@dontkry.com",
"homepage": "http://dontkry.com"
}
],
"config": {
"vendor-dir": "Vendor"
},
"require": {
"php": ">=5.3.0",
"composer/installers": "~1.0",
"croogo/Ckeditor": "~1.0",
"cakedc/search": "dev-master",
"cakedc/migrations": "~2.2"
},
"suggest": {
"croogo/locale": "Localization for Croogo"
},
"autoload": {
"psr-4": {
"Croogo\\": ""
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment