Example #1
0
 /**
  * Reloads and updates installed components.
  * If a new core component is found, it will be activated automatically.
  *
  * @return void
  */
 private function searchNewComponents()
 {
     $components = ak_get_installed_components($this->componentsPath(), true);
     if (empty($components)) {
         $this->components = false;
         return;
     }
     $installed = array();
     $core = array();
     $optional = array();
     // Sort components by core and optional. Then by name.
     foreach ($components as $id => $component) {
         if ($component['Core']) {
             $core[$id] = $component;
         } else {
             $optional[$id] = $component;
         }
     }
     ksort($core);
     ksort($optional);
     // Sort components by ID.
     $components = array_merge($core, $optional);
     // Now, activate new core components, and set activation for optional.
     $this->components = get_option($this->ID . '_components');
     foreach ($components as $id => $component) {
         $installed[$id] = $component;
         if ($component['Core']) {
             $installed[$id]['active'] = 1;
             if (!isset($this->components[$id]) || !$this->components[$id]['active']) {
                 require_once $component['File'];
                 do_action('ak_activate_' . $this->ID . '_' . $id);
             }
         } else {
             if (isset($this->components[$id]['active'])) {
                 $installed[$id]['active'] = $this->components[$id]['active'];
             } else {
                 $installed[$id]['active'] = 0;
             }
         }
     }
     $this->components = $installed;
     update_option($this->ID . '_components', $this->components);
 }
/**
 * Gets information about all optional installed components.
 * The function is recursive to find files in all directory levels.
 *
 * TODO: Path must be provided as AOC_PATH is only for community plugin.
 * @since 0.7
 *
 * @param string $path Absolute path where to search for components.
 * @param boolean $core If we want to include the core components or not.
 * @param array $files An array with filenames to seach information in. If empty will search on $path.
 * @return array Array with all found components information.
 */
function ak_get_installed_components($path, $core = false, $files = array())
{
    if (empty($files)) {
        $files = ak_dir_content($path, 'extensions=php');
    }
    $components = array();
    foreach ($files as $subdir => $file) {
        if (is_array($file)) {
            $newdir = $path . '/' . $subdir;
            $data = ak_get_installed_components($newdir, $core, $file);
            if (is_array($data)) {
                $components = array_merge($components, $data);
            }
        } else {
            $data = ak_component_data($path . '/' . $file, $core);
            if (is_array($data)) {
                $components[$data['Component']] = $data;
            }
        }
    }
    return $components;
}
Example #3
0
 /**
  * Updates plugin to 0.6
  * Changes components design to activation/deactivation hooks.
  * Creates the unmoderated capability.
  *
  * @since 0.7
  *
  * @return void
  */
 private function update060()
 {
     $old_components = get_option($this->ID . '_components');
     $components = ak_get_installed_components($this->componentsPath(), true);
     foreach ($components as $key => $component) {
         $cid = $component['Component'];
         if ($component['Core'] || isset($old_components[$cid]) && $old_components[$cid]) {
             $components[$key]['active'] = true;
         } else {
             $components[$key]['active'] = false;
         }
     }
     update_option($this->ID . '_components', $components);
     $roles = ak_get_roles();
     foreach ($roles as $name) {
         $role = get_role($name);
         $role->add_cap('aoc_unmoderated');
     }
 }