Location: PHPKode > projects > Buzzword > buzzword-0.8.12/gallery/common.inc
<?php

/*
 * buzzword
 * Copyright (c) 2003 Jon Tai
 *
 * $Id: common.inc 267 2004-03-31 03:14:55Z bradt $
 *
 * This file is part of buzzword.
 *
 * buzzword is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * buzzword is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with buzzword; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

function import_gallery_gallery_key() {
    return (int) get_request_var('g');
}

function import_gallery_image_key() {
    return (int) get_request_var('i');
}

function import_gallery_image_comment_key() {
    return (int) get_request_var('c');
}

function import_gallery_form_name() {
    return preg_replace('/[^\w]/', '', get_request_var('f'));
}

function import_gallery_element_name() {
    return preg_replace('/[^\w]/', '', get_request_var('e'));
}

function get_gallery_breadcrumbs($gallery) {
    $galleries = array();

    while ($gallery->gallery_key > 0) {
        $galleries[] = "<a href=\"index.php?g={$gallery->gallery_key}\">".$gallery->get_display_short_title()."</a>";
        $gallery = $gallery->parent;
    }

    global $BUZZWORD_PAGE_TITLE;
    $galleries[] = "<a href=\"index.php\">$BUZZWORD_PAGE_TITLE</a>";

    return array_reverse($galleries);
}

function gallery_toolbar_hook($form_name, $element_name) {
    $toolbar = "<a href=\"#\" onClick=\"gallery_filebrowser_popup('$form_name', '$element_name'); return false;\"><img \n";
    $toolbar .= " src=\"../gallery/images/toolbar-insert-image.gif\" alt=\"Insert Image\" title=\"Insert Image\" \n";
    $toolbar .= " border=\"0\" width=\"22\" height=\"21\"></a>\n";
    return $toolbar;
}

function gallery_longtext_hook($string) {
    return preg_replace_callback('/\<gallery image_key="([0-9]+)"\>/', 'gallery_longtext_hook_callback', $string);
}

function gallery_longtext_hook_callback($matches) {
    $image = new gallery_image($matches[1]);

    if (!$image->exists()) {
        return "<img src=\"../gallery/display.php?i={$image->image_key}\">";
    } else {
        $replace = "<a href=\"../gallery/image.php?i={$image->image_key}\"><img \n";
        $replace .= " src=\"../gallery/display.php?i={$image->image_key}\" ".$image->get_alt();
        $replace .= " border=\"0\" ".$image->get_display_size()."></a>";
        return $replace;
    }
}

function gallery_filebrowser_print_tree($form, $element, $selected, $parent = 0, $level = 0) {
    $sql = 'SELECT gallery_key FROM '.DB_PREFIX.'gallery_galleries ';
    $sql .= 'WHERE parent = '.$parent;
    $result = mysql_query($sql);
    $num_rows = mysql_num_rows($result);

    $i = 0;
    while ($row = mysql_fetch_assoc($result)) {
        $gallery = new gallery_gallery($row['gallery_key']);
   
        if ($level > 0) {
            echo "<img src=\"images/filebrowser-tree-child";
            if ($i < $num_rows - 1) 
                echo "-with-sibling";
            echo ".gif\"\n width=16 height=16 border=0 align=\"middle\"";
            if ($level > 1)
                echo ' style="margin-left: '.(($level - 1) * 17).'px;"';
            echo '>';
        }

        echo "<a href=\"filebrowser.php?g={$gallery->gallery_key}&amp;f=$form&amp;e=$element\"><img\n";
        echo ($selected == $gallery->gallery_key) ? 
            " src=\"images/filebrowser-folder-open.gif\" width=20 height=16 border=0\n align=\"middle\">":
            " src=\"images/filebrowser-folder-closed.gif\" width=20 height=16 border=0\n align=\"middle\">";
        echo $gallery->get_display_title()."</a><br>\n";

        // recurse
        gallery_filebrowser_print_tree($form, $element, $selected, $row['gallery_key'], ($level + 1));
        $i++;
    }
}

?>
Return current item: Buzzword