public function testFactoryShouldSetADefaultLanguageForUnknownLocales()
 {
     $default_language = new BaseLanguage($this->supportedLanguages, ForgeConfig::get('sys_lang'));
     $default_language->loadLanguage(ForgeConfig::get('sys_lang'));
     $factory = new BaseLanguageFactory();
     $this->assertEqual($default_language, $factory->getBaseLanguage('unknown_locale'));
 }
 private function generateVisibilityOptions()
 {
     $options = array(array('value' => Project::ACCESS_PRIVATE, 'label' => $this->language->getText('project_admin_editgroupinfo', 'private_label'), 'selected' => $this->project_visibility === Project::ACCESS_PRIVATE ? 'selected = "selected"' : ''), array('value' => Project::ACCESS_PUBLIC, 'label' => $this->language->getText('project_admin_editgroupinfo', 'public_label'), 'selected' => $this->project_visibility === Project::ACCESS_PUBLIC ? 'selected = "selected"' : ''));
     if ($this->platform_allows_restricted) {
         $options[] = array('value' => Project::ACCESS_PUBLIC_UNRESTRICTED, 'label' => $this->language->getText('project_admin_editgroupinfo', 'unrestricted_label'), 'selected' => $this->project_visibility === Project::ACCESS_PUBLIC_UNRESTRICTED ? 'selected = "selected"' : '');
     }
     $this->options = $options;
 }
Exemplo n.º 3
0
 /**
  * Instantiate and load a new BaseLanguage
  *
  * @param string $supported_languages The supported languages eg: 'en_US,fr_FR'
  * @param string $locale              The current locale
  *
  * @return BaseLanguage
  */
 protected function createBaseLanguage($locale)
 {
     $currentlocale = setlocale(LC_ALL, '0');
     $language = new BaseLanguage($this->supported_languages, $locale);
     $language->loadLanguage($locale);
     setlocale(LC_ALL, $currentlocale);
     return $language;
 }
 /**
  * Get the html body for notification
  *
  * @param Boolean $is_update    It is an update, not a new artifact
  * @param String  $recipient    The recipient who will receive the notification
  * @param BaseLanguage $language The language of the message
  * @param Boolean $ignore_perms ???
  *
  * @return String
  */
 public function getBodyHtml($is_update, $recipient_user, BaseLanguage $language, $ignore_perms)
 {
     $format = 'html';
     $art = $this->getArtifact();
     $hp = Codendi_HTMLPurifier::instance();
     $followup = '';
     $changes = $this->mailDiffToPrevious($format, $recipient_user, $ignore_perms);
     // Display latest changes (diff)
     if ($comment = $this->getComment()) {
         $followup = $comment->fetchMailFollowUp($format);
     }
     $output = '<table style="width:100%">
         <tr>
             <td align="left" colspan="2">
                 <h1>' . $hp->purify($art->fetchMailTitle($recipient_user, $format, $ignore_perms)) . '
                 </h1>
             </td>
         </tr>';
     if ($followup || $changes) {
         $output .= '<tr>
                 <td colspan="2" align="left">
                     <h2>' . $language->getText('plugin_tracker_artifact_changeset', 'header_html_changeset') . '
                     </h2>
                 </td>
             </tr>';
         // Last comment
         if ($followup) {
             $output .= $followup;
         }
         // Last changes
         if ($changes) {
             //TODO check that the following is PHP compliant (what if I made a changes without a comment? -- comment is null)
             if (!empty($comment->body)) {
                 $output .= '
                     <tr>
                         <td colspan="2">
                             <hr size="1" />
                         </td>
                     </tr>';
             }
             $output .= '<tr>
                     <td> </td>
                     <td align="left">
                         <ul>' . $changes . '
                         </ul>
                     </td>
                 </tr>';
         }
         $artifact_link = get_server_url() . '/plugins/tracker/?aid=' . (int) $art->getId();
         $output .= '<tr>
                 <td> </td>
                 <td align="right">' . $this->fetchHtmlAnswerButton($artifact_link) . '</span>
                 </td>
             </tr>';
     }
     $output .= '</table>';
     //Display of snapshot
     $snapshot = $art->fetchMail($recipient_user, $format, $ignore_perms);
     if ($snapshot) {
         $output .= $snapshot;
     }
     return $output;
 }
Exemplo n.º 5
0
// Instantiate System Event listener
$system_event_manager = SystemEventManager::instance();
//Load plugins
$plugin_manager =& PluginManager::instance();
$plugin_manager->loadPlugins();
$feedback = '';
// Initialize global var
//library to determine browser settings
if (!IS_SCRIPT) {
    require_once 'browser.php';
}
//Language
if (!$GLOBALS['sys_lang']) {
    $GLOBALS['sys_lang'] = "en_US";
}
$Language = new BaseLanguage($GLOBALS['sys_supported_languages'], $GLOBALS['sys_lang']);
//various html utilities
require_once 'utils.php';
//database abstraction
require_once 'database.php';
db_connect();
//security library
require_once 'session.php';
//user functions like get_name, logged_in, etc
require_once 'user.php';
$user_manager = UserManager::instance();
$current_user = $user_manager->getCurrentUser();
//Pass username in order to be written in Apache access_log
if (!IS_SCRIPT) {
    apache_note('username', $current_user->getUnixName());
}
 /**
  * Manage the mail content and send it
  * 
  * @param User    $user
  * @param FRSFile $file
  * @param String  $bodyContent
  * @param Array   $option
  * 
  * @return Boolean
  */
 function sendNotificationMail($user, $file, $bodyContent, $option)
 {
     $mail = new Mail();
     $language = new BaseLanguage($GLOBALS['sys_supported_languages'], $GLOBALS['sys_lang']);
     $language->loadLanguage($user->getLanguageID());
     $subject = $GLOBALS['sys_name'] . ' Error in ' . $file->getFileLocation();
     $mail->setFrom($GLOBALS['sys_noreply']);
     $mail->setBcc($user->getEmail());
     $mail->setSubject($subject);
     $mail->setBody($language->getText('mail_system_event', $bodyContent, $option));
     return $mail->send();
 }
Exemplo n.º 7
0
 function itReturnsFalseWhenTheKeyIsNotPresent()
 {
     $l = new BaseLanguage('en_US,fr_FR', 'en_US');
     $this->assertFalse($l->hasText('common', 'missing_key'));
 }
Exemplo n.º 8
0
 /**
  * Returns a peer instance associated with this om.
  *
  * Since Peer classes are not to have any instance attributes, this method returns the
  * same instance for all member of this class. The method could therefore
  * be static, but this would prevent one from overriding the behavior.
  *
  * @return     LanguagePeer
  */
 public function getPeer()
 {
     if (self::$peer === null) {
         self::$peer = new LanguagePeer();
     }
     return self::$peer;
 }
Exemplo n.º 9
0
 /**
  * Get the date in the user's expected format (depends on its locale)
  *
  * @param BaseLanguage $lang The user's language
  * @param int          $date The timestamp to transform
  * @param bool         $day_only True if display only the date, false if you want the time also
  *
  * @return string
  */
 public static function formatForLanguage(BaseLanguage $lang, $date, $day_only = false)
 {
     if ($day_only) {
         $user_date = format_date($lang->getText('system', 'datefmt_short'), $date, null);
     } else {
         $user_date = format_date($lang->getText('system', 'datefmt'), $date, null);
     }
     return $user_date;
 }
 /**
  * Get the html body for notification
  *
  * @param Tracker_DateReminder $reminder Reminder that will send notifications
  * @param Tracker_Artifact $artifact
  * @param String  $recipient    The recipient who will receive the notification
  * @param BaseLanguage $language The language of the message
  *
  * @return String
  */
 protected function getBodyHtml(Tracker_DateReminder $reminder, Tracker_Artifact $artifact, $recipient, BaseLanguage $language)
 {
     $format = Codendi_Mail_Interface::FORMAT_HTML;
     $hp = Codendi_HTMLPurifier::instance();
     $protocol = $GLOBALS['sys_force_ssl'] ? 'https' : 'http';
     $link = $protocol . '://' . $GLOBALS['sys_default_domain'] . TRACKER_BASE_URL . '/?aid=' . $artifact->getId();
     $output = '<h1>' . $hp->purify($artifact->fetchMailTitle($recipient, $format, false)) . '</h1>' . PHP_EOL;
     $output .= $language->getText('plugin_tracker_date_reminder', 'body_header', array($hp->purify($GLOBALS['sys_name']), $hp->purify($reminder->getField()->getLabel()), $reminder->getFieldValue($artifact)));
     $output .= '<br>';
     $output .= $language->getText('plugin_tracker_date_reminder', 'body_art_html_link', array($link));
     $output .= '<br>';
     return $output;
 }
Exemplo n.º 11
0
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
Exemplo n.º 12
0
 public function rules()
 {
     return array_merge(parent::rules());
 }
Exemplo n.º 13
0
 function testDumpLanguageFile()
 {
     $l = new BaseLanguage('en_US', 'en_US');
     $l->dumpLanguageFile('my_lang', array('module' => array('key' => 'value')));
     $this->assertEqual("<?php\n\$this->text_array['module']['key'] = 'value';\n?>", file_get_contents($GLOBALS['codendi_cache_dir'] . '/lang/my_lang.php'));
 }
 /**
  * Get the html body for notification
  *
  * @param Boolean $is_update    It is an update, not a new artifact
  * @param String  $recipient    The recipient who will receive the notification
  * @param BaseLanguage $language The language of the message
  * @param Boolean $ignore_perms ???
  *
  * @return String
  */
 public function getBodyHtml($is_update, $recipient_user, BaseLanguage $language, $ignore_perms)
 {
     $format = 'html';
     $art = $this->getArtifact();
     $hp = Codendi_HTMLPurifier::instance();
     $output = '<h1>' . $hp->purify($art->fetchMailTitle($recipient_user, $format, $ignore_perms)) . '</h1>' . PHP_EOL;
     $followup = '';
     // Display latest changes (diff)
     if ($comment = $this->getComment()) {
         $followup = $comment->fetchFollowUp($format, true, true);
     }
     $changes = $this->diffToPrevious($format, $recipient_user, $ignore_perms);
     if ($followup || $changes) {
         $output .= '<h2>' . $language->getText('plugin_tracker_artifact_changeset', 'header_html_changeset') . '</h2>';
         $output .= '<div class="tracker_artifact_followup_header">';
         // Last comment
         if ($followup) {
             $output .= $followup . PHP_EOL;
         }
         // Last changes
         if ($changes) {
             //TODO check that the following is PHP compliant (what if I made a changes without a comment? -- comment is null)
             if (!empty($comment->body)) {
                 $output .= '<hr size="1" />';
             }
             $output .= '<ul class="tracker_artifact_followup_changes">';
             $output .= $changes;
             $output .= '</ul>';
         }
         $output .= '</div>' . PHP_EOL;
         $output .= $this->fetchHtmlAnswerButton(get_server_url() . '/plugins/tracker/?aid=' . (int) $art->getId());
     }
     //Display of snapshot
     $snapshot = $art->fetchMail($recipient_user, $format, $ignore_perms);
     if ($snapshot) {
         $output .= $snapshot;
     }
     return $output;
 }
Exemplo n.º 15
0
 * Copyright (c) STMicroelectronics, 2008. All Rights Reserved.
 *
 * Originally written by Manuel Vacelet, 2008
 *
 * This file is a part of Codendi.
 *
 * Codendi is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Codendi is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Codendi; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *
 *
 * Generate pre-analysed language files for each language and theme.
 * The resulting files will be located in $codendi_cache_dir/lang (typically
 * /var/tmp/codendi_cache/lang).
 */
require getenv('CODENDI_LOCAL_INC') ? getenv('CODENDI_LOCAL_INC') : '/etc/codendi/conf/local.inc';
require 'common/language/BaseLanguage.class.php';
$Language = new BaseLanguage($GLOBALS['sys_supported_languages'], $GLOBALS['sys_lang']);
$Language->compileAllLanguageFiles();
$Language->testLanguageFiles();
Exemplo n.º 16
0
 /**
  * Removes object and files from filesystem
  * 
  * @param void
  * @return null
  */
 function delete()
 {
     $delete = parent::delete();
     if ($delete && !is_error($delete)) {
         recursive_rmdir($this->getLocalizationPath(), LOCALIZATION_PATH);
         $user_config_options_table = TABLE_PREFIX . 'user_config_options';
         $rows = db_execute_all("SELECT user_id, value FROM {$user_config_options_table} WHERE name = ?", 'language');
         if (is_foreachable($rows)) {
             $used_by_users = array();
             foreach ($rows as $row) {
                 if (unserialize($row['value']) == $this->getId()) {
                     $used_by_users[] = (int) $row['user_id'];
                 }
                 // if
             }
             // foreach
             if (is_foreachable($used_by_users)) {
                 db_execute("DELETE FROM {$user_config_options_table} WHERE name = ? AND user_id IN (?)", 'language', $used_by_users);
                 cache_remove_by_pattern('user_config_options_*');
             }
             // if
         }
         // if
     }
     // if
     return $delete;
 }