Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

[solved] How can i include a PHP Script with MetaMod?

[solved] How can i include a PHP Script with MetaMod?

HI,

I have a PHP script that i like to include as a Module with MetaMod is this possible?

Code:

include('ts3admin.class.php');


$ts3_ip = '127.0.0.1';
$ts3_domain_name = 'domain.com';
$ts3_serverport = '9987';
$ts3_queryport = '10011';

$ts3 = new ts3admin($ts3_ip, $ts3_queryport);
$ts3->connect();
$select = $ts3->selectServer($ts3_serverport);
if ($select["success"]) {
  $data = $ts3->getElement('data', $ts3->serverInfo());
  echo '<center><strong>Status:</strong> <font color="#00B200">Online</font></center>';
  echo 'IP: <font color="#999999">'.$ts3_domain_name.':'.$ts3_serverport.'</font>';
  echo 'Current Clients: <font color="#999999">'.$data['virtualserver_clientsonline'].' / '.$data['virtualserver_maxclients'].'</font>';
  echo 'Current Channels: <font color="#999999">'.$data['virtualserver_channelsonline'].'</font>';
  echo 'Uptime: <font color="#999999">'.$ts3->convertSecondsToStrTime($data['virtualserver_uptime']).'</font>';
  echo 'Traffic In: <font color="#999999">'.round ($data['connection_bytes_received_total']/1024/1024/1024,2).' GB/s</font>';
  echo 'Traffic Out: <font color="#999999">'.round ($data['connection_bytes_sent_total']/1024/1024/1024,2).' GB/s</font>';
  echo 'Version: <font color="#999999">'.preg_replace('/\ (.*)/' ,'', $data['virtualserver_version']).'</font>';
  echo 'Platform: <font color="#999999">'.$data['virtualserver_platform'].'</font>';
  echo '<center><a href="ts3server://'.$ts3_domain_name.'/?port='.$ts3_serverport.'&nickname=WebGuest" title="Connect to TS3 Server">Connect</a> <strong><font color="#999999">|</font></strong> <a href="http://www.teamspeak.com/" target="_blank" title="Download TeamSpeak 3">Download</a></center>';
} else {
  echo '<center><strong>Status:</strong> <font color="#E50000">Offline</font></center>';
  echo 'IP: <font color="#999999">'.$ts3_domain_name.':'.$ts3_serverport.'</font>';
  echo '<center><a href="ts3server://'.$ts3_domain_name.'/?port='.$ts3_serverport.'&nickname=WebGuest" title="Connect to TS3 Server">Connect</a> <strong><font color="#999999">|</font></strong> <a href="http://www.teamspeak.com/" target="_blank" title="Download TeamSpeak 3">Download</a></center>';
}

Edited By: Jeff78
12-May-13 03:58:41

Jeff78
Beginner Modder
ranks
useravatar
Offline
11 Posts
Administrator has disabled public posting

Re: [solved] How can i include a PHP Script with MetaMod?

Sure, you could just put that code as-is into the PHP box in MetaMod. The only thing that you might need to change (that I can see) might be the path of the included ts3admin class file. It may require a relative or absolute path.

The output of the script will appear as the content of a module (i.e. inside the MetaMod).

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

Re: [solved] How can i include a PHP Script with MetaMod?

If i do this the module will not even show up.
I have the feeling that i need to add something into MetaMod but don't know what it is.

Jeff78
Beginner Modder
ranks
useravatar
Offline
11 Posts
Administrator has disabled public posting

Re: [solved] How can i include a PHP Script with MetaMod?

ok, if nothing shows up, then check the following:

1 - ensure the MetaMod is assigned to some or all menu items and is published. To test this, remove everything from the PHP box and turn on "debug" mode in the MetMod (it's one of the options in MetaMod). You should see some output on the page If you see that, then that part is set up right and you can try the PHP code.

2 - if the PHP code has syntax or other errors in it then it may not show up at all, depending on how your computer is set up with error reporting. So in global configuration in Joomla, set error reporting to Full and see if that spits out any errors.

3 - don't put <?php and ?> around the PHP code. (I know you didn't do that above, but don't be tempted to do it. It won't work).

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

Re: [solved] How can i include a PHP Script with MetaMod?

The module will display on the right position if debugging is on but i cannot find any errors. I also used the same code above with a PHP module and it worked but it won't work if i include this code above into MetaMod.

Jeff78
Beginner Modder
ranks
useravatar
Offline
11 Posts
Administrator has disabled public posting

Re: [solved] How can i include a PHP Script with MetaMod?

ok, so maybe you need to just put in the PHP line by line, making sure that each line works and has no errors. Perhaps try the 1st few lines to start with, with a debugging statement:

echo "PHP started<br>";
$ts3_ip = '127.0.0.1';
$ts3_domain_name = 'domain.com';
$ts3_serverport = '9987';
$ts3_queryport = '10011';
$ts3 = new ts3admin($ts3_ip, $ts3_queryport);
$ts3->connect();
var_dump($ts3);


Does that come up with any output?

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

Re: [solved] How can i include a PHP Script with MetaMod?

With this code line "$ts3 = new ts3admin($ts3_ip, $ts3_queryport);" i get a blank page with this error:

Code:

MetaMod debug info:

Module ID: 109
$option: com_content
$view: category
$id: 8
$Itemid: 101
$timezone: UTC
$language: lb-lu
$language_code: lb
$language_region: lu
PHP started

Fatal error: Class 'ts3admin' not found in C:\xampp\htdocs\j2\modules\mod_metamod\helper.php(628) : eval()'d code on line 6

And with this code line "$ts3->connect();" i get a blank page with this error:

Code:

MetaMod debug info:

Module ID: 109
$option: com_content
$view: category
$id: 8
$Itemid: 101
$timezone: UTC
$language: lb-lu
$language_code: lb
$language_region: lu
PHP started

Fatal error: Call to a member function connect() on a non-object in C:\xampp\htdocs\j2\modules\mod_metamod\helper.php(628) : eval()'d code on line 6

Jeff78
Beginner Modder
ranks
useravatar
Offline
11 Posts
Administrator has disabled public posting

Re: [solved] How can i include a PHP Script with MetaMod?

Oh, actually you are going to need to put this line first:


include('ts3admin.class.php');


You might need to alter the path for the file: I have no idea where on your system it's going to be, and it may not find it automatically. So you might end up with something like:


include('/home/mysite/public_html/components/com_something/classes/ts3admin.class.php');

or


include('../../components/com_something/classes/ts3admin.class.php');


But both of those are TOTAL guesses - you need to find the right path for your server.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

Re: [solved] How can i include a PHP Script with MetaMod?

Strange i have now rewritten the code new and now it works i don't know what i did wrong in the first place but i'm glad it works now.

Code:

include('ts3admin.class.php');


$ts3_ip = '127.0.0.1';
$ts3_domain_name = 'domain.com';
$ts3_serverport = '9987';
$ts3_queryport = '10011';

$ts3 = new ts3admin($ts3_ip, $ts3_queryport);
$ts3->connect();
$select = $ts3->selectServer($ts3_serverport);
if ($select["success"]) {
  $data = $ts3->getElement('data', $ts3->serverInfo());
  echo '<div style="width:240px;margin: 0 auto">', PHP_EOL;
  echo '  <div style="text-align:center"><p><span style="font-weight:bold">Status:</span> <span style="color:#00B200">Online</span></p></div>', PHP_EOL;
  echo '  <div>', PHP_EOL;
  echo '    <div style="float:left;width:50%">IP Address: </div>', PHP_EOL;
  echo '    <div style="float:right;width:50%;color:#989898">'.$ts3_domain_name.':'.$ts3_serverport.'</div>', PHP_EOL;
  echo '  </div>', PHP_EOL;
  echo '  <div>', PHP_EOL;
  echo '    <div style="float:left;width:50%">Current Clients: </div>', PHP_EOL;
  echo '    <div style="float:right;width:50%;color:#989898">'.$data['virtualserver_clientsonline'].' / '.$data['virtualserver_maxclients'].'</div>', PHP_EOL;
  echo '  </div>', PHP_EOL;
  echo '  <div>', PHP_EOL;
  echo '    <div style="float:left;width:50%">Uptime: </div>', PHP_EOL;
  echo '    <div style="float:right;width:50%;color:#989898">'.$ts3->convertSecondsToStrTime($data['virtualserver_uptime']).'</div>', PHP_EOL;
  echo '  </div>', PHP_EOL;
  echo '  <div>', PHP_EOL;
  echo '    <div style="float:left;width:50%">Traffic In: </div>', PHP_EOL;
  echo '    <div style="float:right;width:50%;color:#989898">'.round ($data['connection_bytes_received_total']/1024/1024/1024,2).' GB/s</div>', PHP_EOL;
  echo '  </div>', PHP_EOL;
  echo '  <div>', PHP_EOL;
  echo '    <div style="float:left;width:50%">Traffic Out: </div>', PHP_EOL;
  echo '    <div style="float:right;width:50%;color:#989898">'.round ($data['connection_bytes_sent_total']/1024/1024/1024,2).' GB/s</div>', PHP_EOL;
  echo '  </div>', PHP_EOL;
  echo '  <div>', PHP_EOL;
  echo '    <div style="float:left;width:50%">Version: </div>', PHP_EOL;
  echo '    <div style="float:right;width:50%;color:#989898">'.preg_replace('/\ (.*)/' ,'', $data['virtualserver_version']).'</div>', PHP_EOL;
  echo '  </div>', PHP_EOL;
  echo '  <div>', PHP_EOL;
  echo '    <div style="float:left;width:50%">Platform: </div>', PHP_EOL;
  echo '    <div style="float:right;width:50%;color:#989898">'.$data['virtualserver_platform'].'</div>', PHP_EOL;
  echo '  </div>', PHP_EOL;
  echo '  <div style="text-align:center"><p><a href="ts3server://'.$ts3_domain_name.'/?port='.$ts3_serverport.'&nickname=WebGuest" title="Connect to TeamSpeak 3 Server">Connect to Server</a> <span style="color:#989898;font-weight:bold">|</span> <a href="http://www.teamspeak.com/" target="_blank" title="Download TeamSpeak 3 Client">Download Client</a></p></div>', PHP_EOL;
  echo '</div>', PHP_EOL;
} else {
  echo '<div style="width:240px;margin: 0 auto;text-align:center">', PHP_EOL;
  echo '  <div><p><span style="font-weight:bold">Status:</span> <span style="color:#E50000">Offline</span></p></div>', PHP_EOL;
  echo '  <div>', PHP_EOL;
  echo '    <div>IP Address: <span style="color:#989898">'.$ts3_domain_name.':'.$ts3_serverport.'</span></div>', PHP_EOL;
  echo '  </div>', PHP_EOL;
  echo '  <div><p><a href="ts3server://'.$ts3_domain_name.'/?port='.$ts3_serverport.'&nickname=WebGuest" title="Connect to TeamSpeak 3 Server">Connect to Server</a> <span style="color:#989898;font-weight:bold">|</span> <a href="http://www.teamspeak.com/" target="_blank" title="Download TeamSpeak 3 Client">Download Client</a></p></div>', PHP_EOL;
  echo '</div>', PHP_EOL;
}

Jeff78
Beginner Modder
ranks
useravatar
Offline
11 Posts
Administrator has disabled public posting

Re: [solved] How can i include a PHP Script with MetaMod?

Ok, great to hear that it's working for you now.
Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1667
Total Polls:
6
Total Posts:
5909
Posts this week:
1
User Info:
 
Total Users:
10137
Newest User:
lexispoker1
Members Online:
1
Guests Online:
242

Online: 
liaskas

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked