Initialize plugin.

@access public
@return void
340720
public function init()
    {
        craft()->on('assets.onSaveAsset', function (Event $event) {
            $this->copyAsset($event->params['asset']);
        });

        craft()->on('assets.onReplaceFile', function (Event $event) {
            $this->copyAsset($event->params['asset']);
        });

        craft()->on('assets.onBeforeDeleteAsset', function (Event $event) {
            $this->deleteAsset($event->params['asset']);
        });
    }
366909
public function initialize()
    {
        parent::initialize();

        //Sets the theme from configuration
        if (getConfig('default.theme')) {
            $this->setTheme(getConfig('default.theme'));
        }

        //Loads helpers
        $this->loadHelper('Html', ['className' => 'MeTools.Html']);
        $this->loadHelper('MeTools.Dropdown');
        $this->loadHelper('MeTools.Form');
        $this->loadHelper('MeTools.Library');
        $this->loadHelper('MeTools.Paginator');
        $this->loadHelper('Assets.Asset');
        $this->loadHelper('Thumber.Thumb');
        $this->loadHelper('WyriHaximus/MinifyHtml.MinifyHtml');
    }
1361205
public function init()
    {
        parent::init();

        self::$plugin = $this;

        // Register services
        $this->setComponents([
            'imager' => ImagerService::class,
            'placeholder' => PlaceholderService::class,
            'color' => ImagerColorService::class,
            'imgix' => ImgixService::class,
        ]);

        // Add our Twig extensions
        Craft::$app->view->registerTwigExtension(new ImagerTwigExtension());

        /** @var ConfigModel $settings */
        $config = ImagerService::getConfig();

        // Register our variables
        Event::on(CraftVariable::class, CraftVariable::EVENT_INIT,
            function (Event $event) {
                /** @var CraftVariable $variable */
                $variable = $event->sender;
                $variable->set('imager', ImagerVariable::class);
            }
        );

        // Adds Imager paths to the list of things the Clear Caches tool can delete
        Event::on(ClearCaches::class, ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
            function (RegisterCacheOptionsEvent $event) {
                $event->options[] = [
                    'key' => 'imager-transform-cache',
                    'label' => Craft::t('imager', 'Imager image transform cache'),
                    'action' => FileHelper::normalizePath(ImagerService::getConfig()->imagerSystemPath)
                ];
                $event->options[] = [
                    'key' => 'imager-remote-images-cache',
                    'label' => Craft::t('imager', 'Imager remote images cache'),
                    'action' => FileHelper::normalizePath(Craft::$app->getPath()->getRuntimePath() . '/imager/')
                ];
            }
        );

        // Register element action to assets for clearing transforms
        Event::on(Asset::class, Element::EVENT_REGISTER_ACTIONS,
            function (RegisterElementActionsEvent $event) use ($config) {
                $event->actions[] = ClearTransformsElementAction::class;
                // If Imgix purging is possible, add element action for purging – unless the element action is disabled
                if ($config->imgixEnablePurgeElementAction && ImgixService::getCanPurge()) {
                    $event->actions[] = ImgixPurgeElementAction::class;
                }
            }
        );

        // Event listener for clearing caches when an asset is replaced
        Event::on(Assets::class, Assets::EVENT_AFTER_REPLACE_ASSET,
            function (ReplaceAssetEvent $event) use ($config) {
                if ($event->asset) {
                    self::$plugin->imager->removeTransformsForAsset($event->asset);
                    // If Imgix purging is possible, do that too
                    if ($config->imgixEnableAutoPurging && ImgixService::getCanPurge()) {
                        self::$plugin->imgix->purgeAssetFromImgix($event->asset);
                    }
                }
            }
        );

        // Event listener for overriding Craft's internal transform functionality
        Event::on(Assets::class, Assets::EVENT_GET_ASSET_URL,
            function (GetAssetUrlEvent $event) {
                $config = ImagerService::getConfig();

                if ($config->useForNativeTransforms && $event->asset !== null && $event->transform !== null && $event->asset->kind === 'image' && \in_array(strtolower($event->asset->getExtension()), Image::webSafeFormats(), true)) {
                    try {
                        $transform = $event->transform;

                        // Transform is an AssetTransform 
                        if ($transform instanceof AssetTransform) {
                            $transform = ImagerHelpers::normalizeAssetTransformToObject($transform);
                        }

                        // Transform is a named asset transform
                        if (is_string($event->transform)) {
                            $assetTransform = Craft::$app->getAssetTransforms()->getTransformByHandle($transform);

                            if ($assetTransform) {
                                $transform = ImagerHelpers::normalizeAssetTransformToObject($assetTransform);
                            } else {
                                Craft::error('Unknown asset transform handle supplied to native transform', __METHOD__);
                                $transform = [];
                            }
                        }

                        $transformedImage = self::$plugin->imager->transformImage($event->asset, $transform);

                        if ($transformedImage !== null) {
                            $event->url = $transformedImage->url;
                        }
                    } catch (ImagerException $e) {
                        return null;
                    }
                }
            }
        );

        // Event listener for overriding Craft's internal thumb url
        Event::on(Assets::class, Assets::EVENT_GET_ASSET_THUMB_URL,
            function (GetAssetThumbUrlEvent $event) {
                $config = ImagerService::getConfig();

                if ($config->useForCpThumbs && $event->asset !== null && $event->asset->kind === 'image' && \in_array(strtolower($event->asset->getExtension()), Image::webSafeFormats(), true)) {
                    try {
                        /** @var CraftTransformedImageModel|ImgixTransformedImageModel $transformedImage */
                        $transformedImage = self::$plugin->imager->transformImage($event->asset, ['width' => $event->width, 'height' => $event->height, 'mode' => 'fit']);

                        if ($transformedImage !== null) {
                            $event->url = $transformedImage->url;
                        }
                    } catch (ImagerException $e) {
                        // just ignore
                    }
                }
            }
        );

        // Register built-in effects
        $this->registerEffects();

        // Register built-in optimizers
        $this->registerOptimizers();

        // Register built-in external storage options
        $this->registerExternalStorages();
    }
2193
public function init()
    {
        parent::init();
        self::$plugin = $this;

        $this->setComponents([
            'campaignmonitor' => \clearbold\cmservice\services\CampaignMonitorService::class,
        ]);

        Craft::info(
            Craft::t(
                'cm-service',
                '{name} plugin loaded',
                ['name' => $this->name]
            ),
            __METHOD__
        );
    }
662270
public function init()
	{
		parent::init();

		self::$plugin = $this;

		$requestService = Craft::$app->getRequest();

		$this->setComponents([
            'methods' => Service::class,
        ]);

		$this->_configureTemplateVariable();

		if ($requestService->getIsCpRequest())
		{
			$this->_configureCpResources();
			$this->_configureAssetThumbnails();
			$this->_configureAssetIndexAttributes();
		}
	}
792708
private static function init()
    {
        if (!self::$data_initialized) {
            self::$data_initialized = true;

            $page_components_collection = new PageComponentEntityRepository();
            $page_components_collection->setWherePageId(PAGE_ID);
            $page_components_collection->addWhereFieldIsLike('component', 'select_plugin');
            if (Settings::isCacheEnabled()) {
                $page_components_collection->enableUsingCache();
            }

            self::$data = $page_components_collection->getPairs('data', 'component');
        }
    }
675858
public function init()
    {
        parent::init();

        Html::addCssClass($this->carouselOptions, ['plugin' => 'carousel']);
        if ($this->fullWidth) {
            Html::addCssClass($this->carouselOptions, ['fullwidth' => 'carousel-slider']);
            $this->clientOptions['fullWidth'] = true;
        }

        $this->clientOptions['noWrap'] = $this->noWrap;
        $this->clientOptions['indicators'] = $this->showIndicators;
        $this->clientOptions['duration'] = $this->duration;
        $this->clientOptions['dist'] = $this->perspectiveZoom;
        $this->clientOptions['shift'] = $this->centerSpacing;
        $this->clientOptions['padding'] = $this->padding;
        $this->clientOptions['numVisible'] = $this->visibleItems;

        $this->registerPlugin('Carousel', '.carousel');
    }
849453
protected function _init()
    {
        if (!parent::_init()) {
            return false;
        }

        if (!Plugin::exists($this->_plugin['name'])) {
            $this->err(__d('installer', 'The plugin "{0}" is not installed, you cannot update a plugin that is not installed in your system.', $this->_plugin['name']));

            return false;
        } else {
            $plugin = plugin($this->_plugin['name']);
            if (!$this->canBeDeleted($plugin->path)) {
                $this->err(__d('installer', 'Unable to update, please check write permissions for "{0}".', $plugin->path));

                return false;
            }
        }

        return true;
    }
903806
public function initialize()
    {
        parent::initialize();
        $this->loadComponent($this->plugin . '.Extension');
        $this->loadModel($this->plugin . '.Extensions');
    }
1262835
public function init()
    {
        parent::init();

        self::$plugin = $this;

        if (!Craft::$app->getRequest()->getIsCpRequest()) {
            return;
        }

        // Register Components (Services)
        $this->setComponents([
            'singlesList' => SinglesList::class,
        ]);

        // Modified the entry index sources
        Event::on(Entry::class, Element::EVENT_REGISTER_SOURCES, function(RegisterElementSourcesEvent $event) {
            
            // Have we enabled the plugin?
            if ($this->getSettings()->expandSingles) {

                // Are there any Singles at all?
                foreach ($event->sources as $source) {
                    if (array_key_exists('key', $source) && $source['key'] === 'singles') {
                        $this->singlesList->createSinglesList($event);
                    }
                }
            }
        });

        // Hook onto a special hook from Redactor - it handles singles a little differently!
        if (class_exists(RedactorField::class)) {
            Event::on(RedactorField::class, RedactorField::EVENT_REGISTER_LINK_OPTIONS, function(RegisterLinkOptionsEvent $event) {
                
                // Have we enabled the plugin?
                if ($this->getSettings()->expandSingles) {

                    foreach ($event->linkOptions as $i => $linkOption) {

                        // Only apply this for entries, and if there are any singles
                        if ($linkOption['refHandle'] === 'entry') {
                            if (in_array('singles', $linkOption['sources'])) {
                                $modifiedSources = $this->singlesList->createSectionedSinglesList($linkOption['sources']);

                                if ($modifiedSources) {
                                    $event->linkOptions[$i]['sources'] = $modifiedSources;
                                }
                            }
                        }
                    }
                }
            });
        }
    }
774507
public function init()
    {
        self::$plugin = $this;

        // ignore console requests
        if ($this->isInstalled && !\Craft::$app->request->getIsConsoleRequest()) {
            $this->setComponents(
                [
                    'htmlcacheService' => HtmlcacheService::class,
                ]
            );
            // first check if there is a cache to serve
            $this->htmlcacheService->checkForCacheFile();

            // after request send try and create the cache file
            Event::on(Response::class, Response::EVENT_AFTER_SEND, function (Event $event) {
                $this->htmlcacheService->createCacheFile();
            });

            // on every update of an element clear the caches related to the element
            Event::on(Elements::class, Elements::EVENT_AFTER_SAVE_ELEMENT, function (Event $event) {
                $this->htmlcacheService->clearCacheFile($event->element->id);
            });

            // on populated element put to relation table
            Event::on(ElementQuery::class, ElementQuery::EVENT_AFTER_POPULATE_ELEMENT, function ($event) {
                // procceed only if it should be created
                if ($this->htmlcacheService->canCreateCacheFile()) {
                    $elementClass = get_class($event->element);
                    if (!in_array($elementClass, [User::class, GlobalSet::class])) {
                        $uri = \Craft::$app->request->getParam('p', '');
                        $siteId = \Craft::$app->getSites()->getCurrentSite()->id;
                        $elementId = $event->element->id;
                        
                        // check if cache entry already exits otherwise create it
                        $cacheEntry = HtmlCacheCache::findOne(['uri' => $uri, 'siteId' => $siteId]);
                        if (!$cacheEntry) {
                            $cacheEntry = new HtmlCacheCache();
                            $cacheEntry->id = null;
                            $cacheEntry->uri = $uri;
                            $cacheEntry->siteId = $siteId;
                            $cacheEntry->save();
                        }
                        // check if relation element is already added or create it
                        $cacheElement = HtmlCacheElement::findOne(['elementId' => $elementId, 'cacheId' => $cacheEntry->id]);
                        if (!$cacheElement) {
                            $cacheElement = new HtmlCacheElement();
                            $cacheElement->elementId = $elementId;
                            $cacheElement->cacheId = $cacheEntry->id;
                            $cacheElement->save();
                        }
                    }
                }
            });

            // always reset purge cache value
            Event::on(Plugin::class, Plugin::EVENT_BEFORE_SAVE_SETTINGS, function ($event) {
                if ($event->sender === $this) {
                    $settings = $event->sender->getSettings();
                    if ($settings->purgeCache === '1') {
                        $this->htmlcacheService->clearCacheFiles();
                    }
                    // always reset value for purge cache
                    $event->sender->setSettings(['purgeCache' => '']);
                }
            });
        }
        
        // After install create the temp folder
        Event::on(
            Plugins::class,
            Plugins::EVENT_AFTER_INSTALL_PLUGIN,
            function (PluginEvent $event) {
                if ($event->plugin === $this) {
                    // create cache directory
                    $path = \Craft::$app->path->getStoragePath() . DIRECTORY_SEPARATOR . 'runtime' . DIRECTORY_SEPARATOR . 'htmlcache' . DIRECTORY_SEPARATOR;
                    FileHelper::createDirectory($path);
                }
            }
        );

        // Before uninstall clear all cache
        Event::on(
            Plugins::class,
            Plugins::EVENT_BEFORE_UNINSTALL_PLUGIN,
            function (PluginEvent $event) {
                if ($event->plugin === $this) {
                    // clear all files
                    $this->htmlcacheService->clearCacheFiles();
                }
            }
        );

        // After uninstall remove the cache dir
        Event::on(
            Plugins::class,
            Plugins::EVENT_AFTER_UNINSTALL_PLUGIN,
            function (PluginEvent $event) {
                if ($event->plugin === $this) {
                    // remove htmlcache dir
                    $path = \Craft::$app->path->getStoragePath() . DIRECTORY_SEPARATOR . 'runtime' . DIRECTORY_SEPARATOR . 'htmlcache' . DIRECTORY_SEPARATOR;
                    FileHelper::removeDirectory($path);
                }
            }
        );
        parent::init();
    }
947053
public function init()
    {

		parent::init();
		self::$plugin = $this;

		Craft::$app->getView()->registerTwigExtension(new EnvironmentLabelTwigExtension());

		Event::on(
			View::class,
			View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE,
			function (Event $event) {
				EnvironmentLabel::$plugin->label->doItBaby();
			}
		);

    }
1216916
public function init()
    {
        $this->loadResources();
        $this->prepRequestData();

        // initialize the output component by loading it, the component will register
        // handlers on construction
        $this["output.service"];

        $this["logger.service"]("System")->info("Application initialized");

        $this["hooks.service"]->setParams([$this]);
        $this["hooks.service"]->exec("application.init.after");
    }
1214445
private function initialize() {
        $CI = get_instance();
        $CI->config->load('dwootemplate', TRUE);
        $config = $CI->config->item('dwootemplate');
        foreach ($config as $key => $val) {
                $this->$key = $val;
        }
    }
586513
private function initialize()
    {
        $this->extension = 'module';
        $this->extensions = [
            'module' => [],
            'theme' => [],
            'profile' => [],
        ];
        $this->filters = [
            'showInstalled' => false,
            'showUninstalled' => false,
            'showCore' => false,
            'showNoCore' => false
        ];
    }
1341721
public function init()
    {
        parent::init();

        self::$plugin = $this;

        $this->_setPluginComponents();
        $this->_setLogging();
        $this->_registerCpRoutes();
        $this->_registerVariables();
        $this->_registerFieldTypes();
        $this->_registerElementTypes();
        $this->_registerIntegrations();
        $this->_registerProjectConfigEventListeners();
    }
1293116
public function init() {
		// run parents to setup sanitization filters
		$data = uix()->request_vars( 'post' );
		if ( isset( $data[ 'uixNonce_' . $this->id() ] ) && wp_verify_nonce( $data[ 'uixNonce_' . $this->id() ], $this->id() ) ) {
			$this->save_data();
		} else {
			// load data normally
			$this->set_data( array( $this->slug => $this->load_data() ) );
		}
		// set the wrapper element based on static or not
		if ( ! empty( $this->struct['static'] ) ) {
			$this->element = 'div';
		}
	}