PageRenderTime 83ms CodeModel.GetById 44ms RepoModel.GetById 1ms app.codeStats 0ms

/link.php

https://bitbucket.org/jonarano/joneame
PHP | 1383 lines | 1091 code | 232 blank | 60 comment | 374 complexity | 34bd23a79da39e14d713b23ffd14b52e MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. <?
  2. // The source code packaged with this file is Free Software, Copyright (C) 2005 by
  3. // Ricardo Galli <gallir at uib dot es>.
  4. // It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise.
  5. // You can get copies of the licenses here:
  6. // http://www.affero.org/oagpl.html
  7. // AFFERO GENERAL PUBLIC LICENSE is also included in the file called "COPYING".
  8. require_once(mnminclude.'log.php');
  9. require_once(mnminclude.'favorites.php');
  10. class Link {
  11. var $id = 0;
  12. var $author = -1;
  13. var $blog = 0;
  14. var $username = false;
  15. var $randkey = 0;
  16. var $karma = 0;
  17. var $valid = false;
  18. var $date = false;
  19. var $sent_date = 0;
  20. var $sent = 0;
  21. var $modified = 0;
  22. var $url = false;
  23. var $url_title = '';
  24. var $encoding = false;
  25. var $status = 'discard';
  26. var $type = '';
  27. var $category = 0;
  28. var $votes = 0;
  29. var $anonymous = 0;
  30. var $votes_avg = 0;
  31. var $negatives = 0;
  32. var $title = '';
  33. var $tags = '';
  34. var $uri = '';
  35. var $content = '';
  36. var $content_type = '';
  37. var $ip = '';
  38. var $html = false;
  39. var $read = false;
  40. var $voted = false;
  41. var $banned = false;
  42. var $thumb_status = 'unknown';
  43. var $aleatorios_positivos = 0;
  44. var $aleatorios_negativos = 0;
  45. var $clicks = 0;
  46. var $visits = 0;
  47. // sql fields to build an object from mysql
  48. //const SQL = " link_id as id, link_author as author, link_blog as blog, link_status as status, link_votes as votes, link_negatives as negatives, link_anonymous as anonymous, link_votes_avg as votes_avg, link_aleatorios_positivos as aleatorios_positivos, link_aleatorios_negativos as aleatorios_negativos, link_comments as comments, link_karma as karma, link_randkey as randkey, link_category as category, link_url as url, link_uri as uri, link_url_title as title, link_title as title, link_tags as tags, link_content as content, UNIX_TIMESTAMP(link_date) as date, UNIX_TIMESTAMP(link_sent_date) as sent_date, link_sent as sent, UNIX_TIMESTAMP(link_modified) as modified, link_content_type as content_type, link_ip as ip, link_thumb_status as thumb_status, link_thumb_x as thumb_x, link_thumb_y as thumb_y, link_thumb as thumb, link_comentarios_permitidos as comentarios_permitidos, link_votos_permitidos as votos_permitidos, user_login as username, user_email as email, user_avatar as avatar, user_karma as user_karma, user_level as user_level, user_adcode, cat.category_name as category_name, cat.category_uri as category_uri, meta.category_id as meta_id, meta.category_name as meta_name, favorite_link_id as favorite, clicks.counter as clicks, visits.counter as visits FROM links LEFT JOIN favorites ON (@user_id > 0 and favorite_user_id = @user_id and favorite_type = 'link' and favorite_link_id = links.link_id) LEFT JOIN categories as cat on (cat.category_id = links.link_category) LEFT JOIN categories as meta on (meta.category_id = cat.category_parent) LEFT JOIN link_clicks as clicks on (clicks.id = links.link_id) LEFT JOIN link_visits as visits on (visits.id = links.link_id), users ";
  49. // sql fields to build an object from mysql
  50. const SQL = " link_id as id, link_author as author, link_blog as blog, link_status as status, link_votes as votes, link_negatives as negatives, link_anonymous as anonymous, link_votes_avg as votes_avg, link_aleatorios_positivos as aleatorios_positivos, link_aleatorios_negativos as aleatorios_negativos, link_comments as comments, link_karma as karma, link_randkey as randkey, link_category as category, link_url as url, link_uri as uri, link_url_title as title, link_title as title, link_tags as tags, link_content as content, UNIX_TIMESTAMP(link_date) as date, UNIX_TIMESTAMP(link_sent_date) as sent_date, link_sent as sent, UNIX_TIMESTAMP(link_modified) as modified, link_content_type as content_type, link_ip as ip, link_thumb_status as thumb_status, link_thumb_x as thumb_x, link_thumb_y as thumb_y, link_thumb as thumb, link_comentarios_permitidos as comentarios_permitidos, link_votos_permitidos as votos_permitidos, user_login as username, user_email as email, user_avatar as avatar, user_karma as user_karma, user_level , cat.category_name as category_name, cat.category_uri as category_uri, meta.category_id as meta_id, meta.category_name as meta_name, favorite_link_id as favorite, clicks.counter as clicks, visits.counter as visits, votes.vote_value as voted FROM links
  51. INNER JOIN users on (user_id = link_author)
  52. LEFT JOIN (categories as cat, categories as meta) on (cat.category_id = links.link_category AND meta.category_id = cat.category_parent)
  53. LEFT JOIN votes ON (link_date > @enabled_votes and vote_type='links' and vote_link_id = links.link_id and vote_user_id = @user_id and ( @user_id > 0 OR vote_ip_int = @ip_int ) )
  54. LEFT JOIN favorites ON (@user_id > 0 and favorite_user_id = @user_id and favorite_type = 'link' and favorite_link_id = links.link_id)
  55. LEFT JOIN link_clicks as clicks on (clicks.id = links.link_id)
  56. LEFT JOIN link_visits as visits on (visits.id = links.link_id) ";
  57. static function from_db($id) {
  58. global $db;
  59. if (is_numeric($id) && $id > 0) $selector = " link_id = $id ";
  60. else $selector = " link_uri = '$id' ";
  61. if(($object = $db->get_object("SELECT".Link::SQL." WHERE $selector", 'Link'))) {
  62. $object->read = true;
  63. return $object;
  64. }
  65. return false;
  66. }
  67. function json_votes_info($value=false) {
  68. $dict = array();
  69. $dict['id'] = $this->id;
  70. if ($value)
  71. $dict['value'] = $value;
  72. $dict['votes'] = $this->votes;
  73. $dict['aleatorios_positivos'] = $this->aleatorios_positivos;
  74. $dict['anonymous'] = $this->anonymous;
  75. $dict['negatives'] = $this->negatives;
  76. $dict['karma'] = intval($this->karma);
  77. $dict['aleatorio_valor'] = 'no';
  78. return json_encode($dict);
  79. }
  80. function json_votes_info_aleatorio($value=false) {
  81. $voto_aleatorio = $this->aleatorio_info();
  82. $dict = array();
  83. $dict['id'] = $this->id;
  84. if ($value)
  85. $dict['value'] = $value;
  86. $dict['votes'] = $this->votes;
  87. $dict['anonymous'] = $this->anonymous;
  88. $dict['aleatorios_positivos'] = $this->aleatorios_positivos;
  89. $dict['aleatorios_negativos'] = $this->aleatorios_negativos;
  90. $dict['negatives'] = $this->negatives;
  91. $dict['karma'] = intval($this->karma);
  92. $dict['aleatorio_valor'] = $voto_aleatorio->valor;
  93. return json_encode($dict);
  94. }
  95. function print_html() {
  96. echo "Valid: " . $this->valid . "<br>\n";
  97. echo "Url: " . $this->url . "<br>\n";
  98. echo "Title: " . $this->url_title . "<br>\n";
  99. echo "encoding: " . $this->encoding . "<br>\n";
  100. }
  101. function check_url($url, $check_local = true, $first_level = false) {
  102. global $globals, $current_user;
  103. if(!preg_match('/^http[s]*:/', $url))
  104. return false;
  105. $url_components = @parse_url($url);
  106. if (!$url_components)
  107. return false;
  108. if (!preg_match('/[a-z]+/', $url_components['host']))
  109. return false;
  110. $quoted_domain = preg_quote(get_server_name());
  111. if($check_local && preg_match("/^$quoted_domain$/", $url_components['host'])) {
  112. $this->ban = array();
  113. $this->ban['comment'] = _('el servidor es local');
  114. syslog(LOG_NOTICE, "Joneame, server name is local name ($current_user->user_login): $url");
  115. return false;
  116. }
  117. require_once(mnminclude.'ban.php');
  118. if(($this->ban = check_ban($url, 'hostname', false, $first_level))) {
  119. syslog(LOG_NOTICE, "Joneame, server name is banned ($current_user->user_login): $url");
  120. $this->banned = true;
  121. return false;
  122. }
  123. return true;
  124. }
  125. function get($url, $maxlen = 150000, $check_local = true) {
  126. global $globals;
  127. $url=trim($url);
  128. $url_components = @parse_url($url);
  129. if(version_compare(phpversion(), '5.0.0') >= 0) {
  130. $opts = array(
  131. 'http' => array('user_agent' => 'Bot de noticias de Joneame (http://joneame.net/)', 'max_redirects' => 7, 'timeout' => 10, 'header' => 'Referer: http://'.get_server_name().$globals['base_url']."\r\n" ),
  132. 'https' => array('user_agent' => 'Bot de noticias de Joneame (http://joneame.net/)', 'max_redirects' => 7, 'timeout' => 10, 'header' => 'Referer: http://'.get_server_name().$globals['base_url']."\r\n" ),
  133. );
  134. $context = stream_context_create($opts);
  135. if(($stream = @fopen($url, 'r', false, $context))) {
  136. $meta_data = stream_get_meta_data($stream);
  137. foreach($meta_data['wrapper_data'] as $response) {
  138. // Check if it has pingbacks
  139. if (preg_match('/^X-Pingback: /i', $response)) {
  140. $answer = split(' ', $response);
  141. if (!empty($answer[1])) {
  142. $this->pingback = 'ping:'.trim($answer[1]);
  143. }
  144. }
  145. /* Were we redirected? */
  146. if (preg_match('/^location: /i', $response)) {
  147. /* update $url with where we were redirected to */
  148. $answer = split(' ', $response);
  149. $new_url = clean_input_url($answer[1]);
  150. }
  151. if (preg_match('/^content-type: /i', $response)) {
  152. $answer = split(' ', $response);
  153. $this->content_type = preg_replace('/\/.*$/', '', $answer[1]);
  154. }
  155. }
  156. if (!empty($new_url) && $new_url != $url) {
  157. syslog(LOG_NOTICE, "Joneame, redirected ($current_user->user_login): $url -> $new_url");
  158. /* Check again the url */
  159. // Warn: relative path can come in "Location:" headers, manage them
  160. if(!preg_match('/^http[s]*:/', $new_url)) {
  161. // It's relative
  162. $new_url = $url . $new_url;
  163. }
  164. if (!$this->check_url($new_url, $check_local, true)) {
  165. $this->url = $new_url;
  166. return false;
  167. }
  168. // Change the url if we were directed to another host
  169. if (strlen($new_url) < 250 && ($new_url_components = @parse_url($new_url))) {
  170. if ($url_components['host'] != $new_url_components['host']) {
  171. syslog(LOG_NOTICE, "Joneame, changed source URL ($current_user->user_login): $url -> $new_url");
  172. $url = $new_url;
  173. $url_components = $new_url_components;
  174. }
  175. }
  176. }
  177. $url_ok = $this->html = @stream_get_contents($stream, $maxlen);
  178. fclose($stream);
  179. } else {
  180. syslog(LOG_NOTICE, "Joneame, error getting ($current_user->user_login): $url");
  181. $url_ok = false;
  182. }
  183. //$url_ok = $this->html = @file_get_contents($url, false, $context, 0, 200000);
  184. } else {
  185. $url_ok = $this->html = @file_get_contents($url);
  186. }
  187. $this->url=$url;
  188. // Fill content type if empty
  189. // Right now only check for typical image extensions
  190. if (empty($this->content_type)) {
  191. if (preg_match('/(jpg|jpeg|gif|png)(\?|#|$)/i', $this->url)) {
  192. $this->content_type='image';
  193. }
  194. }
  195. // NO more to do
  196. if (!$url_ok)
  197. return true;
  198. if(preg_match('/charset=([a-zA-Z0-9-_]+)/i', $this->html, $matches)) {
  199. $this->encoding=trim($matches[1]);
  200. if(strcasecmp($this->encoding, 'utf-8') != 0) {
  201. $this->html=iconv($this->encoding, 'UTF-8//IGNORE', $this->html);
  202. }
  203. }
  204. // Check if the author doesn't want to share
  205. if (preg_match('/<!-- *jnm_no_share *-->/', $this->html)) {
  206. $this->ban = array();
  207. $this->ban['comment'] = _('el autor no desea que se envíe el artículo, respeta sus deseos');
  208. syslog(LOG_NOTICE, "Joneame, noshare ($current_user->user_login): $url");
  209. return false;
  210. }
  211. // Now we analyse the html to find links to banned domains
  212. // It avoids the trick of using google or technorati
  213. // Ignore it if the link has a rel="nofollow" to ignore comments in blogs
  214. if (!preg_match('/content="[^"]*(vBulletin|phpBB)/i', $this->html)) {
  215. preg_match_all('/(< *meta +http-equiv|< *script|< *iframe|< *frame[^<]*>|< *h[0-9][^<]*>[^<]*<a|window\.|document.\|parent\.|location\.|top\.|self\.)[^>]*(href|url|action|src|location|replace) *[=\(] *[\'"]{0,1}https*:\/\/[^\s "\'>]+[\'"\;\)]{0,1}[^>]*>/i', $this->html, $matches);
  216. } else {
  217. preg_match_all('/(< *a|<* meta +http-equiv|<* script|<* iframe|<* frame[^<]*>|window\.|document.\|parent\.|location\.|top\.|self\.)[^>]*(href|url|action|src|location|replace) *[=\(] *[\'"]{0,1}https*:\/\/[^\s "\'>]+[\'"\;\)]{0,1}[^>]*>/i', $this->html, $matches);
  218. }
  219. $check_counter = 0;
  220. $second_level = preg_quote(preg_replace('/^(.+\.)*([^\.]+)\.[^\.]+$/', "$2", $url_components['host']));
  221. foreach ($matches[0] as $match) {
  222. if (!preg_match('/<a.+rel=.*nofollow.*>/', $match)) {
  223. preg_match('/(href|url|action|src|location|replace) *[=\(] *[\'"]{0,1}(https*:\/\/[^\s "\'>]+)[\'"\;\)]{0,1}/i', $match, $url_a);
  224. $embeded_link = $url_a[2];
  225. $new_url_components = @parse_url($embeded_link);
  226. if (! empty($embeded_link) && $check_counter < 5 && ! $checked_links[$new_url_components['host']]) {
  227. if (! preg_match("/$second_level\.[^\.]+$/", $new_url_components['host']) ) {
  228. $check_counter++;
  229. }
  230. $checked_links[$new_url_components['host']] = true;
  231. if (!$this->check_url($embeded_link, false) && $this->banned) return false;
  232. }
  233. }
  234. }
  235. // The URL has been checked
  236. $this->valid = true;
  237. if(preg_match('/<title[^<>]*>([^<>]*)<\/title>/si', $this->html, $matches)) {
  238. $url_title=clean_text($matches[1]);
  239. if (mb_strlen($url_title) > 3) {
  240. $this->url_title=$url_title;
  241. }
  242. }
  243. return true;
  244. }
  245. function trackback() {
  246. // Now detect trackbacks
  247. if (preg_match('/trackback:ping="([^"]+)"/i', $this->html, $matches) ||
  248. preg_match('/trackback:ping +rdf:resource="([^>]+)"/i', $this->html, $matches) ||
  249. preg_match('/<trackback:ping>([^<>]+)/i', $this->html, $matches)) {
  250. $trackback=trim($matches[1]);
  251. } elseif (preg_match('/<a[^>]+rel="trackback"[^>]*>/i', $this->html, $matches)) {
  252. if (preg_match('/href="([^"]+)"/i', $matches[0], $matches2)) {
  253. $trackback=trim($matches2[1]);
  254. }
  255. } elseif (preg_match('/<a[^>]+href=[^>#]+>[^>]*trackback[^>]*<\/a>/i', $this->html, $matches)) {
  256. if (preg_match('/href="([^"]+)"/i', $matches[0], $matches2)) {
  257. $trackback=trim($matches2[1]);
  258. }
  259. } elseif (preg_match('/(http:\/\/[^\s#]+\/trackback\/*)/i', $this->html, $matches)) {
  260. $trackback=trim($matches[0]);
  261. }
  262. if (!empty($trackback)) {
  263. $this->trackback = clean_input_url($trackback);
  264. return true;
  265. }
  266. return false;
  267. }
  268. function pingback() {
  269. $url_components = @parse_url($this->url);
  270. // Now we use previous pingback or detect it
  271. if ((!empty($url_components['query']) || preg_match('|^/.*[\.-/]+|', $url_components['path']))) {
  272. if (!empty($this->pingback)) {
  273. $trackback = $this->pingback;
  274. } elseif (preg_match('/<link[^>]+rel="pingback"[^>]*>/i', $this->html, $matches)) {
  275. if (preg_match('/href="([^"]+)"/i', $matches[0], $matches2)) {
  276. $trackback='ping:'.trim($matches2[1]);
  277. }
  278. }
  279. }
  280. if (!empty($trackback)) {
  281. $this->trackback = clean_input_url($trackback);
  282. return true;
  283. }
  284. return false;
  285. }
  286. function has_rss() {
  287. return preg_match('/<link[^>]+(text\/xml|application\/rss\+xml|application\/atom\+xml)[^>]+>/i', $this->html);
  288. }
  289. function create_blog_entry() {
  290. require_once(mnminclude.'blog.php');
  291. $blog = new Blog();
  292. $blog->analyze_html($this->url, $this->html);
  293. if(!$blog->read('key')) {
  294. $blog->store();
  295. }
  296. $this->blog=$blog->id;
  297. $this->type=$blog->type;
  298. }
  299. function type() {
  300. if (empty($this->type)) {
  301. if ($this->blog > 0) {
  302. require_once(mnminclude.'blog.php');
  303. $blog = new Blog();
  304. $blog->id = $this->blog;
  305. if($blog->read()) {
  306. $this->type=$blog->type;
  307. return $this->type;
  308. }
  309. }
  310. return 'normal';
  311. }
  312. return $this->type;
  313. }
  314. function store() {
  315. global $db, $current_user;
  316. $link_url = $db->escape($this->url);
  317. $link_uri = $db->escape($this->uri);
  318. $link_url_title = $db->escape($this->url_title);
  319. $link_title = $db->escape($this->title);
  320. $link_tags = $db->escape($this->tags);
  321. $link_content = $db->escape(normalize_smileys($this->content));
  322. $link_thumb = $db->escape($this->thumb);
  323. $link_thumb_x = intval($this->thumb_x);
  324. $link_thumb_y = intval($this->thumb_y);
  325. $link_thumb_status = $db->escape($this->thumb_status);
  326. $db->query("LOCK TABLES links WRITE");
  327. $this->store_basic();
  328. $db->query("UPDATE links set link_url='$link_url', link_uri='$link_uri', link_url_title='$link_url_title', link_title='$link_title', link_content='$link_content', link_tags='$link_tags', link_thumb='$link_thumb', link_thumb_x=$link_thumb_x, link_thumb_y=$link_thumb_y, link_thumb_status='$link_thumb_status' WHERE link_id=$this->id");
  329. $db->query("UNLOCK TABLES");
  330. }
  331. function store_basic() {
  332. global $db, $current_user, $globals;
  333. if(!$this->date)
  334. $this->date=$globals['now'];
  335. $link_author = $this->author;
  336. $link_blog = $this->blog;
  337. $link_status = $db->escape($this->status);
  338. $link_votes = $this->votes;
  339. $link_negatives = $this->negatives;
  340. $link_anonymous = $this->anonymous;
  341. $link_aleatorios_positivos = $this->aleatorios_positivos;
  342. $link_aleatorios_negativos = $this->aleatorios_negativos;
  343. $link_comments = $this->comments;
  344. $link_karma = $this->karma;
  345. $link_votes_avg = $this->votes_avg;
  346. $link_randkey = $this->randkey;
  347. $link_category = $this->category;
  348. $link_votos_permitidos = intval($this->votos_permitidos);
  349. $link_comentarios_permitidos = intval($this->comentarios_permitidos);
  350. $link_date = $this->date;
  351. $link_sent_date = $this->sent_date;
  352. $link_sent = $this->sent;
  353. $link_content_type = $db->escape($this->content_type);
  354. $link_ip = $db->escape($this->ip);
  355. if($this->id===0) {
  356. $db->query("INSERT INTO links (link_author, link_blog, link_status, link_randkey, link_category, link_date, link_sent_date, link_sent, link_votes, link_negatives, link_karma, link_anonymous, link_votes_avg, link_content_type, link_ip) VALUES ($link_author, $link_blog, '$link_status', $link_randkey, $link_category, FROM_UNIXTIME($link_date), FROM_UNIXTIME($link_sent_date), $link_sent, $link_votes, $link_negatives, $link_karma, $link_anonymous, $link_votes_avg, '$link_content_type', '$link_ip')");
  357. $this->id = $db->insert_id;
  358. } else {
  359. // update
  360. $db->query("UPDATE links set link_author=$link_author, link_blog=$link_blog, link_status='$link_status', link_randkey=$link_randkey, link_category=$link_category, link_date=FROM_UNIXTIME($link_date), link_sent_date=FROM_UNIXTIME($link_sent_date), link_votes=$link_votes,link_aleatorios_positivos=$link_aleatorios_positivos,link_aleatorios_negativos=$link_aleatorios_negativos, link_votos_permitidos=$link_votos_permitidos, link_comentarios_permitidos=$link_comentarios_permitidos, link_sent=$link_sent, link_negatives=$link_negatives, link_comments=$link_comments, link_karma=$link_karma, link_anonymous=$link_anonymous, link_votes_avg=$link_votes_avg, link_content_type='$link_content_type', link_ip='$link_ip' WHERE link_id=$this->id");
  361. }
  362. if ($this->votes == 1 && $this->negatives == 0 && $this->status == 'queued') {
  363. // This is a new link, add it to the events, it an additional control
  364. // just in case the user dind't do the last submit phase and voted later
  365. log_conditional_insert('link_new', $this->id, $this->author);
  366. }
  367. }
  368. function read_basic($key='id') {
  369. global $db;
  370. switch ($key) {
  371. case 'id':
  372. $cond = "link_id = $this->id";
  373. break;
  374. case 'uri':
  375. $cond = "link_uri = '$this->uri'";
  376. break;
  377. case 'url':
  378. $cond = "link_url = '$this->url'";
  379. break;
  380. default:
  381. $cond = "link_id = $this->id";
  382. }
  383. if(($link = $db->get_row("SELECT link_id, link_karma as karma, link_author, link_status, link_votes, link_negatives, link_anonymous, link_randkey, link_votos_permitidos, link_aleatorios_positivos, link_sent as sent, UNIX_TIMESTAMP(link_date) as link_ts, link_title FROM links WHERE $cond"))) {
  384. $this->id=$link->link_id;
  385. $this->author=$link->link_author;
  386. $this->status=$link->link_status;
  387. $this->votes=$link->link_votes;
  388. $this->negatives=$link->link_negatives;
  389. $this->anonymous=$link->link_anonymous;
  390. $this->randkey=$link->link_randkey;
  391. $this->votos_permitidos=$link->link_votos_permitidos;
  392. $this->sent = $link->sent;
  393. $this->date=$link->link_ts;
  394. $this->title=$link->link_title;
  395. $this->karma=$link->karma;
  396. $this->aleatorios_positivos=$link->link_aleatorios_positivos;
  397. $this->read = true;
  398. return true;
  399. }
  400. return false;
  401. }
  402. function read($key='id') {
  403. global $db;
  404. switch ($key) {
  405. case 'id':
  406. $cond = "link_id = $this->id";
  407. break;
  408. case 'uri':
  409. $cond = "link_uri = '$this->uri'";
  410. break;
  411. case 'url':
  412. $cond = "link_url = '$this->url'";
  413. break;
  414. default:
  415. $cond = "link_id = $this->id";
  416. }
  417. if(($result = $db->get_row("SELECT".Link::SQL."WHERE $cond AND user_id=link_author"))) {
  418. foreach(get_object_vars($result) as $var => $value) $this->$var = $value;
  419. $this->read = true;
  420. return true;
  421. }
  422. $this->read = false;
  423. return false;
  424. }
  425. function duplicates($url) {
  426. global $db;
  427. $trimmed = $db->escape(preg_replace('/\/$/', '', $url));
  428. $list = "'$trimmed', '$trimmed/'";
  429. if (preg_match('/^http:\/\/www\./', $trimmed)) {
  430. $link_alternative = preg_replace('/^http:\/\/www\./', 'http://', $trimmed);
  431. } else {
  432. $link_alternative = preg_replace('/^http:\/\//', 'http://www.', $trimmed);
  433. }
  434. $list .= ", '$link_alternative', '$link_alternative/'";
  435. $found = $db->get_var("SELECT link_id FROM links WHERE link_url in ($list) AND (link_status not in ('discard', 'abuse') OR link_votes>0) limit 1");
  436. return $found;
  437. }
  438. function print_summary($type='full', $karma_best_comment = 0, $show_tags = true) {
  439. global $current_user, $globals, $db;
  440. if(!$this->read)
  441. return;
  442. if($this->is_votable()) {
  443. if ($this->voted === null) $this->md5 = md5($current_user->user_id.$this->id.$this->randkey.$globals['user_ip']);
  444. }
  445. if ($globals['base_story_url']) {
  446. $joneame_link = 'http://'.get_server_name().$globals['base_url'].$globals['base_story_url'].'0'.$this->id;
  447. }
  448. $url = htmlspecialchars($this->url);
  449. echo '<div class="news-summary">';
  450. echo '<div class="news-body">';
  451. if ($type != 'preview') {
  452. if ($type == 'short')
  453. $this->print_shake_box(true);
  454. else
  455. $this->print_shake_box(true);
  456. }
  457. $this->print_warn();
  458. if ($this->status != 'published')
  459. $nofollow = ' rel="nofollow"';
  460. else
  461. $nofollow = '';
  462. echo '<h1>';
  463. echo '<a href="'.$url.'"'.$nofollow.' onmousedown="return clk(this,'.$this->id.')" target="_blank" class="titular">'. $this->title. '</a>';
  464. // Content type (for video and images)
  465. if ($this->content_type == 'image')
  466. echo '&nbsp;<img src="'.get_cover_pixel().'" class="icon image media-icon" alt="'._('imagen').'" title="'._('imagen').'" />';
  467. elseif ($this->content_type == 'video')
  468. echo '&nbsp;<img src="'.get_cover_pixel().'" class="icon video media-icon" alt="'._('vídeo').'" title="'._('vídeo').'" />';
  469. echo '</h1>';
  470. if (!$this->is_nsfw() && $this->has_thumb() && ($current_user->thumb == 1 || $current_user->user_id == 0))
  471. echo "<img src='$this->thumb' width='$this->thumb_x' height='$this->thumb_y' alt='' class='thumbnail'/>";
  472. if (isset($globals['bot']) && !$globals['bot']) {
  473. echo '<div class="news-submitted">';
  474. if ($type != 'short')
  475. echo '<a href="'.get_user_uri($this->username).'"><img src="'.get_avatar_url($this->author, $this->avatar, 25).'" width="25" height="25" alt="" onmouseover="return tooltip.ajax_delayed(event, \'get_user_info.php\', '.$this->author.');" onmouseout="tooltip.clear(event);" /></a>';
  476. echo '<strong>'.htmlentities(preg_replace('/^https*:\/\//', '', txt_shorter($this->url))).'</strong>'."<br />\n";
  477. echo _('por').' <a href="'.get_user_uri($this->username, 'enviadas').'">'.$this->username.'</a> ';
  478. // Print dates
  479. if ($globals['now'] - $this->date > 604800) { // 7 days
  480. echo _('el').get_date_time($this->sent_date);
  481. if($this->status == 'published')
  482. echo ', ' ._('publicada el').get_date_time($this->date);
  483. } else {
  484. echo _('hace').txt_time_diff($this->sent_date);
  485. if($this->status == 'published')
  486. echo ', ' ._('en portada hace').txt_time_diff($this->date);
  487. }
  488. echo "</div>\n";
  489. }
  490. if($type=='full' || $type=='preview') {
  491. echo '<p>';
  492. echo text_to_html(put_smileys($this->content, 'links'));
  493. if ($type != 'preview') {
  494. if ($this->is_editable() )
  495. echo '&nbsp;&nbsp;<a href="'.$globals['base_url'].'editlink.php?id='.$this->id.'&amp;user='.$current_user->user_id.'" title="'._('editar noticia').' #'.$this->id.'">'.$this->get_editable_teaser().'</a>';
  496. if (isset($this->geo) && $this->geo && $this->is_map_editable() && $globals['joneame'])
  497. echo '&nbsp;&nbsp;<a href="#" onclick="$(\'#geoedit\').load(\''.$globals['base_url']."geo/get_form.php?id=$this->id&amp;type=link&amp;icon=$this->status".'\'); return false;">'.$this->get_map_editable_teaser().'</a><br/>';
  498. if ($this->is_editable() && $current_user->user_id == $this->author && !$current_user->admin) {
  499. echo '<div class="news-details">';
  500. echo '<strong>Si deseas editar la noticia, tienes '.round($globals['edicion_historias_usuario'] / 60).' minutos.<br/>Una vez pasado este tiempo, ponte en contacto con un administrador.</strong>';
  501. echo '</div>';
  502. } elseif ($this->is_editable() && $current_user->especial && $current_user->user_id != $this->author && !$current_user->admin) {
  503. echo '<div class="news-details">';
  504. echo '<strong>Dispones de privilegios especiales que te permiten la edición de esta noticia.<br/>Úsalos con cuidado ;-) </strong>';
  505. echo '</div>';
  506. }
  507. }
  508. echo '</p>';
  509. }
  510. // Print a summary of the best comment
  511. if ($karma_best_comment > 0 &&
  512. ($best_comment = $db->get_row("select comment_id, comment_order, comment_content from comments where comment_link_id = $this->id and comment_karma > $karma_best_comment order by comment_karma desc limit 1"))) {
  513. echo '<div class="mejor-comentario">';
  514. $link = $this->get_permalink().get_comment_page_suffix($globals['comments_page_size'], $best_comment->comment_order, $this->comments).'#comment-'.$best_comment->comment_order;
  515. echo '<a onmouseout="tooltip.clear(event);" onclick="tooltip.clear(this);" onmouseover="return tooltip.ajax_delayed(event, \'get_comment_tooltip.php\', \''.$best_comment->comment_id.'\', 10000);" href="'.$link.'"><strong>'.$best_comment->comment_order.'</strong>';
  516. echo ':&nbsp;'.text_to_summary($best_comment->comment_content, 200).'</a></div>';
  517. }
  518. echo '<div class="news-details">';
  519. $comentarios = '';
  520. $comments_mess = $this->comments > 1 ? ' ' . _('comentarios') : ' ' . _('comentario');
  521. if ($this->comments == 0)
  522. $comments_mess = _('no hay comentarios');
  523. else $comentarios = $this->comments;
  524. echo '<span class="comments">&nbsp;<a href="'.$this->get_relative_permalink().'">';
  525. echo '<span id="n_comentarios-'.$this->id.'">'.$comentarios.'</span><span id="t_comentarios-'.$this->id.'">'.$comments_mess.'</span></a></span>';
  526. echo '&nbsp;<span class="tool">carisma: <strong><span id="a-karma-'.$this->id.'">'.intval($this->karma).'</span></strong></span>';
  527. echo '(<b><span id="a-usu-'.$this->id.'"><abbr title="votos">'.$this->votes.'</abbr></span></b>, <b>';
  528. if ($this->anonymous != 0)
  529. echo '<span id="a-ano-'.$this->id.'">';
  530. else
  531. echo '<span id="a-ano-'.$this->id.'" style="color: #aaa;">';
  532. echo '<abbr title="votos anónimos">'.$this->anonymous.'</abbr></span></b>, <b>';
  533. if ($this->aleatorios_positivos != 0)
  534. echo '<span id="a-ale_pos-'.$this->id.'">';
  535. else
  536. echo '<span id="a-ale_pos-'.$this->id.'" style="color: #aaa;">';
  537. echo '<abbr title="votos aleatorios positivos">'.$this->aleatorios_positivos.'</abbr></span></b>, <b>';
  538. if ($this->aleatorios_negativos != 0)
  539. echo '<span id="a-ale_neg-'.$this->id.'" style="color: red;">';
  540. else
  541. echo '<span id="a-ale_neg-'.$this->id.'" style="color: #aaa;">';
  542. echo '<abbr title="votos aleatorios negativos">'.$this->aleatorios_negativos.'</abbr></span></b>, <b>';
  543. if ($this->negatives != 0)
  544. echo '<span id="a-neg-'.$this->id.'" style="color: red;">';
  545. else
  546. echo '<span id="a-neg-'.$this->id.'" style="color: #aaa;">';
  547. echo '<abbr title="votos negativos">'.$this->negatives.'</abbr></span></b>)';
  548. print_share_icons($this->get_permalink(), $this->get_short_permalink(), $this->title, $this->id);
  549. if($this->voted === null && $this->negatives_allowed() && $type != 'preview' && $this->votes_enabled)
  550. $this->print_problem_form();
  551. // If the user is authenticated, show favorite box
  552. if ($current_user->user_id > 0)
  553. echo '&nbsp;<span class="tool">&nbsp;<a id="fav-'.$this->id.'" href="javascript:obtener(\'joneo_favorito.php\',\''.$current_user->user_id.'\',\'fav-'.$this->id.'\',0,\''.$this->id.'\')">'.favorite_icon($this->favorite, 'link').'</a></span>';
  554. echo '</div><div class="news-details"><b>'._('categoría').':</b>&nbsp;';
  555. if ($this->status == 'published') { //si el estado es publicada, lleva a la categoria publicadas
  556. echo '<a href="'.$globals['base_url'].'?category='.$this->category.'" title="'._('categoría').'">'.$this->category_name.'</a>';
  557. } else { //si no a categorias en pendientes
  558. echo '<a href="'.$globals['base_url'].'jonealas.php?category='.$this->category.'" title="'._('categoría').'">'.$this->category_name.'</a>';
  559. }
  560. echo '&nbsp;';
  561. if ($show_tags && !empty($this->tags)) {
  562. $tags_array = explode(",", $this->tags);
  563. $tags_counter = 0;
  564. echo '<span class="tool"><b>'._('etiquetas').':</b>';
  565. foreach ($tags_array as $tag_item) {
  566. $tag_item=trim($tag_item);
  567. $tag_url = urlencode($tag_item);
  568. if ($tags_counter > 0)
  569. echo ',';
  570. if ($globals['buscador_activado']) {
  571. echo ' <a href="'.$globals['base_url'].'search.php?p=tag&amp;q=';
  572. }
  573. if (!$globals['buscador_activado'])
  574. echo ' '. $tag_item;
  575. else
  576. echo $tag_url.'">'.$tag_item.'</a>';
  577. $tags_counter++;
  578. }
  579. echo '</span>';
  580. }
  581. if ($this->clicks > 0 && isset($globals['show_visits'])){
  582. echo ' <span class="tool">';
  583. echo '<strong>clics:</strong> '.$this->clicks;
  584. echo '</span>';
  585. }
  586. if ($this->visits > 0 && isset($globals['show_visits'])){
  587. echo ' <span class="tool">';
  588. echo '<strong>visitas:</strong> '.$this->visits;
  589. echo '</span>';
  590. }
  591. echo '</div>';
  592. echo '</div>'."\n";
  593. echo '</div>'."\n";
  594. // Geo edit form div
  595. if (isset($this->geo) && $this->geo && $this->is_map_editable() && $globals['joneame']) {
  596. echo '<div id="geoedit" class="geoform" style="margin-left:20px">';
  597. if ($current_user->user_id == $this->author && $this->sent_date > $globals['now'] - 0 && !$this->latlng) {
  598. geo_coder_print_form('link', $this->id, $globals['latlng'], _('ubica al origen de la noticia o evento (ciudad, país)'));
  599. }
  600. echo '</div>'."\n";
  601. }
  602. }
  603. function print_shake_box($print_vote_box = true) {
  604. global $current_user, $anonnymous_vote, $site_key, $globals;
  605. switch ($this->status) {
  606. case 'queued':
  607. $box_class = 'mnm-queued';
  608. break;
  609. case 'abuse':
  610. $box_class = 'jnm-abuse';
  611. break;
  612. case 'autodiscard':
  613. case 'discard':
  614. case 'duplicated':
  615. $box_class = 'mnm-discarded';
  616. break;
  617. case 'published':
  618. default:
  619. $box_class = 'mnm-published';
  620. break;
  621. }
  622. echo '<div class="news-shakeit">';
  623. if ($print_vote_box)
  624. echo '<div class="'.$box_class.'">';
  625. else
  626. echo '<div class="'.$box_class.' without-votebox">';
  627. echo '<a id="a-votes-'.$this->id.'" href="'.$this->get_relative_permalink().'">'.($this->votes+$this->anonymous+$this->aleatorios_positivos).'</a>'._('joneos').'</div>';
  628. if (isset($globals['bot']) && !$globals['bot'] && $print_vote_box) {
  629. echo '<div class="menealo" id="a-va-'.$this->id.'">';
  630. /* Botones de votos */
  631. if ($this->voted === null && $this->votes_enabled) {
  632. if ($this->status == 'queued' && $current_user->user_id > 0 ) {
  633. /* Jonéala pendiente */
  634. echo '<a class="shakebox-central" href="javascript:jonea('."$current_user->user_id,$this->id,$this->id,"."'".$this->md5."'".')" id="a-shake-'.$this->id.'">'._('jon&eacute;ala').'</a>';
  635. /* Aleatorio registrado */
  636. if ($current_user->user_id > 0 && $globals ['aleatorios_usuarios_activados'])
  637. echo '<a href="javascript:joneo_aleatorio('."$current_user->user_id,$this->id,$this->id,"."'".$this->md5."'".')" id="a-shake-'.$this->id.'">'._('aleatorio').'</a>';
  638. } else /* Joneala publicada */
  639. echo '<a href="javascript:jonea('."$current_user->user_id,$this->id,$this->id,"."'".$this->md5."'".')" id="a-shake-'.$this->id.'">'._('jon&eacute;ala').'</a>';
  640. /* Sin votar */
  641. } else {
  642. /* Info de votos */
  643. if ($this->votes_enabled){
  644. /*Obtiene información del voto del usuario*/
  645. if ($current_user->user_id > 0)
  646. $voto_aleatorio = $this->aleatorio_info();
  647. /*Comprueba si el usuario votó aleatorio la historia*/
  648. if ($voto_aleatorio->aleatorio == 'aleatorio' && $current_user->user_id > 0)
  649. $mess = _('valió ').$voto_aleatorio->valor; /*Valor del voto del usuario*/
  650. else {
  651. if ($this->voted >= 0)
  652. $mess = _('&#161;&#161;Biba!!'); /*Votado positivo*/
  653. else if ($this->voted < 0)
  654. $mess = _(':-('); /*Votado negativo*/
  655. }
  656. /* Cerradas */
  657. } else $mess = _('chapau!');
  658. echo '<span id="a-shake-'.$this->id.'">'.$mess.'</span>';
  659. }
  660. echo '</div>'."\n";
  661. }
  662. echo '</div>'."\n";
  663. }
  664. // nos dice si el voto es aleatorio o normal
  665. function aleatorio_info() {
  666. global $db, $current_user;
  667. if ($current_user->user_id == 0) return false;
  668. return $db->get_row("SELECT vote_aleatorio as aleatorio, vote_value as valor FROM votes WHERE vote_type = 'links' AND vote_link_id = $this->id AND vote_user_id = $current_user->user_id LIMIT 1");
  669. }
  670. function print_warn() {
  671. global $db, $globals;
  672. $this->warned = false;
  673. $tiene_negativos = false;
  674. $this->is_nsfw();
  675. /*Votos totales positivos*/
  676. $votos_totales = $db->get_var("SELECT count(*) FROM votes WHERE vote_link_id=$this->id and vote_type='links' and vote_value >= 0");
  677. // votos negativos no-aleatorios
  678. $votos_negativos = $db->get_var("SELECT count(*) FROM votes WHERE vote_link_id=$this->id and vote_type='links' and vote_aleatorio='normal' and vote_value < 0");
  679. // ponemos tiene_negativos en true
  680. if ($this->votes_enabled && !$this->is_discarded() && $votos_negativos > 1 && $votos_negativos > $votos_totales/6)
  681. $tiene_negativos = true;
  682. /* si el estado es abuse muestra un aviso */
  683. if ($this->status == 'abuse') {
  684. echo '<div class="warn"><strong>'._('Aviso').'</strong>: ';
  685. if (!$this->nsfw) echo _('Noticia descartada por incumplir las').' <a href="'.$globals['legal'].'#tos">'._('condiciones de uso').'</a>';
  686. else echo _('El enlace de esta historia contiene material sólo apto para adultos y adem&aacute;s ha sido <strong>descartada por incumplir las').' <a href="'.$globals['legal'].'#tos">'._('condiciones de uso').'</a></strong>' ;
  687. echo "</div>\n";
  688. $this->warned = true;
  689. } else if ($this->status == 'duplicated') {
  690. require_once(mnminclude.'dupe.class.php');
  691. $dupe = new Dupe;
  692. $dupe->id = $this->id;
  693. $dupe->get();
  694. echo '<div class="warn"><strong>'._('Admin:').'</strong> ';
  695. echo _('La historia está descartada por <a href="'.$dupe->duplicate.'">duplicada </a>');
  696. echo "</div>\n";
  697. }
  698. if ($this->status == 'published' && $tiene_negativos && !$this->nsfw ) {
  699. echo '<div class="warn"><strong>'._('Aviso autom&aacute;tico de la mafia').'</strong>: ';
  700. echo _('Noticia controvertida, por favor lee los comentarios, a saber qu&eacute; han liado estos...');
  701. echo "</div>\n";
  702. $this->warned = true;
  703. }
  704. // historias NSFW
  705. if ($this->nsfw && $this->status != 'duplicated') {
  706. if ($tiene_negativos) {
  707. echo '<div class="porn"><strong>'._('Aviso').'</strong>: ';
  708. if ($this->status != 'published')
  709. echo _('Esta noticia tiene varios votos sensuradores. El enlace de esta historia contiene material sólo apto para adultos') ;
  710. else echo _('Noticia controvertida, por favor, lee los comentarios. Ojo. El enlace de esta historia contiene material s&oacute;lo apto para adultos.');
  711. echo "</div>\n";
  712. $this->warned = true;
  713. } else if (!$tiene_negativos && $this->status != 'abuse') {
  714. echo '<div class="porn"><strong>'._('&iexcl;&iexcl;Oiga!!').'</strong> ';
  715. echo _('El enlace de esta historia contiene material s&oacute;lo apto para adultos.');
  716. echo "</div>\n";
  717. }
  718. }
  719. if ($this->votes_enabled && !$this->is_discarded() && $tiene_negativos && !$this->is_nsfw() && $this->status != 'published') {
  720. $negatives = $db->get_row("select vote_value, count(vote_value) as count from votes where vote_type='links' and vote_link_id=$this->id and vote_value < 0 and vote_aleatorio='normal' group by vote_value order by count desc limit 1");
  721. echo '<div class="warn"><strong>'._('Aviso autom&aacute;tico').'</strong>: ';
  722. if ($negatives->vote_value == -1 || $negatives->vote_value == -2)
  723. echo _('Esta noticia podría ser <strong>'). get_negative_vote($negatives->vote_value) . '</strong>';
  724. elseif ($negatives->vote_value == -3)
  725. echo _('A la mafia no le gusta esta noticia');
  726. else
  727. echo _('Esta noticia tiene algunos votos negativos');
  728. if($this->voted ===null )
  729. echo ', <a href="'.$this->get_relative_permalink().'/votos">' ._('asegúrate').'</a> ' . _('antes de votarla') . '.';
  730. else
  731. echo '.';
  732. echo "</div>\n";
  733. $this->warned = true;
  734. }
  735. }
  736. function print_problem_form() {
  737. global $current_user, $globals;
  738. echo '<form class="tool" action="" id="problem-'.$this->id.'">';
  739. echo '<select '.$this->status.' name="ratings" onchange="';
  740. echo 'report_problem(this.form,'."$current_user->user_id, $this->id, "."'".$this->md5."'".')';
  741. echo '">';
  742. echo '<option value="0" selected="selected">'._('sensurar').'</option>';
  743. foreach (array_keys($globals['negative_votes_values']) as $pvalue) {
  744. echo '<option value="'.$pvalue.'">'.$globals['negative_votes_values'][$pvalue].'</option>';
  745. }
  746. echo '</select>';
  747. echo '</form>';
  748. }
  749. function vote_exists($user) {
  750. require_once(mnminclude.'votes.php');
  751. $vote = new Vote;
  752. $vote->user=$user;
  753. $vote->link=$this->id;
  754. $vote->type = 'links';
  755. return $vote->exists(); //devuelve el valor del voto si existe, y false si no existe
  756. }
  757. function votes($user) {
  758. require_once(mnminclude.'votes.php');
  759. $vote = new Vote;
  760. $vote->user=$user;
  761. $vote->link=$this->id;
  762. return $vote->count();
  763. }
  764. function aleatorios_count(){
  765. return $this->aleatorios_positivos + $this->aleatorios_negativos;
  766. }
  767. function insert_vote($value) {
  768. global $db, $current_user;
  769. require_once(mnminclude.'votes.php');
  770. $vote = new Vote;
  771. $vote->user=$current_user->user_id;
  772. $vote->link=$this->id;
  773. if ($vote->exists()) return false;
  774. if (!$this->insert_aleatorio){
  775. // For karma calculation
  776. if ($value < 0)
  777. $karma_value = $value;
  778. else if ($this->status != 'published')
  779. $karma_value = $value;
  780. else
  781. $karma_value = 0;
  782. $vote->aleatorio = false;
  783. if ($karma_value < 0) $user_karma = round($current_user->user_karma);
  784. } else {
  785. $karma_value = $vote->get_aleatorio_value();
  786. $vote->aleatorio = true;
  787. }
  788. $vote->value=$karma_value;
  789. if($vote->insert()) {
  790. /* Aumentar contador aleatorios*/
  791. if ($this->insert_aleatorio && $vote->value >= 0) $db->query("update links set link_aleatorios_positivos=link_aleatorios_positivos+1 where link_id = $this->id");
  792. else if ($this->insert_aleatorio && $vote->value < 0) $db->query("update links set link_aleatorios_negativos=link_aleatorios_negativos+1 where link_id = $this->id");
  793. if ($vote->value < 0) {
  794. if (!$this->insert_aleatorio) /* Aumenta contador y carisma negativos */
  795. $db->query("update links set link_negatives=link_negatives+1, link_karma=link_karma-$user_karma $link_aleatorios where link_id = $this->id"); /* Reduce karma negativo */
  796. else $db->query("update links set link_karma=link_karma-$user_karma where link_id = $this->id");
  797. } else { /* Aumenta contador y carisma positivos */
  798. if ($current_user->user_id > 0 && !$this->insert_aleatorio) $db->query("update links set link_votes = link_votes+1, link_karma=link_karma+$karma_value where link_id = $this->id"); /*Carisma +*/
  799. else if ($current_user->user_id > 0 && $this->insert_aleatorio) $db->query("update links set link_karma=link_karma+$karma_value where link_id = $this->id"); /* Anonimos */
  800. else if ($current_user->user_id == 0) $db->query("update links set link_anonymous = link_anonymous+1, link_karma=link_karma+$karma_value where link_id = $this->id");
  801. }
  802. $new = $db->get_row("select link_votes, link_anonymous, link_negatives, link_karma, link_aleatorios_positivos, link_aleatorios_negativos from links where link_id = $this->id");
  803. $this->votes = $new->link_votes;
  804. $this->anonymous = $new->link_anonymous;
  805. $this->negatives = $new->link_negatives;
  806. $this->karma = $new->link_karma;
  807. $this->aleatorios_positivos = $new->link_aleatorios_positivos;
  808. $this->aleatorios_negativos = $new->link_aleatorios_negativos;
  809. return true;
  810. }
  811. return false;
  812. }
  813. function publish() {
  814. global $globals;
  815. if(!$this->read) $this->read_basic();
  816. $this->published_date = $globals['now'];
  817. $this->date = $globals['now'];
  818. $this->status = 'published';
  819. $this->store_basic();
  820. }
  821. function update_comments() {
  822. global $db;
  823. $this->comments = $db->get_var("SELECT count(*) FROM comments WHERE comment_link_id = $this->id");
  824. $db->query("update links set link_comments = $this->comments where link_id = $this->id");
  825. }
  826. function is_discarded() {
  827. return $this->status == 'discard' || $this->status == 'abuse' || $this->status == 'autodiscard' || $this->sent == 0 || $this->status == 'duplicated' ;
  828. }
  829. function is_editable() {
  830. global $current_user, $globals;
  831. if($current_user->user_id) {
  832. // es el usuario, dispone de los primeros 15 minutos
  833. if(($this->author == $current_user->user_id
  834. && $this->status != 'published'
  835. && $this->status != 'abuse'
  836. && $this->status != 'autodiscard'
  837. && $globals['now'] - $this->sent_date < $globals['edicion_historias_usuario'])
  838. // es "special" , dispone a partir de los 15 minutos, hasta pasados 10
  839. || ($this->author != $current_user->user_id
  840. && $current_user->especial
  841. && $this->status != 'abuse'
  842. && $this->status != 'autodiscard'
  843. // && $this->status != 'published'
  844. && $globals['now'] - $this->sent_date > $globals['edicion_historias_usuario'] + 300
  845. && $globals['now'] - $this->sent_date < $globals['edicion_historias_usuario'] + 600)
  846. // es administrador
  847. || $current_user->admin) {
  848. return true;
  849. }
  850. }
  851. return false;
  852. }
  853. function is_map_editable() {
  854. global $current_user, $globals;
  855. if($current_user->user_id == 0) return false;
  856. if( ($this->author == $current_user->user_id && $current_user->user_level == 'normal' && $globals['now'] - $this->sent_date < 9800)
  857. || ($current_user->especial && $globals['now'] - $this->sent_date < 14400)
  858. || $current_user->admin) {
  859. return true;
  860. }
  861. return false;
  862. }
  863. function get_editable_teaser() {
  864. global $current_user, $globals;
  865. if ($current_user->admin)
  866. $iddqd = ' iddqd';
  867. $editable_teaser = '<span class="n-edit'.$iddqd.'">';
  868. if ($this->author == $current_user->user_id)
  869. $editable_teaser .= calc_remaining_edit_time($this->sent_date, $globals['edicion_historias_usuario']);
  870. elseif ($this->author != $current_user->user_id && $current_user->especial)
  871. $editable_teaser .= 'special';
  872. elseif ($current_user->admin)
  873. $editable_teaser .= 'admin';
  874. $editable_teaser .= '</span>';
  875. return $editable_teaser;
  876. }
  877. function get_map_editable_teaser() {
  878. global $current_user, $globals;
  879. if ($current_user->admin)
  880. $iddqd = ' iddqd';
  881. $editable_teaser = '<span class="geo-edit'.$iddqd.'">';
  882. if ($this->author == $current_user->user_id)
  883. $editable_teaser .= calc_remaining_edit_time($this->sent_date, 9800, true); // !!FIXME hardcoded!
  884. elseif ($this->author != $current_user->user_id && $current_user->especial)
  885. $editable_teaser .= 'special';
  886. elseif ($current_user->admin)
  887. $editable_teaser .= 'admin';
  888. $editable_teaser .= '</span>';
  889. return $editable_teaser;
  890. }
  891. function is_votable() {
  892. global $globals;
  893. if(isset($globals['bot']) && $globals['bot'] || $this->status == 'abuse' || $this->status == 'duplicated' || $this->status == 'autodiscard' ||
  894. ($globals['time_enabled_votes'] > 0 && $this->date < $globals['now'] - $globals['time_enabled_votes']) || !$this->votos_permitidos) {
  895. $this->votes_enabled = false;
  896. } else {
  897. $this->votes_enabled = true;
  898. }
  899. return $this->votes_enabled;
  900. }
  901. function negatives_allowed() {
  902. global $globals, $current_user;
  903. return $current_user->user_id > 0
  904. && $this->author != $current_user->user_id
  905. && $this->status != 'abuse'
  906. && $this->status != 'autodiscard'
  907. && $current_user->user_karma >= $globals['min_karma_for_negatives']
  908. && ($this->status != 'published'
  909. || $this->status == 'published'
  910. && ($this->date > $globals['now'] - 7200
  911. || $this->warned)
  912. );
  913. }
  914. function get_uri() {
  915. global $db, $globals;
  916. $seq = 0;
  917. require_once(mnminclude.'uri.php');
  918. $new_uri = $base_uri = get_uri($this->title);
  919. while ($db->get_var("select count(*) from links where link_uri='$new_uri' and link_id != $this->id") && $seq < 20) {
  920. $seq++;
  921. $new_uri = $base_uri . "-$seq";
  922. }
  923. // In case we tried 20 times, we just add the id of the article
  924. if ($seq >= 20) {
  925. $new_uri = $base_uri . "-$this->id";
  926. }
  927. $this->uri = $new_uri;
  928. }
  929. function get_short_permalink() {
  930. global $globals;
  931. if ($globals['base_story_url']) {
  932. return 'http://'.get_server_name().$globals['base_url'].$globals['base_story_url'].'0'.$this->id;
  933. } else {
  934. return 'http://'.get_server_name().$this->get_relative_permalink();
  935. }
  936. }
  937. function get_relative_permalink() {
  938. global $globals;
  939. if (!empty($this->uri) && !empty($globals['base_story_url']) ) {
  940. return $globals['base_url'] . $globals['base_story_url'] . $this->uri;
  941. } else {
  942. return $globals['base_url'] . 'historia.php?id=' . $this->id;
  943. }
  944. }
  945. function get_permalink() {
  946. return 'http://'.get_server_name().$this->get_relative_permalink();
  947. }
  948. function get_trackback() {
  949. global $globals;
  950. return "http://".get_server_name().$globals['base_url'].'trackback.php?id='.$this->id;
  951. }
  952. function get_status_text($status = false) {
  953. global $current_user, $linkres;
  954. if (!$status) $status = $this->status;
  955. switch ($status) {
  956. case ('abuse'):
  957. return _('abuso');
  958. case ('discard'):
  959. return _('descartada');
  960. case ('queued'):
  961. return _('pendiente');
  962. case ('published'):
  963. return _('publicada');
  964. case ('duplicated'):
  965. return _('duplicada');
  966. case ('autodiscard'):
  967. if ($current_user->user_id == $linkres->author)
  968. return _('autodescartada');
  969. if ((($current_user->admin)) && ($current_user->user_id != $linkres->author))
  970. return _('descartada');
  971. }
  972. return $status;
  973. }
  974. function get_latlng() {
  975. require_once(mnminclude.'geo.php');
  976. return geo_latlng('link', $this->id);
  977. }
  978. function print_content_type_buttons($link_title = false) {
  979. global $globals;
  980. // Is it an image or video?
  981. switch ($this->content_type) {
  982. case 'image':
  983. case 'video':
  984. case 'text':
  985. $type[$this->content_type] = 'checked="checked"';
  986. break;
  987. default:
  988. $type['text'] = 'checked="checked"';
  989. }
  990. // Not Safe For Work (NSFW) y Sólo para adultos (+18)
  991. echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  992. if (stripos($link_title , '[NSFW]')) {
  993. echo '<input type="checkbox" checked="checked" name="sec[0]" value="text" id="nsfw"/>';
  994. } else {
  995. echo '<input type="checkbox" name="sec[0]" value="text" id="nsfw"/>';
  996. }
  997. echo '&nbsp;<label for="nsfw">'._('NSFW').'</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  998. echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  999. if (stripos($link_title , '[+18]')) {
  1000. echo '<input type="checkbox" checked="checked" name="sec[1]" value="text" id="mas18"/>';
  1001. } else {
  1002. echo '<input type="checkbox" name="sec[1]" value="text" id="mas18"/>';
  1003. }
  1004. echo '&nbsp;<label for="mas18">'._('+18').'</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  1005. echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  1006. echo '<input type="radio" '.$type['text'].' name="type" value="text" id="text"/>';
  1007. echo '&nbsp;<label for="text">'._('texto').'</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  1008. echo '<input type="radio" '.$type['image'].' name="type" value="image" id="image"/>';
  1009. echo '&nbsp;<label for="image"><img src="'.get_cover_pixel().'" class="icon image media-icon" alt="'._('¿es una imagen?').'" title="'._('¿es una imagen?').'" /></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  1010. echo '<input type="radio" '.$type['video'].' name="type" value="video" id="video"/>';
  1011. echo '&nbsp;<label for="video"><img src="'.get_cover_pixel().'" class="icon video media-icon" alt="'._('¿es un vídeo?').'" title="'._('¿es un vídeo?').'" /></label>';
  1012. }
  1013. function read_content_type_buttons($type) {
  1014. switch ($type) {
  1015. case 'image':
  1016. $this->content_ty

Large files files are truncated, but you can click here to view the full file