Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class AdminLocalesController extends \BaseController {
- public function index()
- {
- $locales = Config::get('language::available_locales');
- return View::make('admin.locales.index', compact('locales'));
- }
- public function edit($id)
- {
- $id = $id; #dont touch it
- if (!in_array($id, array_keys(Config::get('language::available_locales'))))
- die('HAL');
- $default_locale = require_once app_path()."/lang/en/main.php";
- $main_locale = require_once app_path()."/lang/{$id}/auto.php";
- $static_locale_file = app_path()."/lang/{$id}/static.php";
- if (is_file($static_locale_file))
- $static_locale = require_once $static_locale_file;
- return View::make('admin.locales.edit', compact('id', 'default_locale', 'main_locale','static_locale'));
- }
- public function update($id)
- {
- $data = Input::all();
- $data = $data['data'];
- #delete elements with empty string values (including nested)
- foreach ($data as $key => $value)
- {
- if (is_string($value) && trim($value) == '')
- {
- unset($data[$key]);
- }
- elseif (is_array($value))
- {
- foreach ($value as $skey => $svalue)
- {
- if (trim($svalue) == '')
- unset($data[$key][$skey]);
- }
- }
- }
- //remove empty sub-arrays if present
- foreach ($data as $key => $value)
- {
- if (is_array($value) && (count($value) == 0))
- unset($data[$key]);
- }
- $file_contents = "<?php\n return ".var_export($data, TRUE)."?>";
- $static_locale_file = app_path()."/lang/{$id}/static.php";
- if (is_file($static_locale_file))
- copy(app_path()."/lang/{$id}/static.php", app_path()."/lang/{$id}/backup_static.php");
- if(file_put_contents(app_path()."/lang/{$id}/static.php", $file_contents))
- Messagely::flash('success', "Locales seem to be updated");
- else
- Messagely::flash('error', 'File write error');
- return Redirect::to("/admin/locales/");
- }
- public function revert($locale)
- {
- if (copy(app_path()."/lang/{$locale}/backup_static.php", app_path()."/lang/{$locale}/static.php"))
- Messagely::flash('success', "File replaced from backup lang/{$locale}/static.php");
- else
- Messagely::flash('error', 'Copy from backup failed');
- return Redirect::to("/admin/locales/");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement