Jump to content
DevFuse Forums

Custom script


ShaneV

Recommended Posts

Hi,

 

I recently upgraded my 2.3.5 to 3.0.3 :)

 

Now for 2.3xx i made my own little script called 'Topic Top 50'

It shows 50 topics with most reply's that where post in the last 30 days..

 

With a simple code: http://codedump.mastercode.nl/645/

Placed the file in /sources/components_public/ and access it by index.php?autocom=top50

 

Now i see that in IPB3 almost everything with the code is changed, how can i do something like this for IPB3?

 

Thanks allot!

 

Greetz

Link to comment
Share on other sites

  • 2 weeks later...

Hi thanks,

 

I need a little help here :)

 

I want to work with the template i added in ACP but how does the foreach function work in IPB3, this is what i have so far.

 

The page: http://www.codedump.be/code/346/

 

Template: http://www.codedump.be/code/347/

Template Variables: $t50

 

Inspired on an invite mod for IPB3, but its not working.

 

Thanks

Link to comment
Share on other sites

  • 4 weeks later...

Are there some tuts about using the foreach in ipb3 templates?

 

Like this i simple query what i do wrong?

Example select 50 emails from ipb_members

 

$data = $this->DB->buildAndFetch( array( 'select' => '*', 'from' => 'members','limit' => '50' ) );

$this->output .= $this->registry->output->getTemplate('top50')->showTop50( $data );


$this->registry->output->addContent( $this->output );
$this->registry->output->sendOutput();

 

Template: => template variable: $data=array()

<foreach loop="$data as $k">
{$k['email']}<br />
</foreach>

 

But i get an output like this

1
B
4
m
1
8
3
B
...

Link to comment
Share on other sites

If i do it both ways i get the same error without a query result

 

Warning: Invalid argument supplied for foreach() in /home/bsnet/public_html/Upgrader/admin/sources/classes/output/publicOutput.php(1381) : eval()'d code on line 30

Warning: Cannot modify header information - headers already sent by (output started at /home/bsnet/public_html/Upgrader/admin/sources/classes/output/publicOutput.php(1381) : eval()'d code:30) in /home/bsnet/public_html/Upgrader/admin/sources/classes/output/formats/html/htmlOutput.php on line 91
Warning: Cannot modify header information - headers already sent by (output started at /home/bsnet/public_html/Upgrader/admin/sources/classes/output/publicOutput.php(1381) : eval()'d code:30) in /home/bsnet/public_html/Upgrader/admin/sources/classes/output/formats/html/htmlOutput.php on line 94
Warning: Cannot modify header information - headers already sent by (output started at /home/bsnet/public_html/Upgrader/admin/sources/classes/output/publicOutput.php(1381) : eval()'d code:30) in /home/bsnet/public_html/Upgrader/admin/sources/classes/output/formats/html/htmlOutput.php on line 102
Warning: Cannot modify header information - headers already sent by (output started at /home/bsnet/public_html/Upgrader/admin/sources/classes/output/publicOutput.php(1381) : eval()'d code:30) in /home/bsnet/public_html/Upgrader/admin/sources/classes/output/formats/html/htmlOutput.php on line 103
Warning: Cannot modify header information - headers already sent by (output started at /home/bsnet/public_html/Upgrader/admin/sources/classes/output/publicOutput.php(1381) : eval()'d code:30) in /home/bsnet/public_html/Upgrader/admin/sources/classes/output/formats/html/htmlOutput.php on line 107

 

Full page:

<?php
if ( ! defined( 'IN_IPB' ) )
{
print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
exit();
}

class public_top50_top50mod_top50sec extends ipsCommand
{
   public function doExecute( ipsRegistry $registry )
   {
       /* Load language  */
	$this->registry->class_localization->loadLanguageFile( array( 'public_top50' ), 'core' );
	$this->registry->getClass('class_localization')->loadLanguageFile( array( 'public_top50' ) );

       /* Page Title */
       if( $this->page_title == "" )
       {
           $this->page_title = $this->settings['board_name'] . " - " . $this->lang->words['title'];
       }

       $this->registry->output->setTitle( $this->page_title );

       /* Navigation */
       $this->registry->output->addNavigation( $this->lang->words['title'], 'app=top50&module=top50mod' );

	/* App Online Check */
	if( !$this->settings['bs_top50_online'] )
	{	
		$this->registry->output->showError( 'top50_offline' );
	}

	/* Group Permissions */
	if( !$this->memberData['bs_top50_groups'] )
	{
		$this->registry->output->showError( 'top50_groupPrem' );
	}

	/* There must be at least one forum selected */
	if( !$this->settings['bs_top50_forums'] )
	{
		$this->registry->output->showError( 'top50_noForums' );
	}

	/* Test foreach in ipb3 template */

	$data = $this->DB->buildAndFetch( array( 'select' => '*', 'from' => 'members','limit' => '50' ) );

               /* Skin bit */
	$this->output .= $this->registry->output->getTemplate('top50')->showTop50( $data );

	/* Output */
	$this->registry->output->addContent( $this->output );
	$this->registry->output->sendOutput();

}
}

Edited by ShaneV
Link to comment
Share on other sites

  • Management

buildAndFetch will only return 1 result from the database. Try something like this instead. Also would be a good idea to wrap your template foreach with an is_array if statement.

 

        $this->DB->build( array( 'select' => '*', 'from' => 'members','limit' => '50' ) );
       $this->DB->execute();

       while( $members = $this->DB->fetch() )
       {
           $data[] = $members;
       }

       /* Skin bit */
       $this->output .= $this->registry->output->getTemplate('top50')->showTop50( $data );

Link to comment
Share on other sites

Hi thanks Michael, can you give me an example how to use it in the templates with an is_array if statement.

This is my first time with ipb3 code, only have some basic php skills.

 

Thanks, grtz

 

sorry i didnt even read the script properly as you are now using BuildAndFetch you should be able to use the <foreach> statement i provided in an earlier post but make sure your variable is $data=""

Link to comment
Share on other sites

  • Management

Hi thanks Michael, can you give me an example how to use it in the templates with an is_array if statement.

This is my first time with ipb3 code, only have some basic php skills.

 

Thanks, grtz

 

<if test="has_data:|:is_array( $your_array )">

foreach here

</if> 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...