My objective is to
show a component as a module. I achieved it, at least in part. For this experiment I'm using
htmlsql script, developed by Jonas John and based in
Snoopy class.
I proved with
show the Contact component in frontpage, placing downloaded files in this way:
templates/rhuk_solarflare_ii/htmlsql/htmlsql.class.php
templates/rhuk_solarflare_ii/htmlsql/snoopy.class.php
templates/rhuk_solarflare_ii/htmlsql/snoopy_data/*
In
index.php I included both files:
<?php
include_once("htmlsql/snoopy.class.php");
include_once("htmlsql/htmlsql.class.php");
...
and the code:
$wsql = new htmlsql();
if (!$wsql->connect('url', 'http://localhost/joomla34/index.php?option=com_contact&Itemid=3')){ //absolute URL of contact form
print 'Error while connecting: ' . $wsql->error;
exit;
}
$wsql->isolate_content('<!-- begin query -->', '<!-- end query -->'); // Text into which is the part I want to show.
if (!$wsql->query('SELECT * FROM *')){ // A SQL-style query, but for html
print "Query error: " . $wsql->error;
exit;
}
foreach($wsql->fetch_array() as $row){
echo $row[text]; // Show result
}
?>
And I wrote this in my
components/contact_html.phpAround line 644 search:
/**
* Writes Email form
*/
function _writeEmailForm( &$contact, &$params, $sitename, &$menu_params ) {
global $Itemid;
if ( $contact->email_to && !$params->get( 'popup' ) && $params->get( 'email_form' ) ) {
// used for spoof hardening
$validate = josSpoofValue();
?>
<tr>
Add below:
<!-- begin query -->
Around line 707 search:
<input type="hidden" name="<?php echo $validate; ?>" value="1" />
</form>
<br />
</td>
Add below:
<!-- end query -->
This action give me the reference strings indicated in
isolate_content function.
Well, this really shows the contact form in
index.php, but strangely repeat it three times

. For a correct display I wrote the string adding a count limit:
if (!$wsql->query('SELECT * FROM *')){
print "Query error: " . $wsql->error;
exit;
}
// Added count limit
$limit = 1;
$count = 0;
foreach($wsql->fetch_array() as $row){
echo $row[text];
if( $count == $limit ) break;
$count++;
}
?>
In this way the component appear one time in the page, but I know this is not a good solution. The form would be shown correctly without need to add a limit.
¿What's the better solution for this? I would die for know it

. Only imagine the possibilities.
Finally, this is the entire piece of code from
index.php:
<?php
if ($option == 'com_frontpage') { // Show the component only in frontpage
include_once("htmlsql/snoopy.class.php");
include_once("htmlsql/htmlsql.class.php");
$wsql = new htmlsql();
if (!$wsql->connect('url', 'http://localhost/joomlaprueba/index.php?option=com_contact&Itemid=3')){
print 'Error while connecting: ' . $wsql->error;
exit;
}
$wsql->isolate_content('<!-- begin query -->', '<!-- end query -->');
if (!$wsql->query('SELECT * FROM *')){
print "Query error: " . $wsql->error;
exit;
}
$limit = 2;
$count = 0;
foreach($wsql->fetch_array() as $row){
echo $row[text];
if( $count == $limit ) break;
$count++;
}
}
?>
For more references, see the
Jonas's example/demo page. Those examples are also included in his pack.