// Sacamos las extensiones permitidas para los archivos que se suben
function gettheextattachment(){
// conexion de base de datos
$conexion = Conexion::singleton_conexion();
$SQL = 'SELECT archiveextensions FROM '.SSPREFIX.'socialconfig WHERE id = 1';
$stn = $conexion -> prepare($SQL);
$stn -> execute();
$rstl = $stn -> fetchAll();
}else{
foreach ($rstl as $key){
$fileext = $key['archiveextensions'];
return $fileext;
}
}
}
function validextlist(){
// conexion de base de datos
$conexion = Conexion::singleton_conexion();
$SQL = 'SELECT archiveextensions FROM '.SSPREFIX.'socialconfig WHERE id = 1';
$stn = $conexion -> prepare($SQL);
$stn -> execute();
$rstl = $stn -> fetchAll();
}else{
foreach ($rstl as $key){
echo '<b>'.str_replace('|', ' / ', $key['archiveextensions']).'</b>'; }
}
}
function formatSizeUnits($bytes){
if ($bytes >= 1073741824)
{
}
elseif ($bytes >= 1048576)
{
}
elseif ($bytes >= 1024)
{
}
elseif ($bytes > 1)
{
$bytes = $bytes . ' bytes';
}
elseif ($bytes == 1)
{
$bytes = $bytes . ' byte';
}
else
{
$bytes = '0 bytes';
}
return $bytes;
}
// Para subir un archivo
function attachmentfiles($file,$description){
// conexion de base de datos
$conexion = Conexion::singleton_conexion();
// Primero el Año
// Ahora el Mes
// Ahora usamos la sesion del usuario para su respectiva carpeta
$theuser = $_SESSION['ssid'];
// Creamos un alfanumerico aleatorio.
$characters = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$string = '';
for ($i = 0; $i < 60; $i++) {
$string .= $characters[rand(0, strlen($characters) - 1)]; }
// Tomamos la fecha y hora con segundos
$fechaseconds = date('Y-m-d h:i:s'); $fechanormal = date('Y-m-d');
// Nuevo nombre del Archivo
$thenewname = sha1($fechaseconds.$theuser.$string);
// Obtenemos la extension
$fileext = new SplFileInfo($file);
$getextension = $fileext->getExtension();
// convertimos extension a minusculas
//comprobamos si el archivo ha subido y lo movemos a una su respectiva ruta
if ($file && move_uploaded_file($_FILES['archivo']['tmp_name'],"../attachments/".$theuser."/".$theyear."/".$themonth."/".$thenewname.".".$extension)){ }
// Creamos ruta del temporal
$temporal = "../attachments/".$theuser."/".$theyear."/".$themonth."/".$thenewname.".".$extension;
// Creamos el permalink de la publicacion
$permalink = sha1($string.$fechaseconds);
// Limitamos las publicaciones a tan solo 1000 caracteres
$postparse = substr($description, 0,1000);
// Filtramos para evitar XSS Injection
$filtro = new InputFilter();
$finalpost = $filtro->process($postparse);
// Tamaño del archivo
$filesize = $_FILES['archivo']['size'];
// Nombre del Archivo
$filename = $_FILES['archivo']['name'];
// Revisamos si el resultado es vacio para no tener que postearlo
}
}
// Hacemos el registro del Archivo
$FileAttch = 'INSERT INTO '.SSPREFIX.'attachment (ruta, nombre, usuario, fecha, ext, peso, permalink) VALUES (:ruta, :nombre, :usuario, :fecha, :ext, :peso, :permalink)';
$stnfile = $conexion -> prepare($FileAttch);
$stnfile -> bindParam(':ruta', $temporal ,PDO::PARAM_STR);
$stnfile -> bindParam(':usuario', $_SESSION['ssid'] ,PDO::PARAM_STR);
$stnfile -> bindParam(':nombre', $filename ,PDO::PARAM_INT);
$stnfile -> bindParam(':fecha', $fechaseconds ,PDO::PARAM_STR);
$stnfile -> bindParam(':ext', $extension ,PDO::PARAM_STR);
$stnfile -> bindParam(':peso', $filesize ,PDO::PARAM_STR);
$stnfile -> bindParam(':permalink', $thenewname ,PDO::PARAM_STR);
$stnfile -> execute();
$lastidfile = $conexion -> lastInsertId();
// Post con archivo
$thepostpostarchive = $lastidfile.'|'.$finalpost;
// Como es un post de archivo es 4
$tipo = 4;
$SQL = 'INSERT INTO '.SSPREFIX.'posts (post, usuario, permalink, fecha, tipo) VALUES (:post, :usuario, :permalink, :fecha, :tipo)';
$stn = $conexion -> prepare($SQL);
$stn -> bindParam(':post', $thepostpostarchive ,PDO::PARAM_STR);
$stn -> bindParam(':usuario', $_SESSION['ssid'] ,PDO::PARAM_INT);
$stn -> bindParam(':permalink', $permalink ,PDO::PARAM_STR);
$stn -> bindParam(':fecha', $fechaseconds ,PDO::PARAM_STR);
$stn -> bindParam(':tipo', $tipo ,PDO::PARAM_INT);
$stn -> execute();
$lastid = $conexion -> lastInsertId();
// imagen de perfil
$profileimg = userprofile($_SESSION['ssid']);
// Fecha
$fechastronger = fechastring($fechanormal,$permalink);
echo'
<div id="post-public'.$lastid.'" class="box box-widget">
<div class="box-header with-border">
<div class="user-block">
<img class="img-circle" src="'.$profileimg.'" alt="'.gettheusernamepost().'">
<span class="username"><a href="profile.php?leanserwebmaster">'.gettheusernamepost().'</a></span>
'.$fechastronger.'
</div>
<!-- /.user-block -->
<div class="box-tools">
<button data-post="'.$lastid.'" class="eliminarthispost btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
<!-- /.box-tools -->
</div>
<!-- /.box-header -->
<div class="box-body">
<!-- post text -->';
$postexplode = explode('|', $thepostpostarchive); getattachblock($postexplode[0],$postexplode[1]);
echo'<!-- Social sharing buttons -->
<button id="liker'.$lastid.'" type="button" data-target="'.$lastid.'" onclick="thelikeloadtimeclick('.$lastid.');" class="btn btn-default btn-xs"><i class="fa fa-thumbs-o-up"></i> Me gusta</button>
<span id="likecomment'.$lastid.'" class="pull-right text-muted">
</span>
</div>
<!-- /.box-footer -->
<div class="box-footer">
<form class="commentfrm" data-form="'.$lastid.'" id="commentfrm'.$lastid.'">
<img id="mypiccomment" class="img-responsive img-circle img-sm" src="'.$profileimg.'">
<!-- .img-push is used to add margin to elements next to floating images -->
<div class="img-push">
<input type="text" class="form-control input-sm" name="comentario" placeholder="Comentar...">
</div>
</form>
</div>
<!-- /.box-footer -->
<!-- /.box-body -->
<div id="box-commets-body-'.$lastid.'" class="box-footer box-comments">
</div>
</div>
';
$conexion = '';
}
function downloadarchive($permalink){
// conexion de base de datos
$conexion = Conexion::singleton_conexion();
$SQL = 'SELECT * FROM '.SSPREFIX.'attachment WHERE permalink = :permalink LIMIT 1';
$stn = $conexion -> prepare($SQL);
$stn -> bindParam(':permalink', $permalink ,PDO::PARAM_STR);
$stn -> execute();
$rstl = $stn -> fetchAll();
}else{
foreach ($rstl as $key){
$nombre = $key['nombre'];
}
}
header("Content-type: application/octet-stream"); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=\"$nombre\"\n"); readfile($ruta);
}
// Tomamos los ultimos 6 post
function takepostperpermalink($permalink){
// conexion de base de datos
$conexion = Conexion::singleton_conexion();
$SQL = 'SELECT '.SSPREFIX.'usuarios.id AS userid, '.SSPREFIX.'posts.tipo AS posttipo, '.SSPREFIX.'posts.id AS postingid, '.SSPREFIX.'posts.post, '.SSPREFIX.'posts.permalink, '.SSPREFIX.'posts.fecha, '.SSPREFIX.'usuarios.nombre, '.SSPREFIX.'usuarios.apellido, '.SSPREFIX.'usuarios.permalink AS userperma FROM '.SSPREFIX.'posts INNER JOIN '.SSPREFIX.'usuarios ON '.SSPREFIX.'usuarios.id = '.SSPREFIX.'posts.usuario WHERE '.SSPREFIX.'posts.permalink = :permalink ORDER BY '.SSPREFIX.'posts.fecha DESC LIMIT 1';
$stn = $conexion -> prepare($SQL);
$stn -> bindParam(':permalink' , $permalink, PDO::PARAM_INT);
$stn -> execute();
$rstl = $stn -> fetchAll();
# code...
}else{
foreach ($rstl as $key){
// imagen de perfil
$profileimg = userprofile($key['userid']);
// Fecha
$fecha = fechastring($key['fecha'],$key['permalink']);
// Imagen de perfil en el post
$perfilactual = userprofile($_SESSION['ssid']);
echo'
<div id="post-public'.$key['postingid'].'" class="box box-widget">
<div class="box-header with-border">
<div class="user-block">
<img class="img-circle" src="'.$profileimg.'" alt="'.$key['nombre'].' '.$key['apellido'].'">
<span class="username"><a href="profile.php?'.$key['userperma'].'">'.$key['nombre'].' '.$key['apellido'].'</a></span>
'.$fecha.'
</div>
<!-- /.user-block -->
</div>
<!-- /.box-header -->
<div class="box-body">
<!-- post text -->';
if ($key['posttipo'] == 1){
profileimageposttake($key['post']);
}elseif ($key['posttipo'] == 3) {
portadaimageposttake($key['post']);
}elseif ($key['posttipo'] == 4) {
$postexplode = explode('|', $key['post']); getattachblock($postexplode[0],$postexplode[1]);
}else{
echo'<p>'.emoticons($key['post']).'</p>';
}
echo'<!-- Social sharing buttons -->
';
checklike($key['postingid']);
echo'
<span id="likecomment'.$key['postingid'].'" class="pull-right text-muted">
';
checklikeandcomments($key['postingid']);
echo'
</span>
</div>
<!-- /.box-footer -->
<div class="box-footer">
<form class="commentfrm" data-form="'.$key['postingid'].'" id="commentfrm'.$key['postingid'].'">
<img id="mypiccomment" class="img-responsive img-circle img-sm" src="'.$perfilactual.'">
<!-- .img-push is used to add margin to elements next to floating images -->
<div class="img-push">
<input type="text" class="form-control input-sm" name="comentario" placeholder="Comentar...">
</div>
</form>
</div>
<!-- /.box-footer -->
<!-- /.box-body -->
<div id="box-commets-body-'.$key['postingid'].'" class="box-footer box-comments">';
commentsajx($key['postingid'],$key['permalink']);
echo'</div>
</div>
';
}
}
$conexion = '';
}