2012-11-17, 02:05 AM
I've got a plugin in development which ends up creating a variable such as {$thread['subject']}. The problem is, when I insert the variable into the template, it doesn't work. Here is my hook:
I found a post by euantor explaining that if you were hooking into the postbit, you needed to use &$post as an argument for your function, so I assumed that you needed to do that for this as well.
I have a feeling that I need to globalize thread at the the start of myhook(), but I've tried that and it didn't work.
Any ideas?
Okay, so I switched it to a {$thisvar} format, and it started appearing. Now all I have to do is figure out how to finish my plugin and make it work (currently it's reacting on my else statement, returning an error).
On a similar note, I have this if statement:
Everytime the script is executed, "three" is always being printed, never "four".
Any ideas on how to properly execute this?
I've been trying to fix this plugin for about 8 hours now. Can someone please tell me where I've gone wrong?
All I get in this is "No shortlink exists" (I insert the variable manually because me and the Changing Template system don't get along well. )
I've tried replacing {$tid} with {$thread['tid']}, but nothing's worked. I've also escaped virtually everything you can think of.
//Hooks
$plugins->add_hook("showthread_start", "myhook");
function myhook(&$thread)
{
global $mybb;
if ($mybb->settings['myplugin_enable'] == 1)
{
$thread['thisvar'] = $existingvar;
$thread['thatvar'] = $secondvar;
$thread['someothervar'] = $lastvar;
}
I found a post by euantor explaining that if you were hooking into the postbit, you needed to use &$post as an argument for your function, so I assumed that you needed to do that for this as well.
I have a feeling that I need to globalize thread at the the start of myhook(), but I've tried that and it didn't work.
Any ideas?
Okay, so I switched it to a {$thisvar} format, and it started appearing. Now all I have to do is figure out how to finish my plugin and make it work (currently it's reacting on my else statement, returning an error).
On a similar note, I have this if statement:
$two = "four"
if (!$somesetting)
{
eval("\$one = \"".$two."\";");
}
else
{
eval("\$one= \""."three"."\";");
}
Everytime the script is executed, "three" is always being printed, never "four".
Any ideas on how to properly execute this?
I've been trying to fix this plugin for about 8 hours now. Can someone please tell me where I've gone wrong?
<?php
//Disallow direct access for security reasons
if (!defined("IN_MYBB"))
{
die("You cannot access this file directly.<br />Please make sure IN_MYBB is defined.");
}
//Hooks
$plugins->add_hook("global_start", "shorturl_showthread");
//Information
function shorturl_info()
{
return array(
"name" => "WDTN URL Shortener",
"description"=> "Allow the shortening of URLs using the WDTN URL Shortener API",
"website" => "http://wedesignthe.net",
"author" => "Seabody",
"authorsite" => "http://seabtech.empirehostings.net",
"version" => "1.0",
"guid" => "",
"compatibility" => "16*"
);
}
//Activation Routines
function shorturl_activate() {
global $db;
$shorturl_group = array(
'gid' => 'NULL',
'name' => 'shorturl',
'title' => 'WDTN Short URL',
'description' => 'Settings for the URL Shortener plugin',
'disporder' => "1",
'isdefault' => "0",
);
$db->insert_query('settinggroups', $shorturl_group);
$gid = $db->insert_id();
$shorturl_setting = array(
'sid' => 'NULL',
'name' => 'shorturl_enable',
'title' => 'Do you want to enable the URL shortener plugin?',
'description' => 'If you set this option to yes, this plugin will be active on your board.',
'optionscode' => 'yesno',
'value' => '1',
'disporder' => 1,
'gid' => intval($gid),
);
$db->insert_query('settings', $shorturl_setting);
rebuild_settings();
}
//Deactivation Routines
function shorturl_deactivate()
{
global $db;
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('shorturl_enable')");
$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='shorturl'");
rebuild_settings();
}
function shorturl_showthread()
{
//Get our globals
global $mybb, $shorturl, $result, $templates;
if ($mybb->settings['shorturl_enable'] == 1)
{
//Set up the curl connection
$curl = curl_init('http://wdtn.co/api/shortener/create');
//Get our options downpat
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_TIMEOUT => 30,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array('url' => 'http://www.{$mybb->settings[\'bburl\']}/showthread.php&tid={$tid}'),
)
);
//Shorten it
$result = curl_exec($curl);
//Close curl
curl_close($curl);
//Parsing using json_decode
$result = json_decode($result);
//Checking for errors
if (!$result->error)
{
$shortened = "Shortlink: <input type=\"text\" readonly value=\"\$result->slug\" />";
}
else
{
$shortened = "No shortlink exists";
}
}
eval("\$shorturl = \""."$shortened"."\";");
}
?>
All I get in this is "No shortlink exists" (I insert the variable manually because me and the Changing Template system don't get along well. )
I've tried replacing {$tid} with {$thread['tid']}, but nothing's worked. I've also escaped virtually everything you can think of.