/** * Esta función permite guardar y publicar un envío */ function savePage($edit = 0) { global $xoopsSecurity, $xoopsUser, $myts, $mc, $xoopsModule; $cat = 0; $url = ''; $texto = ''; foreach ($_POST as $k => $v) { ${$k} = $v; } $q = "op=" . ($edit ? 'edit&id=' . $id : 'new') . "&cat={$cat}&page={$page}"; if ($edit) { if ($id <= 0) { redirectMsg("pages.php?cat={$cat}&page={$page}", __('Page ID has not been provided', 'qpages'), 1); die; } $page = new QPPage($id); if ($page->isNew()) { redirectMsg("pages.php?cat={$cat}&page={$page}", __('Specified page does not exists!', 'qpages'), 1); die; } } else { $page = new QPPage(); } if (!$xoopsSecurity->check()) { redirectMsg("pages.php?{$q}", __('Session token expired!', 'qpages'), 1); die; } if ($titulo == '') { redirectMsg("pages.php?{$q}", __('Title is missing', 'qpages'), 1); die; } if (isset($pretitulo)) { if ($pretitulo != $titulo) { $titulo_amigo = TextCleaner::getInstance()->sweetstring($titulo); } else { $titulo_amigo = $titulo_amigo; } $texto = TextCleaner::getInstance()->specialchars_decode($texto, ENT_QUOTES); } else { $titulo_amigo = $edit ? $titulo_amigo != '' ? $titulo_amigo : TextCleaner::getInstance()->sweetstring($titulo) : TextCleaner::getInstance()->sweetstring($titulo); } if ($texto == '' && $type == 0) { redirectMsg("pages.php?op=new&cat={$cat}&page={$page}", __('Content is missing', 'qpages'), 1); die; } if ($catego <= 0) { redirectMsg("pages.php?op=new&cat={$cat}&page={$page}", __('You must select a category for this page', 'qpages'), 1); die; } if (count($grupos) <= 0) { $grupos = array(0); } /** * Comprobamos que no exista otra página con el mismo título */ $db = XoopsDatabaseFactory::getDatabaseConnection(); $sql = "SELECT COUNT(*) FROM " . $db->prefix("qpages_pages") . " WHERE titulo_amigo='{$titulo_amigo}'"; $sql .= $edit ? " AND id_page<>" . $page->getID() : ''; list($num) = $db->fetchRow($db->query($sql)); if ($num > 0) { $form = new RMForm(__('Review Page', 'qpages'), 'frm-review', 'pages.php'); $form->addElement(new RMFormLabel('', __('A page with same friendly name already exists. Please change the freindly title to prevent errors.', 'qpages'))); foreach ($_POST as $k => $v) { if ($k == 'titulo_amigo') { continue; } if ($k == 'texto') { continue; } if ($k == 'grupos') { continue; } if ($k == 'XOOPS_TOKEN_REQUEST') { continue; } if ($k == 'titulo') { $k = 'pretitulo'; } $hiddens[$k] = $v; } $form->addElement(new RMFormText(__('Title', 'qpages'), 'titulo', 50, 255, $titulo), true); $form->addElement(new RMFormText(__('Friendly title', 'qpages'), 'titulo_amigo', 50, 255, $titulo_amigo), true); $form->addElement(new RMFormHidden('texto', TextCleaner::getInstance()->specialchars($texto, ENT_QUOTES))); foreach ($hiddens as $k => $v) { $form->addElement(new RMFormHidden($k, $v)); } foreach ($grupos as $group) { $form->addElement(new RMFormHidden('grupos[]', $group)); } $ele = new RMFormButtonGroup(); $ele->addButton('sbt', __('Save Page', 'qpages'), 'submit'); $ele->addButton('cancel', __('Cancel', 'qpages'), 'button', 'onclick="history.go(-1);"'); $form->addElement($ele); qpages_toolbar(); xoops_cp_header(); $form->display(); xoops_cp_footer(); die; } #Guardamos los datos del Post $page->setTitle($titulo); $page->setFriendTitle($titulo_amigo); $page->setDate($edit ? $page->getVar('fecha') : time()); $page->setModDate(time()); $page->setText($texto); $page->setCategory($catego); $page->setVar('desc', TextCleaner::getInstance()->clean_disabled_tags($desc)); $page->setGroups($grupos); $page->setHTML(isset($dohtml) ? 1 : 0); $page->setXCode(isset($doxcode) ? 1 : 0); $page->setImage(isset($doimage) ? 1 : 0); $page->setBR(isset($dobr) ? 1 : 0); $page->setSmiley(isset($dosmiley) ? 1 : 0); $page->setUid($xoopsUser->uid()); $page->setType($type); $page->setURL(formatURL($url)); $page->setAccess($acceso); // Add Metas foreach ($meta_name as $k => $v) { $page->add_meta($v, $meta_value[$k]); } $ret = $edit ? $page->update() : $page->save(); if ($ret) { $xoopsUser->incrementPost(); redirectMsg("pages.php?op=" . ($page->type() ? 'editlink' : 'edit') . "&id=" . $page->getID() . "&cat={$cat}&page={$page}", __('Database updated successfully!', 'qpages'), 0); } else { redirectMsg("pages.php?{$q}", __('Errors ocurred while trying to update database', 'qpages') . "<br />" . $page->errors(), 1); } }