Fork me on GitHub






Création d'un block pour un module (SmallWorld)
Régulier
Inscrit: 17/12/2008 10:55
Messages: 203
Bonjour les xoopsiens,

Maintenant que j'ai réussi à installer smallworld sur mon site, je souhaiterais en faire un block pour en assouplir l'utilisation.

N'étant pas un pro, j'ai récupérer les codes de 2 fichiers:
smallworld_index.tpl et index.php.

J'ai créer dans Xoops_Version:
// Blocks
$modversion['blocks'][] = [
    
'file'        => 'smallworld_block.php',
    
'name'        => 'Smallworld',
    
'description' => 'This is a Block for SmallWorld',
    
'show_func'   => 'smallworld_blocklist',
    
'template'    => 'smallworld_block.tpl',


Puis le fichier smallworld_block.php dans Smallworld/include
<?php
/**
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code
 * which is considered copyrighted (c) material of the original comment or credit authors.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

/**
 * SmallWorld
 *
 * @copyright    The XOOPS Project (https://xoops.org)
 * @copyright    2011 Culex
 * @license      GNU GPL (http://www.gnu.org/licenses/gpl-2.0.html/)
 * @package      SmallWorld
 * @since        1.0
 * @author       Michael Albertsen (http://culex.dk) <culex@culex.dk>
 */

use XmfRequest;
use 
Xoopsmodulessmallworld;

require_once 
XOOPS_ROOT_PATH '/modules/smallworld/header.php';
require_once 
XOOPS_ROOT_PATH '/mainfile.php';

require_once 
XOOPS_ROOT_PATH '/modules/smallworld/include/functions.php';
require_once 
XOOPS_ROOT_PATH '/modules/smallworld/class/class_collector.php';
require_once 
XOOPS_ROOT_PATH '/modules/smallworld/class/PublicWallUpdates.php';
global 
$xoopsUser$xoTheme$xoopsConfig$xoopsLogger$xoopsModule;

$set smallworld_checkPrivateOrPublic();

if (
$xoopsUser) {
    
$GLOBALS['xoopsOption']['template_main'] = 'smallworld_index.tpl';
} elseif (!
$xoopsUser && == $set['access']) {
    
$GLOBALS['xoopsOption']['template_main'] = 'smallworld_publicindex.html';
} else {
    
redirect_header(XOOPS_URL '/user.php'5_NOPERM);
}
require_once 
XOOPS_ROOT_PATH '/header.php';
if (
== $set['access']) {
    
$id    $xoopsUser $xoopsUser->getVar('uid') : 0;
    
$user  = new XoopsUser($id);
    
$dBase = new smallworldSmallWorldDB;

    
// Check if inspected userid -> redirect to userprofile and show admin countdown
    
$inspect Smallworld_isInspected($id);
    if (
'yes' === $inspect['inspect']) {
        
redirect_header('userprofile.php?username=' $xoopsUser->getVar('uname'), 1);
    }

    
$xoopsTpl->assign('ownerofpage'$id);
    if (
$xoopsUser) {
        if (
$xoopsUser->isAdmin($xoopsModule->getVar('mid'))) {
            
$xoopsTpl->assign('isadminuser''YES');
            
$profile 2;
        } else {
            
$xoopsTpl->assign('isadminuser''NO');
        }
    }
}
    
// Create form for private settings
    
$form         = new smallworldSmallWorldForm;
    
$usersettings $form->usersettings($id$selected null);
    
$xoopsTpl->assign('usersetting'$usersettings);

    
$username $user->getVar('uname');
    
$check    = new smallworldSmallWorldUser;
    
$profile  $xoopsUser $check->CheckIfProfile($id) : 0;

    if (
$profile >= 2) {
        
$xuser = new smallworldSmallWorldProfile;
        
$xuser->ShowUser($id);
        
$menu_startpage "<a href='" XOOPS_URL "/modules/smallworld/publicindex.php'><img id='menuimg' src='" XOOPS_URL "/modules/smallworld/assets/images/highrise.png'>" _SMALLWORLD_STARTPAGE '</a>';
        
$menu_home      "<a href='" XOOPS_URL "/modules/smallworld/'><img id='menuimg' src='" XOOPS_URL "/modules/smallworld/assets/images/house.png'>" _SMALLWORLD_HOME '</a>';
        
$menu_profile   "<a href='" XOOPS_URL '/modules/smallworld/userprofile.php?username=' $username "'><img id='menuimg' src='" XOOPS_URL "/modules/smallworld/assets/images/user_silhouette.png'>" _SMALLWORLD_PROFILEINDEX '</a>';
        
$menu_gallery   "<a href='" XOOPS_URL '/modules/smallworld/galleryshow.php?username=' $username "'><img id='menuimg' src='" XOOPS_URL "/modules/smallworld/assets/images/picture.png'>" _SMALLWORLD_GALLERY '</a>';
        
$menu_friends   "<a href='" XOOPS_URL '/modules/smallworld/friends.php?username=' $username "'><img id='menuimg' src='" XOOPS_URL "/modules/smallworld/assets/images/group.png'>" _SMALLWORLD_FRIENDSPAGE '</a>';
    }

    
// Things to do with wall
    
$Wall = ($profile >= 2) ? new smallworldWallUpdates() : new smallworldPublicWallUpdates();
    if (
$profile && == $set['access']) {
        
$pub          smallworld_checkUserPubPostPerm();
        
$updatesarray $Wall->Updates(0$pub);
    } else {
        
// Follow array here
        
$followers    Smallworld_array_flatten($Wall->getFollowers($id), 0);
        
$updatesarray $Wall->Updates(0$id$followers);
    }

    
//Get friends invitations
    
$getInvitations $xoopsUser $check->getRequests($id) : 0;
    
$Wall->ParsePubArray($updatesarray$id);

    if (
$profile >= 2) {
        
$xoopsTpl->assign('menu_startpage'$menu_startpage);
        
$xoopsTpl->assign('menu_home'$menu_home);
        
$xoopsTpl->assign('menu_profile'$menu_profile);
        
$xoopsTpl->assign('menu_friends'$menu_friends);
        
$xoopsTpl->assign('menu_gallery'$menu_gallery);
    }
    
$xoopsTpl->assign('myusername'$username);
    
$xoopsTpl->assign('pagename''index');
    
$xoopsTpl->assign('check'$profile);

    
$xoopsTpl->assign('friendinvitations'$getInvitations);
    
$xoopsTpl->assign('access'$set['access']);

    
//    }

if (== $profile && == $set['access']) {
    
redirect_header(XOOPS_URL '/modules/smallworld/register.php');
}

 if (
$profile == && $set['access'] <= 1) {
 
redirect_header(XOOPS_URL "/modules/smallworld/register.php");
 }

if (
== $profile && == $set['access']) {
    
redirect_header(XOOPS_URL "/user.php"1_NOPERM);
}

require_once 
XOOPS_ROOT_PATH '/footer.php';


Et le fichier smallworld_block.tpl dans Smallworld/
<{if $xoops_isuser}>
<{if 
$check 1}>
<
ul id="smallworld_menu" class="smallworld_menu">
    <
li class="active">
        <
a href="<{$xoops_url}>/modules/smallworld/index.php"><{$smarty.const._SMALLWORLD_HOME}></a>
    </
li>
</
ul>
<
div id="example1" class="smallworld_content">
    <
table class="smallworld_biotable">
        <
tr>
            <
td>
                <{
$avatar}>
                <
div class="UploadNewAvatar" id="<{$ownerofpage}>" style="display:none">
                    <
div id="smallworld_avatarupload">
                        <
span><{$smarty.const._SMALLWORLD_UPLOADFILEBUTTONTEXT}></span>
                    </
div>
                    <
span id="smallworld_avatarstatus"></span>
                    <
ul id="smallworld_avatarfiles"></ul>

                </
div>
                <
div class="smallworld_userstat_menu">
                    <
h1><{$username}></h1>
                    <
div style="text-align: center;"><{$rankimage}></div>
                    <
br>
                    <
div style="text-align: center;"><{$smarty.const._SMALLWORLD_TOTALPOSTS}>
                        <{
$totalposts}>
                    </
div>
                    <
br><br>
                    <
h1><{$smarty.const._SMALLWORLD_TOTALUSERRATINGS}></h1>
                    <
class="smallworld_rating_menu"><{$usersratinf}></p>
                </
div>
                <
br>

                <{if 
$isadminuser == 'YES' || $username == $myusername}>
                <
br>
                <
class="smallworld_useredits_menu">
                    <
img height="10px" width="10px" src="assets/images/editavatar.png">
                    <
a href="javascript:void(0);" id="smallworld_changeAvatar"><{$smarty.const._SMALLWORLD_CHANGEAVATAR}></a><br>
                    <
img height="10px" width="10px" src="assets/images/edituserprofile.png">
                    <
a href="editprofile.php" id="smallworld_changeEditProfile"><{$smarty.const._SMALLWORLD_EDITPROFILE}></a><br>
                    <
img height="10px" width="10px" src="assets/images/preferences.png">
                    <
a href="javascript:void(0);" id="smallworld_changePersSettings"><{$smarty.const._SMALLWORLD_MENU_PRIVSET}></a>
                    <
br>
                </
p>
                <{/if}>
                <
br>
                <
class="smallworld_useredits_menu">
                    <
img width='10px' height='10px' src="<{$xoops_url}>/modules/smallworld/assets/images/statistics.png">
                    <
a href="javascript:void(0);" id="smallworld_statistics_lnk"><{$smarty.const._SMALLWORLD_STATS}></a><br>
                </
p>
                <
br>
            </
td>

            <
span class="smallworld_search">
                     <
td>
                        <
ul class="smallworld_index_headmenu">
                            <
li><{$menu_startpage}></li>
                            <
li><{$menu_home}></li>
                            <
li><{$menu_profile}></li>
                            <
li><{$menu_friends}></li>
                            <
li><{$menu_gallery}></li>    
                        </
ul>
                        <
br>
                        <
br>
                        
                        <
div style="text-align: center;"><input id="smallworld_searchform" size="35" type="text" value="<{$smarty.const._SMALLWORLD_SEARCHMEMBER}>"></div>
                        <
br>
                        <
br>
                                <
div id="smallworld_wall_container">
                                    <
div id="smallworld_updateboxarea">
                                        <
h4><{$smarty.const._SMALLWORLD_WHATSUP}></h4>
                                        <
form method="post" action="">
                                            <
textarea cols="50" rows="1" rel="<{$ownerofpage}>" name="smallworld_update" id="smallworld_update"></textarea>
                                            <
br>
                                            <
div id="smallworld_updatePrivacyCheck">
                                                <
label for="updatePriv"><{$smarty.const._SMALLWORLD_PRIVATEUPDATE}></label>
                                                <
input type="radio" name="updatePublic" id="updatePublic" value="1">
                                                <
label for="updatePriv"><{$smarty.const._SMALLWORLD_PUBLICUPDATE}></label>
                                                <
input type="radio" name="updatePublic" id="updatePublic" value="0">
                                                <
img id="smallworld_tagIMG" src="https://cdn3.iconfinder.com/data/icons/diagram_v2/PNG/96x96/diagram_v2-06.png" height="15px" width="15px" title="Insert tags for this update">
                                                
                                            </
div>   
<
ul style="display:none" id="tags_input">
                                                </
ul>                                            
                                            <
br><br>
                                            <
input type="submit" value="<{$smarty.const._SMALLWORLD_UPDATEBUTTONTEXT}>" id="smallworld_update_button" class="smallworld_update_button">
                                        </
form>
                                    </
div>
                                    <
hr>
                                    <
div id="smallworld_Stats_container"></div>
                                    <
button id='smallworld_messagecounter_id' onClick='smallworldRefresh();return false;'></button>
                                    <
div id='smallworld_flashmessage'>
                                        <
div id="smallworld_flash" align="left"></div>
                                    </
div>                                        
                                <
div id="smallworld_content">                                                                                            
                                 <{foreach 
item=post from=$walldata}>
                                <
div class="smallworld_stbody" id="smallworld_stbody<{$post.msg_id}>">
                                    <
script type="text/javascript"
                                            
xoops_smallworld(document).ready(function () {
                                                
xoops_smallworld('#smallworld_stexpand<{$post.msg_id}>').oembed('<{$post.orimessage}>', {
                                                    
embedMethod'fill',
                                                    
maxWidth"100%",
                                                    
maxHeight"100%"
                                                
});
                                            });
                                    
</script>
                                    <div class="smallworld_stimg">
                                        <img src="<{$post.avatar_link}>" class='smallworld_big_face' <{$post.avatar_highwide}>>
                                    </div> 
                                <div class="smallworld_sttext">                                       
                                    <{if $isadminuser == 'YES' || $post.username == $myusername}>
                                        <a class="smallworld_stdelete" href="#" rel="<{$post.uid_fk}>" id="<{$post.msg_id}>" title="<{$smarty.const._SMALLWORLD_DELUPD}>">X</a>
                                    <{/if}>
                                        <a href="<{$post.permalink}>"> <img style="height:10px; width:10px" src="<{$post.linkimage}>"> </a>
                                    <b><a class="smallworld_wall_link" href="<{$xoops_url}>/modules/smallworld/userprofile.php?username=<{$post.username}>"><{$post.username}></a></b> <{$post.message}>
                                    <div class="smallworld_sttime"><{$post.created}> <{$post.sharelink}> | <a href='#' class='smallworld_commentopen' id='<{$post.msg_id}>' title='<{$smarty.const._SMALLWORLD_COMMENTWALL}>'><{$smarty.const._SMALLWORLD_COMMENTWALL}></a></div>
                                    <{$post.sharediv}>
                                    <{if $post.username == $myusername}>
                                        <div class="smallworld_stcommentvote">                                            
                                            <span id="smallworld_votenum"><{$post.vote_up}></span>
                                                <img class="smallworld_voteimg" src="assets/images/like.png">
                                            
                                            <span id="smallworld_votenum"><{$post.vote_down}></span>
                                                <img class="smallworld_voteimg" src="assets/images/dislike.png">
                                        </div>    
                                    <{else}>
                                    <div class="smallworld_stcommentvote">                                            
                                            <span id="smallworld_votenum"><{$post.vote_up}></span> <a href="javascript:void(0)" name="up" class="smallworld_stcomment_vote" id="<{$post.msg_id}>" type="msg" owner="<{$post.uid_fk}>">
                                                <img class="smallworld_voteimg" src="assets/images/like.png">
                                            </a>
                                            <span id="smallworld_votenum"><{$post.vote_down}></span> <a href="javascript:void(0)" name="down" class="smallworld_stcomment_vote" id="<{$post.msg_id}>" type="msg" owner="<{$post.uid_fk}>">
                                                <img class="smallworld_voteimg" src="assets/images/dislike.png">
                                            </a>
                                            <a href="javascript:void(0)" auserid="<{$post.uid_fk}>" by_user="<{$myusername}>" a_user="<{$post.username}>" name="complaint" class="smallworld_comment_complaint" id="<{$post.compl_msg_lnk}>">
                                                <img class="smallworld_voteimg" src="assets/images/complaint.png">
                                            </a>                                                
                                    </div>
                                    <{/if}>
                                    <div id="smallworld_stexpandbox">
                                        <div id="smallworld_stexpand<{$post.msg_id}>"></div>
                                    </div>

                                    <div class="smallworld_commentcontainer" id="smallworld_commentload<{$post.msg_id}>">

                                        <{section name=i loop=$comm}>
                                            <{if $comm[i].msg_id_fk == $post.msg_id}>
                                            <div class="smallworld_stcommentbody" id="smallworld_stcommentbody<{$comm[i].com_id}>">
                                                <div class="smallworld_stcommentimg">
                                                <img src="<{$comm[i].avatar_link}>" class='smallworld_small_face' <{$comm[i].avatar_highwide}>>
                                                </div> 
                                                <div class="smallworld_stcommenttext">
                                                    <{if $isadminuser == 'YES' or $comm[i].username == $myusername}>    
                                                    <a class="smallworld_stcommentdelete" href="#" rel="<{$comm[i].uid}>" id='<{$comm[i].com_id}>' title='<{$smarty.const._SMALLWORLD_DELETECOMMENT}>'>X</a>
                                                    <{/if}>
                                                    <div class="comm_holder">
                                                    <a class="smallworld_wall_link" href="<{$xoops_url}>/modules/smallworld/userprofile.php?username=<{$comm[i].username}>">
                                                        <b><{$comm[i].username}></b>
                                                    </a> <{$comm[i].comment}></div>                                                
                                                        <div class="smallworld_stcommenttime"><{$comm[i].time}></div>
                                                         <{if $comm[i].username == $myusername}>    
                                                            <div class="smallworld_stcommentvote">
                                                                <span id="smallworld_votenum"><{$comm[i].vote_up}></span>
                                                                    <img class="smallworld_voteimg" src="assets/images/like.png">
                                                                
                                                                
                                                                <span id="smallworld_votenum"><{$comm[i].vote_down}></span>
                                                                    <img class="smallworld_voteimg" src="assets/images/dislike.png">
                                                            </div>
                                                         <{else}>
                                                          <div class="smallworld_stcommentvote">
                                                                <span id="smallworld_votenum"><{$comm[i].vote_up}></span> <a href="javascript:void(0)" name="up" class="smallworld_stcomment_vote" id="<{$comm[i].com_id}>" owner="<{$comm[i].uid}>" type="com" type2="<{$comm[i].msg_id_fk}>">
                                                                    <img class="smallworld_voteimg" src="assets/images/like.png">
                                                                </a>
                                                                
                                                                <span id="smallworld_votenum"><{$comm[i].vote_down}></span> <a href="javascript:void(0)" name="down" class="smallworld_stcomment_vote" id="<{$comm[i].com_id}>" owner="<{$comm[i].uid}>" type="com" type2="<{$comm[i].msg_id_fk}>">
                                                                    <img class="smallworld_voteimg" src="assets/images/dislike.png">
                                                                </a>
                                                                <a href="javascript:void(0)" auserid="<{$comm[i].uid}>" by_user="<{$myusername}>" a_user="<{$comm[i].username}>" name="complaint" class="smallworld_comment_complaint" id="<{$comm[i].compl_msg_lnk}>">
                                                                    <img class="smallworld_voteimg" src="assets/images/complaint.png">
                                                                </a>                                                             
                                                          </div>
                                                         <{/if}>
                                                </div>
                                            </div>
                                            <{/if}>
                                        <{/section}>
                                    </div>
                                    
                                    <div class="smallworld_commentupdate" style="display:none" id="smallworld_commentbox<{$post.msg_id}>">
                                        <div class="smallworld_stcommentimg">
                                            <img src="<{$myavatarlink}>" class='smallworld_small_face' width="35px" height="35px">
                                        </div> 
                                        <div class="smallworld_stcommenttext">
                                            <form method="post" action="">
                                                <textarea name="smallworld_comment" class="smallworld_comment" id="smallworld_ctextarea<{$post.msg_id}>"></textarea>
                                                <br>
                                                <input type="submit" value="<{$smarty.const._SMALLWORLD_COMMENTBUTTONTEXT}>" id="<{$post.msg_id}>" class="smallworld_comment_button">
                                            </form>
                                        </div>
                                    </div>
                                    
                                </div> 

                                </div>
                                
                                 <{/foreach}>
                                <div id="smallworld_moremsg_ajax" style="display:none">
                                    <img src="assets/images/loader.gif">
                                </div>
                                <a href="javascript:void(0)" class="smallworld_msg_counter" rel2="" rel="<{$pagename}>" id="<{$post.msg_id}>"><{$smarty.const._SMALLWORLD_MOREBUTTONLINK}></a>
                                    </div>
</div>
</td>
</span>
</tr>
</table>
</div>
<div id="friendInvitations_box" title="<{$smarty.const._SMALLWORLD_FRIENDSINVITATIONS}>">
    <table border="0" class="smallworld_invitetable" cellspacing="0" cellpadding="0">
        <tr>
            <th><{$smarty.const._SMALLWORLD_REALNAME}></th>
            <th></th>
            <th><{$smarty.const._SMALLWORLD_DATERECIEVED}></th>
            <th></th>
            <th> <{$smarty.const._SMALLWORLD_ACTION}></th>
            <th></th>
        </tr>
        <{foreach item=post from=$friendinvitations}>
        <tr id="smallworldfriendrequest_<{$post.friendname}>">
            <td><{$post.friendname}></td>
            <td><{$post.friendimage}></td>
            <td><{$post.frienddate}></td>
            <td><{$post.accept}></td>
            <td><{$post.deny}></td>
            <td><{$post.later}></td>
        </tr>
        <{/foreach}>
    </table>
</div>
<{$usersetting}>
<div id="smallworldStatsDiv" title="<{$smarty.const._SMALLWORLD_STATS}>" style="display:none;"></div>
<{else}>
<div id="smallworld_notyetregistered" title="<{$smarty.const._SMALLWORLD_NOTYETREGISTERED_TITLE}>">
    <table border="0" class="smallworld_table" cellspacing="0" cellpadding="0">
        <tr>
            <label for="register"></label>
            <td><p id="smallworld_notyetusercontent"><{$smarty.const._SMALLWORLD_NOTYETUSER_BOXTEXT}></p></td>
        </tr>
    </table>
</div>
<{/if}>
<{/if}>

J'obitens l'erreur
ErrorErrorCall to a member function assign() on null in file /modules/smallworld/blocks/smallworld_block.php line 55


qui correspond au code:
$xoopsTpl->assign('ownerofpage'$id);


Et j'obtiens la même erreur a chaque fois qu'on fait référence à $xoopsTpl

Je suis un apprenti et je ne maitrise clairement pas les tpl, je bricole en général et j'apprends. J'ai du râter quelquechose quelque part.

Je vous remercie par avance pour votre aide.
Bonne fin de journée.
Cordialement,

Sébastien

Posté le : 16/11/2020 17:10
Partager Twitter Partagez cette article sur GG+

 Haut   Précédent   Suivant



Vous pouvez voir les sujets.
Vous ne pouvez pas débuter de nouveaux sujets.
Vous ne pouvez pas répondre aux contributions.
Vous ne pouvez pas éditer vos contributions.
Vous ne pouvez pas effacez vos contributions.
Vous ne pouvez pas ajouter de nouveaux sondages.
Vous ne pouvez pas voter en sondage.
Vous ne pouvez pas attacher des fichiers à vos contributions.
Vous ne pouvez pas poster sans approbation.

Propulsé avec XOOPS | Graphisme adapté par Tatane, Grosdunord, Montuy337513

36 Personne(s) en ligne (29 Personne(s) connectée(s) sur Forum) | Utilisateur(s): 0 | Invité(s): 36 | Plus ...