Exemplo n.º 1
0
 /**
  * @param MauticFactory $factory
  * @param string        $theme
  *
  * @throws BadConfigurationException
  * @throws FileNotFoundException
  */
 public function __construct(MauticFactory $factory, $theme = 'current')
 {
     $this->factory = $factory;
     $this->theme = $theme == 'current' ? $factory->getParameter('theme') : $theme;
     if ($this->theme == null) {
         $this->theme = 'Mauve';
     }
     $this->themeDir = $factory->getSystemPath('themes') . '/' . $this->theme;
     $this->themePath = $factory->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);
     } elseif (file_exists($this->themePath . '/config.php')) {
         $this->config = (include $this->themePath . '/config.php');
     } 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');
     }
 }
Exemplo n.º 2
0
 /**
  * Retrieves the update data from our home server
  *
  * @param bool $overrideCache
  *
  * @return array
  */
 public function fetchData($overrideCache = false)
 {
     $cacheFile = $this->factory->getSystemPath('cache') . '/lastUpdateCheck.txt';
     // Check if we have a cache file and try to return cached data if so
     if (!$overrideCache && is_readable($cacheFile)) {
         $update = (array) json_decode(file_get_contents($cacheFile));
         // Check if the user has changed the update channel, if so the cache is invalidated
         if ($update['stability'] == $this->factory->getParameter('update_stability')) {
             // If we're within the cache time, return the cached data
             if ($update['checkedTime'] > strtotime('-3 hours')) {
                 return $update;
             }
         }
     }
     // Before processing the update data, send up our metrics
     try {
         // Generate a unique instance ID for the site
         $instanceId = hash('sha1', $this->factory->getParameter('secret_key') . 'Mautic' . $this->factory->getParameter('db_driver'));
         $data = array('application' => 'Mautic', 'version' => $this->factory->getVersion(), 'phpVersion' => PHP_VERSION, 'dbDriver' => $this->factory->getParameter('db_driver'), 'serverOs' => php_uname('s') . ' ' . php_uname('r'), 'instanceId' => $instanceId, 'installSource' => $this->factory->getParameter('install_source', 'Mautic'));
         $this->connector->post('https://updates.mautic.org/stats/send', $data, array(), 10);
     } catch (\Exception $exception) {
         // Not so concerned about failures here, move along
     }
     // Get the update data
     try {
         $appData = array('appVersion' => $this->factory->getVersion(), 'phpVersion' => PHP_VERSION, 'stability' => $this->factory->getParameter('update_stability'));
         $data = $this->connector->post('https://updates.mautic.org/index.php?option=com_mauticdownload&task=checkUpdates', $appData, array(), 10);
         $update = json_decode($data->body);
     } catch (\Exception $exception) {
         // Log the error
         $logger = $this->factory->getLogger();
         $logger->addError('An error occurred while attempting to fetch updates: ' . $exception->getMessage());
         return array('error' => true, 'message' => 'mautic.core.updater.error.fetching.updates');
     }
     if ($data->code != 200) {
         // Log the error
         $logger = $this->factory->getLogger();
         $logger->addError(sprintf('An unexpected %1$s code was returned while attempting to fetch updates.  The message received was: %2$s', $data->code, is_string($data->body) ? $data->body : implode('; ', $data->body)));
         return array('error' => true, 'message' => 'mautic.core.updater.error.fetching.updates');
     }
     // If the user's up-to-date, go no further
     if ($update->latest_version) {
         return array('error' => false, 'message' => 'mautic.core.updater.running.latest.version');
     }
     // Last sanity check, if the $update->version is older than our current version
     if (version_compare($this->factory->getVersion(), $update->version, 'ge')) {
         return array('error' => false, 'message' => 'mautic.core.updater.running.latest.version');
     }
     // The user is able to update to the latest version, cache the data first
     $data = array('error' => false, 'message' => 'mautic.core.updater.update.available', 'version' => $update->version, 'announcement' => $update->announcement, 'package' => $update->package, 'checkedTime' => time(), 'stability' => $this->factory->getParameter('update_stability'));
     file_put_contents($cacheFile, json_encode($data));
     return $data;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getPath()
 {
     $controller = str_replace('\\', '/', $this->get('controller'));
     if (!empty($this->themeOverride)) {
         try {
             $theme = $this->factory->getTheme($this->themeOverride);
             $themeDir = $theme->getThemePath();
         } catch (\Exception $e) {
         }
     } else {
         $theme = $this->factory->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->factory->getSystemPath('bundles', true);
         $pluginRoot = $this->factory->getSystemPath('plugins', true);
         // @deprecated 1.1.4; to be removed in 2.0; BC support for MauticAddon
         $addonRoot = $this->factory->getSystemPath('root') . '/addons';
         // Check for a system-wide override
         $themePath = $this->factory->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) || file_exists($addonRoot . '/' . $this->parameters['bundle'] . '/Views/' . $path)) {
                     // Mautic core template
                     $template = '@' . $this->get('bundle') . '/Views/' . $path;
                 }
             }
         }
     } else {
         $themes = $this->factory->getInstalledThemes();
         if (isset($themes[$controller])) {
             //this is a file in a specific Mautic theme folder
             $theme = $this->factory->getTheme($controller);
             $template = $theme->getThemePath() . '/html/' . $fileName;
         }
     }
     if (empty($template)) {
         //try the parent
         return parent::getPath();
     }
     return $template;
 }
Exemplo n.º 4
0
 /**
  * Fetches a language package from the remote server
  *
  * @param string $languageCode
  *
  * @return array
  */
 public function fetchPackage($languageCode)
 {
     // Check if we have a cache file, generate it if not
     if (!is_readable($this->cacheFile)) {
         $this->fetchLanguages();
     }
     $cacheData = json_decode(file_get_contents($this->cacheFile), true);
     // Make sure the language actually exists
     if (!isset($cacheData['languages'][$languageCode])) {
         return array('error' => true, 'message' => 'mautic.core.language.helper.invalid.language');
     }
     // GET the update data
     try {
         $data = $this->connector->get('https://updates.mautic.org/index.php?option=com_mauticdownload&task=downloadLanguagePackage&langCode=' . $languageCode);
     } catch (\Exception $exception) {
         $logger = $this->factory->getLogger();
         $logger->addError('An error occurred while attempting to fetch the package: ' . $exception->getMessage());
         return array('error' => true, 'message' => 'mautic.core.language.helper.error.fetching.package');
     }
     if ($data->code != 200) {
         return array('error' => true, 'message' => 'mautic.core.language.helper.error.fetching.package');
     }
     // Set the filesystem target
     $target = $this->factory->getSystemPath('cache') . '/' . $languageCode . '.zip';
     // Write the response to the filesystem
     file_put_contents($target, $data->body);
     // Return an array for the sake of consistency
     return array('error' => false);
 }
Exemplo n.º 5
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->devMode = $factory->getEnvironment() == 'dev';
     $this->imageDir = $factory->getSystemPath('images');
     $this->assetHelper = $factory->getHelper('template.assets');
     $this->avatarHelper = $factory->getHelper('template.avatar');
 }
Exemplo n.º 6
0
 /**
  * Find asset overrides in the template
  *
  * @param $env
  * @param $assets
  *
  * @return array
  */
 protected function findOverrides($env, &$assets)
 {
     $rootPath = $this->factory->getSystemPath('assets_root');
     $currentTheme = $this->factory->getSystemPath('current_theme');
     $modifiedLast = array();
     $types = array('css', 'js');
     $overrideFiles = array("libraries" => "libraries_custom", "app" => "app_custom");
     foreach ($types as $ext) {
         foreach ($overrideFiles as $group => $of) {
             if (file_exists("{$rootPath}/{$currentTheme}/{$ext}/{$of}.{$ext}")) {
                 $fullPath = "{$rootPath}/{$currentTheme}/{$ext}/{$of}.{$ext}";
                 $relPath = "{$currentTheme}/{$ext}/{$of}.{$ext}";
                 $details = array('fullPath' => $fullPath, 'relPath' => $relPath);
                 if ($env == 'prod') {
                     $lastModified = filemtime($fullPath);
                     if (!isset($modifiedLast[$ext][$group]) || $lastModified > $modifiedLast[$ext][$group]) {
                         $modifiedLast[$ext][$group] = $lastModified;
                     }
                     $assets[$ext][$group][$relPath] = $details;
                 } else {
                     $assets[$ext][$relPath] = $details;
                 }
             }
         }
     }
     return $modifiedLast;
 }
Exemplo n.º 7
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->factory = $factory;
     $this->cacheDir = $factory->getSystemPath('cache', true);
     $this->env = $factory->getEnvironment();
     $this->configFile = $this->factory->getLocalConfigFile(false);
     $this->containerFile = $this->factory->getKernel()->getContainerFile();
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $bundles = $this->factory->getMauticBundles(true);
     $catalogue = new MessageCatalogue($locale);
     //Bundle translations
     foreach ($bundles as $name => $bundle) {
         //load translations
         $translations = $bundle['directory'] . '/Translations/' . $locale;
         if (file_exists($translations)) {
             $iniFiles = new Finder();
             $iniFiles->files()->in($translations)->name('*.ini');
             foreach ($iniFiles as $file) {
                 $this->loadTranslations($catalogue, $locale, $file);
             }
         }
     }
     //Theme translations
     $themeDir = $this->factory->getSystemPath('current_theme', true);
     if (file_exists($themeTranslation = $themeDir . '/translations/' . $locale)) {
         $iniFiles = new Finder();
         $iniFiles->files()->in($themeTranslation)->name('*.ini');
         foreach ($iniFiles as $file) {
             $this->loadTranslations($catalogue, $locale, $file);
         }
     }
     //3rd Party translations
     $translationsDir = $this->factory->getSystemPath('translations', true) . '/' . $locale;
     if (file_exists($translationsDir)) {
         $iniFiles = new Finder();
         $iniFiles->files()->in($translationsDir)->name('*.ini');
         foreach ($iniFiles as $file) {
             $this->loadTranslations($catalogue, $locale, $file);
         }
     }
     //Overrides
     $overridesDir = $this->factory->getSystemPath('translations', true) . '/overrides/' . $locale;
     if (file_exists($overridesDir)) {
         $iniFiles = new Finder();
         $iniFiles->files()->in($overridesDir)->name('*.ini');
         foreach ($iniFiles as $file) {
             $this->loadTranslations($catalogue, $locale, $file);
         }
     }
     return $catalogue;
 }
Exemplo n.º 9
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->devMode = $factory->getEnvironment() == 'dev';
     $this->imageDir = $factory->getSystemPath('images');
     $this->assetHelper = $factory->getHelper('template.assets');
     $this->avatarHelper = $factory->getHelper('template.avatar');
     $this->request = $factory->getRequest();
     $this->devHosts = (array) $factory->getParameter('dev_hosts');
 }
Exemplo n.º 10
0
 /**
  * Helper method can load $parameters array from a config file.
  *
  * @param string $path (relative from the root dir)
  *
  * @return array
  */
 public function getParameters($path = null)
 {
     $paramsFile = $this->factory->getSystemPath('app') . $path;
     if (file_exists($paramsFile)) {
         // Import the bundle configuration, $parameters is defined in this file
         include $paramsFile;
     }
     if (!isset($parameters)) {
         $parameters = array();
     }
     return $parameters;
 }
Exemplo n.º 11
0
 /**
  * Get icon for Integration
  *
  * @return string
  */
 public function getIcon()
 {
     $systemPath = $this->factory->getSystemPath('root');
     $bundlePath = $this->factory->getSystemPath('bundles');
     $pluginPath = $this->factory->getSystemPath('plugins');
     $genericIcon = $bundlePath . '/PluginBundle/Assets/img/generic.png';
     $name = $this->getName();
     $bundle = $this->settings->getPlugin()->getBundle();
     $icon = $pluginPath . '/' . $bundle . '/Assets/img/' . strtolower($name) . '.png';
     if (file_exists($systemPath . '/' . $icon)) {
         return $icon;
     }
     return $genericIcon;
 }
Exemplo n.º 12
0
 /**
  * Get the path to the integration's icon relative to the site root
  *
  * @param $integration
  *
  * @return string
  */
 public function getIconPath($integration)
 {
     $systemPath = $this->factory->getSystemPath('root');
     $genericIcon = 'app/bundles/AddonBundle/Assets/img/generic.png';
     $name = $integration->getIntegrationSettings()->getName();
     // For non-core bundles, we need to extract out the bundle's name to figure out where in the filesystem to look for the icon
     $className = get_class($integration);
     $exploded = explode('\\', $className);
     $icon = 'addons/' . $exploded[1] . '/Assets/img/' . strtolower($name) . '.png';
     if (file_exists($systemPath . '/' . $icon)) {
         return $icon;
     }
     return $genericIcon;
 }
Exemplo n.º 13
0
 /**
  * @param           $country
  * @param bool|true $urlOnly
  * @param string    $class
  *
  * @return string
  */
 public function getCountryFlag($country, $urlOnly = true, $class = '')
 {
     $flagPath = $this->factory->getSystemPath('assets', true) . '/images/flags/';
     $relpath = $this->factory->getSystemPath('assets') . '/images/flags/';
     $country = ucwords(str_replace(' ', '-', $country));
     $flagImg = '';
     if (file_exists($flagPath . $country . '.png')) {
         if (file_exists($flagPath . $country . '.png')) {
             $flagImg = $this->getUrl($relpath . $country . '.png');
         }
     }
     if ($urlOnly) {
         return $flagImg;
     } else {
         return '<img src="' . $flagImg . '" class="' . $class . '" />';
     }
 }
Exemplo n.º 14
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->factory = $factory;
     $this->mailboxes = $this->factory->getParameter('monitored_email');
     if (isset($this->mailboxes['general'])) {
         $this->settings = $this->mailboxes['general'];
     } else {
         $this->settings = array('host' => '', 'port' => '', 'password' => '', 'user' => '', 'encryption' => '');
     }
     // Check that cache attachments directory exists
     $cacheDir = $factory->getSystemPath('cache');
     $this->attachmentsDir = $cacheDir . '/attachments';
     if (!file_exists($this->attachmentsDir)) {
         mkdir($this->attachmentsDir);
     }
     if ($this->settings['host'] == 'imap.gmail.com') {
         $this->isGmail = true;
     }
 }
Exemplo n.º 15
0
 /**
  * Get the path to the integration's icon relative to the site root
  *
  * @param $integration
  *
  * @return string
  */
 public function getIconPath($integration)
 {
     $systemPath = $this->factory->getSystemPath('root');
     $bundlePath = $this->factory->getSystemPath('bundles');
     $pluginPath = $this->factory->getSystemPath('plugins');
     $genericIcon = $bundlePath . '/PluginBundle/Assets/img/generic.png';
     if (is_array($integration)) {
         // A bundle so check for an icon
         $icon = $pluginPath . '/' . $integration['bundle'] . '/Assets/img/icon.png';
     } elseif ($integration instanceof Plugin) {
         // A bundle so check for an icon
         $icon = $pluginPath . '/' . $integration->getBundle() . '/Assets/img/icon.png';
     } elseif ($integration instanceof AbstractIntegration) {
         return $integration->getIcon();
     }
     if (file_exists($systemPath . '/' . $icon)) {
         return $icon;
     }
     return $genericIcon;
 }
Exemplo n.º 16
0
 /**
  * Get the path to the integration's icon relative to the site root
  *
  * @param $integration
  *
  * @return string
  */
 public function getIconPath($integration)
 {
     $systemPath = $this->factory->getSystemPath('root');
     $bundlePath = $this->factory->getSystemPath('bundles');
     $pluginPath = $this->factory->getSystemPath('plugins');
     $genericIcon = $bundlePath . '/PluginBundle/Assets/img/generic.png';
     if (is_array($integration)) {
         // A bundle so check for an icon
         $icon = $pluginPath . '/' . $integration['bundle'] . '/Assets/img/icon.png';
     } elseif ($integration instanceof Plugin) {
         // A bundle so check for an icon
         $icon = $pluginPath . '/' . $integration->getBundle() . '/Assets/img/icon.png';
     } else {
         // For non-core bundles, we need to extract out the bundle's name to figure out where in the filesystem to look for the icon
         $name = $integration->getIntegrationSettings()->getName();
         $className = get_class($integration);
         $exploded = explode('\\', $className);
         $icon = $pluginPath . '/' . $exploded[1] . '/Assets/img/' . strtolower($name) . '.png';
     }
     if (file_exists($systemPath . '/' . $icon)) {
         return $icon;
     }
     return $genericIcon;
 }
Exemplo n.º 17
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->factory = $factory;
     $this->cacheDir = $factory->getSystemPath('cache', true);
     $this->env = $factory->getEnvironment();
 }
Exemplo n.º 18
0
 /**
  * @param bool|false $absolute
  *
  * @return mixed
  */
 public function getDefaultAvatar($absolute = false)
 {
     return $this->factory->getHelper('template.assets')->getUrl($this->factory->getSystemPath('assets') . '/images/avatar.png', null, null, $absolute);
 }
Exemplo n.º 19
0
 public function __construct(MauticFactory $factory)
 {
     $this->mediaDir = $factory->getSystemPath('assets', true) . '/sounds';
 }