Salut,
Dis moi si vraiment cela t'interrèsse de créer ton module, je te met un extrait du module news (juste UN extrait d'UN fichier)
function getmoduleoption($option, $repmodule='news')
{
global $xoopsModuleConfig, $xoopsModule;
static $tbloptions= Array();
if(is_array($tbloptions) && array_key_exists($option,$tbloptions)) {
return $tbloptions[$option];
}
$retval=false;
if (isset($xoopsModuleConfig) && (is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $repmodule && $xoopsModule->getVar('isactive'))) {
if(isset($xoopsModuleConfig[$option])) {
$retval= $xoopsModuleConfig[$option];
}
} else {
$module_handler =& xoops_gethandler('module');
$module =& $module_handler->getByDirname($repmodule);
$config_handler =& xoops_gethandler('config');
if ($module) {
$moduleConfig =& $config_handler->getConfigsByCat(0, $module->getVar('mid'));
if(isset($moduleConfig[$option])) {
$retval= $moduleConfig[$option];
}
}
}
$tbloptions[$option]=$retval;
return $retval;
}
/**
* updates rating data in item table for a given item
*/
function news_updaterating($storyid)
{
global $xoopsDB;
$query = "SELECT rating FROM ".$xoopsDB->prefix("stories_votedata")." WHERE storyid = ".$storyid."";
$voteresult = $xoopsDB->query($query);
$votesDB = $xoopsDB->getRowsNum($voteresult);
$totalrating = 0;
while(list($rating)=$xoopsDB->fetchRow($voteresult)){
$totalrating += $rating;
}
$finalrating = $totalrating/$votesDB;
$finalrating = number_format($finalrating, 4);
$sql = sprintf("UPDATE %s SET rating = %u, votes = %u WHERE storyid = %u", $xoopsDB->prefix("stories"), $finalrating, $votesDB, $storyid);
$xoopsDB->queryF($sql);
}
/**
* Internal function for permissions
*
* Returns a list of all the permitted topics Ids for the current user
*
* @return array $topics Permitted topics Ids
*/
function MygetItemIds()
{
global $xoopsUser;
$module_handler =& xoops_gethandler('module');
$newsModule =& $module_handler->getByDirname('news');
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
$gperm_handler =& xoops_gethandler('groupperm');
$topics = $gperm_handler->getItemIds('news_view', $groups, $newsModule->getVar('mid'));
return($topics);
}
function news_html2text($document)
{
// PHP Manual:: function preg_replace
// $document should contain an HTML document.
// This will remove HTML tags, javascript sections
// and white space. It will also convert some
// common HTML entities to their text equivalent.
$search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
"'<[/!]*?[^<>]*?>'si", // Strip out HTML tags
"'([rn])[s]+'", // Strip out white space
"'&(quot|#34);'i", // Replace HTML entities
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(d+);'e"); // evaluate as php
$replace = array ("",
"",
"\1",
""",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(\1)");
$text = preg_replace($search, $replace, $document);
return $text;
}
function &news_getWysiwygForm($caption, $name, $value = "", $width = '100%', $height = '400px', $supplemental='')
{
$editor = false;
switch(strtolower(getmoduleoption('form_options'))){
case "spaw":
if (is_readable(XOOPS_ROOT_PATH . "/class/spaw/formspaw.php")) {
$myts =& MyTextSanitizer::getInstance();
include_once(XOOPS_ROOT_PATH . "/class/spaw/formspaw.php");
$editor = new XoopsFormSpaw($caption, $name, $value, $width, $height);
}
break;
case "fck":
if ( is_readable(XOOPS_ROOT_PATH . "/class/fckeditor/formfckeditor.php")) {
include_once(XOOPS_ROOT_PATH . "/class/fckeditor/formfckeditor.php");
$editor = new XoopsFormFckeditor($caption, $name, $value, $width, $height);
}
break;
case "htmlarea":
if ( is_readable(XOOPS_ROOT_PATH . "/class/htmlarea/formhtmlarea.php")) {
include_once(XOOPS_ROOT_PATH . "/class/htmlarea/formhtmlarea.php");
$editor = new XoopsFormHtmlarea($caption, $name, $value);
}
break;
case "dhtml":
$editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 10, 50, $supplemental);
break;
case "textarea":
$editor = new XoopsFormTextArea($caption, $name, $value);
break;
case "koivi":
if ( is_readable(XOOPS_ROOT_PATH . "/class/wysiwyg/formwysiwygtextarea.php")) {
include_once(XOOPS_ROOT_PATH . "/class/wysiwyg/formwysiwygtextarea.php");
$editor = new XoopsFormWysiwygTextArea($caption, $name, $value, $width, $height, '');
}
break;
}
return $editor;
}
/**
* Create, for Mozilla/Netscape and Opera a site navigation's bar
*/
function CreateSiteNavBar()
{
global $xoopsConfig;
$content='';
$myts =& MyTextSanitizer::getInstance();
include_once XOOPS_ROOT_PATH."/modules/news/class/class.newstopic.php";
$content=sprintf("<link rel="Home" title="%s" href="%s/" />n",$xoopsConfig['sitename'],XOOPS_URL);
$content.=sprintf("<link rel="Contents" href="%s" />n",XOOPS_URL.'/modules/news/index.php');
$content.=sprintf("<link rel="Search" href="%s" />n",XOOPS_URL.'/search.php');
$content.=sprintf("<link rel="Glossary" href="%s" />n",XOOPS_URL.'/modules/news/archive.php');
$content.=sprintf("<link rel="%s" href="%s" />n",$myts->htmlSpecialChars(_NW_SUBMITNEWS),XOOPS_URL.'/modules/news/submit.php');
$content.=sprintf("<link rel="alternate" type="application/rss+xml" title="%s" href="%s/" />n",$xoopsConfig['sitename'],XOOPS_URL.'/backend.php');
// create chapters
$xt = new NewsTopic();
$restricted=getmoduleoption('restrictindex');
$perms='';
if ($restricted) {
global $xoopsUser;
$module_handler =& xoops_gethandler('module');
$newsModule =& $module_handler->getByDirname('news');
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
$gperm_handler =& xoops_gethandler('groupperm');
$topics = $gperm_handler->getItemIds('news_view', $groups, $newsModule->getVar('mid'));
if(count($topics)>0) {
$topics = implode(',', $topics);
$perms = " AND topic_id IN (".$topics.") ";
} else {
return '';
}
}
$maintopics = $xt->getChildTreeArray(0,"topic_title", $perms);
foreach ($maintopics as $ontetopic) {
$content.=sprintf("<link rel="Chapter" title="%s" href="%s" />n",$myts->htmlSpecialChars($ontetopic['topic_title']),XOOPS_URL.'/modules/news/index.php?storytopic='.$ontetopic['topic_id']);
}
unset($mytree);
return($content);
}
/**
* Remove module's cache
*
*/
function updateCache() {
global $xoopsModule;
$tpllist=array('news_item.html','news_archive.html','news_article.html','news_index.html','news_by_topic.html','news_by_this_author.html','news_ratenews.html','news_rss.html');
include_once XOOPS_ROOT_PATH."/class/xoopsblock.php";
include_once XOOPS_ROOT_PATH.'/class/template.php';
// Clear blocks cache
xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
// Clear pages cache
$xoopsTpl = new XoopsTpl();
foreach ($tpllist as $onetemplate) {
$xoopsTpl->clear_cache('db:'.$onetemplate);
}
}
function TableExists($tablename)
{
global $xoopsDB;
$result=$xoopsDB->queryF("SHOW TABLES LIKE '$tablename'");
return($xoopsDB->getRowsNum($result) > 0);
}
function FieldExists($fieldname,$table)
{
global $xoopsDB;
$result=$xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'");
return($xoopsDB->getRowsNum($result) > 0);
}
function AddField($field, $table)
{
global $xoopsDB;
$result=$xoopsDB->queryF("ALTER TABLE " . $table . " ADD $field;");
return $result;
}
?>
Evidemment, dans un module, il y a un certain nombre de fichier à créer, ainsi que les templates pour l'affichage des données provenant des tables de ta base de données.
A +