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.


How do i make [block="something"]block[/block] work on a custom block file?

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#24964 (In Topic #5908)

Fan in action

I've made my own blocks but they're all similar, (block 1 takes images from file list 1, block 2 takes images from list 2, block 3 from list 3…) and I was wondering how I would go about using the param feature of the block comcode…


Currently; <block>imageblocklist1</block> , <block>imageblocklist2</block> , <block>imageblocklist3</block>
Want it to; <block="list1">imageblock</block> , <block="list2">imageblock</block> , <block="list1">imageblock</block>

I would imagine "list1" is assigned to a variable somewhere but what variable?

Was thinking something like "if (somevar) == list1 { do this stuff }"

 :sarcy:  :sarcy:  :sarcy:

ocProducts :wub: :wub:

Click here to drop by my website!
Back to the top
 
Posted
Rating:
#24965
Avatar

Community saint

I would think you would put the peramitors in the blocks php file as thats the way the rest are set up. How ever I am not sure how to do it.

I run http://otakuplayground.com and am hopping to make themes and other things for ocportal even though I no longer use it for otakuplayground.com I still love it and feel it could go far with the right help. It needs themes and needs people to advertise for it.
Back to the top
 
Posted
Rating:
#24970
Avatar

Just use the $map['param'] variable for the unnamed parameter ('something' in your topic title). Then use $map['example'] for a parameter named 'example', and so on.
The only tricky thing is reading them in when they might not necessarily exist, so you might want to do something like:

Code

$example=array_key_exists('example',$map)?$map['example']:'';
which would load the 'example' parameter into $example but set it to blank if it doesn't exist.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#24980

Fan in action

I got your "example" thing I think but im afraid the $map['param'] got me a tad confused… where would that go? I looked in other files and didn't find anything to give me an exact area…

(note I just added the $example thing, didnt change the rest of the code to work with it yet)

Code (php)

<?php /*

 ocPortal
 Copyright (c) ocProducts, 2004-2006

 You may not distribute a modified version of this file, unless it is solely as an ocPortal modification.
 See text/en/licence.txt for full licencing information.

*/


class Block_defender_gallery_databank
{

   /**
    * Standard modular info function.
    *
    * @return ?array    Map of module info (NULL: module is disabled).
    */


   function info()
   {
      //removed-assert

      $info=array();
      $info['author']='Chris Graham';
      $info['organisation']='ocProducts';
      $info['hacked_by']=Eric Lacombe;
      $info['hack_version']=1.0;
      $info['version']=2;
      $info['locked']=true;
      $info['parameters']=array('param');
      return $info;
   }
   
   
   /**
    * Standard modular cache function.
    *
    * @return ?array    Map of cache details (cache_on and ttl) (NULL: module is disabled).
    */


/*
   function cacheing_environment()
   {
      //removed-assert

      $info=array();
      $mode=array_key_exists('mode',$map)?$map['mode']:'';
      $info['cache_on']='array($GLOBALS[\'FORUM_DRIVER\']->get_members_groups(get_member()),array_key_exists(\'zone\',$map)?$map[\'zone\']:get_module_zone(\'iotds\'))';
      $info['ttl']=1;
      return $info;
   }
*/
 
   /**
    * Standard modular run function.
    *
    * @param  array       A map of parameters.
    * @return tempcode    The result of execution.
    */


   function run($map)
   {
    if ($mode == "wristconsole") {
     include("./data_custom/defender/php/galleries/defmods/wristconsole.php");
     // ==================================================================
     $random = mt_rand(1,30);

      $var_picture_large_source = "{$wristconsole_large[$random]}";
      $var_picture_small_source = "{$wristconsole_small[$random]}";
      $var_picture_caption      = "{$wristconsole_caption[$random]}";
      $var_settings_target      = "{$wristconsole_target[$random]}";
      $var_settings_border      = "{$wristconsole_border[$random]}";
      $var_settings_title       = "{$wristconsole_title[$random]}";
    }

     // ==================================================================
     // PICTURE_LARGE_SOURCE    => The url to the large 640x480 picture.
     // PICTURE_SMALL_SOURCE    => The url to the small 200x150 picture.
     // PICTURE_CAPTION         => The caption for the current picture.
     // SETTINGS_TARGET         => The new window target, usually _Blank.
     // SETTINGS_BORDER         => if 0 then no border around the linked thumbnail.
     // SETTINGS_TITLE          => able to customize title of block based on image theme.
     // SETTINGS_PATH           => The file path to the images

       return do_template('DEFENDER_GALLERY',array('_GUID'=>'d710da3675a1775867168ae37db02ad4','PICTURE_LARGE_SOURCE'=>$var_picture_large_source,'PICTURE_SMALL_SOURCE'=>$var_picture_small_source,'PICTURE_CAPTION'=>$var_picture_caption,'SETTINGS_TARGET'=>$var_settings_target,'SETTINGS_BORDER'=>$var_settings_border,'SETTINGS_TITLE'=>$var_settings_title,'SETTINGS_PATH'=>$var_settings_path,'SETTINGS_PICKED'=>$random));
   }

}

?>

ocProducts :wub: :wub:

Click here to drop by my website!
Back to the top
 
Posted
Rating:
#24981
Avatar

PHP code

<?php /*

 ocPortal
 Copyright (c) ocProducts, 2004-2006

 You may not distribute a modified version of this file, unless it is solely as an ocPortal modification.
 See text/en/licence.txt for full licencing information.

*/

class Block_defender_gallery_databank
{

   
/**
    * Standard modular info function.
    *
    * @return ?array    Map of module info (NULL: module is disabled).
    */

   
function info()
   {
      
//removed-assert

      
$info=array();
      
$info['author']='Chris Graham'
      
$info['organisation']='ocProducts';
      
$info['hacked_by']=Eric Lacombe
      
$info['hack_version']=1.0;
      
$info['version']=2;
      
$info['locked']=true;
      
$info['parameters']=array('param');
      return 
$info;
   }
   
   
   
/**
    * Standard modular cache function.
    *
    * @return ?array    Map of cache details (cache_on and ttl) (NULL: module is disabled).
    */

/*
   function cacheing_environment()
   {
      //removed-assert

      $info=array();
      $mode=array_key_exists('mode',$map)?$map['mode']:'';
      $info['cache_on']='array(array_key_exists(\'param\',$map)?$map[\'param\']:\'\')';
      $info['ttl']=1;
      return $info;
   }
*/  
   /**
    * Standard modular run function.
    *
    * @param  array       A map of parameters.
    * @return tempcode    The result of execution.
    */

   
function run($map)
   {
      
$mode=array_key_exists('param',$map)?$map['param']:'';
     include(
"./data_custom/defender/php/galleries/defmods/'.filter_naughty($mode).'.php");
     
// ==================================================================
     
$random mt_rand(1,30);

      
$var_picture_large_source "{$data_large[$random]}"
      
$var_picture_small_source "{$data_small[$random]}"
      
$var_picture_caption     "{$data_caption[$random]}"
      
$var_settings_target     "{$data_target[$random]}"
      
$var_settings_border     "{$data_border[$random]}"
      
$var_settings_title     "{$data_title[$random]}";

     
// ==================================================================
     // PICTURE_LARGE_SOURCE     => The url to the large 640x480 picture.
     // PICTURE_SMALL_SOURCE    => The url to the small 200x150 picture.
     // PICTURE_CAPTION        => The caption for the current picture.
     // SETTINGS_TARGET        => The new window target, usually _Blank.
     // SETTINGS_BORDER        => if 0 then no border around the linked thumbnail.
     // SETTINGS_TITLE        => able to customize title of block based on image theme.
     // SETTINGS_PATH        => The file path to the images

       
return do_template('DEFENDER_GALLERY',array('_GUID'=>'d710da3675a1775867168ae37db02ad4','PICTURE_LARGE_SOURCE'=>$var_picture_large_source,'PICTURE_SMALL_SOURCE'=>$var_picture_small_source,'PICTURE_CAPTION'=>$var_picture_caption,'SETTINGS_TARGET'=>$var_settings_target,'SETTINGS_BORDER'=>$var_settings_border,'SETTINGS_TITLE'=>$var_settings_title,'SETTINGS_PATH'=>$var_settings_path,'SETTINGS_PICKED'=>$random));
   }

}

?>

This assumes you edit ./data_custom/defender/php/galleries/defmods/*.php to start using $data* in place of $wristconsole*.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#24989

Fan in action

so, with that code… <block="something">imageblock</block> would get the information from the something.php file right?

and in something.php file all vars are $data instead of whatever they are now (i.e $wristconsole)

but what I do not fully understand is what the "filter naughty" does exactly?

ocProducts :wub: :wub:

Click here to drop by my website!
Back to the top
 
Posted
Rating:
#24990
Avatar

Correct. filter_naughty is just a security thing I always use as a matter of course. It prevents people (in this case, people with 'dangerous Comcode' permission) from dong naughty stuff such as putting '../' into your 'param' value to try and load up some PHP file that was never intended.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#24991
Avatar

mrdefender said

so, with that code… <block="something">imageblock</block> would get the information from the something.php file right?

and in something.php file all vars are $data instead of whatever they are now (i.e $wristconsole)

Yes. :)

but what I do not fully understand is what the "filter naughty" does exactly?

filter_naughty is a very important function when dealing with files in ocPortal. It makes sure that the variable you're giving it doesn't contain any "naughty" character sequences which could change the file path. For example, if $mode was "../../../../../index", your block would be including the  main file. This isn't a particularly destructive example, but the possibilities are endless. ;) filter_naughty basically makes sure there are no up-directory strings ("../"), no slashes, and nothing else dangerous in the string it's given. :)

Back to the top
 
Posted
Rating:
#24992
Avatar

Community saint

Nice features.

I run http://otakuplayground.com and am hopping to make themes and other things for ocportal even though I no longer use it for otakuplayground.com I still love it and feel it could go far with the right help. It needs themes and needs people to advertise for it.
Back to the top
 
Posted
Rating:
#24993

Fan in action

I'm running into an odd problem with the filter naughty part…

include("./data_custom/defender/php/galleries/'.filter_naugh
ty($mode).'.php");
PHP WARNING [2] Block_defender_gallery::include(./data_custom/defender/php/b
locks/'.filter_naughty(dbgameplay).'.php) [<a href='function.Block-defender-gallery-include'>function.Bloc
k-defender-gallery-include</a>]: failed to open stream: No such file or directory (ocPortal version: 3.0.11, PHP version: 5.1.4, URL: /databank/index.php?page=start)

However, this one makes it work ok (so far) but from what you tell me about the filter naughty safety stuff, i should use that one (above) instead of this one (below)
include("./data_custom/defender/php/galleries/{$mode}.php");

ocProducts :wub: :wub:

Click here to drop by my website!
Back to the top
 
Posted
Rating:
#24994
Avatar

Whoops, the line should be:

PHP code

include('./data_custom/defender/php/galleries/defmods/'.filter_naughty($mode).'.php');



Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: