* Goteo 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Goteo. If not, see <http://www.gnu.org/licenses/agpl.txt>. * */ use Goteo\Library\Text, Goteo\Library\Content; $bodyClass = 'admin'; $table = $this['table']; $id = $this['id']; $content = Content::get($table, $id, $_SESSION['translator_lang']); $sizes = array('title' => 'cols="100" rows="2"', 'name' => 'cols="100" rows="1"', 'description' => 'cols="100" rows="4"', 'url' => 'cols="100" rows="1"', 'text' => 'cols="100" rows="10"'); $fields = Content::_fields(); ?> <div class="widget board"> <form action="/translate/<?php echo $table; ?> /edit/<?php echo $id; ?> /<?php echo $this['filter'] . '&page=' . $_GET['page']; ?> " method="post" > <input type="hidden" name="table" value="<?php echo $table; ?>
public function index($table = '', $action = 'list', $id = null, $auxAction = 'list', $contentId = null) { $_SESSION['user']->translangs = Model\User\Translate::getLangs($_SESSION['user']->id); if (empty($_SESSION['user']->translangs)) { Message::Error(Text::_('No tienes ningún idioma, contacta con el administrador')); throw new Redirection('/dashboard'); } if (empty($_SESSION['translate_lang']) || !isset($_SESSION['user']->translangs[$_SESSION['translate_lang']])) { if (count($_SESSION['user']->translangs) > 1 && isset($_SESSION['user']->translangs['en'])) { $_SESSION['translate_lang'] = 'en'; } else { $_SESSION['translate_lang'] = current(array_keys($_SESSION['user']->translangs)); } } if ($table == '') { return new View('view/translate/index.html.php', array('menu' => self::menu())); } // para el breadcrumbs segun el contenido $section = $table == 'news' || $table == 'promote' ? 'home' : 'contents'; // muy especial para traducción de nodo if ($table == 'node') { $BC = self::menu(array('section' => 'node', 'node' => $action, 'option' => $id, 'action' => $auxAction, 'id' => $contentId)); } else { $BC = self::menu(array('section' => $section, 'option' => $table, 'action' => $action, 'id' => $id)); } define('ADMIN_BCPATH', $BC); $errors = array(); // la operación según acción switch ($table) { case 'texts': // comprobamos los filtros $filters = array(); $fields = array('group', 'text', 'pending'); if (!isset($_GET['pending'])) { $_GET['pending'] = 0; } foreach ($fields as $field) { if (isset($_GET[$field])) { $filters[$field] = $_GET[$field]; $_SESSION['translate_filters']['texts'][$field] = (string) $_GET[$field]; } elseif (!empty($_SESSION['translate_filters']['texts'][$field])) { // si no lo tenemos en el get, cogemos de la sesion pero no lo pisamos $filters[$field] = $_SESSION['translate_filters']['texts'][$field]; } } $filter = "?group={$filters['group']}&text={$filters['text']}&pending={$filters['pending']}"; // si llega post, vamos a guardar los cambios if ($action == 'edit' && $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['save'])) { if (Text::save(array('id' => $id, 'text' => $_POST['text'], 'lang' => $_POST['lang']), $errors)) { // Evento Feed /* $log = new Feed(); $log->populate('texto traducido (traductor)', '/translate/texts', \vsprintf('El traductor %s ha %s el texto %s al %s', array( Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('relevant', 'Traducido'), Feed::item('blog', $id), Feed::item('relevant', Lang::get($_POST['lang'])->name) ))); $log->doAdmin('admin'); unset($log); */ Message::Info('Texto <strong>' . $id . '</strong> traducido correctamente al <strong>' . Lang::get($_POST['lang'])->name . '</strong>'); throw new Redirection("/translate/texts/{$filter}&page=" . $_GET['page']); } else { // Evento Feed $log = new Feed(); $log->setTarget($_SESSION['user']->id, 'user'); $log->populate('texto traducido (traductor)', '/translate/texts', \vsprintf('Al traductor %s le ha %s el texto %s al %s', array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('relevant', 'Fallado al traducir'), Feed::item('blog', $id), Feed::item('relevant', Lang::get($_POST['lang'])->name)))); $log->doAdmin('admin'); unset($log); Message::Error('Ha habido algun ERROR al traducir el Texto <strong>' . $id . '</strong> al <strong>' . Lang::get($_POST['lang'])->name . '</strong><br />' . implode('<br />', $errors)); } } // sino, mostramos la lista return new View('view/translate/index.html.php', array('section' => 'texts', 'action' => $action, 'id' => $id, 'filter' => $filter, 'filters' => $filters, 'errors' => $errors)); break; case 'node': // parametros especiales $node = $action; $action = $auxAction; $contentTable = $id; // si llega post, vamos a guardar los cambios if ($action == 'edit' && $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['save'])) { switch ($contentTable) { case 'banner': if (Content::save(array('id' => $contentId, 'table' => $contentTable, 'title' => $_POST['title'], 'description' => $_POST['description'], 'lang' => $_POST['lang']), $errors)) { Message::Info('El Banner <strong>' . $contentId . '</strong> del nodo <strong>' . $node . '</strong> traducido correctamente al <strong>' . Lang::get($_POST['lang'])->name . '</strong>'); throw new Redirection("/translate/node/{$node}/{$contentTable}/list"); } else { Message::Error('Ha habido algun ERROR al traducir el Banner <strong>' . $contentId . '</strong> del nodo <strong>' . $node . '</strong> al <strong>' . Lang::get($_POST['lang'])->name . '</strong><br />' . implode('<br />', $errors)); } break; case 'page': $page = Page::get($contentId, $node); if ($page->update($contentId, $_POST['lang'], $node, $_POST['name'], $_POST['description'], $_POST['content'], $errors)) { Message::Info('La página <strong>' . $contentId . '</strong> del nodo <strong>' . $node . '</strong> traducido correctamente al <strong>' . Lang::get($_POST['lang'])->name . '</strong>'); throw new Redirection("/translate/node/{$node}/{$contentTable}/list"); } else { Message::Error('Ha habido algun ERROR al traducir la página <strong>' . $contentId . '</strong> del nodo <strong>' . $node . '</strong> al <strong>' . Lang::get($_POST['lang'])->name . '</strong><br />' . implode('<br />', $errors)); } break; case 'post': if (Content::save(array('id' => $contentId, 'table' => $contentTable, 'title' => $_POST['title'], 'text' => $_POST['text'], 'legend' => $_POST['legend'], 'lang' => $_POST['lang']), $errors)) { Message::Info('La entrada <strong>' . $contentId . '</strong> del nodo <strong>' . $node . '</strong> traducido correctamente al <strong>' . Lang::get($_POST['lang'])->name . '</strong>'); throw new Redirection("/translate/node/{$node}/{$contentTable}/list"); } else { Message::Error('Ha habido algun ERROR al traducir la Entrada <strong>' . $contentId . '</strong> del nodo <strong>' . $node . '</strong> al <strong>' . Lang::get($_POST['lang'])->name . '</strong><br />' . implode('<br />', $errors)); } break; default: $node = Model\Node::get($node); $node->lang_lang = $_SESSION['translate_lang']; $node->subtitle_lang = $_POST['subtitle']; $node->description_lang = $_POST['description']; if ($node->updateLang($errors)) { Message::Info('La Descripción del nodo <strong>' . $node->id . '</strong> traducido correctamente al <strong>' . Lang::get($_POST['lang'])->name . '</strong>'); throw new Redirection("/translate/node/{$node->id}"); } else { Message::Error('Ha habido algun ERROR al traducir la Descripción del nodo <strong>' . $node->id . '</strong> al <strong>' . Lang::get($_POST['lang'])->name . '</strong><br />' . implode('<br />', $errors)); } } return new View('view/translate/index.html.php', array('section' => 'node', 'action' => 'edit_' . $contentTable, 'option' => $contentTable, 'id' => $contentId, 'node' => $node)); } elseif ($action == 'edit') { return new View('view/translate/index.html.php', array('section' => 'node', 'action' => 'edit_' . $contentTable, 'option' => $contentTable, 'id' => $contentId, 'node' => $node)); } elseif ($contentTable == 'data') { return new View('view/translate/index.html.php', array('section' => 'node', 'action' => 'edit_' . $contentTable, 'option' => $contentTable, 'id' => $node, 'node' => $node)); } else { // sino, mostramos la lista return new View('view/translate/index.html.php', array('section' => 'node', 'action' => 'list_' . $contentTable, 'option' => $contentTable, 'node' => $node)); } break; case 'pages': // si llega post, vamos a guardar los cambios if ($action == 'edit' && $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['save'])) { if (Page::update($id, $_POST['lang'], $_POST['node'], $_POST['name'], $_POST['description'], $_POST['content'], $errors)) { Message::Info('Contenido de la Pagina <strong>' . $id . '</strong> traducido correctamente al <strong>' . Lang::get($_POST['lang'])->name . '</strong>'); throw new Redirection("/translate/pages"); } else { // Evento Feed $log = new Feed(); $log->setTarget($_SESSION['user']->id, 'user'); $log->populate('pagina traducida (traductor)', '/translate/pages', \vsprintf('Al traductor %s le ha %s la página %s del nodo %s al %s', array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('relevant', 'Fallado al traducir'), Feed::item('blog', $id), Feed::item('blog', $_POST['node']), Feed::item('relevant', Lang::get($_POST['lang'])->name)))); $log->doAdmin('admin'); unset($log); Message::Error('Ha habido algun ERROR al traducir el contenido de la pagina <strong>' . $id . '</strong> al <strong>' . Lang::get($_POST['lang'])->name . '</strong><br />' . implode('<br />', $errors)); } } // sino, mostramos la lista return new View('view/translate/index.html.php', array('section' => 'pages', 'action' => $action, 'id' => $id, 'errors' => $errors)); break; default: // comprobamos los filtros $filters = array(); $fields = array('type', 'text', 'pending'); if (!isset($_GET['pending'])) { $_GET['pending'] = 0; } foreach ($fields as $field) { if (isset($_GET[$field])) { $filters[$field] = $_GET[$field]; $_SESSION['translate_filters']['contents'][$field] = (string) $_GET[$field]; } elseif (!empty($_SESSION['translate_filters']['contents'][$field])) { // si no lo tenemos en el get, cogemos de la sesion pero no lo pisamos $filters[$field] = $_SESSION['translate_filters']['contents'][$field]; } } $filter = "?type={$filters['type']}&text={$filters['text']}&pending={$filters['pending']}"; // si llega post, vamos a guardar los cambios if ($action == 'edit' && $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['save'])) { if (!in_array($table, \array_keys(Content::_tables()))) { $errors[] = Text::_("Tabla ") . $table . Text::_(" desconocida"); break; } if (Content::save($_POST, $errors)) { // Evento Feed /* $log = new Feed(); $log->populate('contenido traducido (traductor)', '/translate/'.$table, \vsprintf('El traductor %s ha %s el contenido del registro %s de la tabla %s al %s', array( Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('relevant', 'Traducido'), Feed::item('blog', $id), Feed::item('blog', $table), Feed::item('relevant', Lang::get($_SESSION['translate_lang'])->name) ))); $log->doAdmin('admin'); unset($log); */ Message::Info('Contenido del registro <strong>' . $id . '</strong> de la tabla <strong>' . $table . '</strong> traducido correctamente al <strong>' . Lang::get($_POST['lang'])->name . '</strong>'); if (isset($_SESSION['translate_node'])) { throw new Redirection('/dashboard/translates/' . $table . 's'); } throw new Redirection("/translate/{$table}/{$filter}&page=" . $_GET['page']); } else { // Evento Feed $log = new Feed(); $log->setTarget($_SESSION['user']->id, 'user'); $log->populate('contenido traducido (traductor)', '/translate/' . $table, \vsprintf('El traductor %s le ha %s el contenido del registro %s de la tabla %s al %s', array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('relevant', 'Fallado al traducir'), Feed::item('blog', $id), Feed::item('blog', $table), Feed::item('relevant', Lang::get($_SESSION['translate_lang'])->name)))); $log->doAdmin('admin'); unset($log); Message::Error('Ha habido algun ERROR al traducir el contenido del registro <strong>' . $id . '</strong> de la tabla <strong>' . $table . '</strong> al <strong>' . Lang::get($_POST['lang'])->name . '</strong><br />' . implode('<br />', $errors)); } } // sino, mostramos la lista return new View('view/translate/index.html.php', array('section' => 'contents', 'action' => $action, 'table' => $table, 'id' => $id, 'filter' => $filter, 'filters' => $filters, 'errors' => $errors)); } // si no pasa nada de esto, a la portada return new View('view/translate/index.html.php', array('menu' => self::menu())); }
//recolocamos los post para la paginacion $list = array(); foreach ($data['pending'] as $key=>$item) { $item->pendiente = 1; $list[] = $item; } foreach ($data['ready'] as $key=>$item) { $item->pendiente = 0; $list[] = $item; } $pagedResults = new \Paginated($list, 20, isset($_GET['page']) ? $_GET['page'] : 1); // valores de filtro $fields = Content::_fields(); // por tipo de campo $types = $fields[$table]; // metemos el todos \array_unshift($types, Text::_('Todos los tipos')); ?> <!-- Filtro --> <div class="widget board"> <form id="filter-form" action="/translate/<?php echo $table ?>/list/<?php echo $filter ?>" method="get"> <input type="hidden" name="table" value="<?php echo $table ?>" /> <label for="filter-<?php echo $id; ?>"><?php echo Text::get('dashboard-translate_filter'); ?></label> <select id="filter-<?php echo $id; ?>" name="<?php echo $id; ?>" onchange="document.getElementById('filter-form').submit();"> <?php foreach ($types as $val=>$opt) : ?> <option value="<?php echo $val; ?>"<?php if ($this['filters']['type'] == $val) echo ' selected="selected"';?>><?php echo $opt; ?></option>