コード例 #1
0
ファイル: base.php プロジェクト: sontv1003/fashionbeans
 /**
  * function to generate objects of different types, managing file requiring in order to be the most efficient
  * @staticvar array $arrayOfObjects
  * @param string $name
  * @param string $type : in which folder do we go and pick the class
  * @param boolean $force_side : this parameter is almost never set to true,
  *                              it will be useful for instance if you want to get a back controller
  *                              from the frontend, it was used maybe in the shop but it can be ignored for wysija-newsletters
  * @param type $extended_plugin : used only when calling the url from a different plugin it is used watch those files :
  *                              -core/controller.php line 21, 23 ,24
  * @param type $load_lang : the load lang is in the get  to be sure we don't forget to load the language file for each plugin at least once
  *                          the way I see it it could be moved to the index.php of each plugin. for now only wysija-newsletters is translated anyway
  * @return boolean
  */
 public static function get($name, $type, $force_side = false, $extended_plugin = 'wysija-newsletters', $load_lang = true)
 {
     static $array_of_objects;
     if ($load_lang) {
         WYSIJA::load_lang($extended_plugin);
     }
     // store all the objects made so that we can reuse them accross the application if the object is already set we return it immediately
     if (isset($array_of_objects[$extended_plugin][$type . $name])) {
         return $array_of_objects[$extended_plugin][$type . $name];
     }
     // which folder do we pick for controllersand views ? back or front ?
     if ($force_side) {
         $side = $force_side;
     } else {
         $side = WYSIJA_SIDE;
     }
     // for each plugin we will define the $extended_constant variable if it's not defined already
     // also we will defined the $extended_plugin_name which corresponds to the folder name and also will be used to build the class to be called
     switch ($extended_plugin) {
         case 'wysija-newsletters-premium':
             $extended_constant = 'WYSIJANLP';
             if (!defined($extended_constant)) {
                 define($extended_constant, $extended_constant);
             }
             $extended_plugin_name = 'wysijanlp';
             break;
         case 'wysija-newsletters':
             $extended_constant = 'WYSIJA';
             if (!defined($extended_constant)) {
                 define($extended_constant, $extended_constant);
             }
             $extended_plugin_name = 'wysija';
             break;
         default:
             $extended_constant = strtoupper($extended_plugin);
             if (!defined($extended_constant)) {
                 define($extended_constant, $extended_constant);
             }
             $extended_plugin_name = $extended_plugin;
     }
     // security to protect against dangerous ./../ includes
     $name = preg_replace('#[^a-z0-9_]#i', '', $name);
     // this switch will require_once the file needed and build a the class name depending on the parameters passed to the function
     switch ($type) {
         case 'controller':
             // require the parent class necessary
             require_once WYSIJA_CORE . 'controller.php';
             $ctrdir = WYSIJA_PLG_DIR . $extended_plugin . DS . 'controllers' . DS;
             // if we are doing ajax we don't go to one side, ajax is for frontend or backend in the same folder
             if (defined('DOING_AJAX')) {
                 $class_path = $ctrdir . 'ajax' . DS . $name . '.php';
             } else {
                 // the other controllers are called in a side folder back or front
                 $class_path = $ctrdir . $side . DS . $name . '.php';
                 // require the side specific controller file
                 require_once WYSIJA_CTRL . $side . '.php';
             }
             $class_name = strtoupper($extended_plugin_name) . '_control_' . $side . '_' . $name;
             break;
         case 'view':
             $viewdir = WYSIJA_PLG_DIR . $extended_plugin . DS . 'views' . DS;
             // let's get the right path for the view front or back and the right class_name
             $class_path = $viewdir . $side . DS . $name . '.php';
             $class_name = strtoupper($extended_plugin_name) . '_view_' . $side . '_' . $name;
             // require the common view file and the side view file
             require_once WYSIJA_CORE . 'view.php';
             require_once WYSIJA_VIEWS . $side . '.php';
             break;
         case 'helper':
             $helpdir = WYSIJA_PLG_DIR . $extended_plugin . DS . 'helpers' . DS;
             $class_path = $helpdir . $name . '.php';
             $class_name = strtoupper($extended_plugin_name) . '_help_' . $name;
             break;
         case 'model':
             $modeldir = WYSIJA_PLG_DIR . $extended_plugin . DS . 'models' . DS;
             $class_path = $modeldir . $name . '.php';
             $class_name = strtoupper($extended_plugin_name) . '_model_' . $name;
             // require the parent class necessary
             require_once WYSIJA_CORE . 'model.php';
             break;
         case 'widget':
             $modeldir = WYSIJA_PLG_DIR . $extended_plugin . DS . 'widgets' . DS;
             $class_path = $modeldir . $name . '.php';
             if ($name == 'wysija_nl') {
                 $class_name = 'WYSIJA_NL_Widget';
             } else {
                 $class_name = strtoupper($extended_plugin_name) . '_widget_' . $name;
             }
             break;
         default:
             WYSIJA::setInfo('error', 'WYSIJA::get does not accept this type of file "' . $type . '" .');
             return false;
     }
     if (!file_exists($class_path)) {
         WYSIJA::setInfo('error', 'file has not been recognised ' . $class_path);
         return;
     }
     // require the file needed once and store & return the object needed
     require_once $class_path;
     return $array_of_objects[$extended_plugin][$type . $name] = new $class_name($extended_plugin_name);
 }
コード例 #2
0
ファイル: base.php プロジェクト: rotoballer/emily
 /**
  * function to generate objects of different types, managing file requiring in order to be the most efficient
  * @staticvar array $arrayOfObjects
  * @param type $name
  * @param type $type
  * @return type
  */
 public static function get($name, $type, $forceside = false, $extendedplugin = 'wysija-newsletters')
 {
     static $arrayOfObjects;
     WYSIJA::load_lang($extendedplugin);
     /*store all the objects made so that we can reuse them accross the application*/
     if (isset($arrayOfObjects[$extendedplugin][$type . $name])) {
         return $arrayOfObjects[$extendedplugin][$type . $name];
     }
     if ($forceside) {
         $side = $forceside;
     } else {
         $side = WYSIJA_SIDE;
     }
     if ($extendedplugin == 'wysija-newsletters') {
         $extendeconstant = strtoupper("wysija");
         if (!defined($extendeconstant)) {
             define($extendeconstant, $extendeconstant);
         }
         $extendedpluginname = 'wysija';
     } else {
         $extendeconstant = strtoupper($extendedplugin);
         if (!defined($extendeconstant)) {
             define($extendeconstant, $extendeconstant);
         }
         $extendedpluginname = $extendedplugin;
     }
     //security to protect against ./../ includes
     $name = preg_replace('#[^a-z0-9_]#i', '', $name);
     switch ($type) {
         case 'controller':
             $ctrdir = WYSIJA_PLG_DIR . $extendedplugin . DS . 'controllers' . DS;
             /*require the parent class necessary*/
             require_once WYSIJA_CORE . 'controller.php';
             /*require the common controller file*/
             if (defined('DOING_AJAX')) {
                 $classpath = $ctrdir . 'ajax' . DS . $name . '.php';
             } else {
                 $classpath = $ctrdir . $side . DS . $name . '.php';
                 require_once WYSIJA_CTRL . $side . '.php';
                 /*require the side specific controller file*/
             }
             $classname = strtoupper($extendedpluginname) . '_control_' . $side . '_' . $name;
             break;
         case 'view':
             $viewdir = WYSIJA_PLG_DIR . $extendedplugin . DS . 'views' . DS;
             $classpath = $viewdir . $side . DS . $name . ".php";
             $classname = strtoupper($extendedpluginname) . '_view_' . $side . '_' . $name;
             require_once WYSIJA_CORE . 'view.php';
             /*require the common view file*/
             require_once WYSIJA_VIEWS . $side . '.php';
             /*require the side specific view file*/
             break;
         case 'helper':
             $helpdir = WYSIJA_PLG_DIR . $extendedplugin . DS . 'helpers' . DS;
             $classpath = $helpdir . $name . '.php';
             $classname = strtoupper($extendedpluginname) . '_help_' . $name;
             break;
         case 'model':
             $modeldir = WYSIJA_PLG_DIR . $extendedplugin . DS . 'models' . DS;
             $classpath = $modeldir . $name . '.php';
             $classname = strtoupper($extendedpluginname) . '_model_' . $name;
             /*require the parent class necessary*/
             require_once WYSIJA_CORE . 'model.php';
             break;
         default:
             WYSIJA::setInfo('error', 'WYSIJA::get does not accept this type of file "' . $type . '" .');
             return false;
     }
     if (!file_exists($classpath)) {
         WYSIJA::setInfo('error', 'file has not been recognised ' . $classpath);
         return;
     }
     require_once $classpath;
     return $arrayOfObjects[$extendedplugin][$type . $name] = new $classname($extendedpluginname);
 }