61
irmtfan
Re: How to write an standard module for xoops (div table, pagination , sort, order)
  • 2013/5/27 11:51

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Ok. Today i finally finish the xoops_version.php tutorial.
I add the following to the first post:
Quote:


3-1-6- search functionality:
// Search
$modversion['hasSearch'] = 1;
$modversion['search']['file'] = "include/search.inc.php";
$modversion['search']['func'] = "publisher_search";

- The above is for search functionality:
It is better to write the 'func' name without $dirname to avoid hard-code:
$modversion['search']['func'] = $modversion["dirname"] . "_search";


You can find more information about xoops search system in this post:
https://xoops.org/modules/newbb/viewtopic.php?post_id=349697#forumpost349697

3-1-7- module links in mainmenu block:
// Menu
$modversion['hasMain'] = 1;


- shows your module has functionality in user side (in modules/MODULE/*.*)
It will show a link of your module in xoops 'mainmenu' block which show modules/MODULE/index.php page.

global $xoopsModule;
if (
is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $modversion['dirname']) {
    global 
$xoopsModuleConfig$xoopsUser;
    
$isAdmin false;
    if (
is_object($xoopsUser)) {
        
$isAdmin $xoopsUser->isAdmin($xoopsModule->getVar('mid'));
    }
    
// Add the Submit new item button
    
$allowsubmit = (isset($xoopsModuleConfig['perm_submit']) && $xoopsModuleConfig['perm_submit'] == 1) ? true false;
    
$anonpost = (isset($xoopsModuleConfig['permissions_anon_post']) && $xoopsModuleConfig['permissions_anon_post'] == 1) ? true false;
    if (
$isAdmin || ($allowsubmit && (is_object($xoopsUser) || $anonpost))) {
        
$modversion['sub'][1]['name'] = _MI_PUBLISHER_SUB_SMNAME1;
        
$modversion['sub'][1]['url'] = "submit.php?op=add";
    }

    
// Add the Search button
    
$allowsearch = (isset($xoopsModuleConfig['perm_search']) && $xoopsModuleConfig['perm_search'] == 1) ? true false;
    if (
$allowsearch) {
        
$modversion['sub'][2]['name'] = _MI_PUBLISHER_SUB_SMNAME3;
        
$modversion['sub'][2]['url'] = "search.php";
    }
}
// Add the Archive button
$modversion['sub'][3]['name'] = _MI_PUBLISHER_SUB_ARCHIVE;
$modversion['sub'][3]['url'] = "archive.php";

- show sub links in the 'mainmenu' block.
As you can see you can prevent some users to some sub links like submit.php

3-1-8- module blocks:
If your module has a block you should define them here.
$modversion['blocks'][$i]['file'] = "views.php";
$modversion['blocks'][$i]['name'] = _MI_USERLOG_BLOCK_VIEWS;
$modversion['blocks'][$i]['description'] = _MI_USERLOG_BLOCK_VIEWS_DSC;
$modversion['blocks'][$i]['show_func'] = $modversion['dirname'] . "_views_show";
$modversion['blocks'][$i]['edit_func'] = $modversion['dirname'] . "_views_edit";
$modversion['blocks'][$i]['options'] = "10|0|1|-1|0|count|DESC";
$modversion['blocks'][$i]['template'] = $modversion['dirname'] . "_block_views.html";


- show that this module has block. you can see we can avoid hard-coded $dirname.
- The file for block functions (show_func and edit_func) will be located in modules/MODULE/blocks
eg: modules/MODULE/blocks/views.php
- show_func: is the function that will be parsed when the block is visible.
- edit_func: is the function that just add a form in Blocks Administration (modules/system/admin.php?fct=blocksadmin&op=edit&bid=BLOCK_ID) for 'options' field.
a module block may not have edit_func if it dont need any extra options.
- options: are default options only will be stored in module install. (Note: So in upgrade they will not be changed in database if you change them here!!!)
- template: the template for this block located in modules/MODULE/templates/blocks
eg: modules/MODULE/templates/blocks/userlog_block_views.html

3-1-9- module templates:
Your module should use templates for user and admin side.
// Templates - if you dont define 'type' it will be 'module' | '' -> templates
$i 0;
$modversion['templates'][$i]['file'] = $modversion['dirname'] . '_admin_sets.html';
$modversion['templates'][$i]['type'] = 'admin'// $type = 'blocks' -> templates/blocks , 'admin' -> templates/admin , 'module' | '' -> templates
$modversion['templates'][$i]['description'] = 'list of userlog setting';

- Templates of your module will show a nice and formatted data in user side.
- Try always use one template for one page/section of your module. More templates means less hard-code.
- Note that you should avoid any direct php output like echo, print_r and ...
- Template types are: 'module' (default), 'admin', 'blocks' (if you dont define it will be 'module')
- In the current xoops 2.5.6 'description' is not used anywhere so you dont need to add a language definition.

3-1-10- module configurations:
Xoops core use 3 tables to save core and module configs:
_config
_configcategory
_configoption

So you dont need to have extra tables for your module configurations.

These tables used for storing module and core configs in database.
configs can be changed in admin > Preferences > MODULE:
xoops256/modules/system/admin.php?fct=preferences&op=showmod&mod=MID

and configs are in modules/MODULE/xoops_version.php
example:
$i=0;
$modversion['config'][$i]['name'] = 'status';
$modversion['config'][$i]['title'] = '_MI_USERLOG_STATUS';
$modversion['config'][$i]['description'] = '_MI_USERLOG_STATUS_DSC';
$modversion['config'][$i]['formtype'] = 'select';
$modversion['config'][$i]['valuetype'] = 'int';
$modversion['config'][$i]['default'] = 1;
$modversion['config'][$i]['options'] = array(_MI_USERLOG_ACTIVE => 1_MI_USERLOG_IDLE => 0);

$i++;
$modversion['config'][$i]['name'] = 'postlog';
$modversion['config'][$i]['title'] = '_MI_USERLOG_POSTLOG';
$modversion['config'][$i]['description'] = '_MI_USERLOG_POSTLOG_DSC';
$modversion['config'][$i]['formtype'] = 'yesno';
$modversion['config'][$i]['valuetype'] = 'int';
$modversion['config'][$i]['default'] = 1;
$modversion['config'][$i]['options'] = array();

_config table:
the below information will be stored in config table:
conf_id: auto generate id
conf_modid: module id
conf_catid: 0 not used in 2.5x series but reserve for 2.6
conf_name: $modversion['config'][$i]['name']
conf_title: $modversion['config'][$i]['title']
conf_value: The value selected by user from $modversion['config'][$i]['options']. The default is: $modversion['config'][$i]['default'] which will be stored once the module is installed.
conf_desc: $modversion['config'][$i]['description']
conf_formtype: $modversion['config'][$i]['formtype']
conf_valuetype: $modversion['config'][$i]['valuetype']
conf_order: $i : number of config in the $modversion['config'] array

A side note about changing conf_value:
the conf_value will be changed only by:
a - install a fresh module which $modversion['config'][$i]['default'] will be stored(as i described above).
b - select by user (as i described above)
c - In update when formtype or valuetype was changed in xoops_version.php $modversion['config'][$i]['default'] will be stored.
A developer may decide to change the value by this trick!!!

_configcategory table:
In 2.5.x only used by core and not used for modules. reserve for xoops 2.6

_configoption table:
information comes from $modversion['config'][$i]['options'] will be stored in this table.
if empty($modversion['config'][$i]['options']) => nothing will be stored in this table.
As an example for this option:
$modversion['config'][$i]['options'] = array(_MI_USERLOG_ACTIVE => 1_MI_USERLOG_IDLE => 0);


Below information will be stored:
confop_id : auto generate option id
confop_name: _MI_USERLOG_ACTIVE (will be parsed to user own language)
confop_value: 1
conf_id: the linked id in config table.

Note: options only will be stored in install and update process.

== END OF xoops_version.php ==


Also I remove the magic function __call

And I add a brief statement to guide using another table/handler in one handler by using the module helper class. (eg: join purposes)
Quote:

As you can see we have an instance of publisher helper object to use it anywhere we need that helper.
for example to access another table in this handler. (eg: in joining purposes)
$this->publisher->getHandler('item')->table

means publisher_items table.


@bumciach:
AFAIK developers should avoid JOIN as much as possible.
But anyway i add the above tutorial.

I am sure 2 simple queries is better than one JOIN.

but I am not sure about that when tables are more than 2 like 3, 4, 5 or more.

somebody with more information could tell us.

Quote:

I mean add variable initialized for the object (mymoduleArticles) not to add field into table (articles) in database.

Then it will not help you to reduce queries.*/



62
irmtfan
Re: How does the config tables works in XOOPS Core?
  • 2013/5/27 9:26

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


These tables used for storing module and core configs in database.
configs can be changed in:
xoops256/modules/system/admin.php?fct=preferences&op=showmod&mod=MID

and configs come from modules/MODULE/xoops_version.php
example:
$i=0;
$modversion['config'][$i]['name'] = 'status';
$modversion['config'][$i]['title'] = '_MI_USERLOG_STATUS';
$modversion['config'][$i]['description'] = '_MI_USERLOG_STATUS_DSC';
$modversion['config'][$i]['formtype'] = 'select';
$modversion['config'][$i]['valuetype'] = 'int';
$modversion['config'][$i]['default'] = 1;
$modversion['config'][$i]['options'] = array(_MI_USERLOG_ACTIVE => 1_MI_USERLOG_IDLE => 0);

$i++;
$modversion['config'][$i]['name'] = 'postlog';
$modversion['config'][$i]['title'] = '_MI_USERLOG_POSTLOG';
$modversion['config'][$i]['description'] = '_MI_USERLOG_POSTLOG_DSC';
$modversion['config'][$i]['formtype'] = 'yesno';
$modversion['config'][$i]['valuetype'] = 'int';
$modversion['config'][$i]['default'] = 1;
$modversion['config'][$i]['options'] = array();

config table:
the below information will be stored in config table:
conf_id: auto generate id
conf_modid: module id
conf_catid: 0 not used in 2.5x series but reserve for 2.6
conf_name: $modversion['config'][$i]['name']
conf_title: $modversion['config'][$i]['title']
conf_value: The value selected by user from $modversion['config'][$i]['options']. The default is: $modversion['config'][$i]['default'] which will be stored once the module is installed.
conf_desc: $modversion['config'][$i]['description']
conf_formtype: $modversion['config'][$i]['formtype']
conf_valuetype: $modversion['config'][$i]['valuetype']
conf_order: $i : number of config in the $modversion['config'] array

A side note about changing conf_value:
the conf_value will be changed only by:
1- install a fresh module which $modversion['config'][$i]['default'] will be stored(as i described above).
2- select by user (as i described above)
3- In update when formtype or valuetype was changed in xoops_version.php $modversion['config'][$i]['default'] will be stored.
A developer may decide to change the value by this trick!!!

configcategory table:
In 2.5.x only used by core and not used for modules. reserve for xoops 2.6

configoption table:
information comes from $modversion['config'][$i]['options'] will be stored in this table.
if empty($modversion['config'][$i]['options']) => nothing will be stored in this table.
As an example for this option:
$modversion['config'][$i]['options'] = array(_MI_USERLOG_ACTIVE => 1_MI_USERLOG_IDLE => 0);


Below information will be stored:
confop_id : auto generate option id
confop_name: _MI_USERLOG_ACTIVE (will be parsed to user own language)
confop_value: 1
conf_id: the linked id in config table.

Note: options only will be stored in install and update process.



63
irmtfan
Re: Missing Forums and posts in CBB/NEWBB
  • 2013/5/27 4:23

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


I think you have problems because your recovery is not correct
Quote:

I have since reset the whole site with a clean install of Xoops and CBB and imported the SQL to get the posts and everything back.

The above is wrong.
for restore purposes, you should not install a new xoops and cbb. You just need to upload files and export database.
see this i wrote for userlog module:

Quote:

To Upgrade
==========================
1- Close your website. (highly recommended) be sure you be logged in.
2- Get a backup from your old userlog database.(all XOOPSPREFIX_mod_userlog_* tables)
3- Get a backup from your old XOOPSROOT/modules/userlog folder.
4- IF EXIST get a backup from your all old userlog custom templates in themes folder located in XOOPSROOT/themes/MY_THEME/modules/userlog. eg: XOOPSROOT/themes/default/modules/userlog
5- Go to userlog > preferences and set the module log status as Idle.
6- Delete your old userlog folder located in modules. (Do not rename it. Only delete will work and while you have the backup you should not worry about anything)
7- IF EXIST delete all old userlog custom templates in themes folder located in XOOPSROOT/themes/MY_THEME/modules/userlog. eg: XOOPSROOT/themes/default/modules/userlog
8- Upload the most recent version of userlog to XOOPSROOT/modules/userlog (upload the compressed file and decompressed via Cpanel is the best way to insure all files are correctly uploaded)
9- Go to your admin > system > modules > userlog -> update (important: wait until you see the report page. It is better to save this page for future review)
10- Go to system > maintenance > clear all caches
11- Change the default settings to your desired in the module preferences. Do not forget to back the module log status to Active.
12 - Do not forget to open your website again.

What you should not do in upgrade:
----------------------------------
- Do not install the most recent version and import the old database backup and try to update it in admin. (Do not do it in any other xoops module too otherwise it will not work correctly after upgrade)
It will not work because Xoops store other information from modules like the module version in some other tables like _modules table and you just import the module tables and not this other information.
- Do not rename the old userlog folder to something like userlog_old. because xoops system will find any folder inside modules folder and try to take it as a new module.
- Do not save your old custom template. instead try to implement your changes in templates in the new template.

To Downgrade (To Restore the old version if the upgrade goes wrong)
===================================================
1- Close your website. (highly recommended) be sure you be logged in.
2- IF YOU CAN Go to userlog > preferences and set the module log status as Idle.
3- Delete the most recent bad working userlog folder located in modules. (Do not rename it.)
4- Drop the most recent bad working userlog database. (all XOOPSPREFIX_mod_userlog_* tables)
5- IF EXIST delete all userlog custom templates in themes folder located in XOOPSROOT/themes/MY_THEME/modules/userlog. eg: XOOPSROOT/themes/default/modules/userlog
6- Upload your previous working version of userlog to XOOPSROOT/modules/userlog (upload the compressed file and decompressed via Cpanel is the best way to insure all files are correctly uploaded)
7- Import your previous working userlog database. (all XOOPSPREFIX_mod_userlog_* tables)
8- Go to your admin > system > modules > userlog -> update (important: wait until you see the report page. It is better to save this page for future review)
9- Go to system > maintenance > clear all caches
10- Change the default settings to your desired in the module preferences. Do not forget to back the module log status to Active.
11- Do not forget to open your website again.


You should follow the above for any upgrade or downgrade (restore) of xoops core or modules purposes.

specially pay more attention to this:
Quote:

It will not work because Xoops store other information from modules like the module version in some other tables like _modules table and you just import the module tables and not this other information.

It seems you lost some permission data in your CBB because of the wrong recovery.



64
irmtfan
Re: Like system (module/extension) for xoops
  • 2013/5/27 2:25

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Hi, kraven30
I still didnt hear from you.
I want to repeat the main request for a rating system.
It could be able to rate many item_id in one page with a multi level permission system and also recognize who is voting who's article.
for example: In a forum topic:

- newbb/viewtopic.php?topic_id=XX
this rating has already built-in functions and tables in newbb. but it is useless. It seems this new rating extension do this for all modules.

- newbb/viewtopic.php?post_id=XX
we need this rating system. It could be able to rate all posts in one page of a topic.
Or all comments in one page.

I know you can find many examples yourself because now it is widely used in websites:
1- Thank you system:(Like)
Can be simplify as (entry in db = like) (nothing in db = no like)
It is the simplest rating system widely used in forums and Also FB. It just has a "thank you" Or "like" button. Also it shows who is like who's post/page.

2- Vote-up, vote-down OR (Thumbs-up and Thumbs-down) OR (Like and dislike)
can be simplify as 1 = like and 0 = dislike
eg: see the comment in this link:http://net.tutsplus.com/tutorials/html-css-techniques/building-a-5-star-rating-system-with-jquery-ajax-and-php/
As you can see, It has a permission for "vote-up" (like) for anon users but you should be registered to "vote-down" (dislike)
Also you can cancel your vote-up which means "Unvote-up" (unlike)

3- more complicated rating eg: that 5-star you worked on.



65
irmtfan
Re: How to write an standard module for xoops (div table, pagination , sort, order)
  • 2013/5/25 5:39

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Hi bumciach,
Im glad that you liked this topic.
Really the main goal of this "how to write a standard module" would be guidelines for writing a strong, understandable, easy to debug and consistent base codes for all xoops modules.
Therefore because this standard has to be basic I did not add special needs (eg: special queries like joining).

but if a developer follow this guideline the output module is ready for adding any special needs too.
for example for joining purposes, the most important thing is not adding a hard-coded table name
And if the developer followed this guideline:
1- If module had one class for each table we should use handlers to find/use table name and avoid hard-code.
2- If module used helper class it will be easier too

So for example to join (of course you dont need join which I will describe later) we can improve your query:
class mymoduleArticleHandler extends XoopsPersistableObjectHandler 

  function &
getObjects($args
  { 
      
$sql "SELECT t2.name AS category_name, t1.* FROM {$this->table} t1, LEFT JOIN {$this->MODULE_X->getHandler('category')->table} t2 ON t2.category_id = t1.category_id"//need add initVar('category_name') to Article class

and $this->MODULE_X is the helper class for module x.(module x can be the module itself)
The above is without hard-code and very understandable for everybody.

Then I like to discuss about your special need and your exampled code(which is off-topic so maybe it is better to be in another topic ):
Side note 1:
I dont know these codes you wrote comes from what module? but they are not good. One can do this without JOIN by enhancing that Easy way
Quote:

For example: displays list articles with category names.

Easy way:
1 - read articles from database by using article class
2 - for every article object do access to database by using category class

why do you (or that module developer) think you cannot follow that easy way more effective and with much less codes than the JOIN way?
It can be done just by two queries.
1 - read articles from database by using article handler class
SELECT FROM {$this->table}

2- for all above article category Ids do access to database by using category handler class.
SELECT category_idcategory_name FROM {$this->tableWHERE category_id IN {$articles_category_id}


which $articles_category_id is all category ids you get from the first query.

To implement the above you even dont need to write special function (function &getObjects($args))

All can be done in front side
I commented the below code for you to see how it can be done with ease
$articleH xoops_getmodulehandler('article''MODULE');
$categoryH xoops_getmodulehandler('category''MODULE');
$criteriaArticle = new CriteriaCompo();
//  continue your criteria here for $criteriaArticle
// ...

// START first query for articles
// remember getAll($criteria = null, $fields = null, $asObject = true, $id_as_key = true)
$articleObjs $articleH->getAll($criteriaArticle);
// END first query for articles

$articles_category_id = array();
foreach (
$articleObjs as $artObj) {
    
$articles_category_id[] = $artObj->getVar("category_id");
    
// you can do any other thing here with articles!!!
    // ...
}
// START second query for category names
$criteriaCat = new CriteriaCompo();
$criteriaCat->add(new Criteria("category_id""(" implode(", "$articles_category_id) . ")""IN"), "AND");
// you can add what fields you need here :D
$catFields = array("category_id","category_name");
$catNames $categoryH->getAll($criteriaCat$catFieldsfalse);
// END second query for category names

// FINISH!!!
// usage: $catNames[$artObj->getVar("category_id")]["category_name"]

As i said before the above code is:
1- most effective code to do the job (more than JOIN) 2 simple queries are better than one query with JOIN.
2- no need to write any code in the handler class
3- can be extend very easy. eg: if you need category_created time you can add the field.

Side note 2:
Anyway IMO your query will not work because you didnt add db prefix:
instead of:
mymodule_article

you have to use:
$this->db->prefix('mymodule_article')

but using hadlers and helper class you will not need to think about such a annoying thing (like i must add prefix here or not)

Side note 3:
If you are very tight for using only one query you should add one field category_name to articles table.
//need add initVar('category_name') to Article class

As the above comment after your query suggested, If you really need to display the category name alongside an article in many links of your module it is better to add another field called "category_name" in mymodule_article table.
But generally you dont need that and i dont advise it




66
irmtfan
Re: Xoopspoll v1.40 Beta 1 - Ready for testing
  • 2013/5/24 2:57

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


sorry forget what i wrote in the last post about the way to find newbb version.
you can simply use method_exists to find if it is the newbb version which support any poll module.
$topic_handler xoops_getmodulehandler('topic''newbb'); 
if (
method_exists('NewbbTopicHandler''findPollModule')) {
    
$poll_module_in_newbb $topic_handler->findPollModule();
} else {
    
$poll_module_in_newbb "xoopspoll"// it is hard-coded no clone is supported
}

if(
$poll_module_in_newbb == $thisModule->getVar("dirname") ) {
 
// do some actions like uninstall, ...
}

So IMO you dont need to write any extra code because as i said all old newbb versions only support hard-coded "xoopspoll" dirname.

Note: we should use the above findPollModule only in OnInstall, OnUpdate and OnUninstall process because it is an in depth checking to find the newbb poll module.
In common usages you can search for and use new config "poll_module" in newbb.

Quote:

until you are able to merge your changes into the trunk.

Technically merging any old newbb version < 4.4 Alfred (include newbb 2, newbb 3.08 and trunk) with the latest irmtfan branch is as simple as copying files.
But newbb needs a team of developers include at least one core developer and an official badge.

Quote:

change date handling to use the PHP DateTime class support that was implemented back in PHP 5.2


By adding any enhancements in the future, xoops core will always support its own function "formatTimestamp" or method "XoopsLocal::formatTimestamp"
So all developers should use it now and their modules will be work in any newer version of xoops.

Edit:
A side note:
this line will be dangerous for the current cloning method in xoopspoll using smartclone:
$poll_module_in_newbb "xoopspoll"// it is hard-coded no clone is supported

because it should be remained as "xoopspoll" in all xoopspoll clones!!!
That is show the necessity of using a helper class and try to remove any instance of dirname (here: xoopspoll) from codes as much as possible.
so in the clone process you dont need to change strtolower($dirname) anymore.





67
irmtfan
Re: Problems with displaying stories after moving to another server
  • 2013/5/24 2:51

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Also you should look at your database tables to be sure that all tables are exist.

Then you must turn php debug on and find all errors, warning, sql, ...



68
irmtfan
Re: Xoopspoll v1.40 Beta 1 - Ready for testing
  • 2013/5/23 6:35

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Quote:

I'll have to duplicate something similar to your findPollModule() method so xoopspoll will work with the newbb trunk code too - until you are able to merge your changes into the trunk.


I forgot to mention that.
instead of all other modules in svn, newbb trunk is very old, full of bugs and IMO bad working version and it seems nobody is using this version now. So leave newbb trunk and just stick on 2 versions:
1- Alfred newbb 4.3 stable version (of course still has many bugs) and maybe newbb 4.4
http://www.simple-xoops.de/projekt/2:1-Forum_-_newBB.html

2- irmtfan newbb 4.33 RC7

but to support Alfred and irmtfan < version 4.33 you dont need to write codes because newbb Alfred amd irmtfan < 4.33 only support hard-coded "xoopspoll" and "umfrage" dirnames and not any clone.
to recognize irmtfan version >= 4.33 you can use "author":
$modversion['author'] = "Marko Schmuck (predator) / D.J. (phppp) / Alfred(dhcst) / xoops.org (irmtfan)";
or i can add another special recognition.

IMO and based on tests, current irmtfan branch is the most stable newbb version. I found and solved many bugs in newbb1, newbb2, newbb 3.08 and ...



69
irmtfan
Re: Xoopspoll v1.40 Beta 1 - Ready for testing
  • 2013/5/23 2:06

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


@zyspec : As you can see i used (copy/paste) many of your codes for xoopspoll 1.4 functionality in newbb located in xoopspoll/extras/newbb_4x/irmtfan (so you can remove that extra in your next versions) Therefore thanks to your codes, I didnt have to put time to learn your xoopspoll 1.4 functionality. Of course there were some bugs which i solved. so it was a good team work. After that I decided to make newbb work with any poll module regardless of version or dirname so i did that too. Quote:
That's no longer true (could be a clone of xoopspoll or umfrage). I'll have to create a function to determine if the polls are associated with 'this' copy of xoopspoll and then take the appropriate actions.
Yes previously it was hardcoded to "xoopspoll" Today i add a function to find poll module that is in used in the current newbb installation. This function is totally reliable and you can use it. so you dont need to put time on it.
// START irmtfan findPollModule
    /**
     * find poll module that is in used in the current newbb installtion.
     * @access public
     * @param array $pollDirs dirnames of all active poll modules
     * @return string $dir_def | true | false
     *    $dir_def: dirname of poll module that is in used in the current newbb installtion.
     *    true: no poll module is installed | newbb has no topic with poll | newbb has no topic
     *    false: errors (see below xoops_errors)
     */
    
public function findPollModule($pollDirs = array()) {
        if(empty(
$pollDirs)) $pollDirs $this->getActivePolls();
        if(empty(
$pollDirs)) return true;
        
// if only one active poll module still we need to check!!!
        //if(count($pollDirs) == 1) return end($pollDirs);
        
$topicPollObjs $this->getAll(new Criteria("topic_haspoll"1));
        if(empty(
$topicPollObjs)) return true// no poll or no topic!!!
        
foreach($topicPollObjs as $tObj) {
            
$poll_idInMod 0;
            foreach(
$pollDirs as $dirname) {
                
$pollObj $tObj->getPoll($tObj->getVar("poll_id"), $dirname);
                if(
is_object($pollObj) && ($pollObj->getVar("poll_id") == $tObj->getVar("poll_id"))) {
                    
$poll_idInMod++;
                    
$dir_def $dirname;
                }
            }
            
// Only one poll module should has this poll_id
            // if 0 there is an error
            
if($poll_idInMod == 0) {
                
xoops_error("Error: Cannot find poll module for poll_id='{$tObj->getVar('poll_id')}'");
                return 
false;
            }
            
// if 1 => $dir_def is correct
            
if($poll_idInMod == 1) {
                return 
$dir_def;
            }
            
// if more than 1 continue
        
}
        
// if there is some topics but no module or more than one module have polls
        
xoops_error("Error: Cannot find poll module that is in used in newbb!!! <br><br>You should select the correct poll module yourself in newbb > preferences > poll module setting.");
        return 
false;
    }
    
// END irmtfan findPollModule
so the usage is as simple as this:
$topic_handler xoops_getmodulehandler('topic''newbb');

            
$poll_module_in_use $topic_handler->findPollModule();
as you can see the output is informative: Quote:
* $dir_def: dirname of poll module that is in used in the current newbb installation. * true: no poll module is installed | newbb has no topic with poll | newbb has no topic * false: errors (see below xoops_errors)
I used that in 'OnUpdate' and 'preferences saving' processes to make sure the "poll_module" config will be saved correctly. I changed the version to newbb 4.33 and RC7:http://svn.code.sf.net/p/xoops/svn/XoopsModules/newbb/branches/irmtfan/newbb/ Quote:
the 'hard coded date() functoin' usage - I thought I'd removed those where applicable.
yes. eg: in xoopspoll/class/renderer.php line 173 should be replaced by this
$xuEndFormatted formatTimeStamp($xuEndTimestamp);
I think it would be the best solution for you to write a helper class and be free from any dirname, config, handler, date format, ... in next version of xoopspoll helper really reduce my coding time in userlog.



70
irmtfan
Re: Xoopspoll v1.40 Beta 1 - Ready for testing
  • 2013/5/22 8:04

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Quote:
I don't understand your concern about additional queries. All it should take is adding something like $criteria->add(new Criteria('poll_mid', $poll_mid, '=')); to an existing query.
i think in any case a new field means more time/load in select, update , ... 1- in existing query we have to modify all existing queries. needs time. 2- sometimes we should add new query. If we use dirname or mid field we should drop config "poll_module" so sometimes we should recheck to find if poll_module is still exist or active. for example when i want to delete a poll after delete the topic. now i just write a standalone function.
public function deletePoll($poll_id)
    {
        if (empty(
$poll_id)) return false;
        
$module_handler = &xoops_gethandler('module');
        
$newbbConfig newbb_load_config();
        
$pollModuleHandler =& $module_handler->getByDirname($newbbConfig["poll_module"]);
        if (!
is_object($pollModuleHandler)  || !$pollModuleHandler->getVar('isactive')) return false;
        
// new xoopspoll module
        
if($pollModuleHandler->getVar("version") >= 140) {
            
$poll_handler =& xoops_getmodulehandler('poll'$newbbConfig["poll_module"]);
            if (
false !== $poll_handler->deleteAll(new Criteria('poll_id'$poll_id'='))) {
                
$option_handler =& xoops_getmodulehandler('option'$newbbConfig["poll_module"]);
                
$option_handler->deleteAll(new Criteria('poll_id'$poll_id'='));
                
$log_handler =& xoops_getmodulehandler('log'$newbbConfig["poll_module"]);
                
$log_handler->deleteAll(new Criteria('poll_id'$poll_id'='));
                
xoops_comment_delete($GLOBALS['xoopsModule']->getVar('mid'), $poll_id);
            }
        
// old xoopspoll or umfrage or any clone from them
        
} else {
            
$classPoll $this->loadOldPoll();
            
$poll = new $classPoll($poll_id);
            if ( 
$poll->delete() != false ) {
                
$classOption $classPoll "Option";
                
$classOption::deleteByPollId($poll->getVar("poll_id"));
                
$classLog $classPoll "Log";
                
$classLog::deleteByPollId($poll->getVar("poll_id"));
                
xoops_comment_delete($xoopsModule->getVar('mid'), $poll->getVar('poll_id'));
            }
        } 
// end poll_module new or old
        
return true;
    }
but if we drop config i have to check the poll_module field. I think about dropping topic_haspoll field. this field is useless we can just have a poll_id. if poll_id > 0 => topic has a poll I dont understand why old developers add this field. Quote:
I'm not sure how this could be implemented effectively - but maybe you have some ideas.
for sure! see newbb/xoops_version.php
// START irmtfan add a poll_module config
$pollDirs = array();
$dir_def 0;
// if in install, update
if($isModuleAction) {
    
$allDirs xoops_getActiveModules();
    foreach(
$allDirs as $dirname) {
        
// pollresults.php file is exist in all xoopspoll versions and umfrage versions
        
if(file_exists($GLOBALS['xoops']->path("modules/" $dirname "/pollresults.php"))) {
            
$pollDirs[$dirname] = $dirname;
        }
    }
    
// priorities for default poll module : 1- xoopspoll 2- last element in array 3- if no poll module => 0
    
$dir_def = !empty($pollDirs) ? (!empty($pollDirs["xoopspoll"]) ? $pollDirs["xoopspoll"] : end($pollDirs))
                                 : 
0;
}

$isPref = (
    
// action module "system"
    
is_object($GLOBALS["xoopsModule"]) && "system" == $GLOBALS["xoopsModule"]->getVar("dirname""n")
    &&
    
// current action
    
$_REQUEST['fct'] == "preferences"
    
);
// if in pref AND click on save AND 'poll_module' != 0
if($isPref && !empty($_POST['poll_module'])) {
    
$hModConfig xoops_gethandler('config');
    
$criteria = new CriteriaCompo();
    
$criteria->add(new Criteria('conf_name'"poll_module""="), "AND");
    
$criteria->add(new Criteria('conf_formtype'"select""="), "AND"); // not hidden
    
$criteria->add(new Criteria('conf_id'"(" implode(", ",$_POST['conf_ids']). ")""IN"), "AND");
    
$pollOptions $hModConfig->getConfigs($criteria);
    
$pollOptions end($pollOptions);
    if(
is_object($pollOptions) && $pollOptions->getVar("conf_value") != "0") {
        
$topic_handler xoops_getmodulehandler('topic'$modversion['dirname']);
        
$topicPolls $topic_handler->getCount(new Criteria("topic_haspoll"1));
        if(
$topicPolls 0) {
            
$pollOptions->setVar("conf_formtype""hidden");
            
$result $hModConfig->insertConfig($pollOptions);
            if(!
$result) {
                
//echo "error: poll_module is in danger!!!";
            
}
        }
    }
}
xoops_loadLanguage('admin'$modversion['dirname']);
$i count($modversion['config']); // temporary until change the whole xoops_version config
$i++;
$modversion['config'][$i]['name'] = 'poll_module';
$modversion['config'][$i]['title'] = '_AM_NEWBB_POLLMODULE';
$modversion['config'][$i]['description'] = '_AM_NEWBB_POLLMODULE';
$modversion['config'][$i]['valuetype'] = 'text';
$modversion['config'][$i]['default'] = $dir_def;

if(
count($pollDirs) <= 1) {
    
$modversion['config'][$i]['formtype'] = 'hidden';
} else {
    
$modversion['config'][$i]['formtype'] = 'select';
    
$modversion['config'][$i]['options'] = $pollDirs;
}
// END irmtfan add a poll_module config
and $isModuleAction is:
$isModuleAction = @(
        
// action module "system"
        
!empty($GLOBALS["xoopsModule"]) && "system" == $GLOBALS["xoopsModule"]->getVar("dirname""n")
        &&
        
// current dirname
        
($dirname == $_POST["dirname"] || $dirname == $_POST["module"])
        &&
        
// current op 
        
("update_ok" == $_POST["op"] || "install_ok" == $_POST["op"] || "uninstall_ok" == $_POST["op"])
        &&
        
// current action
        
"modulesadmin" == $_POST["fct"]
        );
That is reliable way. - in update and install it will check and add config. if there is just one poll the config will be hidden. if there is more than one poll module it will select with this priority: 1- xoopspoll 2- last element in array ps: we can leave all OnInstall, OnUpdate and OnUninstall functions and use this method. It will be very useful to make a module like xoopspoll clonable with a simple rename of dirname. even it will be possible to update a clone "blabla" using original "xoopspoll" - when user goes to pref and click on submit. it will check the "poll_module" config and find if there is a topic with poll. then it will hide the config. Note: currently it is not possible to find the poll module in newbb installations before most recent version (version 4.32) but we can add some guess to the above code. Quote:
if he still plans to actively develop newbb.
AFAIK Alfred continue developing newbb but some adding/dropping features are not acceptable for me. eg: he dropped the user moderation in forums and replace it with group moderation. It is very bad. I need to let one user to be a moderator in one forum without any additional group or permissions. Quote:
You could find the poll module(s) by looking for a 'signature' (file name, class, etc.) that is consistent between poll modules.
I used pollresults.php. it is consistent in all xoopspoll and umfrage versions and all current and future clones. do you have better idea? you used hard-code date() function in the current xoopspoll 1.4. do you want to consider using formatTimeStamp or better XoopsLocal::formatTimeStamp for formatted times in templates? in result forms you should use it. but in edit forms we still should add the hejira date in JQuery date time picker @redheadedrod: Quote:
What happens now if you remove the poll module? Does newbbs recognize this?
because newbb and all other poll modules are completely separated modules we cannot add many tight relations. but newbb will check the poll module existence every time wants to do something. but if somebody uninstall xoopspoll newbb will not understand it. (that is why zyspec add the functionality to xooppoll) I think xoopspoll will not understand whether newbb is uninstalled too




TopTop
« 1 ... 4 5 6 (7) 8 9 10 ... 284 »



Login

Who's Online

199 user(s) are online (142 user(s) are browsing Support Forums)


Members: 0


Guests: 199


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits