Welcome Guest, Not a member yet? Register   Sign In
CMS - parse a gallery from view, from database-stored content?
#1

[eluser]Enorog[/eluser]
I am building a CMS that will store pages in DB like this:

Code:
- id (numeric)
- page_title (Shocking! Mother Parses Child!)
- page_title_url_friendly (mother_parses_child)
- page_content (entered by the client trough FCKEditor,
  stored with HTML tags in the database,
  cleaned of dangerous tags like <?php, ?>)

In the page_content (stored in DB), I would like the client to enter this:

Code:
<p>Some html</p>
{gallery[gallery_name]}
<p>Some more html</p>

I will send the contents of page_content via a controller to a view. When it is displayed in a view, it should be parsed like this:

- run a DB query on the database (get all rows with "gallery_name" from some table to get filenames for this gallery)
- format the array into html (add some <li><img...> tags around the filenames from DB)
- replace {gallery[...]} with this html, leaving the top and bottom html around the gallery of course, like this:

Code:
<p>Some html</p>
<div id="gallery">
<li><img src="images/path_from_database01.jpg"></li>
<li><img src="images/path_from_database02.jpg"></li>
</div>
<p>Some more html</p>


My thoughts:

- if I knew which gallery the client wants to display, I could prepare the file list in the controller (calling a model) and add some html around it (with a helper function). But I don't know this at the controller stage, unless I search for {gallery} in the whole contents ... this seems painful, plus the client could add more galleries between his HTML contents.

- I tried parsers that work from views, but the content isn't in my view, it's in a variable that only shows up on the finally processed page...

Thank you for ANY help, this has really been bugging me and it would make my CMS very simple to modularize (I would program some HTML-injecting buttons into FCKEditor for adding modules anywhere inside the content).
#2

[eluser]charlie spider[/eluser]
i do something similiar in my cms, but i have the page content stored in it's own table which allows multiple content blocks per page (think: main content vs sidebars vs. headers, footers, etc) when you access a page, the content blocks for just that page are retreived and then parsed for the appropriate media tag from within the controller. works fine and isn't that slow.

the "appropriate media tag" is the name that the admin gave to the media file when they uploaded it in the cms. They simply add {filename} anywhere within their content to have the media and all of it's formatting appear there. In your case, you would have to have them do the following:

1) upload individual media files and store file info in db
2) create a gallery name and store name in db
3) add individual media files to that gallery and store the associations in the db

this way you can know the gallery names and their associated files from within your controller.

then, just like my system, have them enter {gallery name} into their content and BAM >>> the gallery automagically appears

you could build the table as a view (return as binary) and pass the appropriate data to it, then pass everything to your main view for display. another highly recommended thing is to use multiple sortable lists in the admin section for when they add files to their gallery. this gives them simple drag and drop capabilities. very user friendly.

i don't know if i answered any questions for you, but i hope that helps
#3

[eluser]Enorog[/eluser]
Thanks for your ideas, it's close to what I need.

I ended up solving my problem - I used an upgraded parsing library that can call a helper from the view. I created a function in the helper that does all the gallery preparation for me. I wanted this flexibility to avoid too many modules on the page - I want the client to just compose everything in the html editor (FCKeditor).

I think it might be useful for somebody else to see how I've created the helper function.

It goes to a directory on my server, looks for the images, looks for the thumbnails and then creates a nice list (I process this with a jQuery popup script). Everything gets created automatically, the client only needs to write {prepare_gallery(folder_name)} inside his html content.

Here is the source code:

Code:
function prepare_gallery($folder_name)
{

    $result = '<div id="gallery">';
    
    $listing_big = get_filenames('files/images/galleries/' . $folder_name);
    $listing_thumb = get_filenames('files/images/galleries/' . $folder_name . '-thumb');

    $listing_size = sizeof($listing_big);

    for ($i = 0; $i < $listing_size; $i++) {
        
        $listing_big[$i] = 'files/images/galleries/' . $folder_name . '/' . $listing_big[$i];
        $listing_thumb[$i] = 'files/images/galleries/' . $folder_name . '-thumb/' . $listing_thumb[$i];
        
        $size_big[$i] = getimagesize($listing_big[$i]);
        $size_thumb[$i] = getimagesize($listing_thumb[$i]);
        
        $result .= '<div class="gallery_box"> ';
        $result .= '<a class="popup" href="' . base_url() . $listing_big[$i] . '">';
        $result .= '<img class="gallery_border" src="' . base_url() . $listing_thumb[$i] . '" alt="Your_Selector" />';
        $result .= '</a>';
        $result .= '</div> &lt;!-- end gallery_box --&gt;
        ';
    
    }
    
    $result .= '</div> &lt;!-- end gallery --&gt;';
    
    return $result;

}




Theme © iAndrew 2016 - Forum software by © MyBB