Exemplo n.º 1
0
 /**
  * Process the request.
  *
  * @param Pluf_HTTP_Request The request
  * @return bool false
  */
 function process_request(&$request)
 {
     // Find which language to use. By priority:
     // A session value with 'pluf_language'
     // A cookie with 'pluf_language'
     // The browser information.
     $lang = false;
     if (!empty($request->session)) {
         $lang = $request->session->getData('pluf_language', false);
         if ($lang and !in_array($lang, Pluf::f('languages', array('en')))) {
             $lang = false;
         }
     }
     if ($lang === false and !empty($request->COOKIE[Pluf::f('lang_cookie', 'pluf_language')])) {
         $lang = $request->COOKIE[Pluf::f('lang_cookie', 'pluf_language')];
         if ($lang and !in_array($lang, Pluf::f('languages', array('en')))) {
             $lang = false;
         }
     }
     if ($lang === false) {
         // will default to 'en'
         $lang = Pluf_Translation::getAcceptedLanguage(Pluf::f('languages', array('en')));
     }
     Pluf_Translation::loadSetLocale($lang);
     $request->language_code = $lang;
     return false;
 }
Exemplo n.º 2
0
 public static function loadSetLocale($lang)
 {
     $GLOBALS['_PX_current_locale'] = $lang;
     setlocale(LC_TIME, array($lang . '.UTF-8', $lang . '_' . strtoupper($lang) . '.UTF-8'));
     if (isset($GLOBALS['_PX_locale'][$lang])) {
         return;
         // We consider that it was already loaded.
     }
     $GLOBALS['_PX_locale'][$lang] = array();
     foreach (Pluf::f('installed_apps') as $app) {
         if (false != ($pofile = Pluf::fileExists($app . '/locale/' . $lang . '/' . strtolower($app) . '.po'))) {
             $GLOBALS['_PX_locale'][$lang] += Pluf_Translation::readPoFile($pofile);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Notify of the update of the review.
  *
  *
  * @param IDF_Conf Current configuration
  * @param bool Creation (true)
  */
 public function notify($conf, $create = true)
 {
     $patch = $this->get_patch();
     $review = $patch->get_review();
     $prj = $review->get_project();
     $to_email = array();
     if ('' != $conf->getVal('review_notification_email', '')) {
         $langs = Pluf::f('languages', array('en'));
         $to_email[] = array($conf->getVal('issues_notification_email'), $langs[0]);
     }
     $current_locale = Pluf_Translation::getLocale();
     $reviewers = $review->getReviewers();
     if (!Pluf_Model_InArray($review->get_submitter(), $reviewers)) {
         $reviewers[] = $review->get_submitter();
     }
     $comments = $patch->getFileComments(array('order' => 'id DESC'));
     $gcomments = $patch->get_comments_list(array('order' => 'id DESC'));
     $context = new Pluf_Template_Context(array('review' => $review, 'patch' => $patch, 'comments' => $comments, 'gcomments' => $gcomments, 'project' => $prj, 'url_base' => Pluf::f('url_base')));
     // build the list of emails and lang
     foreach ($reviewers as $user) {
         $email_lang = array($user->email, $user->language);
         if (!in_array($email_lang, $to_email)) {
             $to_email[] = $email_lang;
         }
     }
     $tmpl = new Pluf_Template('idf/review/review-updated-email.txt');
     foreach ($to_email as $email_lang) {
         Pluf_Translation::loadSetLocale($email_lang[1]);
         $email = new Pluf_Mail(Pluf::f('from_email'), $email_lang[0], sprintf(__('Updated Code Review %s - %s (%s)'), $review->id, $review->summary, $prj->shortname));
         $email->addTextMessage($tmpl->render($context));
         $email->sendMail();
     }
     Pluf_Translation::loadSetLocale($current_locale);
 }
Exemplo n.º 4
0
 /**
  * Notification of change of the object.
  *
  * @param IDF_Conf Current configuration
  * @param bool Creation (true)
  */
 public function notify($conf, $create = true)
 {
     // Now we add to the queue, soon we will push everything in
     // the queue, including email notifications and indexing.
     // Even if the url is empty, we add to the queue as some
     // plugins may want to do something with this information in
     // an asynchronous way.
     $project = $this->get_project();
     $scm = $project->getConf()->getVal('scm', 'git');
     $url = str_replace(array('%p', '%r'), array($project->shortname, $this->scm_id), $conf->getVal('webhook_url', ''));
     $payload = array('to_send' => array('project' => $project->shortname, 'rev' => $this->scm_id, 'scm' => $scm, 'summary' => $this->summary, 'fullmessage' => $this->fullmessage, 'author' => $this->origauthor, 'creation_date' => $this->creation_dtime), 'project_id' => $project->id, 'authkey' => $project->getPostCommitHookKey(), 'url' => $url);
     $item = new IDF_Queue();
     $item->type = 'new_commit';
     $item->payload = $payload;
     $item->create();
     if ('' == $conf->getVal('source_notification_email', '')) {
         return;
     }
     $current_locale = Pluf_Translation::getLocale();
     $langs = Pluf::f('languages', array('en'));
     Pluf_Translation::loadSetLocale($langs[0]);
     $context = new Pluf_Template_Context(array('c' => $this, 'project' => $this->get_project(), 'url_base' => Pluf::f('url_base')));
     $tmpl = new Pluf_Template('idf/source/commit-created-email.txt');
     $text_email = $tmpl->render($context);
     $email = new Pluf_Mail(Pluf::f('from_email'), $conf->getVal('source_notification_email'), sprintf(__('New Commit %s - %s (%s)'), $this->scm_id, $this->summary, $this->get_project()->shortname));
     $email->addTextMessage($text_email);
     $email->sendMail();
     Pluf_Translation::loadSetLocale($current_locale);
 }
Exemplo n.º 5
0
 /**
  * Notification of change of the object.
  *
  * For the moment, only email, but one can add webhooks later.
  *
  * Usage:
  * <pre>
  * $this->notify($conf); // Notify the creation
  * $this->notify($conf, false); // Notify the update of the object
  * </pre>
  *
  * @param IDF_Conf Current configuration
  * @param bool Creation (true)
  */
 public function notify($conf, $create = true)
 {
     $prj = $this->get_project();
     $to_email = array();
     if ('' != $conf->getVal('issues_notification_email', '')) {
         $langs = Pluf::f('languages', array('en'));
         $to_email[] = array($conf->getVal('issues_notification_email'), $langs[0]);
     }
     $current_locale = Pluf_Translation::getLocale();
     $id = '<' . md5($this->id . md5(Pluf::f('secret_key'))) . '@' . Pluf::f('mail_host', 'localhost') . '>';
     if ($create) {
         if (null != $this->get_owner() and $this->owner != $this->submitter) {
             $email_lang = array($this->get_owner()->email, $this->get_owner()->language);
             if (!in_array($email_lang, $to_email)) {
                 $to_email[] = $email_lang;
             }
         }
         $comments = $this->get_comments_list(array('order' => 'id ASC'));
         $context = new Pluf_Template_Context(array('issue' => $this, 'comment' => $comments[0], 'project' => $prj, 'url_base' => Pluf::f('url_base')));
         foreach ($to_email as $email_lang) {
             Pluf_Translation::loadSetLocale($email_lang[1]);
             $email = new Pluf_Mail(Pluf::f('from_email'), $email_lang[0], sprintf(__('Issue %s - %s (%s)'), $this->id, $this->summary, $prj->shortname));
             $tmpl = new Pluf_Template('idf/issues/issue-created-email.txt');
             $email->addTextMessage($tmpl->render($context));
             $email->addHeaders(array('Message-ID' => $id));
             $email->sendMail();
         }
     } else {
         $comments = $this->get_comments_list(array('order' => 'id DESC'));
         $email_sender = '';
         if (isset($comments[0])) {
             $email_sender = $comments[0]->get_submitter()->email;
         }
         foreach ($this->get_interested_list() as $interested) {
             $email_lang = array($interested->email, $interested->language);
             if (!in_array($email_lang, $to_email)) {
                 $to_email[] = $email_lang;
             }
         }
         $email_lang = array($this->get_submitter()->email, $this->get_submitter()->language);
         if (!in_array($email_lang, $to_email)) {
             $to_email[] = $email_lang;
         }
         if (null != $this->get_owner()) {
             $email_lang = array($this->get_owner()->email, $this->get_owner()->language);
             if (!in_array($email_lang, $to_email)) {
                 $to_email[] = $email_lang;
             }
         }
         $context = new Pluf_Template_Context(array('issue' => $this, 'comments' => $comments, 'project' => $prj, 'url_base' => Pluf::f('url_base')));
         foreach ($to_email as $email_lang) {
             if ($email_lang[0] == $email_sender) {
                 continue;
                 // Do not notify the one having created
                 // the comment
             }
             Pluf_Translation::loadSetLocale($email_lang[1]);
             $email = new Pluf_Mail(Pluf::f('from_email'), $email_lang[0], sprintf(__('Updated Issue %s - %s (%s)'), $this->id, $this->summary, $prj->shortname));
             $tmpl = new Pluf_Template('idf/issues/issue-updated-email.txt');
             $email->addTextMessage($tmpl->render($context));
             $email->addHeaders(array('References' => $id));
             $email->sendMail();
         }
     }
     Pluf_Translation::loadSetLocale($current_locale);
 }
Exemplo n.º 6
0
/**
 * Translate the plural form of a string.
 *
 * @param string Singular form of the string.
 * @param string Plural form of the string.
 * @param int Number of elements.
 * @return string Translated string.
 */
function _n($sing, $plur, $n)
{
    $locale = isset($GLOBALS['_PX_current_locale']) ? $GLOBALS['_PX_current_locale'] : 'en';
    if (isset($GLOBALS['_PX_current_locale_plural_form'])) {
        $pform = $GLOBALS['_PX_current_locale_plural_form'];
    } else {
        $pform = Pluf_Translation::getPluralForm($locale);
    }
    $index = Pluf_Translation::$pform($n);
    if (!empty($GLOBALS['_PX_locale'][$locale][$sing . '#' . $plur][$index])) {
        return $GLOBALS['_PX_locale'][$locale][$sing . '#' . $plur][$index];
    }
    // We have no translations or default English
    if ($n == 1) {
        return $sing;
    }
    return $plur;
}
Exemplo n.º 7
0
 /**
  * Notification of change of the object.
  *
  * @param IDF_Conf Current configuration
  * @param bool Creation (true)
  */
 public function notify($conf, $create = true)
 {
     if ('' == $conf->getVal('downloads_notification_email', '')) {
         return;
     }
     $current_locale = Pluf_Translation::getLocale();
     $langs = Pluf::f('languages', array('en'));
     Pluf_Translation::loadSetLocale($langs[0]);
     $context = new Pluf_Template_Context(array('file' => $this, 'urlfile' => $this->getAbsoluteUrl($this->get_project()), 'project' => $this->get_project(), 'tags' => $this->get_tags_list()));
     $tmpl = new Pluf_Template('idf/downloads/download-created-email.txt');
     $text_email = $tmpl->render($context);
     $addresses = explode(',', $conf->getVal('downloads_notification_email'));
     foreach ($addresses as $address) {
         $email = new Pluf_Mail(Pluf::f('from_email'), $address, sprintf(__('New download - %s (%s)'), $this->summary, $this->get_project()->shortname));
         $email->addTextMessage($text_email);
         $email->sendMail();
     }
     Pluf_Translation::loadSetLocale($current_locale);
 }
Exemplo n.º 8
0
 public function notify($conf, $create = true)
 {
     if ('' == $conf->getVal('review_notification_email', '')) {
         return;
     }
     $current_locale = Pluf_Translation::getLocale();
     $langs = Pluf::f('languages', array('en'));
     Pluf_Translation::loadSetLocale($langs[0]);
     $context = new Pluf_Template_Context(array('review' => $this->get_review(), 'patch' => $this, 'comments' => array(), 'project' => $this->get_review()->get_project(), 'url_base' => Pluf::f('url_base')));
     $tmpl = new Pluf_Template('idf/review/review-created-email.txt');
     $text_email = $tmpl->render($context);
     $addresses = explode(';', $conf->getVal('review_notification_email'));
     foreach ($addresses as $address) {
         $email = new Pluf_Mail(Pluf::f('from_email'), $address, sprintf(__('New Code Review %s - %s (%s)'), $this->get_review()->id, $this->get_review()->summary, $this->get_review()->get_project()->shortname));
         $email->addTextMessage($text_email);
         $email->sendMail();
     }
     Pluf_Translation::loadSetLocale($current_locale);
 }
Exemplo n.º 9
0
 /**
  * Notification of change of a WikiPage.
  *
  * The content of a WikiPage is in the IDF_WikiRevision object,
  * this is why we send the notificatin from there. This means that
  * when the create flag is set, this is for the creation of a
  * wikipage and not, for the addition of a new revision.
  *
  * Usage:
  * <pre>
  * $this->notify($conf); // Notify the creation of a wiki page
  * $this->notify($conf, false); // Notify the update of the page
  * </pre>
  *
  * @param IDF_Conf Current configuration
  * @param bool Creation (true)
  */
 public function notify($conf, $create = true)
 {
     if ('' == $conf->getVal('wiki_notification_email', '')) {
         return;
     }
     $current_locale = Pluf_Translation::getLocale();
     $langs = Pluf::f('languages', array('en'));
     Pluf_Translation::loadSetLocale($langs[0]);
     $context = new Pluf_Template_Context(array('page' => $this->get_wikipage(), 'rev' => $this, 'project' => $this->get_wikipage()->get_project(), 'url_base' => Pluf::f('url_base')));
     if ($create) {
         $template = 'idf/wiki/wiki-created-email.txt';
         $title = sprintf(__('New Documentation Page %s - %s (%s)'), $this->get_wikipage()->title, $this->get_wikipage()->summary, $this->get_wikipage()->get_project()->shortname);
     } else {
         $template = 'idf/wiki/wiki-updated-email.txt';
         $title = sprintf(__('Documentation Page Changed %s - %s (%s)'), $this->get_wikipage()->title, $this->get_wikipage()->summary, $this->get_wikipage()->get_project()->shortname);
     }
     $tmpl = new Pluf_Template($template);
     $text_email = $tmpl->render($context);
     $email = new Pluf_Mail(Pluf::f('from_email'), $conf->getVal('wiki_notification_email'), $title);
     $email->addTextMessage($text_email);
     $email->sendMail();
     Pluf_Translation::loadSetLocale($current_locale);
 }