File: /home/httpd/html/baretube.com.new/admin/models_bulk_add.php
<?php
ignore_user_abort();
ini_set('max_execution_time', 86400);
require "db.php";
if (isset($_POST['dump'])) {
unset($arr);
$selectsAmount = (int)$_POST['selectsCounter'];
$arr = array_filter(explode("\n", $_POST['dump']), 'strlen');
foreach ($arr as $key => $value) {
$k = explode('|', $value);
for ($i = 1; $i <= $selectsAmount; $i++) {
if ($_POST['select' . $i]) {
$import[$key][$_POST['select' . $i]] = $k[$i - 1];
}
}
}
$models_fields = getFieldValues('models');
foreach ($models_fields as &$_field) {
$_field = array_flip($field);
}
reset($models_fields);
$counter = 0;
$errors = 0;
$updated = 0;
foreach ($import as $item) {
if ($item['name'] != "") {
$costom_f = array();
foreach ($item as $key => $val){
if(stripos($key, 'custom_') !== false){
$costom_f[str_replace('custom_', '', $key)] = $val;
}
}
$bad = array("\r","\n","\t");
if (!is_array(dbQuery("SELECT * FROM `pornstars` WHERE `name` LIKE '" . mysqli_real_escape_string($dbconn, str_replace($bad,"",trim($item['name']))) . "' LIMIT 1", false))) {
$item = array_map_array('trim', $item);
$model_id = dbInsert('pornstars', array(
'name' => $item['name'],
'aka' => $item['aka'],
'dob' => $item['dob'],
'height' => $item['height'],
'weight' => $item['weight'],
'measurements' => $item['measurements'],
'hair' => isset($models_fields['hair_colors'][$item['hair']]) ? $models_fields['hair_colors'][$item['hair']] : $item['hair'],
'eyes' => isset($models_fields['eyes_colors'][$item['eyes']]) ? $models_fields['eyes_colors'][$item['eyes']] : $item['eyes'],
'ethnicity' => isset($models_fields['ethnicities'][$item['ethnicity']]) ? $models_fields['ethnicities'][$item['ethnicity']] : $item['ethnicity'],
'official_site_name' => $item['official_site_name'],
'official_site_url' => $item['official_site_url'],
'biography' => $item['biography'],
'custom' => serialize($costom_f),
));
if (is_numeric($model_id)) {
if ($item['thumbnail']) {
$thumbData = file_get_contents($item['thumbnail']);
if (strlen($thumbData) > 1024) { // prevent downloading too small/LQ images
if (file_put_contents("$basepath/media/misc/model$model_id.jpg", $thumbData)) {
dbQuery("UPDATE `pornstars` SET `thumb` = 'model$model_id.jpg' WHERE `record_num` = '$model_id'");
if (is_numeric($_POST['resizeImageWidth']) && is_numeric($_POST['resizeImageHeight'])) {
_mogrifyImageThumbnail("$basepath/media/misc/model$model_id.jpg", $_POST['resizeImageWidth'], $_POST['resizeImageHeight']);
}
}
}
}
$counter++;
} else {
$errors++;
}
} else {
$item = array_map_array('trim', $item);
$model_data = dbQuery("SELECT * FROM `pornstars` WHERE `name` LIKE '" . mysqli_real_escape_string($dbconn, str_replace($bad,"",trim($item['name']))) . "' LIMIT 1", false);
$model_id = $model_data[0]['record_num'];
$actualCustom = unserialize($model_data[0]['custom']);
$newCustom = array();
foreach ($custom_pornstar_fields as $key => $val){
if($item['custom_'.$key] != $actualCustom[$key] && $item['custom_'.$key] != ''){
$newCustom[$key] = $item['custom_'.$key];
} else {
if($actualCustom[$key] != ''){
$newCustom[$key] = $actualCustom[$key];
} else {
$newCustom[$key] = '';
}
}
}
$updateFields = array();
foreach ($item as $key => $value) {
if(stripos($key, 'custom_') === false){
if($value && $value != ''){
$updateFields[$key] = $value;
}
}
}
$updateFields['custom'] = serialize($newCustom);
$buildSql = array();
foreach($updateFields as $key => $val){
$buildSql[] = "`$key` = '".mysqli_real_escape_string($dblink, $val)."'";
}
$buildSql = implode(', ', $buildSql);
dbQuery("UPDATE pornstars SET $buildSql WHERE record_num = '$model_id'", false);
if (is_numeric($model_id)) {
if ($item['thumbnail']) {
$thumbData = file_get_contents($item['thumbnail']);
if (strlen($thumbData) > 1024) { // prevent downloading too small/LQ images
if (file_put_contents("$basepath/media/misc/model$model_id.jpg", $thumbData)) {
dbQuery("UPDATE `pornstars` SET `thumb` = 'model$model_id.jpg' WHERE `record_num` = '$model_id'");
if (is_numeric($_POST['resizeImageWidth']) && is_numeric($_POST['resizeImageHeight'])) {
_mogrifyImageThumbnail("$basepath/media/misc/model$model_id.jpg", $_POST['resizeImageWidth'], $_POST['resizeImageHeight']);
}
}
}
}
$updated++;
} else {
$errors++;
}
}
}
}
setMessage("$counter models were added. $errors models were not added. $updated models were updated.");
header("Location: $_SERVER[REQUEST_URI]");
exit();
}
?>
<? require "header.php"; ?>
<div class="content-page">
<div class="header-area">
<div class="breadcrumbs">
<a href="index.php">Admin Home</a>
<span><a href="models_bulk_add.php">Models CSV Import</a></span>
</div>
</div>
<div class="content-outer">
<h2>CSV<strong>Models</strong></h2>
<?php if (getMessages(false)) { ?>
<?php echo getMessages(); ?>
<?php } else { ?>
<div class="notification info">
<div>Imports must be delimited by | (aka. pipes) only!</div>
<div>Please note: Make sure you don't accidently put any linebreaks, as it will produce undesirable results with your import!</div>
</div>
<?php } ?>
<div class="content-inner">
<form method="POST" action="" class="form" novalidate autocomplete="off">
<table class="pagetable">
<tbody>
<tr>
<td>Import Format</td>
<td>
<div class="row columnized-input" id="selectFields">
<?php for ($i = 1; $i <= 12; $i++) { ?>
<div class="col-xs-12 col-sm-4 col select-field" data-id="<? echo $i; ?>">
<span class="prefix"><?php echo $i; ?></span>
<select name="select<?php echo $i; ?>">
<option value="" selected="selected">-</option>
<option value="name">name</option>
<option value="dob">dob</option>
<option value="aka">aka</option>
<option value="height">height</option>
<option value="weight">weight</option>
<option value="measurements">measurements</option>
<option value="hair">hair</option>
<option value="eyes">eyes</option>
<option value="ethnicity">ethnicity</option>
<option value="official_site_name">official_site_name</option>
<option value="official_site_url">official_site_url</option>
<option value="biography">biography</option>
<option value="thumbnail">thumbnail</option>
<? foreach($custom_pornstar_fields as $key => $val){ ?>
<option value="custom_<? echo $key; ?>"><? echo $key; ?></option>
<? } ?>
</select>
</div>
<?php } ?>
</div>
</td>
</tr>
<tr>
<td><input type="hidden" name="selectsCounter" id="selectsCounter" value="12"></td>
<td>
<a href="#" id="addNewField">Add Custom Field</a>
</td>
</tr>
<script type="text/javascript">
$(document).ready(function(){
$('#addNewField').click(function(e){
e.preventDefault();
var lastSelectId = parseInt($('#selectFields .select-field').last().data('id')) + 1;
$('#selectsCounter').val(parseInt($('#selectsCounter').val())+1);
$('#selectFields').append($('<div class="col-xs-12 col-sm-4 col select-field" data-id="' + lastSelectId + '"></div>').load('<? echo $basehttp; ?>/admin/ajax/ajax.csvFields.php?id=' + lastSelectId));
});
});
</script>
<tr>
<td>Resize Thumbs:</td>
<td>
<input type="number" name="resizeImageWidth" value="" class="tiny" min="0" placeholder="width" />
<span class="suffix">px</span>
x
<input type="number" name="resizeImageHeight" value="" class="tiny" min="0" placeholder="height" />
<span class="suffix">px</span>
<p class="hint">Leave blank to skip resizing</p>
</td>
</tr>
<tr>
<td>Dump:</td>
<td><textarea name="dump" rows="10" required></textarea></td>
</tr>
<tr class="item submit">
<td colspan="2">
<button type="submit" class="btn action-save">Submit</button>
</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</div>
<?php require "footer.php"; ?>