Esempio n. 1
0
function ltrsymlink()
{
    global $HTTP_POST_VARS, $thisnode, $sess;
    foreach ($HTTP_POST_VARS as $key => $value) {
        if (preg_match('/(.*)?_([0-9]+)/', $key, $erg)) {
            if ($erg[1] == "rename" or $erg[1] == "delete") {
                $method = $erg[1];
                $id = $erg[2];
            }
        }
    }
    if ($id != "" and $method != "") {
        if ($method == "delete") {
            delete_symlink($id);
        } elseif ($method == "rename") {
            if ($HTTP_POST_VARS["field_name-{$id}"] != "") {
                if (level_count($HTTP_POST_VARS["field_name-{$id}"]) > 0) {
                    include "directory/edit/err_invalidslash.html";
                    exit;
                }
                $fullpath = id2path($id);
                rename_symlink($id, parent_path($fullpath) . $HTTP_POST_VARS["field_name-{$id}"] . '/');
            }
        }
    }
    //echo("Location: ".$thisnode['path']."?editmode=1");
    header("Location: " . $sess->url($thisnode['path'] . "?editmode=1"));
    exit;
}
Esempio n. 2
0
function _create_page($page_id)
{
    global $database;
    $link = $database->get_one("SELECT `link` FROM " . TABLE_PREFIX . "pages WHERE page_id = " . $page_id);
    $filename = WB_PATH . PAGES_DIRECTORY . $link . PAGE_EXTENSION;
    $level = level_count($page_id);
    create_access_file($filename, $page_id, $level);
}
 $filename = $row['filename'];
 // Get new order
 //				$position = $order->get_new($parent);
 //				echoh("Position: $position<br>");
 // Work-out if the page parent (if selected) has a seperate template to the default
 $query = "SELECT template FROM " . TABLE_PREFIX . "pages WHERE page_id = '{$parent}'";
 echoh($query . "<br />Module: {$module}<br />");
 $query_parent = $database->query($query);
 if ($query_parent->numRows() > 0) {
     $fetch_parent = $query_parent->fetchRow();
     $template = $fetch_parent['template'];
 } else {
     $template = '';
 }
 // Work out level
 $level = level_count($page_id);
 // Work out root parent
 $root_parent = root_parent($page_id);
 // Work out page trail
 $page_trail = get_page_trail($page_id);
 // Update page with new level and link
 $query = "UPDATE " . TABLE_PREFIX . "pages SET level = '{$level}', root_parent = '{$root_parent}', page_trail = '{$page_trail}', template = '{$template}' WHERE page_id = '{$page_id}'";
 echoh($query . "<br />");
 $database->query($query);
 // Create a new file in the /pages dir
 create_access_file($filename, $page_id, $level);
 /* clean up page order */
 $order = new order(TABLE_PREFIX . 'pages', 'position', 'page_id', 'parent');
 // First clean order
 $order->clean($parent);
 // Get new order for section
 public function createPage($title, $parent, $module, $visibility, $admin_groups, $viewing_groups)
 {
     global $database;
     // admin object initialisieren
     require_once WB_PATH . '/framework/class.admin.php';
     require_once WB_PATH . '/framework/functions.php';
     require_once WB_PATH . '/framework/class.order.php';
     $admin = new admin('Pages', 'pages_add', false, false);
     $title = htmlspecialchars($title);
     // sicherstellen, dass Admin in der Admin-Gruppe und in der Betrachter-Gruppe existiert
     if (!in_array(1, $admin_groups)) {
         $admin_groups[] = 1;
     }
     if (!in_array(1, $viewing_groups)) {
         $viewing_groups[] = 1;
     }
     // Leerer Titel?
     if ($title == '' || substr($title, 0, 1) == '.') {
         $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, kit_error_blank_title));
         return false;
     }
     // pruefen, ob die Seite ueber die erforderlichen Rechte verfuegt
     if (!in_array(1, $admin->get_groups_id())) {
         $admin_perm_ok = false;
         foreach ($admin_groups as $adm_group) {
             if (in_array($adm_group, $admin->get_groups_id())) {
                 $admin_perm_ok = true;
             }
         }
         if ($admin_perm_ok == false) {
             $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, kit_error_insufficient_permissions));
             return false;
         }
         $admin_perm_ok = false;
         foreach ($viewing_groups as $view_group) {
             if (in_array($view_group, $admin->get_groups_id())) {
                 $admin_perm_ok = true;
             }
         }
         if ($admin_perm_ok == false) {
             $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, kit_error_insufficient_permissions));
             return false;
         }
     }
     $admin_groups = implode(',', $admin_groups);
     $viewing_groups = implode(',', $viewing_groups);
     // Dateinamen erstellen
     if ($parent == '0') {
         $link = '/' . page_filename($title);
         // Dateinamen 'index' und 'intro' umbenennen um Kollisionen zu vermeiden
         if ($link == '/index' || $link == '/intro') {
             $link .= '_0';
             $filename = WB_PATH . PAGES_DIRECTORY . '/' . page_filename($title) . '_0' . PAGE_EXTENSION;
         } else {
             $filename = WB_PATH . PAGES_DIRECTORY . '/' . page_filename($title) . PAGE_EXTENSION;
         }
     } else {
         $parent_section = '';
         $parent_titles = array_reverse(get_parent_titles($parent));
         foreach ($parent_titles as $parent_title) {
             $parent_section .= page_filename($parent_title) . '/';
         }
         if ($parent_section == '/') {
             $parent_section = '';
         }
         $page_filename = page_filename($title);
         $page_filename = str_replace('_', '-', $page_filename);
         $link = '/' . $parent_section . $page_filename;
         $filename = WB_PATH . PAGES_DIRECTORY . '/' . $parent_section . $page_filename . PAGE_EXTENSION;
         make_dir(WB_PATH . PAGES_DIRECTORY . '/' . $parent_section);
     }
     // prufen, ob bereits eine Datei mit dem gleichen Dateinamen existiert
     $dbPages = new db_wb_pages();
     $where = array();
     $where[db_wb_pages::field_link] = $link;
     $pages = array();
     if (!$dbPages->sqlSelectRecord($where, $pages)) {
         $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbPages->getError()));
         return false;
     }
     if (sizeof($pages) > 0 || file_exists(WB_PATH . PAGES_DIRECTORY . $link . PAGE_EXTENSION) || file_exists(WB_PATH . PAGES_DIRECTORY . $link . '/')) {
         $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(kit_error_page_exists, $link)));
         return false;
     }
     // include the ordering class
     $order = new order(TABLE_PREFIX . 'pages', 'position', 'page_id', 'parent');
     // clean order
     $order->clean($parent);
     // get the new order
     $position = $order->get_new($parent);
     // Template und Sprache der uebergeordneten Seite ermitteln
     $where = array();
     $where[db_wb_pages::field_page_id] = $parent;
     $pages = array();
     if (!$dbPages->sqlSelectRecord($where, $pages)) {
         $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbPages->getError()));
         return false;
     }
     if (sizeof($pages) > 0) {
         $template = $pages[0][db_wb_pages::field_template];
         $language = $pages[0][db_wb_pages::field_language];
     } else {
         $template = '';
         $language = DEFAULT_LANGUAGE;
     }
     // Neue Seite in Tabelle einfuegen
     $data = array();
     $data[db_wb_pages::field_page_title] = $title;
     $data[db_wb_pages::field_menu_title] = $title;
     $data[db_wb_pages::field_parent] = $parent;
     $data[db_wb_pages::field_template] = $template;
     $data[db_wb_pages::field_target] = '_top';
     $data[db_wb_pages::field_position] = $position;
     $data[db_wb_pages::field_visibility] = $visibility;
     $data[db_wb_pages::field_searching] = 1;
     $data[db_wb_pages::field_menu] = 1;
     $data[db_wb_pages::field_language] = $language;
     $data[db_wb_pages::field_admin_groups] = $admin_groups;
     $data[db_wb_pages::field_viewing_groups] = $viewing_groups;
     $data[db_wb_pages::field_modified_when] = time();
     $data[db_wb_pages::field_modified_by] = $admin->get_user_id();
     $page_id = -1;
     if (!$dbPages->sqlInsertRecord($data, $page_id)) {
         $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbPages->getError()));
         return false;
     }
     // work out the level
     $level = level_count($page_id);
     // work out root parent
     $root_parent = root_parent($page_id);
     // work out page trail
     $page_trail = get_page_trail($page_id);
     $where = array();
     $where[db_wb_pages::field_page_id] = $page_id;
     $data = array();
     $data[db_wb_pages::field_link] = $link;
     $data[db_wb_pages::field_level] = $level;
     $data[db_wb_pages::field_root_parent] = $root_parent;
     $data[db_wb_pages::field_page_trail] = $page_trail;
     if (!$dbPages->sqlUpdateRecord($data, $where)) {
         $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbPages->getError()));
         return false;
     }
     // create a new file in the /pages directory
     create_access_file($filename, $page_id, $level);
     // add position 1 to new page
     $position = 1;
     // add a new record to section table
     $dbSections = new db_wb_sections();
     $data = array();
     $data[db_wb_sections::field_page_id] = $page_id;
     $data[db_wb_sections::field_position] = $position;
     $data[db_wb_sections::field_module] = $module;
     $data[db_wb_sections::field_block] = 1;
     $section_id = -1;
     if (!$dbSections->sqlInsertRecord($data, $section_id)) {
         $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbSections->getError()));
         return false;
     }
     if (file_exists(WB_PATH . '/modules/' . $module . '/add.php')) {
         require WB_PATH . '/modules/' . $module . '/add.php';
     }
     if ($database->is_error()) {
         $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $database->get_error()));
         return false;
     }
     return $page_id;
 }
        if (file_exists(WB_PATH . PAGES_DIRECTORY . $old_link . '/') && is_dir(WB_PATH . PAGES_DIRECTORY . $old_link . '/')) {
            @rename(WB_PATH . PAGES_DIRECTORY . $old_link . '/', WB_PATH . PAGES_DIRECTORY . $link . '/');
        }
        // Update any pages that had the old link with the new one
        $old_link_len = strlen($old_link);
        $sql = 'SELECT `page_id`,`link`,`level` FROM `' . TABLE_PREFIX . 'pages` ' . 'WHERE `link` LIKE \'%' . addcslashes($old_link, '%_') . '/%\' ' . 'ORDER BY `level` ASC';
        if ($query_subs = $database->query($sql)) {
            while ($sub = $query_subs->fetchRow(MYSQLI_ASSOC)) {
                // Double-check to see if it contains old link
                if (substr($sub['link'], 0, $old_link_len) == $old_link) {
                    // Get new link
                    $replace_this = $old_link;
                    $old_sub_link_len = strlen($sub['link']);
                    $new_sub_link = $link . '/' . substr($sub['link'], $old_link_len + 1, $old_sub_link_len);
                    // Work out level
                    $new_sub_level = level_count($sub['page_id']);
                    // Update level and link
                    $sql = 'UPDATE `' . TABLE_PREFIX . 'pages` SET ' . '`link` = \'' . $database->escapeString($new_sub_link) . '\', ' . '`level` = ' . (int) $new_sub_level . ' ' . 'WHERE `page_id` = ' . (int) $sub['page_id'];
                    $database->query($sql);
                    // Re-write the access file for this page
                    $old_subpage_file = WB_PATH . PAGES_DIRECTORY . $new_sub_link . PAGE_EXTENSION;
                    if (file_exists($old_subpage_file)) {
                        @unlink($old_subpage_file);
                    }
                    create_access_file(WB_PATH . PAGES_DIRECTORY . $new_sub_link . PAGE_EXTENSION, $sub['page_id'], $new_sub_level);
                }
            }
        }
    }
}
// Function to fix page trail of subs
Esempio n. 6
0
function create($kat, $title, $description, $pass_language_check = false)
{
    global $sess, $auth, $glob_language_name, $glob_language;
    if (!defined("SPELLING_INC")) {
        include "commonapi/spelling.inc";
    }
    if (!strstr($kat, '/')) {
        $kat = base64_decode($kat);
    }
    $predef['kat'] = $kat;
    $predef['title'] = $title;
    $predef['description'] = $description;
    $title = str_replace(' ', '_', $title);
    $exists = get_node_info($kat . $title);
    $exists = $exists != -1;
    if (strstr($title, '/')) {
        $errfile = "err_invalidslash.html";
        addform($predef, $errfile);
        exit;
    } elseif ($title == "") {
        $errfile = "err_notitle.html";
        addform($predef, $errfile);
        exit;
    } elseif ($description == "") {
        $errfile = "err_nodesc.html";
        addform($predef, $errfile);
        exit;
    } elseif ($exists) {
        $errfile = "err_object_exists.html";
        addform($predef, $errfile);
        exit;
    } elseif (!check_language($description, $glob_language_name) and !$pass_language_check) {
        lang_query($kat, $title, $description);
    } else {
        $title = str_replace(' ', '_', $title);
        $obj['name'] = $kat . $title;
        $obj['parent'] = path2id($kat);
        $obj['level'] = level_count($kat);
        $obj['objecttype'] = "trail";
        $obj['description'] = $description;
        $obj['useraccess'] = 4;
        $obj['friendaccess'] = 12;
        $obj['owner'] = $auth->auth["uid"];
        $obj['language'] = $glob_language;
        add_object($obj, true);
        Header("Location: " . $sess->url(build_good_url($obj['name']) . "?reloadparent=1"));
        exit;
        // echo("Debug: dieses Fenster schliessen");
    }
}
function clone_page($title, $parent, $pagetoclone, $copy_title, $visibility)
{
    // Get objects and vars from outside this function
    global $admin, $template, $database, $TEXT, $PCTEXT, $MESSAGE;
    global $page_id, $section_id;
    // Get page list from database
    $query = "SELECT * FROM `" . TABLE_PREFIX . "pages` WHERE `page_id` = " . $pagetoclone;
    $get_page = $database->query($query);
    $is_page = $get_page->fetchRow(MYSQL_ASSOC);
    // Work-out what the link and page filename should be
    if ($parent == '0') {
        $link = '/' . page_filename($title);
        $filename = WB_PATH . PAGES_DIRECTORY . $link . '.php';
    } else {
        $parent_section = '';
        $parent_titles = array_reverse(get_parent_titles($parent));
        foreach ($parent_titles as $parent_title) {
            $parent_section .= page_filename($parent_title) . '/';
        }
        if ($parent_section == '/') {
            $parent_section = '';
        }
        $link = '/' . $parent_section . page_filename($title);
        $filename = WB_PATH . PAGES_DIRECTORY . '/' . $parent_section . page_filename($title) . '.php';
        make_dir(WB_PATH . PAGES_DIRECTORY . '/' . $parent_section);
    }
    // Check if a page with same page filename exists
    $get_same_page = $database->query("SELECT `page_id` FROM `" . TABLE_PREFIX . "pages` WHERE `link` = '{$link}'");
    if ($get_same_page->numRows() > 0 or file_exists(WB_PATH . PAGES_DIRECTORY . $link . '.php') or file_exists(WB_PATH . PAGES_DIRECTORY . $link . '/')) {
        $admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS'], 'tool_clone.php?pagetoclone=' . $pagetoclone);
    }
    // check the title
    if ($copy_title) {
        $page_title = $is_page['page_title'];
    } else {
        $page_title = $title;
    }
    // Include the ordering class
    $order = new order(TABLE_PREFIX . 'pages', 'position', 'page_id', 'parent');
    // First clean order
    $order->clean($parent);
    // Get new order
    $position = $order->get_new($parent);
    // Insert page into pages table
    $template = $is_page['template'];
    $visibility = $visibility;
    $admin_groups = $is_page['admin_groups'];
    $viewing_groups = $is_page['viewing_groups'];
    $query = "INSERT INTO `" . TABLE_PREFIX . "pages` " . "(`page_title`,`menu_title`,`parent`,`template`,`target`,`position`,`visibility`,`searching`,`menu`,`language`,`admin_groups`,`viewing_groups`,`modified_when`,`modified_by`) VALUES ('" . $database->escapeString($page_title) . "','" . $database->escapeString($title) . "','{$parent}','{$template}','_top','{$position}','{$visibility}','1','1','" . DEFAULT_LANGUAGE . "','{$admin_groups}','{$viewing_groups}','" . time() . "','" . $admin->get_user_id() . "')";
    $database->query($query);
    if ($database->is_error()) {
        $admin->print_error($database->get_error());
    }
    // Get the page id
    $page_id = $database->get_one("SELECT LAST_INSERT_ID()");
    // Work out level
    $level = level_count($page_id);
    // Work out root parent
    $root_parent = root_parent($page_id);
    // Work out page trail
    $page_trail = get_page_trail($page_id);
    // Update page with new level and link
    $database->query("UPDATE `" . TABLE_PREFIX . "pages` SET `link` = '{$link}', `level` = '{$level}', `root_parent` = '{$root_parent}', `page_trail` = '{$page_trail}' WHERE `page_id` = '{$page_id}'");
    // Create a new file in the /pages dir
    create_access_file($filename, $page_id, $level);
    // Make new sections, database
    $query = "SELECT * FROM `" . TABLE_PREFIX . "sections` WHERE `page_id` = '{$pagetoclone}'";
    $get_section = $database->query($query);
    while (false != ($is_section = $get_section->fetchRow(MYSQL_ASSOC))) {
        // Add new record into the sections table
        $from_section = $is_section['section_id'];
        $position = $is_section['position'];
        $module = $is_section['module'];
        $block = $is_section['block'];
        $publ_start = $is_section['publ_start'];
        $publ_end = $is_section['publ_end'];
        $database->query("INSERT INTO `" . TABLE_PREFIX . "sections` (`page_id`,`position`,`module`,`block`,`publ_start`,`publ_end`) VALUES ('{$page_id}','{$position}', '{$module}','{$block}','{$publ_start}','{$publ_end}')");
        // Get the section id
        $section_id = $database->get_one("SELECT LAST_INSERT_ID()");
        require WB_PATH . '/modules/' . $module . '/info.php';
        // Include the selected modules add file if it exists
        if (file_exists(WB_PATH . '/modules/' . $module . '/add.php')) {
            require WB_PATH . '/modules/' . $module . '/add.php';
        }
        // copy module settings per section
        $query = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '%mod_" . $module . "%'";
        $res = $database->query($query);
        while ($row = $res->fetchRow()) {
            // there must be a section_id column at least
            if ($database->query("DESCRIBE {$row['0']} section_id")) {
                clone_lines($row[0], $pagetoclone, $page_id, $from_section, $section_id, $database);
            }
        }
        // some manual corrections that can not be automatically detected
        if ($module == 'miniform') {
            // delete the form submissions which are also copied
            $query = "DELETE FROM " . TABLE_PREFIX . "mod_miniform_data WHERE `section_id` = " . $section_id;
            $database->query($query);
        } elseif ($module == 'mpform') {
            // delete the form submissions which are also copied
            $query = "DELETE FROM " . TABLE_PREFIX . "mod_mpform_submissions WHERE `section_id` = " . $section_id;
            $database->query($query);
            // update refererence to result table
            $query = "UPDATE " . TABLE_PREFIX . "mod_mpform_settings SET `tbl_suffix` = " . $section_id . " WHERE `section_id` = " . $section_id;
            $database->query($query);
            // new results table
            $results = TABLE_PREFIX . "mod_mpform_results_" . $section_id;
            $s = "CREATE TABLE `{$results}` ( `session_id` VARCHAR(20) NOT NULL," . ' `started_when` INT NOT NULL DEFAULT \'0\' ,' . ' `submitted_when` INT NOT NULL DEFAULT \'0\' ,' . ' `referer` VARCHAR( 255 ) NOT NULL, ' . ' PRIMARY KEY ( `session_id` ) ' . ' )';
            $database->query($s);
            $query = "SELECT field_id FROM " . TABLE_PREFIX . "mod_mpform_fields WHERE `section_id` = " . $section_id;
            $ids = $database->query($query);
            while ($fid = $ids->fetchRow()) {
                // Insert new column into database
                $s = "ALTER TABLE `{$results}` add `field" . $fid[0] . "` TEXT NOT NULL";
                $database->query($s);
            }
        } elseif ($module == 'form') {
            // delete the form submissions which are also copied
            $query = "DELETE FROM " . TABLE_PREFIX . "mod_form_submissions WHERE `section_id` = " . $section_id;
            $database->query($query);
        } elseif ($module == 'minigallery') {
            // copy images
            $mediaDir = WB_PATH . MEDIA_DIRECTORY;
            $src = $mediaDir . "/minigallery/{$from_section}";
            $dst = $mediaDir . "/minigallery/{$section_id}";
            recurse_copy($src, $dst);
        }
    }
    return $page_id;
}