コード例 #1
0
 /**
  * @throws \Exception
  */
 public function addOptOutStyles()
 {
     /** @var \Piwik\Plugins\CoreAdminHome\OptOutManager $manager */
     $manager = StaticContainer::get('Piwik\\Plugins\\CoreAdminHome\\OptOutManager');
     // See Issue #33
     $siteId = Common::getRequestVar('idsite', 0, 'integer');
     // Is still available for BC
     if (!$siteId) {
         $siteId = Common::getRequestVar('idSite', 0, 'integer');
     }
     // Try to find siteId in Session
     if (!$siteId) {
         return;
     }
     $site = API::getInstance()->getSiteDataId($siteId);
     if (!$site) {
         return;
     }
     $manager->addQueryParameter('idsite', $siteId);
     // Add CSS file if set
     if (!empty($site['custom_css_file'])) {
         $manager->addStylesheet($site['custom_css_file'], false);
     }
     // Add CSS Inline Styles if set
     if (!empty($site['custom_css'])) {
         $manager->addStylesheet($site['custom_css'], true);
     }
 }
コード例 #2
0
 /**
  * Main Plugin Index
  *
  * @return mixed
  * @throws \Exception
  */
 public function index()
 {
     Piwik::checkUserHasSomeAdminAccess();
     if (isset($_SERVER['REQUEST_METHOD']) && 'POST' == $_SERVER['REQUEST_METHOD']) {
         // Cannot use Common::getRequestVar, because the function remove whitespaces and newline breaks
         $postedSiteData = isset($_POST['site']) ? $_POST['site'] : null;
         if (is_array($postedSiteData) && count($postedSiteData) > 0) {
             foreach ($postedSiteData as $id => $site) {
                 if (!isset($site['css'], $site['file'])) {
                     continue;
                 }
                 // Check URL
                 if (!UrlHelper::isLookLikeUrl($site['file'])) {
                     $site['file'] = null;
                 }
                 API::getInstance()->saveSite($id, $site['css'], $site['file']);
             }
             // Redirect to, clear POST vars
             $this->redirectToIndex('CustomOptOut', 'index');
             return;
         }
     }
     $view = new View('@CustomOptOut/index.twig');
     Site::clearCache();
     if (Piwik::hasUserSuperUserAccess()) {
         $sitesRaw = APISiteManager::getInstance()->getAllSites();
     } else {
         $sitesRaw = APISiteManager::getInstance()->getSitesWithAdminAccess();
     }
     // Gets sites after Site.setSite hook was called
     $sites = array_values(Site::getSites());
     if (count($sites) != count($sitesRaw)) {
         throw new \Exception("One or more website are missing or invalid.");
     }
     foreach ($sites as &$site) {
         $site['alias_urls'] = APISiteManager::getInstance()->getSiteUrlsFromId($site['idsite']);
     }
     $view->adminSites = $sites;
     $view->adminSitesCount = count($sites);
     $view->language = LanguagesManager::getLanguageCodeForCurrentUser();
     $view->isEditorEnabled = API::getInstance()->isCssEditorEnabled();
     $view->editorTheme = API::getInstance()->getEditorTheme();
     $view->showOldLinks = false;
     $this->setBasicVariablesView($view);
     return $view->render();
 }