/** * Check if an email address is on a list of exceptions. * * @param string $email * @param object $config (optional) * @return string|null */ public function getSendingMethodForEmailAddress($email, $config = null) { if (!$config) { $config = $this->getConfig(); } if (!isset($config->exceptions) || !is_array($config->exceptions) || !count($config->exceptions)) { return null; } $email = Rhymix\Framework\URL::encodeIdna($email); foreach ($config->exceptions as $exception) { $domains = array(); foreach ($exception['domains'] as $domain) { $domains[] = preg_quote($domain, '/'); } if (count($domains) && preg_match('/\\b(?:' . implode('|', $domains) . ')$/i', $email)) { return $exception['method']; } } return null; }
/** * Return the exact url of the current page * * @return string */ function getCurrentPageUrl($escape = true) { $url = Rhymix\Framework\URL::getCurrentURL(); return $escape ? escape($url) : $url; }
/** * Add OpenGraph metadata tags. * * @param string $output * @return void */ function _addOpenGraphMetadata() { // Get information about the current request. $page_type = 'website'; $current_module_info = Context::get('current_module_info'); $site_module_info = Context::get('site_module_info'); $document_srl = Context::get('document_srl'); if ($document_srl) { $oDocument = Context::get('oDocument') ?: getModel('document')->getDocument($document_srl, false, false); if ($oDocument instanceof documentItem && $oDocument->document_srl == $document_srl && !$oDocument->isSecret()) { $page_type = 'article'; } } // Add basic metadata. Context::addOpenGraphData('og:title', Context::getBrowserTitle()); Context::addOpenGraphData('og:site_name', Context::getSiteTitle()); if ($page_type === 'article' && config('seo.og_extract_description')) { $description = trim(utf8_normalize_spaces($oDocument->getContentText(200))); } else { $description = Context::getMetaTag('description'); } Context::addOpenGraphData('og:description', $description); Context::addMetaTag('description', $description); // Add metadata about this page. Context::addOpenGraphData('og:type', $page_type); if ($page_type === 'article') { $canonical_url = getFullUrl('', 'mid', $current_module_info->mid, 'document_srl', $document_srl); } elseif (($page = Context::get('page')) > 1) { $canonical_url = getFullUrl('', 'mid', $current_module_info->mid, 'page', $page); } elseif ($current_module_info->module_srl == $site_module_info->module_srl) { $canonical_url = getFullUrl(''); } else { $canonical_url = getFullUrl('', 'mid', $current_module_info->mid); } Context::addOpenGraphData('og:url', $canonical_url); Context::setCanonicalURL($canonical_url); // Add metadata about the locale. $lang_type = Context::getLangType(); $locales = (include \RX_BASEDIR . 'common/defaults/locales.php'); if (isset($locales[$lang_type])) { Context::addOpenGraphData('og:locale', $locales[$lang_type]['locale']); } if ($page_type === 'article' && $oDocument->getLangCode() !== $lang_type && isset($locales[$oDocument->getLangCode()])) { Context::addOpenGraphData('og:locale:alternate', $locales[$oDocument->getLangCode()]); } // Add image. if ($page_type === 'article' && config('seo.og_extract_images')) { if (($document_images = Rhymix\Framework\Cache::get("seo:document_images:{$document_srl}")) === null) { $document_images = array(); if ($oDocument->hasUploadedFiles()) { foreach ($oDocument->getUploadedFiles() as $file) { if ($file->isvalid !== 'Y' || !preg_match('/\\.(?:bmp|gif|jpe?g|png)$/i', $file->uploaded_filename)) { continue; } list($width, $height) = @getimagesize($file->uploaded_filename); if ($width < 100 && $height < 100) { continue; } $image = array('filepath' => $file->uploaded_filename, 'width' => $width, 'height' => $height); if ($file->cover_image === 'Y') { array_unshift($document_images, $image); } else { $document_images[] = $image; } if (count($document_images) >= 1) { break; } } } Rhymix\Framework\Cache::set("seo:document_images:{$document_srl}", $document_images, 0, true); } } else { $document_images = null; } if ($document_images) { $first_image = reset($document_images); $first_image['filepath'] = preg_replace('/^.\\/files\\//', \RX_BASEURL . 'files/', $first_image['filepath']); Context::addOpenGraphData('og:image', Rhymix\Framework\URL::getCurrentDomainURL($first_image['filepath'])); Context::addOpenGraphData('og:image:width', $first_image['width']); Context::addOpenGraphData('og:image:height', $first_image['height']); } elseif ($default_image = getAdminModel('admin')->getSiteDefaultImageUrl($width, $height)) { Context::addOpenGraphData('og:image', Rhymix\Framework\URL::getCurrentDomainURL($default_image)); if ($width && $height) { Context::addOpenGraphData('og:image:width', $width); Context::addOpenGraphData('og:image:height', $height); } } // Add datetime for articles. if ($page_type === 'article' && config('seo.og_use_timestamps')) { Context::addOpenGraphData('article:published_time', $oDocument->getRegdate('c')); Context::addOpenGraphData('article:modified_time', $oDocument->getUpdate('c')); } }
/** * Convert a URL to a server-side path. * * This function is an alias to Rhymix\Framework\URL::toServerPath(). * It returns false if the URL cannot be converted. * * @param string $url * @return string|false */ function url2path($url) { return Rhymix\Framework\URL::toServerPath($url); }
/** * Convert IDNA (punycode) domain into UTF-8 * * @param string $domain Domain to convert * @return string Converted string */ public static function decodeIdna($domain) { return Rhymix\Framework\URL::decodeIdna($domain); }
/** * Save the exception configuration. */ public function procAdvanced_MailerAdminInsertExceptions() { // Get the current configuration. $config = $this->getConfig(); $sending_methods = Rhymix\Framework\Mail::getSupportedDrivers(); // Get and validate the list of exceptions. $exceptions = array(); for ($i = 1; $i <= 3; $i++) { $method = strval(Context::get('exception_' . $i . '_method')); $domains = trim(Context::get('exception_' . $i . '_domains')); if ($method !== '' && $domains !== '') { if ($method !== 'default' && !isset($sending_methods[$method])) { return new Object(-1, 'msg_advanced_mailer_sending_method_is_invalid'); } if ($method !== 'default') { foreach ($this->sending_methods[$method]['required'] as $conf_name) { if (!Rhymix\Framework\Config::get("mail.{$method}.{$conf_name}")) { return new Object(-1, sprintf(Context::getLang('msg_advanced_mailer_sending_method_is_not_configured'), Context::getLang('cmd_advanced_mailer_sending_method_' . $method))); } } } $exceptions[$i]['method'] = $method; $exceptions[$i]['domains'] = array(); $domains = array_map('trim', preg_split('/[,\\n]/', $domains, null, PREG_SPLIT_NO_EMPTY)); foreach ($domains as $domain) { if (strpos($domain, 'xn--') !== false) { $domain = Rhymix\Framework\URL::decodeIdna($domain); } $exceptions[$i]['domains'][] = $domain; } } } // Save the new configuration. $config->exceptions = $exceptions; $output = getController('module')->insertModuleConfig('advanced_mailer', $config); if ($output->toBool()) { $this->setMessage('success_registed'); } else { return $output; } if (Context::get('success_return_url')) { $this->setRedirectUrl(Context::get('success_return_url')); } else { $this->setRedirectUrl(getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAdvanced_mailerAdminExceptions')); } }