Firefox PHP

Use of new flags in module

Posted by Mapex 
Use of new flags in module
April 07, 2011 03:04PM
Thank you very much, for and trying to create a module, but my skills are insufficient. and do not wish to create something unstable.
attempt to create the module based on an example.

I work, but I can not understand the system of "flags" to highlight in bold the post that are not yet seen.

Also I would like to understand, because I have several ideas and eager to learn the internal system phorum.

Thanks.

Language: PHP
<?php   // This module demonstrates the use of multiple hooks in a single module.   if(!defined("PHORUM")) return;   function phorum_mod_example_multiplehooks_after_header () {   global $PHORUM;   print "<b>Ultimos Mensjes </b><br />";   $mensajes = phorum_db_get_recent_messages(6,0,0,0,LIST_RECENT_MESSAGES); unset($mensajes[';users';]); // #print_r($mensajes);   foreach($mensajes as $id => $data){ #echo print_r($data)." => ".$id."<br />"; $id_mensaje = $data[';message_id';]; $id_autor = $data[';user_id';]; $id_forum = $data[';forum_id';]; $id_thread = $data[';thread';]; $autor = $data[';author';]; $titulo = $data[';subject';];     #print_r(phorum_db_newflag_get_flags($id_forum)); $url = phorum_get_url(PHORUM_FOREIGN_READ_URL, $id_forum, $id_thread, $id_mensaje); $url_autor = phorum_get_url(PHORUM_PROFILE_URL, $id_autor); ?>     <td><h4><a href="<?=$url;?>"><?=$titulo;?></a></h4> </td><td class="author" align="left"><a href="<?=$url_autor;?>"> <?=$autor;?> </a><br /><? #LA HORA ; ?></td>   </tr> <?     }//end foreach       }         ?>

Paste2
[paste2.org]


Edit Maurice: split off as a separate thread from the recent messages module thread, because it has no relation to the recent messages module.



Edited 2 time(s). Last edit at 04/07/2011 03:07PM by Maurice Makaay.
Re: Use of new flags in module
April 07, 2011 03:15PM
The flags are not an easy concept at all. If you want to read code that implements them, then check out include/api/newflags.php. Applying newflags can be handled by that API layer script. I would advise using this API: phorum_api_newflags_format_messages()

The recent messages module was written before the newflags API was created. If you look at the code for that module (recent_messages.php), you can find an implementation without using the newflags API. While that can be an interesting exercise, using the provided newflags API will be more future proof.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce



Edited 1 time(s). Last edit at 04/07/2011 03:29PM by Maurice Makaay.
Re: Use of new flags in module
April 08, 2011 04:51PM
Works!
It works!.
But as I can modify the template without the need to edit the php?.
<?php

// This module demonstrates the use of multiple hooks in a single module.

if(!defined("PHORUM")) return;

function phorum_mod_example_multiplehooks_after_header () {
 
global $PHORUM;
require_once('./include/api/newflags.php');
 print "<b>Ultimos Mensjes </b><br />";

$mensajes = phorum_db_get_recent_messages(6,0,0,0,LIST_RECENT_MESSAGES);
$mensajes = phorum_api_newflags_format_messages($mensajes);
#print_r($data);
unset($mensajes['users']); //
#print_r($mensajes);

#    if ($PHORUM["DATA"]["LOGGEDIN"]){	
#	}


?>

<table border="0" cellspacing="0" class="list">
<tr>
<th width="1%">&nbsp;</th>
<th align="left" width="80%">Subject</th>
<th align="left" width="19%" nowrap="nowrap">Author</th>
</tr>

<? foreach($mensajes as $id => $data){
	#echo print_r($data)." => ".$id."<br />";
	$id_mensaje = $data['message_id'];
	$id_autor = $data['user_id'];
	$id_forum = $data['forum_id'];
	$id_thread = $data['thread'];
	$autor = $data['author'];
	$titulo = $data['subject'];


  $url = phorum_get_url(PHORUM_FOREIGN_READ_URL, $id_forum, $id_thread, $id_mensaje); 
   $url_autor = phorum_get_url(PHORUM_PROFILE_URL, $id_autor);
?>




<tr style="margin:0px;font-size:12px;font-family: 'Droid Sans', arial, serif;">
<td align="center"  >
</td>



<?
if (isset($data['new']) && $data['new'] == 'new'){
	$titulo = "<b>".$titulo."</b>"."<span class=\"new-flag\"> new</span>";
}

?>
<td><h4><a href="<?=$url;?>"><?=$titulo;?></a></h4>
</td><td align="left"><a  style="font-size:12px;" href="<?=$url_autor;?>"> 
<?=$autor;?>
</a><br /><? #LA HORA ; ?></td>

</tr>








<?	




}//end foreach

?>


<tr class="footer"><th colspan="4">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </th></tr></table>

<?

#print_r($mensajes['8593']);

}

/*
function phorum_mod_example_multiplehooks_before_footer () {
    print "World!";
}
*/



?>
Re: Use of new flags in module
April 08, 2011 05:01PM
I don't understand your question, sorry.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Use of new flags in module
April 08, 2011 05:15PM
ok!.
I do not understand how to modify the template.
to contain the css and html.

because the module has to contain only php. this is correct?.

to enter this, but in a tpl file

<td><h4><a href="<?=$url;?>"><?=$titulo;?></a></h4>
</td><td align="left"><a  style="font-size:12px;" href="<?=$url_autor;?>"> 
<?=$autor;?>
</a><br /><? #LA HORA ; ?></td
Re: Use of new flags in module
April 08, 2011 05:26PM
If you want to write an after_header hook that outputs the data this way, then this is fine. Normally, we separate the HTML into a module template though.

Take a look at some other modules to see how module templates work. In general, the module can contain its own templates under mods/yourmod/templates/emerald/something.tpl, after which it can be loaded from the after_header hook using include phorum_get_template("yourmod::something")


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Use of new flags in module
April 12, 2011 06:00PM
Thanks.
Do not think it necessary to create a tpl file.
Is fully completed.
Thank you thank you very much!.
<?php



if(!defined("PHORUM")) return;

function phorum_mod_example_multiplehooks_after_header () {
 
global $PHORUM;
require_once('./include/api/newflags.php');
require_once './include/api/forums.php';

 print "<b>Ultimos Mensajes </b><br />";


$mensajes = phorum_db_get_recent_messages(9,0,0,0,LIST_RECENT_MESSAGES);
if ($PHORUM["DATA"]["LOGGEDIN"]){	
	$mensajes = phorum_api_newflags_format_messages($mensajes);
}
$secciones_disponibles= phorum_api_forums_by_vroot($PHORUM['vroot']);
unset($mensajes['users']); //

?>

<table border="0" cellspacing="0" class="list">
<tr>
<th width="1%">&nbsp;</th>
<th align="left" width="80%">Subject</th>
<th align="left" width="20%" nowrap="nowrap">Seccion</th>
<th align="left" width="10%" nowrap="nowrap">Author</th>

</tr>

<? foreach($mensajes as $id => $data){
	#echo print_r($data)." => ".$id."<br />";
	$id_mensaje = $data['message_id'];
	$id_autor = $data['user_id'];
	$id_forum = $data['forum_id'];
	$id_thread = $data['thread'];
	$autor = $data['author'];
	$titulo = $data['subject'];

	$nombre_seccion =  $secciones_disponibles[$id_forum]["name"];
	$url_seccion =   phorum_get_url(PHORUM_LIST_URL, $id_forum);
	$url = phorum_get_url(PHORUM_FOREIGN_READ_URL, $id_forum, $id_thread, $id_mensaje); 
	$url_autor = phorum_get_url(PHORUM_PROFILE_URL, $id_autor);

?>




<tr style="margin:0px;font-size:12px;font-family: 'Droid Sans', arial, serif;">
<td align="center"  >
</td>



<?
if (isset($data['new']) && $data['new'] == 'new'){
	$titulo = "<b>".$titulo."</b>"."<span class=\"new-flag\"> new</span>";
}

?>
<td><h4><a href="<?=$url;?>"><?=$titulo;?></a></h4></td>
<td align="left"><a  style="font-size:12px;" href="<?=$url_seccion;?>"><?=$nombre_seccion;?></a>
<td align="left"><a  style="font-size:12px;" href="<?=$url_autor;?>"><?=$autor;?></a>

<br /><? #LA HORA ; ?></td>

</tr>








<?	




}//end foreach

?>


<tr class="footer"><th colspan="4">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </th></tr></table>

<?

#print_r($mensajes['8593']);

}

/*
function phorum_mod_example_multiplehooks_before_footer () {
    print "World!";
}
*/



?>
Re: Use of new flags in module
April 13, 2011 03:00PM
My Contribution! Thank you very much!.
[www.phorum.org]
Sorry, only registered users may post in this forum.

Click here to login