Fantome
vendredi 31 décembre 2004 à 19:31
Bloc Sondage+ pour IPB PortalAffiche le dernier sondage sur tous les forums ou seulement ceux choisi (paramétrable par ACP). Et cela en respectant les autorisations de lecture des topics.
Ce bloc a était addapté depuis un bloc pour MyIbPortal créé par Simous.
Etape 1 : Ouvrir sources/ipbportal.phpChercherCODE
$this->site_bits['affiliates'] = $this->_show_affiliates();
Ajouter en-dessousCODE
$this->site_bits['sondage'] = $this->_show_sondage();
ChercherCODE
}
?>
Ajouter au-dessusCODE
/*-------------------------------------------------------------------------*/
// Bloc Sondage
/*-------------------------------------------------------------------------*/
function _show_sondage()
{
global $ibforums, $DB, $std, $print;
$extra = "";
$sql = "";
$check = 0;
if ( ! $ibforums->vars['csite_sondage_show'] )
{
return;
}
if ( count($this->good_forum) <= 0 )
{
return;
}
if ( $ibforums->vars['csite_sondage_forum'] != "" ) {
$forum = explode(',', $ibforums->vars['csite_sondage_forum'] );
$forumid = array_intersect ($this->good_forum, $forum);
}
else {
$forumid = $this->good_forum;
}
$qe = "t.forum_id IN(".implode(',', $forumid ).") AND ";
$DB->query( "SELECT t.tid, t.title, t.state, t.last_vote, p.*, v.member_id as member_voted
FROM ".SQL_PREFIX."topics t, ".SQL_PREFIX."polls p
LEFT JOIN ".SQL_PREFIX."voters v ON (v.member_id=".intval($ibforums->member['id'])." and v.tid=t.tid)
WHERE ".$qe."p.tid=t.tid
ORDER BY p.start_date DESC
LIMIT 1", 1 );
//-----------------------------------------
// Pour le suite c'est la copie de la fonction _show_poll
//-----------------------------------------
$poll = $DB->fetch_row();
if ( ! $poll['pid'] )
{
return;
}
$poll['poll_question'] = $poll['poll_question'] ? $poll['poll_question'] : $poll['title'];
//-----------------------------------------
// Can we vote?
//-----------------------------------------
if ( $poll['state'] == 'closed' )
{
$check = 1;
$poll_footer = $ibforums->lang['poll_finished'];
}
else if (! $ibforums->member['id'] )
{
$check = 1;
$poll_footer = $ibforums->lang['poll_noguest'];
}
else if ( $poll['member_voted'] )
{
$check = 1;
$poll_footer = $ibforums->lang['poll_voted'];
}
else if ( ($poll['starter_id'] == $ibforums->member['id']) and ($ibforums->vars['allow_creator_vote'] != 1) )
{
$check = 1;
$poll_footer = $ibforums->lang['poll_novote'];
}
else
{
$check = 0;
$poll_footer = $this->html->tmpl_poll_vote();
}
//-----------------------------------------
// Show it
//-----------------------------------------
if ($check == 1)
{
//-----------------------------------------
// Show the results
//-----------------------------------------
$total_votes = 0;
$html = $this->html->tmpl_poll_header($poll['poll_question'], $poll['tid']);
$poll_answers = unserialize(stripslashes($poll['choices']));
reset($poll_answers);
foreach ($poll_answers as $entry)
{
$id = $entry[0];
$choice = $entry[1];
$votes = $entry[2];
$total_votes += $votes;
if ( strlen($choice) < 1 )
{
continue;
}
if ($ibforums->vars['poll_tags'])
{
$choice = $this->parser->parse_poll_tags($choice);
}
if ( $ibforums->vars['post_wordwrap'] > 0 )
{
$choice = $this->parser->my_wordwrap( $choice, $ibforums->vars['post_wordwrap']);
}
$percent = $votes == 0 ? 0 : $votes / $poll['votes'] * 100;
$percent = sprintf( '%.2f' , $percent );
$width = $percent > 0 ? floor( round( $percent ) * ( 150 / 100 ) ) : 0;
$html .= $this->html->tmpl_poll_result_row($votes, $id, $choice, $percent, $width);
}
}
else
{
$poll_answers = unserialize(stripslashes($poll['choices']));
reset($poll_answers);
//-----------------------------------------
// Show poll form
//-----------------------------------------
$html = $this->html->tmpl_poll_header($poll['poll_question'], $poll['tid']);
foreach ($poll_answers as $entry)
{
$id = $entry[0];
$choice = $entry[1];
$votes = $entry[2];
$total_votes += $votes;
if ( strlen($choice) < 1 )
{
continue;
}
if ($ibforums->vars['poll_tags'])
{
$choice = $this->parser->parse_poll_tags($choice);
}
if ( $ibforums->vars['post_wordwrap'] > 0 )
{
$choice = $this->parser->my_wordwrap( $choice, $ibforums->vars['post_wordwrap']);
}
$html .= $this->html->tmpl_poll_choice_row($id, $choice);
}
}
$html .= $this->html->tmpl_poll_footer($poll_footer, sprintf( $ibforums->lang['poll_total_votes'], $total_votes ), $poll['tid'] );
return $html;
}
Enregistrer et Fermer sources/ipbportal.phpEtape 2 : Aller dans l'ACP de votre forumEtape 2.1 : Dans
System Settings > View All General Setting > Import an XML settings filePuis Puis importer les settings contenue dans le fichier ipb_settings_bloc_sondage+.xml (dans le zip)
Configuré les options du bloc dans les paramétres du portail.
Etape 2.2 :Dans
Skins & Templates > Skin Manager > IPB Default Skin > Edit Root Skin Template HTMLPuis
IPB Portal > csite_skeleton_templateAjouter
CODE
<!--CS.TEMPLATE.SONDAGE-->
Entre <!--Main Content--> et <!--End Main Content-->
Valider en cliquant sur
Save Template Bit(s)FIN