Advertisement
Guest User

Untitled

a guest
Mar 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.66 KB | None | 0 0
  1. <?php
  2.  
  3. include_once('internal/Smarty.class.php');
  4. $main_smarty = new Smarty;
  5.  
  6. include('config.php');
  7. include(mnminclude.'html1.php');
  8. include(mnminclude.'link.php');
  9. include(mnminclude.'smartyvariables.php');
  10.  
  11. check_referrer();
  12.  
  13. force_authentication();
  14.  
  15. // restrict access to admins
  16. $canIhaveAccess = 0;
  17. $canIhaveAccess = $canIhaveAccess + checklevel('admin');
  18. if($canIhaveAccess == 0){  
  19.     header("Location: " . getmyurl('login', $_SERVER['REQUEST_URI']));
  20.     die();
  21. }
  22.  
  23. function dowork(){ 
  24.     $canIhaveAccess = 0;
  25.     $canIhaveAccess = $canIhaveAccess + checklevel('admin');
  26.     if($canIhaveAccess == 1)
  27.     {
  28.         if(is_writable('settings.php') == 0){
  29.             die("Error: settings.php is not writeable.");
  30.         }
  31.         if(isset($_REQUEST['action'])){
  32.             $action = $_REQUEST['action'];
  33.         } else {
  34.             $action = "view";
  35.         }
  36.         if($action == "view"){
  37.             $config = new kliqqiconfig;
  38.             if(isset($_REQUEST['page'])){
  39.                 $config->var_page = $_REQUEST['page'];
  40.                 $config->showpage();
  41.             }
  42.         }
  43.         if($action == "save"){
  44.             $config = new kliqqiconfig;
  45.             $config->var_id = substr($_REQUEST['var_id'], 6, 10);
  46.             $config->var_value = $_REQUEST['var_value'];
  47.             $config->store();
  48.         }
  49.     }
  50. }  
  51.  
  52. // pagename
  53. define('pagename', 'delete');
  54. $main_smarty->assign('pagename', pagename);
  55. if(isset($_REQUEST['link_id'])){
  56.     global $db;
  57.     $link_id = $_REQUEST['link_id'];
  58.     if(!is_numeric($link_id)){die();}
  59.     $linkres = new Link;
  60.     $linkres->id = $link_id;
  61.     $linkres->read();
  62.     totals_adjust_count($linkres->status, -1);
  63.  
  64.     // module system hook
  65.     $vars = array('link_id' => $linkres->id);
  66.     check_actions('admin_story_delete', $vars);
  67.  
  68.     /*********find out the page slug dynamically ***********/
  69.     $linkslugvalue =  $db->get_results("SELECT ".table_links.".link_category, ".table_categories.".category_safe_name FROM ".table_categories." LEFT JOIN ".table_links. " ON ".table_links.".link_category = ".table_categories.".category__auto_id WHERE ".table_links.".link_id = '".$link_id."' LIMIT 0,1");
  70.    
  71.     $linkslug = '';
  72.     foreach($linkslugvalue as $slug)
  73.         $linkslug = $slug->category_safe_name;
  74.  
  75.     $delete_referrer = $_SERVER["HTTP_REFERER"];
  76.  
  77. if ($URLMethod == 1) {
  78.     $delete_referrer_no_query= strtok($_SERVER["HTTP_REFERER"],'?');
  79.     if (strstr($delete_referrer, 'group_story.php')) {
  80.         $redirectUrl = $delete_referrer;
  81.     }elseif (strstr($delete_referrer, 'story.php')) {
  82.         if ($linkres->status == 'new') {
  83.             $redirectUrl = $my_base_url.$my_kliqqi_base . "/".$linkres->status.".php?category=$linkslug";
  84.         }else{
  85.             $redirectUrl = $my_base_url.$my_kliqqi_base . "/?category=$linkslug";
  86.         }
  87.     }else{
  88.         $redirectUrl = $delete_referrer;
  89.     }
  90. }elseif ($URLMethod == 2) {
  91.     /*Redwine: the first part of the below conditional stattement: strstr($delete_referrer, "story.php?title=".$linkres->title_url) is to account for when an Admin is discarding a story; the links are in url method 1 and having the link safe title instead of the link id!*/
  92.     if (strstr($delete_referrer, "story.php?title=".$linkres->title_url) || strstr($delete_referrer, "/$linkslug/".$linkres->title_url)) {
  93.         if ($linkres->status == 'new') {
  94.             $redirectUrl = $my_base_url.$my_kliqqi_base . "/".$linkres->status."/$linkslug/";
  95.         }else{
  96.             $redirectUrl = $my_base_url.$my_kliqqi_base . "/$linkslug/";
  97.         }
  98.     }else{
  99.         $redirectUrl = $delete_referrer;
  100.     }  
  101. }
  102.  
  103.     $link_delete = $db->query(" Delete from ".table_links." where link_id =".$linkres->id);
  104.     $vote_delete = $db->query(" Delete from ".table_votes." where vote_link_id =".$linkres->id);
  105.     $comment_delete = $db->query(" Delete from ".table_comments." where comment_link_id =".$linkres->id);
  106.     $tag_delete = $db->query(" Delete from ".table_tags." where tag_link_id =".$linkres->id);
  107.     $saved_delete = $db->query(" Delete from ".table_saved_links." where saved_link_id =".$linkres->id);
  108.     $trackback_delete = $db->query(" Delete from ".table_trackbacks." where trackback_link_id =".$linkres->id);
  109.  
  110.     $db->query("DELETE FROM ".table_additional_categories." WHERE ac_link_id =".$linkres->id);
  111.  
  112.     $db->query("DELETE FROM ".table_tag_cache);
  113.    
  114.     # Redwine - Sidebar tag cache fix
  115.     $db->query($sql="INSERT INTO ".table_tag_cache." select tag_words, count(DISTINCT link_id) as count FROM ".table_tags.", ".table_links." WHERE tag_lang='en' and link_id = tag_link_id and (link_status='published' OR link_status='new') GROUP BY tag_words order by count desc");
  116.  
  117.     if ($_SERVER['HTTP_REFERER'] && strpos($_SERVER['HTTP_REFERER'], $my_base_url.$my_kliqqi_base)  !== false){
  118.         header('Location: '.$redirectUrl);
  119.     }else{
  120.         header('Location: '.$my_base_url.$my_kliqqi_base);
  121.     }
  122. }
  123.  
  124.  
  125. if(isset($_REQUEST['comment_id'])){
  126.  
  127.     global $db;
  128.     $comment_id = $_REQUEST['comment_id'];
  129.     if(!is_numeric($comment_id)){die();}
  130.     $link_id = $db->get_var("SELECT comment_link_id FROM `" . table_comments . "` WHERE `comment_id` = $comment_id");
  131.    
  132.     $vars = array('comment_id' => $comment_id);
  133.     check_actions('comment_deleted', $vars);
  134.    
  135.     $db->query('DELETE FROM `' . table_comments . '` WHERE `comment_id` = "'.$comment_id.'"');
  136.     $comments = $db->get_results($sql="SELECT comment_id FROM " . table_comments . " WHERE `comment_parent` = '$comment_id'");
  137.     if (!empty($comments)) {
  138.         foreach($comments as $comment)
  139.         {
  140.             $vars = array('comment_id' => $comment->comment_id);
  141.             check_actions('comment_deleted', $vars);
  142.         }
  143.     }
  144.     $db->query('DELETE FROM `' . table_comments . '` WHERE `comment_parent` = "'.$comment_id.'"');
  145.     $link = new Link;
  146.     $link->id=$link_id;
  147.     $link->read();
  148.     $link->recalc_comments();
  149.     $link->store();
  150.     $link='';
  151.    
  152.     if ($_SERVER['HTTP_REFERER'] && strpos($_SERVER['HTTP_REFERER'], $my_base_url.$my_kliqqi_base)===0)
  153.        header('Location: '.$_SERVER['HTTP_REFERER']);
  154.     else
  155.         header('Location: '.$redirectUrl);
  156. }
  157. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement