HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Create a recent video block

Title: Creating a recent video pseudo block
Author: SoccerDad (Todd Rittinger)
ocPortal skill level: Intermediate

The ocPortal system currently does not have a native block for showing off recent video additions to your collection. This tutorial will show you how to create a pseudo block for this by utilizing OCP's main_multi_content block.


1) Create the following file: sources_custom/templates.php with the following content:

Code

<?php
/**
 * Get the tempcode for a standard box (CSS driven), with the specified content entered. Please rarely use this function; it is not good to assume people want anythings in one of these boxes... use templates instead
 *
 * @param  tempcode      The content being put inside the box
 * @param  mixed         The title of the standard box, string or Tempcode (blank: titleless standard box)
 * @param  ?string      The width/height classification (e.g. 100%, 100%|300px, ...) (NULL: unset)
 * @param  ID_TEXT      The type of the table. Refers to a template (STANDARDBOX_type)
 * @param  string         '|' separated list of options (meaning dependant upon templates interpretation)
 * @param  string         '|' separated list of meta information (key|value|key|value|...)
 * @param  string         '|' separated list of link information (linkhtml|...)
 * @param  boolean      If the box will be allowed to expand.
 * @param  string         Link to be added to the header of the box
 * @return tempcode      The contents, put inside a standard box, according to the other parameters
 */
function put_in_standard_box_video($content,$title='',$dimensions=NULL,$type='video',$options='',$meta='',$links='',$expand=false,$toplink='')
{
   if ((get_page_name()=='start') && (get_zone_name()=='adminzone') && (($options=='') || ($options=='tray_open')))
   {
      $expand=true;
      $options='tray_open';
   }

   if ($dimensions===NULL) $dimensions=($type=='panel')?get_option('panel_width'):'100%';
   if ($type=='') $type='classic';
   $height='auto';
   $dimensions_bits=explode('|',$dimensions);
   $width=$dimensions_bits[0];
   if (is_numeric($width)) $width.='px';
   if ($width=='') $width='auto';
   if (array_key_exists(1,$dimensions_bits)) $height=$dimensions_bits[1];
   if (is_numeric($height)) $height.='px';
   $_meta=array();
   if ($meta!='')
   {
      $meta_bits=explode('|',$meta);
      if (count($meta_bits)%2==1) unset($meta_bits[count($meta_bits)-1]);
      for ($i=0;$i<count($meta_bits);$i+=2)
         $_meta[]=array('KEY'=>$meta_bits[$i+0],'VALUE'=>$meta_bits[$i+1]);
   }
   $_links=array();
   if ($links!='')
   {
      $_links=explode('|',$links);
      if ($_links[count($_links)-1]=='') array_pop($_links);
   }
   $_options=explode('|',$options);
   //$interlock=in_array('interlock',$_options);
   return do_template('STANDARDBOX_'.filter_naughty($type),array(/*'INTERLOCK'=>$interlock,*/'CONTENT'=>$content,'LINKS'=>$_links,'META'=>$_meta,'OPTIONS'=>$_options,'WIDTH'=>$width,'HEIGHT'=>$height,'EXPAND'=>$expand,'TOPLINK'=>$toplink),NULL,true);
}
?>

2) Change the name of the function (on or around line 16):

Original:

Code

function put_in_standard_box
Modified:

Code

function put_in_standard_box_video

3) Change the type of box being created (on or around line 16, same as step 2):
 
Original:

Code

$type='classic'
Modified:

Code

$type='video'

4) Remove

Code

'TITLE'=>$title,
from the return do_template.

Original:

Code

return do_template('STANDARDBOX_'.filter_naughty($type),array(/*'INTERLOCK'=>$interlock,*/'CONTENT'=>$content,'LINKS'=>$_links,'META'=>$_meta,'OPTIONS'=>$_options,'WIDTH'=>$width,'HEIGHT'=>$height,'TITLE'=>$title,'EXPAND'=>$expand,'TOPLINK'=>$toplink),NULL,true);
Modified:

Code

return do_template('STANDARDBOX_'.filter_naughty($type),array(/*'INTERLOCK'=>$interlock,*/'CONTENT'=>$content,'LINKS'=>$_links,'META'=>$_meta,'OPTIONS'=>$_options,'WIDTH'=>$width,'HEIGHT'=>$height,'EXPAND'=>$expand,'TOPLINK'=>$toplink),NULL,true);
and save.

5) Copy sources/hooks/systems/awards/video.php to sources_custom/hooks/systems/awards/ Note: you may have to create the awards directory in sources_custom.

6) Edit the last line of sources_custom/hooks/systems/awards/video.php to reflect the name of the function from step #1:

Original:

Code

return put_in_standard_box($tpl,do_lang_tempcode('VIDEO'));
Modified

Code

return put_in_standard_box_video($tpl,do_lang_tempcode('VIDEO'));

7) Open sources/blocks/main_multi_content.php and change the
  • class declaration name (on or around line 21):

Original:

Code

class Block_main_multi_content
Modified:

Code

class Block_main_multi_content_video
  • your particulars (on or around line 34):

Code

      $info['hacked_by']='Todd Rittinger';
      $info['hack_version']='1.0';
  • the template call (on or around line 510):

Original:

Code

return do_template('BLOCK_MAIN_MULTI_CONTENT'
Modified:

Code

return do_template('BLOCK_MAIN_MULTI_CONTENT_VIDEO'

8) Save your modified file to: sources_custom/blocks/main_multi_content_video.php

9) Modify BLOCK_MAIN_MULTI_CONTENT.tpl and remove the following from the top:

Code

{+START,IF_NON_EMPTY,{TITLE}}
   <h2>{TITLE*}</h2>
{+END}

10) If you would like to add a horizontal rule between entries, add the following (on or around line 8)

Code

<br /><hr class="half" /><br />
Note: the first line break should already be present.

11) Save the modified template to: themes/your_theme/templates_custom/BLOCK_MAIN_MULTI_CONTENT_
video.tpl
[*chuckle*, for the life of me I can't figure out why this line is wrapping!]

12) Create your new wrapper box as referenced in step #3: themes/default/templates/STANDARDBOX_video.tpl

13) Add

Code

{CONTENT}
to the wrapper box and save. Note: you can add any CSS div and id tags here if you like by adding your own or copying the contents of one of OCP's pre-made boxes (ie. curved, light, classic, etc.) and simply add "_video" to the end of whatever CSS class tags you'd like to customize. I left mine completely empty of div's as I add them in the comcode page in which I've placed the block.

14) Modify IMG_THUMB.tpl and add the following immediately after each of the two img tags (on or around line 6 and 15 respectively):

Code

{+START,IF,{$MATCH_KEY_MATCH,site:start}}<div class="recent_video_link">{CAPTION}</div>{+END}
Note: change the match-key to reflect the page you are calling your block from. This example matches the start page in zone site.

15) Save as themes/your_theme/templates_custom/IMG_THUMB.tpl

16) Fire up your new block:

Code

[block="video" efficient="1" zone="_SEARCH" mode="recent" max="5" title=""]main_multi_content_video[/block]
Note the parameters "video" and "recent".

Customize via CSS until your heart is content! :)

Any problems, post under here or drop me note here: View topic: Specifying box template for main_muti_content block - ocPortal

There are no pages beneath this page

There are no posts yet

CEDI change-log Post