コード例 #1
0
ファイル: index.php プロジェクト: bearcms/bearframework-addon
$app->components->addAlias('bearcms-heading-element', 'file:' . $context->dir . '/components/bearcmsHeadingElement.php');
$app->components->addAlias('bearcms-text-element', 'file:' . $context->dir . '/components/bearcmsTextElement.php');
$app->components->addAlias('bearcms-link-element', 'file:' . $context->dir . '/components/bearcmsLinkElement.php');
$app->components->addAlias('bearcms-video-element', 'file:' . $context->dir . '/components/bearcmsVideoElement.php');
$app->components->addAlias('bearcms-image-element', 'file:' . $context->dir . '/components/bearcmsImageElement.php');
$app->components->addAlias('bearcms-image-gallery-element', 'file:' . $context->dir . '/components/bearcmsImageGalleryElement.php');
$app->components->addAlias('bearcms-navigation-element', 'file:' . $context->dir . '/components/bearcmsNavigationElement.php');
$app->components->addAlias('bearcms-html-element', 'file:' . $context->dir . '/components/bearcmsHtmlElement.php');
$app->components->addAlias('bearcms-blog-posts-element', 'file:' . $context->dir . '/components/bearcmsBlogPostsElement.php');
$context->assets->addDir('assets');
$app->container->set('bearCMS', \BearCMS::class);
Options::set($app->addons->get('bearcms/bearframework-addon')['options']);
$app->hooks->add('initialized', function () use($app) {
    // Load the CMS managed addons
    if (Options::hasFeature('ADDONS')) {
        $addons = InternalData\Addons::getList();
        foreach ($addons as $addonData) {
            $addonID = $addonData['id'];
            $addonDir = Options::$addonsDir . DIRECTORY_SEPARATOR . $addonID . DIRECTORY_SEPARATOR;
            if (is_file($addonDir . 'autoload.php')) {
                include $addonDir . 'autoload.php';
            } else {
                throw new Exception('Cannot find autoload.php file for ' . $addonID);
            }
            if (\BearFramework\Addons::exists($addonID)) {
                $_addonData = \BearFramework\Addons::get($addonID);
                $_addonOptions = $_addonData['options'];
                if (isset($_addonOptions['bearCMS']) && is_array($_addonOptions['bearCMS']) && isset($_addonOptions['bearCMS']['assetsDirs']) && is_array($_addonOptions['bearCMS']['assetsDirs'])) {
                    foreach ($_addonOptions['bearCMS']['assetsDirs'] as $dir) {
                        if (is_string($dir)) {
                            $app->assets->addDir($addonDir . $dir);
コード例 #2
0
 /**
  * 
  * @param array $data
  * @return array
  * @throws \Exception
  */
 static function addon($data)
 {
     $app = App::$instance;
     if (!isset($data['id'])) {
         throw new \Exception('');
     }
     if (\BearFramework\Addons::exists($data['id'])) {
         $addonData = [];
         $addonData['id'] = $data['id'];
         $result = $app->data->get(['key' => 'bearcms/addons/addon/' . md5($data['id']) . '.json', 'result' => ['key', 'body']]);
         if (isset($result['body'])) {
             $temp = json_decode($result['body'], true);
             $addonData['enabled'] = isset($temp['enabled']) ? (int) $temp['enabled'] > 0 : false;
             $optionsValues = isset($temp['options']) ? $temp['options'] : [];
         } else {
             $addonData['enabled'] = false;
             $optionsValues = [];
         }
         $includeOptions = isset($data['includeOptions']) && !empty($data['includeOptions']);
         $addonManifestData = \BearCMS\Internal\Data\Addons::getManifestData($data['id']);
         if (is_array($addonManifestData)) {
             $addonData['hasOptions'] = isset($addonManifestData['options']) && !empty($addonManifestData['options']);
             if ($includeOptions) {
                 $addonData['options'] = [];
                 $addonData['options']['definition'] = isset($addonManifestData['options']) ? $addonManifestData['options'] : [];
                 $addonData['options']['values'] = $optionsValues;
                 $addonData['options']['valid'] = \BearCMS\Internal\Data\Addons::validateOptions($addonData['options']['definition'], $addonData['options']['values']);
             }
             unset($addonManifestData['options']);
             $addonData = array_merge($addonData, $addonManifestData);
         } else {
             $addonData['hasOptions'] = false;
             if ($includeOptions) {
                 $addonData['options'] = [];
                 $addonData['options']['definition'] = [];
                 $addonData['options']['values'] = [];
                 $addonData['options']['valid'] = true;
             }
         }
         return $addonData;
     }
     return null;
 }