Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function getPath()
 {
     $controller = str_replace('\\', '/', $this->get('controller'));
     if (!empty($this->themeOverride)) {
         try {
             $theme = $this->themeHelper->getTheme($this->themeOverride);
             $themeDir = $theme->getThemePath();
         } catch (\Exception $e) {
         }
     } else {
         $theme = $this->themeHelper->getTheme();
         $themeDir = $theme->getThemePath();
     }
     $fileName = $this->get('name') . '.' . $this->get('format') . '.' . $this->get('engine');
     $path = (empty($controller) ? '' : $controller . '/') . $fileName;
     if (!empty($this->parameters['bundle'])) {
         $bundleRoot = $this->pathsHelper->getSystemPath('bundles', true);
         $pluginRoot = $this->pathsHelper->getSystemPath('plugins', true);
         // Check for a system-wide override
         $themePath = $this->pathsHelper->getSystemPath('themes', true);
         $systemTemplate = $themePath . '/system/' . $this->parameters['bundle'] . '/' . $path;
         if (file_exists($systemTemplate)) {
             $template = $systemTemplate;
         } else {
             //check for an override and load it if there is
             if (!empty($themeDir) && file_exists($themeDir . '/html/' . $this->parameters['bundle'] . '/' . $path)) {
                 // Theme override
                 $template = $themeDir . '/html/' . $this->parameters['bundle'] . '/' . $path;
             } else {
                 preg_match('/Mautic(.*?)Bundle/', $this->parameters['bundle'], $match);
                 if (!empty($match[1]) && file_exists($bundleRoot . '/' . $match[1] . 'Bundle/Views/' . $path) || file_exists($pluginRoot . '/' . $this->parameters['bundle'] . '/Views/' . $path)) {
                     // Mautic core template
                     $template = '@' . $this->get('bundle') . '/Views/' . $path;
                 }
             }
         }
     } else {
         $themes = $this->themeHelper->getInstalledThemes();
         if (isset($themes[$controller])) {
             //this is a file in a specific Mautic theme folder
             $theme = $this->themeHelper->getTheme($controller);
             $template = $theme->getThemePath() . '/html/' . $fileName;
         }
     }
     if (empty($template)) {
         //try the parent
         return parent::getPath();
     }
     return $template;
 }
Beispiel #2
0
 /**
  * Method to get important folders with a writable flag
  *
  * @return array
  */
 public function getFolders()
 {
     if (!is_null($this->folders)) {
         return $this->folders;
     }
     $importantFolders = array($this->pathsHelper->getSystemPath('local_config'), $this->coreParametersHelper->getParameter('cache_path'), $this->coreParametersHelper->getParameter('log_path'), $this->coreParametersHelper->getParameter('upload_dir'), $this->pathsHelper->getSystemPath('images', true), $this->pathsHelper->getSystemPath('translations', true));
     // Show the spool folder only if the email queue is configured
     if ($this->coreParametersHelper->getParameter('mailer_spool_type') == 'file') {
         $importantFolders[] = $this->coreParametersHelper->getParameter('mailer_spool_path');
     }
     foreach ($importantFolders as $folder) {
         $folderPath = realpath($folder);
         $folderKey = $folderPath ? $folderPath : $folder;
         $isWritable = $folderPath ? is_writable($folderPath) : false;
         $this->folders[$folderKey] = $isWritable;
     }
     return $this->folders;
 }
Beispiel #3
0
 /**
  * @param PathsHelper $pathsHelper
  * @param string      $theme
  *
  * @throws BadConfigurationException
  * @throws FileNotFoundException
  */
 public function __construct(PathsHelper $pathsHelper, $theme)
 {
     $this->theme = $theme;
     $this->themeDir = $pathsHelper->getSystemPath('themes') . '/' . $this->theme;
     $this->themePath = $pathsHelper->getSystemPath('themes_root') . '/' . $this->themeDir;
     // check to make sure the theme exists
     if (!file_exists($this->themePath)) {
         throw new FileNotFoundException($this->theme . ' not found!');
     }
     // get the config
     if (file_exists($this->themePath . '/config.json')) {
         $this->config = json_decode(file_get_contents($this->themePath . '/config.json'), true);
     } else {
         throw new BadConfigurationException($this->theme . ' is missing a required config file');
     }
     if (!isset($this->config['name'])) {
         throw new BadConfigurationException($this->theme . ' does not have a valid config file');
     }
 }
Beispiel #4
0
 /**
  * @param object $entity
  */
 public function deleteEntity($entity)
 {
     // Delete custom avatar if one exists
     $imageDir = $this->pathsHelper->getSystemPath('images', true);
     $avatar = $imageDir . '/lead_avatars/avatar' . $entity->getId();
     if (file_exists($avatar)) {
         unlink($avatar);
     }
     parent::deleteEntity($entity);
 }
 /**
  * Get content for notifications.
  *
  * @param null $afterId
  *
  * @return array
  */
 public function getNotificationContent($afterId = null, $includeRead = false)
 {
     if ($this->userHelper->getUser()->isGuest) {
         return [[], false, ''];
     }
     $this->updateUpstreamNotifications();
     $userId = $this->userHelper->getUser() ? $this->userHelper->getUser()->getId() : 0;
     $notifications = $this->getRepository()->getNotifications($userId, $afterId, $includeRead);
     $showNewIndicator = false;
     //determine if the new message indicator should be shown
     foreach ($notifications as $n) {
         if (!$n['isRead']) {
             $showNewIndicator = true;
             break;
         }
     }
     // Check for updates
     $updateMessage = '';
     $newUpdate = false;
     if (!$this->disableUpdates && $this->userHelper->getUser()->isAdmin()) {
         $updateData = [];
         $cacheFile = $this->pathsHelper->getSystemPath('cache') . '/lastUpdateCheck.txt';
         //check to see when we last checked for an update
         $lastChecked = $this->session->get('mautic.update.checked', 0);
         if (time() - $lastChecked > 3600) {
             $this->session->set('mautic.update.checked', time());
             $updateData = $this->updateHelper->fetchData();
         } elseif (file_exists($cacheFile)) {
             $updateData = json_decode(file_get_contents($cacheFile), true);
         }
         // If the version key is set, we have an update
         if (isset($updateData['version'])) {
             $announcement = $this->translator->trans('mautic.core.updater.update.announcement_link', ['%announcement%' => $updateData['announcement']]);
             $updateMessage = $this->translator->trans($updateData['message'], ['%version%' => $updateData['version'], '%announcement%' => $announcement]);
             $alreadyNotified = $this->session->get('mautic.update.notified');
             if (empty($alreadyNotified) || $alreadyNotified != $updateData['version']) {
                 $newUpdate = true;
                 $this->session->set('mautic.update.notified', $updateData['version']);
             }
         }
     }
     return [$notifications, $showNewIndicator, ['isNew' => $newUpdate, 'message' => $updateMessage]];
 }
Beispiel #6
0
 /**
  * Creates a zip file from a theme and returns the path where it's stored.
  *
  * @param string $themeName
  *
  * @return string
  *
  * @throws Exception
  */
 public function zip($themeName)
 {
     $themePath = $this->pathsHelper->getSystemPath('themes', true) . '/' . $themeName;
     $tmpPath = $this->pathsHelper->getSystemPath('cache', true) . '/tmp_' . $themeName . '.zip';
     $zipper = new \ZipArchive();
     $finder = new Finder();
     if (file_exists($tmpPath)) {
         @unlink($tmpPath);
     }
     $archive = $zipper->open($tmpPath, \ZipArchive::CREATE);
     $finder->files()->in($themePath);
     if ($archive !== true) {
         throw new \Exception($this->getExtractError($archive));
     } else {
         foreach ($finder as $file) {
             $filePath = $file->getRealPath();
             $localPath = $file->getRelativePathname();
             $zipper->addFile($filePath, $localPath);
         }
         $zipper->close();
         return $tmpPath;
     }
     return false;
 }
Beispiel #7
0
 /**
  * Mailbox constructor.
  *
  * @param CoreParametersHelper $parametersHelper
  * @param PathsHelper          $pathsHelper
  */
 public function __construct(CoreParametersHelper $parametersHelper, PathsHelper $pathsHelper)
 {
     $this->mailboxes = $parametersHelper->getParameter('monitored_email', []);
     if (isset($this->mailboxes['general'])) {
         $this->settings = $this->mailboxes['general'];
     } else {
         $this->settings = ['host' => '', 'port' => '', 'password' => '', 'user' => '', 'encryption' => ''];
     }
     // Check that cache attachments directory exists
     $cacheDir = $pathsHelper->getSystemPath('cache', true);
     $this->attachmentsDir = $cacheDir . '/attachments';
     if (!file_exists($this->attachmentsDir)) {
         mkdir($this->attachmentsDir);
     }
     if ($this->settings['host'] == 'imap.gmail.com') {
         $this->isGmail = true;
     }
 }
Beispiel #8
0
 /**
  * Configurator constructor.
  *
  * @param PathsHelper $pathsHelper
  */
 public function __construct(PathsHelper $pathsHelper)
 {
     $this->filename = $pathsHelper->getSystemPath('local_config');
     $this->parameters = $this->read();
 }
Beispiel #9
0
 /**
  * Clears the temporary widget cache
  */
 public function clearDashboardCache()
 {
     $cacheDir = $this->coreParametersHelper->getParameter('cached_data_dir', $this->pathsHelper->getSystemPath('cache', true));
     $cacheStorage = new CacheStorageHelper($cacheDir, $this->user->getId());
     $cacheStorage->clear();
 }