Exemplo n.º 1
0
 public function __construct($folder, $translator = null)
 {
     $this->_basePath = realpath(ptc_path('app') . static::BASE_PATH . $folder);
     if (!$this->_basePath) {
         trigger_error('EmailManager helper could not find folder ' . ptc_path('app') . static::BASE_PATH . $folder . ' for email templates!', E_USER_ERROR);
     }
     if ($translator && !$this->_xml($translator)) {
         return false;
     }
 }
Exemplo n.º 2
0
 /**
  *
  */
 public static function autoload($controllers)
 {
     $controllers = is_array($controllers) ? $controllers : array($controllers);
     \Router::group('website.autoload', function () use($controllers) {
         $xml = simplexml_load_file(\App::option('website.xml_config_path') . '/routes.xml');
         foreach ($controllers as $controller) {
             static::controller($controller, $xml);
         }
         if (\App::option('website.auto_include_js_lang')) {
             \Router::get('/js/website-helper/lang/{lang}.js', function ($lang) {
                 header('Content-Type: application/javascript');
                 if (file_exists(\App::option('website.language_files_path') . '/' . $lang . '.js')) {
                     ob_start();
                     require_once \App::option('website.language_files_path') . '/' . $lang . '.js';
                     return ob_get_clean();
                 } else {
                     return 'var _lang = _lang || {"key":"file not found"};';
                 }
             });
         }
         if (\App::option('website.use_app_prototype_js')) {
             \Router::get('/js/website-helper/app/{prototype}.js', function ($prototype) {
                 header('Content-Type: application/javascript');
                 ob_start();
                 require_once ptc_path('helpers') . '/Website/app.prototype.js/' . $prototype . '.js';
                 return ob_get_clean();
             })->where('prototype', 'App|BaseModel|BaseController|BaseForm|BaseContainer|BaseElements|Validator');
         }
         $helpers = \App::option('website.app_prototype_helpers');
         if ($helpers) {
             \Router::get('/js/website-helper/app/helpers/{helper}.js', function ($helper) {
                 header('Content-Type: application/javascript');
                 ob_start();
                 require_once ptc_path('helpers') . '/Website/app.prototype.js/helpers/' . $helper . '.js';
                 return ob_get_clean();
             })->where('helper', $helpers);
         }
     })->prefix(\App::env());
 }
Exemplo n.º 3
0
 protected static function _addModule($name)
 {
     $path = ptc_path('root') . '/modules/' . $name;
     if (!realpath($path)) {
         trigger_error('Module "' . $name . '" is not accessible!', E_USER_ERROR);
         return;
     }
     static::$_modules[$name] = new Instance($name, $path);
     ptc_add_path(['module_' . $name => $path]);
 }
Exemplo n.º 4
0
 public static function intercept($path, $type = 'file', $debug = false)
 {
     $modules = Manager::all();
     foreach ($modules as $module) {
         $m_path = $module->path();
         if (false !== strpos($path, ptc_path('root') . '/app/config')) {
             continue;
             // do nothing
         } else {
             if (false !== strpos($path, ptc_path('root') . '/app') && false === strpos($path, $m_path)) {
                 $file = str_replace(ptc_path('root') . '/app', $m_path, $path);
                 if ('realpath' === $type && ($f = realpath($file))) {
                     $path = $f;
                     break;
                     // load the first file found
                 } else {
                     if ('file' === $type && file_exists($file)) {
                         if ($debug) {
                             ptc_log([$file, $path], 'StreamWrapper intercepted module file!', 'StreamWrapper Config');
                         }
                         $path = $file;
                         break;
                         // load the first file found
                     }
                 }
             }
         }
     }
     return $path;
 }
}
/* STOP CODE COVERAGE ANALYSIS */
ptc_stop_coverage();
// PtcDebug::stopCoverage( )
/* STOP FUNCTION CALLS TRACING */
ptc_stop_trace();
// PtcDebug::stopTrace( )
/*** PTC HANDYMAN HELPERPS ****************************************************/
/* ADDING APPLICATION PATHS FOR LATER USAGE ( PtcHandMan::addAppPath( ) ) */
ptc_add_path(array('lib' => dirname(__FILE__) . '/autoloader-example-files'));
/* ADDING CLASS FILES ( PtcHandMan::addFile( ) ) */
ptc_add_file(array('HmTestClassFile' => ptc_path('lib') . '/class-file.php', 'ns\\HmTestClassFile' => ptc_path('lib') . '/ns-class-file.php'));
/* ADDING DIRECTORIES WITH CLASSES TO THE AUTOLOADER ( PtcHandMan::addDir( ) ) */
ptc_add_dir(ptc_path('lib'));
// PtcHandMan::getAppPath(
/* ADDING A NAMESPACED DIRECTORY WITH CLASSES TO THE AUTOLOADER */
ptc_add_dir(array('nsTest' => ptc_path('lib') . '/namespaceTest'));
/* GETTING THE DIRECTORIES OF THE AUTOLOADER ( PtcHandyMan::getDirs( ) )*/
$dirs = ptc_dir();
// PtcHandyMan::getDirs( ) params: ( files , directories , ns )
ptc_log($dirs, 'getting all directories and files to be autoloaded');
//PtcDebug::bufferLog( );
/*** PTC EVENT HELPERPS ****************************************************/
/* ADDING EVENT LISTENERS ( PtcEvent::listen( ) ) */
ptc_listen('some.event', function ($data) {
    // do some stuff
    ptc_log($data, 'Called event with closure as call back');
    // PtcDebug::bufferLog( )
});
/* FIRING EVENTS ( PtcEvent::fire( ) ) */
PtcEvent::fire('some.event', array('some data'));
Exemplo n.º 6
0
 /**
  * Load module config files that are not in root config
  */
 protected static function _loadModulesConfig()
 {
     $config = array('..', '.');
     foreach (static::options() as $key => $val) {
         $config[] = $key . '.php';
     }
     foreach (Module::all() as $k => $module) {
         $scanned_directory = array_diff(scandir(ptc_path('root') . '/modules/' . $k . '/config'), $config);
         if (!empty($scanned_directory)) {
             foreach ($scanned_directory as $file) {
                 $option_name = str_replace('.php', '', $file);
                 $options = (require ptc_path('root') . '/modules/' . $k . '/config/' . $file);
                 if (ptc_array_get($options, '_load')) {
                     $options = call_user_func(ptc_array_get($options, '_load'), $options);
                 }
                 static::option($option_name, $options);
             }
         }
     }
 }
<?php

/*
| ---------------------------------------------------
| Wesite Helper Cofiguration File
| ---------------------------------------------------
|
*/
return array('_load' => '\\helpers\\Website\\Website::loadConfig', 'controllers' => array('main'), 'xml_config_path' => ptc_path('xml') . '/config', 'language_files_path' => ptc_path('xml') . '/lang', 'views_path' => ptc_path('views'), 'lang_param' => '_lang', 'resources_param' => '_resources', 'data_param' => '_data', 'elements_param' => '_elements', 'current_route_param' => '_currentRoute', 'current_page_param' => '_currentPage', 'auto_include_js_lang' => true, 'use_app_prototype_js' => true, 'debug_category' => 'Website Helper', 'listener_priority' => 0);
<?php

/*
| ---------------------------------------------------
| Wesite Helper Cofiguration File
| ----------------------------------------------------------
|
| This file should hold details for all your database connections
| Refer to http://phptoolcase.com/ptc-db-guide.html to 
| understand all available options
|
*/
return array('_load' => '\\helpers\\Website\\Manager::loadConfig', 'controllers' => array('main'), 'xml_config_path' => ptc_path('xml') . '/config', 'language_files_path' => ptc_path('xml') . '/lang', 'views_path' => ptc_path('views'), 'lang_param' => '_lang', 'resources_param' => '_resources', 'data_param' => '_data', 'elements_param' => '_elements', 'meta_tags_param' => '_metatags', 'router_param' => '_router', 'auto_include_js_lang' => true, 'use_app_prototype_js' => true, 'debug_category' => 'Website Helper', 'listener_priority' => 0, 'app_prototype_helpers' => 'Facebook');