Spice up your Joomla and Mambo website with 2 great extensions!
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

38736 Posts in 10488 Topics by 27226 Members
Latest Member: tbl
JoomlaWorks Community ForumTutorials contributed by usersFor Joomla! 1.0.xExperiment: Showing ANY component to any place of website (as modules)
Pages: [1]   Go Down
  Print  
Author Topic: Experiment: Showing ANY component to any place of website (as modules)  (Read 13187 times)
0 Members and 1 Guest are viewing this topic.
metacortex
Jr. Member
**
Offline Offline

Posts: 83


Designer


View Profile WWW
« on: February 24, 2008, 08:53:58 AM »

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:

Code:
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:

Code:
<?php
include_once("htmlsql/snoopy.class.php");
include_once(
"htmlsql/htmlsql.class.php");
...

and the code:

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.php

Around line 644 search:

Code:
/**
* 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:

Code:
<!-- begin query -->

Around line 707 search:

Code:
<input type="hidden" name="<?php echo $validate?>" value="1" />
</form>
<br />
</td>

Add below:

Code:
<!-- 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 Huh? . For a correct display I wrote the string adding a count limit:

Code:
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 Tongue. Only imagine the possibilities.


Finally, this is the entire piece of code from index.php:

Code:
<?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.
Logged

"If you fall down seven times, get up eight."

JoomlaWorks Support Team
Pages: [1]   Go Up
  Print  
 
Jump to: