Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2012, 09:15:03 PM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
155527 Posts in 21712 Topics by 7737 Members
Latest Member: chris85
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Snippet: WbRandomSection  (Read 1718 times)
WebBird
Guest
« on: August 04, 2009, 01:16:00 PM »

Due to a request in the German board, I created a RandomSection Snippet. I am aware of the existence of "RandomSection", but I think it is too restrictive, for it limits the sections to choose from to WYSIWYG.

So, I created a Snippet called "WbRandomSection" (where Wb is for Webbird grin), which gives you more freedom.

For download, see the AMASP page: http://www.websitebakers.com/pages/modules/listings/section-pages/wbrandomsection.php?lang=EN

Usage instruction can be found in the readme.txt:

Quote
USAGE
=====

1. In a Code section

* Add a code section to the page
* Insert the following code (the two lines between --- and ---):

---
include_once WB_PATH.'/modules/wbrandomsection/include.php';
show_random( array( <Option> ) );
---

2. In a template

* Open the index.php of the template
* Insert the code mentioned above where the random section(s) shall occur


3. As a droplet

* Name: WBRandomSection
* Code:

---
include_once WB_PATH.'/modules/wbrandomsection/include.php';

$options = array();

if ( isset( $page_id ) ) {
    $options['page_id'] = $page_id;
}

if ( isset( $types ) ) {
    $options['types'] = explode( ',', $types );
}

if ( isset( $limit ) ) {
    $options['limit'] = $limit;
}

ob_start();
show_random( $options );
$return = ob_get_clean();

return $return;

---

* Comment:
  [[WBRandomSection?page_id=<ID>;types=<Type(s)>;limit=<Int>]]


Examples:

[[WBRandomSection?page_id=5]]
[[WBRandomSection?types=wysiwyg,imagegallery,code]]
[[WBRandomSection?page_id=5;types=wysiwyg,imagegallery,code]]


OPTIONS
=======

There are several options to control the snippet's behaviour:

page_id => <Number>

    A page number to choose the sections from. By default, the section
    is chosen from all sections of all pages.

types => '<Moduletype>' | array( 'List', 'of', 'Types' )

    Module types to choose from. May be a string or a list. By default,
    the section is chosen from all available module types.
    
limit => <Number>

    Number of sections to show. Default is 1.
  


EXAMPLES
========

* All default; choose a (=one) random section from all available pages

show_random();

* Show 2 random sections from page with ID 5, but only of type
 "wysiwyg" or "imagegallery".

show_random(
    array(
        'page_id' => 5,
        'limit'   => 2,
        'types'   => array( 'wysiwyg', 'imagegallery' )
    )
);


STYLES
======

To style your Random Sections, two CSS classes are provided:

div.randomsection

    Each section is wrapped into a <div> of class "randomsection". To
    add a gray border to each section, for example, add this code to
    your frontend.css (of the template you are using):
    
    div.randomsection { border: 1px solid #ccc; }
    
    To add a margin on the bottom of each section, try this:
    
    div.randomsection { margin-bottom: 15px; }

div.randomsectionwr ap

    Wraps the complete RandomSection part. That is, if you include more
    than one section, the complete list of rendered sections is
    wrapped into a <div> of class "randomsectionwrap".
    
    You can use this to "float" the complete RandomSection block:
    
    div.randomsectionwrap { width: 100px; float: right; }
    
« Last Edit: August 04, 2009, 01:40:43 PM by WebBird » Logged
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #1 on: August 04, 2009, 01:36:42 PM »

Thanks again WebBird.

Thats a very handy Snippet.

Regards,
Stefek
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
WebBird
Guest
« Reply #2 on: August 04, 2009, 01:41:09 PM »

 grin
Logged
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #3 on: August 04, 2009, 02:15:36 PM »

can you put sections id in array ?
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #4 on: August 04, 2009, 02:33:20 PM »

Hello Ivan,


All you need to do is: name your pageID.
The snippet returns the sections of this pageID in random.

So you do not have to call the sections in a array.
But f you need it that way, there is another module for this at AMASP.

Regards,
Stefek
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #5 on: August 04, 2009, 02:39:36 PM »

I ment if sections are on different pages..

But if there is already exist cool Smiley

cheers
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
WebBird
Guest
« Reply #6 on: August 04, 2009, 03:01:42 PM »

Hum? Do you want to give a list of sections to choose from? If so, you don't need the snippet. grin

By default, a random section will be chosen from ALL active sections on ALL pages.
Logged
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #7 on: August 04, 2009, 03:20:47 PM »

I was thinking maybe to have in array section id like (5,10,20,21) and then to chose random between those 4..

Does it metter which module is it, or any module can work ?
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #8 on: August 04, 2009, 03:42:17 PM »

I was thinking maybe to have in array section id like (5,10,20,21) and then to chose random between those 4..

Does it metter which module is it, or any module can work ?

I think this is the module you're looking for.
But notice, that it handles WYSIWYG only.

Regards,
Stefek
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
WebBird
Guest
« Reply #9 on: August 05, 2009, 09:03:07 AM »

The original RandomSection module only handles WYSIWYG.

WbRandomSection handles any section/module type.

I can add the option to give a list of section id's to choose from, but I think you could do it as a droplet.

Try this code (untested) in a code section:

Code:
global $database;
$sections = array();

// get random section id
$rand = rand( 0, sizeof($sections) );
$section_id = $sections[$rand];

// get module type from DB
$result = $database->query( "SELECT module FROM ".TABLE_PREFIX."sections WHERE section_id='$section_id'" );

if ( $result ) {

    $data   = $result->fetchRow();
    $module = $data['module'];
   
    $file = WB_PATH.'/modules/'.$module.'/view.php';
    if ( file_exists ($file) ) {
      ob_start(); // Output Buffer start
      require($file);
      $foo = ob_get_contents(); // put Output Buffer in $foo
      ob_end_clean();           // end and clean the Output Buffer
     
      $output .= '<div class="randomsection">'
            .  $foo
            .  '</div>';
           
      return $output;

}

return false;

In
Code:
$sections = array();
, insert the comma seperated section IDs between the (...).
« Last Edit: August 05, 2009, 10:35:43 AM by WebBird » Logged
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #10 on: August 05, 2009, 11:19:26 AM »

cool.

It is important that it can use any section Smiley

cheers
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
WebBird
Guest
« Reply #11 on: August 05, 2009, 11:24:14 AM »

With the WbRandomSection snippet you can, but you can't give a list of sections to choose from. Maybe in the next version. grin
Logged
mr-fan

Offline Offline

Posts: 1556


WWW
« Reply #12 on: August 25, 2009, 07:13:34 AM »

for WB 2.8 there was a missing index.php file in the zip...

attached file with index.php

regards martin (thanks to doc - he figured this out...)

Logged

 
WebBird
Guest
« Reply #13 on: August 26, 2009, 09:52:01 AM »

Updated version 0.3 uploaded to AMASP.
Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!