/*::::::::::::::::::::::::::::::::::::::::::
509716
function getbytes($l)
	{
		for($i = 0; $i < $l; $i++)
		{
			if($this->mod == 'C_FILE')
			{
        		$bin = unpack('C*', fread($this->fin, 1));
        		$this->buffer[$i] = $bin[1];
        	}
        	else if($this->mod == 'C_MEMORY')
        	{
                $bin = unpack('C*', substr($this->fin, $this->ch, 1));
                $this->buffer[$i] = $bin[1];
                $this->ch++;
        	}
		}
		return $this->buffer;
	}
429831
public function init()
    {
        /**
         * 设置默认时区
         */
        if ($this->timezone)
        {
            date_default_timezone_set($this->timezone);
        }

        /**
         * 设置地区信息（地域信息）
         */
        if ($this->locale)
        {
            setlocale(LC_ALL, $this->locale);
        }

        if ($this->charset && function_exists('mb_internal_encoding'))
        {
            mb_internal_encoding($this->charset);
        }

        /**
         * 当输入字符的编码是无效的，或者字符代码不存在于输出的字符编码中时，可以为其指定一个替代字符。
         *
         * @link http://www.php.net/manual/function.mb-substitute-character.php
         */
        mb_substitute_character('none');

        // 确保输入的数据安全
        $_GET = Security::sanitize($_GET);
        $_POST = Security::sanitize($_POST);
        $_COOKIE = Security::sanitize($_COOKIE);

        self::cleanComponents();
    }
277510
public function create()
    {
        $autoIncrementField = $this->getAutoIncrementField();
        if ($autoIncrementField && $this->$autoIncrementField === null) {
            $this->$autoIncrementField = $this->getNextAutoIncrementId();
        }

        $fields = $this->getFields();
        foreach ($this->getAutoFilledData(self::OP_CREATE) as $field => $value) {
            /** @noinspection NotOptimalIfConditionsInspection */
            if (!in_array($field, $fields, true) || $this->$field !== null) {
                continue;
            }
            $this->$field = $value;
        }

        $this->validate($fields);

        $this->eventsManager->fireEvent('model:beforeSave', $this);
        $this->eventsManager->fireEvent('model:beforeCreate', $this);

        $fieldValues = [];
        $defaultValueFields = [];
        foreach ($fields as $field) {
            if ($this->$field !== null) {
                $fieldValues[$field] = $this->$field;
            } elseif ($field !== $autoIncrementField) {
                $defaultValueFields[] = $field;
            }
        }

        foreach ($this->getJsonFields() as $field) {
            if (is_array($this->$field)) {
                $fieldValues[$field] = json_encode($this->$field, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
            }
        }

        /**
         * @var \ManaPHP\DbInterface $connection
         */
        $connection = $this->_di->getShared($this->getDb($this));

        if ($autoIncrementField && $this->$autoIncrementField === null) {
            $this->$autoIncrementField = (int)$connection->insert($this->getSource($this), $fieldValues, true);
        } else {
            $connection->insert($this->getSource($this), $fieldValues);
        }

        if ($defaultValueFields) {
            if ($r = static::query(null, $this)->select($defaultValueFields)->where($this->_getPrimaryKeyValuePairs())->fetch(true)) {
                foreach ($r[0] as $field => $value) {
                    $this->$field = $value;
                }
            }
        }

        $this->_snapshot = $this->toArray();

        $this->eventsManager->fireEvent('model:afterCreate', $this);
        $this->eventsManager->fireEvent('model:afterSave', $this);

        return $this;
    }
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();
    }
132156
public function initialize()
    {
        if ($this->initialized === false) {
            $this->data = $this->cursor->toArray();
        }
        $this->initialized = true;
    }
257868
public function process()
    {
        parent::process();

        if ($this->value === null) {
            $this->path = array();
        } else {
            $this->path = $this->value;
            $this->value = end($this->path);
        }
    }
650442
public function init()
    {
        $this->header('Content-Type: text/html'); // default header.

        $this->proc = new \PHPDaemon\Core\ShellCommand();
        $this->proc->readPacketSize = $this->appInstance->readPacketSize;
        $this->proc->onReadData([$this, 'onReadData']);
        $this->proc->onWrite([$this, 'onWrite']);
        $this->proc->binPath = $this->appInstance->binPath;
        $this->proc->chroot = $this->appInstance->chroot;

        if (isset($this->attrs->server['BINPATH'])) {
            if (isset($this->appInstance->binAliases[$this->attrs->server['BINPATH']])) {
                $this->proc->binPath = $this->appInstance->binAliases[$this->attrs->server['BINPATH']];
            } elseif ($this->appInstance->config->allowoverridebinpath->value) {
                $this->proc->binPath = $this->attrs->server['BINPATH'];
            }
        }

        if (isset($this->attrs->server['CHROOT']) && $this->appInstance->config->allowoverridechroot->value) {
            $this->proc->chroot = $this->attrs->server['CHROOT'];
        }

        if (isset($this->attrs->server['SETUSER']) && $this->appInstance->config->allowoverrideuser->value) {
            $this->proc->setUser = $this->attrs->server['SETUSER'];
        }

        if (isset($this->attrs->server['SETGROUP']) && $this->appInstance->config->allowoverridegroup->value) {
            $this->proc->setGroup = $this->attrs->server['SETGROUP'];
        }

        if (isset($this->attrs->server['CWD']) && $this->appInstance->config->allowoverridecwd->value) {
            $this->proc->cwd = $this->attrs->server['CWD'];
        } elseif ($this->appInstance->config->cwd->value !== null) {
            $this->proc->cwd = $this->appInstance->config->cwd->value;
        } else {
            $this->proc->cwd = dirname($this->attrs->server['SCRIPT_FILENAME']);
        }

        $this->proc->setArgs([$this->attrs->server['SCRIPT_FILENAME']]);
        $this->proc->setEnv($this->attrs->server);
        $this->proc->execute();
    }
98668
public function init() {
		if(empty($this->options))
			$this->options['minLength'] = 1;
		$this->registerClientScript();
		
		if(!isset($this->htmlOptions['class']) || empty($this->htmlOptions['class']))
			$this->htmlOptions['class'] = 'typeahead';
		else
			$this->htmlOptions['class'] .= ' typeahead';
		
		parent::init();
	}
968454
function () {
        var value = this.valueOf();

        // returns empty string if the value is
        // null or undefined or does not implement a toString
        return (!_.isNil(value) && _.isFunction(value.toString)) ? value.toString() : E;
    }
747808
public function init(): void
    {
        parent::init();

        if ($this->default !== '' && $this->default !== null && !is_array($this->default)) {
            try {
                $default = Json::decode($this->default);

                if (is_array($default)) {
                    $this->default = $default;
                }
            } catch (InvalidArgumentException $exception) {}
        }
    }
935544
public function process()
    {
        // {{{ defines the xhtml template

        static $xhtml_template = '';

        if ($xhtml_template == '') {
            $doctype =
                '<!DOCTYPE html PUBLIC ' .
                '"-//W3C//DTD XHTML 1.0 Strict//EN" ' .
                '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' .
                "\n";

            $xhtml_template =
                $doctype .
                <<<XHTML
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		<title>SwatXHTMLTextarea Content</title>
	</head>
	<body>
		<div>
		%s
		</div>
	</body>
</html>

XHTML;
        }

        // }}}

        parent::process();

        $ignore_validation_errors =
            $this->allow_ignore_validation_errors &&
            $this->ignore_errors_checkbox->value;

        $xhtml_content = sprintf($xhtml_template, $this->getXHTMLContent());

        $errors = libxml_use_internal_errors(true);

        $document = new DOMDocument();
        $document->loadXML(
            $xhtml_content,
            LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID
        );

        $xml_errors = libxml_get_errors();
        libxml_clear_errors();
        libxml_use_internal_errors($errors);

        if (count($xml_errors) > 0 && !$ignore_validation_errors) {
            $this->addMessage($this->getValidationErrorMessage($xml_errors));
            $this->has_validation_errors = true;
        }
    }
627938
public function bootstrap(): void
    {
        foreach ($this->bootstrap as $mixed) {
            $component = null;
            if ($mixed instanceof \Closure) {
                $this->debug('Bootstrap with Closure', __METHOD__);
                if (empty($component = call_user_func($mixed, $this))) {
                    continue;
                }
            } elseif (is_string($mixed)) {
                if ($this->has($mixed)) {
                    $component = $this->get($mixed);
                } elseif ($this->hasModule($mixed)) {
                    $component = $this->getModule($mixed);
                } elseif (strpos($mixed, '\\') === false) {
                    throw new InvalidConfigException("Unknown bootstrapping component ID: $mixed");
                }
            }

            if (!isset($component)) {
                $component = $this->createObject($mixed);
            }

            if ($component instanceof BootstrapInterface) {
                $this->debug('Bootstrap with ' . get_class($component) . '::bootstrap()', __METHOD__);
                $component->bootstrap($this);
            } else {
                $this->debug('Bootstrap with ' . get_class($component), __METHOD__);
            }
        }
    }
583835
public function main()
    {
        // INIT
        $this->metaTagList = array();

        $this->initialize();

        $sysLanguageId = 0;
        if (!empty($this->tsSetup['config.']['sys_language_uid'])) {
            $sysLanguageId = $this->tsSetup['config.']['sys_language_uid'];
        }

        // Init News extension
        $this->initExtensionSupport();

        if ($this->tsSetupSeo) {
            $this->collectMetaDataFromPage();
            $customMetaTagList = $this->collectMetaDataFromConnector();

            // #####################################
            // Blacklists
            // #####################################

            // Check search engine indexing blacklist
            if (!empty($this->tsSetupSeo['robotsIndex.']['blacklist.'])) {
                // Page is blacklisted, set to noindex
                $this->tsSetupSeo['robotsIndex'] = 0;
            }

            // #####################################
            // Process StdWrap List
            // #####################################
            $stdWrapItemList = array(
                'title',
                'description',
                'keywords',
                'copyright',
                'email',
                'author',
                'publisher',
                'distribution',
                'rating',
                'lastUpdate',
            );
            foreach ($stdWrapItemList as $key) {
                $this->tsSetupSeo[$key] = $this->applyStdWrap($key, $this->tsSetupSeo[$key]);
            }

            // Call hook
            GeneralUtility::callHookAndSignal(
                __CLASS__,
                'metatagSetup',
                $this,
                $this->tsSetupSeo
            );

            // standard metatags
            $this->generateStandardMetaTags();

            // crawler (eg. robots)
            $this->generateCrawlerMetaTags();

            // geo position
            $this->generateGeoPosMetaTags();

            // services (eg. google plus)
            $this->generateServicesMetaTags();

            // user agent stuff
            $this->generateUserAgentMetaTags();

            // Link meta tags (eg. prev, next...)
            if (!empty($this->tsSetupSeo['linkGeneration'])) {
                $this->generateLinkMetaTags();
            }

            // canonical url
            $this->generateCanonicalUrlMetaTags();

            // OpenGraph
            if (!empty($this->tsSetupSeo['opengraph']) && !empty($this->tsSetupSeo['opengraph.'])) {
                $this->generateOpenGraphMetaTags();
            }

            // Advanced meta tags
            $this->advMetaTags($this->metaTagList, $this->pageRecord, $sysLanguageId, $customMetaTagList);
        }

        // #################
        // SOCIAL
        // #################
        if (!empty($this->tsSetup['plugin.']['metaseo.']['social.'])) {
            $this->tsSetupSeo = $this->tsSetup['plugin.']['metaseo.']['social.'];

            if (!empty($this->tsSetupSeo['googlePlus.']['profilePageId'])) {
                $this->metaTagList['social.googleplus.direct-connect'] = array(
                    'tag'        => 'link',
                    'attributes' => array(
                        'rel'  => 'publisher',
                        'href' => 'https://plus.google.com/' . $this->tsSetupSeo['googlePlus.']['profilePageId'],
                    ),
                );
            }
        }

        $this->processMetaTags($this->metaTagList);

        return $this->renderMetaTags($this->metaTagList);
    }
803308
public function validate() {
		parent::validate();

		if ($this->getId() === null) {
			throw new ValidationException("'id' can't be null", 'id', $this);
		}
		if ($this->getVersion() === null) {
			throw new ValidationException("'version' can't be null", 'version', $this);
		}
	}
466075
public function index() {            
        HookProvider::getInstance()->updateHooks();
        
        $action = Filter::post('action');        
        if($action == 'update' && Filter::checkCsrf()) $this->update();
        
        Theme::theme(new AdministrationTheme)->init(Globals::getTree());        
        $ctrl = new PageController();
        $ctrl
            ->restrictAccess(Auth::isAdmin())
            ->setPageTitle($this->module->getTitle());
        
        $table_id = 'table-installedhooks-' . Uuid::uuid4();

        $view_bag = new ViewBag();
        $view_bag->set('title', $ctrl->getPageTitle());
        $view_bag->set('table_id', $table_id);
        $view_bag->set('hook_list', HookProvider::getInstance()->getRawInstalledHooks());
        
        $ctrl
        ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
        ->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL)
        ->addInlineJavascript('
		  	jQuery(document).ready(function() {
				jQuery("#'.$table_id.'").dataTable( {
					'.I18N::datatablesI18N().',		
					sorting: [[ 2, "asc" ], [ 3, "asc" ]],
					displayLength: 10,
					pagingType: "full_numbers",
					columns: [
						/* 0 Enabled 		*/	{ dataSort: 1, class: "center" },
						/* 1 Enabled sort	*/	{ visible: false},
						/* 2 Hook function	*/	null,
						/* 3 Hook context	*/	null,
						/* 4 Module name	*/	null,
						/* 5 Priority		*/	{ dataSort: 6, class: "center" },
						/* 6 Priority sort	*/	{ type: "num", visible: false}
					]
			  });
			});
		');
        
        ViewFactory::make('AdminConfig', $this, $ctrl, $view_bag)->render();
    }
651532
public function execute()
    {
        $out = '';

        $topic = isset($this->getParseResult()->command->args['topic'])
               ? $this->getParseResult()->command->args['topic'] : null;
        if (null === $topic) {
            $out = $this->getUsageHelp();
        } else {
            $out = $this->getTopicHelp($topic);
        }

        $this->out($this->getHeader());
        $this->out($out);
        $this->out($this->getFooter());
    }
1239169
public function init()
    {
        parent::init();
        $db = $this->getDb();
        if (!isset($this->options['user'])) {
            $this->options['user'] = $db->username;
        }
        if (!isset($this->options['password'])) {
            $this->options['password'] = $db->password;
        }
        $parsed = $this->parseConnectionString($db->connectionString);
        if (!isset($this->options['host'])) {
            $this->options['host'] = $parsed['hostName'];
        }
        if (!isset($this->options['port']) && isset($parsed['port'])) {
            $this->options['port'] = $parsed['port'];
        }
    }