Using PHP code to close a MOD

Started by bigjoe11a, October 31, 2012, 08:49:06 PM

Previous topic - Next topic

bigjoe11a

Quote from: Kays on November 02, 2012, 11:34:31 PM
Take a look at the permissions in your code.


'bjblog_post' => array(false, 'bjblog', 'bjblog'),
'bjblog_comm' => array(false, 'bjblog', 'bjblog'),
'bjblog_blog' => array(false, 'bjblog', 'bjblog'),
'bjblog_view' => array(false, 'bjblog', 'bjblog'),


That should be:


'post_bjblog' => array(false, 'bjblog', 'bjblog'),
'comm_bjblog' => array(false, 'bjblog', 'bjblog'),
'blog_bjblog' => array(false, 'bjblog', 'bjblog'),
'view_bjblog' => array(false, 'bjblog', 'bjblog'),



Sorry, I changed that a long time ago. The 1st ones right, and the 2nd one is wrong. I have every thing set to the 1st one.

This is how it should look.

<?php
if (!defined('SMF'))
die('Hacking attempt...');

function 
BJBlog_add_hook(&$actionArray) {
$actionArray['bjblog'] = array('bjblog.php''bjblogMain');
}

function 
BJBlogAddPermissions(&$permissionGroups, &$permissionList, &$leftPermissionGroups, &$hiddenPermissions, &$relabelPermissions) {

loadLanguage('BJBlog');

$permissionList['membergroup'] = array_merge(
array(
'bjblog_post' => array(false'bjblog''bjblog'),
'bjblog_comm' => array(false'bjblog''bjblog'),
'bjblog_blog' => array(false'bjblog''bjblog'),
'bjblog_view' => array(false'bjblog''bjblog'),
),
$permissionList['membergroup']
);

}

function 
BJBlog_load_permissions(&$permissionGroups, &$permissionList, &$leftPermissionGroups, &$hiddenPermissions, &$relabelPermissions)
{
global $context;

    
loadLanguage('BJBlog');
    
$permissionList['membergroup'] += array(
'bjblog_view' => array(false'bjblog''bjblog'),
'bjblog_blog' => array(false'bjblog''bjblog'),
'bjblog_post' => array(false'bjblog''bjblog'),
'bjblog_comm' => array(false'bjblog''bjblog'),        
);
    
}

function 
ModifyBJBlogModSettings($return_config false) {
    
    
$context[$context['admin_menu_name']]['tab_data'] = array(
'title' => $txt['bjblog_admin_modifications'],
'help' => 'modsettings',
'description' => $txt['bjblog_mod_settings_desc'],
'tabs' => array(
'bjblog' => array(
),
),
);
    
    
}

function 
BJBlog_Settings(&$config_vars) {
    
        global 
$txt;
    
    
$config_vars[] = $txt['bjblog_header'];    
    
$config_vars[] = array('check''enabled_bjblog');
    
$config_vars[] = array('int''bjblog_page_per_post');
    
$config_vars[] = array('int''bjblog_page_per_comm');
    
    
}


function 
BJBlog_who() {
    
    global 
$txt;
    
    
$BJBLOG '<a href="http://www.df-barracks.com">' $txt['bjblog_verison'].'</a>';
    
    return 
$BJBLOG;
    
    
}


?>


SMF Forums http://www.df-barracks.com Where gamers go.

Kays

NO!!  >:(

For the $txt strings previously posted. The first set will not work. You need to use the second set so that the permission name is part of the index of the $txt string.

For:


$txt['permissionname_view_bjblog'] = 'Allowed to View Blogs';
$txt['permissionname_blog_bjblog'] = 'allowed to Blog';
$txt['permissionname_post_bjblog'] = 'Allowed to Post to a Blog';
$txt['permissionname_comm_bjblog'] = 'Allowed to post comments';


You need to use:


'post_bjblog' => array(false, 'bjblog', 'bjblog'),
'comm_bjblog' => array(false, 'bjblog', 'bjblog'),
'blog_bjblog' => array(false, 'bjblog', 'bjblog'),
'view_bjblog' => array(false, 'bjblog', 'bjblog'),


Which is how the permissions were when you originally posted them

Or for what you just posted then you need to use:


$txt['permissionname_bjblog_view'] = 'Allowed to View Blogs';
$txt['permissionname_bjblog_blog'] = 'allowed to Blog';
$txt['permissionname_bjblog_post'] = 'Allowed to Post to a Blog';
$txt['permissionname_bjblog_comm'] = 'Allowed to post comments';


If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

bigjoe11a

Like I said, I changed them all. They now have the bjblog_ comes 1st. and then the permissionname_

look again. I read some where they said I should put the mod name 1st and use the mod name in the $txt and any thing else.  That's why I was up to 3:00 am last night changing them, I still have the $txt in the source and in the template to change. I need to add a bjblog_ in front of all of them and change them in my code.

Any way this is how I have my code as of now.

My Hook

<?php
// If SSI.php is in the same place as this file, and SMF isn't defined, this is being run standalone.
if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
require_once(dirname(__FILE__) . '/SSI.php');
// Hmm... no SSI.php and no SMF?
elseif (!defined('SMF'))
die('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');



global 
$modSettings$smcFunc;

// Add your mod setting to the database
if(!isset($modSettings['bjblog_enabled']))
$smcFunc['db_query']('''
INSERT INTO {db_prefix}settings
VALUES ("bjblog_enabled", 1)'
,
array()
);
        

// Add your mod setting to the database
if(!isset($modSettings['bjblog_page_per_post']))
$smcFunc['db_query']('''
INSERT INTO {db_prefix}settings
VALUES ("bjblog_page_per_post", 5)'
,
array()
);


// Add your mod setting to the database
if(!isset($modSettings['bjblog_page_per_comm']))
$smcFunc['db_query']('''
INSERT INTO {db_prefix}settings
VALUES ("bjblog_page_per_comm", 5)'
,
array()
);



add_integration_function('integrate_pre_include''$sourcedir/Subs-bjblog.php');
add_integration_function('integrate_actions''bjblog_add_hook');
add_integration_function('integrate_load_permissions''BJBlogAddPermissions');
add_integration_function('integrate_general_mod_settings''BJBlog_Settings');
?>



My Subs-bjblog.php

<?php
if (!defined('SMF'))
die('Hacking attempt...');

function 
BJBlog_add_hook(&$actionArray) {
$actionArray['bjblog'] = array('bjblog.php''bjblogMain');
}

function 
BJBlogAddPermissions(&$permissionGroups, &$permissionList, &$leftPermissionGroups, &$hiddenPermissions, &$relabelPermissions) {

loadLanguage('BJBlog');

$permissionList['membergroup'] = array_merge(
array(
'bjblog_post' => array(false'bjblog''bjblog'),
'bjblog_comm' => array(false'bjblog''bjblog'),
'bjblog_blog' => array(false'bjblog''bjblog'),
'bjblog_view' => array(false'bjblog''bjblog'),
),
$permissionList['membergroup']
);

}

function 
BJBlog_load_permissions(&$permissionGroups, &$permissionList, &$leftPermissionGroups, &$hiddenPermissions, &$relabelPermissions)
{
global $context;

    
loadLanguage('BJBlog');
    
$permissionList['membergroup'] += array(
'bjblog_view' => array(false'bjblog''bjblog'),
'bjblog_blog' => array(false'bjblog''bjblog'),
'bjblog_post' => array(false'bjblog''bjblog'),
'bjblog_comm' => array(false'bjblog''bjblog'),        
);
    
}

function 
ModifyBJBlogModSettings($return_config false) {
    
    
$context[$context['admin_menu_name']]['tab_data'] = array(
'title' => $txt['bjblog_admin_modifications'],
'help' => 'modsettings',
'description' => $txt['bjblog_mod_settings_desc'],
'tabs' => array(
'bjblog' => array(
),
),
);
    
    
}

function 
BJBlog_Settings(&$config_vars) {
    
        global 
$txt;
    
    
$config_vars[] = $txt['bjblog_header'];    
    
$config_vars[] = array('check''enabled_bjblog');
    
$config_vars[] = array('int''bjblog_page_per_post');
    
$config_vars[] = array('int''bjblog_page_per_comm');
    
    
}


function 
BJBlog_who() {
    
    global 
$txt;
    
    
$BJBLOG '<a href="http://www.df-barracks.com">' $txt['bjblog_verison'].'</a>';
    
    return 
$BJBLOG;
    
    
}


?>



And last, This is what I have in my BJBlog language file. All so in my ManagePermissions.english.php



//SMF Permissions
$txt['permissionname_bjblog_view'] = 'Allowed to View Blogs';
$txt['permissionname_bjblog_blog'] = 'allowed to Blog';
$txt['permissionname_bjblog_post'] = 'Allowed to Post to a Blog';
$txt['permissionname_bjblog_comm'] = 'Allowed to post comments';


As you can see it was all changed


SMF Forums http://www.df-barracks.com Where gamers go.

Kays

But you changing the variable names in the middle of trouble shooting has made this a lot more confusing than it should be.

If there's still nothing showing, check your error log. There should be a an undefined index error which should give you a clue as to what's happening.

Can't help any more tonight as it's getting late. So good luck with this. :)

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

bigjoe11a

Well No, I told you that it is working, The $txt are displaying the required information. The problem is that the Title is missing and the help option, The '?' is missing all so. I need to find out how to add them. Then I can go on to settings.

and the only error I see in the error log is this



http://www.toppersbbs.info/smf/index.php?action=admin;area=permissions;pid=0
8: Undefined index: permissiongroup_bjblog
File: C:/www/vhosts/_static/toppers/smf/Sources/ManagePermissions.php
Line: 1646

And I have no idea what it has the permissiongroup_bjblog. I don't think I made that.

SMF Forums http://www.df-barracks.com Where gamers go.

Kays

Well, same as you. I don't always absorb what's been posted. :P


For the (?), again your $txt string needs to be properly formated. For this prefix the index with "permissionhelp_" 

$txt['permissionhelp_bjblog_view'] = 'This will Allowed to View Blogs etc etc';

Quote
And I have no idea what it has the permissiongroup_bjblog. I don't think I made that.

For that, "bjblog" needs to be added to $permissionGroups. And there I can't help you. So take a look at the post which explains permission and try to figure it out.

Btw, you have two functions for permissions which do essentially the same thing. Since BJBlogAddPermissions() isn't called. You can eliminate it.


If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

bigjoe11a

QuoteWell, same as you. I don't always absorb what's been posted. :P

If I said some thing to piss you off, Sorry, Remember I don't all ways under stand every thing I read. And I have to read it again and again to try and under stand.

Any way your telling me that I have 2 functions that do the same thing, Can you tell me what function is the 2nd one is. Sense I was told to add the BJBlogAddPermissions(); function and this should be called.

And way the last thing with the permissions is the title. The title is missing at the top. How do I add that.

SMF Forums http://www.df-barracks.com Where gamers go.

Kays

these two functions appear to be similar.


function BJBlogAddPermissions(&$permissionGroups, &$permissionList, &$leftPermissionGroups, &$hiddenPermissions, &$relabelPermissions) {

loadLanguage('BJBlog');

$permissionList['membergroup'] = array_merge(
array(
'bjblog_post' => array(false, 'bjblog', 'bjblog'),
'bjblog_comm' => array(false, 'bjblog', 'bjblog'),
'bjblog_blog' => array(false, 'bjblog', 'bjblog'),
'bjblog_view' => array(false, 'bjblog', 'bjblog'),
),
$permissionList['membergroup']
);

}

function BJBlog_load_permissions(&$permissionGroups, &$permissionList, &$leftPermissionGroups, &$hiddenPermissions, &$relabelPermissions)
{
global $context;

    loadLanguage('BJBlog');
   
$permissionList['membergroup'] += array(
'bjblog_view' => array(false, 'bjblog', 'bjblog'),
'bjblog_blog' => array(false, 'bjblog', 'bjblog'),
'bjblog_post' => array(false, 'bjblog', 'bjblog'),
'bjblog_comm' => array(false, 'bjblog', 'bjblog'),       
);
   
}


And only the first is called.


add_integration_function('integrate_pre_include', '$sourcedir/Subs-bjblog.php');
add_integration_function('integrate_actions', 'bjblog_add_hook');
add_integration_function('integrate_load_permissions', 'BJBlogAddPermissions');
add_integration_function('integrate_general_mod_settings', 'BJBlog_Settings');


So is the second one needed?

Quote
And way the last thing with the permissions is the title. The title is missing at the top. How do I add that.

Looking at the managePermissions language file I see that $txt strings for the permission group name is formatted in a special way also. So start of by adding the following to the language strings for the permissions.


$txt['permissiongroup_bjblogl'] = 'BJ Blogl';

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

bigjoe11a

I removed this function


function BJBlog_load_permissions(&$permissionGroups, &$permissionList, &$leftPermissionGroups, &$hiddenPermissions, &$relabelPermissions)
{
global $context;

    loadLanguage('BJBlog');
   
$permissionList['membergroup'] += array(
'bjblog_view' => array(false, 'bjblog', 'bjblog'),
'bjblog_blog' => array(false, 'bjblog', 'bjblog'),
'bjblog_post' => array(false, 'bjblog', 'bjblog'),
'bjblog_comm' => array(false, 'bjblog', 'bjblog'),       
);
   
}


and I removed this line


add_integration_function('integrate_load_permissions', 'BJBlogAddPermissions');


and I added this next line to the language file for my mod


$txt['permissiongroup_bjblog'] = 'BJ Blog';


I'll run the hook again. and ......COOL. That works. Thanks Kays. Look at my new permissions group



SMF Forums http://www.df-barracks.com Where gamers go.

bigjoe11a

Before I started another post. The last thing on my list is Settings. Can you help with those. The same thing as for the permissions. The tab is missing and the $txt['']; are missing and I don't know where to add them at. Here's a settings page and i know that's wrong.

SMF Forums http://www.df-barracks.com Where gamers go.

Kays

[quote]
and I removed this line

Code: [Select]

add_integration_function('integrate_load_permissions', 'BJBlogAddPermissions');



Since that function still exists. That line should remain as it's what calls that function. But I don't understand why it's loading unless you call that elsewhere.

For the $txt strings for the settings. Just use the setting name as the index with no prefix this time.

The reason the tab is missing is that you are adding it to the general modifications settings. To add it to a separate section you should use integrate_modify_modifications instead. Then $context['post_url'] & $context['settings_title'] are used to show the tabs.

Take a look at my member notepad mod since that's where it places it's settings. Use that as a guide since you are also missing the code to save the settings. Also for a more detailed description of how that some of that works. Look in manageSever.php.




If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

bigjoe11a

Nope, This line


add_integration_function('integrate_load_permissions', 'BJBlogAddPermissions');


was removed The only code's that  are left in my add_hook.php are,


add_integration_function('integrate_pre_include', '$sourcedir/Subs-bjblog.php');
add_integration_function('integrate_actions', 'bjblog_add_hook');
add_integration_function('integrate_general_mod_settings', 'BJBlog_Settings');


and I'll download and look at your textpad and see what I can find. I hope I can under stand it.


SMF Forums http://www.df-barracks.com Where gamers go.

Kays

That should be added back.

Quoteand I'll download and look at your textpad and see what I can find. I hope I can under stand it.

Do look at it and try to use that as a reference since it does a lot stuff which is similar to a blog.

http://custom.simplemachines.org/mods/index.php?mod=2351


If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

bigjoe11a

Quote from: Kays on November 03, 2012, 03:23:05 PM
That should be added back.

Quoteand I'll download and look at your textpad and see what I can find. I hope I can under stand it.


Well then I just went over what you posted above it you said that the 2 functions that are defined that only one of them runs. Only the 1st one. Not the 2nd one. So sense the 2nd one didn't run I took it out. So now your saying I should add it back in. I'm confused..


Do look at it and try to use that as a reference since it does a lot stuff which is similar to a blog.

http://custom.simplemachines.org/mods/index.php?mod=2351



Well then I just went over what you posted above it you said that the 2 functions that are defined that only one of them runs. Only the 1st one. Not the 2nd one. So sense the 2nd one didn't run I took it out. So now your saying I should add it back in. I'm confused..

SMF Forums http://www.df-barracks.com Where gamers go.

Kays

That line is not a function. But rather a call to a function so that the specified function is executed when the hooks are called.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

bigjoe11a

Quote from: Kays on November 03, 2012, 04:01:03 PM
That line is not a function. But rather a call to a function so that the specified function is executed when the hooks are called.

Well sense I don't under stand. I don't know what to do.
SMF Forums http://www.df-barracks.com Where gamers go.

Kays

Just re-add that line only and don't worry about it. :)

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

bigjoe11a

Quote from: Kays on November 03, 2012, 04:33:19 PM
Just re-add that line only and don't worry about it. :)

I take it this is the only line you wanted me to add back into the add_hook.php file. All done.


add_integration_function('integrate_load_permissions', 'BJBlogAddPermissions');


And so this is what it looks like.


add_integration_function('integrate_pre_include', '$sourcedir/Subs-bjblog.php');
add_integration_function('integrate_actions', 'bjblog_add_hook');
add_integration_function('integrate_load_permissions', 'BJBlogAddPermissions');
add_integration_function('integrate_general_mod_settings', 'BJBlog_Settings');


And as all ways. I'm only getting parts of you settings. So I don't know what to do.. Here's some of what I have and I'm not sure if this is right or wrong.. I just don't know what to do.


function BJBlog_Settings(&$config_vars) {
     
  $subAction['bjblog'] = 'ModifyBJBlogModSettings';
}


function ModifyBJBlogModSettings($return_config = false) {
   
   
    global $txt, $scripturl, $context, $settings, $sc, $modSettings, $txt;
   
    // The other options you have above this Kays. I have no idea
    $config_vars = array(
                   array('check', 'enabled_bjblog'),
                   array('int', 'bjblog_page_per_post'),
                   array('int', 'bjblog_page_per_comm'),
);
   
if ($return_config)
return $config_vars;
       
       

$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=bjblog';
$context['settings_title'] = $txt['BJBlog_Settings_Title'];

if (isset($_GET['save']))
{
checkSession();
saveDBSettings($config_vars);
redirectexit('action=admin;area=modsettings;sa=bjblog');
}

prepareDBSettingContext($config_vars);
   
}


SMF Forums http://www.df-barracks.com Where gamers go.

Kays

Off hand that looks OK. Don't worry about the extra code at the beginning. That's there to allow the menu button to be placed where the user wishes. It goes with some of the code for the button.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

bigjoe11a

Well then I don't know what to do then. I ran the hook again and now all my settings are gone. So I'm stump at what to do.

SMF Forums http://www.df-barracks.com Where gamers go.

Advertisement: