Example #1
0
    /**
     * Finds an addon
     * 
     * @param string  $addon  Name of add-on to find
     * @return mixed
     */
    protected static function find($addon)
    {
        // if this is new, check for it
        if (!isset(self::$addon_cache[$addon])) {
            // this is a new one, find it
            $locations = Config::getAddOnLocations();

            $addon_location = null;
            foreach ($locations as $location) {
                if (Folder::exists($location . $addon . "/")) {
                    $addon_location = $location . $addon . "/";
                    break;
                }
            }

            // set this for future reference
            self::$addon_cache[$addon] = $addon_location;
        }

        // return it
        return self::$addon_cache[$addon];
    }
Example #2
0
 /**
  * Attempts to load an add-on file
  * 
  * @param integer  $type  Type of add-on file to load
  * @param string  $addon  Add-on to load
  * @return Addon
  * @throws Exception
  */
 public static function loadAddonResource($type, $addon)
 {
     $folders = Config::getAddOnLocations();
     $file = null;
     $type_map = array(self::PLUGIN => array('abbreviation' => 'pi', 'name' => 'plugin'), self::FIELDTYPE => array('abbreviation' => 'ft', 'name' => 'fieldtype'), self::HOOKS => array('abbreviation' => 'hooks', 'name' => 'hooks'), self::TASKS => array('abbreviation' => 'tasks', 'name' => 'tasks'), self::MODIFIER => array('abbreviation' => 'mod', 'name' => 'modifier'), self::API => array('abbreviation' => 'api', 'name' => 'API'));
     if (!isset($type_map[$type])) {
         Log::error("Unknown add-on type.", "API", "Resource");
         throw new Exception("Unknown add-on type.");
     }
     // grab the abbreviation and name
     $addon_details = $type_map[$type];
     $abbr = $addon_details['abbreviation'];
     $name = $addon_details['name'];
     // loop through folders looking for addon
     foreach ($folders as $folder) {
         if (Folder::exists(BASE_PATH . '/' . $folder . $addon) && File::exists(BASE_PATH . '/' . $folder . $addon . '/' . $abbr . '.' . $addon . '.php')) {
             $file = $folder . $addon . '/' . $abbr . '.' . $addon . '.php';
             break;
         }
     }
     if (!$file) {
         Log::error("Could not find files to load the `{$addon}` {$name}.", "API", "Resource");
         throw new Exception("Could not find files to load the `{$addon}` {$name}.");
     }
     $class = ucwords($name) . "_" . $addon;
     if (!class_exists($class)) {
         throw new ResourceNotFoundException("Improperly formatted {$name} object.");
     }
     return new $class();
 }
 public static function process_field_data($fieldtype, $field_data, $settings = NULL, $fieldname = NULL)
 {
     $fieldtype_folders = Config::getAddOnLocations();
     foreach ($fieldtype_folders as $folder) {
         if (is_dir($folder . $fieldtype) && is_file($folder . $fieldtype . '/ft.' . $fieldtype . '.php')) {
             $file = $folder . $fieldtype . '/ft.' . $fieldtype . '.php';
             break;
         } elseif (is_file($folder . '/ft.' . $fieldtype . '.php')) {
             $file = $folder . '/ft.' . $fieldtype . '.php';
             break;
         }
     }
     # fieldtype exists
     if (isset($file)) {
         require_once $file;
         $class = 'Fieldtype_' . $fieldtype;
         #formatted properly
         if (class_exists($class)) {
             $field = new $class();
         }
         # function exists
         if (method_exists($field, 'process')) {
             $field->fieldname = $fieldname;
             $field->field_data = $field_data;
             $field->settings = $settings;
             $field_data = $field->process($settings);
         }
     }
     return $field_data;
 }