Foros del Web » Programando para Internet » PHP »

Creación de un muro para una red social

Estas en el tema de Creación de un muro para una red social en el foro de PHP en Foros del Web. Hola, Mirad, tengo un problema, estoy haciendo una red social, y en este mismo momento estoy en el paso de la creación del muro de ...
  #1 (permalink)  
Antiguo 06/03/2010, 11:31
 
Fecha de Ingreso: enero-2010
Mensajes: 14
Antigüedad: 14 años, 2 meses
Puntos: 0
Exclamación Creación de un muro para una red social

Hola,

Mirad, tengo un problema, estoy haciendo una red social, y en este mismo momento estoy en el paso de la creación del muro de mensajes. Tengo un problema, tengo todo el código perfectamente, CSS + PHP + AJAX + jQuery + MySQL, lo tengo todo hecho. Vale, por el momento se envían las notas y se publican perfectamente, pero ahora viene el problema, no hay manera de que el sistema recoja el nombre de la persona (nombre real, no nombre de usuario) que a enviado la nota, y lo inserte en la base de datos, y por lo tanto, no se visualiza quien lo publicó. Por ejemplo queda así:

Cita:
: Hola! Esto es una nota :)
Cuando tendría que quedar por ejemplo así:

Cita:
Juan Francisco: Hola! Esto es una nota :)
Les dejo el código de los archivos para que lo revisen a ver que es lo que puede estar fallando.

Archivo "sendpost.php":

Código:
<?php

require('connect.php');

// 'username' => The username in DB
// 'realname' => The real name
// This get the data of the DB	
if (defined('SEEING_PROFILE')) {
	global $_PROFILE;
	$userInfo = $_PROFILE;
	$user = SEEING_PROFILE;
	$id = $_PROFILE['ID'];
	$profile = true;
	$external = true;
} elseif ($_USER) {
	$profile = true;
	if (MODULE != 'tag' || (MODULE == 'tag' && (!$params))) {
		$userInfo = $_USER;
		$user = $_USER['username'];
		$realname = $_USER['realname'];
		$id = $_USER['ID'];
	}
	else $tags = true;
}
else {
	if (MODULE == 'tag') {
		if (strlen($params) > 0) {
			$profile = true;
			$tags = true;
		}
		else $profile = true;
	}
	else $profile = false;
}

if(empty($_POST['comment'])) die("0");
// If there isn't a comment text, exit

$comment = mysql_real_escape_string(nl2br(strip_tags($_POST['comment'])));
$user= $_USER[$realname];
// This would be a nice place to start customizing - the default user
// You can integrate it to any site and show a different username.

$addon='';
if($_POST['parent']) $addon=',parent='.(int)$_POST['parent'];

mysql_query("INSERT INTO wallpost SET usr='".$user."', comment='".$comment."', dt=NOW()".$addon);

if(mysql_affected_rows($link)==1)
	echo mysql_insert_id($link);
	// If the insert was successful, echo the newly assigned ID
else
	echo '0';
?>

Archivo "notsscrpt.js":

Código:
$(document).ready(function(){
// Executed once all the page elements are loaded

	lastVal = totHistory;
	
	// Create the slider:
	$("#slider").slider({
			value:totHistory,
			min: 1,
			max: totHistory,
			animate: true,
			slide: function(event, ui) {

				if(lastVal>ui.value)
					$(buildQ(lastVal,ui.value)).hide('fast').find('.addComment').remove();
				// Using buildQ to build the jQuery selector
				// If we are moving the slider backward, hide the previous comment

				
				else if(lastVal<ui.value)
					$(buildQ(lastVal,ui.value)).show('fast');
				// Otherwise show it
				
				lastVal = ui.value;
			}
		});
});

var totHistory=0;
// Holds the number of comments

var positions = new Array();
var lastVal;

function addHistory(obj)
{
	/* Gets called on page load for each comment, and on comment submit */
	totHistory++;
	positions.push(obj.id);
}

function buildQ(from,to)
{
	/* Building a jQuery selector from the begin
		and end point of the slide */
	
	if(from>to)
	{
		var tmp=to;
		to=from;
		from=tmp;
	}
	
	from++;
	to++;
	
	var query='';
	for(var i=from;i<to;i++)
	{
		if(i!=from) query+=',';
		query+='.com-'+positions[i-1];
	}

	/* Each comment has an unique com-(Comment ID) class
		that we are using to address it */

	return query;
}

function addComment(where,parent)
{
	/*	This functions gets called from both the "Add a comment" button 
		on the bottom of the page, and the add a reply link.
		It shows the comment submition form */
		
	var $el;

	if($('.waveButton').length) return false;
	// If there already is a comment submition form
	// shown on the page, return and exit
	
	if(!where)
		$el = $('#commentArea');
	else
		$el = $(where).closest('.waveComment');

	if(!parent) parent=0;

	// If we are adding a comment, but there are hidden comments by the slider:
	
	$('.waveComment').show('slow');
	lastVal = totHistory;
	$('#slider').slider('option','value',totHistory);

	// Move the slider to the end point and show all comments
	

	var comment = '<div class="waveComment addComment">\
		\
		<div class="comment">\
			<div class="commentAvatar">\
			<img src="img/demo.png" width="30" height="30" />\
			</div>\
			\
			<div class="commentText">\
			\
			<textarea class="textArea" rows="2" cols="70" name="" />\
			<div><input type="button" class="waveButton" value="Add comment" onclick="addSubmit(this,'+parent+')" /> or <a href="" onclick="cancelAdd(this);return false">cancel</a></div>\
			\
			</div>\
		</div>\
	\
	</div>';
	
	$el.append(comment);
	
	// Append the form
}

function cancelAdd(el)
{
	$(el).closest('.waveComment').remove();
}

function addSubmit(el,parent)
{
	/* Executed when clicking the submit button */
	
	var cText = $(el).closest('.commentText');
	var text = cText.find('textarea').val();
	var wC = $(el).closest('.waveComment');
	
	if(text.length<4)
	{
		alert("Your comment is too short!");
		return false;
	}
	
	$(el).parent().html('<img src="img/ajax_load.gif" width="16" height="16" />');
	// Showing the loading gif animation
	
	// Send an AJAX request:
	$.ajax({
		type: "POST",
		url: "sendpost.php",
		data: "comment="+encodeURIComponent(text)+"&parent="+parent,
		/* Sending both the text and the parent of the comment */
		success: function(msg){
			
			/* PHP returns the automatically assigned ID of the new comment */
			var ins_id = parseInt(msg);
			if(ins_id)
			{
				wC.addClass('com-'+ins_id);
				addHistory({id:ins_id});
				$('#slider').slider('option', 'max', totHistory).slider('option','value',totHistory);
				lastVal=totHistory;
			}
			
			transForm(text,cText);
			// Hiding the form and showing the comment
			
		}
	});

}

function transForm(text,cText)
{
	var tmpStr ='<span class="name">Demo:</span> '+text;
	cText.html(tmpStr);
}

Archivo "dashboard.php" (la página de inicio de los usuarios donde se envían y muestran las notas):

Código:
<?php
$comments_result = mysql_query("SELECT * FROM wallpost ORDER BY id ASC");
// Selecting all the comments ordered by id in ascending order

$comments=array();
$js_history='';

while($row=mysql_fetch_assoc($comments_result))
{
	if($row['parent']==0)
		// If the comment is not a reply to a previous comment, put it into $comments directly
		$comments[$row['id']] = $row;
	else
	{
		if(!$comments[$row['parent']]) continue;
		
		$comments[$row['parent']]['replies'][] = $row;
		// If it is a reply, put it in the 'replies' property of its parent
	}
	
	$js_history.='addHistory({id:"'.$row['id'].'"});'.PHP_EOL;
	// Adds JS history for each comment
}

$js_history='<script type="text/javascript">
'.$js_history.'
</script>'; ?>

// Aquí va el header, creo que no hace falta que ponga el código

</header>
<body>

<?php echo $js_history; ?>
	<!-- Outputting the addHistory functions -->
	
	<div id="wave">
	        <div id="sliderContainer">
	        	<div id="slider"></div>
	            <div class="clear"></div>
	        </div>
	        <div id="commentArea">

	<?php


		foreach($comments as $c)
		{
			showComment($c);

			// Showing each comment
		}

	?>



	        </div>

	        <input type="button" class="waveButtonMain" value="Add a comment" onclick="addComment()" />
	    </div>
Este es todo el código que hace que funcione el sistema de notas. Falta más código por en medio, pero creo que no hace falta ponerlo ya que no tiene nada que ver. Tampoco he incluido los archivos de conexión, ya que si se envían las notas y se publican perfectamente no es problema de la conexión.

¡Saludos!

P.D.: Si necesitan algún dato más no duden en pedir. Gracias.
P.D2.: En todos los archivos que he puesto el código antes piden el archivo de conexión para la base de datos, pero para acortar no lo he puesto.
  #2 (permalink)  
Antiguo 06/03/2010, 11:36
 
Fecha de Ingreso: agosto-2009
Ubicación: Al fondo a la derecha
Mensajes: 308
Antigüedad: 14 años, 7 meses
Puntos: 6
Respuesta: Creación de un muro para una red social

me podrías mandar tu red social por mp? gracias
__________________
Abre tu mente: Index no signigica index, significa índice
  #3 (permalink)  
Antiguo 06/03/2010, 11:43
 
Fecha de Ingreso: enero-2010
Mensajes: 14
Antigüedad: 14 años, 2 meses
Puntos: 0
Respuesta: Creación de un muro para una red social

Cita:
Iniciado por iLeaz Ver Mensaje
me podrías mandar tu red social por mp? gracias
En estos momentos solo funciona en el servidor local.
  #4 (permalink)  
Antiguo 21/02/2013, 14:27
 
Fecha de Ingreso: octubre-2012
Ubicación: Machalí, Chile
Mensajes: 6
Antigüedad: 11 años, 5 meses
Puntos: 0
Respuesta: Creación de un muro para una red social

Hola, pues yo tambien tengo una red social, y algo parecida a la tuya (obviamente mejor... no es mentira jajajaja...), y justamente tengo tambien un muro para los usuarios...
Lo que hago yo es insertar la ID del usuario que escribe en una tabla llamada wallShares (obviamente en mi caso, en el tuyo puede tener otro nombre...) y selecciono el nombre completo del usuario que tenga la ID insertada anteriormente en la tabla users...
Por ejemplo:
Código SQL:
Ver original
  1. SELECT full_name FROM users WHERE id='$uSender' LIMIT 1
Donde $uSender es la variable del usuario que publica...
Ojala te sirva de algo, lo puedes adaptar a tu sitio, a mi me funciona correctamente...
Saludos
  #5 (permalink)  
Antiguo 21/02/2013, 14:42
Avatar de jonni09lo
Colaborador
 
Fecha de Ingreso: septiembre-2011
Ubicación: Estigia
Mensajes: 1.471
Antigüedad: 12 años, 6 meses
Puntos: 397
Respuesta: Creación de un muro para una red social

Últimamente he visto mucho desubicado (sin intención de ofender) mira la fecha del hilo y compara con la fecha actual... NO revivas temas antiguos

Saludos
__________________
Haz preguntas inteligentes-Como ser Hacker
No hacer preguntas por mensaje privado. No sólo no es inteligente sino que es egoísta.

Etiquetas: creación, muro, red, social
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:25.