function promote_from_subs($destination, $hours, $min_karma, $min_votes) { global $db; echo "Promote to main: {$destination}\n"; $res = $db->get_results("select sub_statuses.*, link_url, link_karma, link_votes from sub_statuses, subs, links where date > date_sub(now(), interval {$hours} hour) and status = 'published' and link_karma >= {$min_karma} and sub_statuses.id = origen and subs.id = sub_statuses.id and subs.created_from = {$destination} and not subs.private and not subs.nsfw and sub_statuses.id not in (select src from subs_copy where dst={$destination}) and {$destination} not in (select id from sub_statuses as t where t.link=sub_statuses.link) and link_id = sub_statuses.link and link_votes >= {$min_votes}"); foreach ($res as $status) { // If there are more of the same sub in queue or published, multiply minimums $promoted = $db->get_var("select count(*) from sub_statuses where id = {$destination} and origen = {$status->id} and date > date_sub(now(), interval {$hours} hour)"); echo "PROMOTED {$status->id} -> {$destination}: {$promoted}\n"; if ($promoted > 0 && $status->link_karma < min(4, $promoted * 0.5 + 1) * $min_karma && $status->link_votes < min(4, $promoted * 0.5 + 1) * $min_votes) { echo "Already in main {$promoted}, doesn't have minimums, {$status->link_url}\n"; continue; } $properties = SitesMgr::get_extended_properties($status->id); if (!empty($properties['no_link']) && empty($status->link_url)) { echo "NO LINK, {$status->id}\n"; // continue; } if (!empty($status->link_url) && Link::duplicates($status->link_url, $destination)) { echo "Duplicated in destination, {$status->link_url}\n"; continue; } $status->id = $destination; $status->status = 'queued'; echo "--->\n"; if (!DEBUG) { SitesMgr::store($status); } } }
function do_posts($link) { global $globals; $info = SitesMgr::get_info(); $properties = SitesMgr::get_extended_properties(); syslog(LOG_INFO, "Meneame, posting {$link->uri}"); $url = $link->get_permalink($info->sub); echo "Posting {$url}: " . $globals['server_name'] . "\n"; // NEW format $image = false; if ($link->has_thumb()) { $media = $link->get_media(); if ($media && file_exists($media->pathname())) { $image = $media->pathname(); } } if ($globals['url_shortener']) { $short_url = $link->get_short_permalink(); } else { $short_url = $url; } if (!empty($properties['twitter_token']) && !empty($properties['twitter_token_secret']) && !empty($properties['twitter_consumer_key']) && !empty($properties['twitter_consumer_secret'])) { $r = false; $tries = 0; while (!$r && $tries < 4) { $r = twitter_post($properties, $link->title, $url, $image); $tries++; if (!$r) { sleep(4); } } } if (!empty($properties['facebook_token']) && !empty($properties['facebook_key']) && !empty($properties['facebook_secret'])) { $r = false; $tries = 0; while (!$r && $tries < 4) { $r = facebook_post($properties, $link); $tries++; if (!$r) { sleep(4); } } } /* if ($globals['pubsub']) { pubsub_post(); } */ }
function do_sub_message_right() { global $db, $globals; if ($globals['mobile'] || !$globals['submnm']) { return; } $properties = SitesMgr::get_extended_properties(); if (empty($properties['message'])) { return; } $message = LCPBase::html($properties['message']); Haanga::Load('message_right.html', compact('message')); return; }
#! /usr/bin/env php <?php // Check which hostname server we run for, for example: mnm, emnm, etc. $site_name = $argv[2]; include dirname(__FILE__) . '/../www/config.php'; include mnminclude . 'external_post.php'; $my_id = SitesMgr::get_id($site_name); if (!$my_id > 0) { syslog(LOG_INFO, "Meneame, " . basename(__FILE__) . " site not found {$site_name}"); echo "No site id found\n"; die; } SitesMgr::__init($my_id); syslog(LOG_INFO, "Meneame, running " . basename(__FILE__) . " for {$site_name}"); $info = SitesMgr::get_info(); $properties = SitesMgr::get_extended_properties(); if (intval($argv[1]) > 0) { $hours = intval($argv[1]); } else { $hours = 1; } $key = "post_best_comment_{$my_id}"; $previous = Annotation::get_text($key); if ($previous) { $extra = "AND comment_id not in ({$previous})"; } $now = intval(time() / 60) * 60; $coef = 0.8; $min_karma = $globals['comment_highlight_karma'] * 2; $min_value = $globals['comment_highlight_karma']; $min_length = 400;
function do_save($link) { global $dblang, $globals, $current_user, $db; $link->status = $link->sub_status; $site_properties = SitesMgr::get_extended_properties(); // Store previous value for the log $link_old = new stdClass(); $link_old->url = $link->url; $link_old->title = $link->title; $link_old->content = $link->content; $link_old->tags = $link->tags; $link_old->status = $link->status; $link_old->sub_id = $link->sub_id; $link->read_content_type_buttons($_POST['type']); $link->sub_id = intval($_POST['sub_id']); if ($link->sub_id != $link_old->sub_id) { $link->sub_changed = true; // To force to delete old statuses with another origin } if ($current_user->admin || $current_user->user_level == 'blogger' || SitesMgr::is_owner()) { if (!empty($_POST['url'])) { $link->url = clean_input_url($_POST['url']); } if ($_POST['thumb_delete']) { $link->delete_thumb(); } if ($_POST['uri_update']) { $link->get_uri(); } if ($_POST['thumb_get']) { $link->get_thumb(); } elseif (!empty($_POST['thumb_url'])) { $url = clean_input_url($_POST['thumb_url']); $link->get_thumb(false, $url); } } $link->title = $_POST['title']; $link->content = $_POST['bodytext']; $link->tags = tags_normalize_string($_POST['tags']); $errors = link_edit_errors($link); // change the status if ($_POST['status'] != $link->status && ($_POST['status'] == 'autodiscard' || $current_user->admin || SitesMgr::is_owner()) && preg_match('/^[a-z]{4,}$/', $_POST['status']) && (!$link->is_discarded() || $current_user->admin || SitesMgr::is_owner())) { if (preg_match('/discard|abuse|duplicated|autodiscard/', $_POST['status'])) { // Insert a log entry if the link has been manually discarded $insert_discard_log = true; } $link->status = $_POST['status']; } if (!$errors) { if (empty($link->uri)) { $link->get_uri(); } // Check the blog_id $blog_id = Blog::find_blog($link->url, $link->id); if ($blog_id > 0 && $blog_id != $link->blog) { $link->blog = $blog_id; } $db->transaction(); $link->store(); // Disabled table tags // tags_insert_string($link->id, $dblang, $link->tags, $link->date); // Insert edit log/event if the link it's newer than 15 days if ($globals['now'] - $link->date < 86400 * 15) { if ($insert_discard_log) { // Insert always a link and discard event if the status has been changed to discard Log::insert('link_discard', $link->id, $current_user->user_id); if ($link->author == $current_user->user_id) { // Don't save edit log if it's discarded by an admin Log::insert('link_edit', $link->id, $current_user->user_id); } } elseif ($link->votes > 0) { Log::conditional_insert('link_edit', $link->id, $current_user->user_id, 60, serialize($link_old)); } } // Check this one is a draft, allows the user to save and send it to the queue if ($link->votes == 0 && $link->status != 'queued' && $link->author == $current_user->user_id) { $link->enqueue(); } $db->commit(); } $link->read(); $link->permalink = $link->get_permalink(); Haanga::Load('link/edit_result.html', compact('link', 'errors')); }
function save_sub($id, &$errors) { global $current_user, $db; // Double check $owner = intval($_POST['owner']); if (!SitesMgr::can_edit($id)) { array_push($errors, _('usuario no autorizado a editar')); return false; } $site = SitesMgr::get_info(); $extended = SitesMgr::get_extended_properties($id); if ($_POST['created_from'] != $site->id) { array_push($errors, _('sitio erróneo')); } if ($owner != $current_user->user_id && !$current_user->admin) { array_push($errors, _('propietario erróneo')); } $name = mb_substr(clean_input_string($_POST['name']), 0, 12); if (mb_strlen($name) < 3 || !preg_match('/^\\p{L}[\\p{L}\\d_]+$/u', $name)) { array_push($errors, _('nombre erróneo') . ' ' . $_POST['name']); } $name_long = mb_substr(clean_text($_POST['name_long']), 0, 40); if (mb_strlen($name_long) < 6) { array_push($errors, _('título erróneo')); } $name = $db->escape($name); $name_long = $db->escape($name_long); if ($db->get_var("select count(*) from subs where name = '{$name}' and id != {$id}") > 0) { array_push($errors, _('nombre duplicado')); } $page_mode = $db->escape($_POST['page_mode']); if ($current_user->admin) { $enabled = intval($_POST['enabled']); $allow_main_link = intval($_POST['allow_main_link']); } else { // Keep the values $enabled = $site->enabled; $allow_main_link = $site->allow_main_link; $_POST['post_html'] = $extended['post_html']; } $nsfw = intval($_POST['nsfw']); $private = intval($_POST['private']); // Check the extended info foreach (array('no_link', 'no_anti_spam', 'allow_local_links', 'intro_max_len', 'intro_min_len') as $k) { if (isset($_POST[$k]) && $_POST[$k] !== '') { $_POST[$k] = intval($_POST[$k]); } } if ($_POST['intro_max_len'] > 5000) { $_POST['intro_max_len'] = 5000; } if (empty($errors)) { $db->transaction(); if ($id > 0) { $r = $db->query("update subs set owner = {$owner}, enabled = {$enabled}, allow_main_link = {$allow_main_link}, nsfw = {$nsfw}, name = '{$name}', name_long = '{$name_long}', private = {$private}, page_mode = '{$page_mode}' where id = {$id}"); } else { $r = $db->query("insert into subs (created_from, owner, nsfw, name, name_long, sub, private) values ({$site->id}, {$owner}, {$nsfw}, '{$name}', '{$name_long}', 1, {$private})"); $id = $db->insert_id; } if ($r && $id > 0) { // Copy values from first site $r = $db->query("update subs as a join subs as b on a.id = {$id} and b.id={$site->id} set a.server_name = b.server_name, a.base_url = b.base_url"); // Update copy_from if ($current_user->admin) { sub_copy_from($id, $_POST['copy_from']); } // Update colors $color_regex = '/^#[a-f0-9]{6}/i'; if (preg_match($color_regex, $_POST['color1'])) { $color1 = $db->escape($_POST['color1']); } else { $color1 = ''; } if (preg_match($color_regex, $_POST['color2'])) { $color2 = $db->escape($_POST['color2']); } else { $color2 = ''; } $db->query("update subs set color1 = '{$color1}', color2 = '{$color2}' where id = {$id}"); } if ($r && $id > 0) { SitesMgr::store_extended_properties($id, $_POST); $db->commit(); store_image($id); return $id; } else { array_push($errors, _('error actualizando la base de datos')); $db->rollback(); } } return false; }
function check_field_errors() { global $globals; $errors = array(); if (!$this->sub_id > 0) { $errors[] = _("sub no seleccionado"); $site_id = SitesMgr::my_id(); } else { $site_id = $this->sub_id; } $properties = SitesMgr::get_extended_properties($site_id); if (empty($this->url) && empty($properties['no_link'])) { $errors[] = _("falta url enlace"); } // Filter content and title // It also deletes punctuaction marks at the end $this->title = clean_text(preg_replace('/(\\w) *[.,] *$/', "\$1", $this->title), 50, true, 120); if ($properties['allow_paragraphs']) { $replace_nl = false; } else { $replace_nl = true; } $this->content = clean_text_with_tags($this->content, 0, $replace_nl, $properties['intro_max_len']); if (mb_strlen($this->title) < 8) { $errors[] = _("título incompleto"); } if (get_uppercase_ratio($this->title) > 0.5) { $errors[] = "demasiadas mayúsculas en el título"; } /* The length is already constrained in clean_text() if(mb_strlen(html_entity_decode($this->title, ENT_COMPAT, 'UTF-8'), 'UTF-8') > 120) { $errors[] = ("título demasiado largo"); } */ if ($properties['intro_max_len'] > 0 && $properties['intro_min_len'] > 0 && mb_strlen($this->content) < $properties['intro_min_len']) { $errors[] = _("texto incompleto"); } if (get_uppercase_ratio($this->content) > 0.3) { $errors[] = "demasiadas mayúsculas en el texto"; } /* Already constrained in clean_text_with_tags() if( $properties['intro_max_len'] > 0 && mb_strlen(html_entity_decode($this->content, ENT_COMPAT, 'UTF-8'), 'UTF-8') > $properties['intro_max_len'] ) { $errors[] = ("texto demasiado largo"); } */ if (strlen($this->tags) < 3) { $errors[] = "no has puesto etiquetas"; } if (preg_match('/.*http:\\//', $this->title)) { $errors[] = "no pongas URLs en el título, no ofrece información"; } return $errors; }
if ($_POST['created_from']) { $id = save_sub($id, $errors); $sub = SitesMgr::get_info($id, true); if ($id && empty($errors)) { header("Location: " . $globals['base_url_general'] . "m/{$sub->name}/subedit"); die; } if (!$id) { $sub = (object) $_POST; // Copy the data for the form, in case it failed to store } } } if ($id > 0) { $globals['submnm_info'] = $sub = SitesMgr::get_info($id); $extended = SitesMgr::get_extended_properties($id); } if ($current_user->admin) { $candidates_from = $db->get_results("select id, name from subs where owner = 0 and id not in (select src from subs_copy where dst = {$id})"); $copy_from = $db->get_results("select id, name from subs, subs_copy where dst = {$id} and id = src"); } else { $copy_from = $candidates_from = false; } do_header(_("editar sub")); echo '<div id="singlewrap">' . "\n"; Haanga::Load('sub_edit.html', compact('sub', 'extended', 'errors', 'site', 'candidates_from', 'copy_from')); echo "</div>" . "\n"; do_footer(); function save_sub($id, &$errors) { global $globals, $current_user, $db;