예제 #1
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;
     }
 }
예제 #2
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;
     }
 }