/** * Load and extract our application development files * * @return void */ public static function extract() { /* Are we IN_DEV (and does it matter)? */ if (static::$checkInDev) { if (!defined('\\IPS\\IN_DEV') or !\IPS\IN_DEV) { return; } } /* Attempt to load our application */ $thisApp = NULL; $applications = \IPS\Application::applications(); foreach ($applications as $application) { if ($application->directory === static::$appDir) { $thisApp = $application; } } if (!$thisApp) { \IPS\Log::i(\LOG_ERR)->write('Error : Application ' . static::$appDir . ' not found', 'devpackager_error'); return; } /* Set our paths */ $appPath = join(\DIRECTORY_SEPARATOR, [\IPS\ROOT_PATH, 'applications', $thisApp->directory]); $devPath = join(\DIRECTORY_SEPARATOR, [$appPath, 'dev']); $devTar = join(\DIRECTORY_SEPARATOR, [$appPath, 'data', 'dev.tar']); /* Load and extract our tarball */ try { if (!is_dir($devPath)) { mkdir($devPath, 0777, true); } $devFiles = new \PharData($devTar, 0, NULL, \Phar::TAR); $devFiles->extractTo($devPath, NULL, TRUE); } catch (\Exception $e) { \IPS\Log::i(\LOG_ERR)->write('Error : ' . $e->getMessage() . "\n" . $e->getTraceAsString(), 'devpackager_error'); } }
/** * Dynamic AdminCP menu generator for extensions * * @return array */ public function acpMenu() { $extensions = \IPS\faker\Faker::allExtensions(); $menu = array(); foreach ($extensions as $key => $extension) { $splitKey = explode('_', $key); /* What app is this extension for? */ $app = property_exists($extension, 'app') ? $extension::$app : implode('_', array_slice($splitKey, 0, -1)); /* Make sure the application is enabled */ if (!\IPS\Application::appIsEnabled($app)) { continue; } /* Do we need to create a new category for this app? */ if (!isset($menu[$app])) { $menu[$app] = array(); } $extName = implode('_', array_slice($splitKey, 1)); $menu[$app][$extName] = array('tab' => 'faker', 'controller' => $extension::$_controller, 'do' => "manage&module=generator&extApp={$app}&extension={$extName}", 'restriction' => $extension::$acpRestriction); } /* Append any misc. modules we want to display here */ $origMenu = parent::acpMenu(); $menu['tools'] = $origMenu['tools']; return $menu; }
/** * Retrieve generator extensions * * @param string|null $generator The generator to retrieve extensions for, or NULL to retrieve all generators * @return array */ public static function allExtensions($generator = NULL) { /* Fetching extensions for a specific generator or all generators? */ if ($generator === NULL) { $rawExtensions = array_merge(\IPS\Application::allExtensions('faker', static::NODES), \IPS\Application::allExtensions('faker', static::ITEMS), \IPS\Application::allExtensions('faker', static::COMMENTS), \IPS\Application::allExtensions('faker', static::ACTIVERECORDS)); } else { $rawExtensions = \IPS\Application::allExtensions('faker', $generator); } /* Update keys for extensions with explicitly defined apps */ $extensions = array(); foreach ($rawExtensions as $key => $extension) { if (property_exists($extension, 'app')) { $splitKey = explode('_', $key); $splitKey = array($extension::$app, end($splitKey)); $key = implode('_', $splitKey); } $extensions[$key] = $extension; } return $extensions; }