/** * Initial rendering of the page when user just come the Submit Data page. * * @return [type] [description] */ function do_submit0() { global $main_smarty, $db, $dblang, $current_user, $the_template; $linkres = new Link(); $edit = false; if (is_numeric($_GET['id'])) { $linkres->id = $_GET['id']; } else { $author = $current_user->user_id; $linkres->author = $current_user->user_id; $main_smarty->assign('StorySummary_ContentTruncate', StorySummary_ContentTruncate); $main_smarty->assign('SubmitSummary_Allow_Edit', SubmitSummary_Allow_Edit); $main_smarty->assign('enable_tags', Enable_Tags); $main_smarty->assign('submit_link_group_id', $linkres->link_group_id); include_once mnminclude . 'dbtree.php'; $array = tree_to_array(0, table_categories, FALSE); $array = array_values(array_filter($array, "allowToAuthorCat")); $main_smarty->assign('submit_lastspacer', 0); $main_smarty->assign('submit_cat_array', $array); } if ($current_user->authenticated != TRUE) { $vars = ''; check_actions('register_showform', $vars); } //$queryEngine = new QueryEngine(); //$sid = $queryEngine->simpleQuery->getNewSid($current_user->user_id, 'draft'); $main_smarty->assign('user_id', $current_user->user_id); $main_smarty->assign('tpl_extra_fields', $the_template . '/submit_extra_fields'); $main_smarty->assign('tpl_center', $the_template . '/submit_step_21'); $main_smarty->assign('tpl_jsFilesAtBottom', $the_template . '/submit_step_21_jsFilesAtBottom'); $main_smarty->assign('tpl_cssInHTMLHead', $the_template . '/submit_step_21_cssInHTMLHead'); define('pagename', 'submit'); $main_smarty->assign('pagename', pagename); $main_smarty->display($the_template . '/pligg.tpl'); }
public function nodeList() { $nodes = $this->order("sort desc")->select(); $list = list_to_tree($nodes, 'id', 'pid'); $nodes = array(); tree_to_array($list, $nodes); return $nodes; }
function tree_to_array($tree, &$cat = array(), $level = 1) { foreach ($tree as $key => $value) { $temp = $value; if ($temp['_child']) { $temp['_child'] = true; $temp['level'] = $level; $cat[$value['id']] = $temp; } else { $temp['_child'] = false; $temp['level'] = $level; $cat[$value['id']] = $temp; } if ($value['_child']) { tree_to_array($value['_child'], $cat, $level + 1); } } }
/** * 获取经过Tree处理的Terms * @param string $post_type 模型表名 * @return array */ public function getPostTerms($post_type) { $terms = $this->getPostTermsOriginData($post_type); if (empty($terms)) { return array(); } $cats = list_to_tree($terms, 'id', 'parentid'); $list = array(); tree_to_array($cats, $list); unset($cats); unset($terms); $temp = array(); foreach ($list as $key => $value) { $temp[$value['taxonomy']][] = $value; } foreach ($taxonomies as $key => $value) { $taxonomies[$key]['terms'] = isset($temp[$value['name']]) ? $temp[$value['name']] : array(); } return $taxonomies; }
public function edit() { if (IS_POST) { $this->checkToken(); $cat = $this->db->where("siteid = %d and id = %d", $this->siteid, $_POST['id'])->find(); $data = $_POST['info']; $data['letter'] = join('', gbk_to_pinyin($data['catname'])); $model = $this->model_db->find(intval($data['modelid'])); $data['module'] = $model['name']; $data['setting'] = var_export($_POST['setting'], true); // 是否修改父栏目 if ($data['parentid'] == $cat['parentid']) { // echo "没有修改父栏目"; if ($this->db->where("siteid = %d and id = %d", $this->siteid, $_POST['id'])->save($data) !== false) { // echo $this->db->getLastSql(); $this->success('操作成功!', __MODULE__ . '/Category/index'); } else { $this->error('操作失败!'); } } else { if ($data['parentid']) { // 更新 'parentid' and 'arrparentid' $parentcat = $this->db->where("siteid = %d and id = %d", $this->siteid, $data['parentid'])->find(); if (!$parentcat) { $this->error('父栏目不存在'); exit(0); } $data['arrparentid'] = $parentcat['arrparentid'] . "," . $parentcat['id']; $data['parentdir'] = $parentcat['parentdir'] . $parentcat['catdir'] . "/"; $data['level'] = $parentcat['level'] + 1; $this->db->startTrans(); if ($this->db->where("siteid = %d and id = %d", $this->siteid, $_POST['id'])->save($data) !== false) { /* 更新原父栏目 */ $origin_parentcat = $this->db->where("siteid = %d and id = %d", $this->siteid, $cat['parentid'])->find(); if ($origin_parentcat) { $arrchildid = explode(',', $origin_parentcat['arrchildid']); foreach ($arrchildid as $key => $value) { if ($value == $cat['id']) { unset($arrchildid[$key]); break; } } $arrchildid = join(',', $arrchildid); $origin_parent_data = array('arrchildid' => $arrchildid); if ($arrchildid == $origin_parentcat['id']) { $origin_parent_data['child'] = 0; } if ($this->db->where("siteid = %d and id = %d", $this->siteid, $origin_parentcat['id'])->save($origin_parent_data) === false) { $this->db->rollback(); $this->error("更新原父栏目失败!"); } } /* 更新现父栏目 */ $data_parent = array('child' => 1, 'arrchildid' => $parentcat['arrchildid'] . "," . $cat['id']); if ($this->db->where("siteid = %d and id = %d", $this->siteid, $data['parentid'])->save($data_parent) !== false) { // echo '更新现父栏目成功'; $this->db->commit(); $this->success('操作成功!', __MODULE__ . '/Category/index'); } else { $this->db->rollback(); $this->error("更新现父栏目失败!"); } } else { $this->db->rollback(); $this->error("栏目更新失败!"); } } else { $data['level'] = 1; $data['arrparentid'] = "0"; $this->db->startTrans(); if ($this->db->where("siteid = %d and id = %d", $this->siteid, $_POST['id'])->save($data) !== false) { $origin_parentcat = $this->db->where("siteid = %d and id = %d", $this->siteid, $cat['parentid'])->find(); $arrchildid = explode(',', $origin_parentcat['arrchildid']); foreach ($arrchildid as $key => $value) { if ($value == $cat['id']) { unset($arrchildid[$key]); break; } } $arrchildid = join(',', $arrchildid); $origin_parent_data = array('arrchildid' => $arrchildid); if ($arrchildid == $origin_parentcat['id']) { $origin_parent_data['child'] = 0; } if ($this->db->where("siteid = %d and id = %d", $this->siteid, $origin_parentcat['id'])->save($origin_parent_data) !== false) { $this->db->commit(); $this->success('操作成功!', __MODULE__ . '/Category/index'); } else { $this->db->rollback(); $this->error("更新原父栏目失败!"); } } else { $this->db->rollback(); $this->error("栏目更新失败!"); } } } } else { $cats = list_to_tree($this->db->cat_list(), 'id', 'parentid'); $list = array(); tree_to_array($cats, $list); $cat = $this->db->where("siteid = %d and id = %d", $this->siteid, $_GET['id'])->find(); $model_list = $this->model_db->where(array('siteid' => $this->siteid, 'typeid' => 0))->select(); $cat['setting'] = string2array($cat['setting']); $this->assign('cat', $cat); $this->assign('cat_id', $cat_id); $this->assign('cats', $list); $this->assign("model_list", $model_list); $this->display(); } }
header("Location: admin_categories.php"); } else { die('You cannot move a category into it\'s own subcategory. Click <a href = "admin_categories.php">here</a> to reload.'); } } else { $sql = "Select * from " . table_categories . " where category__auto_id=" . $move_id . ";"; $results = $db->get_row($sql); $move_sort = $results->category_order; $sql = "update " . table_categories . " set category_parent = " . $results->category_parent . ", category_order = " . ($move_sort + 1) . " where category__auto_id=" . $id . ";"; $db->query($sql); rebuild_the_tree(); header("Location: admin_categories.php"); } } if ($action == "view") { $array = tree_to_array(0, table_categories, true); $main_smarty->assign('cat_count', count($array)); $main_smarty->assign('cat_array', $array); $main_smarty->assign('tpl_center', '/admin/category_manager'); $main_smarty->display($template_dir . '/admin/admin.tpl'); echo $QEIP->ShowOnloadJS(); } } else { echo 'not for you! go away!'; } function makeCategoryFriendly($input) { // this was moved out of utils.php because it's only needed when changing // category information $input = utf8_substr($input, 0, 240); $output = utf8_strtolower($output);
function do_sidebar($var_smarty, $navwhere = '') { // show the categories in the sidebar global $db, $dblang, $globals, $the_cats; if ($navwhere == '') { global $navwhere; } // fix for 'undefined index' errors if (!isset($navwhere['text4'])) { $navwhere['text4'] = ''; } else { $navwhere['text4'] = htmlspecialchars($navwhere['text4']); } if (!isset($navwhere['text3'])) { $navwhere['text3'] = ''; } else { $navwhere['text3'] = htmlspecialchars($navwhere['text3']); } if (!isset($navwhere['text2'])) { $navwhere['text2'] = ''; } else { $navwhere['text2'] = htmlspecialchars($navwhere['text2']); } if (!isset($navwhere['text1'])) { $navwhere['text1'] = ''; } else { $navwhere['text1'] = htmlspecialchars($navwhere['text1']); } if (!isset($navwhere['link4'])) { $navwhere['link4'] = ''; } if (!isset($navwhere['link3'])) { $navwhere['link3'] = ''; } if (!isset($navwhere['link2'])) { $navwhere['link2'] = ''; } if (!isset($navwhere['link1'])) { $navwhere['link1'] = ''; } $var_smarty->assign('navbar_where', $navwhere); $var_smarty->assign('body_args', ''); // fix for 'undefined index' errors $_caching = $var_smarty->cache; // get the current cache settings $var_smarty->cache = true; // cache has to be on otherwise is_cached will always be false $var_smarty->cache_lifetime = -1; // lifetime has to be set to something otherwise is_cached will always be false $thetpl = $var_smarty->get_template_vars('the_template_sidebar_modules') . '/categories.tpl'; // check to see if the category sidebar module is already cached // if it is, use it if (isset($_GET['category'])) { $thecat = sanitize($_GET['category'], 3); } else { $thecat = ''; } if ($var_smarty->is_cached($thetpl, 'sidebar|category|' . $thecat)) { $var_smarty->assign('cat_array', 'x'); // this is needed. sidebar.tpl won't include the category module if cat_array doesnt have some data } else { if (isset($_GET['category'])) { $thecat = get_cached_category_data('category_safe_name', urlencode(sanitize($_GET['category'], 1))); $thecat = $thecat->category_name; } $var_smarty->assign('UrlMethod', urlmethod); foreach ($the_cats as $cat) { if ($cat->category_id == $thecat && $cat->category_lang == $dblang && $cat->category_parent == 0) { $globals['category_id'] = $cat->category_id; $globals['category_name'] = $cat->category_name; } } $pos = strrpos($_SERVER["SCRIPT_NAME"], "/"); $script_name = substr($_SERVER["SCRIPT_NAME"], $pos + 1, 100); $script_name = str_replace(".php", "", $script_name); include_once 'dbtree.php'; $login_user = $db->escape(sanitize($_COOKIE['mnm_user'], 3)); if ($login_user) { /////// for user set category----sorojit. $sqlGeticategory = $db->get_var("SELECT user_categories from " . table_users . " where user_login = '******';"); $array1 = "SELECT * from " . table_categories . " where category__auto_id in ({$sqlGeticategory})"; $result = mysql_query($array1); $array = array(); while ($row = mysql_fetch_array($result)) { //print_r($row); $row[] = $row; } $right = array(); $array1 = "SELECT * from " . table_categories . " where category__auto_id in ({$sqlGeticategory}) ORDER BY lft"; $result1 = mysql_query($array1); while ($row = mysql_fetch_object($result1)) { $a[] = $row; } $result = $a; $i = 0; $lastspacer = 0; // added @ thanks to `parterburn` - http://www.pligg.com/forum/showthread.php?t=4888 foreach ($result as $row) { if (count($right) > 0) { // check if we should remove a node from the stack while ($right[count($right) - 1] < $row->rgt) { if (array_pop($right) == NULL) { break; // We've reached the top of the category chain } } } $array[$i]['principlecat'] = $row->rgt - $row->lft - 1; $array[$i]['spacercount'] = count($right); $array[$i]['lastspacercount'] = $lastspacer; $array[$i]['spacerdiff'] = abs($lastspacer - count($right)); $array[$i]['auto_id'] = $row->category__auto_id; $array[$i]['name'] = $row->category_name; $array[$i]['safename'] = $row->category_safe_name; if (isset($row->category_color)) { $array[$i]['color'] = $row->category_color; } if (isset($row->category_parent)) { $array[$i]['parent'] = $row->category_parent; $array[$i]['parent_name'] = GetCatName($row->category_parent); $array[$i]['parent_subcat_count'] = GetSubCatCount($row->category_parent); } $array[$i]['subcat_count'] = GetSubCatCount($row->category__auto_id); $lastspacer = count($right); $i = $i + 1; $right[] = $row->rgt; } ///////end of for user set category $var_smarty->assign('start', 0); } else { $array = tree_to_array(0, table_categories); $var_smarty->assign('start', 1); } $var_smarty->assign('lastspacer', 0); $var_smarty->assign('cat_array', $array); // use the 'totals' table now $published_count = get_story_count('published'); $var_smarty->assign('published_count', $published_count); // $sql = "select *, count(*) as count from " . table_links . ", " . table_categories . " where category_lang='$dblang' and category_id=link_category group by link_category ORDER BY category_name ASC"; // $categorylist = object_2_array($db->get_results($sql)); // $var_smarty->assign('categorylist', $categorylist); $var_smarty->assign('category_url', getmyurl('maincategory')); } $var_smarty->cache = $_caching; // set cache back to original value $vars = ''; check_actions('do_sidebar', $vars); return $var_smarty; }
function do_submit1() { global $main_smarty, $db, $dblang, $current_user, $the_template; $linkres = new Link(); $linkres->randkey = sanitize($_POST['randkey'], 3); $edit = false; if (is_numeric($_GET['id'])) { $linkres->id = $_GET['id']; $trackback = $_GET['trackback']; } else { if ($_FILES['wrapper']['error'] > 0) { $main_smarty->assign('submit_error', 'wrongtype'); $main_smarty->assign('tpl_center', $the_template . '/submit_errors'); $main_smarty->display($the_template . '/pligg.tpl'); return; } $error = $linkres->get($_FILES['wrapper']); if ($error) { $main_smarty->assign('submit_error', $error); $main_smarty->assign('tpl_center', $the_template . '/submit_errors'); $main_smarty->display($the_template . '/pligg.tpl'); return; } $fname = $_FILES["wrapper"]["name"]; $sname = explode('.', $fname); $linkres->title = $sname[0]; $author = $current_user->user_id; $datetime = date("Y-m-d H:i:s", mktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y'))); $_SESSION['EntryDate'] = $datetime; $sql = "INSERT INTO " . table_prefix . "sourceinfo (UserId, EntryDate, Status) VALUES ('{$author}','{$datetime}','discard');"; //$sql="INSERT INTO ".table_prefix."links (link_author, link_date, link_status) VALUES ('$author','$datetime','discard');" ; $rs = $db->query($sql); if ($rs) { //get sid returned from insert $newSid = mysql_insert_id(); } $newSid = mysql_insert_id(); $_SESSION['newSid'] = $newSid; $linkres->newSid = $newSid; $target_path = "temp/"; //echo $target_path; $target_path = $target_path . "{$newSid}.ktr"; move_uploaded_file($_FILES['wrapper']['tmp_name'], $target_path); //echo $_FILES['wrapper']['tmp_name']; $current_timestamp = $datetime; $sql = 'INSERT INTO ' . table_prefix . 'executeinfo (Sid ,Userid ,TimeStart)VALUES (' . $newSid . ' , ' . $author . ',CURRENT_TIMESTAMP);'; //print($sql); $rs = $db->query($sql); if ($rs) { //get eid returned from the insert $logID = mysql_insert_id(); //print $logID; } else { //print (mysql_error()); //rollback(); $main_smarty->assign('mysql_error', mysql_error()); $main_smarty->assign('submit_error', 'mysql_error'); $main_smarty->assign('tpl_center', $the_template . '/submit_errors'); $main_smarty->display($the_template . '/pligg.tpl'); return; } if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $locationOfPan = realpath(dirname(__FILE__)) . '\\kettle-data-integration\\Pan_WHDV.bat'; $command = 'cmd.exe /C ' . $locationOfPan . ' /file:"' . realpath(dirname(__FILE__)) . '\\' . $target_path . '" ' . '"-param:Sid=' . $newSid . '"' . ' "-param:Eid=' . $logID . '"'; } else { $locationOfPan = realpath(dirname(__FILE__)) . '/kettle-data-integration/pan.sh'; $command = 'sh ' . $locationOfPan . ' -file="' . realpath(dirname(__FILE__)) . '/' . $target_path . '" ' . '-param:Sid=' . $newSid . ' -param:Eid=' . $logID; } $ret = exec($command, $outA, $returnVar); if (strpos($ret, 'ended successfully') === false) { $num = 0; $sql = "UPDATE " . table_prefix . "executeinfo SET ExitStatus=0, ErrorMessage='" . mysql_real_escape_string(implode("\n", $outA)) . "', RecordsProcessed='" . $num . "', TimeEnd=CURRENT_TIMESTAMP WHERE EID=" . $logID; $rs = $db->query($sql); if (!$rs) { print mysql_error(); //rollback(); die; } //echo 'Dataset cannot be immigrated at this time.<br />'; $error = implode("<br />", $outA); //print($error); $errora = array(); $errorb = array(); $re1 = '(at)'; $re2 = '( )'; for ($i = 0; $i < count($outA); $i++) { if (strstr($outA[$i], 'ERROR') != FALSE) { break; } } $n = $i; for ($j = $n + 1; $j < count($outA); $j++) { if ($c = preg_match_all("/" . $re1 . $re2 . '/is', $outA[$j], $matches)) { break; } } for ($i; $i < $j; $i++) { array_push($errora, $outA[$i]); } for ($o = 0; $o < count($outA); $o++) { if ($c = preg_match_all("/" . $re1 . $re2 . '/is', $outA[$o], $matches)) { array_push($errorb, " " . $outA[$o]); } } $main_smarty->assign('mysql_error', implode("<br />", $errora)); $main_smarty->assign('mysql_errordetail', implode("<br />", $errorb)); $main_smarty->assign('submit_error', 'wrongktr'); $main_smarty->assign('tpl_center', $the_template . '/submit_errors'); $main_smarty->display($the_template . '/pligg.tpl'); return; die; } else { //TODO parse msg to get num inserted $lastLine = $outA[count($outA) - 1]; preg_match("/d+\\s{1}[0-9]+\\s{1}l+/", $lastLine, $matches); $m = explode(' ', $matches[0]); $numProcessed = $m[1]; $sql = "UPDATE " . table_prefix . "executeinfo SET ExitStatus=1, RecordsProcessed='" . $numProcessed . "', TimeEnd=CURRENT_TIMESTAMP WHERE EID=" . $logID; //print($sql); $rs = $db->query($sql); if (!$rs) { print mysql_error(); //rollback(); die; } $main_smarty->assign('randkey', $linkres->randkey); //$main_smarty->assign('submit_url', $url); //$data = parse_url($url); //$main_smarty->assign('url', $url); //$main_smarty->assign('url_short', 'http://'.$data['host']); //$main_smarty->assign('Submit_Show_URL_Input', $Submit_Show_URL_Input); //$main_smarty->assign('Submit_Require_A_URL', Submit_Require_A_URL); $linkres->author = $current_user->user_id; $main_smarty->assign('StorySummary_ContentTruncate', StorySummary_ContentTruncate); $main_smarty->assign('SubmitSummary_Allow_Edit', SubmitSummary_Allow_Edit); $main_smarty->assign('enable_tags', Enable_Tags); $main_smarty->assign('submit_url_title', str_replace('"', """, $linkres->url_title)); $main_smarty->assign('submit_url_description', $linkres->url_description); $main_smarty->assign('submit_id', $linkres->id); if (isset($link_title)) { $main_smarty->assign('submit_title', str_replace('"', """, $link_title)); } if (isset($link_content)) { $main_smarty->assign('submit_content', $link_content); } $main_smarty->assign('submit_trackback', $trackback); $main_smarty->assign('submit_link_group_id', $linkres->link_group_id); // $main_smarty->assign('submit_id', $_GET['id']); $main_smarty->assign('submit_title', str_replace('"', """, $linkres->title)); $main_smarty->assign('submit_content', str_replace("<br />", "\n", $linkres->content)); $main_smarty->assign('storylen', utf8_strlen(str_replace("<br />", "\n", $linkres->content))); $main_smarty->assign('submit_summary', $linkres->link_summary); $main_smarty->assign('submit_group', $linkres->link_group_id); $main_smarty->assign('submit_category', $linkres->category); $main_smarty->assign('submit_additional_cats', $linkres->additional_cats); $main_smarty->assign('tags_words', $linkres->tags); include_once mnminclude . 'dbtree.php'; $array = tree_to_array(0, table_categories, FALSE); $array = array_values(array_filter($array, "allowToAuthorCat")); $main_smarty->assign('submit_lastspacer', 0); $main_smarty->assign('submit_cat_array', $array); } } //to display group drop down if (enable_group == "true") { $output = ''; $group_membered = $db->get_results("SELECT group_id,group_name FROM " . table_groups . "\r\n\t\t\t\tLEFT JOIN " . table_group_member . " ON member_group_id=group_id\r\n\t\t\t\tWHERE member_user_id = {$current_user->user_id} AND group_status = 'Enable' AND member_status='active'\r\n\t\t\t\tORDER BY group_name ASC"); if ($group_membered) { $output .= "<select name='link_group_id'>"; $output .= "<option value = ''>" . $main_smarty->get_config_vars('PLIGG_Visual_Group_Select_Group') . "</option>"; foreach ($group_membered as $results) { $output .= "<option value = " . $results->group_id . ($linkres->link_group_id ? ' selected' : '') . ">" . $results->group_name . "</option>"; } $output .= "</select>"; } $main_smarty->assign('output', $output); } if ($current_user->authenticated != TRUE) { $vars = ''; check_actions('register_showform', $vars); } $main_smarty->assign('Spell_Checker', Spell_Checker); $main_smarty->assign('tpl_extra_fields', $the_template . '/submit_extra_fields'); $main_smarty->assign('tpl_center', $the_template . '/submit_step_2'); define('pagename', 'submit'); $main_smarty->assign('pagename', pagename); $vars = ''; check_actions('do_submit1', $vars); $_SESSION['step'] = 1; $main_smarty->display($the_template . '/pligg.tpl'); }
function do_submit1() { global $main_smarty, $db, $dblang, $current_user, $the_template; $url = htmlspecialchars(sanitize($_POST['url'], 3)); $url = str_replace('&', '&', $url); $url = html_entity_decode($url); if (strpos($url, 'http') !== 0) { $url = "http://{$url}"; } $linkres = new Link(); $linkres->randkey = sanitize($_POST['randkey'], 3); if (Submit_Show_URL_Input == false) { $url = "http://"; $linkres->randkey = rand(10000, 10000000); } $Submit_Show_URL_Input = Submit_Show_URL_Input; if ($url == "http://" || $url == "") { $Submit_Show_URL_Input = false; } $edit = false; if (is_numeric($_GET['id'])) { $linkres->id = $_GET['id']; $linkres->read(FALSE); $trackback = $_GET['trackback']; } else { $linkres->get($url); if ($_POST['title']) { $linkres->title = stripslashes(sanitize($_POST['title'], 4, $Story_Content_Tags_To_Allow)); } if ($_POST['tags']) { $linkres->tags = stripslashes(sanitize($_POST['tags'], 4)); } if ($_POST['description']) { $linkres->content = stripslashes(sanitize($_POST['description'], 4, $Story_Content_Tags_To_Allow)); } if ($_POST['category']) { $cats = explode(',', $_POST['category']); foreach ($cats as $cat) { if ($cat_id = $db->get_var("SELECT category_id FROM " . table_categories . " WHERE category_name='" . $db->escape(trim($cat)) . "'")) { $linkres->category = $cat_id; break; } } } $trackback = $linkres->trackback; } $main_smarty->assign('randkey', $linkres->randkey); $main_smarty->assign('submit_url', $url); $data = parse_url($url); $main_smarty->assign('url', $url); $main_smarty->assign('url_short', 'http://' . $data['host']); $main_smarty->assign('Submit_Show_URL_Input', $Submit_Show_URL_Input); $main_smarty->assign('Submit_Require_A_URL', Submit_Require_A_URL); // check if URL is valid format $pattern = '/^(([\\w]+:)?\\/\\/)?(([\\d\\w]|%[a-fA-f\\d]{2,2})+(:([\\d\\w]|%[a-fA-f\\d]{2,2})+)?@)?([\\d\\w]([-\\d\\w]{0,253}[\\d\\w])?\\.)+[\\w]{2,4}(:[\\d]+)?(\\/([-+_~.,\\d\\w]|%[a-fA-f\\d]{2,2})*)*(\\?(&?([-+_~.,\\d\\w]|%[a-fA-f\\d]{2,2})=?)*)?(#([-+_~.,\\/\\d\\w]|%[a-fA-f\\d]{2,2})*)?$/'; # $pattern = '/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w]([-\d\w]{0,253}[\d\w])?\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.,\d\w]|%[a-fA-f\d]{2,2})*)*(\??(&?([-+_~.,\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.,\/\d\w]|%[a-fA-f\d]{2,2})*)?$/'; # $pattern = '/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?(\d\w?)+[\w]{2,4}(:[\d]+)?(([\/#!+-~.,\d\w]+|%[a-fA-f\d]{2,2}))(\??(&?([-+~.,\d\w]|%[a-fA-f\d]{2,2})=?))?(#([-+_~.,\/\d\w]|%[a-fA-f\d]{2,2}))?$/'; $isLink = preg_match($pattern, $url); // Returns true if a link if ($url == "http://" || $url == "") { if (Submit_Require_A_URL == false) { $linkres->valid = true; } else { $linkres->valid = false; } $linkres->url_title = ""; } elseif ($isLink == false) { $linkres->valid = false; } $vars = array("url" => $url, 'linkres' => $linkres); check_actions('submit_validating_url', $vars); $linkres = $vars['linkres']; if (!$linkres->valid) { $main_smarty->assign('submit_error', 'invalidurl'); $main_smarty->assign('tpl_center', $the_template . '/submit_errors_center'); $main_smarty->display($the_template . '/pligg.tpl'); return; } if (Submit_Require_A_URL == true || $url != "http://" && $url != "") { if (!is_numeric($_GET['id']) && $linkres->duplicates($url) > 0) { $main_smarty->assign('submit_search', getmyurl("search_url", htmlentities($url))); $main_smarty->assign('submit_error', 'dupeurl'); $main_smarty->assign('tpl_center', $the_template . '/submit_errors_center'); define('pagename', 'submit'); $main_smarty->assign('pagename', pagename); $main_smarty->display($the_template . '/pligg.tpl'); return; } } $vars = array("url" => $url); check_actions('submit_validating_url', $vars); totals_adjust_count('discard', 1); //echo 'id'.$current_user->user_id; $linkres->status = 'discard'; $linkres->author = $current_user->user_id; $linkres->store(); $main_smarty->assign('StorySummary_ContentTruncate', StorySummary_ContentTruncate); $main_smarty->assign('SubmitSummary_Allow_Edit', SubmitSummary_Allow_Edit); $main_smarty->assign('enable_tags', Enable_Tags); $main_smarty->assign('submit_url_title', str_replace('"', """, $linkres->url_title)); $main_smarty->assign('submit_url_description', $linkres->url_description); $main_smarty->assign('submit_id', $linkres->id); $main_smarty->assign('submit_type', $linkres->type()); if (isset($link_title)) { $main_smarty->assign('submit_title', str_replace('"', """, $link_title)); } if (isset($link_content)) { $main_smarty->assign('submit_content', $link_content); } $main_smarty->assign('submit_trackback', $trackback); $main_smarty->assign('submit_link_field1', $linkres->link_field1); $main_smarty->assign('submit_link_field2', $linkres->link_field2); $main_smarty->assign('submit_link_field3', $linkres->link_field3); $main_smarty->assign('submit_link_field4', $linkres->link_field4); $main_smarty->assign('submit_link_field5', $linkres->link_field5); $main_smarty->assign('submit_link_field6', $linkres->link_field6); $main_smarty->assign('submit_link_field7', $linkres->link_field7); $main_smarty->assign('submit_link_field8', $linkres->link_field8); $main_smarty->assign('submit_link_field9', $linkres->link_field9); $main_smarty->assign('submit_link_field10', $linkres->link_field10); $main_smarty->assign('submit_link_field11', $linkres->link_field11); $main_smarty->assign('submit_link_field12', $linkres->link_field12); $main_smarty->assign('submit_link_field13', $linkres->link_field13); $main_smarty->assign('submit_link_field14', $linkres->link_field14); $main_smarty->assign('submit_link_field15', $linkres->link_field15); $main_smarty->assign('submit_link_group_id', $linkres->link_group_id); // $main_smarty->assign('submit_id', $_GET['id']); $main_smarty->assign('submit_title', str_replace('"', """, $linkres->title)); $main_smarty->assign('submit_content', str_replace("<br />", "\n", $linkres->content)); $main_smarty->assign('storylen', utf8_strlen(str_replace("<br />", "\n", $linkres->content))); $main_smarty->assign('submit_summary', $linkres->link_summary); $main_smarty->assign('submit_group', $linkres->link_group_id); $main_smarty->assign('submit_category', $linkres->category); $main_smarty->assign('submit_additional_cats', $linkres->additional_cats); $main_smarty->assign('tags_words', $linkres->tags); include_once mnminclude . 'dbtree.php'; $array = tree_to_array(0, table_categories, FALSE); $array = array_values(array_filter($array, "allowToAuthorCat")); $main_smarty->assign('submit_lastspacer', 0); $main_smarty->assign('submit_cat_array', $array); /*include_once(mnminclude.'group.php'); $group_arr=array(); $group_arr = get_groupdetail_user(); //echo "group".print_r($group_arr); $main_smarty->assign('submit_group_array', get_groupdetail_user());*/ //to display group drop down if (enable_group == "true") { $output = ''; $group_membered = $db->get_results("SELECT group_id,group_name FROM " . table_groups . " \n\t\t\tLEFT JOIN " . table_group_member . " ON member_group_id=group_id\n\t\t\tWHERE member_user_id = {$current_user->user_id} AND group_status = 'Enable' \n\t\t\t\tAND member_status='active'\n\t\t\t\tAND (member_role != 'banned' && member_role != 'flagged') \n\t\t\tORDER BY group_name ASC"); if ($group_membered) { $output .= "<select name='link_group_id' tabindex='3' class='form-control submit_group_select'>"; $output .= "<option value = ''>" . $main_smarty->get_config_vars('PLIGG_Visual_Group_Select_Group') . "</option>"; foreach ($group_membered as $results) { $output .= "<option value = " . $results->group_id . ($linkres->link_group_id ? ' selected' : '') . ">" . $results->group_name . "</option>"; } $output .= "</select>"; } $main_smarty->assign('output', $output); } if ($current_user->authenticated != TRUE) { $vars = ''; check_actions('register_showform', $vars); } $main_smarty->assign('tpl_extra_fields', $the_template . '/submit_extra_fields'); $main_smarty->assign('tpl_center', $the_template . '/submit_step_2_center'); define('pagename', 'submit'); $main_smarty->assign('pagename', pagename); $vars = ''; check_actions('do_submit1', $vars); $_SESSION['step'] = 1; $main_smarty->display($the_template . '/pligg.tpl'); }
$main_smarty->assign('submit_link_field9', $linkres->link_field9); $main_smarty->assign('submit_link_field10', $linkres->link_field10); $main_smarty->assign('submit_link_field11', $linkres->link_field11); $main_smarty->assign('submit_link_field12', $linkres->link_field12); $main_smarty->assign('submit_link_field13', $linkres->link_field13); $main_smarty->assign('submit_link_field14', $linkres->link_field14); $main_smarty->assign('submit_link_field15', $linkres->link_field15); $main_smarty->assign('Spell_Checker', Spell_Checker); $catsql = mysql_query("SELECT category_id, category_name FROM " . table_categories . " WHERE category_lang='{$dblang}' ORDER BY category_name ASC"); $categories = array(); while ($rows = mysql_fetch_array($catsql, MYSQL_ASSOC)) { array_push($categories, $rows); } $main_smarty->assign('categories', $categories); include_once mnminclude . 'dbtree.php'; $array = tree_to_array(0, table_categories, FALSE); $main_smarty->assign('lastspacer', 0); $main_smarty->assign('cat_array', $array); $canIhaveAccess = 0; $canIhaveAccess = $canIhaveAccess + checklevel('god'); $canIhaveAccess = $canIhaveAccess + checklevel('admin'); $main_smarty->assign('canIhaveAccess', $canIhaveAccess); if (Enable_Tags) { $main_smarty->assign('tags', $linkres->tags); if (!empty($linkres->tags)) { $tags_words = str_replace(",", ", ", $linkres->tags); $tags_url = urlencode($linkres->tags); $main_smarty->assign('tags_words', $tags_words); $main_smarty->assign('tags_url', $tags_url); } }
function do_sidebar($var_smarty) { global $db, $dblang, $globals; $_caching = $var_smarty->cache; // get the current cache settings $var_smarty->cache = true; // cache has to be on otherwise is_cached will always be false $var_smarty->cache_lifetime = -1; // lifetime has to be set to something otherwise is_cached will always be false $thetpl = $var_smarty->get_template_vars('the_template_sidebar_modules') . '/categories.tpl'; // check to see if the category sidebar module is already cached // if it is, use it if (isset($_REQUEST['category'])) { $thecat = $_REQUEST['category']; } else { $thecat = ''; } if ($var_smarty->is_cached($thetpl, 'sidebar|category|' . $thecat)) { $var_smarty->assign('cat_array', 'x'); // this is needed. sidebar.tpl won't include the category module if cat_array doesnt have some data } else { if (isset($_REQUEST['category'])) { $thecat = $db->get_var("SELECT category_name FROM " . table_categories . " WHERE `category_safe_name` = '" . $_REQUEST['category'] . "';"); } if (!empty($_REQUEST['id'])) { $doing_story = true; } else { $doing_story = false; } $var_smarty->assign('UrlMethod', urlmethod); $categories = $db->get_results("SELECT category_id, category_name FROM " . table_categories . " WHERE category_lang='{$dblang}' and category_parent = 0 ORDER BY category_name ASC"); foreach ($categories as $category) { if (isset($thecat)) { if ($category->category_id == $thecat) { $globals['category_id'] = $category->category_id; $globals['category_name'] = $category->category_name; } } } $pos = strrpos($_SERVER["SCRIPT_NAME"], "/"); $script_name = substr($_SERVER["SCRIPT_NAME"], $pos + 1, 100); $script_name = str_replace(".php", "", $script_name); if ($script_name != 'submit') { include_once 'dbtree.php'; $array = tree_to_array(0, table_categories); $var_smarty->assign('lastspacer', 0); $var_smarty->assign('cat_array', $array); } $published_count = $db->get_var("SELECT count(*) FROM " . table_links . " WHERE link_status = 'published'"); $var_smarty->assign('published_count', $published_count); $categories = mysql_query("select *, count(*) as count from " . table_links . ", " . table_categories . " where category_lang='{$dblang}' and category_id=link_category group by link_category ORDER BY category_name ASC"); $categorylist = array(); while ($rows = mysql_fetch_array($categories, MYSQL_ASSOC)) { array_push($categorylist, $rows); } $var_smarty->assign('categorylist', $categorylist); $var_smarty->assign('category_url', getmyurl('maincategory')); } $var_smarty->cache = $_caching; // set cache back to original value check_actions('do_sidebar'); return $var_smarty; }
/** * 将树转换为平面的数组 * * @param array $node * @param string $fchildrens * * @return array */ function tree_to_array(&$node, $fchildrens = 'childrens') { $ret = array(); if (isset($node[$fchildrens]) && is_array($node[$fchildrens])) { foreach ($node[$fchildrens] as $child) { $ret = array_merge($ret, tree_to_array($child, $fchildrens)); } unset($node[$fchildrens]); $ret[] = $node; } else { $ret[] = $node; } return $ret; }
function do_submit1() { global $main_smarty, $db, $dblang, $current_user, $the_template; $url = htmlspecialchars(sanitize($_POST['url'], 3)); $url = str_replace('&', '&', $url); $url = html_entity_decode($url); $linkres = new Link(); $linkres->randkey = sanitize($_POST['randkey'], 3); if (Submit_Show_URL_Input == false) { $url = "http://"; $linkres->randkey = rand(10000, 10000000); } $Submit_Show_URL_Input = Submit_Show_URL_Input; if ($url == "http://" || $url == "") { $Submit_Show_URL_Input = false; } $main_smarty->assign('randkey', $linkres->randkey); $main_smarty->assign('submit_url', $url); $main_smarty->assign('Submit_Show_URL_Input', $Submit_Show_URL_Input); $main_smarty->assign('Submit_Require_A_URL', Submit_Require_A_URL); $edit = false; $linkres->get($url); $trackback = $linkres->trackback; if ($url == "http://" || $url == "") { if (Submit_Require_A_URL == false) { $linkres->valid = true; } else { $linkres->valid = false; } $linkres->url_title = ""; } $vars = array("url" => $url, 'linkres' => $linkres); check_actions('submit_validating_url', $vars); $linkres = $vars['linkres']; if (!$linkres->valid) { $main_smarty->assign('submit_error', 'invalidurl'); $main_smarty->assign('tpl_center', $the_template . '/submit_errors'); $main_smarty->display($the_template . '/pligg.tpl'); return; } if (Submit_Require_A_URL == true || $url != "http://" && $url != "") { if ($linkres->duplicates($url) > 0) { $main_smarty->assign('submit_search', getmyurl("search_url", htmlentities($url))); $main_smarty->assign('submit_error', 'dupeurl'); $main_smarty->assign('tpl_center', $the_template . '/submit_errors'); define('pagename', 'submit'); $main_smarty->assign('pagename', pagename); $main_smarty->display($the_template . '/pligg.tpl'); return; } } $vars = array("url" => $url); check_actions('submit_validating_url', $vars); totals_adjust_count('discard', 1); //echo 'id'.$current_user->user_id; $linkres->status = 'discard'; $linkres->author = $current_user->user_id; $linkres->store(); $main_smarty->assign('StorySummary_ContentTruncate', StorySummary_ContentTruncate); $main_smarty->assign('SubmitSummary_Allow_Edit', SubmitSummary_Allow_Edit); $main_smarty->assign('enable_tags', Enable_Tags); $main_smarty->assign('submit_url_title', $linkres->url_title); $main_smarty->assign('submit_id', $linkres->id); $main_smarty->assign('submit_type', $linkres->type()); if (isset($link_title)) { $main_smarty->assign('submit_title', $link_title); } if (isset($link_content)) { $main_smarty->assign('submit_content', $link_content); } $main_smarty->assign('submit_trackback', $trackback); $main_smarty->assign('submit_link_field1', $linkres->link_field1); $main_smarty->assign('submit_link_field2', $linkres->link_field2); $main_smarty->assign('submit_link_field3', $linkres->link_field3); $main_smarty->assign('submit_link_field4', $linkres->link_field4); $main_smarty->assign('submit_link_field5', $linkres->link_field5); $main_smarty->assign('submit_link_field6', $linkres->link_field6); $main_smarty->assign('submit_link_field7', $linkres->link_field7); $main_smarty->assign('submit_link_field8', $linkres->link_field8); $main_smarty->assign('submit_link_field9', $linkres->link_field9); $main_smarty->assign('submit_link_field10', $linkres->link_field10); $main_smarty->assign('submit_link_field11', $linkres->link_field11); $main_smarty->assign('submit_link_field12', $linkres->link_field12); $main_smarty->assign('submit_link_field13', $linkres->link_field13); $main_smarty->assign('submit_link_field14', $linkres->link_field14); $main_smarty->assign('submit_link_field15', $linkres->link_field15); $main_smarty->assign('submit_link_group_id', $linkres->link_group_id); include_once mnminclude . 'dbtree.php'; $array = tree_to_array(0, table_categories, FALSE); $array = array_values(array_filter($array, "allowToAuthorCat")); $main_smarty->assign('submit_lastspacer', 0); $main_smarty->assign('submit_cat_array', $array); /*include_once(mnminclude.'group.php'); $group_arr=array(); $group_arr = get_groupdetail_user(); //echo "group".print_r($group_arr); $main_smarty->assign('submit_group_array', get_groupdetail_user());*/ //to display group drop down if (enable_group == "true") { $output = ''; $group_membered = $db->get_results("SELECT group_id,group_name FROM " . table_groups . " \r\n\t\t\t\t\t\t\tLEFT JOIN " . table_group_member . " ON member_group_id=group_id\r\n\t\t\t\t\t\t\tWHERE member_user_id = {$current_user->user_id} AND group_status = 'Enable' AND member_status='active'"); if ($group_membered) { $output .= "<select name='link_group_id'>"; $output .= "<option value = ''>" . $main_smarty->get_config_vars('PLIGG_Visual_Group_Select_Group') . "</option>"; foreach ($group_membered as $results) { $output .= "<option value = " . $results->group_id . ">" . $results->group_name . "</option>"; } $output .= "</select>"; } $main_smarty->assign('output', $output); } if ($current_user->authenticated != TRUE) { $vars = ''; check_actions('register_showform', $vars); } $main_smarty->assign('Spell_Checker', Spell_Checker); $main_smarty->assign('tpl_extra_fields', $the_template . '/submit_extra_fields'); $main_smarty->assign('tpl_center', $the_template . '/submit_step_2'); define('pagename', 'submit'); $main_smarty->assign('pagename', pagename); $vars = ''; check_actions('do_submit1', $vars); $main_smarty->display($the_template . '/pligg.tpl'); }
function do_submit1() { global $main_smarty, $db, $dblang, $current_user, $the_template; $url = htmlspecialchars(strip_tags(trim($_POST['url']))); $url = html_entity_decode($url); // thanks czytom $linkres = new Link(); $linkres->randkey = strip_tags($_POST['randkey']); if (Submit_Show_URL_Input == false) { $url = "http://"; $linkres->randkey = rand(10000, 10000000); } $Submit_Show_URL_Input = Submit_Show_URL_Input; if ($url == "http://" || $url == "") { $Submit_Show_URL_Input = false; } $main_smarty->assign('randkey', $linkres->randkey); $main_smarty->assign('submit_url', $url); $main_smarty->assign('Submit_Show_URL_Input', $Submit_Show_URL_Input); $main_smarty->assign('Submit_Require_A_URL', Submit_Require_A_URL); $edit = false; $linkres->get($url); $trackback = $linkres->trackback; if ($url == "http://" || $url == "") { if (Submit_Require_A_URL == false) { $linkres->valid = true; } else { $linkres->valid = false; } } if (!$linkres->valid) { $main_smarty->assign('submit_error', 'invalidurl'); $main_smarty->assign('tpl_center', $the_template . '/submit_errors'); define('pagename', 'submit'); $main_smarty->assign('pagename', pagename); $main_smarty->display($the_template . '/pligg.tpl'); return; } if (Submit_Require_A_URL == true || $url != "http://" && $url != "") { if ($linkres->duplicates($url) > 0) { $main_smarty->assign('submit_search', getmyurl("search", htmlentities($url))); $main_smarty->assign('submit_error', 'dupeurl'); $main_smarty->assign('tpl_center', $the_template . '/submit_errors'); define('pagename', 'submit'); $main_smarty->assign('pagename', pagename); $main_smarty->display($the_template . '/pligg.tpl'); return; } } check_actions('submit_validating_url', array("url" => $url)); $linkres->status = 'discard'; $linkres->author = $current_user->user_id; $linkres->store(); $main_smarty->assign('StorySummary_ContentTruncate', StorySummary_ContentTruncate); $main_smarty->assign('SubmitSummary_Allow_Edit', SubmitSummary_Allow_Edit); $main_smarty->assign('enable_tags', Enable_Tags); $main_smarty->assign('submit_url_title', $linkres->url_title); $main_smarty->assign('submit_id', $linkres->id); $main_smarty->assign('submit_type', $linkres->type()); if (isset($link_title)) { $main_smarty->assign('submit_title', $link_title); } if (isset($link_content)) { $main_smarty->assign('submit_content', $link_content); } $main_smarty->assign('submit_trackback', $trackback); $main_smarty->assign('submit_link_field1', $linkres->link_field1); $main_smarty->assign('submit_link_field2', $linkres->link_field2); $main_smarty->assign('submit_link_field3', $linkres->link_field3); $main_smarty->assign('submit_link_field4', $linkres->link_field4); $main_smarty->assign('submit_link_field5', $linkres->link_field5); $main_smarty->assign('submit_link_field6', $linkres->link_field6); $main_smarty->assign('submit_link_field7', $linkres->link_field7); $main_smarty->assign('submit_link_field8', $linkres->link_field8); $main_smarty->assign('submit_link_field9', $linkres->link_field9); $main_smarty->assign('submit_link_field10', $linkres->link_field10); $main_smarty->assign('submit_link_field11', $linkres->link_field11); $main_smarty->assign('submit_link_field12', $linkres->link_field12); $main_smarty->assign('submit_link_field13', $linkres->link_field13); $main_smarty->assign('submit_link_field14', $linkres->link_field14); $main_smarty->assign('submit_link_field15', $linkres->link_field15); $catsql = mysql_query("SELECT category_id, category_name FROM " . table_categories . " WHERE category_lang='{$dblang}' ORDER BY category_name ASC"); $categories = array(); while ($rows = mysql_fetch_array($catsql, MYSQL_ASSOC)) { array_push($categories, $rows); } $main_smarty->assign('categories', $categories); include_once mnminclude . 'dbtree.php'; $array = tree_to_array(0, table_categories, FALSE); $main_smarty->assign('lastspacer', 0); $main_smarty->assign('cat_array', $array); //spellchecker $main_smarty->assign('Spell_Checker', Spell_Checker); $main_smarty->assign('tpl_extra_fields', $the_template . '/submit_extra_fields'); $main_smarty->assign('tpl_center', $the_template . '/submit_step_2'); define('pagename', 'submit'); $main_smarty->assign('pagename', pagename); $main_smarty->display($the_template . '/pligg.tpl'); }