Example #1
0
 public function build()
 {
     $params = $this->getParams();
     // Params contain the exception in an array: 'code' => $e->http_code, 'msg' => $e->getMessage(), 'trace' => $e->getTraceAsString()
     switch ($params['code']) {
         // Codes that we have in templates:
         case $params['code'] >= 300 && $params['code'] <= 307:
             $this->setLayout('error/30x_redirect.tpl');
             break;
         case 404:
             $this->setLayout('error/' . $params['code'] . '.tpl');
             break;
         case 401:
         case 403:
             $this->setLayout('error/40x.tpl');
             // Pass the referer for coming back after login:
             $this->assign('referer', $this->params['current_url']);
             break;
         case 500:
             $this->setLayout('error/500.tpl');
             break;
         default:
             $this->setLayout('error/common.tpl');
     }
     // Assign error_code and error_code_msg so we can use it
     // eventually in the template.
     $this->assign('error_code', $params['code']);
     $this->assign('error_code_msg', $params['code_msg']);
     $this->assign('metadata', $this->getErrorMetadata());
     // The error controller should not load modules to prevent major disasters.
     if (\Sifo\Domains::getInstance()->getDebugMode()) {
         $this->assign('error', $params);
     }
 }
Example #2
0
 /**
  * Get Sphinx connection params from config files.
  *
  * @return array
  * @throws Exception_500|Exception_Configuration
  */
 protected function getConnectionParams($profile)
 {
     // The domains.config file has priority, let's fetch it.
     $sphinx_config = \Sifo\Domains::getInstance()->getParam('sphinx');
     if (empty($sphinx_config)) {
         try {
             // If the domains.config doesn't define the params, we use the sphinx.config.
             $sphinx_config = Config::getInstance()->getConfig('sphinx');
             if (isset($sphinx_config[$profile])) {
                 $sphinx_config = $sphinx_config[$profile];
             } elseif (isset($sphinx_config['default'])) {
                 // Is using profiles but there isn't the required one.
                 throw new \Sifo\Exception_500("Expected sphinx settings not defined for profile {$profile} in sphinx.config.");
             } else {
                 if (Domains::getInstance()->getDebugMode() === true) {
                     trigger_error("DEPRECATED: You aren't using profiles for your sphinx.config file. Please, define at leat the 'default' one. (This message is only readable with the debug flag enabled)");
                 }
             }
             $sphinx_config['config_file'] = 'sphinx';
         } catch (Exception_Configuration $e) {
             throw new \Sifo\Exception_500('You must define the connection params in sphinx.config or domains.config file');
         }
     } else {
         $sphinx_config['config_file'] = 'domains';
     }
     return $sphinx_config;
 }
Example #3
0
 public function build()
 {
     if (!\Sifo\Domains::getInstance()->getDevMode()) {
         throw new \Sifo\Exception_404('Translation only available while in devel mode');
     }
     $filter = \Sifo\Filter::getInstance();
     // Get instance name.
     $params = $this->getParams();
     $instance = $this->instance;
     if (isset($params['params'][0])) {
         $instance = $params['params'][0];
     }
     $lang = $filter->getString('lang');
     $given_translation = $filter->getUnfiltered('translation');
     $id_message = $filter->getString('id_message');
     $translator_email = !isset($user['email']) ? '' : $user['email'];
     if ($given_translation) {
         // TODO: REMOVE this: Temporal fix until magic quotes is disabled:
         $given_translation = str_replace('\\', '', $given_translation);
         $query = 'REPLACE i18n_translations (id_message, lang, translation,author,instance) VALUES(?,?,?,?,?);';
         $result = \Sifo\Database::getInstance()->Execute($query, array($id_message, $lang, $given_translation, $translator_email, $instance));
         if ($result) {
             return array('status' => 'OK', 'msg' => 'Successfully saved');
         }
     }
     return array('status' => 'KO', 'msg' => 'Failed to save the translation');
 }
Example #4
0
 /**
  * Constructor. Inherits all methods from Smarty.
  */
 public function __construct()
 {
     parent::__construct();
     // Paths definition:
     $templates_path = ROOT_PATH . '/instances/' . Bootstrap::$instance . '/templates/';
     $this->setTemplateDir(ROOT_PATH . '/');
     // The templates are taken using the templates.config.php mappings, under the variable $_tpls.
     $this->setCompileDir($templates_path . '_smarty/compile/');
     $this->setConfigDir($templates_path . '_smarty/configs/');
     $this->setCacheDir($templates_path . '_smarty/cache/');
     // Get the instances inheritance.
     $instance_inheritance = \Sifo\Domains::getInstance()->getInstanceInheritance();
     // If there is inheritance.
     if (is_array($instance_inheritance)) {
         // First the child instance, last the parent instance.
         $instance_inheritance = array_reverse($instance_inheritance);
         foreach ($instance_inheritance as $current_instance) {
             $this->addPluginsDir(ROOT_PATH . '/instances/' . $current_instance . '/templates/' . '_smarty/plugins');
         }
     } else {
         $this->addPluginsDir($templates_path . '_smarty/plugins');
     }
     // Last path is the default smarty plugins directory.
     $this->addPluginsDir(ROOT_PATH . '/libs/Smarty-sifo-plugins');
     // Set this to false to avoid magical parsing of literal blocks without the {literal} tags.
     $this->auto_literal = false;
 }
Example #5
0
 /**
  * Send an email whith debug interruption.
  *
  * @param string $to
  * @param string $subject
  * @param string $body
  * @return boolean
  */
 public function send($to, $subject, $body)
 {
     // Debug advice:
     if (\Sifo\Domains::getInstance()->getDebugMode()) {
         $this->_dispatchMailController($to, $subject, $body);
     }
     return parent::send($to, $subject, $body);
 }
Example #6
0
/**
 * Alias of krumo::dump(). Formatted data dump. No output in production.
 * You need to download Krumo into "libs" first and declare it in "libraries.config.php"
 *
 * @param mixed $data,...
 */
function d($var)
{
    // Enable Krumo only when debug is present.
    if (\Sifo\Domains::getInstance()->getDebugMode()) {
        require_once ROOT_PATH . '/libs/' . \Sifo\Config::getInstance()->getLibrary('krumo') . '/class.krumo.php';
        krumo($var);
    } else {
        return false;
    }
}
Example #7
0
 public function __construct()
 {
     try {
         $this->credentials = \Sifo\Config::getInstance()->getConfig('twitter_oauth', \Sifo\Domains::getInstance()->getDomain());
         parent::__construct($this->credentials['consumer_key'], $this->credentials['consumer_secret']);
         $this->useAsynchronous(true);
         $this->setTimeout($this->credentials['request_timeout'], $this->credentials['connection_timeout']);
     } catch (\Exception $e) {
         throw new \Sifo\Exception_500($e->getMessage());
     }
 }
/**
 * Smarty number_format modifier plugin
 *
 * Type:     modifier<br>
 * Name:     number_format<br>
 * Purpose:  format strings via number_format
 * @author   Albert Lombarte
 * @param string
 * @param string
 * @param string
 * @param string
 * @return string
 */
function smarty_modifier_number_format($string, $decimals = 2)
{
    // Numeric locale vars.
    // Remember to change the size_format modifier if you change the locales management here.
    setlocale(LC_NUMERIC, \Sifo\Domains::getInstance()->getLanguage());
    $locale = localeconv();
    setlocale(LC_NUMERIC, null);
    $thousand_separator = $locale['thousands_sep'] == '' ? '.' : $locale['thousands_sep'];
    $decimal_separator = $locale['decimal_point'];
    return @number_format($string, $decimals, $decimal_separator, $thousand_separator);
}
Example #9
0
 /**
  * Assign a variable to the tpl with the HTML code to load the JS and CSS files.
  */
 protected function assignMedia()
 {
     // On development create all the packed files on the fly:
     if (\Sifo\Domains::getInstance()->getDevMode()) {
         $packer = new \Sifo\JsPacker();
         $packer->packMedia();
         $packer = new \Sifo\CssPacker();
         $packer->packMedia();
     }
     $this->assign('media', \Sifo\Config::getInstance()->getConfig('css'));
     $this->assign('css_groups', $this->css_groups);
     $this->assign('js_groups', $this->js_groups);
     $this->assign('static_rev', $this->getStaticRevision());
     $this->assign('media_module', $this->fetch('shared/media_packer.tpl'));
 }
Example #10
0
 public function build()
 {
     if (!\Sifo\Domains::getInstance()->getDevMode()) {
         throw new \Sifo\Exception_404('Translation only available while in devel mode');
     }
     // Get instance name.
     $params = $this->getParams();
     switch ($params['parsed_params']['action']) {
         case 'addMessage':
             $result = $this->addMessage($params['parsed_params']['instance']);
             break;
         case 'customizeTranslation':
             $result = $this->customizeTranslation();
             break;
     }
     return $result;
 }
Example #11
0
 public function build()
 {
     if (!\Sifo\Domains::getInstance()->getDevMode()) {
         throw new \Sifo\Exception_404('Translation only available while in devel mode');
     }
     $this->addModule('system_messages', 'SharedSystemMessages');
     $this->setLayout('i18n/status.tpl');
     // Instance navigation.
     $current_instance_inheritance = \Sifo\Domains::getInstance()->getInstanceInheritance();
     $this->assign('current_instance_inheritance', $current_instance_inheritance);
     // Get instance name.
     $params = $this->getParams();
     $instance = $this->instance;
     if (isset($params['params'][0])) {
         $instance = $params['params'][0];
     }
     // Get selected instance inheritance.
     $instance_domains = $this->getConfig('domains', $instance);
     $instance_inheritance = array();
     if (isset($instance_domains['instance_inheritance'])) {
         $instance_inheritance = $instance_domains['instance_inheritance'];
     }
     $is_parent_instance = false;
     if (empty($instance_inheritance) || count($instance_inheritance) == 1 && $instance_inheritance[0] == 'common') {
         $is_parent_instance = true;
     }
     $translator = new I18nTranslatorModel();
     $different_languages = $translator->getStats($instance, $is_parent_instance);
     $current_lang = $this->getCurrentLang();
     $translations = false;
     $this->assign('langs', $different_languages);
     // The languages are defined with 5 chars. E.g: es_ES
     if ($current_lang && 5 == strlen($current_lang)) {
         $translations = $translator->getTranslations($current_lang, $instance, $is_parent_instance);
     }
     $this->assign('instance', $instance);
     $this->assign('instance_inheritance', $instance_inheritance);
     $this->assign('is_parent_instance', $is_parent_instance);
     $this->assign('different_languages', $different_languages);
     $this->assign('translations', $translations);
     $this->assign('curr_lang', $current_lang);
     $this->assign('can_edit', $this->canEdit());
     $this->assign('isAdmin', $this->isAdmin());
 }
Example #12
0
 public function build()
 {
     $this->setLayout('manager/findi18n.tpl');
     if (!\Sifo\Domains::getInstance()->getDevMode()) {
         throw new \Sifo\Exception_404('Translation only available while in devel mode');
     }
     $post = \Sifo\Filter::getInstance();
     $available_instances = $this->getFileSystemFiles('instances', true);
     $locales_available = array();
     foreach ($available_instances as $inst) {
         $locales_available[$inst] = $this->getFilesystemFiles("instances/{$inst}/locale");
     }
     $this->assign('instances', $available_instances);
     $this->assign('locales', $locales_available);
     $charset = $post->getString('charset');
     $this->assign('charset', $charset ? $charset : 'utf-8');
     $this->assign('instance', 'common');
     if ($post->isSent('instance')) {
         $instance = $post->getString('instance');
         $locale = $post->getString('locale');
         $temp_lang = explode('_', $locale);
         $this->assign('language', $temp_lang[1]);
         $literals = $this->getLiterals($instance);
         $this->assign('literals', $literals);
         $path = \Sifo\Bootstrap::$application . "/{$instance}";
         $translations_file = "{$path}/locale/{$locale}";
         if (file_exists($translations_file)) {
             include "{$translations_file}";
             $missing = array();
             foreach ($literals as $key => $relative_path) {
                 if (!isset($translations[$key])) {
                     $missing[$key] = $relative_path;
                 }
             }
             $this->assign('missing', $missing);
             $this->assign('instance', $instance);
             $this->assign('locale', $locale);
         } else {
             $this->assign('error', "File {$locale} not available for <strong>{$instance}</strong>");
         }
     }
 }
Example #13
0
/**
 * Smarty time_format modifier plugin.
 *
 * Type:     modifier<br>
 * Name:     time_format<br>
 * Purpose:  format times directly from DB.
 *
 * @param integer $time Time given in ms.
 * @param integer $decimals Number of decimals.
 * @return string
 */
function smarty_modifier_time_format($time, $decimals = 3)
{
    // Numeric locale vars.
    // Remember to change the number_format modifier if you change the locales management here.
    setlocale(LC_NUMERIC, \Sifo\Domains::getInstance()->getLanguage());
    $locale = localeconv();
    setlocale(LC_NUMERIC, null);
    $thousand_separator = $locale['thousands_sep'] == '' ? '.' : $locale['thousands_sep'];
    $decimal_separator = $locale['decimal_point'];
    if (is_null($decimals)) {
        $decimals = 0;
    }
    $time = $time * 1000;
    if ($time < 100) {
        // Miliseconds.
        $formatted_time = number_format($time, $decimals, $decimal_separator, $thousand_separator) . ' milisec';
    } else {
        // Seconds.
        $formatted_time = number_format($time / 1000, $decimals, $decimal_separator, $thousand_separator) . ' sec';
    }
    return $formatted_time;
}
Example #14
0
 public function build()
 {
     if (!\Sifo\Domains::getInstance()->getDebugMode()) {
         throw new \Sifo\Exception_404('Only in debug mode');
     }
     $this->setLayout('debug/mail.tpl');
     if ($this->getParam('current_url') == $this->getUrl('mail-continue')) {
         $this->assign('mail_sent', true);
         $this->assign('result', $this->continueMail());
         if (isset($this->mail_data['return_page'])) {
             $this->assign('return_page', $this->mail_data['return_page']);
         }
     } else {
         $new_mail_data = $this->getParam('mail_data');
         if (\Sifo\FilterServer::getInstance()->getString('HTTP_REFERER')) {
             $new_mail_data['return_page'] = \Sifo\FilterServer::getInstance()->getString('HTTP_REFERER');
         }
         // So it continue by clicking on the link:
         \Sifo\Session::getInstance()->set('mail_data', $new_mail_data);
         $this->assign('mail_data', $new_mail_data);
         $this->assign('continue_sending', $this->getUrl('mail-continue'));
     }
 }
 public function build()
 {
     if (true !== \Sifo\Domains::getInstance()->getDevMode()) {
         throw new \Sifo\Exception_404('User tried to access the rebuild page, but he\'s not in development');
     }
     $get = \Sifo\FilterGet::getInstance();
     if ($this->_selected_template = $get->getString('template')) {
         $this->assign('selected_template', $this->_selected_template);
     }
     $post = \Sifo\Filter::getInstance();
     if ($post_elems = $post->getRawRequest()) {
         if (!$this->_selected_template) {
             trigger_error('Template identifier not found in the current url.', E_USER_ERROR);
         }
         $this->setLayout($this->_selected_template);
         foreach ($post_elems as $key => $elem) {
             if (!empty($elem)) {
                 $elem = false !== stripos($elem, 'array') ? $elem : "'{$elem}'";
                 eval('$var = ' . $elem . ';');
                 // Usefull for $var=dummy and $var=array('k'=>'v');
                 $this->assign($key, $var);
             }
         }
     } else {
         $this->setLayout('manager/tpl_launcher.tpl');
         $this->_available_templates = $this->getAvailableTemplates();
         if (empty($this->_available_templates)) {
             trigger_error("Templates config files is empty. Your instance hasn't available templates yet.", E_USER_WARNING);
         }
         $this->assign('available_templates', array_keys($this->_available_templates));
         if ($this->_selected_template) {
             $used_vars = $this->_getRequiredVars($this->_selected_template);
             $this->assign('used_vars', $used_vars);
         }
     }
 }
Example #16
0
/**
 * Smarty size_format modifier plugin.
 *
 * Type:     modifier<br>
 * Name:     size_format<br>
 * Purpose:  format sizes directly from DB.
 *
 * @param integer $size Size of a file.
 * @param integer $decimals Number of decimals.
 * @return string
 */
function smarty_modifier_size_format($size, $decimals = null)
{
    // Numeric locale vars.
    // Remember to change the number_format modifier if you change the locales management here.
    setlocale(LC_NUMERIC, \Sifo\Domains::getInstance()->getLanguage());
    $locale = localeconv();
    setlocale(LC_NUMERIC, null);
    $thousand_separator = $locale['thousands_sep'] == '' ? '.' : $locale['thousands_sep'];
    $decimal_separator = $locale['decimal_point'];
    if ($size < 1024) {
        if (is_null($decimals)) {
            $decimals = 0;
        }
        // Kilobytes.
        $formatted_size = number_format($size, $decimals, $decimal_separator, $thousand_separator) . ' B';
    } elseif ($size < 1048576) {
        if (is_null($decimals)) {
            $decimals = 0;
        }
        // Kylobytes.
        $formatted_size = number_format($size / 1024, $decimals, $decimal_separator, $thousand_separator) . ' KB';
    } elseif ($size < 1073741824) {
        if (is_null($decimals)) {
            $decimals = 1;
        }
        // Megabytes.
        $formatted_size = number_format($size / 1048576, $decimals, $decimal_separator, $thousand_separator) . ' MB';
    } else {
        if (is_null($decimals)) {
            $decimals = 1;
        }
        // Gigabytes.
        $formatted_size = number_format($size / 1073741824, $decimals, $decimal_separator, $thousand_separator) . ' GB';
    }
    return $formatted_size;
}
Example #17
0
 private function _common_exec()
 {
     foreach ($this->command_options as $option) {
         switch ($option[0]) {
             case "h":
             case "help":
                 $this->showHelp();
                 die;
             case "v":
             case "verbose":
                 $this->_verbose = true;
                 break;
             case "t":
             case "test":
                 $this->test = true;
                 break;
             case "r":
             case "recipient":
                 $this->_recipient = $option[1];
                 break;
             case "f":
             case "force":
                 $this->force = true;
                 break;
             case "dm":
             case "debugmode":
                 $this->params['has_debug'] = (bool) $option[1];
                 \Sifo\Domains::getInstance()->setDebugMode((bool) $option[1]);
                 break;
         }
     }
 }
Example #18
0
 protected function getAvailableFiles($type, $current_instance)
 {
     $d = new \Sifo\Dir();
     $type_files = array();
     $core_inheritance = \Sifo\Domains::getInstance()->getCoreInheritance();
     if ($type == 'core') {
         foreach ($core_inheritance as $corelib) {
             $available_files = $d->getFileListRecursive(ROOT_PATH, '/libs/' . $corelib);
             if (count($available_files) > 0) {
                 foreach ($available_files as $v) {
                     // Allow only extensions PHP, TPL, CONF
                     $desired_file_pattern = preg_match('/\\.(php|tpl|conf)$/i', $v["relative"]);
                     if ($desired_file_pattern) {
                         $rel_path = $this->cleanStartingSlash($v["relative"]);
                         $path = $rel_path;
                         $rel_path = str_replace('libs/' . $corelib . '/', '', $rel_path);
                         $rel_path = str_replace('.php', '', $rel_path);
                         // Default
                         $class = $this->getClassTypeStandarized($rel_path);
                         $type_files[$class]['Sifo'] = $path;
                     }
                 }
             }
         }
     } else {
         $available_files = $d->getFileListRecursive(ROOT_PATH . "/instances/" . $current_instance . "/{$type}");
         if (is_array($available_files) === true && count($available_files) > 0) {
             foreach ($available_files as $k => $v) {
                 $rel_path = $this->cleanStartingSlash($v["relative"]);
                 $path = str_replace('//', '/', "instances/{$current_instance}/{$type}/{$rel_path}");
                 // Calculate the class name for the given file:
                 $rel_path = str_replace('.model.php', '', $rel_path);
                 $rel_path = str_replace('.ctrl.php', '', $rel_path);
                 $rel_path = str_replace('.config.php', '', $rel_path);
                 $rel_path = str_replace('.php', '', $rel_path);
                 // Default
                 $class = $this->getClassTypeStandarized($rel_path);
                 if ('default' != $current_instance) {
                     $class_extended = $class . ucfirst($current_instance);
                 } else {
                     $class_extended = $class;
                 }
                 switch ($type) {
                     case 'controllers':
                         $class .= 'Controller';
                         $type_files[$class][ucfirst($current_instance)] = $path;
                         break;
                     case 'models':
                         $class .= 'Model';
                         $type_files[$class][ucfirst($current_instance)] = $path;
                         break;
                     case 'classes':
                         $type_files[$class][ucfirst($current_instance)] = $path;
                         break;
                     case 'config':
                         if ($rel_path == 'configuration_files') {
                             continue;
                         }
                     case 'templates':
                     default:
                         $type_files[$rel_path] = $path;
                 }
             }
         }
     }
     ksort($type_files);
     return $type_files;
 }
Example #19
0
 /**
  * Initializes the PDO object with the domains.config.php database configuration.
  *
  * @param string $profile The database server to connect to.
  */
 public function __construct($profile)
 {
     $params = Domains::getInstance()->getDatabaseParams();
     $this->db_params = $params[$profile];
     $this->pdo = new PDO("mysql:host={$this->db_params['db_host']};dbname={$this->db_params['db_name']}", $this->db_params['db_user'], $this->db_params['db_password'], $this->db_params['db_init_commands']);
     $class = get_called_class();
     $this->pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, array($class::STATEMENT_CLASS, array($this->pdo, $profile)));
 }
Example #20
0
<?php

// Do not translate:
$config['base'] = $base = \Sifo\Urls::$base_url;
$config['domain'] = $domain = \Sifo\Domains::getInstance()->getDomain();
$config['subdomain'] = $subdomain = \Sifo\Domains::getInstance()->getSubdomain();
$config['lang'] = $subdomain = \Sifo\Domains::getInstance()->getLanguage();
$config['static'] = \Sifo\Domains::getInstance()->getStaticHost();
$config['mail-continue'] = $base . '/mail-continue';
// Translator
$config['translate'] = $base . '/translate';
$config['translations_save'] = $base . '/translation-save';
$config['translations_rebuild'] = $base . '/translation-rebuild';
$config['translations_add'] = $base . '/translations-add';
$config["locales"] = $base . '/locales';
$config["locales_save"] = $base . '/locales-save';
// Translate below:
Example #21
0
<?php

/**
 * This file should define all the properties regarding advertising modules.
 *
 * The key is used as 'module_name'.
 */
// Store the Google client ID, for repetitive usage:
$config['google_client'] = 'pub-XXXXXXXXXXXXXXXX';
// Link analytics with adsense:
$config['google_analytics_domain_name'] = \Sifo\Domains::getInstance()->getDomain();
$config['ads_google_skyscrapper'] = array('google_analytics_domain_name' => $config['google_analytics_domain_name'], 'client' => $config['google_client'], 'comment' => 'Skyscrapper 120x600', 'containter_class' => 'skyscrapper', 'layout' => 'ads/google.tpl', 'slot' => '7567220975', 'width' => 120, 'height' => 600, 'type' => 'text_image', 'colors' => array('border' => 'FFFFFF', 'bg' => 'FFFFFF', 'link' => '085fd6', 'url' => '008000', 'text' => 'CCCCCC'));
$config['ads_google_standard'] = array('google_analytics_domain_name' => $config['google_analytics_domain_name'], 'client' => $config['google_client'], 'comment' => 'Gràfic i text 300x250', 'containter_class' => 'standard_banner', 'layout' => 'ads/google.tpl', 'slot' => '8051831856', 'width' => 300, 'height' => 250, 'type' => 'text_image', 'colors' => array('border' => 'FFFFFF', 'bg' => 'FFFFFF', 'link' => '085fd6', 'url' => '008000', 'text' => 'CCCCCC'));
Example #22
0
 public function build()
 {
     if (!\Sifo\Domains::getInstance()->getDevMode()) {
         throw new \Sifo\Exception_404('Translation only available while in devel mode');
     }
     $translator = new I18nTranslatorModel();
     // Get instance name.
     $params = $this->getParams();
     $instance = $this->instance;
     if (isset($params['params'][0])) {
         $instance = $params['params'][0];
     }
     // Get selected instance inheritance.
     $instance_domains = $this->getConfig('domains', $instance);
     $instance_inheritance = array();
     if (isset($instance_domains['instance_inheritance'])) {
         $instance_inheritance = $instance_domains['instance_inheritance'];
     }
     $is_parent_instance = false;
     if (empty($instance_inheritance) || count($instance_inheritance) == 1 && $instance_inheritance[0] == 'common') {
         $is_parent_instance = true;
     }
     // Get languages.
     $langs_in_DB = $translator->getDifferentLanguages();
     foreach ($langs_in_DB as $l) {
         $language_list[] = $l['l10n'];
     }
     foreach ($language_list as $language) {
         $language_str = $translator->getTranslations($language, $instance, $is_parent_instance);
         foreach ($language_str as $str) {
             $msgid = $str['message'];
             $msgstr = $str['translation'] == null ? '' : $str['translation'];
             $translations[$msgid][$language] = $msgstr;
         }
         unset($language_str);
     }
     ksort($translations);
     $failed = array();
     $result = true;
     foreach ($language_list as $language) {
         $buffer = '';
         $empty_strings_buffer = '';
         $empty[$language] = 0;
         foreach ($translations as $msgid => $msgstr) {
             $msgstr[$language] = isset($msgstr[$language]) ? trim($msgstr[$language]) : null;
             if (!empty($msgstr[$language])) {
                 $item = $this->buildItem($msgid, $msgstr[$language]);
                 $buffer .= $item;
             } else {
                 $item = $this->buildItem($msgid, $msgid);
                 $empty[$language]++;
                 $empty_strings_buffer .= $item;
             }
         }
         // Get instance inheritance.
         $include_parent_instance = $this->getIncludeInheritance($instance, $language);
         $buffer = "<?php\n{$include_parent_instance}\n\n\n// Translations file, lang='{$language}'\n// Empty strings: {$empty[$language]}\n{$empty_strings_buffer}\n// Completed strings:\n{$buffer}\n?>";
         $path = ROOT_PATH . '/instances/' . $instance . '/locale/messages_' . $language . '.php';
         $write = @file_put_contents($path, $buffer);
         if (!$write) {
             $failed[] = $language;
         }
         $result = $result && $write;
     }
     if ($result) {
         return array('status' => 'OK', 'msg' => 'Successfully saved');
     }
     return array('status' => 'KO', 'msg' => 'Failed to save the translation:' . implode("\n", $failed));
 }