Well for some very strange reason I've got a sunday coder fever and managed to hack the hell out of a few addons. Now I've something which works fine. There's a working "Hot Discussions" link in the Discussions Filters, and popular discussions appear marked as Hot! next to their title.
I'd like to add two definitions, one for the number of comments making a discussion hot (above 20 in our case) and one for the Hot! text. But I don't know how :B
//put this at the beginning of default.php of that extension, or just before the code you posted
$Context->SetDefinition( 'HotCommentsSetting', '20' );
$Context->SetDefinition( 'TextHot', 'Hot!' );
//and alter the code you posted here to:
if( $Context->SelfUrl == 'index.php' ) {
function DiscussionGrid_DiscussionPages($DiscussionGrid) {
$Discussion = &$DiscussionGrid->DelegateParameters['Discussion'];
$DiscussionList = &$DiscussionGrid->DelegateParameters['DiscussionList'];
$DiscussionList = str_replace($Discussion->Name.'</a>', $Discussion->Name .'</a>'. ($Discussion->CountComments >$Context->GetDefinition('HotCommentsSetting') ?' <i>$Context->GetDefinition('TextHot')</i>':''), $DiscussionList);
} I just would like to say that using dictionary definitions for add-on settings is not the cleanest way, but I know that some add-ons use this. There is another way how to do it, but this would work
Thanks, I'll try this. However it looks like what I did earlier, and I was getting messages complaining about non-objects and stuff like that (sorry for not being more precise, I can't reproduce these errors right now). But it was late in the night...
I've seen you've released an extension for localisation purposes but I didn't understand everthing, what would you suggest for the cleanest way ?
@Ø: (this looks like a perl code :-) well, I don't know much about the issue you write, but check some other add-ons how they handle definitions
well, the second issue (clean way) I meant about only for settings, and number of comments making discussion Hot is rather a setting than a language data. For example there is a FeedReader extension reading RSS and displaying the feed in Control Panel on the left, but the RSS URL and some other settings is saved in dictionary definitions. I think it has been only temporary solution, because I can see there is some draft of settings panel for that. So I only think that in dictionary definitions there should be only language data :-)
About the clean way I'm not sure, because I'm still kind of newbie here and I haven't yet used it much, but I guess this should work: AddConfigurationSetting( $Context, 'HOT_COMMENTS_NUMBER', 20 ); somewhere at the beginning of default.php of the add-on
and you can read the settings any time later by: $Context->Configuration['HOT_COMMENTS_NUMBER']
so the code above would look like this: //put this at the beginning of default.php of that extension, or just before the code you posted
AddConfigurationSetting( $Context, 'HOT_COMMENTS_NUMBER', 20 );
$Context->SetDefinition( 'TextHot', 'Hot!' );
//and alter the code you posted here to:
if( $Context->SelfUrl == 'index.php' ) {
function DiscussionGrid_DiscussionPages($DiscussionGrid) {
$Discussion = &$DiscussionGrid->DelegateParameters['Discussion'];
$DiscussionList = &$DiscussionGrid->DelegateParameters['DiscussionList'];
$DiscussionList = str_replace($Discussion->Name.'</a>', $Discussion->Name .'</a>'. ($Discussion->CountComments > $Context->Configuration['HOT_COMMENTS_NUMBER'] ?' <i>$Context->GetDefinition('TextHot')</i>':''), $DiscussionList);
}
Then anybody can change the number in conf/settings.php and doesn't have to define language definition to change it
I've somewhat managed to write values like that in the configuration file for my Stuff Displayer extension. I think I'll try to do the same here. It will be more user-friendly to have administrator settings for specifying the "Hot" value and the text (or the image). Thanks for the input.
Comments
My problem is about dictionary definitions.
if( $Context->SelfUrl == 'index.php' ) { function DiscussionGrid_DiscussionPages($DiscussionGrid) { $Discussion = &$DiscussionGrid->DelegateParameters['Discussion']; $DiscussionList = &$DiscussionGrid->DelegateParameters['DiscussionList']; $DiscussionList = str_replace($Discussion->Name.'</a>', $Discussion->Name .'</a>'. ($Discussion->CountComments >20 ?' <i>Hot!</i>':''), $DiscussionList); }
I'd like to add two definitions, one for the number of comments making a discussion hot (above 20 in our case) and one for the Hot! text. But I don't know how :B
Any idea?
//put this at the beginning of default.php of that extension, or just before the code you posted $Context->SetDefinition( 'HotCommentsSetting', '20' ); $Context->SetDefinition( 'TextHot', 'Hot!' ); //and alter the code you posted here to: if( $Context->SelfUrl == 'index.php' ) { function DiscussionGrid_DiscussionPages($DiscussionGrid) { $Discussion = &$DiscussionGrid->DelegateParameters['Discussion']; $DiscussionList = &$DiscussionGrid->DelegateParameters['DiscussionList']; $DiscussionList = str_replace($Discussion->Name.'</a>', $Discussion->Name .'</a>'. ($Discussion->CountComments >$Context->GetDefinition('HotCommentsSetting') ?' <i>$Context->GetDefinition('TextHot')</i>':''), $DiscussionList); }
I just would like to say that using dictionary definitions for add-on settings is not the cleanest way, but I know that some add-ons use this.
There is another way how to do it, but this would work
I've seen you've released an extension for localisation purposes but I didn't understand everthing, what would you suggest for the cleanest way ?
well, the second issue (clean way) I meant about only for settings, and number of comments making discussion Hot is rather a setting than a language data.
For example there is a FeedReader extension reading RSS and displaying the feed in Control Panel on the left, but the RSS URL and some other settings is saved in dictionary definitions. I think it has been only temporary solution, because I can see there is some draft of settings panel for that.
So I only think that in dictionary definitions there should be only language data :-)
About the clean way I'm not sure, because I'm still kind of newbie here
AddConfigurationSetting( $Context, 'HOT_COMMENTS_NUMBER', 20 );
somewhere at the beginning of default.php of the add-on
and you can read the settings any time later by:
$Context->Configuration['HOT_COMMENTS_NUMBER']
so the code above would look like this:
//put this at the beginning of default.php of that extension, or just before the code you posted AddConfigurationSetting( $Context, 'HOT_COMMENTS_NUMBER', 20 ); $Context->SetDefinition( 'TextHot', 'Hot!' ); //and alter the code you posted here to: if( $Context->SelfUrl == 'index.php' ) { function DiscussionGrid_DiscussionPages($DiscussionGrid) { $Discussion = &$DiscussionGrid->DelegateParameters['Discussion']; $DiscussionList = &$DiscussionGrid->DelegateParameters['DiscussionList']; $DiscussionList = str_replace($Discussion->Name.'</a>', $Discussion->Name .'</a>'. ($Discussion->CountComments > $Context->Configuration['HOT_COMMENTS_NUMBER'] ?' <i>$Context->GetDefinition('TextHot')</i>':''), $DiscussionList); }
Then anybody can change the number in conf/settings.php and doesn't have to define language definition to change it
I've somewhat managed to write values like that in the configuration file for my Stuff Displayer extension. I think I'll try to do the same here. It will be more user-friendly to have administrator settings for specifying the "Hot" value and the text (or the image). Thanks for the input.