PageRenderTime 787ms CodeModel.GetById 44ms RepoModel.GetById 11ms app.codeStats 0ms

/libs/link.php

https://github.com/sad1990/--
PHP | 1421 lines | 1151 code | 185 blank | 85 comment | 225 complexity | f4a1762774752f246ef6f2803b1cef8e MD5 | raw file
Possible License(s): CC-BY-3.0, GPL-2.0, Apache-2.0
  1. <?php
  2. if(!defined('mnminclude')){header('Location: ../error_404.php');die();}
  3. class Link {
  4. var $id = 0;
  5. var $author = -1;
  6. var $username = false;
  7. var $randkey = 0;
  8. var $karma = 1;
  9. var $valid = true;
  10. var $date = false;
  11. var $published_date = 0;
  12. var $modified = 0;
  13. var $url = '';
  14. var $url_title = '';
  15. var $url_description = '';
  16. var $encoding = false;
  17. var $status = 'discard';
  18. var $type = '';
  19. var $category = 0;
  20. var $additional_cats = array();
  21. var $votes = 0;
  22. var $comments = 0;
  23. var $reports = 0;
  24. var $title = '';
  25. var $title_url = '';
  26. var $tags = '';
  27. var $content = '';
  28. var $html = true;
  29. var $trackback = false;
  30. var $read = true;
  31. var $fullread = true;
  32. var $voted = false;
  33. var $link_field1 = '';
  34. var $link_field2 = '';
  35. var $link_field3 = '';
  36. var $link_field4 = '';
  37. var $link_field5 = '';
  38. var $link_field6 = '';
  39. var $link_field7 = '';
  40. var $link_field8 = '';
  41. var $link_field9 = '';
  42. var $link_field10 = '';
  43. var $link_field11 = '';
  44. var $link_field12 = '';
  45. var $link_field13 = '';
  46. var $link_field14 = '';
  47. var $link_field15 = '';
  48. var $link_group_id = 0;
  49. var $current_user_votes = 0;
  50. var $current_user_reports = 0;
  51. var $debug = false;
  52. var $check_saved = true; // check to see if the user has 'saved' this link. sidebarstories doesn't need to check (so don't waste time on it)
  53. var $get_author_info = true; // get information about the link_author. sidebarstories doesn't need this information (so don't waste time on it)
  54. var $check_friends = true; // see if the author is a friend of the logged in user. sidebarstories doesn't need this information (so don't waste time on it)
  55. var $vote_from_this_ip=0; // if disable multiple vote from the same ip
  56. var $report_from_this_ip=0; // if disable multiple vote from the same ip
  57. function get($url) {
  58. $url=trim($url);
  59. if(CHECK_SPAM && $this->check_spam($url)){
  60. $this->valid = false;
  61. return;
  62. }
  63. if(Validate_URL != false){
  64. if($url != 'http://' && $url != ''){
  65. $r = new PliggHTTPRequest($url);
  66. $xxx = $r->DownloadToString();
  67. } else {
  68. $this->url='http://';
  69. $xxx = '';
  70. }
  71. }else{
  72. $xxx = "";
  73. $this->valid = true;
  74. $this->url=$url;
  75. return;
  76. }
  77. if(!($this->html = $xxx)) {
  78. return;
  79. }
  80. if($xxx == "BADURL") {
  81. $this->valid = false; return;
  82. }
  83. $this->valid = true;
  84. $this->url=$url;
  85. if(preg_match('/<title>(.+)<\/title>/', $this->html, $matches)) {
  86. $this->url_title=trim($matches[1]);
  87. }
  88. if(preg_match("'<meta name=\"description\" content=\"([^<]*?)\"\s?/?>'i", $this->html, $matches)) {
  89. $this->url_description=$matches[1];
  90. }else{
  91. // Fall back on the first <p> tag content
  92. $start = strpos($this->html, '<p>');
  93. $end = strpos($this->html, '</p>', $start);
  94. $paragraph = substr($this->html, $start, $end-$start+4);
  95. $paragraph = html_entity_decode(strip_tags($paragraph));
  96. // Make sure that it's over 100 characters in length
  97. if (strlen($paragraph)>100){
  98. $this->url_description=$paragraph;
  99. }
  100. }
  101. // Detect trackbacks
  102. if (sanitize($_POST['trackback'], 3) != '') {
  103. $this->trackback=trim(sanitize($_POST['trackback'], 3));
  104. } elseif (preg_match('/trackback:ping="([^"]+)"/i', $this->html, $matches) ||
  105. preg_match('/trackback:ping +rdf:resource="([^>]+)"/i', $this->html, $matches) ||
  106. preg_match('/<trackback:ping>([^<>]+)/i', $this->html, $matches)) {
  107. $this->trackback=trim($matches[1]);
  108. } elseif (preg_match('/<a[^>]+rel="trackback"[^>]*>/i', $this->html, $matches)) {
  109. if (preg_match('/href="([^"]+)"/i', $matches[0], $matches2)) {
  110. $this->trackback=trim($matches2[1]);
  111. }
  112. } elseif (preg_match('/<a[^>]+href=[^>]+>trackback<\/a>/i', $this->html, $matches)) {
  113. if (preg_match('/href="([^"]+)"/i', $matches[0], $matches2)) {
  114. $this->trackback=trim($matches2[1]);
  115. }
  116. }
  117. }
  118. function type() {
  119. if (empty($this->type)) {
  120. return 'normal';
  121. }
  122. return $this->type;
  123. }
  124. function store() {
  125. global $db, $current_user;
  126. // DB 09/03/08
  127. if(!is_numeric($this->id)){return false;}
  128. /////
  129. $this->store_basic();
  130. $link_url = $db->escape($this->url);
  131. $link_url_title = $db->escape($this->url_title);
  132. $link_url_description = $db->escape($this->url_description);
  133. $link_title = $db->escape($this->title);
  134. $link_title_url = $db->escape($this->title_url);
  135. if($link_title_url == ""){$link_title_url = makeUrlFriendly($this->title, $this->id);}
  136. $link_tags = $db->escape($this->tags);
  137. $link_content = $db->escape($this->content);
  138. $link_field1 = $db->escape($this->link_field1);
  139. $link_field2 = $db->escape($this->link_field2);
  140. $link_field3 = $db->escape($this->link_field3);
  141. $link_field4 = $db->escape($this->link_field4);
  142. $link_field5 = $db->escape($this->link_field5);
  143. $link_field6 = $db->escape($this->link_field6);
  144. $link_field7 = $db->escape($this->link_field7);
  145. $link_field8 = $db->escape($this->link_field8);
  146. $link_field9 = $db->escape($this->link_field9);
  147. $link_field10 = $db->escape($this->link_field10);
  148. $link_field11 = $db->escape($this->link_field11);
  149. $link_field12 = $db->escape($this->link_field12);
  150. $link_field13 = $db->escape($this->link_field13);
  151. $link_field14 = $db->escape($this->link_field14);
  152. $link_field15 = $db->escape($this->link_field15);
  153. $link_group_id = $db->escape($this->link_group_id);
  154. $link_summary = $db->escape($this->link_summary);
  155. // Save old SEO URL if changed
  156. $old_url = $db->get_var("SELECT link_title_url FROM " . table_links . " WHERE link_id={$this->id}");
  157. if ($old_url && $old_url != $this->title_url)
  158. $db->query("INSERT INTO ".table_old_urls." SET old_link_id={$this->id}, old_title_url='$old_url'");
  159. $sql = "UPDATE " . table_links . " set link_summary='$link_summary', link_title_url='$link_title_url', link_url='$link_url', link_url_title='$link_url_title', link_title='$link_title', link_content='$link_content', link_tags='$link_tags', link_field1='$link_field1', link_field2='$link_field2', link_field3='$link_field3', link_field4='$link_field4', link_field5='$link_field5', link_field6='$link_field6', link_field7='$link_field7', link_field8='$link_field8', link_field9='$link_field9', link_field10='$link_field10', link_field11='$link_field11', link_field12='$link_field12', link_field13='$link_field13', link_field14='$link_field14', link_field15='$link_field15', link_group_id = $link_group_id WHERE link_id=$this->id";
  160. if($this->debug == true){echo '<hr>Store:'. $sql . '<hr>';}
  161. //echo "query".$sql;
  162. $db->query($sql);
  163. $pos = strrpos($_SERVER["SCRIPT_NAME"], "/");
  164. $script_name = substr($_SERVER["SCRIPT_NAME"], $pos + 1, 100);
  165. $script_name = str_replace(".php", "", $script_name);
  166. }
  167. function store_basic() {
  168. global $db, $current_user;
  169. // DB 09/03/08
  170. if(!is_numeric($this->id)){return false;}
  171. /////
  172. if(!$this->date) $this->date=time();
  173. $link_author = $this->author;
  174. $link_status = $this->status;
  175. $link_votes = $this->votes;
  176. $link_comments = $this->comments;
  177. $link_reports = $this->reports;
  178. $link_karma = $this->karma;
  179. $link_randkey = $this->randkey;
  180. $link_category = $this->category;
  181. $link_date = $this->date;
  182. if($this->published_date == 0){$this->published_date = 943941600;}
  183. $link_published_date = $this->published_date;
  184. $link_group_id = $this->link_group_id;
  185. $vars = array('link' => $this);
  186. check_actions('link_store_basic_pre_sql', $vars);
  187. if($this->id===0) {
  188. if(buries_to_spam == 0) {
  189. $sql = "INSERT IGNORE INTO " . table_links . " (link_author, link_randkey, link_category, link_date, link_published_date, link_votes, link_karma, link_title, link_content ,link_group_id) VALUES ($link_author, $link_randkey, $link_category, FROM_UNIXTIME($link_date), FROM_UNIXTIME($link_published_date), $link_votes, $link_karma, '', '',$link_group_id)";
  190. } else {
  191. $sql = "INSERT IGNORE INTO " . table_links . " (link_author, link_status, link_randkey, link_category, link_date, link_published_date, link_votes, link_karma, link_title, link_content ,link_group_id) VALUES ($link_author, '$link_status', $link_randkey, $link_category, FROM_UNIXTIME($link_date), FROM_UNIXTIME($link_published_date), $link_votes, $link_karma, '', '',$link_group_id)";
  192. }
  193. if($this->debug == true){
  194. echo '<hr>store_basic:Insert:' . $sql . '<hr>';
  195. }
  196. $db->query($sql);
  197. $this->id = $db->insert_id;
  198. } else {
  199. // update
  200. if(buries_to_spam == 0) {
  201. $sql = "UPDATE " . table_links . " set `link_reports`=$link_reports, `link_comments`=$link_comments, link_author=$link_author, link_status='$link_status', link_randkey=$link_randkey, link_category='$link_category', link_modified=NULL, link_date=FROM_UNIXTIME($link_date), link_published_date=FROM_UNIXTIME($link_published_date), link_votes=$link_votes, link_karma=$link_karma, link_group_id=$link_group_id WHERE link_id=$this->id";
  202. } else {
  203. $sql = "UPDATE " . table_links . " set `link_reports`=$link_reports, `link_comments`=$link_comments, link_author=$link_author, link_randkey=$link_randkey, link_category='$link_category', link_modified=NULL, link_date=FROM_UNIXTIME($link_date), link_published_date=FROM_UNIXTIME($link_published_date), link_votes=$link_votes, link_karma=$link_karma, link_group_id=$link_group_id WHERE link_id=$this->id";
  204. }
  205. if($this->debug == true){
  206. echo '<hr>store_basic:Update:' . $sql . '<hr>';
  207. }
  208. $db->query($sql);
  209. $db->query("DELETE FROM ".table_additional_categories." WHERE ac_link_id={$this->id}");
  210. }
  211. foreach ($this->additional_cats as $cat)
  212. $db->query("INSERT INTO ".table_additional_categories." SET ac_cat_id='".sanitize($cat,3)."', ac_link_id={$this->id}");
  213. $vars = array('link' => $this);
  214. check_actions('link_store_basic_post_sql', $vars);
  215. }
  216. function read($usecache = TRUE) {
  217. global $db, $current_user, $cached_links;
  218. $id = $this->id;
  219. $this->rating = 0;
  220. if(!is_numeric($id)){return false;}
  221. // check to see if the link is cached
  222. // if it is, use it
  223. // if not, get from mysql and save to cache
  224. if (isset($cached_links[$id]) && $usecache == TRUE) {
  225. $link = $cached_links[$id];
  226. } else {
  227. $link = $db->get_row("SELECT " . table_links . ".* FROM " . table_links . " WHERE link_id = $id");
  228. $cached_links[$id] = $link;
  229. }
  230. if($link) {
  231. $this->author=$link->link_author;
  232. $this->userid=$link->link_author;
  233. $this->status=$link->link_status;
  234. $this->votes=$link->link_votes;
  235. $this->karma=$link->link_karma;
  236. $this->reports=$link->link_reports;
  237. $this->comments=$link->link_comments;
  238. $this->randkey=$link->link_randkey;
  239. $this->category=$link->link_category;
  240. $this->url= $link->link_url;
  241. $this->url= str_replace('&amp;', '&', $link->link_url);
  242. $this->url_title=$link->link_url_title;
  243. $this->url_description=$link->link_url_description;
  244. $this->title=$link->link_title;
  245. $this->title_url=$link->link_title_url;
  246. $this->tags=$link->link_tags;
  247. $this->content=$link->link_content;
  248. // DB 01/08/09
  249. $this->date=strtotime($link->link_date);
  250. // $date=$link->link_date;
  251. // $this->date=$db->get_var("SELECT UNIX_TIMESTAMP('$date')");
  252. $this->published_date=strtotime($link->link_published_date);
  253. // $date=$link->link_published_date;
  254. // $this->published_date=$db->get_var("SELECT UNIX_TIMESTAMP('$date')");
  255. $this->modified=strtotime($link->link_modified);
  256. // $date=$link->link_modified;
  257. // $this->modified=$db->get_var("SELECT UNIX_TIMESTAMP('$date')");
  258. /////
  259. $this->fullread = $this->read = true;
  260. $this->link_summary = $link->link_summary;
  261. $this->link_field1=$link->link_field1;
  262. $this->link_field2=$link->link_field2;
  263. $this->link_field3=$link->link_field3;
  264. $this->link_field4=$link->link_field4;
  265. $this->link_field5=$link->link_field5;
  266. $this->link_field6=$link->link_field6;
  267. $this->link_field7=$link->link_field7;
  268. $this->link_field8=$link->link_field8;
  269. $this->link_field9=$link->link_field9;
  270. $this->link_field10=$link->link_field10;
  271. $this->link_field11=$link->link_field11;
  272. $this->link_field12=$link->link_field12;
  273. $this->link_field13=$link->link_field13;
  274. $this->link_field14=$link->link_field14;
  275. $this->link_field15=$link->link_field15;
  276. $this->link_group_id=$link->link_group_id;
  277. $this->additional_cats = array();
  278. if ($results = $db->get_results("SELECT ac_cat_id FROM ".table_additional_categories." WHERE ac_link_id=$id", ARRAY_N))
  279. foreach ($results as $cat)
  280. $this->additional_cats[] = $cat[0];
  281. return true;
  282. }
  283. $this->fullread = $this->read = false;
  284. return false;
  285. }
  286. function read_basic() {
  287. global $db, $current_user;
  288. $this->username = false;
  289. $this->fullread = false;
  290. $this->rating = 0;
  291. $id = $this->id;
  292. if(!is_numeric($id)){return false;}
  293. if(($link = $db->get_row("SELECT link_comments, link_author, link_status, link_randkey, link_category, link_date, link_votes, link_karma, link_published_date,link_group_id FROM " . table_links . " WHERE link_id = $id"))) {
  294. $this->author=$link->link_author;
  295. $this->votes=$link->link_votes;
  296. $this->karma=$link->link_karma;
  297. $this->status=$link->link_status;
  298. $this->randkey=$link->link_randkey;
  299. $this->category=$link->link_category;
  300. // DB 01/08/09
  301. $this->date=strtotime($link->link_date);
  302. //$date=$link->link_date;
  303. //$this->date=$db->get_var("SELECT UNIX_TIMESTAMP('$date')");
  304. $this->published_date=strtotime($link->link_published_date);
  305. //$date=$link->link_published_date;
  306. //$this->published_date=$db->get_var("SELECT UNIX_TIMESTAMP('$date')");
  307. /////
  308. $this->comments=$link->link_comments;
  309. $this->link_group_id=$link->link_group_id;
  310. $this->read = true;
  311. $this->additional_cats = array();
  312. if ($results = $db->get_results("SELECT ac_cat_id FROM ".table_additional_categories." WHERE ac_link_id=$id", ARRAY_N))
  313. foreach ($results as $cat)
  314. $this->additional_cats[] = $cat[0];
  315. return true;
  316. }
  317. $this->read = false;
  318. return false;
  319. }
  320. function duplicates($url) {
  321. global $db;
  322. $link_url=$db->escape($url);
  323. $n = $db->get_var("SELECT count(*) FROM " . table_links . " WHERE link_url = '$link_url' AND link_status != 'discard'");
  324. return $n;
  325. }
  326. function duplicates_title($title) {
  327. global $db;
  328. $link_title=$db->escape($title);
  329. $n = $db->get_var("SELECT count(*) FROM " . table_links . " WHERE link_title = '$link_title' AND link_status != 'discard'");
  330. return $n;
  331. }
  332. function print_summary($type='full', $fetch = false, $link_summary_template = 'link_summary.tpl') {
  333. global $current_user, $globals, $the_template, $smarty, $ranklist, $db;
  334. // DB 09/03/08
  335. if(!is_numeric($this->id)){return false;}
  336. /////
  337. include_once('../internal/Smarty.class.php');
  338. $main_smarty = new Smarty;
  339. $main_smarty->compile_check=false;
  340. // enable caching at your own risk. this code is still experimental
  341. //$smarty->cache = true;
  342. $main_smarty->cache_lifetime = 120;
  343. $main_smarty->compile_dir = mnmpath."cache/";
  344. $main_smarty->template_dir = mnmpath."templates/";
  345. $main_smarty->cache_dir = mnmpath."cache/";
  346. $main_smarty->config_dir = "";
  347. $main_smarty->assign('pligg_language', pligg_language);
  348. $main_smarty->config_load(lang_loc . "/languages/lang_" . pligg_language . ".conf");
  349. $anonymous_can_vote = $db->get_var('SELECT var_value from ' . table_config . ' where var_name = "anonymous_vote";');
  350. $main_smarty->assign('anonymous_vote', $anonymous_can_vote);
  351. if(phpnum() == 4) {
  352. $main_smarty->force_compile = true;
  353. }
  354. $main_smarty = $this->fill_smarty($main_smarty, $type);
  355. $main_smarty->assign('use_title_as_link', use_title_as_link);
  356. $main_smarty->assign('open_in_new_window', open_in_new_window);
  357. $main_smarty->assign('the_template', The_Template);
  358. include mnminclude.'extra_fields_smarty.php';
  359. if($fetch == false){
  360. $main_smarty->display($the_template . '/' . $link_summary_template, 'story' . $this->id . "|" . $current_user->user_id . "|" . $type);
  361. } else {
  362. return $main_smarty->fetch($the_template . '/' . $link_summary_template, 'story' . $this->id . "|" . $current_user->user_id . "|" . $type);
  363. }
  364. }
  365. function fill_smarty($smarty, $type='full'){
  366. static $link_index=0;
  367. $link_index=$this->id;
  368. global $current_user, $globals, $the_template, $db, $ranklist;
  369. if (!$ranklist)
  370. {
  371. $users = $db->get_results("SELECT user_karma, COUNT(*) FROM ".table_users." WHERE user_level NOT IN ('Spammer') AND user_karma>0 GROUP BY user_karma ORDER BY user_karma DESC",ARRAY_N);
  372. $ranklist = array();
  373. $rank = 1;
  374. if ($users)
  375. foreach ($users as $dbuser)
  376. {
  377. $ranklist[$dbuser[0]] = $rank;
  378. $rank += $dbuser[1];
  379. }
  380. }
  381. // DB 08/04/08
  382. if(!is_numeric($this->id)){return false;}
  383. /////
  384. $smarty->assign('link_id', $this->id);
  385. if(!$this->read) return $smarty;
  386. $url = str_replace('&amp;', '&', htmlspecialchars($this->url));
  387. $url_short = txt_shorter($url);
  388. if($this->url == "http://" || $this->url == ''){
  389. $url_short = "http://";
  390. } else {
  391. $parsed = parse_url($this->url);
  392. if(isset($parsed['scheme'])){$url_short = $parsed['scheme'] . "://" . $parsed['host'];}
  393. }
  394. $title_short = htmlspecialchars(utf8_wordwrap($this->title, 30, " ", 1));
  395. $smarty->assign('viewtype', $type);
  396. $smarty->assign('URL_tagcloud', getmyurl("tagcloud"));
  397. $smarty->assign('No_URL_Name', No_URL_Name);
  398. if(track_outgoing == true && $url_short != "http://"){
  399. if(track_outgoing_method == "id"){$smarty->assign('url', getmyurl("out", ($this->id)));}
  400. if(track_outgoing_method == "title"){$smarty->assign('url', getmyurl("outtitle", urlencode($this->title_url)));}
  401. if(track_outgoing_method == "url"){$smarty->assign('url', getmyurl("outurl", ($url)));}
  402. } else {
  403. $smarty->assign('url', ($url));
  404. }
  405. // DB 11/12/08
  406. if ($url_short == "http://" || $url_short == "://")
  407. $smarty->assign('enc_url', urlencode(my_base_url.$this->get_internal_url()));
  408. else
  409. $smarty->assign('enc_url', urlencode($url));
  410. /////
  411. $smarty->assign('url_short', $url_short);
  412. $smarty->assign('title_short', $title_short);
  413. $smarty->assign('title_url', urlencode($this->title_url));
  414. $smarty->assign('enc_title_short', urlencode($title_short));
  415. $smarty->assign('story_url', $this->get_internal_url());
  416. $previd = $db->get_var("SELECT link_title_url FROM ".table_links." WHERE link_status = 'published' AND link_id < $this->id ORDER BY link_id DESC LIMIT 1");
  417. $nextid = $db->get_var("SELECT link_title_url FROM ".table_links." WHERE link_status = 'published' AND link_id > $this->id ORDER BY link_id ASC LIMIT 1");
  418. $smarty->assign('story_prev_url', getmyurl("storytitle", $previd));
  419. $smarty->assign('story_next_url', getmyurl("storytitle", $nextid));
  420. $smarty->assign('story_edit_url', getmyurl("editlink", $this->id));
  421. $smarty->assign('story_admin_url', getmyurl("admin_modify", $this->id));
  422. $smarty->assign('story_comment_count', $this->comments());
  423. $smarty->assign('story_status', $this->status);
  424. $smarty->assign('story_karma', $this->karma);
  425. if($type == "summary"){
  426. if($this->link_summary == ""){
  427. $smarty->assign('story_content', $this->truncate_content());
  428. } else {
  429. $smarty->assign('story_content', $this->link_summary);
  430. }
  431. }
  432. if($type == "full"){
  433. $smarty->assign('story_content', $this->content);
  434. }
  435. if($this->get_author_info == true){
  436. $smarty->assign('link_submitter', $this->username());
  437. $smarty->assign('submitter_profile_url', getmyurl('user', $this->username));
  438. $smarty->assign('submitter_rank', $ranklist[$this->userkarma]);
  439. $smarty->assign('user_extra_fields', $this->extra_field);
  440. }
  441. $smarty->assign('link_submit_time', $this->date);
  442. $smarty->assign('link_submit_timeago', txt_time_diff($this->date));
  443. $smarty->assign('link_submit_date', date('F, d Y g:i A',$this->date));
  444. $smarty->assign('link_published_time', $this->published_date);
  445. $smarty->assign('link_published_timeago', txt_time_diff($this->published_date));
  446. $smarty->assign('link_category', $this->category_name());
  447. if (Multiple_Categories)
  448. {
  449. $cats = array();
  450. foreach ($this->additional_cats as $cat)
  451. {
  452. $url = $this->category_safe_name($cat);
  453. if ($this->status == "published") $url = getmyurl("maincategory", $url);
  454. if ($this->status == "new") $url = getmyurl("newcategory", $url);
  455. if ($this->status == "discard") $url = getmyurl("discardedcategory", $url);
  456. $cats[$url] = $this->category_name($cat);
  457. }
  458. $smarty->assign('link_additional_cats', $cats);
  459. }
  460. //assign category id to smarty, so we can use it in the templates. Needed for category colors!
  461. $smarty->assign('category_id', $this->category);
  462. global $URLMethod;
  463. {$catvar = $this->category_safe_name();}
  464. $smarty->assign('Voting_Method', Voting_Method);
  465. $this->votecount = $this->countvotes();
  466. if(Voting_Method == 2)
  467. {
  468. if (!$this->rating)
  469. $this->rating = $this->rating($this->id)/2;
  470. $smarty->assign('link_rating', $this->rating);
  471. $smarty->assign('link_rating_width', $this->rating * 25);
  472. $current_user_id = $current_user->user_id;
  473. $jsLink = "vote($current_user_id, $this->id, $link_index, '" . md5($current_user_id . $this->randkey) . "', ";
  474. for ($stars = 1; $stars <= 5; $stars++)
  475. $smarty->assign("link_shakebox_javascript_vote_{$stars}star", $jsLink . ($stars * 2) . ')' );
  476. $smarty->assign('vote_count', $this->votecount);
  477. if($this->votes($current_user_id) > 0){
  478. $smarty->assign('star_class', "-noh");
  479. } else {
  480. $smarty->assign('star_class', "");
  481. }
  482. }
  483. $smarty->assign('get_group_membered', $this->get_group_membered());
  484. if($this->status == "published"){$smarty->assign('category_url', getmyurl("maincategory", $catvar));}
  485. if($this->status == "new"){$smarty->assign('category_url', getmyurl("newcategory", $catvar));}
  486. if($this->status == "discard"){$smarty->assign('category_url', getmyurl("discardedcategory", $catvar));}
  487. $smarty->assign('trackback_url', get_trackback($this->id));
  488. $smarty->assign('user_logged_in', $current_user->user_login);
  489. $smarty->assign('randmd5', md5($current_user->user_id.$this->randkey));
  490. $smarty->assign('user_id', $this->author);
  491. $smarty->assign('current_user_id', $current_user_id);
  492. if(Enable_Extra_Fields){
  493. $main_smarty = $smarty; include mnminclude.'extra_fields_smarty.php'; $smarty=$main_smarty;
  494. $smarty->assign('link_field1', $this->link_field1);
  495. $smarty->assign('link_field2', $this->link_field2);
  496. $smarty->assign('link_field3', $this->link_field3);
  497. $smarty->assign('link_field4', $this->link_field4);
  498. $smarty->assign('link_field5', $this->link_field5);
  499. $smarty->assign('link_field6', $this->link_field6);
  500. $smarty->assign('link_field7', $this->link_field7);
  501. $smarty->assign('link_field8', $this->link_field8);
  502. $smarty->assign('link_field9', $this->link_field9);
  503. $smarty->assign('link_field10', $this->link_field10);
  504. $smarty->assign('link_field11', $this->link_field11);
  505. $smarty->assign('link_field12', $this->link_field12);
  506. $smarty->assign('link_field13', $this->link_field13);
  507. $smarty->assign('link_field14', $this->link_field14);
  508. $smarty->assign('link_field15', $this->link_field15);
  509. }
  510. $smarty->assign('link_group_id', $this->link_group_id);
  511. $smarty->assign('instpath', my_base_url . my_pligg_base . "/");
  512. $smarty->assign('UseAvatars', do_we_use_avatars());
  513. $smarty->assign('Avatar', $avatars = get_avatar('all', "", "", "", $this->userid));
  514. $smarty->assign('Avatar_ImgSrc', $avatars['large']);
  515. $smarty->assign('Avatar_ImgSrcs', $avatars['small']);
  516. $canIhaveAccess = 0;
  517. $canIhaveAccess = $canIhaveAccess + checklevel('admin');
  518. $canIhaveAccess = $canIhaveAccess + checklevel('moderator');
  519. if($canIhaveAccess == 1)
  520. {$smarty->assign('isadmin', 'yes');}
  521. if($this->check_friends == true){
  522. // For Friends //
  523. include_once(mnminclude.'friend.php');
  524. $friend = new Friend;
  525. // make sure we're logged in and we didnt submit the link.
  526. if($current_user->user_id > 0 && $current_user->user_login != $this->username()){
  527. $friend_md5 = friend_MD5($current_user->user_login, $this->username());
  528. $smarty->assign('FriendMD5', $friend_md5);
  529. $isfriend = $friend->get_friend_status($this->author);
  530. if (!$isfriend) {$friend_text = 'add to'; $friend_url = 'addfriend';}
  531. else{$friend_text = 'remove from'; $friend_url = 'removefriend';}
  532. $smarty->assign('Friend_Text', $friend_text);
  533. $smarty->assign('user_add_remove', getmyurl('user', $this->username(), $friend_url));
  534. }
  535. $smarty->assign('Allow_Friends', Allow_Friends);
  536. // --- //
  537. }
  538. if($current_user->user_id != '')
  539. {
  540. $vars = array('author_id' => $this->author,'link_id' => $this->id);
  541. check_actions('friends_activity_function', $vars);
  542. if($vars['value'] == true){
  543. $smarty->assign('friendvoted', 1);
  544. }
  545. }
  546. /*
  547. //for friends voting activity
  548. include_once(mnminclude.'friend.php');
  549. $friend = new Friend;
  550. $sql = 'SELECT ' . table_votes . '.*, ' . table_users . '.user_id FROM ' . table_votes . ' INNER JOIN ' . table_users . ' ON ' . table_votes . '.vote_user_id = ' . table_users . '.user_id WHERE (((' . table_votes . '.vote_value)>0) AND ((' . table_votes . '.vote_link_id)='.$this->id.') AND (' . table_votes . '.vote_type= "links"));';
  551. $voters = $db->get_results($sql);
  552. $voters = object_2_array($voters);
  553. foreach($voters as $key => $val)
  554. {
  555. $voteduserid = $val['user_id'];
  556. if($voteduserid == $friend->get_friend_status($this->author))
  557. {
  558. $friendvoted = 1;
  559. }
  560. $smarty->assign('friendvoted', $friendvoted);
  561. }*/
  562. if($this->check_saved == true){
  563. global $cached_saved_links;
  564. if(isset($cached_saved_links[$this->id])){
  565. $smarty->assign('link_mine', $cached_saved_links[$this->id]);
  566. } else {
  567. $smarty->assign('link_mine', $db->get_row("SELECT * FROM " . table_saved_links . " WHERE saved_user_id=$current_user->user_id AND saved_link_id=$this->id LIMIT 1;"));
  568. }
  569. }
  570. $smarty->assign('user_url_saved', getmyurl('user2', $current_user->user_login, 'saved'));
  571. $smarty->assign('user_add_links_private', getmyurl('user_add_links_private', $this->id));
  572. $smarty->assign('user_add_links_public', getmyurl('user_add_links_public', $this->id));
  573. $smarty->assign('group_story_links_publish', getmyurl('group_story_links_publish', $this->id));
  574. $smarty->assign('group_story_links_new', getmyurl('group_story_links_new', $this->id));
  575. $smarty->assign('group_story_links_discard', getmyurl('group_story_links_discard', $this->id));
  576. $smarty->assign('link_id',$this->id);
  577. $smarty->assign('user_url_add_links', getmyurl('user_add_links', $this->id));
  578. $smarty->assign('user_url_remove_links', getmyurl('user_remove_links', $this->id));
  579. $smarty->assign('enable_tags', Enable_Tags);
  580. $smarty->assign('link_shakebox_index', $link_index);
  581. $smarty->assign('link_shakebox_votes', $this->votes);
  582. $smarty->assign('link_shakebox_showbury', $this->reports);
  583. $this->get_current_user_votes($current_user->user_id);
  584. if(votes_per_ip > 0){
  585. $smarty->assign('vote_from_this_ip', $this->vote_from_this_ip);
  586. $smarty->assign('report_from_this_ip', $this->report_from_this_ip);
  587. }
  588. $smarty->assign('link_shakebox_currentuser_votes', $this->current_user_votes);
  589. $smarty->assign('link_shakebox_currentuser_reports', $this->current_user_reports);
  590. if($this->reports == -1){
  591. // reporting was added to the svn and some people started using it
  592. // so in upgrade if someone already has the reports field, we set it to
  593. // -1. Then when we read() we check if -1. if it still is, update the count
  594. // from the votes table and store it into the link_reports field so we
  595. // don't have to look at the votes table again.
  596. $this->reports = $this->count_all_votes("<0");
  597. $this->store_basic();
  598. $smarty->assign('link_shakebox_reports', $this->reports);
  599. }
  600. $jslink = "vote($current_user->user_id,$this->id,$link_index," . "'" . md5($current_user->user_id.$this->randkey) . "',10)";
  601. $jsreportlink = "vote($current_user->user_id,$this->id,$link_index," . "'" . md5($current_user->user_id.$this->randkey) . "',-10)";
  602. $smarty->assign('link_shakebox_javascript_vote', $jslink);
  603. $jsunvote = "unvote($current_user->user_id,$this->id,$link_index," . "'" . md5($current_user->user_id.$this->randkey) . "',10)";
  604. $smarty->assign('link_shakebox_javascript_unvote', $jsunvote);
  605. $jsunbury = "unvote($current_user->user_id,$this->id,$link_index," . "'" . md5($current_user->user_id.$this->randkey) . "',-10)";
  606. $smarty->assign('link_shakebox_javascript_unbury', $jsunbury);
  607. $smarty->assign('link_shakebox_javascript_report', $jsreportlink);
  608. if(!defined('alltagtext')){
  609. // for pages like index, this ->display was being called for each story
  610. // which was sometimes 15+ times per page. this way it's just called once
  611. $smarty->display('blank.tpl'); //this is just to load the lang file so we can pull from it in php
  612. define('alltagtext', $smarty->get_config_vars('PLIGG_Visual_Tags_All_Tags'));
  613. }
  614. $alltagtext = alltagtext;
  615. if(Enable_Tags){
  616. $smarty->assign('tags', $this->tags);
  617. if (!empty($this->tags)) {
  618. $tags_words = str_replace(", ", ",", $this->tags);
  619. $tags_count = substr_count($tags_words, ',');
  620. if ($tags_count > 1){$tags_words = $tags_words;}
  621. $tag_array = explode(",", $tags_words);
  622. $c = count($tag_array);
  623. $tag_array[$c] = $this->tags;
  624. $c++;
  625. for($i=0; $i<=$c; $i++)
  626. {
  627. if(isset($tag_array[$i])){
  628. if ( $URLMethod == 1 ) {
  629. $tags_url_array[$i] = my_pligg_base . "/search.php?search=".urlencode(trim($tag_array[$i]))."&amp;tag=true";
  630. } elseif ( $URLMethod == 2) {
  631. $tags_url_array[$i] = my_pligg_base . "/tag/" . urlencode(trim($tag_array[$i]));
  632. }
  633. }
  634. }
  635. $tag_array[$c - 1] = $alltagtext;
  636. $smarty->assign('tag_array', $tag_array);
  637. $smarty->assign('tags_url_array', $tags_url_array);
  638. $tags_url = urlencode($this->tags);
  639. $smarty->assign('tags_count', $tags_count);
  640. $smarty->assign('tags_words', $tags_words);
  641. $smarty->assign('tags_url', $tags_url);
  642. }
  643. }
  644. $smarty->assign('enable_group', enable_group);
  645. $smarty->assign('pagename', pagename);
  646. $smarty->assign('my_base_url', my_base_url);
  647. $smarty->assign('my_pligg_base', my_pligg_base);
  648. $smarty->assign('Default_Gravatar_Large', Default_Gravatar_Large);
  649. //$link_index++;
  650. $vars['smarty'] = $smarty;
  651. check_actions('lib_link_summary_fill_smarty', $vars);
  652. return $smarty;
  653. }
  654. //sharing membered group list
  655. function get_group_membered()
  656. {
  657. global $db, $main_smarty, $rows,$current_user;
  658. $current_userid = $current_user->user_id;
  659. if (!isset($this->group_membered) && $current_userid)
  660. // $this->group_membered = $db->get_results("SELECT group_id,group_name FROM " . table_groups . " WHERE group_creator = $current_userid and group_status = 'Enable'");
  661. $this->group_membered = $db->get_results("SELECT DISTINCT group_id,group_name FROM " . table_groups . " LEFT JOIN ".table_group_member." ON member_group_id=group_id AND member_user_id = $current_userid WHERE group_status = 'Enable' AND member_status='active'");
  662. $output = '';
  663. if ($this->group_membered)
  664. foreach($this->group_membered as $results)
  665. $output .= "<a class='group_member_share' href='".my_base_url.my_pligg_base."/group_share.php?link_id=".$this->id."&group_id=".$results->group_id."&user_id=".$current_user->user_id."' >".$results->group_name."</a><br />";
  666. return $output;
  667. }
  668. //--------------------------------------
  669. function truncate_content(){
  670. if(utf8_strlen($this->content) > StorySummary_ContentTruncate){
  671. if(Auto_scroll==true){
  672. global $main_smarty;
  673. $content= close_tags(utf8_substr($this->content, 0, StorySummary_ContentTruncate));
  674. $content.="<div class=\"read_more_article\" storyid=\"".$this->id."\" > ".$main_smarty->get_config_vars('PLIGG_Visual_Read_More')."</div>" ;
  675. $content.="<div class=\"read_more_story".$this->id." hide\" >";
  676. $content.=close_tags(utf8_substr($this->content, StorySummary_ContentTruncate,utf8_strlen($this->content) ));
  677. $content.="</div>";
  678. // echo $content;
  679. return $content;
  680. }else{
  681. return close_tags(utf8_substr($this->content, 0, StorySummary_ContentTruncate)) . "...";
  682. }
  683. }
  684. return $this->content;
  685. }
  686. function print_shake_box($smarty) {
  687. global $current_user;
  688. }
  689. function rating($linkid)
  690. {
  691. require_once(mnminclude.'votes.php');
  692. $vote = new Vote;
  693. $vote->type='links';
  694. $vote->link=$linkid;
  695. return $vote->rating();
  696. }
  697. function countvotes() {
  698. require_once(mnminclude.'votes.php');
  699. $vote = new Vote;
  700. $vote->type='links';
  701. $vote->link=$this->id;
  702. return $vote->anycount();
  703. }
  704. function count_all_votes($value="> 0") {
  705. require_once(mnminclude.'votes.php');
  706. $vote = new Vote;
  707. $vote->type='links';
  708. $vote->link=$this->id;
  709. return $vote->count_all($value);
  710. }
  711. function votes($user, $value="> 0") {
  712. require_once(mnminclude.'votes.php');
  713. $vote = new Vote;
  714. $vote->type='links';
  715. $vote->user=$user;
  716. $vote->link=$this->id;
  717. return $vote->count($value);
  718. }
  719. function reports($user) {
  720. require_once(mnminclude.'votes.php');
  721. $vote = new Vote;
  722. $vote->type='links';
  723. $vote->user=$user;
  724. $vote->link=$this->id;
  725. return $vote->reports();
  726. }
  727. // DB 11/10/08
  728. function votes_from_ip($ip='') {
  729. require_once(mnminclude.'votes.php');
  730. $vote = new Vote;
  731. $vote->type='links';
  732. if ($ip)
  733. $vote->ip=$ip;
  734. else {
  735. require_once(mnminclude.'check_behind_proxy.php');
  736. $vote->ip=check_ip_behind_proxy();
  737. }
  738. $vote->link=$this->id;
  739. return $vote->count();
  740. }
  741. function reports_from_ip($ip='') {
  742. require_once(mnminclude.'votes.php');
  743. $vote = new Vote;
  744. $vote->type='links';
  745. if ($ip)
  746. $vote->ip=$ip;
  747. else {
  748. require_once(mnminclude.'check_behind_proxy.php');
  749. $vote->ip=check_ip_behind_proxy();
  750. }
  751. $vote->link=$this->id;
  752. return $vote->reports();
  753. }
  754. /////
  755. function get_current_user_votes($user) {
  756. require_once(mnminclude.'votes.php');
  757. $vote = new Vote;
  758. $vote->type='links';
  759. $vote->user=$user;
  760. $vote->link=$this->id;
  761. $results = $vote->user_list_all_votes();
  762. $votes = 0;
  763. $reports = 0;
  764. if(is_array($results)){
  765. foreach ($results as $row){
  766. if(isset($row->vote_value)){
  767. if($row->vote_value > 0){$votes = $votes + 1;}
  768. if($row->vote_value < 0){$reports = $reports + 1;}
  769. }
  770. }
  771. }
  772. $this->current_user_votes = $votes;
  773. $this->current_user_reports = $reports;
  774. if(votes_per_ip > 0 && $user==0){
  775. $ac_vote_from_IP=$this->votes_from_ip();
  776. if($ac_vote_from_IP<=1)
  777. $ac_vote_from_IP=0;
  778. $ac_report_from_IP=$this->reports_from_ip();
  779. if($ac_report_from_IP<=1)
  780. $ac_report_from_IP=0;
  781. $this->vote_from_this_ip=$ac_vote_from_IP;
  782. $this->report_from_this_ip=$ac_report_from_IP;
  783. }
  784. }
  785. function remove_vote($user=0, $value=10) {
  786. $vote = new Vote;
  787. $vote->type='links';
  788. $vote->user=$user;
  789. $vote->link=$this->id;
  790. $vote->value=$value;
  791. $vote->remove();
  792. $vote = new Vote;
  793. $vote->type='links';
  794. $vote->link=$this->id;
  795. if(Voting_Method == 1){
  796. $this->votes=$vote->count();
  797. $this->reports = $this->count_all_votes("<0");
  798. }
  799. elseif(Voting_Method == 2){
  800. $this->votes=$vote->rating();
  801. $this->votecount=$vote->count();
  802. $this->reports = $this->count_all_votes("<0");
  803. }
  804. elseif(Voting_Method == 3){
  805. $this->votes=$vote->count();
  806. $this->votecount=$vote->count();
  807. $this->karma = $vote->karma();
  808. $this->reports = $this->count_all_votes("<0");
  809. }
  810. $this->store_basic();
  811. $vars = array('link' => $this);
  812. check_actions('link_remove_vote_post', $vars);
  813. }
  814. function insert_vote($user=0, $value=10) {
  815. global $anon_karma;
  816. require_once(mnminclude.'votes.php');
  817. if($value>10){$value=10;}
  818. $vote = new Vote;
  819. $vote->type='links';
  820. $vote->user=$user;
  821. $vote->link=$this->id;
  822. $vote->value=$value;
  823. // if($value<10) {$vote->value=($anon_karma/10)*$value;}
  824. if($user>0) {
  825. require_once(mnminclude.'user.php');
  826. $dbuser = new User($user);
  827. if($dbuser->id>0)
  828. $vote->karma = $dbuser->karma;
  829. } elseif (!anonymous_vote) {
  830. return;
  831. } else {
  832. $vote->karma = $anon_karma;
  833. }
  834. if($vote->insert()) {
  835. $vote = new Vote;
  836. $vote->type='links';
  837. $vote->link=$this->id;
  838. if(Voting_Method == 1){
  839. $this->votes=$vote->count();
  840. $this->reports = $this->count_all_votes("<0");
  841. }
  842. elseif(Voting_Method == 2){
  843. $this->votes=$vote->rating();
  844. $this->votecount=$vote->count();
  845. $this->reports = $this->count_all_votes("<0");
  846. }
  847. elseif(Voting_Method == 3){
  848. $this->votes=$vote->count();
  849. $this->votecount=$vote->count();
  850. $this->karma = $vote->karma();
  851. $this->reports = $this->count_all_votes("<0");
  852. }
  853. $this->store_basic();
  854. $this->check_should_publish();
  855. $vars = array('vote' => $this);
  856. check_actions('link_insert_vote_post', $vars);
  857. return true;
  858. }
  859. return false;
  860. }
  861. function check_should_publish(){
  862. $votes = $this->category_votes();
  863. // $votes must be explicitly cast to (int) to compare accurately
  864. if (!is_numeric($votes))
  865. $votes = (int) votes_to_publish;
  866. else
  867. $votes = (int) $votes;
  868. if(Voting_Method == 1){
  869. // check to see if we should change the status to publish
  870. if($this->status == 'new' && $this->votes>=$votes) {
  871. $now = time();
  872. $diff=$now-$this->date;
  873. $days=intval($diff/86400);
  874. if ($days <=days_to_publish) {
  875. $this->publish();
  876. }
  877. }
  878. }
  879. elseif(Voting_Method == 2){
  880. if($this->status == 'new' && $this->votes>=(rating_to_publish * 2) && $this->votecount>=$votes) {
  881. $now = time();
  882. $diff=$now-$this->date;
  883. $days=intval($diff/86400);
  884. if ($days <=days_to_publish+1000) {
  885. $this->publish();
  886. }
  887. }
  888. }
  889. elseif(Voting_Method == 3){
  890. $karma = $this->category_karma();
  891. if (!is_numeric($karma))
  892. $karma = karma_to_publish;
  893. if($this->status == 'new' && $this->karma>=$karma && $this->votecount>=$votes) {
  894. $now = time();
  895. $diff=$now-$this->date;
  896. $days=intval($diff/86400);
  897. if ($days <=days_to_publish) {
  898. $this->publish();
  899. }
  900. }
  901. }
  902. if(($this->status == 'new' || $this->status == 'discard') && buries_to_spam>0 && $this->reports>=buries_to_spam) {
  903. $this->status='discard';
  904. $this->store_basic();
  905. $vars = array('link_id' => $this->id);
  906. check_actions('story_spam', $vars);
  907. }
  908. }
  909. function category_votes() {
  910. // $the_cats is set in /libs/smartyvariables.php
  911. global $dblang, $the_cats, $main_smarty;
  912. foreach($the_cats as $cat){
  913. if($cat->category_id == $this->category)
  914. return $cat->category_votes;
  915. }
  916. return $main_smarty->get_config_vars('PLIGG_Visual_Submit3Errors_NoCategory');
  917. }
  918. function category_karma() {
  919. global $dblang, $the_cats, $main_smarty;
  920. foreach($the_cats as $cat){
  921. if($cat->category_id == $this->category)
  922. return $cat->category_karma;
  923. }
  924. return $main_smarty->get_config_vars('PLIGG_Visual_Submit3Errors_NoCategory');
  925. }
  926. function category_name($id=0) {
  927. // $the_cats is set in /libs/smartyvariables.php
  928. global $dblang, $the_cats, $main_smarty;
  929. if (!$id) $id = $this->category;
  930. foreach($the_cats as $cat){
  931. if($cat->category_id == $id)
  932. // if($cat->category_id == $this->category && $cat->category_lang == $dblang)
  933. {
  934. return $cat->category_name;
  935. }
  936. }
  937. return $main_smarty->get_config_vars('PLIGG_Visual_Submit3Errors_NoCategory');
  938. }
  939. function category_safe_name($id=0) {
  940. // $the_cats is set in /libs/smartyvariables.php
  941. global $dblang, $the_cats;
  942. if (!$id) $id = $this->category;
  943. foreach($the_cats as $cat){
  944. if($cat->category_id == $id && $cat->category_lang == $dblang)
  945. {
  946. return $cat->category_safe_name;
  947. }
  948. }
  949. }
  950. function category_safe_names() {
  951. $cats = array($this->category_safe_name());
  952. foreach ($this->additional_cats as $cat)
  953. $cats[] = $this->category_safe_name($cat);
  954. sort($cats, SORT_STRING);
  955. return join(',',$cats);
  956. }
  957. function publish() {
  958. if(!$this->read) $this->read_basic();
  959. $this->published_date = time();
  960. totals_adjust_count($this->status, -1);
  961. totals_adjust_count('published', 1);
  962. $this->status = 'published';
  963. $this->store_basic();
  964. $vars = array('link_id' => $this->id);
  965. check_actions('link_published', $vars);
  966. }
  967. function username() {
  968. global $db;
  969. include_once(mnminclude.'user.php');
  970. $user = new User;
  971. $user->id = $this->author;
  972. $user->read();
  973. $this->username = $user->username;
  974. $this->userkarma = $user->karma;
  975. $this->extra_field = $user->extra_field;
  976. return $user->username;
  977. }
  978. function recalc_comments(){
  979. global $db;
  980. // DB 08/04/08
  981. if(!is_numeric($this->id)){return false;}
  982. /////
  983. $this->comments = $db->get_var("SELECT count(*) FROM " . table_comments . " WHERE comment_status='published' AND comment_link_id = $this->id");
  984. }
  985. function comments() {
  986. global $db;
  987. if(summarize_mysql == 1){
  988. return $this->comments;
  989. }else{
  990. // DB 08/04/08
  991. if(!is_numeric($this->id)){return false;}
  992. /////
  993. return $db->get_var("SELECT count(*) FROM " . table_comments . " WHERE comment_status='published' AND comment_link_id = $this->id");
  994. }
  995. }
  996. function evaluate_formulas ()
  997. {
  998. global $db;
  999. $res = $db->get_results("select * from " . table_formulas . " where type = 'report' and enabled = 1;");
  1000. if (!$res) return;
  1001. foreach ($res as $formula) {
  1002. $reports = $this->count_all_votes("< 0");
  1003. $votes = $this->count_all_votes("> 0");
  1004. $from = $this->date;
  1005. $now = time();
  1006. $diff=$now-$from;
  1007. $hours=($diff/3600);
  1008. $hours_since_submit = intval($hours * 100) / 100;
  1009. $evalthis = 'if (' . $formula->formula . '){return "1";}else{return "0";}';
  1010. if(eval($evalthis) == 1 && $this->status!='spam'){
  1011. totals_adjust_count($this->status, -1);
  1012. totals_adjust_count('discard', 1);
  1013. $this->status = 'discard';
  1014. $this->store_basic();
  1015. $vars = array('link_id' => $this->id);
  1016. check_actions('story_discard', $vars);
  1017. }
  1018. }
  1019. }
  1020. function return_formula_system_version()
  1021. {
  1022. // 0.1 original
  1023. // 0.2 added hours_since_submit
  1024. return 0.2;
  1025. }
  1026. function adjust_comment($value)
  1027. {
  1028. $this->comments = $this->comments + $value;
  1029. }
  1030. function verify_ownership($authorid){
  1031. global $db;
  1032. // DB 09/03/08
  1033. if(!is_numeric($this->id)){return false;}
  1034. if(!is_numeric($authorid)){return false;}
  1035. /////
  1036. $sql = 'SELECT `link_id` from `' . table_links . '` WHERE `link_id` = ' . $this->id . ' AND `link_author` = ' . $authorid . ' ORDER BY `link_date` DESC LIMIT 1;';
  1037. if($db->get_var($sql)){
  1038. return true;
  1039. } else {
  1040. return false;
  1041. }
  1042. }
  1043. function get_internal_url(){
  1044. // returns the internal (comments page) url
  1045. if ($this->title_url == ""){
  1046. return getmyurl("story", $this->id);
  1047. } else {
  1048. return getmyurl("storyURL", $this->category_safe_names(), urlencode($this->title_url), $this->id);
  1049. }
  1050. }
  1051. function check_spam($text )
  1052. {
  1053. global $MAIN_SPAM_RULESET;
  1054. global $USER_SPAM_RULESET;
  1055. $regex_url = "/(http:\/\/|https:\/\/|ftp:\/\/|www\.)([^\/\"<\s]*)/im";
  1056. $mk_regex_array = array();
  1057. preg_match_all($regex_url, $text, $mk_regex_array);
  1058. for( $cnt=0; $cnt < count($mk_regex_array[2]); $cnt++ )
  1059. {
  1060. $test_domain = rtrim($mk_regex_array[2][$cnt],"\\");
  1061. if (strlen($test_domain) > 3)
  1062. {
  1063. $domain_to_test = $test_domain . ".multi.surbl.org";
  1064. if( strstr(gethostbyname($domain_to_test),'127.0.0'))
  1065. { logSpam( "surbl rejected $test_domain"); return true; }
  1066. }
  1067. }
  1068. $retVal = $this->check_spam_rules($MAIN_SPAM_RULESET, strtoupper($text));
  1069. if(!$retVal) { $retVal = $this->check_spam_rules($USER_SPAM_RULESET, strtoupper($text)); }
  1070. return $retVal;
  1071. }
  1072. #####################################
  1073. # check a file of local rules
  1074. # . . the rules are written in a regex format for php
  1075. # . . or one entry per line eg: bigtimespammer.com on one line
  1076. ####################
  1077. function check_spam_rules($ruleFile, $text)
  1078. {
  1079. if(!file_exists( $ruleFile)) { echo $ruleFile . " does not exist\n"; return false; }
  1080. $handle = fopen( $ruleFile, "r");
  1081. while (!feof($handle))
  1082. {
  1083. $buffer = fgets($handle, 4096);
  1084. $splitbuffer = explode("####", $buffer);
  1085. // Parse domain name from a line
  1086. $expression = parse_url(trim($splitbuffer[0]),PHP_URL_HOST);
  1087. if (!$expression) $expression = trim($splitbuffer[0]);
  1088. // Make it regexp compatible
  1089. $expression = str_replace('.','\.',$expression);
  1090. // Check $text against http://<domain>
  1091. if (strlen($expression) > 0 && preg_match("/\/\/([^\.]+\.)*$expression(\/|$)/i", $text))
  1092. {
  1093. $this->logSpam( "$ruleFile violation: $expression");
  1094. return true;
  1095. }
  1096. }
  1097. fclose($handle);
  1098. return false;
  1099. }
  1100. // log date, time, IP address and rule which triggered the spam
  1101. function logSpam($message)
  1102. {
  1103. global $SPAM_LOG_BOOK;
  1104. $ip = "127.0.0.0";
  1105. if(!empty($_SERVER["REMOTE_ADDR"])) { $ip = $_SERVER["REMOTE_ADDR"]; }
  1106. $date = date('M-d-Y');
  1107. $timestamp = time();
  1108. $message = $date . "\t" . $timestamp . "\t" . $ip . "\t" . $message . "\n";
  1109. $file = fopen( $SPAM_LOG_BOOK, "a");
  1110. fwrite( $file, $message );
  1111. fclose($file);
  1112. }
  1113. }
  1114. class PliggHTTPRequest
  1115. {
  1116. var $_fp; // HTTP socket
  1117. var $_url; // full URL
  1118. var $_host; // HTTP host
  1119. var $_protocol; // protocol (HTTP/HTTPS)
  1120. var $_uri; // request URI
  1121. var $_port; // port
  1122. // scan url
  1123. function _scan_url()
  1124. {
  1125. $req = $this->_url;
  1126. $pos = strpos($req, '://');
  1127. $this->_protocol = strtolower(substr($req, 0, $pos));
  1128. $req = substr($req, $pos+3);
  1129. $pos = strpos($req, '/');
  1130. if($pos === false)
  1131. $pos = strlen($req);
  1132. $host = substr($req, 0, $pos);
  1133. if(strpos($host, ':') !== false)
  1134. {
  1135. list($this->_host, $this->_port) = explode(':', $host);
  1136. }
  1137. else
  1138. {
  1139. $this->_host = $host;
  1140. $this->_port = ($this->_protocol == 'https') ? 443 : 80;
  1141. }
  1142. $this->_uri = substr($req, $pos);
  1143. if($this->_uri == '')
  1144. $this->_uri = '/';
  1145. }
  1146. // constructor
  1147. function PliggHTTPRequest($url)
  1148. {
  1149. $this->_url = $url;
  1150. $this->_scan_url();
  1151. }
  1152. // download URL to string
  1153. function DownloadToString()
  1154. {
  1155. $crlf = "\r\n";
  1156. // generate request
  1157. $req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf
  1158. . 'Host: ' . $this->_host . $crlf
  1159. . $crlf;
  1160. // fetch
  1161. $this->_fp = fsockopen(($this->_protocol == 'https' ? 'tls://' : '') . $this->_host, $this->_port, $errno, $errstr, 20);
  1162. // $this->_fp = file_get_contents("http://www.money.21cbh.com");
  1163. // var_dump($this->_fp);
  1164. // die();
  1165. if(!$this->_fp)
  1166. return("BADURL");
  1167. //fwrite($this->_fp, $req);
  1168. // while(is_resource($this->_fp) && $this->_fp && !feof($this->_fp))
  1169. // $response .= fread($this->_fp, 1024);
  1170. fputs($this->_fp, $req);
  1171. $html = '';
  1172. while (!feof($this->_fp))
  1173. {
  1174. $response.=fgets($this->_fp);
  1175. }
  1176. // var_dump($response);
  1177. // die();
  1178. fclose($this->_fp);
  1179. if (!strstr($response,'HTTP/'))
  1180. return("BADURL");
  1181. // split header and body
  1182. $pos = strpos($response, $crlf . $crlf);
  1183. if($pos === false)
  1184. return($response);
  1185. $header = substr($response, 0, $pos);
  1186. $body = substr($response, $pos + 2 * strlen($crlf));
  1187. // var_dump($body);
  1188. // die();
  1189. // parse headers
  1190. $headers = array();
  1191. $lines = explode($crlf, $header);
  1192. foreach($lines as $line)
  1193. if(($pos = strpos($line, ':')) !== false)
  1194. $headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos+1));
  1195. //var_dump($headers);
  1196. //die();
  1197. // redirection?
  1198. if(isset($headers['location']))
  1199. {
  1200. $http = new PliggHTTPRequest($headers['location']);
  1201. return($http->DownloadToString($http));
  1202. }
  1203. else
  1204. {
  1205. if (extension_loaded('iconv') && preg_match('/charset=(.+)$/',$headers['content-type'],$m))
  1206. // if($m[1])
  1207. $body = iconv("$m[1]","UTF-8",$body);
  1208. //var_dump($body);
  1209. //die();
  1210. //$body = mb_convert_encoding($content, "UTF-8","gb2312");
  1211. return($body);
  1212. }
  1213. }
  1214. }
  1215. ?>