. // It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise. // You can get copies of the licenses here: // http://www.affero.org/oagpl.html // AFFERO GENERAL PUBLIC LICENSE is also included in the file called "COPYING". require_once('config.php'); require_once(mnminclude.'html1.php'); require_once(mnminclude.'link.php'); require_once(mnminclude.'tags.php'); require_once(mnminclude.'ban.php'); require_once(mnminclude.'blog.php'); require_once(mnminclude.'thumbnails.php'); $globals['ads'] = true; if(isset($_POST["phase"])) { force_authentication(); switch ($_POST["phase"]) { case 1: do_header(_("enviar noticia"), "post"); do_submit1(); break; case 2: do_header(_("enviar noticia"), "post"); do_submit2(); break; case 3: do_submit3(); break; } } else { check_already_sent(); force_authentication(); do_header(_("enviar noticia"), "post"); do_submit0(); } do_footer(); exit; function preload_indicators() { global $globals; echo ''."\n"; } function check_already_sent() { global $db; // Check if the url has been sent already if (!empty($_GET['url'])) { $linkres = new Link; if (($found = $linkres->duplicates($_GET['url']))) { $linkres->id = $found; if($linkres->read()) { header('Location: ' . $linkres->get_permalink()); die; } } } } function print_empty_submit_form() { global $globals; preload_indicators(); if (!empty($_GET['url'])) { $url = clean_input_url($_GET['url']); } else { $url = 'http://'; } echo '
'; echo '
'._('dirección de la noticia').''; echo '
'; echo '


'; echo '

'; echo ''; echo ''; echo ''; echo ''."\n"; echo '

    

'; echo '
'; echo '
'; echo '
'; } function do_submit0() { do_banner_top(); echo '
' . "\n"; echo '
'."\n"; echo '

'._('envío de una nueva noticia: paso 1 de 3').'

'; echo '
'; echo '

'._('por favor, respeta estas instrucciones para mejorar la calidad:').'

'; echo '
    '; echo '
  • '._('contenido interesante').': '._('¿la noticia conseguirá suficientes votos por méritos propios? esto es, sin que haga falta la ayuda de tus amigos, conocidos y saludados. usa la empatía para intentar averiguarlo: ¿interesará a una cantidad razonable de lectores?').'
  • '; echo '
  • '._('enlaza la fuente original').': '._('no hagas perder tiempo a los lectores.').'
  • '; echo '
  • '._('busca antes').': '._('evita duplicar noticias.').'
  • '; echo '
  • '._('sé descriptivo').': '._('explica la noticia lo mejor que puedas y porqué es interesante').'.
  • '; echo '
  • '._('repetimos, por las dudas... ¡enlaza la fuente original!').'
  • '; echo '
  • '._('respeta el voto de los demás').'. '._('si los votos o la falta de ellos te pueden afectar personalmente, es mejor que no envíes la noticia.').'
  • '; echo '
  • '._('NO envíes').': '._('spam, sensacionalismo, amarillismo, cotilleos, noticias del corazón, provocaciones, difamaciones e insultos.').'
  • '; echo '
'."\n"; print_empty_submit_form(); echo '
'; } function do_submit1() { global $db, $dblang, $current_user, $globals; do_banner_top(); echo '
' . "\n"; echo '
'."\n"; if ($globals['min_karma_for_links'] > 0 && $current_user->user_karma < $globals['min_karma_for_links'] ) { echo '

'._('no tienes el mínimo de karma para enviar una nueva historia').'

'; // echo '
' . "\n"; echo '
'. "\n"; return; } if(check_ban($globals['user_ip'], 'ip') || check_ban_proxy()) { echo '

'._('Dirección IP no permitida para enviar').': '.$globals['user_ip'].' ('. $globals['ban_message'].')

'; syslog(LOG_NOTICE, "Meneame, banned IP $globals[user_ip] ($current_user->user_login): $_POST[url]"); print_empty_submit_form(); echo '
'. "\n"; return; } // avoid spams, an extra security check // it counts the numbers of links in the last 2 hours $same_user = $db->get_var("select count(*) from links where link_date > date_sub(now(), interval 2 hour) and link_author=$current_user->user_id and link_votes > 0"); $same_ip = $db->get_var("select count(*) from links, votes where link_date > date_sub(now(), interval 2 hour) and vote_type='links' and vote_link_id = link_id and vote_user_id = link_author and vote_ip_int = ".$globals['user_ip_int']); if ($same_user > 6 || $same_ip > 6 ) { echo '

'._('debes esperar, ya se enviaron varias con el mismo usuario o dirección IP'). '

'; echo '
' . "\n"; echo '
'. "\n"; return; } // avoid users sending continuous "rubbsih" or "propaganda", specially new users // it takes in account the number of positive votes in the last six hours if ($same_user > 1 && $current_user->user_karma < 7.5) { $positives_received = $db->get_var("select count(*) from votes left join links on link_date > date_sub(now(), interval 6 hour) and link_author = $current_user->user_id where vote_type='links' and vote_link_id = link_id and vote_user_id > 0 and vote_value > 0"); $negatives_received = $db->get_var("select count(*) from votes left join links on link_date > date_sub(now(), interval 6 hour) and link_author = $current_user->user_id where vote_type='links' and vote_link_id = link_id and vote_user_id > 0 and vote_value < 0"); echo "\n"; echo "\n"; if ($negatives_received > $positives_received * 1.5) { echo '

'._('debes esperar, has tenido demasiados votos negativos en tus últimos envíos'). '

'; echo '
' . "\n"; echo ''. "\n"; return; } } $url = clean_input_url($_POST['url']); $url = preg_replace('/^http:\/\/http:\/\//', 'http://', $url); // Some users forget to delete the foo http:// $linkres=new Link; $edit = false; if(report_dupe($url)) return; if(!$linkres->check_url($url) || !$linkres->get($url)) { echo '

'._('URL inválido').': '.htmlspecialchars($url).'

'; echo '

'._('URL inválido, incompleto o no permitido'). ' ('. $globals['ban_message'].')

'; // If the domain is banned, decrease user's karma if ($linkres->banned) { $db->query("update users set user_karma = user_karma - 0.05 where user_id = $current_user->user_id"); } print_empty_submit_form(); echo ''. "\n"; return; } // If the URL has changed, check again is not dupe if($linkres->url != $url && report_dupe($linkres->url)) return; $linkres->randkey = intval($_POST['randkey']); if(!$linkres->valid) { echo '

'._('error leyendo el url').': '.htmlspecialchars($url).'

'; // Dont allow new users with low karma to post wrong URLs if ($current_user->user_karma < 8 && $current_user->user_level == 'normal') { echo '

'._('URL inválido, incompleto o no permitido').'

'; print_empty_submit_form(); return; } echo '

'._('no es válido, está fuera de línea, o tiene mecanismos antibots, continúa, pero asegúrate que sea correcto').'

'; } // check that the user also votes, not only sends links if ($current_user->user_karma < 7) { $from = time() - 3600*24; $user_votes = $db->get_var("select count(*) from votes where vote_type='links' and vote_date > from_unixtime($from) and vote_user_id=$current_user->user_id"); $user_links = 1 + $db->get_var("select count(*) from links where link_author=$current_user->user_id and link_date > from_unixtime($from) and link_status != 'discard'"); $total_links = $db->get_var("select count(*) from links where link_date > from_unixtime($from) and link_status = 'queued'"); $min_votes = min(4, intval($total_links/20)) * $user_links; if ($user_votes < $min_votes) { $needed = $min_votes - $user_votes; echo '

'._('no tienes el mínimo de votos necesarios para enviar una nueva historia').'

'; echo '

'._('necesitas votar como mínimo a'). " $needed " . _('noticias') . ', '; echo ''._('haz clic aquí para ir a votar').'

'; echo '
' . "\n"; echo ''. "\n"; return; } } $linkres->status='discard'; $linkres->author=$current_user->user_id; if (!$linkres->trackback()) { $linkres->pingback(); } $trackback=htmlspecialchars($linkres->trackback); $linkres->create_blog_entry(); $blog = new Blog; $blog->id = $linkres->blog; $blog->read(); $blog_url_components = @parse_url($blog->url); $blog_url = $blog_url_components[host].$blog_url_components[path]; // Now we check against the blog table // it's done because there could be banned blogs like http://lacotelera.com/something if(check_ban($blog_url, 'hostname', false)) { echo '

'._('URL inválido').': '.htmlspecialchars($url).'

'; echo '

'._('El sitio') . " $blog->url ". _('está deshabilitado'). ' ('. $globals['ban_message'].')

'; syslog(LOG_NOTICE, "Meneame, banned site ($current_user->user_login): $blog->url <- $_POST[url]"); print_empty_submit_form(); echo ''. "\n"; return; } // avoid auto-promotion (autobombo) $minutes = 15; $same_blog = $db->get_var("select count(*) from links where link_date > date_sub(now(), interval $minutes minute) and link_author=$current_user->user_id and link_blog=$linkres->blog and link_votes > 0"); if ($same_blog > 0 && $current_user->user_karma < 12) { syslog(LOG_NOTICE, "Meneame, forbidden due to short period between links to same site ($current_user->user_login): $linkres->url"); echo '

'._('ya has enviado un enlace al mismo sitio hace poco tiempo').'

'; echo '

'._('debes esperar'). " $minutes " . _(' minutos entre cada envío al mismo sitio.') . ', '; echo ''._('lee el FAQ').'

'; echo '
' . "\n"; echo ''. "\n"; return; } // Avoid spam, count links in last two months $sents = $db->get_var("select count(*) from links where link_author=$current_user->user_id and link_date > date_sub(now(), interval 60 day) and link_votes > 0"); $same_blog = $db->get_var("select count(*) from links where link_author=$current_user->user_id and link_date > date_sub(now(), interval 60 day) and link_blog=$linkres->blog and link_votes > 0"); if ($sents > 2 && $same_blog > 0 && ($ratio = $same_blog/$sents) > 0.5) { // Check if the domain should be banned // Calculate ban period according to previous karma $avg_karma = (int) $db->get_var("select avg(link_karma) from links where link_blog=$blog->id and link_date > date_sub(now(), interval 30 day) and link_votes > 0"); // This is the case of unique/few users sending just their site and take care of choosing goog titles and text // the condition is stricter, more links and higher ratio if (($sents > 2 && $ratio > 0.9) || ($sents > 6 && $ratio > 0.8) || ($sents > 12 && $ratio > 0.6)) { $unique_users = (int) $db->get_var("select count(distinct link_author) from links where link_blog=$blog->id and link_date > date_sub(now(), interval 15 day);"); if ($unique_users < 3) { if ($avg_karma < -10) { $ban_period = 86400*30; $ban_period_txt = _('un mes'); } else { $ban_period = 86400*7; $ban_period_txt = _('una semana'); } syslog(LOG_NOTICE, "Meneame, high ratio ($ratio) and few users ($unique_users), going to ban $blog->url ($current_user->user_login)"); } // Otherwise check previous karma } elseif ($sents > 4 && $avg_karma < 30) { if ($avg_karma < -40) { $ban_period = 86400*30; $ban_period_txt = _('un mes'); } elseif ($avg_karma < -10) { $ban_period = 86400*7; $ban_period_txt = _('una semana'); } elseif ($avg_karma < 10) { $ban_period = 86400; $ban_period_txt = _('un día'); } else { $ban_period = 7200; $ban_period_txt = _('dos horas'); } syslog(LOG_NOTICE, "Meneame, high ratio ($ratio) and low karma ($avg_karma), going to ban $blog->url ($current_user->user_login)"); } if ($ban_period > 0) { echo '

'._('ya has enviado demasiados enlaces a')." $blog->url".'

'; echo '

'._('varía tus fuentes, es para evitar abusos y enfados por votos negativos') . ', '; echo ''._('lee el FAQ').'

'; if (!empty($blog_url)) { $ban = insert_ban('hostname', $blog_url, _('envíos excesivos de'). " $current_user->user_login", time() + $ban_period); $banned_host = $ban->ban_text; echo '

'._('el dominio'). " '$banned_host' ". _('ha sido baneado por')." $ban_period_txt

"; syslog(LOG_NOTICE, "Meneame, banned '$ban_period_txt' due to high ratio ($current_user->user_login): $banned_host <- $linkres->url"); } else { syslog(LOG_NOTICE, "Meneame, error parsing during ban: $blog->id, $blog->url ($current_user->user_login)"); } echo '
' . "\n"; echo ''. "\n"; return; } else { echo '

'._('Aviso, estás enviando noticias del mismo web, podrías recibir muchos votos negativos y/o el sitio podría ser baneado automáticamente si continúas enviando').'

'; syslog(LOG_NOTICE, "Meneame, warn, high ratio ($current_user->user_login): $linkres->url"); } } // check there is no an "overflow" from the same site if ($current_user->user_karma < 15) { $total_links = $db->get_var("select count(*) from links where link_date > date_sub(now(), interval 24 hour)"); $site_links = intval($db->get_var("select count(*) from links where link_date > date_sub(now(), interval 24 hour) and link_blog=$linkres->blog")); if ($site_links > 5 && $site_links > $total_links * 0.04) { // Only 4% from the same site syslog(LOG_NOTICE, "Meneame, forbidden due to overflow to the same site ($current_user->user_login): $linkres->url"); echo '

'._('ya se han enviado demasiadas noticias del mismo sitio, espera unos minutos por favor').'

'; echo '

'._('total en 24 horas').": $site_links , ". _('el máximo actual es'). ': ' . intval($total_links * 0.04). '

'; echo '
' . "\n"; echo ''. "\n"; return; } } // Now stores new draft $linkres->store(); echo '

'._('envío de una nueva noticia: paso 2 de 3').'

'."\n"; echo '
'."\n"; echo '
'."\n"; echo ''."\n"; echo ''."\n"; echo ''."\n"; echo ''."\n"; echo ''."\n"; echo '
'._('información del enlace').''."\n"; echo '

'; echo mb_substr($linkres->url_title, 0, 200); echo '
'; echo htmlspecialchars($linkres->url); echo '

'."\n"; echo '
'."\n"; echo '
'._('detalles de la noticia').''."\n"; echo ''."\n"; echo '

'._('título de la noticia. máximo: 120 caracteres').''."\n"; echo '

'."\n"; echo ''."\n"; echo '

'._('pocas palabras, genéricas, cortas y separadas por "," (coma)').' Ejemplo: web, programación, software libre'."\n"; echo '

'."\n"; print_simpleformat_buttons('bodytext'); echo '

'."\n"; echo '
'._('describe la noticia con tus palabras. entre dos y cinco frases es suficiente. sé cuidadoso.').''."\n"; echo '
'."\n"; echo '
' . _('caracteres libres') . ''; echo '

'."\n"; print_categories_form(); ////////////////////////////////// // IMAGE SELECTOR echo '
' . "\n"; //echo '
'."\n"; echo '


'."\n"; echo ''._('Opcional. Esta función puede dar error o largos tiempos de espera. Pulsa en cargar imágenes y selecciona la que quieras adjuntar al enlace.').''."\n"; echo '
'._('Mostrar imágenes').''; echo '

'; ///////////// End of TODO echo '
'; echo '


'."\n"; if (empty($trackback)) { echo ''._('puedes agregar o cambiar el trackback si ha sido detectado automáticamente').''."\n"; echo '

'."\n"; } else { echo ''.$trackback.''."\n"; echo '

'."\n"; } echo '  '."\n"; echo ''."\n"; echo ''."\n"; echo ''."\n"; echo ''."\n"; echo ''."\n"; } function do_submit2() { global $db, $dblang, $globals; $linkres=new Link; $linkres->id=$link_id = intval($_POST['id']); $linkres->read(); $linkres->category=intval($_POST['category']); $linkres->title = clean_text(preg_replace('/(\w) *[;.,] *$/', "$1", $_POST['title']), 40); // It also deletes punctuaction signs at the end $linkres->tags = tags_normalize_string(clean_text($_POST['tags'])); if ( !empty($_POST['fotoescollida']) ) { $base_filename = get_link_image_filename ($linkres->id); create_thumbnail_folder ($linkres->id); require_once('libs/phpt/phpthumb.class.php'); $phpThumb = new phpThumb(); $thumbnail_widths = array(70, 120); foreach($thumbnail_widths as $thw) { $phpThumb->resetObject(); $phpThumb->setSourceFilename($db->escape($_POST["fotoescollida"])); $phpThumb->setParameter('w', $thw); $phpThumb->setParameter('h', $thw); $phpThumb->setParameter('zc', '1'); $phpThumb->setParameter('q', '90'); $output_filename = get_thumbnails_dir() . $base_filename . '.' . $thw . '.' .$phpThumb->config_output_format; if ($phpThumb->GenerateThumbnail()) { if ($phpThumb->RenderToFile($output_filename)) { //$fh = fopen($output_filename, 'rb'); //$contents = fread($fh, filesize($output_filename)); //fclose($fh); //$srvc->putObject($_POST['id'].'_'.$thw.'.'.$phpThumb->config_output_format, $contents,"imaxes"); } else { echo 'Failed:
'.implode("\n\n", $phpThumb->debugmessages).'
'; } } else { echo 'Failed:
'.$phpThumb->fatalerror."\n\n".implode("\n\n", $phpThumb->debugmessages).'
'; } } $linkres->image = $base_filename; } else { $linkres->image = ''; } $linkres->content = clean_text($_POST['bodytext']); if (link_errors($linkres)) { echo '
'."\n"; echo '

'."\n"; echo '
'."\n"; echo ''."\n"; // opened in print_form_submit_error return; } $linkres->store(); tags_insert_string($linkres->id, $dblang, $linkres->tags); $linkres->read(); $edit = true; $link_title = $linkres->title; $link_content = $linkres->content; do_banner_top(); preload_indicators(); echo '
' . "\n"; echo '
'."\n"; echo '

'._('envío de una nueva noticia: paso 3 de 3').'

'."\n"; echo '
'."\n"; echo '
'._('detalles de la noticia').''."\n"; echo '
  
'._('Ahora puedes 1) ').''._(' o 2) ').''._('. Cualquier otro clic convertirá tu noticia en comida para gatos elefantes (o no).').'
'; echo '
'."\n"; $linkres->print_summary('preview'); echo '
'."\n"; echo ''."\n"; echo ''."\n"; echo ''."\n"; echo ''."\n"; echo ''."\n"; echo '

'."\n"; echo '  '."\n"; echo '    '; echo '
'."\n"; echo '
'."\n"; echo '
'."\n"; } function do_submit3() { global $db, $current_user; $linkres=new Link; $linkres->id=$link_id = intval($_POST['id']); if(!$linkres->read()) die; // Check it is not in the queue already if($linkres->votes == 0 && $linkres->status != 'queued') { $linkres->status='queued'; $linkres->date=time(); $linkres->get_uri(); $linkres->store(); $linkres->insert_vote($current_user->user_id, $current_user->user_karma); // Add the new link log/event require_once(mnminclude.'log.php'); log_conditional_insert('link_new', $linkres->id, $linkres->author); $db->query("delete from links where link_author = $linkres->author and link_status='discard' and link_votes=0"); if(!empty($_POST['trackback'])) { require_once(mnminclude.'trackback.php'); $trackres = new Trackback; $trackres->url=clean_input_url($_POST['trackback']); $trackres->link_id=$linkres->id; $trackres->link=$linkres->url; //$trackres->title=$linkres->title; $trackres->author=$linkres->author; //$trackres->content=$linkres->content; $res = $trackres->send($linkres); } fork("backend/send_pingbacks.php?id=$linkres->id"); } header('Location: '. $linkres->get_permalink()); die; } function link_errors($linkres) { $error = false; // Errors if(intval($_POST['randkey']) != $linkres->randkey) { //echo '
'; print_form_submit_error(_("Clave incorrecta")); $error = true; } if($linkres->status != 'discard') { //echo '
'; print_form_submit_error(_("La historia ya está en cola").": $linkres->status"); $error = true; } if(strlen($linkres->title) < 10 || strlen($linkres->content) < 30 ) { print_form_submit_error(_("Título o texto incompletos")); $error = true; } if(get_uppercase_ratio($linkres->title) > 0.25 || get_uppercase_ratio($linkres->content) > 0.25 ) { print_form_submit_error(_("Demasiadas mayúsculas en el título o texto")); $error = true; } if(mb_strlen(html_entity_decode($linkres->title, ENT_COMPAT, 'UTF-8'), 'UTF-8') > 120 || mb_strlen(html_entity_decode($linkres->content, ENT_COMPAT, 'UTF-8'), 'UTF-8') > 550 ) { print_form_submit_error(_("Título o texto demasiado largos")); $error = true; } if(strlen($linkres->tags) < 3 ) { print_form_submit_error(_("No has puesto etiquetas")); $error = true; } if(preg_match('/.*http:\//', $linkres->title)) { //echo '
'; print_form_submit_error(_("Por favor, no pongas URLs en el título, no ofrece información")); $error = true; } if(!$linkres->category > 0) { //echo '
'; print_form_submit_error(_("Categoría no seleccionada")); $error = true; } return $error; } function print_form_submit_error($mess) { static $previous_error=false; if (!$previous_error) { do_banner_top(); echo '
' . "\n"; echo '
'."\n"; // this div MUST be closed after function call! echo '

'._('ooops!').'

'."\n"; $previous_error = true; } echo '
  '._($mess).'
'."\n"; } function report_dupe($url) { global $globals; $link = new Link; if(($found = $link->duplicates($url))) { $dupe = new Link; $dupe->id = $found; $dupe->read(); echo '

'._('noticia repetida!').'

'; echo '

'._('lo sentimos').'

'; echo '

'.$dupe->title.''; echo '

' . "\n"; echo '

'; echo ''; echo '
'. "\n"; echo '
'. "\n"; return true; } return false; } ?>