Skip to main content
Topic: What replaces $smfunc and others? (Read 4233 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

What replaces $smfunc and others?

Converting some mods from SMF. I wish to know what replaces $smfunc?

What are other differences that should be noted?

Re: What replaces $smfunc and others?

Reply #1

Found it. It is $db. $smcFunc['code'] is now $db>code.

What about $smfhooks? Is it now just $hook? Can anybody confirm this?

Re: What replaces $smfunc and others?

Reply #2

Remember that $smcFunc was a global variable, while $db is "local" and you need to:
Code: [Select]
$db = database();
before the first time you use it in a function. ;)

Also, not all the functions in $smcFunc have been replaced by database(), only those related to the database. The functions related to strings are in Utils, so for example $smcFunc['htmlspecialchars'] is now Utils::htmlspecialchars.

As far as I know $smfhooks has never been used in SMF... an example?
Bugs creator.
Features destroyer.
Template killer.

Re: What replaces $smfunc and others?

Reply #3

Quote from: emanuele – Remember that $smcFunc was a global variable, while $db is "local" and you need to:
Code: [Select]
$db = database();
before the first time you use it in a function. ;)

Also, not all the functions in $smcFunc have been replaced by database(), only those related to the database. The functions related to strings are in Utils, so for example $smcFunc['htmlspecialchars'] is now Utils::htmlspecialchars.

Thank you very much. This is a very useful information.

Quote from: emanuele – As far as I know $smfhooks has never been used in SMF... an example?

Oh yes. This relates to subforums mod that I am in the mid of converting.  The code is as follows:

Code: [Select]
// get the hooks from database
$smfhooks = array();
$request = $smcFunc['db_query']('', '
 SELECT variable, value FROM {db_prefix}settings
 WHERE variable IN ({array_string:hooks})',
 array('hooks' => array_keys($hooklist))
);
if($smcFunc['db_num_rows']($request) > 0)
{
 while($row = $smcFunc['db_fetch_assoc']($request))
 $smfhooks[$row['variable']] = $row['value'];
 $smcFunc['db_free_result']($request);
}

// update the hooks
foreach($hooklist as $hookname => $value)
{
 if(isset($smfhooks[$hookname]))
 $smfhooks[$hookname] = trim($hooklist[$hookname] .','. trim(str_replace($value, '', $smfhooks[$hookname]), ','), ',');
 else
 $smfhooks[$hookname] = trim($value);

 $smcFunc['db_insert']('replace', '
 {db_prefix}settings',
 array('variable' => 'string', 'value' => 'string'),
 array($hookname, $smfhooks[$hookname]),
 array()
 );
}

So, is replacing it with $hook correct?

Re: What replaces $smfunc and others?

Reply #4

$smfhooks is a variable used by the subforums mod, so you can call it whatever you want. ;)

BTW, I'm not sure why you (I mean the mod) is doing a "raw" query to insert the hooks when there is the function add_integration_function.
This is enough:
Code: [Select]
$hooklist = array(
'integrate_pre_include' => '$sourcedir/SubForums/Subforums.php',
'integrate_admin_areas' => 'Subforums_AdminMenu',
'integrate_register' => 'Subforums_Register',
);

foreach($hooklist as $hook => $value)
add_integration_function($hook, $value);
Bugs creator.
Features destroyer.
Template killer.

Re: What replaces $smfunc and others?

Reply #5

Quote from: emanuele – The functions related to strings are in Utils, so for example $smcFunc['htmlspecialchars'] is now Utils::htmlspecialchars.
I tried changing this $context['forum_name_html_safe'] = $smcFunc['htmlspecialchars'] to $context['forum_name_html_safe'] = Utils::htmlspecialchars but it causes error. System says: PHP Fatal error:  Class 'Utils' not found.

Why is that? I already insert $db = database(); before it but the error remains.


Got that one. It is Util without s.

What replaces $context['character_set'] in ElkArte?
Last Edit: December 08, 2014, 07:27:06 pm by ahrasis

Re: What replaces $smfunc and others?

Reply #6

QuoteWhat replaces $context['character_set'] in ElkArte?
Replace it with "UTF-8" since ElkArte is utf-8 only :)

Re: What replaces $smfunc and others?

Reply #7

Darn, I always exchange plurals... :-[
Bugs creator.
Features destroyer.
Template killer.

Re: What replaces $smfunc and others?

Reply #8

Thanks @Spuds , UTF-8 did the trick.

No problem @emanuele . I miss that all the time. ;) But I haven't the hook yet. I will change the hook to suggested, when this url problem is "fixed".

Anybody sees any problem with the url definition here?

Code: [Select]
global $SubforumFunc, $base_boardurl, $boardurl, $board_language, $language;

// define the url's
$base_boardurl = $boardurl;
$parts = parse_url($boardurl);
$boardurl = $parts['scheme'] .'://'. $_SERVER['SERVER_NAME'] .(!empty($parts['port']) ? ':'. $parts['port'] : '') . (!empty($parts['path']) ? $parts['path'] : '');
$board_language = $language;

Somehow, the subforum's url isn't respected. The mod is working except (I think) for this url part. :(