/** * Get a class map for all enabled Faker extensions * * @return string[] */ protected function getContentTypes() { $extensions = \IPS\faker\Faker::allExtensions(); $contentMap = array(); foreach ($extensions as $extension) { $reflect = new \ReflectionClass($extension); $contentMap[$extension::$class] = "menu__faker_{$extension::$app}_" . $reflect->getShortName(); } return $contentMap; }
/** * Load the Comments extension for this Item * * @return mixed The extension if it exists, otherwise NULL */ protected function commentExt() { /* Return the extension if it has already been loaded */ if ($this->_commentExtension) { return $this->_commentExtension; } $extensions = \IPS\faker\Faker::allExtensions(\IPS\faker\Faker::COMMENTS); /* Do we have an explicitly defined app for the Comment extension? */ $app = static::$app; $commentExtension = static::$commentExtension; if (is_array($commentExtension)) { $app = $commentExtension[0]; $commentExtension = $commentExtension[1]; } /* Return the extension if it exists */ if (isset($extensions[$app . '_' . $commentExtension])) { return $this->_commentExtension = $extensions[$app . '_' . $commentExtension]; } return NULL; }
/** * Get request extension data * * @return array Extension object, app name, extension name */ protected function extData() { /* Return pre-generated extension data if we have it */ if ($this->extData) { return $this->extData; } /* Make sure our extension app and extension name have been defined */ if (!($extApp = \IPS\Request::i()->extApp) or !($extension = \IPS\Request::i()->extension)) { \IPS\Output::i()->error('generic_error', '3FAKE108/1', 400); return array(); } /* Try and fetch the requested extension or display a generic 404 error if we can't find it */ try { $extensions = \IPS\faker\Faker::allExtensions(constant('\\IPS\\faker\\Faker::' . mb_strtoupper(static::$controller))); $ext = $extensions[\IPS\Request::i()->extApp . '_' . \IPS\Request::i()->extension]; } catch (\Whoops\Exception\ErrorException $e) { \IPS\Output::i()->error('node_error', '2FAKE108/2', 404); return array(); } return $this->extData = array($ext, $extApp, $extension, static::$controller); }
/** * 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; }