News:

SMF 2.1.6 has been released! Take it for a spin! Read more.

Main Menu

[wip] unable to load ' ' template

Started by Mick., May 14, 2010, 05:45:42 PM

Previous topic - Next topic

Mick.

Here's the deal,..... im writing a mod for RC3 that replaces SMF search bar in the theme with Google's custom search bar and show the results within SMF in its own page.

Ive been dealing with this for 2 days now and cant figure out why i can load the template.

I need to know if im missing a command somewhere.

The XML...

<?xml version="1.0"?>
<!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">
<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
<id>BlueDevil:GoogleCustomSearchResults_v.1</id>
<version>v.1</version>


<file name="$themedir/index.template.php">
<operation>
<search position="replace"><![CDATA[ <form id="search_form" style="margin: 0;" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
<input type="text" name="search" value="" class="input_text" />&nbsp;
<input type="submit" name="submit" value="', $txt['search'], '" class="button_submit" />
<input type="hidden" name="advanced" value="0" />';]]></search>
<add><![CDATA[
<form action="', $scripturl, '?action=gresults" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="partner-pub-', $modSettings['googleCustomSearchKey'], '" />
    <input type="hidden" name="cof" value="FORID:10" />
    <input type="hidden" name="ie" value="ISO-8859-1" />
    <input type="text" name="q" size="31" />
    <input type="submit" name="sa" value="Search" />
  </div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"></script>';]]></add>
</operation>
</file>


<file name="$boarddir/index.php">
<operation>
<search position="after"><![CDATA[
'groups' => array('Groups.php', 'Groups'),]]></search>
<add><![CDATA[
'gresults' => array('GoogleResults.php', 'Gresults'),]]></add>
</operation>
</file>


<file name="$sourcedir/Admin.php">
<operation>
<search position="after"><![CDATA[
'general' => array($txt['mods_cat_modifications_misc']),]]></search>
<add><![CDATA[
'gresults' => array($txt['googleCustomSearch']),]]></add>
</operation>
</file>


<file name="$sourcedir/ManageSettings.php">
<operation>
<search position="before"><![CDATA[ $subActions = array(
'general' => 'ModifyGeneralModSettings',]]></search>
<add><![CDATA[
'gresults' => 'ModifyGoogleResultsSettings',]]></add>
</operation>

<operation>
<search position="after"><![CDATA[
'description' => $txt['modification_settings_desc'],
'tabs' => array(
'general' => array(
),]]></search>
<add><![CDATA[
'gresults' => array(
),]]></add>
</operation>

<operation>
<search position="after"><![CDATA[?>]]></search>
<add><![CDATA[
function ModifyGoogleResultsSettings()
{
global $txt, $scripturl, $context, $settings, $sc;

$config_vars = array(

// Google Custom Search Key
array('text', 'googleCustomSearchKey'),
);

// Saving?
if (isset($_GET['save']))
{
checkSession();

saveDBSettings($config_vars);
redirectexit('action=admin;area=modsettings;sa=gresults');
}

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

prepareDBSettingContext($config_vars);
}
]]></add>
</operation>
</file>


<file name="$themedir/languages/Modifications.english.php">
<operation>
<search position="after"><![CDATA[?>]]></search>
<add><![CDATA[
global $scripturl;
$txt['googleCustomSearch'] = 'Google Custom Search';
$txt['googleresultsadmin'] = 'Google Custom Search Admin';
$txt['page_title'] = 'Google Custom Search';
$txt['googleMapc'] = 'Google Custom Search <a href="http://www.bluedevilcustoms.com/">v.1</a>';
]]></add>
</operation>
</file>

<file name="$themedir/languages/Modifications.english-utf8.php" error="skip">
<operation>
<search position="after"><![CDATA[?>]]></search>
<add><![CDATA[
global $scripturl;
$txt['googleCustomSearch'] = 'Google Custom Search';
$txt['googleresultsadmin'] = 'Google Custom Search Admin';
$txt['page_title'] = 'Google Custom Search';
$txt['googleMapc'] = 'Google Custom Search <a href="http://www.bluedevilcustoms.com/">v.1</a>';
]]></add>
</operation>
</file>

<file name="$themedir/languages/ManageSettings.english.php">
<operation>
<search position="before"><![CDATA[
$txt['karmaLabel'] = 'Karma label';
$txt['karmaApplaudLabel'] = 'Karma applaud label';
$txt['karmaSmiteLabel'] = 'Karma smite label';
]]></search>
<add><![CDATA[
$txt['googleCustomSearchKey'] = 'Your Google Publisher ID number';
$txt['googleCustomSearch'] = 'Google Custom Search';
]]></add>
</operation>
</file>
</modification>


The source GoogleResults.php:

<?php
// Google Custom Search Results v.1 Mod
// by
// BlueDevil <bluedevilcustoms.com>

// We calling this directly, if so, your evil...
if (!defined('SMF'))
die('Hacking attempt...');

function
gresults()
{
global $db_prefix, $context, $scripturl, $txt, $modSettings, $user_info;


// Get the template ready.....
//loadLanguage('Gresults');
loadTemplate('Gresults');
$context['sub_template'] = $txt['google_search'];
$context['page_title'] = $txt['googleCustomSearch'];


}

?>


and the GoogleResults.template.php:
<?php
// Google Custom Search Results v.1 Mod
// by
// BlueDevil <bluedevilcustoms.com>

function template_gresults()
{
global $context, $modSettings, $scripturl, $txt, $settings;

echo '  

<div align="center"><div id="cse-search-results"></div>
<script type="text/javascript">
 var googleSearchIframeName = "cse-search-results";
 var googleSearchFormName = "cse-search-box";
 var googleSearchFrameWidth = 800;
 var googleSearchDomain = "www.google.com";
 var googleSearchPath = "/cse";
</script>
<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script></div>
<br />
<div style="text-align: center;">'
,$txt['googleResultsc'],'</div>';
}
}

?>

Arantor

You've said loadTemplate('Gresults'), which means it'll look for Gresults.template.php, then it'll look for template_google_search() in there.

What you need is loadTemplate('GoogleResults'), and $context['sub_template'] = 'gresults';
Holder of controversial views, all of which my own.


Mick.

Quote from: Arantor on May 14, 2010, 05:47:03 PM
You've said loadTemplate('Gresults'), which means it'll look for Gresults.template.php, then it'll look for template_google_search() in there.

What you need is loadTemplate('GoogleResults'), and $context['sub_template'] = 'gresults';

You kidding?   lol,..... all backwards.   My goodness, ive been staring at it all day with out a clue back and forth.

Arantor

Yeah, loadTemplate tells it what file to load, $context['sub_template'] tells it what to do once it's loaded, if that makes sense.

It does take a little getting used to. Note if you don't set your own $context['sub_template'], template_main() will be called on your behalf.
Holder of controversial views, all of which my own.


Mick.

Thanx for guiding me to the right direction.  I needed those extra set of eyes ;)

Mick.


Arantor

$scripturl is the base URL to the forum's index.php, assuming you've pulled it in from global. Here, it would be http://www.simplemachines.org/community/index.php
Holder of controversial views, all of which my own.


Mick.

Quote from: Arantor on May 14, 2010, 06:14:38 PM
$scripturl is the base URL to the forum's index.php, assuming you've pulled it in from global. Here, it would be http://www.simplemachines.org/community/index.php

That's what i thought as i matched it to my google map mod but its not redirecting to the template.

For instance...

This is the button, once the word its imput, it takes me to the forum instead of to ?action=gresults

I tried different formulas but its not listening to me.

<form action="', $scripturl,' ?action=gresults" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="partner-pub-', $modSettings['googleCustomSearchKey'], '" />
    <input type="hidden" name="cof" value="FORID:10" />
    <input type="hidden" name="ie" value="ISO-8859-1" />
    <input type="text" name="q" size="31" />
    <input type="submit" name="sa" value="Search" />
  </div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"></script>






<form action="', $scripturl,' ?action=gresults" id="cse-search-box">
<form action="', $scripturl,' index.php?action=gresults" id="cse-search-box">
<form action="', $scripturl,' /index.php?action=gresults" id="cse-search-box">

Arantor

<form action="', $scripturl, '?action=gresults" id="cse-search-box">

No space between the ' and ?
Holder of controversial views, all of which my own.


Mick.

Quote from: Arantor on May 14, 2010, 06:23:45 PM
<form action="', $scripturl, '?action=gresults" id="cse-search-box">

No space between the ' and ?

I didnt know that.  Thanx for the tip on it.

For some odd reason, its not riderecting.  http://www.bluedevilcustoms.com/devsite/index.php

See, google asks where do you want the results to appear, i want it to appear in http://www.bluedevilcustoms.com/devsite/index.php?action=gresults

That's why in the post form i added $scripturl since it will be a mod.

Ill keep digging. ;)

Arantor

Hmm, I have no idea how you tell Google what to do there. :(
Holder of controversial views, all of which my own.


Mick.

Quote from: Arantor on May 14, 2010, 06:32:40 PM
Hmm, I have no idea how you tell Google what to do there. :(

You know?   I remember once i tried the search button code in the index.template.php in which is fine.

But the results code, once added to a custom page from simpleportal or tinyportal, it wouldnt take it.   I wonder if google has a block to the template from being executed within other programs.

In my other webiste i have the results show in SMF in a custom php page i created manually just fine but is not a packaged mod.
http://www.bluedevilcustoms.com/results.php

<?php require("/home/******/public_html/SSI.php");
$context['page_title_html_safe'] = 'Results';
template_header();
echo
'
<br />


<center><div id="cse-search-results"></div>
<script type="text/javascript">
 var googleSearchIframeName = "cse-search-results";
 var googleSearchFormName = "cse-search-box";
 var googleSearchFrameWidth = 950;
 var googleSearchDomain = "www.google.com";
 var googleSearchPath = "/cse";
</script>
<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>

</center></td>
       </tr>
   </tbody>
</table>'
;

template_footer(); ?>



Advertisement: