示例#1
0
    /**
     * Save translations into file
     *
     * @return void
     */
    public function save()
    {
        $post = \Sifo\FilterPost::getInstance();
        if ($post->isSent('save')) {
            $translations = $post->getArray("translations");
            //if ( is_array( $translations ) ) sort($translations);
            $instance = $post->getString('instance');
            $language_file = $post->getString('language');
            foreach ($translations as $index => $translation) {
                if ($translation["translation"] != '') {
                    $translated_keys[] = $translation;
                }
            }
            if (is_array($translated_keys)) {
                $this->natksort($translated_keys);
                $file = fopen(ROOT_PATH . '/instances/' . $instance . '/' . 'locale/' . $language_file, 'w+');
                fwrite($file, '<?php

namespace Common;' . "\n");
                foreach ($translated_keys as $index => $translation) {
                    if ($translation["translation"] != '') {
                        if (get_magic_quotes_gpc()) {
                            $text = '$translations["' . str_replace("\\'", "'", $translation["key"]) . '"] = "' . str_replace("\\'", "'", $translation["translation"]) . '";' . "\n";
                        } else {
                            $text = '$translations["' . str_replace('"', '\\"', $translation["key"]) . '"] = "' . str_replace('"', '\\"', $translation["translation"]) . '";' . "\n";
                        }
                        fwrite($file, $text);
                    }
                }
                fwrite($file, '?>');
                fclose($file);
            }
            $params = $this->getParams();
            throw new \SifoException_302($params['url']['locales'] . ':saved-true:i:' . $instance . ':l:' . $language_file);
        } else {
            $params = $this->getParams();
            if (isset($params) && isset($params["parsed_params"]["instance"]) && isset($params["parsed_params"]["new_language"])) {
                $file = fopen(ROOT_PATH . '/instances/' . $params["parsed_params"]["instance"] . '/' . 'locale/' . $params["parsed_params"]["new_language"], 'w+');
                if ($file) {
                    fwrite($file, '<?php

namespace Common;' . "\n");
                    fclose($file);
                }
                throw new \SifoException_302($params['url']['locales'] . ':created-true:i:' . $params["parsed_params"]["instance"]);
            }
        }
    }
示例#2
0
 /**
  * Customize translation.
  * @return mixed
  */
 protected function customizeTranslation()
 {
     $message = \Sifo\FilterPost::getInstance()->getString('msgid');
     $id_message = null;
     if (is_numeric($message)) {
         $id_message = $message;
     }
     $instance = $this->getParsedParam('instance');
     $translator_model = new I18nTranslatorModel();
     $id_message = $translator_model->getTranslation($message, $id_message);
     $result = array('status' => 'KO', 'msg' => 'This Message or ID doesn\'t exist.');
     if ($id_message) {
         $result = array('status' => 'OK', 'msg' => 'Message successfully customized.');
         if (!$translator_model->customizeTranslation($id_message, $instance)) {
             $result = array('status' => 'KO', 'msg' => 'This message is already customized in this instance.');
         }
     }
     return $result;
 }
示例#3
0
 /**
  * Because this class is extending from SharedFirstLevelController instead of Controller,
  * some modules are executed in first place, like: head, header or footer.
  *
  * See template for inclusion.
  */
 public function buildCommon()
 {
     $filtering_post = \Sifo\FilterPost::getInstance();
     // EXAMPLE OF HOW MODULES WORK. Add an advertising module:
     $this->addModule('ads_google_skyscrapper', 'SharedAdvertising');
     // TEST FORM SENT
     if ($filtering_post->isSent('testform')) {
         $form = \Sifo\Form::getInstance($filtering_post);
         if (!$form->validateElements('forms/example.form')) {
             // Basic validation: The data sent has an invalid form.
             $errors = $form->getErrors();
             \Sifo\FlashMessages::set($errors, \Sifo\FlashMessages::MSG_KO);
         } else {
             \Sifo\FlashMessages::set("Validated data. Mai inglish is parfect!", \Sifo\FlashMessages::MSG_OK);
         }
         $this->assign("form_fields", $form->getFields());
     }
     // INVITE  SENT
     if ($filtering_post->isSent('inviteform')) {
         if (($account_email = $filtering_post->getEmail('account_email')) && ($account_password = $filtering_post->getString('account_password'))) {
             if (strstr($account_email, '@yahoo.') || strstr($account_email, '@ymail.')) {
                 $account_provider = 'yahoo';
             } elseif (strstr($account_email, '@hotmail.') || strstr($account_email, '@live.') || strstr($account_email, '@msn.')) {
                 $account_provider = 'hotmail';
             } else {
                 $account_provider = 'gmail';
             }
         }
     }
     $smileys = array(':-)', ':-(', '¬¬', 'xD', ':_(', ':-0', '=)');
     // Set a system message
     \Sifo\FlashMessages::set('<strong>Installation correct!</strong> <small>(This is an example OK message.)</small>', \Sifo\FlashMessages::MSG_OK);
     //\Sifo\FlashMessages::set( 'Installation failed!', \Sifo\FlashMessages::MSG_KO );
     //\Sifo\FlashMessages::set( 'For your information...!', \Sifo\FlashMessages::MSG_INFO );
     //\Sifo\FlashMessages::set( 'Your account is incomplete', \Sifo\FlashMessages::MSG_WARNING );
     // Same message translated (include the message in messages_xx_XX.config.php first):
     // \Sifo\FlashMessages::set( $this->translate( 'Installation correct!' ) );
     // Same message translated with variable strings
     // \Sifo\FlashMessages::set( $this->translate( 'Installation correct! %1', $var1 ) );
     // Pass to the template a random smiley:
     $rand = array_rand($smileys, 1);
     $this->assign('mood', $smileys[$rand]);
     // Parameters in the application
     // var_dump( $this->getParams() );
     // SAMPLE: Get data from the database without a \SifoModel:
     // $this->assign( 'data', Db::getInstance()->getAll( 'SELECT * FROM accounts where id_account < ?', 20 ) );
     // With a \Sifo\Model
     // $user = new UserDataModel();
     // $user->getMyDataInsideMyClass();
     // Add another module (execute a controller and capture the output)
     // $this->addModule( 'name_used_in_tpl', 'Class' );
     // Add pagination
     // @See:  Quick reference for usage in pagination class.
     $pagination = new Pagination();
     $pagination->setNumTotalResults(2500);
     // Set total number of items
     $pagination->setCurrentPage(5);
     // Set current page.
     $pagination->setUrlBase('http://www.test.com/pag');
     // Set url base & template.
     $pagination->setTemplate('home/pagination.tpl');
     // Set pagination template.
     // Parameters optionals:
     // $pagination->setItemsPerPage(5);									// Set items per page. By default 10.
     // $pagination->setMaxPages(20);									// Set maxim number of pages to show.
     // $pagination->setTemplateParam( 'title', 'pagination test' );		// Set a parameter assigned to the pagination template.
     // $pagination->setSeparatorLink( '-' );							// Set the default separator for the page link.
     // $pagination->setDisplayItemsPerPage( array( 10, 25, 50, 100 ) );	// Set display items per page.
     // $pagination->setWindowPage( 'default', 20 );						// Set page range ( window ). [ 'default'=> 15,	'short'	=> 12,'very_short'	=> 10]
     // Get pagination data and pass data to the template.
     $result = $pagination->getLinks();
     $this->assign('pagination_data', $result);
     // Note: To show the paginator, you should use the following smarty function in your template: {pagination data=$result}
     $this->setLayout('home/index.tpl');
 }