This is only used for exported widgets
@return string
@throws Exception
@throws \Piwik\NoAccessException
488484
public function renderWidgetContainer()
    {
        Piwik::checkUserHasSomeViewAccess();
        $this->checkSitePermission();

        $view = new View('@CoreHome/widgetContainer');
        $view->isWidgetized = (bool) Common::getRequestVar('widget', 0, 'int');
        $view->containerId  = Common::getRequestVar('containerId', null, 'string');

        return $view->render();
    }
1047974
private function renderWidget()
    {
        $img = $this->getImageSource();

        echo "<div>$img</div>";

        if ($this->link || is_string($this->link)) {
            echo Html::a($this->link, $this->otp->getProvisioningUri());
        }

        if ($this->hasModel()
            && $this->model->hasProperty($this->attribute)
            && empty($this->model->{$this->attribute})
        ) {
            $this->model->setAttributes([$this->attribute => $this->otp->getSecret()]);
        }
        echo Html::activeHiddenInput($this->model, $this->attribute, $this->options);
    }
1229232
public function renderWidget()
    {
        $items = [];
        foreach ($this->items as $item) {
            $appkey = $this->getShareKey($item);
            $name = self::t(ArrayHelper::getValue($this->shareMapping, $item));
            $icon = Html::tag('i', '', ['class' => "fa fa-{$this->icon_size} fa-{$item} share-{$item}", 'aria-hidden' => 'true']);
            $link = Html::a($icon, 'javascript:void(0);', [
                'data' => ['toggle' => 'tooltip', 'placement' => 'top', 'original-title' => self::t('Share to {name}', ['name' => $name])]
            ]);
            $items[] = Html::tag('li', $link, ['data' => ['network' => $item, 'appkey' => $appkey]]);
        }
        return Html::tag('ul', implode("\n", $items), $this->itemOptions);
    }
1079497
public function checkUserHasSomeViewAccess()
    {
        if ($this->hasSuperUserAccess()) {
            return;
        }

        $idSitesAccessible = $this->getSitesIdWithAtLeastViewAccess();

        if (count($idSitesAccessible) == 0) {
            throw new NoAccessException(Piwik::translate('General_ExceptionPrivilegeAtLeastOneWebsite', array('view')));
        }
    }
302923
public function output()
    {
        $output = $this->outputType();
        switch ($output) {
            case static::PROPERTY_DISPLAY:
                $type   = $this->displayType();
                $prop   = $this->display();
                $getter = 'displayId';
                $setter = 'setDisplayId';
                break;

            case static::PROPERTY_CONTROL:
                $type   = $this->inputType();
                $prop   = $this->input();
                $getter = 'inputId';
                $setter = 'setInputId';
                break;
        }

        $GLOBALS['widget_template'] = $type;

        if ($this->l10n() && $this->loopL10n()) {
            $locales  = $this->translator()->availableLocales();
            $outputId = $prop->{$getter}();
            foreach ($locales as $langCode) {
                // Set a unique property output ID for each locale.
                $prop->{$setter}($outputId.'_'.$langCode);
                $prop->setLang($langCode);

                yield $prop;
            }

            $GLOBALS['widget_template'] = '';
            $prop->{$setter}($outputId);
        } else {
            yield $prop;

            $GLOBALS['widget_template'] = '';
        }
    }
951579
public function render()
    {
        try {
            $this->currentModule = Piwik::getModule();
            $this->currentAction = Piwik::getAction();

            $this->url = Common::sanitizeInputValue(Url::getCurrentUrl());
            $this->token_auth = Piwik::getCurrentUserTokenAuth();
            $this->userHasSomeAdminAccess = Piwik::isUserHasSomeAdminAccess();
            $this->userIsAnonymous = Piwik::isUserIsAnonymous();
            $this->userIsSuperUser = Piwik::hasUserSuperUserAccess();
            $this->latest_version_available = UpdateCheck::isNewestVersionAvailable();
            $this->showUpdateNotificationToUser = !SettingsPiwik::isShowUpdateNotificationToSuperUsersOnlyEnabled() || Piwik::hasUserSuperUserAccess();
            $this->disableLink = Common::getRequestVar('disableLink', 0, 'int');
            $this->isWidget = Common::getRequestVar('widget', 0, 'int');
            $this->isMultiServerEnvironment = SettingsPiwik::isMultiServerEnvironment();
            $this->isInternetEnabled = SettingsPiwik::isInternetEnabled();
            $this->shouldPropagateTokenAuth = $this->shouldPropagateTokenAuthInAjaxRequests();

            $piwikAds = StaticContainer::get('Piwik\ProfessionalServices\Advertising');
            $this->areAdsForProfessionalServicesEnabled = $piwikAds->areAdsForProfessionalServicesEnabled();

            if (Development::isEnabled()) {
                $cacheBuster = rand(0, 10000);
            } else {
                $cacheBuster = UIAssetCacheBuster::getInstance()->piwikVersionBasedCacheBuster();
            }
            $this->cacheBuster = $cacheBuster;

            $this->loginModule = Piwik::getLoginPluginName();

            $user = APIUsersManager::getInstance()->getUser($this->userLogin);
            $this->userAlias = $user['alias'];
        } catch (Exception $e) {
            Log::debug($e);

            // can fail, for example at installation (no plugin loaded yet)
        }

        ProxyHttp::overrideCacheControlHeaders('no-store');

        Common::sendHeader('Content-Type: ' . $this->contentType);
        // always sending this header, sometimes empty, to ensure that Dashboard embed loads
        // - when calling sendHeader() multiple times, the last one prevails
        if(!empty($this->xFrameOptions)) {
            Common::sendHeader('X-Frame-Options: ' . (string)$this->xFrameOptions);
        }

        return $this->renderTwigTemplate();
    }
695788
public function renderError()
	{
		$parent=$this->getParent();
		return $parent->getActiveFormWidget()->error($parent->getModel(), $this->name, $this->errorOptions, $this->enableAjaxValidation, $this->enableClientValidation);
	}
1358127
public function widgetOptions()
    {
        $options = [
            'obj_type'           => $this->obj()->objType(),
            'obj_id'             => $this->obj()->id(),
            'group'              => $this->group(),
            'attachment_options' => $this->attachmentOptions(),
            'attachable_objects' => $this->attachableObjects(),
            'title'              => $this->title(),
            'lang'               => $this->translator()->getLocale()
        ];

        return json_encode($options, true);
    }
752569
public function preview()
	{
		$selector = 'ctrl_textarea' . $this->id;

		$strPreview = '<div class="widget" style="padding-top:10px;"><h3 style="margin: 0;"><label>' . $this->label . '</label></h3>';
		$strPreview .= '<textarea id="' . $selector . '" aria-hidden="true" class="tl_textarea noresize" rows="12" cols="80"></textarea>';
		
		// Register all tinyMCE template files
		if (!array_key_exists($this->rteTemplate, TemplateLoader::getFiles()))
		{
			$objFilesystem = new Filesystem();
			
			$arrTemplateFiles = glob(TL_ROOT . '/templates/*/be_tinyMCE*');

			foreach ($arrTemplateFiles as $strFile)
			{
				$arrTemplates[basename($strFile, '.html5')] = rtrim($objFilesystem->makePathRelative(dirname($strFile), TL_ROOT), '/');
			}
			
			if ($arrTemplates !== null)
			{
				TemplateLoader::addFiles($arrTemplates);
			}
		}

		if (array_key_exists($this->rteTemplate, TemplateLoader::getFiles()))
		{
			$objTemplate = new \BackendTemplate($this->rteTemplate);
			$objTemplate->selector = $selector;

			$strPreview .= $objTemplate->parse();
		}
			
		$strPreview .= '<p title="" class="tl_help tl_tip">' . $this->description . '</p></div>';	

		return $strPreview;
	}
269815
public function getExampleFormMarkup()
    {
        $states = $this->getToggleStates();

        $options = array();

        foreach ($states as $handle => $v) {
            $options[] = array($v, null, $v);
        }

        $fieldname = 'fields['.$this->get('element_name').']';

        if ($this->get('allow_multiple_selection') === 'yes') {
            $fieldname .= '[]';
        }

        $label = Widget::Label($this->get('label'));
        $label->appendChild(Widget::Select($fieldname, $options, ($this->get('allow_multiple_selection') === 'yes' ? array('multiple' => 'multiple') : null)));

        return $label;
    }
1011043
function getLayout()
    {
        $layoutName = ($this->layout) ? $this->layout
            : $this->getDefaultLayoutName();

        if (strstr($layoutName, '/') === false) {
            // we have just layout name
            // the directory prefix assigned to it
            $DS = (defined('DS')) ? constant('DS') : DIRECTORY_SEPARATOR;
            // derive default layout pathname
            $pathname =
                self::$PATH_PREFIX               # widgets
                .$DS
                .$this->deriveLayoutPathPrefix() # namespace_widget\widget_name\
                .$DS
                .$layoutName;

            $this->layout = $pathname;
        }

        return $this->layout;
    }
287983
public function GetOutput() {
        $numberOfVarsExtracted = extract($this->variablesList);
        if (count($this->variablesList) !== $numberOfVarsExtracted) {
            $errMsg = "Number of variables extracted different from the $vars array";
            throw new \Exception($errMsg, Codes\LogicErrors::UNEXPECTED_VALUE, null);
        }
        ob_start();
        include_once $this->contentFile;
        $content = ob_get_clean();
        ob_start();
        include_once "APP_ROOT_DIR" . \Puzzlout\Framework\Enums\FrameworkFolderName::ViewsFolderName . \Puzzlout\Framework\Enums\FileNameConst::LayoutTemplate;
        return ob_get_clean();
    }
1152536
public function getMenuHeaderView(): string
    {
        // Outside of authorized area
        if (!defined('USER_ID') || !USER_ID || !defined('LNG')) {
            return '';
        }

        // Show non-default CMS headers
        $cfg = Configuration::getInstance()->get('cms');
        if (isset($cfg['custom_header']) && $cfg['custom_header']) {
            // Need to create this file prior to use
            return include DIR_MODULES . 'cms/Admin/Menu/getMenuHeaderView.php';
        }

        // Notifications from system
        $notification_repository = new UsersMessageEntityRepository;
        $notification_repository
            ->setWhereToUserId(USER_ID)
            ->setWhereFromUserId(0)
            ->addOrderByField('ts', true)
            ->setWhereSeen(0);

        // All count for number
        $total_notifications = $notification_repository->getCountOfObjectsInCollection();

        // Show a few latest
        $notifications = $notification_repository
            ->setLimit(10)
            ->getAsArrayOfObjects();

        // Messages from users
        $messages_repository = new UsersMessageEntityRepository;
        $messages_repository
            ->setWhereToUserId(USER_ID)
            ->addWhereFieldIsNot('from_user_id', 0)
            ->addOrderByField('ts', true)
            ->setWhereSeen(0);

        // All count for number
        $total_messages = $messages_repository->getCountOfObjectsInCollection();

        $messages = $messages_repository
            ->setLimit(10)
            ->getAsArrayOfObjects();

        // Custom notifiers
        $custom_notifiers = [];

        $custom_notifiers[] = $this->getHelpTextsNotifier();

        // Logo image and link
        $logo = '';
        if (array_key_exists('logo', Configuration::getInstance()->get('cms'))) {
            $logo = Configuration::getInstance()->get('cms')['logo'];
        }

        $logo_link = DIR_CMS_URL;
        if (array_key_exists('logo_link', Configuration::getInstance()->get('cms'))) {
            $logo_link = Configuration::getInstance()->get('cms')['logo_link'];
        }

        // User avatar image
        $user_avatar = Users::getInstance()->getUserData('avatar');
        if (!$user_avatar) {
            $user_avatar = '/vendor/devp-eu/tmcms-core/src/assets/cms/layout/img/avatar.png';
        }

        $languages = AdminLanguages::getPairs();

        ob_start();

        ?>
        <div class="page-header-inner">
            <?php if ($logo): ?>
                <div class="page-logo">
                    <a href="<?= $logo_link ?>">
                        <img src="<?= $logo ?>" alt="logo" class="logo-default">
                    </a>

                    <div class="menu-toggler sidebar-toggler"></div>
                </div>
            <?php endif; ?>
            <a href="javascript:" class="menu-toggler responsive-toggler" data-toggle="collapse"
               data-target=".navbar-collapse"></a>

            <div class="top-menu">
                <ul class="nav navbar-nav pull-right">
                    <li class="dropdown dropdown-extended dropdown-home" id="header_home_bar">
                        <a href="/" target="_blank" class="dropdown-toggle" data-hover="dropdown"
                           data-close-others="true">
                            <i class="cms-icon-globe"></i>
                        </a>
                    </li>
                    <?php if (count($languages) > 1): ?>
                        <li class="dropdown dropdown-language">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown"
                               data-close-others="true">
                                <?php if (Settings::get('show_language_selector_flags')): ?>
                                    <img alt=""
                                         src="/vendor/devp-eu/tmcms-core/src/assets/cms/img/flags/<?= LNG ?>.png">
                                <?php endif; ?>
                                <span class="langname"><?= strtoupper(LNG) ?> </span>
                                <i class="fa fa-angle-down"></i>
                            </a>
                            <ul class="dropdown-menu">
                                <?php foreach ($languages as $k => $v):
                                    if ($k == LNG) {
                                        continue;
                                    }
                                    ?>
                                    <li>
                                        <a href="?p=users&do=_change_lng&lng=<?= $k ?>">
                                            <?php if (Settings::get('show_language_selector_flags')): ?>
                                                <img alt=""
                                                     src="/vendor/devp-eu/tmcms-core/src/assets/cms/img/flags/<?= $k ?>.png">
                                            <?php endif; ?>
                                            <?= $v ?>
                                        </a>
                                    </li>
                                <?php endforeach; ?>
                            </ul>
                        </li>
                    <?php endif; ?>
                    <?php if ($notifications): ?>
                        <li class="dropdown dropdown-extended dropdown-notification" id="header_notification_bar">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown"
                               data-close-others="true">
                                <i class="cms-icon-bell"></i>
                                <span class="badge badge-default"><?= count($notifications); ?></span>
                            </a>
                            <ul class="dropdown-menu">
                                <li>
                                    <p>
                                        You have <?= $total_notifications; ?> new notifications
                                    </p>
                                </li>
                                <li>
                                    <ul class="dropdown-menu-list scroller" style="height: 250px;">
                                        <?php foreach ($notifications as $k => $message): /** @var UsersMessageEntity $message */ ?>
                                            <li>
                                                <a href="#">
                                                    <span class="label label-sm label-icon label-warning">
                                                        <i class="fa fa-bell-o"></i>
                                                    </span>
                                                    <?= $message->getMessage() ?>
                                                    <span class="time">
                                                        <?= Converter::getTimeFromEventAgo((int)$message->getTs()) ?>
                                                    </span>
                                                </a>
                                            </li>
                                        <?php endforeach; ?>
                                    </ul>
                                </li>
                                <li class="external">
                                    <a href="?p=home&do=notifications">
                                        See all notifications <i class="m-icon-swapright"></i>
                                    </a>
                                </li>
                            </ul>
                        </li>
                    <?php endif; ?>
                    <?php if ($messages): ?>
                        <li class="dropdown dropdown-extended dropdown-inbox" id="header_inbox_bar">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown"
                               data-close-others="true">
                                <i class="cms-icon-envelope-open"></i>
                                <span class="badge badge-default"><?= count($messages); ?></span>
                            </a>
                            <ul class="dropdown-menu">
                                <li>
                                    <p>
                                        You have <?= $total_messages; ?> new messages
                                    </p>
                                </li>
                                <li>
                                    <ul class="dropdown-menu-list scroller" style="height: 250px;">
                                        <?php foreach ($notifications as $k => $message): /** @var UsersMessageEntity $message */
                                            $user = new AdminUser($message->getFromUserId());
                                            $avatar = $user->getAvatar(); ?>
                                            <li>
                                                <a href="?p=users&do=chat&user_id=2">
                                                    <?php if ($avatar): ?>
                                                        <span class="photo">
                                                           <img src="<?= $avatar ?>" alt="" style="height=40px">
                                                        </span>
                                                    <?php endif; ?>
                                                    <span class="subject">
                                                        <span class="from"><?= $user->getName() ?></span>
                                                        <span class="time"><?= Converter::getTimeFromEventAgo((int)$message->getTs()) ?></span>
                                                    </span>
                                                    <span class="message"><?= Converter::cutLongStrings($message->getMessage()) ?></span>
                                                </a>
                                            </li>
                                        <?php endforeach; ?>
                                    </ul>
                                </li>
                                <li class="external">
                                    <a href="?p=users&do=chat">
                                        See all messages <i class="m-icon-swapright"></i>
                                    </a>
                                </li>
                            </ul>
                        </li>
                    <?php endif; ?>
                    <?php if ($custom_notifiers): ?>
                        <?= implode('', $custom_notifiers) ?>
                    <?php endif; ?>
                    <li class="dropdown dropdown-user">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown"
                           data-close-others="true">
                            <img alt="" class="img-circle" src="<?= $user_avatar ?>" style="height: 29px;">
                            <span class="username"><?= Users::getInstance()->getUserData('name') ?></span>
                            <i class="fa fa-angle-down"></i>
                        </a>
                        <ul class="dropdown-menu">
                            <li>
                                <a href="?p=users&do=users_edit&id=<?= USER_ID ?>">
                                    <i class="cms-icon-user"></i> My Profile
                                </a>
                            </li>
                            <li>
                                <a href="?p=home&do=notifications">
                                    <i class="cms-icon-envelope-open"></i>My notifications
                                    <span class="badge badge-danger"> <?= count($notifications) ?></span>
                                </a>
                            </li>
                            <li class="divider"></li>
                            <li>
                                <a href="#" onclick="clipboard_forms.copy_page_forms(); return false;">
                                    <i class="cms-icon-cloud-download"></i>Copy form data
                                </a>
                            </li>
                            <li>
                                <a href="#" onclick="clipboard_forms.paste_page_forms(); return false;">
                                    <i class="cms-icon-cloud-upload"></i>Paste form data
                                </a>
                            </li>
                            <li class="divider"></li>
                            <li>
                                <a href="?p=home&do=_exit" onclick="return confirm('<?= __('Are you sure?') ?>');">
                                    <i class="cms-icon-key"></i> Log Out
                                </a>
                            </li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
        <?php

        return ob_get_clean();
    }
342654
public function indexAction()
    {
        $visibilityService = $this->getVisibilityService();
        $options = $visibilityService->getOptions();

        $widgetId = $options->getWidgetId();
        if (! $widgetId) {
            $this->flashMessenger()->addMessage(
                $this->scTranslate('The widget identifier was not specified.')
            );
            return $this->redirect()
                ->toRoute('sc-admin/layout')
                ->setStatusCode(303);
        }

        $widget = $this->deriveWidget($widgetId);
        if (empty($widget)) {
            return $this->getResponse();
        }
        if ($this->getRequest()->isPost()) {
            $event = $this->request->getPost('suboperation');
            if (! empty($event)) {
                $events = $this->getEventManager();
                $params = $this->getRequest()->getPost();
                $params['widget_id'] = $widget->getId();
                $result = $events->trigger($event, $this, $params);
                if ($result->last() instanceof Response) {
                    return $result->last();
                }
            }
        }

        $view = new ViewModel;
        $view->options = $options;
        $view->widget = $widget;

        $moduleOptions = $this->getModuleOptions();
        $view->config = $moduleOptions->getWidgetByName($widget->getName());

        $view->list = $visibilityService->getContentList();
        $visibilityService->saveOptions();

        return $view;
    }
1209560
public function navigation() {
		$output = null;

		if ( $this->child_count() > 1 ) {

			$output .= '<ul class="uix-' . esc_attr( $this->type ) . '-tabs uix-panel-tabs">';
			$active = 'true';
			foreach ( $this->child as $child ) {
				if ( $this->is_section_object( $child ) ) {
					$output .= $this->tab_label( $child, $active );
					$active = 'false';
				}
			}
			$output .= '</ul>';
		}

		return $output;
	}
741121
public function getPresentNonExportIgnoresContent()
    {
        if ($this->hasGitattributesFile() === false) {
            return '';
        }

        $gitattributesContent = (string) file_get_contents($this->gitattributesFile);
        $eol = $this->detectEol($gitattributesContent);

        $gitattributesLines = preg_split(
            '/\\r\\n|\\r|\\n/',
            $gitattributesContent
        );

        $nonExportIgnoreLines = [];
        $exportIgnoresPlacementPlaceholderSet = false;
        $exportIgnoresPlacementPlaceholder = self::EXPORT_IGNORES_PLACEMENT_PLACEHOLDER;

        array_filter($gitattributesLines, function ($line) use (
            &$nonExportIgnoreLines,
            &$exportIgnoresPlacementPlaceholderSet,
            &$exportIgnoresPlacementPlaceholder
        ) {
            if (strstr($line, 'export-ignore') === false || strstr($line, '#')) {
                return $nonExportIgnoreLines[] = trim($line);
            } else {
                if ($exportIgnoresPlacementPlaceholderSet === false) {
                    $exportIgnoresPlacementPlaceholderSet = true;
                    return $nonExportIgnoreLines[] = $exportIgnoresPlacementPlaceholder;
                }
            }
        });

        return implode($eol, $nonExportIgnoreLines);
    }
846868
public function generateCacheId()
    {
        if (!$this->getCurrentView()) {
            throw new \Exception(sprintf(
                'Cannot generate an hash for widget %s if currentView is not defined.',
                $this->getId()
            ));
        }

        return sprintf(
            '%s-%s-%s',
            $this->getId(),
            $this->getUpdatedAt()->getTimestamp(),
            $this->getCurrentView()->getReference()->getId()
        );
    }