Пример #1
0
 function run($url = '', $args = array())
 {
     if (empty($url)) {
         return '';
     }
     $args = array_merge($this->embed_defaults, $args);
     foreach ($this->handlers as $handler) {
         if (in_array('OCCustomEmbedHandlerInterface', class_implements($handler))) {
             if ($regex = call_user_func(array($handler, 'regex'))) {
                 if (preg_match($regex, $url, $matches)) {
                     if (false !== ($result = call_user_func(array($handler, 'callback'), $matches, $url, $args))) {
                         eZDebugSetting::writeNotice('ocembed', 'Autoembed has found url "' . $url . '" in ' . $handler, __METHOD__);
                         return $result;
                     }
                 }
             }
         }
     }
     $oembed = new OCoEmbed();
     $result = $oembed->get_html($url, $args);
     if ($result) {
         eZDebugSetting::writeNotice('ocembed', 'Autoembed has found url "' . $url . '" in a OEmbed provider', __METHOD__);
         if (!eZINI::instance('ocembed.ini')->hasVariable('Settings', 'DisableFixHttps')) {
             $result = str_replace('http://', '//', $result);
         }
         return $result;
     }
     // Still unknown
     eZDebugSetting::writeNotice('ocembed', 'Autoembed did not find url "' . $url . '"', __METHOD__);
     return array($this->maybe_make_link($url));
 }
Пример #2
0
 function modify(&$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters)
 {
     switch ($operatorName) {
         case 'tidy_output':
             eZDebugSetting::writeNotice("extension-eztidy", "Use 'tidy_output' template operator", "eZTidy::tidyCleaner()");
             $tidy = eZTidy::instance('OutputFilter');
             $operatorValue = $tidy->tidyCleaner($operatorValue);
             break;
     }
 }
 /**
  * Execute sending process in Email
  * @see extension/ezcomments/classes/ezcomNotificationManager#executeSending($subject, $body, $subscriber)
  */
 public function executeSending($subject, $body, $subscriber)
 {
     $email = $subscriber->attribute('email');
     $parameters = array();
     $parameters['content_type'] = $this->emailContentType;
     $parameters['from'] = $this->emailFrom;
     $transport = eZNotificationTransport::instance('ezmail');
     $result = $transport->send(array($email), $subject, $body, null, $parameters);
     if ($result === false) {
         throw new Exception('Send email error! Subscriber id:' . $subscriber->attribute('id'));
     }
     eZDebugSetting::writeNotice('extension-ezcomments', "An email has been sent to '{$email}' (subject: {$subject})", __METHOD__);
 }
 /**
  * Add comment into ezcomment table and do action
  * The adding doesn't validate the data in http
  * @param $comment: ezcomComment object which has not been stored
  *        title, name, url, email, created, modified, text, notification
  * @param $user: user object
  * @param $time: comment time
  * @return  true : if adding succeeds
  *          false otherwise
  *
  */
 public function addComment($comment, $user, $time = null, $notification = null)
 {
     if ($time === null) {
         $time = time();
     }
     $beforeAddingResult = $this->beforeAddingComment($comment, $user, $notification);
     if ($beforeAddingResult !== true) {
         return $beforeAddingResult;
     }
     $comment->store();
     eZDebugSetting::writeNotice('extension-ezcomments', 'Comment has been added', __METHOD__);
     $this->afterAddingComment($comment, $notification);
     return true;
 }
 /**
  *  Send the notification after registeration
  */
 public static function sendUserNotification($userID)
 {
     eZDebugSetting::writeNotice('Sending approval notification to the user.', 'kernel-user', 'user register');
     $user = eZUser::fetch($userID);
     $ini = eZINI::instance();
     // Send mail
     $tpl = eZTemplate::factory();
     $tpl->setVariable('user', $user);
     $templateResult = $tpl->fetch('design:user/registrationapproved.tpl');
     $mail = new eZMail();
     if ($tpl->hasVariable('content_type')) {
         $mail->setContentType($tpl->variable('content_type'));
     }
     $emailSender = $ini->variable('MailSettings', 'EmailSender');
     if ($tpl->hasVariable('email_sender')) {
         $emailSender = $tpl->variable('email_sender');
     } else {
         if (!$emailSender) {
             $emailSender = $ini->variable('MailSettings', 'AdminEmail');
         }
     }
     if ($tpl->hasVariable('subject')) {
         $subject = $tpl->variable('subject');
     } else {
         $subject = ezpI18n::tr('kernel/user/register', 'User registration approved');
     }
     $mail->setSender($emailSender);
     $receiver = $user->attribute('email');
     $mail->setReceiver($receiver);
     $mail->setSubject($subject);
     $mail->setBody($templateResult);
     $mailResult = eZMailTransport::send($mail);
     return array('status' => eZModuleOperationInfo::STATUS_CONTINUE);
 }
Пример #6
0
 static function storeString($filename, $data)
 {
     $file = @fopen($filename, 'w');
     if ($file) {
         fwrite($file, $data);
         fclose($file);
         eZPackage::applyStorageFilePermissions($filename);
         eZDebugSetting::writeNotice('kernel-ezpackage-store', "Stored file {$filename}", 'eZPackage::storeString');
         return true;
     } else {
         eZDebug::writeError("Failed to write package '{$filename}'");
     }
     return false;
 }
Пример #7
0
 /**
  * Loads a translation file
  * Will load from cache if possible, or generate cache if needed
  *
  * Also checks for translation files expiry based on mtime if RegionalSettings.TranslationCheckMTime is enabled
  *
  * @access private
  * @param string $locale
  * @param string $filename
  * @param string $requestedContext
  *
  * @return bool The operation status, true or false
  */
 function loadTranslationFile($locale, $filename, $requestedContext)
 {
     // First try for current charset
     $charset = eZTextCodec::internalCharset();
     $tsTimeStamp = false;
     $ini = eZINI::instance();
     $checkMTime = $ini->variable('RegionalSettings', 'TranslationCheckMTime') === 'enabled';
     if (!$this->RootCache) {
         $roots = array($ini->variable('RegionalSettings', 'TranslationRepository'));
         $extensionBase = eZExtension::baseDirectory();
         $translationExtensions = $ini->variable('RegionalSettings', 'TranslationExtensions');
         foreach ($translationExtensions as $translationExtension) {
             $extensionPath = $extensionBase . '/' . $translationExtension . '/translations';
             if (!$checkMTime || file_exists($extensionPath)) {
                 $roots[] = $extensionPath;
             }
         }
         $this->RootCache = array('roots' => $roots);
     } else {
         $roots = $this->RootCache['roots'];
         if (isset($this->RootCache['timestamp'])) {
             $tsTimeStamp = $this->RootCache['timestamp'];
         }
     }
     // Load cached translations if possible
     if ($this->UseCache == true) {
         if (!$tsTimeStamp) {
             $expiry = eZExpiryHandler::instance();
             $globalTsTimeStamp = $expiry->getTimestamp(self::EXPIRY_KEY, 0);
             $localeTsTimeStamp = $expiry->getTimestamp(self::EXPIRY_KEY . '-' . $locale, 0);
             $tsTimeStamp = max($globalTsTimeStamp, $localeTsTimeStamp);
             if ($checkMTime && $tsTimeStamp < time()) {
                 // iterate over each known TS file, and get the highest timestamp
                 // this value will be used to check for cache validity
                 foreach ($roots as $root) {
                     $path = eZDir::path(array($root, $locale, $charset, $filename));
                     if (file_exists($path)) {
                         $timestamp = filemtime($path);
                         if ($timestamp > $tsTimeStamp) {
                             $tsTimeStamp = $timestamp;
                         }
                     } else {
                         $path = eZDir::path(array($root, $locale, $filename));
                         if (file_exists($path)) {
                             $timestamp = filemtime($path);
                             if ($timestamp > $tsTimeStamp) {
                                 $tsTimeStamp = $timestamp;
                             }
                         }
                     }
                 }
             }
             $this->RootCache['timestamp'] = $tsTimeStamp;
         }
         $key = 'cachecontexts';
         if ($this->HasRestoredCache or eZTranslationCache::canRestoreCache($key, $tsTimeStamp)) {
             eZDebug::accumulatorStart('tstranslator_cache_load', 'tstranslator', 'TS cache load');
             if (!$this->HasRestoredCache) {
                 if (!eZTranslationCache::restoreCache($key)) {
                     $this->BuildCache = true;
                 }
                 $contexts = eZTranslationCache::contextCache($key);
                 if (!is_array($contexts)) {
                     $contexts = array();
                 }
                 $this->HasRestoredCache = $contexts;
             } else {
                 $contexts = $this->HasRestoredCache;
             }
             if (!$this->BuildCache) {
                 $contextName = $requestedContext;
                 if (!isset($this->CachedMessages[$contextName])) {
                     eZDebug::accumulatorStart('tstranslator_context_load', 'tstranslator', 'TS context load');
                     if (eZTranslationCache::canRestoreCache($contextName, $tsTimeStamp)) {
                         if (!eZTranslationCache::restoreCache($contextName)) {
                             $this->BuildCache = true;
                         }
                         $this->CachedMessages[$contextName] = eZTranslationCache::contextCache($contextName);
                         foreach ($this->CachedMessages[$contextName] as $key => $msg) {
                             $this->Messages[$key] = $msg;
                         }
                     }
                     eZDebug::accumulatorStop('tstranslator_context_load');
                 }
             }
             eZDebugSetting::writeNotice('i18n-tstranslator', "Loading cached translation", __METHOD__);
             eZDebug::accumulatorStop('tstranslator_cache_load');
             if (!$this->BuildCache) {
                 return true;
             }
         }
         eZDebugSetting::writeNotice('i18n-tstranslator', "Translation cache has expired. Will rebuild it from source.", __METHOD__);
         $this->BuildCache = true;
     }
     $status = false;
     // first process country translation files
     // then process country variation translation files
     $localeParts = explode('@', $locale);
     $triedPaths = array();
     $loadedPaths = array();
     $ini = eZINI::instance("i18n.ini");
     $fallbacks = $ini->variable('TranslationSettings', 'FallbackLanguages');
     foreach ($localeParts as $localePart) {
         $localeCodeToProcess = isset($localeCodeToProcess) ? $localeCodeToProcess . '@' . $localePart : $localePart;
         // array with alternative subdirs to check
         $alternatives = array(array($localeCodeToProcess, $charset, $filename), array($localeCodeToProcess, $filename));
         if (isset($fallbacks[$localeCodeToProcess]) && $fallbacks[$localeCodeToProcess]) {
             if ($fallbacks[$localeCodeToProcess] === 'eng-GB') {
                 $fallbacks[$localeCodeToProcess] = 'untranslated';
             }
             $alternatives[] = array($fallbacks[$localeCodeToProcess], $charset, $filename);
             $alternatives[] = array($fallbacks[$localeCodeToProcess], $filename);
         }
         foreach ($roots as $root) {
             if (!file_exists($root)) {
                 continue;
             }
             unset($path);
             foreach ($alternatives as $alternative) {
                 $pathParts = $alternative;
                 array_unshift($pathParts, $root);
                 $pathToTry = eZDir::path($pathParts);
                 $triedPaths[] = $pathToTry;
                 if (file_exists($pathToTry)) {
                     $path = $pathToTry;
                     break;
                 }
             }
             if (!isset($path)) {
                 continue;
             }
             eZDebug::accumulatorStart('tstranslator_load', 'tstranslator', 'TS load');
             $doc = new DOMDocument('1.0', 'utf-8');
             $success = $doc->load($path);
             if (!$success) {
                 eZDebug::writeWarning("Unable to load XML from file {$path}", __METHOD__);
                 continue;
             }
             if (!$this->validateDOMTree($doc)) {
                 eZDebug::writeWarning("XML text for file {$path} did not validate", __METHOD__);
                 continue;
             }
             $loadedPaths[] = $path;
             $status = true;
             $treeRoot = $doc->documentElement;
             $children = $treeRoot->childNodes;
             for ($i = 0; $i < $children->length; $i++) {
                 $child = $children->item($i);
                 if ($child->nodeType == XML_ELEMENT_NODE) {
                     if ($child->tagName == "context") {
                         $this->handleContextNode($child);
                     }
                 }
             }
             eZDebug::accumulatorStop('tstranslator_load');
         }
     }
     eZDebugSetting::writeDebug('i18n-tstranslator', implode(PHP_EOL, $triedPaths), __METHOD__ . ': tried paths');
     eZDebugSetting::writeDebug('i18n-tstranslator', implode(PHP_EOL, $loadedPaths), __METHOD__ . ': loaded paths');
     // Save translation cache
     if ($this->UseCache == true && $this->BuildCache == true) {
         eZDebug::accumulatorStart('tstranslator_store_cache', 'tstranslator', 'TS store cache');
         if (eZTranslationCache::contextCache('cachecontexts') == null) {
             $contexts = array_keys($this->CachedMessages);
             eZTranslationCache::setContextCache('cachecontexts', $contexts);
             eZTranslationCache::storeCache('cachecontexts');
             $this->HasRestoredCache = $contexts;
         }
         foreach ($this->CachedMessages as $contextName => $context) {
             if (eZTranslationCache::contextCache($contextName) == null) {
                 eZTranslationCache::setContextCache($contextName, $context);
             }
             eZTranslationCache::storeCache($contextName);
         }
         $this->BuildCache = false;
         eZDebug::accumulatorStop('tstranslator_store_cache');
     }
     return $status;
 }
 /**
  * clean up subscription after updating comment
  * @see extension/ezcomments/classes/ezcomCommentManager#afterUpdatingComment($comment, $notified)
  */
 public function afterUpdatingComment($comment, $notified, $time)
 {
     $user = eZUser::fetch($comment->attribute('user_id'));
     // if notified is true, add subscription, else cleanup the subscription on the user and content
     $contentID = $comment->attribute('contentobject_id');
     $languageID = $comment->attribute('language_id');
     $subscriptionType = 'ezcomcomment';
     if (!is_null($notified)) {
         $subscriptionManager = ezcomSubscriptionManager::instance();
         if ($notified === true) {
             //add subscription but not send activation
             try {
                 $subscriptionManager->addSubscription($comment->attribute('email'), $user, $contentID, $languageID, $subscriptionType, $time, false);
             } catch (Exception $e) {
                 eZDebug::writeError($e->getMessage(), __METHOD__);
                 switch ($e->getCode()) {
                     case ezcomSubscriptionManager::ERROR_SUBSCRIBER_DISABLED:
                         return 'The subscriber is disabled.';
                     default:
                         return false;
                 }
             }
         } else {
             $subscriptionManager->deleteSubscription($comment->attribute('email'), $comment->attribute('contentobject_id'), $comment->attribute('language_id'));
         }
     }
     //3. update queue. If there is subscription, add one record into queue table
     // if there is subcription on this content, add one item into queue
     if (ezcomSubscription::exists($contentID, $languageID, $subscriptionType)) {
         $notification = ezcomNotification::create();
         $notification->setAttribute('contentobject_id', $comment->attribute('contentobject_id'));
         $notification->setAttribute('language_id', $comment->attribute('language_id'));
         $notification->setAttribute('comment_id', $comment->attribute('id'));
         $notification->store();
         eZDebugSetting::writeNotice('extension-ezcomments', 'There are subscriptions, added an update notification to the queue.', __METHOD__);
     } else {
         // todo: if there is no subscription on this content, consider to clean up the queue
     }
     return true;
 }
 /**
  * Add an subscription. If the subscriber is disabled, throw an exception
  * If there is no subscriber, add one.
  * If there is no subscription for the content, add one
  * @param $email: user's email
  * @return void
  */
 public function addSubscription($email, $user, $contentID, $languageID, $subscriptionType, $currentTime, $activate = true)
 {
     //1. insert into subscriber
     $ezcommentsINI = eZINI::instance('ezcomments.ini');
     $subscriber = ezcomSubscriber::fetchByEmail($email);
     //if there is no data in subscriber for same email, save it
     if (is_null($subscriber)) {
         $subscriber = ezcomSubscriber::create();
         $subscriber->setAttribute('user_id', $user->attribute('contentobject_id'));
         $subscriber->setAttribute('email', $email);
         if ($user->isAnonymous()) {
             $util = ezcomUtility::instance();
             $hashString = $util->generateSusbcriberHashString($subscriber);
             $subscriber->setAttribute('hash_string', $hashString);
         }
         $subscriber->store();
         eZDebugSetting::writeNotice('extension-ezcomments', 'Subscriber does not exist, added one', __METHOD__);
         $subscriber = ezcomSubscriber::fetchByEmail($email);
     } else {
         if ($subscriber->attribute('enabled') == false) {
             throw new Exception('Subscription can not be added because the subscriber is disabled.', self::ERROR_SUBSCRIBER_DISABLED);
         }
     }
     //3 insert into subscription table
     // if there is no data in ezcomment_subscription with given contentobject_id and subscriber_id
     $hasSubscription = ezcomSubscription::exists($contentID, $languageID, $subscriptionType, $email);
     if ($hasSubscription === false) {
         $subscription = ezcomSubscription::create();
         $subscription->setAttribute('user_id', $user->attribute('contentobject_id'));
         $subscription->setAttribute('subscriber_id', $subscriber->attribute('id'));
         $subscription->setAttribute('subscription_type', $subscriptionType);
         $subscription->setAttribute('content_id', $contentID);
         $subscription->setAttribute('language_id', $languageID);
         $subscription->setAttribute('subscription_time', $currentTime);
         $defaultActivated = $ezcommentsINI->variable('CommentSettings', 'SubscriptionActivated');
         if ($user->isAnonymous() && $defaultActivated !== 'true' && $activate === true) {
             $subscription->setAttribute('enabled', 0);
             $utility = ezcomUtility::instance();
             $subscription->setAttribute('hash_string', $utility->generateSubscriptionHashString($subscription));
             $subscription->store();
             $result = ezcomSubscriptionManager::sendActivationEmail(eZContentObject::fetch($contentID), $subscriber, $subscription);
             if (!$result) {
                 eZDebug::writeError("Error sending mail to '{$email}'", __METHOD__);
             }
         } else {
             $subscription->setAttribute('enabled', 1);
             $subscription->store();
         }
         eZDebugSetting::writeNotice('extension-ezcomments', 'No existing subscription for this content and user, added one', __METHOD__);
     }
 }
Пример #10
0
 function _fetch_with_format($provider_url_with_args, $format)
 {
     $provider_url_with_args = $this->_add_query_arg('format', $format, $provider_url_with_args);
     if (!self::getDataByUrl($provider_url_with_args, true)) {
         return false;
     }
     $response = self::getDataByUrl($provider_url_with_args);
     eZDebugSetting::writeNotice('ocembed', $provider_url_with_args, __METHOD__);
     if (!$response) {
         return false;
     }
     $parse_method = "_parse_{$format}";
     return $this->{$parse_method}($response);
 }