Пример #1
0
/**
* @desc Muestra el contenido de las secciones editadas y original para su revisión
*/
function reviewEdit()
{
    global $xoopsModule;
    $id = rmc_server_var($_GET, 'id', 0);
    if ($id <= 0) {
        redirectMsg('edits.php', __('You have not specified any section!', 'docs'), 1);
        die;
    }
    $edit = new RDEdit($id);
    if ($edit->isNew()) {
        redirectMsg('edits.php', __('Specified content does not exists!', 'docs'), 1);
        die;
    }
    $sec = new RDSection($edit->getVar('id_sec'));
    if ($sec->isNew()) {
        redirectMsg('edits.php', __('The section indicated by current element does not exists!', 'docs'), 1);
        die;
    }
    // Datos de la Sección
    $section = array('id' => $sec->id(), 'title' => $sec->getVar('title'), 'text' => $sec->getVar('content'), 'link' => $sec->permalink(), 'res' => $sec->getVar('id_res'));
    // Datos de la Edición
    $new_content = array('id' => $edit->id(), 'title' => $edit->getVar('title'), 'text' => $edit->getVar('content'));
    xoops_cp_location("<a href='./'>" . $xoopsModule->name() . "</a> &raquo; <a href='./edits.php'>" . __('Waiting Content', 'docs') . "</a> &raquo; " . sprintf(__('Editing %s', 'docs'), $sec->getVar('title')));
    xoops_cp_header();
    RMTemplate::get()->add_style('admin.css', 'docs');
    include RMEvents::get()->run_event('docs.template.review.waiting', RMTemplate::get()->get_template('admin/rd_reviewedit.php', 'module', 'docs'));
    xoops_cp_footer();
}
Пример #2
0
 /**
  * Get a single section and all his sub sections
  */
 public function get_section_tree($id, RDResource $res, $number = 1, $text = false)
 {
     global $xoopsUser;
     $db = XoopsDatabaseFactory::getDatabaseConnection();
     if (get_class($res) != 'RDResource') {
         return;
     }
     $sql = "SELECT * FROM " . $db->prefix("rd_sections") . " WHERE " . ($res->id() > 0 ? "id_res='" . $res->id() . "' AND" : '') . "\n                id_sec='{$id}'";
     $result = $db->query($sql);
     if ($db->getRowsNum($result) <= 0) {
         return;
     }
     $sec = new RDSection();
     $row = $db->fetchArray($result);
     $sec->assignVars($row);
     $sections[0] = array('id' => $sec->id(), 'title' => $sec->getVar('title'), 'nameid' => $sec->getVar('nameid'), 'jump' => 0, 'link' => $sec->permalink(), 'order' => $sec->getVar('order'), 'author' => $sec->getVar('uid'), 'author_name' => $sec->getVar('uname'), 'created' => $sec->getVar('created'), 'modified' => $sec->getVar('modified'), 'number' => $number, 'comments' => $sec->getVar('comments'), 'edit' => !$xoopsUser ? 0 : ($xoopsUser->isAdmin() ? true : $res->isEditor($xoopsUser->uid())), 'resource' => $sec->getVar('id_res'), 'metas' => $sec->metas());
     if ($text) {
         $sections[0]['content'] = $sec->getVar('content');
     }
     self::sections_tree_index($sec->id(), 1, $res, '', $number, false, $sections, $text);
     return $sections;
 }
Пример #3
0
/**
* @desc Muestra el contenido completo de una sección
*/
function showSection(RDResource &$res, RDSection &$section)
{
    global $xoopsUser, $xoopsModuleConfig, $xoopsOption, $xoopsTpl, $xoopsConfig, $standalone;
    include 'header.php';
    $xoopsTpl->assign('xoops_pagetitle', $section->getVar('title'));
    // Resource data
    $resource = array('id' => $res->id(), 'title' => $res->getVar('title'), 'link' => $res->permalink(), 'reads' => $res->getVar('reads'));
    $res->add_read($res);
    // Navegación de Secciones
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    $sql = "SELECT * FROM " . $db->prefix("rd_sections") . " WHERE id_res='" . $res->id() . "' AND parent = '0' ORDER BY `order`";
    $result = $db->query($sql);
    $i = 1;
    $number = 1;
    $located = false;
    // Check if current position has been located
    while ($row = $db->fetchArray($result)) {
        $sec = new RDSection();
        $sec->assignVars($row);
        if ($sec->id() == $section->id()) {
            $number = $i;
            $located = true;
        }
        if ($sec->id() == $section->id() && isset($sprev)) {
            $prev_section = array('id' => $sprev->id(), 'title' => $sprev->getVar('title'), 'link' => $sprev->permalink());
        }
        if ($number == $i - 1 && $located) {
            $next_section = array('id' => $sec->id(), 'title' => $sec->getVar('title'), 'link' => $sec->permalink());
            break;
        }
        $i++;
        $sprev = $sec;
    }
    $GLOBALS['rd_section_number'] = $number;
    $sections = RDFunctions::get_section_tree($section->id(), $res, $number, true);
    array_walk($sections, 'rd_insert_edit');
    // Check last modification date
    $last_modification = 0;
    foreach ($sections as $sec) {
        if ($sec['modified'] > $last_modification) {
            $last_modification = $sec['modified'];
            $last_author = array('id' => $sec['author'], 'name' => $sec['author_name']);
        }
    }
    // Event
    $sections = RMEvents::get()->run_event('docs.show.section', $sections, $res, $section);
    RMTemplate::get()->add_style('docs.css', 'docs');
    RMTemplate::get()->add_jquery();
    RMTemplate::get()->add_script(XOOPS_URL . '/modules/docs/include/js/docs.js');
    // URLs
    if ($xoopsModuleConfig['permalinks']) {
        /**
         * @todo Generate friendly links
         */
        if (RMFunctions::plugin_installed('topdf')) {
            $pdf_book_url = RDFunctions::url() . '/pdfbook/' . $section->id() . '/';
            $pdf_section_url = RDFunctions::url() . '/pdfsection/' . $section->id() . '/';
        }
        $print_book_url = RDFunctions::url() . '/printbook/' . $section->id() . '/';
        $print_section_url = RDFunctions::url() . '/printsection/' . $section->id() . '/';
        if (RDFunctions::new_resource_allowed($xoopsUser ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS)) {
            $publish_url = RDFunctions::url() . '/publish/';
        }
    } else {
        if (RMFunctions::plugin_installed('topdf')) {
            $pdf_book_url = XOOPS_URL . '/modules/docs/index.php?page=content&amp;id=' . $section->id() . '&amp;action=pdfbook';
            $pdf_section_url = XOOPS_URL . '/modules/docs/index.php?page=content&amp;id=' . $section->id() . '&amp;action=pdfsection';
        }
        $print_book_url = XOOPS_URL . '/modules/docs/index.php?page=content&amp;id=' . $section->id() . '&amp;action=printbook';
        $print_section_url = XOOPS_URL . '/modules/docs/index.php?page=content&amp;id=' . $section->id() . '&amp;action=printsection';
        if (RDFunctions::new_resource_allowed($xoopsUser ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS)) {
            $publish_url = RDFunctions::url() . '/?action=publish';
        }
    }
    // Comments
    RMFunctions::get_comments('docs', 'res=' . $res->id() . '&id=' . $section->id(), 'module', 0);
    RMFunctions::comments_form('docs', 'res=' . $res->id() . '&id=' . $section->id(), 'module', RDPATH . '/class/mywordscontroller.php');
    RDFunctions::breadcrumb();
    RMBreadCrumb::get()->add_crumb($res->getVar('title'), $res->permalink());
    RMBreadCrumb::get()->add_crumb($section->getVar('title'), $section->permalink());
    include RMEvents::get()->run_event('docs.section.template', RMTemplate::get()->get_template('rd_section.php', 'module', 'docs'));
    if ($standalone) {
        RDFunctions::standalone();
    }
    include 'footer.php';
}
Пример #4
0
/**
* @desc Almacena toda la información referente a la sección
**/
function saveSection($edit = 0, $ret = 0)
{
    global $xoopsUser, $xoopsModuleConfig;
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    //Verifica si se proporcionó una publicación para la sección
    if ($res <= 0) {
        redirect_header(RDURL, 1, __('Operation not allowed!', 'docs'));
        die;
    }
    //Verifica si la publicación existe
    $res = new RDResource($res);
    if ($res->isNew()) {
        redirect_header(RDURL, 1, __('Operation not allowed!', 'docs'));
        die;
    }
    //Verificamos si es una publicación aprobada
    if (!$res->getVar('approved')) {
        redirect_header(RDURL, 2, __('This Document has not been approved yet!', 'docs'));
        die;
    }
    // TODO: Crear el link correcto de retorno
    if ($xoopsModuleConfig['permalinks']) {
        $retlink = RDFunctions::url() . '/list/' . $res->getVar('nameid') . '/';
    } else {
        $retlink = RDFunctions::url() . '?page=edit&action=list&res=' . $res->id();
    }
    //Verificamos si el usuario tiene permisos de edicion
    if (!$xoopsUser->uid() == $res->getVar('owner') && !$res->isEditor($xoopsUser->uid()) && !$xoopsUser->isAdmin()) {
        redirect_header(RDURL, 2, __('You can not edit this content!', 'docs'));
        die;
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    if ($edit) {
        //Verifica si la sección es válida
        if ($id == '') {
            redirect_header($retlink, 1, __('Specified section is not valid!', 'docs'));
            die;
        }
        //Comprueba si la sección es existente
        $sec = new RDSection($id);
        if ($sec->isNew()) {
            redirect_header($retlink, 1, __('Specified section does not exists!', 'docs'));
            die;
        }
        //Comprueba que el título de la sección no exista
        $sql = "SELECT COUNT(*) FROM " . $db->prefix('rd_sections') . " WHERE title='{$title}' AND id_res='{$res}' AND id_sec<>" . $sec->id();
        list($num) = $db->fetchRow($db->queryF($sql));
        if ($num > 0) {
            redirect_header($sec->editlink(), 1, __('Already exists another section with same title!', 'docs'));
            die;
        }
        /**
         * Comprobamos si debemos almacenar las ediciones en la
         * tabla temporal o directamente en la tabla de secciones
         */
        if (!$res->getVar('editor_approve') && !$xoopsUser->isAdmin()) {
            $sec = new RDEdit(null, $id_sec);
        }
    } else {
        //Comprueba que el título de la sección no exista
        $sql = "SELECT COUNT(*) FROM " . $db->prefix('rd_sections') . " WHERE title='{$title}' AND id_res='" . $res->id() . "'";
        list($num) = $db->fetchRow($db->queryF($sql));
        if ($num > 0) {
            redirect_header(ah_make_link('publish/' . $res->nameId() . '/'), 1, _MS_AH_ERRTITLE);
            die;
        }
        $sec = new RDSection();
    }
    //Genera $nameid Nombre identificador
    if ($title != $sec->getVar('title')) {
        $found = false;
        $i = 0;
        do {
            $nameid = TextCleaner::getInstance()->sweetstring($title) . ($found ? $i : '');
            $sql = "SELECT COUNT(*) FROM " . $db->prefix('rd_sections') . " WHERE nameid = '{$nameid}'";
            list($num) = $db->fetchRow($db->queryF($sql));
            if ($num > 0) {
                $found = true;
                $i++;
            } else {
                $found = false;
            }
        } while ($found == true);
    }
    if (!$res->getVar('editor_approve') && !$xoopsUser->isAdmin() && !($res->getVar('owner') == $xoopsUser->uid())) {
        $sec->setVar('id_sec', $id);
    }
    $sec->setVar('title', $title);
    $sec->setVar('content', $content);
    $sec->setVar('order', $order);
    $sec->setVar('id_res', $res->id());
    isset($nameid) ? $sec->setVar('nameid', $nameid) : '';
    $sec->setVar('parent', $parent);
    $sec->setVar('uid', $xoopsUser->uid());
    $sec->setVar('uname', $xoopsUser->uname());
    if ($edit) {
        $sec->setVar('modified', time());
    } else {
        $sec->setVar('created', time());
        $sec->setVar('modified', time());
    }
    // Metas
    if ($edit) {
        $sec->clear_metas();
    }
    // Clear all metas
    // Initialize metas array if not exists
    if (!isset($metas)) {
        $metas = array();
    }
    // Get meta key if "select" is visible
    if (isset($meta_name_sel) && $meta_name_sel != '') {
        $meta_name = $meta_name_sel;
    }
    // Add meta to metas array
    if (isset($meta_name) && $meta_name != '') {
        array_push($metas, array('key' => $meta_name, 'value' => $meta_value));
    }
    // Assign metas
    foreach ($metas as $value) {
        $sec->add_meta($value['key'], $value['value']);
    }
    RMEvents::get()->run_event('docs.saving.section', $sec);
    if (!$sec->save()) {
        redirect_header($sec->editlink(), 3, __('Section could not be saved!', 'docs'));
    } else {
        if ($edit) {
            $sec = new RDSection($sec->getVar('id_sec'));
        }
        if ($return == 1) {
            redirect_header($sec->permalink(), 1, __('Database updated successfully!', 'docs'));
        } elseif ($return == 2) {
            redirect_header($sec->editlink(), 1, __('Database updated successfully!', 'docs'));
        } else {
            redirect_header($retlink, 1, __('Database updated successfully!', 'docs'));
        }
    }
}
Пример #5
0
/**
* @desc Formulario de creación y edición de sección
**/
function rd_show_form($edit = 0)
{
    global $xoopsModule, $xoopsConfig, $xoopsSecurity, $xoopsUser, $xoopsModuleConfig, $rmc_config;
    define('RMCSUBLOCATION', 'newresource');
    $id = rmc_server_var($_GET, 'id', 0);
    $parent = rmc_server_var($_GET, 'parent', 0);
    if ($id <= 0) {
        redirectMsg('sections.php?id=' . $id, __('You must select a Document in order to create a new section', 'docs'), 1);
        die;
    }
    // Check if provided Document exists
    global $res;
    $res = new RDResource($id);
    if ($res->isNew()) {
        redirectMsg('sections.php?id=' . $id, __('Specified Document does not exists!', 'docs'), 1);
        die;
    }
    if ($edit) {
        $id_sec = rmc_server_var($_GET, 'sec', 0);
        //Verifica si la sección es válida
        if ($id_sec <= 0) {
            redirectMsg('sections.php?id=' . $id, __('Specify a section to edit', 'docs'), 1);
            die;
        }
        //Comprueba si la sección es existente
        $sec = new RDSection($id_sec);
        if ($sec->isNew()) {
            redirectMsg('sections.php?id=' . $id, __('Specified section does not exists', 'docs'), 1);
            die;
        }
    }
    // Get order
    $order = RDFunctions::order('MAX', $parent, $res->id());
    $order++;
    $rmc_config = RMFunctions::configs();
    $form = new RMForm('', 'frmsec', 'sections.php');
    if ($rmc_config['editor_type'] == 'tiny') {
        $tiny = TinyEditor::getInstance();
        $tiny->add_config('theme_advanced_buttons1', 'rd_refs');
        $tiny->add_config('theme_advanced_buttons1', 'rd_figures');
        $tiny->add_config('theme_advanced_buttons1', 'rd_toc');
    }
    $editor = new RMFormEditor('', 'content', '100%', '300px', $edit ? $rmc_config['editor_type'] == 'tiny' ? $sec->getVar('content') : $sec->getVar('content', 'e') : '', '', 0);
    $usrfield = new RMFormUser('', 'uid', false, $edit ? array($sec->getVar('uid')) : $xoopsUser->getVar('uid'));
    RMTemplate::get()->add_style('admin.css', 'docs');
    RMTemplate::get()->add_script('../include/js/scripts.php?file=metas.js');
    RMTemplate::get()->add_script(RMCURL . '/include/js/jquery.validate.min.js');
    RMTemplate::get()->add_head('<script type="text/javascript">var docsurl = "' . XOOPS_URL . '/modules/docs";</script>');
    RDFunctions::toolbar();
    xoops_cp_location("<a href='./'>" . $xoopsModule->name() . "</a> &raquo; " . ($edit ? __('Edit Section', 'docs') : __('Create Section', 'docs')));
    RMTemplate::get()->assign('xoops_pagetitle', $edit ? __('Edit Section', 'docs') : __('Create Section', 'docs'));
    xoops_cp_header();
    $sections = array();
    RDFunctions::getSectionTree($sections, 0, 0, $id, 'id_sec, title', isset($sec) ? $sec->id() : 0);
    include RMEvents::get()->run_event('docs.get.secform.template', RMTemplate::get()->get_template('admin/rd_sections_form.php', 'module', 'docs'));
    xoops_cp_footer();
}