Example #1
0
 public static function widget($element)
 {
     static $classes = array();
     $class_key = 'widget_' . $element;
     if (isset($classes[$class_key])) {
         $class = $classes[$class_key];
     } else {
         $widget_locations = HC_App::widget_locations();
         foreach ($widget_locations as $prfx => $locations) {
             $class = strtoupper($prfx) . '_Html_Widget_' . ucfirst($element);
             if (!class_exists($class)) {
                 /* attempt to load the file */
                 if (!is_array($locations)) {
                     $locations = array($locations);
                 }
                 foreach ($locations as $location) {
                     //echo "ATTEMPT TO LOAD '$class'<br>";
                     $file = $location . '/html/' . $element . '.php';
                     if (file_exists($file)) {
                         include_once $file;
                         break;
                     }
                 }
             }
             if (class_exists($class)) {
                 $classes[$class_key] = $class;
                 break;
             }
         }
     }
     $args = func_get_args();
     if (class_exists($class)) {
         $return = new $class();
         array_shift($args);
         if ($args) {
             call_user_func_array(array($return, "init"), $args);
         }
         return $return;
     } else {
         throw new Exception("No class defined: '{$class}'");
     }
 }