예제 #1
0
 function action_move($args)
 {
     global $manager, $tree, $user, $lang;
     /* Decode argumenst */
     $id = array_shift($args);
     $item =& $tree->getItemById($id);
     $id = $item['id'];
     if (!$tree->_hasRights('admin', $item['rights'])) {
         header('Location: ' . url::item($id));
         exit;
     }
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $parentid = intval($_POST['parent']);
         $position = 0;
         if ($parentid == 0) {
             reset($tree->tree);
             while (list($k, ) = each($tree->tree)) {
                 if ($tree->tree[$k]['id'] != 'admin') {
                     $position = max($position, $tree->tree[$k]['position']);
                 }
             }
         } else {
             if ($parent =& $tree->getItemById($parentid)) {
                 if (isset($parent['children'])) {
                     reset($parent['children']);
                     while (list($k, ) = each($parent['children'])) {
                         $position = max($position, $parent['children'][$k]['position']);
                     }
                 }
             }
         }
         $position++;
         treeStorage::startTransaction();
         treeStorage::prepareForMove($id, $parentid, $_POST['language']);
         sql::query("\r\n\t\t\t\t\tUPDATE \r\n\t\t\t\t\t\t" . _TABLE_PREFIX_ . "contents\r\n\t\t\t\t\tSET \r\n\t\t\t\t\t\t`parent`='" . $parentid . "',\r\n\t\t\t\t\t\t`position`=" . $position . "\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t`ID`='" . $id . "'\r\n\t\t\t\t");
         treeStorage::stopTransaction();
         // Our url needs to be rebuild...
         $url = url::item($id);
         $url = str_replace('/' . $item['meta']['language'] . '/', '/' . $_POST['language'] . '/', $url);
         header("Location: " . $url);
         exit;
     } else {
         @(include _BASE_LIBRARIES_ . 'resources/iso639to3166.php');
         $languages = array();
         $list = new languages(_DEFAULT_SITE_);
         while (list(, $language) = each($list->nodes)) {
             if ($language->public) {
                 $languages[] = array('id' => $language->id, 'name' => $language->name, 'flag' => strtolower($iso639to3166[$language->id]));
             }
         }
         $tpl = new Template($this->getTemplate('move.template'));
         $tpl->set('languages', $languages);
         $tpl->set('id', $id);
         echo $tpl->fetch();
         exit;
     }
 }
예제 #2
0
 function _deleteItem($id)
 {
     global $manager;
     /* Delete pages recursively */
     $res = sql::query("\r\n\t\t\t\tSELECT \r\n\t\t\t\t\t*\r\n\t\t\t\tFROM \r\n\t\t\t\t\t" . _TABLE_PREFIX_ . "contents\r\n\t\t\t\tWHERE \r\n\t\t\t\t\tparent = '" . $id . "'\r\n\t\t\t");
     while ($row = sql::fetch_array($res, MYSQL_ASSOC)) {
         $this->_deleteItem($row['ID']);
     }
     /* Delete the plugin data */
     $delete = array('id' => $id);
     $manager->handleEvent('DeleteItem', $delete);
     /* Delete the revision history */
     revisions::doDeletePage($id);
     /* Delete */
     treeStorage::startTransaction();
     treeStorage::prepareForDelete($id);
     $res = sql::query("\r\n\t\t\t\tDELETE FROM\r\n\t\t\t\t\t" . _TABLE_PREFIX_ . "contents\r\n\t\t\t\tWHERE\r\n\t\t\t\t\tID='" . $id . "'\r\n\t\t\t");
     treeStorage::stopTransaction();
 }
예제 #3
0
 function action_create($args)
 {
     global $manager, $tree, $user, $lang;
     /* Decode argumenst */
     $id = array_shift($args);
     $item =& $tree->getItemById($id);
     $id = $item['id'];
     if (!$tree->_hasRights('create', $item['rights'])) {
         header('Location: ' . url::item($id));
         exit;
     }
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         // Determine the type of the page
         $type = $_POST['childtype'];
         if (isset($_POST['location']) && $_POST['location'] == 'sibling') {
             // Overwrite the type of the page
             $type = $_POST['siblingtype'];
             if ($item['parent'] > 0) {
                 // Set the item to its parent an continue...
                 $item =& $tree->getItemById($item['parent']);
             } else {
                 $position = 0;
                 reset($tree->tree);
                 while (list($k, ) = each($tree->tree)) {
                     if ($tree->tree[$k]['id'] != 'admin') {
                         $position = max($position, $tree->tree[$k]['position']);
                     }
                 }
                 $position++;
                 if (isset($_POST['language'])) {
                     $language = $_POST['language'];
                 } else {
                     $language = $tree->language;
                 }
                 if (isset($_POST['name'])) {
                     $name = $_POST['name'];
                 } else {
                     $name = $user->lang->s('untitled');
                 }
                 $slug = strtolower($name);
                 $slug = preg_replace('/(\\s+|_)/i', '-', $slug);
                 $slug = preg_replace('/[^a-z0-9\\-]/i', '', $slug);
                 $base = explode('/', $GLOBALS['HASH_URLS'][$data['params']['id']]);
                 array_shift($base);
                 $unique = false;
                 while (!$unique) {
                     $url = implode('/', array_merge($base, array($slug)));
                     if (isset($GLOBALS['HASH_IDS'][$url])) {
                         if (preg_match('/^(.*)-([0-9]+)$/i', $slug, $matches)) {
                             $slug = $matches[1] . '-' . (intval($matches[2]) + 1);
                         } else {
                             $slug = $slug . '-2';
                         }
                     } else {
                         $unique = true;
                     }
                 }
                 treeStorage::startTransaction();
                 list($left, $right) = treeStorage::prepareForInsert(0, $language);
                 $res = sql::query("\r\n\t\t\t\t\t\t\tINSERT INTO \r\n\t\t\t\t\t\t\t\t" . _TABLE_PREFIX_ . "contents\r\n\t\t\t\t\t\t\tSET\r\n\t\t\t\t\t\t\t\t`parent`='',\r\n\t\t\t\t\t\t\t\t`left`='" . $left . "',\r\n\t\t\t\t\t\t\t\t`right`='" . $right . "',\r\n\t\t\t\t\t\t\t\t`site`='" . _DEFAULT_SITE_ . "',\r\n\t\t\t\t\t\t\t\t`name`='" . addslashes($name) . "',\r\n\t\t\t\t\t\t\t\t`title`='',\r\n\t\t\t\t\t\t\t\t`slug`='" . addslashes($slug) . "',\r\n\t\t\t\t\t\t\t\t`type`='" . $type . "',\r\n\t\t\t\t\t\t\t\t`status`='0',\r\n\t\t\t\t\t\t\t\t`revision`=0,\r\n\t\t\t\t\t\t\t\t`position`='" . $position . "',\r\n\t\t\t\t\t\t\t\t`language`='" . $language . "',\r\n\t\t\t\t\t\t\t\t`author`='" . $user->id . "',\r\n\t\t\t\t\t\t\t\t`r_view`='3',\r\n\t\t\t\t\t\t\t\t`r_view_inv`='0',\r\n\t\t\t\t\t\t\t\t`r_edit`='6',\r\n\t\t\t\t\t\t\t\t`r_edit_inv`='0',\r\n\t\t\t\t\t\t\t\t`r_create`='6',\r\n\t\t\t\t\t\t\t\t`r_create_inv`='0',\r\n\t\t\t\t\t\t\t\t`r_admin`='6',\r\n\t\t\t\t\t\t\t\t`r_admin_inv`='0',\r\n\t\t\t\t\t\t\t\t`created`='" . time() . "',\r\n\t\t\t\t\t\t\t\t`modified`='" . time() . "',\r\n\t\t\t\t\t\t\t\t`visible`='1'\r\n\t\t\t\t\t\t");
                 treeStorage::stopTransaction();
                 $id = sql::insert_id();
                 /* Create the first revision */
                 revisions::doCreatePage($id);
                 header("Location: " . url::item($id, 'edit'));
                 exit;
             }
         }
         // Create the page
         $position = 0;
         if (isset($item['children'])) {
             reset($item['children']);
             while (list($k, ) = each($item['children'])) {
                 $position = max($position, $item['children'][$k]['position']);
             }
         }
         $position++;
         if (isset($_POST['language'])) {
             $language = $_POST['language'];
         } else {
             $language = $tree->language;
         }
         if (isset($_POST['name'])) {
             $name = $_POST['name'];
         } else {
             $name = $user->lang->s('untitled');
         }
         $slug = strtolower($name);
         $slug = preg_replace('/(\\s+|_)/i', '-', $slug);
         $slug = preg_replace('/[^a-z0-9\\-]/i', '', $slug);
         $base = explode('/', $GLOBALS['HASH_URLS'][$data['params']['id']]);
         array_shift($base);
         while (!$unique) {
             $url = implode('/', array_merge($base, array($slug)));
             if (isset($GLOBALS['HASH_IDS'][$url])) {
                 if (preg_match('/^(.*)-([0-9]+)$/i', $slug, $matches)) {
                     $slug = $matches[1] . '-' . (intval($matches[2]) + 1);
                 } else {
                     $slug = $slug . '-2';
                 }
             } else {
                 $unique = true;
             }
         }
         // Newly created items have the same
         // writing and creation rights as their
         // parents...
         $r_view = $item['rights']['r_view'];
         $r_edit = $item['rights']['r_create'];
         $r_create = $item['rights']['r_create'];
         $r_admin = $item['rights']['r_create'];
         if ($item['rights']['r_create'] != $item['rights']['r_admin']) {
             // Check if we are trying to create this page
             // with admin rights, or with create rights.
             if ($tree->_hasRights('create', $item['rights']) && !$tree->_hasRights('create', $item['rights'], true)) {
                 $r_admin = $item['rights']['r_admin'];
             }
         }
         treeStorage::startTransaction();
         list($left, $right) = treeStorage::prepareForInsert($item['id'], $language);
         sql::query("\r\n\t\t\t\t\tINSERT INTO \r\n\t\t\t\t\t\t" . _TABLE_PREFIX_ . "contents\r\n\t\t\t\t\tSET\r\n\t\t\t\t\t\t`parent`='" . $item['id'] . "',\r\n\t\t\t\t\t\t`left`='" . $left . "',\r\n\t\t\t\t\t\t`right`='" . $right . "',\r\n\t\t\t\t\t\t`site`='" . _DEFAULT_SITE_ . "',\r\n\t\t\t\t\t\t`name`='" . addslashes($name) . "',\r\n\t\t\t\t\t\t`title`='',\r\n\t\t\t\t\t\t`slug`='" . addslashes($slug) . "',\r\n\t\t\t\t\t\t`type`='" . $type . "',\r\n\t\t\t\t\t\t`status`='0',\r\n\t\t\t\t\t\t`position`='" . $position . "',\r\n\t\t\t\t\t\t`language`='" . $language . "',\r\n\t\t\t\t\t\t`author`='" . $user->id . "',\r\n\t\t\t\t\t\t`r_view`='" . $r_view . "',\r\n\t\t\t\t\t\t`r_view_inv`='0',\r\n\t\t\t\t\t\t`r_edit`='" . $r_edit . "',\r\n\t\t\t\t\t\t`r_edit_inv`='0',\r\n\t\t\t\t\t\t`r_create`='" . $r_create . "',\r\n\t\t\t\t\t\t`r_create_inv`='0',\r\n\t\t\t\t\t\t`r_admin`='" . $r_admin . "',\r\n\t\t\t\t\t\t`r_admin_inv`='0',\r\n\t\t\t\t\t\t`created`='" . time() . "',\r\n\t\t\t\t\t\t`modified`='" . time() . "',\r\n\t\t\t\t\t\t`visible`='1'\r\n\t\t\t\t");
         treeStorage::stopTransaction();
         $id = sql::insert_id();
         /* Create the first revision */
         revisions::doCreatePage($id);
         header("Location: " . url::item($id, 'edit'));
         exit;
     } else {
         if (is_null($item)) {
             $siblingAllowed = false;
             $siblingTypes = $manager->types();
             if ($user->memberof(6)) {
                 $siblingAllowed = count($siblingTypes) ? true : false;
             }
             $childAllowed = false;
             $childTypes = array();
         } else {
             $childTypes = $manager->types($item['type']);
             $childAllowed = count($childTypes) ? true : false;
             $siblingAllowed = false;
             $siblingTypes = array();
             if ($item['parent'] > 0) {
                 $parent =& $tree->getItemById($item['parent']);
                 if ($parent && $tree->_hasRights('create', $parent['rights'])) {
                     $siblingAllowed = true;
                 }
                 $siblingTypes = $manager->types($parent['type']);
             } else {
                 $siblingTypes = $manager->types();
             }
             if ($user->memberof(6)) {
                 $siblingAllowed = true;
             }
             if (!$id) {
                 $siblingAllowed = false;
             }
         }
         $tpl = new Template($this->getTemplate('create.template'));
         $tpl->set('childTypes', $childTypes);
         $tpl->set('childAllowed', $childAllowed);
         $tpl->set('siblingTypes', $siblingTypes);
         $tpl->set('siblingAllowed', $siblingAllowed);
         $tpl->set('name', $user->lang->s('untitled'));
         $tpl->set('id', $id);
         echo $tpl->fetch();
         exit;
     }
 }
예제 #4
0
 function prepareForDelete($id)
 {
     $res = sql::query("\n\t\t\tSELECT \n\t\t\t\t`right`, \n\t\t\t\t`language` \n\t\t\tFROM \n\t\t\t\t" . _TABLE_PREFIX_ . "contents \n\t\t\tWHERE \n\t\t\t\t`ID` = " . $id . "\n\t\t");
     $ref = sql::fetch_array($res, MYSQL_ASSOC);
     $right = intval($ref['right']);
     $language = $ref['language'];
     treeStorage::_removeSpace($language, $right, 2);
 }
예제 #5
0
    function event_ExecuteEditor(&$data)
    {
        global $tree, $lang, $user, $config, $manager;
        if ($data['sheet'] == 'navigation') {
            $item =& $data['item'];
            $allow = false;
            $allow = $allow || $tree->_hasRights('admin', $item['rights']);
            if ($item['parent'] != '' && $item['parent'] != '0') {
                $parent =& $tree->getItemById($item['parent']);
                $allow = $allow || $tree->_hasRights('admin', $parent['rights']);
            }
            $errors = array();
            $tpl = new Template($this->getTemplate('editor.template'));
            if ($_SERVER['REQUEST_METHOD'] == 'POST') {
                $hidden = isset($_POST['hidden']) && $_POST['hidden'] == 'yes' ? 0 : 1;
                $set = isset($_POST['set']) ? intval($_POST['set']) : 0;
                $res = sql::query("\r\n\t\t\t\t\t\tUPDATE \r\n\t\t\t\t\t\t\t" . _TABLE_PREFIX_ . "contents \r\n\t\t\t\t\t\tSET \r\n\t\t\t\t\t\t\t`set` = '" . addslashes($set) . "', \r\n\t\t\t\t\t\t\t`visible` = '" . $hidden . "' \r\n\t\t\t\t\t\tWHERE \r\n\t\t\t\t\t\t\t`ID` = '" . $item['id'] . "'\r\n\t\t\t\t\t");
                if ($allow && isset($_POST['position'])) {
                    for ($i = 0; $i < intval($config->get('navigationSets')); $i++) {
                        $position = explode(',', $_POST['position'][$i]);
                        if ($set != $i) {
                            while (list($p, $id) = each($position)) {
                                if ($id == $item['id']) {
                                    unset($position[$p]);
                                }
                            }
                            reset($position);
                        }
                        /* Also include all disabled siblings, but at the bottom... */
                        $res = sql::query('
								SELECT 
									`ID`
								FROM 
									' . _TABLE_PREFIX_ . 'contents 
								WHERE 
									`parent` = ' . $item['parent'] . ' AND
									`set` = ' . $set . ' AND 
									`status` = 2 
								ORDER BY 
									`position`
							');
                        while ($row = sql::fetch_array($res, MYSQL_ASSOC)) {
                            $position[] = $row['ID'];
                        }
                        /* Sort */
                        while (list($p, $id) = each($position)) {
                            treeStorage::startTransaction();
                            treeStorage::prepareForMove($id, $item['parent'], $item['meta']['language']);
                            $res = sql::query("\r\n\t\t\t\t\t\t\t\t\tUPDATE \r\n\t\t\t\t\t\t\t\t\t\t" . _TABLE_PREFIX_ . "contents \r\n\t\t\t\t\t\t\t\t\tSET \r\n\t\t\t\t\t\t\t\t\t\t`position`='" . addslashes($p + 100 * $set) . "'\r\n\t\t\t\t\t\t\t\t\tWHERE \r\n\t\t\t\t\t\t\t\t\t\t`ID` = '" . addslashes($id) . "'\r\n\t\t\t\t\t\t\t\t");
                            treeStorage::stopTransaction();
                        }
                    }
                    header("Location: " . url::item($data['params']['id'], 'edit') . "/navigation");
                    exit;
                }
            }
            if ($data['item']['parent'] != '' && $data['item']['parent'] != '0') {
                $tpl->set('pages', $parent['children']);
            } else {
                // Make a copy that we can edit...
                $pages = $tree->tree;
                reset($pages);
                while (list($k, ) = each($pages)) {
                    if ($pages[$k]['id'] == 'admin') {
                        unset($pages[$k]);
                        continue;
                    }
                    if ($pages[$k]['status'] > 1) {
                        unset($pages[$k]);
                        continue;
                    }
                    /*
                    if ($data['item']['parent'] == 0 && $pages[$k]['set'] != $data['item']['set']) {
                    	unset($pages[$k]);
                    	continue;
                    }
                    */
                }
                $tpl->set('pages', $pages);
            }
            // Determine if we must sort this item manually
            $sort = 0;
            $hidden = true;
            if ($item['parent'] > 0) {
                $parent =& $tree->getItemById($item['parent']);
                if (isset($manager->types[$parent['type']])) {
                    $sort = $manager->types[$parent['type']]['sort'];
                    $hidden = $manager->types[$parent['type']]['visible'] == 0;
                }
            }
            $tpl->set('item', $data['item']);
            $tpl->set('id', $data['params']['id']);
            $tpl->set('allow', $allow);
            $tpl->set('hidden', $hidden);
            $tpl->set('sort', $sort);
            $tpl->set('sets', intval($config->get('navigationSets')));
            $data['template']->append('content', $tpl->fetch());
        }
    }
예제 #6
0
 function _duplicateItem($from, $parent, $position = null)
 {
     global $manager, $lang;
     $res = sql::query("\r\n\t\t\t\tSELECT \r\n\t\t\t\t\t*\r\n\t\t\t\tFROM \r\n\t\t\t\t\t" . _TABLE_PREFIX_ . "contents\r\n\t\t\t\tWHERE \r\n\t\t\t\t\tID = '" . $from . "'\r\n\t\t\t");
     if ($row = sql::fetch_array($res, MYSQL_ASSOC)) {
         $slug = strtolower($row['name']);
         $slug = preg_replace('/(\\s+|_)/i', '-', $slug);
         $slug = preg_replace('/[^a-z0-9\\-]/i', '', $slug);
         $base = explode('/', $GLOBALS['HASH_URLS'][$from]);
         array_pop($base);
         $unique = false;
         while (!$unique) {
             $url = implode('/', array_merge($base, array($slug)));
             if (isset($GLOBALS['HASH_IDS'][$url])) {
                 if (preg_match('/^(.*)-([0-9]+)$/i', $slug, $matches)) {
                     $slug = $matches[1] . '-' . (intval($matches[2]) + 1);
                 } else {
                     $slug = $slug . '-2';
                 }
             } else {
                 $unique = true;
             }
         }
         if ($position == null) {
             $position = $row['position'];
         }
         treeStorage::startTransaction();
         list($left, $right) = treeStorage::prepareForInsert($parent, $row['language']);
         sql::query("\r\n\t\t\t\t\tINSERT INTO \r\n\t\t\t\t\t\t" . _TABLE_PREFIX_ . "contents\r\n\t\t\t\t\tSET \r\n\t\t\t\t\t\t`parent`='" . $parent . "', \r\n\t\t\t\t\t\t`left`='" . $left . "',\r\n\t\t\t\t\t\t`right`='" . $right . "',\r\n\t\t\t\t\t\t`site`='" . $row['site'] . "',\r\n\t\t\t\t\t\t`name`='" . addslashes($row['name']) . "',\r\n\t\t\t\t\t\t`title`='" . addslashes($row['title']) . "',\r\n\t\t\t\t\t\t`slug`='" . addslashes($slug) . "',\r\n\t\t\t\t\t\t`type`='" . addslashes($row['type']) . "',\r\n\t\t\t\t\t\t`revision`='" . $row['revision'] . "',\r\n\t\t\t\t\t\t`set`=" . $row['set'] . ",\r\n\t\t\t\t\t\t`position`=" . $position . ",\r\n\t\t\t\t\t\t`r_view`=" . $row['r_view'] . ",\r\n\t\t\t\t\t\t`r_view_inv`=" . $row['r_view_inv'] . ",\r\n\t\t\t\t\t\t`r_edit`=" . $row['r_edit'] . ",\r\n\t\t\t\t\t\t`r_edit_inv`=" . $row['r_edit_inv'] . ",\r\n\t\t\t\t\t\t`r_create`=" . $row['r_create'] . ",\r\n\t\t\t\t\t\t`r_create_inv`=" . $row['r_create_inv'] . ",\r\n\t\t\t\t\t\t`r_admin`=" . $row['r_admin'] . ",\r\n\t\t\t\t\t\t`r_admin_inv`=" . $row['r_admin_inv'] . ",\r\n\t\t\t\t\t\t`author`=" . $row['author'] . ",\r\n\t\t\t\t\t\t`language`='" . addslashes($row['language']) . "',\r\n\t\t\t\t\t\t`activation`=" . $row['activation'] . ",\r\n\t\t\t\t\t\t`expiration`=" . $row['expiration'] . ",\r\n\t\t\t\t\t\t`created`=" . time() . ",\r\n\t\t\t\t\t\t`modified`=" . time() . ",\r\n\t\t\t\t\t\t`visible`=" . $row['visible'] . ",\r\n\t\t\t\t\t\t`status`=" . $row['status'] . "\r\n\t\t\t\t");
         treeStorage::stopTransaction();
         $to = sql::insert_id();
         /* Copy the plugin data */
         $duplicate = array('from' => $from, 'to' => $to);
         $manager->handleEvent('DuplicateItem', $duplicate);
         /* Copy the revision history */
         revisions::doDuplicatePage($from, $to);
         /* Duplicate pages recursively */
         $res = sql::query("\r\n\t\t\t\t\tSELECT \r\n\t\t\t\t\t\t*\r\n\t\t\t\t\tFROM \r\n\t\t\t\t\t\t" . _TABLE_PREFIX_ . "contents\r\n\t\t\t\t\tWHERE \r\n\t\t\t\t\t\tparent = '" . $from . "'\r\n\t\t\t\t");
         while ($row = sql::fetch_array($res, MYSQL_ASSOC)) {
             $this->_duplicateItem($row['ID'], $to);
         }
         return $to;
     }
 }