function store_new_links($url, $name, $pid, $weight) { global $xoopsDB; $url = normal_url($url); $now = time(); $data = array('cutid' => cutid_default($url), 'url' => $url, 'uid' => 0, 'title' => $name, 'pscref' => $pid); foreach ($data as $k => $v) { $data[$k] = $xoopsDB->quoteString($v); } if (!$pid) { if (!$weight) { $res = $xoopsDB->query("SELECT max(weight) FROM " . SHORT . " WHERE pscref=0 AND uid=0"); list($weight) = $xoopsDB->fetchRow($res); $weight++; } } else { if ($weight) { $res = $xoopsDB->query("SELECT weight FROM " . SHORT . " WHERE pscref={$pid} AND weight={$weight} AND uid=0"); if ($xoopsDB->getRowsNum($res)) { $res = $xoopsDB->query("UPDATE " . SHORT . " SET weight=weight+1 WHERE pscref={$pid} AND weight>={$weight} AND uid=0"); } } } $data['weight'] = $weight; $data['mdate'] = time(); $res = $xoopsDB->query("INSERT INTO " . SHORT . "(" . join(',', array_keys($data)) . ")VALUES(" . join(',', $data) . ") "); return $xoopsDB->getInsertID($res); }
} $myts =& MyTextSanitizer::getInstance(); $uid = $xoopsUser->getVar('uid'); $scid = isset($_POST['scid']) ? intval($_POST['scid']) : 0; $data = post_vars(); $msgs = array(); if (isset($_POST['save'])) { if (store_entry($data, $scid, $uid)) { redirect_header("index.php", 1, _MD_SHORTCUT_STOREOK); exit; } $msgs[] = _MD_SHORTCUT_STORENG . ' - ' . $xoopsDB->error(); } include XOOPS_ROOT_PATH . "/header.php"; $xoopsTpl->assign('errors', $msgs); $data['url'] = normal_url($data['url']); if (!isset($_POST['scid'])) { // generate uniq id if empty if (isset($_GET['scid'])) { $scid = intval($_GET['scid']); $cond = "scid=" . $scid; if (!$xoopsUser->isAdmin($xoopsModule->getVar('mid'))) { $cond .= " AND uid=" . $xoopsUser->getVar('uid'); } $res = $xoopsDB->query('SELECT * FROM ' . SHORTCUT . ' WHERE ' . $cond); $data = $xoopsDB->fetchArray($res); } else { $rand = ""; do { $cutid = substr(base64_encode(md5($xoopsUser->getVar('uid') . '-' . $data['url'] . $rand, true)), 0, 5); $rand = rand(0, 1000);