Shout Box Block

Discussions on blocks
Forum rules
Asking about a release date will get you banned

Read the global rules post before your do anything

Shout Box Block

Postby Bigbuck » Sat Dec 13, 2008 5:52 pm

Ok, I started working on the block but to be honest am completely lost. I am trying to figure out how the block structure works and cannot get it straight. The code for the block itself seems pretty straightforward, its just moving it over correctly that confused me. If you have time could you give me a basic run through of the block structure?
Image
Image
Bigbuck
Developer
 
Posts: 593
Joined: Mon Mar 24, 2008 3:32 pm
Location: Wisconsin, USA
Gender: Male

Re: Shout Box Block

Postby ceaser » Sat Dec 13, 2008 5:53 pm

tomorrow i will post the details unless tech gets to it first
Image
Image
ceaser
Developer
 
Posts: 943
Joined: Fri Feb 01, 2008 7:11 pm
Location: NJ, USA
Gender: Male

Re: Shout Box Block

Postby Technocrat » Mon Dec 15, 2008 9:36 am

I am not sure how much detail to go in so I am going to give you a real general overview.

The block needs to be a class. The class name must match the name of the block. So if your block name is block_Shout_Box your class needs to be class_Shout_Box. The constructor needs to setup the block base class:
Code: Select all
   function __construct() {
      $this->block = new Base_Block(__FILE__);
   }


The class only has to contain the display function. It must take in the location and title.
Code: Select all
public function display($location, $title) {

That function needs to put a title to the block and the block content. If the block is going to use a template to display the content (which it should) you need to use the template assigned to the block name.
Code: Select all
      $template->assign_block_vars('block_'.$location, array(
         'TITLE'      => $title,
         'CONTENT'   => $template->assign_display($this->block->template_prefix),
         )
      );

So basically what this sets up is a block at the location (ie right, left, center). The title in this case what is passed in to the function. And the content which is using the template.

Thats a real quick and basic overview.
User avatar
Technocrat
Site Admin
 
Posts: 695
Joined: Thu Jan 24, 2008 5:32 pm
Location: California
Gender: Male

Re: Shout Box Block

Postby Bigbuck » Mon Dec 15, 2008 9:57 am

Here is what I have so far. I am not sure how to set the path correctly for the javascript folder. There is probably a lot of stuff wrong as I don't think I can just copy/paste the original shout box code into the new block.

Code: Select all
<?php

/**
*
* Shout Box Block
*
* Notes
*
* Credits
*
* @author Bigbuck <www.evolution-cms.com>
* @version $Id:$ (9.0.0)
* @package phpBB-Evolution
* @copyright 2007 The Evolution-CMS Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

/**
* @ignore
*/
if (!defined('CMS')) {
    die('Direct access is not allowed');
}

class block_Shout_Box {
   
   /**
    * Holds the block base class
    *
    * @var class Base_Block
    */
   private $block;

   /**
    * Constructor
    *
    */
   function __construct() {
      $this->block = new Base_Block(__FILE__);
   }

   /**
    * Display the block
    *
    * @return string
    */
   public function display($location, $title) {
      global $prefix, $ShoutSubmit, $ShoutComment, $db, $user, $cookie, $shoutuid, $top_content, $mid_content, $bottom_content, $ShoutMarqueewidth, $ShoutMarqueeheight, $currentlang, $template;
      
      include_once(_PATH_MODULES.$this->block->base_name.'core/class_shout.inc.php');
      
      //Setup the template
      $template->set_filenames(array(
         $this->block->template_prefix => 'cms/blocks/'.$this->block->template_prefix.'.html',
         )
      );
   
      //Create the block
      $template->assign_block_vars('block_'.$location, array(
         'TITLE'      => $title,
         'CONTENT'   => $template->assign_display($this->block->template_prefix),
         )
        );
   
      switch($ShoutSubmit) {
         default:
         ShoutBox($ShoutSubmit, $ShoutComment, $shoutuid);
         break;
      }

      if (!isset($_GET['Action']) && $_GET['Action'] != 'AJAX') {
         echo '<script type="text/javascript">var SBheight = \''.$ShoutMarqueeheight.'\';var SBcontent = new String(\''.$mid_content.'\');</script>
         <script type="text/javascript" src="javascript/shoutbox/shoutbox.js"></script>';

         $content = $top_content."\n";
         $content .= "<div align=\"center\" id=\"shoutbox\"><script type=\"text/javascript\">document.write(SBtxt);</script></div>\n";
         $content .= $bottom_content."\n";
      }
   }
}
Last edited by Bigbuck on Wed Dec 17, 2008 2:34 pm, edited 1 time in total.
Image
Image
Bigbuck
Developer
 
Posts: 593
Joined: Mon Mar 24, 2008 3:32 pm
Location: Wisconsin, USA
Gender: Male

Re: Shout Box Block

Postby Technocrat » Tue Dec 16, 2008 9:24 am

Good start.

First make sure you read:
http://wiki.phpbb-evolution.com/index.p ... _Standards
So your coding will match. Like no ?> ;)

Ok for your include statement your using the global module. This wont work because that holds the module that the user current is in. So on the home page it would be News, and thats not where your block lives.

So I would make a module folder called Shout_Box and use:
Code: Select all
include_once(_PATH_MODULES.$this->block->base_name.'/shout.php');


Then get rid of:
Code: Select all
if (empty($modules->current) || !is_object($current_module) || !is_callable($call)) {
         return ;
      }


For loading the template use the block basename again. Also there is no sense in trying to load the standard template since it will fail.

For the javascript put the script in the javascript.html file and put a template if around it for like SHOUT_BOX. Then turn it on in the block. That way it won't load all the time.
User avatar
Technocrat
Site Admin
 
Posts: 695
Joined: Thu Jan 24, 2008 5:32 pm
Location: California
Gender: Male

Re: Shout Box Block

Postby Bigbuck » Wed Dec 17, 2008 2:35 pm

I changed it a bit and edited my post above. I am not sure what you mean with the JS stuff but I put the JS file in javascript/shoutbox/shoutbox.js and changed the block to reflect that.
Image
Image
Bigbuck
Developer
 
Posts: 593
Joined: Mon Mar 24, 2008 3:32 pm
Location: Wisconsin, USA
Gender: Male

Re: Shout Box Block

Postby Technocrat » Thu Dec 18, 2008 9:27 am

It's pretty easy. Just open \Forums\styles\prosilver\template\javascript.html

Put the code in there with:
Code: Select all
{if SHOUT_BOX}
{/if}


Then in your block assign SHOUT_BOX to true in the template.
User avatar
Technocrat
Site Admin
 
Posts: 695
Joined: Thu Jan 24, 2008 5:32 pm
Location: California
Gender: Male

Re: Shout Box Block

Postby Bigbuck » Thu Dec 18, 2008 10:48 am

I added the JS to the javascript.html file like you said but am not sure how to turn it on. I tried var SHOUT_BOX = true in the block but it gave a parse error which I think is because I was trying to take a JS variable into PHP? Am getting errors because the other files are not coded properly for PE yet, so am working on them as they come.
Image
Image
Bigbuck
Developer
 
Posts: 593
Joined: Mon Mar 24, 2008 3:32 pm
Location: Wisconsin, USA
Gender: Male

Re: Shout Box Block

Postby Technocrat » Thu Dec 18, 2008 10:52 am

Put your stuff on the SVN and I will help you with it.
User avatar
Technocrat
Site Admin
 
Posts: 695
Joined: Thu Jan 24, 2008 5:32 pm
Location: California
Gender: Male

Re: Shout Box Block

Postby Bigbuck » Thu Dec 18, 2008 11:22 am

I only added those two files because right now you will get a bunch of errors if you try to go to the CMS home.
Image
Image
Bigbuck
Developer
 
Posts: 593
Joined: Mon Mar 24, 2008 3:32 pm
Location: Wisconsin, USA
Gender: Male

Next

Return to Blocks

Who is online

Users browsing this forum: No registered users and 1 guest

cron