File: //home/httpd/mech_ftp/baretube.com/admin/modules/mbtubeapi/mbtubeapi.php
<?php
ignore_user_abort();
ini_set('max_execution_time', 86400);
include('functions.api.php');
if ($argv[1]) {
foreach ($argv as $arg) {
$e = explode("=", $arg);
if (count($e) == 2) {
$_POST[$e[0]] = $e[1];
} else {
$_POST[$e[0]] = 0;
}
}
}
if (!$argv[1]) {
require "../../header.php";
} else {
require "../../db.php";
//running from cli
$videos = getMBJson($_POST['feed']);
foreach ($videos as $arr) {
$arr = mysql_real_escape_array($arr);
$bad = array("\r", "\n", "\t");
$arr[embed] = trim(str_replace($bad, "", $arr[embed]));
$check = dbQuery("SELECT record_num FROM content WHERE embed LIKE '%$arr[embed]%'",false);
if (count($check) < 1) {
if (dbQuery("INSERT INTO content (length, title, description, keywords, date_added, approved, embed, submitter, paysite) VALUES ('$arr[lengthsec]','$arr[title]', '$arr[title]', '$arr[keywords]', NOW(), 2, '$arr[embed]','$_POST[submitter]', '$_POST[paysite]')")) {
$insert = mysqli_insert_id($dbconn);
$file = file_get_contents($arr[thumb]);
@mkdir($thumb_path . '/embedded');
file_put_contents($thumb_path . '/embedded/' . $insert . '.jpg', $file);
dbQuery("INSERT INTO content_views (content,views) VALUES ('$insert',0)");
if (filesize($thumb_path . '/embedded/' . $insert . '.jpg') > 48) {
$counter++;
$thisThumb = $thumb_path . '/embedded/' . $insert . '.jpg';
if(cephUploadObject($thisThumb,str_replace("$basepath/media/","",$thisThumb))) {
if($ceph_delete_local) {
@unlink($thisThumb);
}
}
} else {
dbQuery("DELETE FROM content WHERE record_num = '$insert'");
dbQuery("DELETE FROM content_views WHERE content = '$insert'");
$errors++;
}
if ($arr[keywords]) {
$parray = explode(',', $arr[keywords]);
foreach ($parray as $p) {
$p = trim($p);
$rresult = dbQuery("SELECT record_num FROM niches WHERE name LIKE '$p' OR (csv_match != '' AND csv_match LIKE '%$p%')",false);
if (count($rresult) > 0) {
$rrow = $rresult[0];
dbQuery("INSERT INTO content_niches (niche, content) VALUES ($rrow[record_num], $insert)");
unset($rrow, $rresult);
}
}
}
if ($arr[channels]) {
$parray = explode(',', $arr[channels]);
foreach ($parray as $p) {
$p = trim($p);
$rresult = dbQuery("SELECT record_num FROM niches WHERE name LIKE '$p' OR (csv_match != '' AND csv_match LIKE '%$p%')",false);
if (count($rresult) > 0) {
$rrow = $rresult[0];
dbQuery("INSERT INTO content_niches (niche, content) VALUES ($rrow[record_num], $insert)");
unset($rrow, $rresult);
}
}
}
if ($arr[models]) {
$parray = explode(',', $arr[models]);
foreach ($parray as $p) {
$p = trim($p);
$rresult = dbQuery("SELECT record_num FROM pornstars WHERE name LIKE '$p'",false);
if (count($rresult) > 0) {
$rrow = $rresult[0];
dbQuery("INSERT INTO content_pornstars (pornstar, content) VALUES ($rrow[record_num], $insert)");
unset($rrow, $rresult);
}
}
}
}
}
}
$outputMsg = "Done";
}
if ($_POST['list']) {
foreach ($_POST['list'] as $i) {
if (is_numeric($i)) {
dbQuery("DELETE FROM mb_api_endpoints WHERE record_num = '$i'");
}
}
}
if ($_POST['name'] && $_POST['endpoint'] && $_POST['amount']) {
$_POST = mysql_real_escape_array($_POST);
dbQuery("INSERT INTO mb_api_endpoints SET name = '$_POST[name]', endpoint = '$_POST[endpoint]', amount = '$_POST[amount]', mode = '$_POST[mode]', query = '$_POST[query]'");
}
?>
<div class="content-page">
<div class="header-area">
<div class="breadcrumbs">
<a href="index.php">Admin Home</a>
<span><a href="mbtubeapi.php">MB Tube Api</a></span>
</div>
</div>
<div class="content-outer">
<h2>MB<strong>Tube Api</strong></h2>
<div class="notification info">This page lets you add feeds from other mechbunny-based tube sites which have API endpoints enabled. Mechbunny API is available from version 5.0.12 and up, but can also be installed on earlier versions manually. API Endpoint is typically http://www.domain.com/api/ (with the trailing slash). You can check if a site has it's api enabled by visiting http://www.domain.com/api/.</div>
<div class="notification info">
<strong>This script must be executed from cron by using the following command line in crontab to run at whatever interval you like:</strong><br />
<em>cd <? echo $basepath; ?>/admin/modules/mbtubeapi/; <? echo $php_path; ?> mbtubeapi.php paysite=X submitter=Y feed=Z</em><Br />
(X is id number of paysite, Y is id number of user that "submitted" the video, Z is the ID number of the feed)
</div>
<? if ($outputMsg) { ?><div class="notification success"><? echo $outputMsg; ?></div><? } ?>
<div class="content-inner">
<form method="POST" action="" enctype="multipart/form-data" class="form" novalidate autocomplete="off">
<table class="pagetable">
<thead>
<tr>
<th colspan="2">Add Endpoint</th>
</tr>
</thead>
<tbody>
<tr>
<td>Site Name</td>
<td><input name="name" type="text" placeholder="Mechbunny Tube Site" /></td>
</tr>
<tr>
<td>EndPoint URL</td>
<td><input name="endpoint" type="text" placeholder="http://www.domain.com/api/" /></td>
</tr>
<tr>
<td>Mode</td>
<td>
<select name="mode">
<option value="newest">Newest</option>
<option value="search">Search</option>
</select>
</td>
</tr>
<tr>
<td>Search Query</td>
<td><input name="query" type="text" placeholder="Amateur" /></td>
</tr>
<tr>
<td>Videos To Fetch</td>
<td><input name="amount" type="number" value="1000" min="1" class="tiny" /></td>
</tr>
<tr class="item submit">
<td colspan="2">
<button type="submit" class="btn action-save">Save</button>
</td>
</tr>
</tbody>
</table>
</form>
<form method="POST" action="" class="form" novalidate autocomplete="off">
<?
$page = (isset($_GET['page']) && is_numeric($_GET['page'])) ? (int) $_GET['page'] : 1;
$max_results = (isset($_GET['setmax']) && $_GET['setmax'] > 0) ? (int) $_GET['setmax'] : 100;
$from = ($page * $max_results) - $max_results;
$total_results = dbQuery("SELECT COUNT(*) AS `count` FROM mb_api_endpoints",false);
$total_results = $total_results[0];
$result = dbQuery("SELECT * FROM mb_api_endpoints ORDER BY name ASC LIMIT $from, $max_results",false);
$total_pages = ceil($total_results['count'] / $max_results);
?>
<table class="pagetable">
<thead>
<tr>
<th>Name</th>
<th>Endpoint</th>
<th>ID</th>
<th>Mode</th>
<th>Query</th>
<th>Amount</th>
<th style="width:50px">
<label for="check-select-all-1" class="checkbox">
<input type="checkbox" name="select_all" value="1" data-items="list[]" id="check-select-all-1">
<i></i>
</label>
</th>
</tr>
</thead>
<tbody>
<? if (count($result) == 0) { ?>
<tr><td colspan="7"><div class="notification alert">No entries found</div></td></tr>
<? } else { ?>
<? foreach($result as $row) { ?>
<tr>
<td><? echo $row['name']; ?></td>
<td><? echo $row['endpoint']; ?></td>
<td><? echo $row['record_num']; ?></td>
<td><? echo $row['mode']; ?></td>
<td><? echo $row['query']; ?></td>
<td><? echo $row['amount']; ?></td>
<td>
<label class="checkbox">
<input type="checkbox" name="list[]" value="<? echo $row['record_num']; ?>" id="ids-<? echo $row['record_num']; ?>"><i></i>
</label>
</td>
</tr>
<? } ?>
<? } ?>
<tr class="item submit">
<td colspan="7">
<? if (count($result) > 0) { ?>
<button type="submit" class="btn action-delete">Delete Selected</button>
<? } ?>
</td>
</tr>
</tbody>
</table>
</form>
<div id="adminPagination"><? echo showAdminPagination($total_pages); ?></div>
</div>
</div>
</div>
<? require "../../footer.php"; ?>