/**
 * Outputs the Fancybox popup code.
 *
 * @param array $params
 * @param object $smarty
 * @return string
 */
function smarty_fancybox($params, &$smarty)
{
    global $PIVOTX;
    // If we've set the hidden config option for 'never_jquery', just return without doing anything.
    if ($PIVOTX['config']->get('never_jquery') == 1) {
        debug("JQuery is disabled by the 'never_jquery' config option. FancyBox won't work.");
        return;
    }
    $params = cleanParams($params);
    $filename = $params['file'];
    $thumbname = getDefault($params['description'], "(thumbnail)");
    $org_thumbname = $thumbname;
    $alt = $params['alt'];
    $title = $params['title'];
    $align = getDefault($params['align'], "center");
    // rel_id can be used to specify your own prefix; all fancybox images with the same prefix will become a gallery
    $rel_id = getDefault($params['rel_id'], "entry-");
    // fb_type can be used to specify the type of the fancybox
    // image (default) - selfexplanatory
    // youtube - creates an embedded object with the youtube link (use url for that)
    $fb_type = getDefault($params['fb_type'], "image");
    $width = getDefault($params['width'], "560");
    $height = getDefault($params['height'], "340");
    $objwidth = getDefault($params['objwidth'], "0");
    $objheight = getDefault($params['objheight'], "0");
    $maxthumb = getDefault($params['specthumbmax'], "0");
    $txtcol = getDefault($params['txtcol'], "black");
    $txtcolbg = getDefault($params['txtcolbg'], "white");
    $txtcls = getDefault($params['txtcls'], "pivotx-popupimage");
    // this one can be used together with fb_type="youtube" and "vimeo"
    // !! structure should be like explained on youtube e.g. http://www.youtube.com/v/MOVID
    // or for vimeo: http://www.vimeo.com/moogaloop.swf?clip_id=CLIPID
    // it's better to just use movid to specify youtube or clipid for vimeo
    // url can also be used for fb type="iframe" or "flash"
    $url = $params['url'];
    $url = strip_tags($url);
    $movid = $params['movid'];
    $text = getDefault($params['text'], "Specify your text in parm 'text'.");
    // $border = getDefault($params['border'], 0);
    $imgw = getDefault($PIVOTX['config']->get('upload_thumb_width'), 200);
    $imgh = getDefault($PIVOTX['config']->get('upload_thumb_height'), 200);
    $uplbasepath = $PIVOTX['paths']['upload_base_path'];
    // Config option 'fancybox_thumbnail' can be added and used as default for thumbnail behaviour
    // 1 = always make sure the dimensions of the img tag are the same irrelevant of current thumbnail size
    //     (this means that when thumbnail gets created the upload width/height settings are used)
    // 2 = if thumbnail already exists always use its dimensions for the img tag (default)
    // 3 = if thumbnail exists and doesn't adhere to current width/height setting recreate it
    $fbthumb = getDefault($PIVOTX['config']->get('fancybox_thumbnail'), 2);
    $fbthumb = getDefault($params['thumbbehav'], $fbthumb);
    // debug("fb info: '$filename'-'$thumbname'-'$title'-'$alt'-'$align'-'$fb_type'");
    if ($align == 'center' || $align == 'inline') {
        $fbclass = 'pivotx-popupimage';
        $txclass = 'pivotx-popuptext';
    } else {
        $fbclass = 'pivotx-popupimage align-' . $align;
        $txclass = 'pivotx-popuptext align-' . $align;
    }
    // Get the UID for the page or entry
    $vars = $smarty->get_template_vars();
    $uid = intval($vars['uid']);
    if (empty($alt)) {
        $alt = $filename;
    }
    if ($objwidth == "0") {
        $objwidth = $width;
    }
    if ($objheight == "0") {
        $objheight = $height;
    }
    // Fix Thumbname, perhaps use a thumbname, instead of textual link
    // and try to fill both alt and title if still empty
    if ($thumbname == "(thumbnail)") {
        if (empty($filename)) {
            debug("No filename specified for thumbnail to process");
        } else {
            $thumbname = makeThumbname($filename);
            // If thumbnail exists and option 3 is chosen then check the dimensions for possible recreation
            $recreate = 0;
            if (file_exists($PIVOTX['paths']['upload_base_path'] . $thumbname) && $fbthumb == 3) {
                list($thumbw, $thumbh) = getimagesize($uplbasepath . $thumbname);
                //debug("dimensions of thumbnail: " . $thumbw . "/" . $thumbh);
                //debug("imgw/h: " . $imgw . "/" . $imgh);
                //debug("maxthumb: " . $maxthumb);
                if ($maxthumb > 0) {
                    // specthumbmax specified: calculate the right values (useful for vertical images)
                    if ($thumbw > $thumbh) {
                        $imgh = round($thumbh * ($maxthumb / $thumbw));
                        $imgw = $maxthumb;
                    } else {
                        $imgw = round($thumbw * ($maxthumb / $thumbh));
                        $imgh = $maxthumb;
                    }
                }
                if ($thumbw != $imgw || $thumbh != $imgh) {
                    $recreate = 1;
                    //debug("thumb will be recreated");
                }
            }
            // If the thumbnail does not exist and extension is jpg or png then try to create it
            // gif could be problematic so don't try it here......
            // filename could contain a subdir! this part is removed by auto_thumbnail
            // so save it through specifying a folder var
            if (!file_exists($PIVOTX['paths']['upload_base_path'] . $thumbname) || $recreate == 1) {
                $ext = strtolower(getExtension($filename));
                if ($ext == "jpeg" || $ext == "jpg" || $ext == "png") {
                    require_once $PIVOTX['paths']['pivotx_path'] . 'modules/module_imagefunctions.php';
                    $folder = $PIVOTX['paths']['upload_base_path'];
                    $dirpart = dirname($filename);
                    $basename = basename($filename);
                    $action = "Fancybox";
                    if ($dirpart != "" && $dirpart != ".") {
                        $folder = $folder . $dirpart . "/";
                    }
                    if (!auto_thumbnail($basename, $folder, $action, $maxthumb)) {
                        debug("Failed to create thumbnail for " . $filename);
                    }
                } else {
                    debug("Unable to create thumbnail for this extension " . $filename);
                }
            }
        }
    }
    if (empty($alt)) {
        $alt = $thumbname;
    }
    if (empty($title)) {
        $title = $alt;
    }
    // special string "null" to get rid of any title/alt
    if ($title == "null" || $alt == "null") {
        $title = "";
        $alt = "";
    }
    // Clean title and alternative text before using in generated html
    $title = cleanAttributes($title);
    $alt = cleanAttributes($alt);
    // If the thumbnail exists, make the HTML for it, else just use the text for a link.
    // use the current settings for uploadwidth/height because thumb can have diff.size
    if (file_exists($PIVOTX['paths']['upload_base_path'] . $thumbname)) {
        $ext = strtolower(getExtension($thumbname));
        if ($ext == "jpg" || $ext == "jpeg" || $ext == "gif" || $ext == "png") {
            // get image dimensions
            list($thumbw, $thumbh) = getimagesize($uplbasepath . $thumbname);
            if ($maxthumb > 0) {
                // specthumbmax specified: calculate the right values (useful for vertical images)
                if ($thumbw > $thumbh) {
                    $imgh = round($thumbh * ($maxthumb / $thumbw));
                    $imgw = $maxthumb;
                } else {
                    $imgw = round($thumbw * ($maxthumb / $thumbh));
                    $imgh = $maxthumb;
                }
            }
            // thumbnail behaviour 2: always use the dimensions of the found thumbnail
            if ($fbthumb == 2) {
                $imgw = $thumbw;
                $imgh = $thumbh;
                //debug("dimensions of found thumb used: " . $thumbw . "/" . $thumbh);
            }
            // if parms width or height have been specified they should be used!
            if (isset($params['width'])) {
                $imgw = $width;
            }
            if (isset($params['height'])) {
                $imgh = $height;
            }
            $thumbname = sprintf("<img src=\"%s%s\" alt=\"%s\" title=\"%s\" class=\"%s\" width=\"%s\" height=\"%s\" />", $PIVOTX['paths']['upload_base_url'], $thumbname, $alt, $title, $fbclass, $imgw, $imgh);
        } else {
            $thumbname = $org_thumbname;
        }
    } else {
        $thumbname = $org_thumbname;
    }
    // pack text in aligned paragraph (thumbname has been unchanged by the above)
    if ($thumbname == $org_thumbname) {
        if (strlen($org_thumbname) < 2) {
            $org_thumbname = "popup";
        }
        $thumbname = sprintf("<span class=\"%s\">%s</span>", $txclass, $org_thumbname);
    }
    // Prepare the HMTL for the link to the popup..
    // fb_type image
    if ($fb_type == 'image') {
        if (file_exists($PIVOTX['paths']['upload_base_path'] . $filename)) {
            $filename = $PIVOTX['paths']['upload_base_url'] . $filename;
            $code = sprintf("<a href=\"%s\" class=\"fancybox\" title=\"%s\" rel=\"%s%s\" >%s</a>", $filename, $title, $rel_id, $uid, $thumbname);
            if ('center' == $align) {
                $code = '<p class="pivotx-wrapper">' . $code . '</p>';
            }
        } else {
            debug("Rendering error: could not popup '{$filename}'. File does not exist.");
            $code = "<!-- Rendering error: could not popup '{$filename}'. File does not exist. -->";
        }
    } else {
        if ($fb_type == 'youtube' || $fb_type == "vimeo") {
            // filename is not mandatory so fix an empty one with dummy string so code gets returned
            if (empty($filename)) {
                $filename = '==fbdummy==';
            }
            // use random number to be fairly sure that constructed href will be unique
            // if by chance the number is the same then movie shown (when clicked) will be the first one
            // this is because a gallery of movies is not possible yet
            // uploadwidth/height is not used here because default youtube images are smaller
            $randnum = rand();
            if (empty($movid) && empty($url)) {
                debug("Popup type youtube/vimeo needs either a 'movid' or a fully qualified 'url' parm!");
            }
            $movstart = 0;
            if (empty($movid)) {
                $movthumb = formatFilename($url);
                $movthumb = str_replace('watch?v=', '', $movthumb);
                $movtime = '';
                // link contains time parm? &t=
                if (strpos($movthumb, "&t=")) {
                    $timepos = strpos($movthumb, "&t=");
                    $movtime = substr($movthumb, $timepos + 3);
                    $movthumb = substr($movthumb, 0, $timepos);
                }
                // short link supplied with time parm?
                if (strpos($movthumb, "?t=")) {
                    $timepos = strpos($movthumb, "?t=");
                    $movtime = substr($movthumb, $timepos + 3);
                    $movthumb = substr($movthumb, 0, $timepos);
                }
                // calculate the amount of seconds to supply to the player
                if ($movtime != '') {
                    $movh = 0;
                    $movm = 0;
                    $movs = 0;
                    $hpos = strpos($movtime, "h");
                    if ($hpos) {
                        $movh = substr($movtime, 0, $hpos);
                        $movtime = substr($movtime, $hpos + 1);
                    }
                    $mpos = strpos($movtime, "m");
                    if ($mpos) {
                        $movm = substr($movtime, 0, $mpos);
                        $movtime = substr($movtime, $mpos + 1);
                    }
                    $spos = strpos($movtime, "s");
                    if ($spos) {
                        $movs = substr($movtime, 0, $spos);
                        $movtime = substr($movtime, $spos + 1);
                    }
                    if (is_numeric($movh)) {
                        $movstart = $movh * 3600;
                    }
                    if (is_numeric($movm)) {
                        $movstart = $movstart + $movm * 60;
                    }
                    if (is_numeric($movs)) {
                        $movstart = $movstart + $movs;
                    }
                }
                // formatFilename replaces underscore by space -- undo this
                $movthumb = str_replace(' ', '_', $movthumb);
                if ($fb_type == "vimeo") {
                    // possible formats: http://www.vimeo.com/moogaloop.swf?clip_id=6566857
                    //                   http://www.vimeo.com/5324878
                    $pos = strpos($url, "clip_id=");
                    if ($pos !== false) {
                        $pos = $pos + 8;
                        $movthumb = substr($url, $pos);
                    } else {
                        $pos = strpos($url, "vimeo.com/");
                        if ($pos !== false) {
                            $pos = $pos + 10;
                            $movthumb = substr($url, $pos);
                            // if this format is received rewrite it to embed format
                            $url = "http://www.vimeo.com/moogaloop.swf?clip_id=" . $movthumb;
                        }
                    }
                }
            } else {
                $movthumb = $movid;
            }
            if ($fb_type == "youtube") {
                $urlthumb = "http://i2.ytimg.com/vi/" . $movthumb . "/default.jpg";
            } else {
                if ($fb_type == "vimeo") {
                    $urlvimphp = "http://vimeo.com/api/v2/video/" . $movthumb . ".php";
                    $vimeocontents = @file_get_contents($urlvimphp);
                    $thumbcontents = @unserialize(trim($vimeocontents));
                    $urlthumb = $thumbcontents[0][thumbnail_small];
                    if (empty($urlthumb)) {
                        $urlthumb = $thumbcontents[0][user_thumbnail_small];
                    }
                }
            }
            $code = sprintf("<a href=\"#%s%s\" class=\"fancytube\" title=\"%s\" rel=\"%s%s\" ><img src=\"%s\" class=\"%s\" alt=\"%s\" /></a>", $rel_id, $randnum, $title, $rel_id, $uid, $urlthumb, $fbclass, $alt);
            // some extra options for youtube (end with ampersand)
            // for explanation see http://code.google.com/intl/nl/apis/youtube/player_parameters.html
            // hl = language
            // autoplay: 1 = autoplay; 0 = click to play
            // rel = play related videos (0 = no)
            // fs = fullscreen allowed
            // options for vimeo just found by browsing through Google
            if (empty($movid)) {
                $urlmain = str_replace('watch?v=', 'v/', $url);
                $urlmain = str_replace('/embed/', '/v/', $urlmain);
                // convert a short link to a long one otherwise it won't work (if parms were in link they are now gone)
                // also if time parm was found the link needs to be reformatted to obligatory format
                if (strpos($urlmain, "//youtu.be/") || $movstart != 0) {
                    $urlmain = "http://www.youtube.com/v/" . $movthumb;
                }
                $urlid = "";
            } else {
                if ($fb_type == "youtube") {
                    $urlmain = "http://www.youtube.com/v/";
                    $urlid = $movid;
                } else {
                    if ($fb_type == "vimeo") {
                        $urlmain = "http://www.vimeo.com/moogaloop.swf?clip_id=";
                        $urlid = $movid;
                    }
                }
            }
            if ($fb_type == "youtube") {
                $urlextra = "&amp;hl=en&amp;autoplay=1&amp;rel=0&amp;fs=1&amp;start=" . $movstart;
            } else {
                if ($fb_type == "vimeo") {
                    $urlextra = "&amp;server=vimeo.com&amp;autoplay=1&amp;fullscreen=1&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0";
                }
            }
            $anchor_obj = sprintf("<span style=\"display: none\"><span id=\"%s%s\" ><object type=\"application/x-shockwave-flash\" data=\"%s%s%s\" width=\"%s\" height=\"%s\"><param name=\"movie\" value=\"%s%s%s\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param></object></span></span>", $rel_id, $randnum, $urlmain, $urlid, $urlextra, $objwidth, $objheight, $urlmain, $urlid, $urlextra);
            $code = $code . $anchor_obj;
            if ('center' == $align) {
                $code = '<p class="pivotx-wrapper">' . $code . '</p>';
            }
        } else {
            if ($fb_type == 'text') {
                // filename is not mandatory so fix an empty one with dummy string so code gets returned
                if (empty($filename)) {
                    $filename = '==fbdummy==';
                }
                // use random number to be fairly sure that constructed href will be unique
                // if by chance the number is the same then text shown (when clicked) will be the first one
                // also use this random number to construct a unique rel because grouping results
                // in array-reverse errors and crashing of the webpage when scrolling with the mouse!
                $randnum = rand();
                $code = sprintf("<a href=\"#%s%s\" class=\"fancytext\" title=\"%s\" rel=\"%s%s%s\" >%s</a>", $rel_id, $randnum, $title, $rel_id, $uid, $randnum, $thumbname);
                $textbegin = substr($text, 0, 5);
                $textrest = substr($text, 5);
                if ($textbegin !== "file:") {
                    $lines = $text;
                } else {
                    $docfile = $PIVOTX['paths']['pivotx_path'] . "docs/" . $textrest;
                    if (file_exists($docfile) && is_readable($docfile) && ($handle = fopen($docfile, 'r'))) {
                        $lines = fread($handle, filesize($docfile));
                        fclose($handle);
                    } else {
                        debug("Specified file cannot be found or read:'{$docfile}'");
                    }
                }
                // check whether the lines contain html.
                // If there are the popup will still function but with visible elements
                // better use iframe for text with html
                if (strlen($lines) != strlen(strip_tags($lines))) {
                    debug("Popup: '{$rel_id}{$randnum}' contains HTML elements.");
                    debug("A text popup should only contain plain text.");
                    debug("Try using fb_type iframe with an url pointing to a saved file instead.");
                }
                // couldn't get it to work correctly with an object (kept on forcing its own default size)
                // just specifying a span had the same result; can't use div and so on because pop-up
                // can be within an open paragraph
                // so switched to textarea (which is more customisable anyway); cols and rows are there for valid html
                $anchor_obj = sprintf("<span style=\"display: none\"><span id=\"%s%s\"><textarea class=\"%s\" style=\"width: %s; height: %s; overflow: auto; color: %s; background-color: %s\" readonly=\"readonly\" cols=\"\" rows=\"\">%s</textarea></span></span>", $rel_id, $randnum, $txtcls, $objwidth, $objheight, $txtcol, $txtcolbg, $lines);
                $code = $code . $anchor_obj;
                if ('center' == $align) {
                    $code = '<p class="pivotx-wrapper">' . $code . '</p>';
                }
            } else {
                if ($fb_type == 'iframe') {
                    // filename is not mandatory so fix an empty one with dummy string so code gets returned
                    if (empty($filename)) {
                        $filename = '==fbdummy==';
                    }
                    // use random number to be fairly sure that constructed rel will be unique
                    // if by chance the number is the same then iframe will open but clicking
                    // in the frame itself will be impossible
                    $randnum = rand();
                    $code = sprintf("<a href=\"%s\" class=\"fancyframe\" title=\"%s\" rel=\"%s%s%s\" >%s</a>", $url, $title, $rel_id, $uid, $randnum, $thumbname);
                    if ('center' == $align) {
                        $code = '<p class="pivotx-wrapper">' . $code . '</p>';
                    }
                } else {
                    if ($fb_type == 'flash') {
                        // filename is not mandatory so fix an empty one with dummy string so code gets returned
                        if (empty($filename)) {
                            $filename = '==fbdummy==';
                        }
                        // use random number to be fairly sure that constructed rel will be unique
                        // if by chance the number is the same then flash will open but clicking
                        // in the window itself will be impossible
                        $randnum = rand();
                        $code = sprintf("<a href=\"%s\" class=\"fancyflash\" title=\"%s\" rel=\"%s%s%s\" >%s</a>", $url, $title, $rel_id, $uid, $randnum, $thumbname);
                        if ('center' == $align) {
                            $code = '<p class="pivotx-wrapper">' . $code . '</p>';
                        }
                    }
                }
            }
        }
    }
    $PIVOTX['extensions']->addHook('after_parse', 'callback', 'fancyboxIncludeCallback');
    // not every type uses parm file so var filename gets a dummy value in those types
    if (!empty($filename)) {
        return $code;
    } else {
        return "";
    }
}
Beispiel #2
0
/**
 * Given raw text (eg typed in by a user), this function cleans it up
 * and removes any nasty tags that could mess up Moodle pages.
 *
 * NOTE: the format parameter was deprecated because we can safely clean only HTML.
 *
 * @param string $text The text to be cleaned
 * @param int $format deprecated parameter, should always contain FORMAT_HTML or FORMAT_MOODLE
 * @param array $options Array of options; currently only option supported is 'allowid' (if true,
 *   does not remove id attributes when cleaning)
 * @return string The cleaned up text
 */
function clean_text($text, $format = FORMAT_HTML, $options = array())
{
    global $ALLOWED_TAGS, $CFG;
    if (empty($text) or is_numeric($text)) {
        return (string) $text;
    }
    if ($format != FORMAT_HTML and $format != FORMAT_HTML) {
        // TODO: we need to standardise cleanup of text when loading it into editor first
        //debugging('clean_text() is designed to work only with html');
    }
    if ($format == FORMAT_PLAIN) {
        return $text;
    }
    if (!empty($CFG->enablehtmlpurifier)) {
        $text = purify_html($text, $options);
    } else {
        /// Fix non standard entity notations
        $text = fix_non_standard_entities($text);
        /// Remove tags that are not allowed
        $text = strip_tags($text, $ALLOWED_TAGS);
        /// Clean up embedded scripts and , using kses
        $text = cleanAttributes($text);
        /// Again remove tags that are not allowed
        $text = strip_tags($text, $ALLOWED_TAGS);
    }
    // Remove potential script events - some extra protection for undiscovered bugs in our code
    $text = preg_replace("~([^a-z])language([[:space:]]*)=~i", "\$1Xlanguage=", $text);
    $text = preg_replace("~([^a-z])on([a-z]+)([[:space:]]*)=~i", "\$1Xon\$2=", $text);
    return $text;
}
function clean_text($text, $format = FORMAT_MOODLE)
{
    global $ALLOWED_TAGS;
    switch ($format) {
        case FORMAT_PLAIN:
            return $text;
        default:
            /// Remove tags that are not allowed
            $text = strip_tags($text, $ALLOWED_TAGS);
            /// Add some breaks into long strings of &nbsp;
            $text = preg_replace('/((&nbsp;){10})&nbsp;/', '\\1 ', $text);
            /// Clean up embedded scripts and , using kses
            $text = cleanAttributes($text);
            /// Remove script events
            $text = eregi_replace("([^a-z])language([[:space:]]*)=", "\\1Xlanguage=", $text);
            $text = eregi_replace("([^a-z])on([a-z]+)([[:space:]]*)=", "\\1Xon\\2=", $text);
            return $text;
    }
}
Beispiel #4
0
/**
 * Given raw text (eg typed in by a user), this function cleans it up
 * and removes any nasty tags that could mess up Moodle pages.
 *
 * @uses FORMAT_MOODLE
 * @uses FORMAT_PLAIN
 * @uses ALLOWED_TAGS
 * @param string $text The text to be cleaned
 * @param int $format Identifier of the text format to be used
 *            (FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_WIKI, FORMAT_MARKDOWN)
 * @return string The cleaned up text
 */
function clean_text($text, $format = FORMAT_MOODLE)
{
    global $ALLOWED_TAGS, $CFG;
    if (empty($text) or is_numeric($text)) {
        return (string) $text;
    }
    switch ($format) {
        case FORMAT_PLAIN:
        case FORMAT_MARKDOWN:
            return $text;
        default:
            if (!empty($CFG->enablehtmlpurifier)) {
                $text = purify_html($text);
            } else {
                /// Fix non standard entity notations
                $text = preg_replace('/(&#[0-9]+)(;?)/', "\\1;", $text);
                $text = preg_replace('/(&#x[0-9a-fA-F]+)(;?)/', "\\1;", $text);
                /// Remove tags that are not allowed
                $text = strip_tags($text, $ALLOWED_TAGS);
                /// Clean up embedded scripts and , using kses
                $text = cleanAttributes($text);
                /// Again remove tags that are not allowed
                $text = strip_tags($text, $ALLOWED_TAGS);
            }
            /// Remove potential script events - some extra protection for undiscovered bugs in our code
            $text = eregi_replace("([^a-z])language([[:space:]]*)=", "\\1Xlanguage=", $text);
            $text = eregi_replace("([^a-z])on([a-z]+)([[:space:]]*)=", "\\1Xon\\2=", $text);
            return $text;
    }
}
/**
 * Inserts a linked list to the the different weblogs.
 *
 * @param array $params
 * @param object $smarty
 * @return string
 */
function smarty_weblog_list($params, &$smarty)
{
    global $PIVOTX;
    $params = cleanParams($params);
    $aExclude = array();
    if (!empty($params['exclude'])) {
        $aExclude = explode(",", $params['exclude']);
        $aExclude = array_map("trim", $aExclude);
        $aExclude = array_map("safe_string", $aExclude);
    }
    $Current_weblog = $PIVOTX['weblogs']->getCurrent();
    $format = getDefault($params['format'], "<li %active%><a href='%link%' title='%payoff%'>%display%</a></li>");
    $active = getDefault($params['current'], "class='activepage'");
    $output = array();
    $weblogs = $PIVOTX['weblogs']->getWeblogs();
    //echo "<pre>\n"; print_r($weblogs); echo "</pre>";
    foreach ($weblogs as $key => $weblog) {
        if (in_array(safeString($weblog['name']), $aExclude)) {
            continue;
        }
        $this_output = $format;
        $this_output = str_replace("%link%", $weblog['link'], $this_output);
        $this_output = str_replace("%name%", $weblog['name'], $this_output);
        $this_output = str_replace("%display%", $weblog['name'], $this_output);
        $this_output = str_replace("%payoff%", cleanAttributes($weblog['payoff']), $this_output);
        $this_output = str_replace("%internal%", $key, $this_output);
        if ($Current_weblog == $key) {
            $this_output = str_replace("%active%", $active, $this_output);
        } else {
            $this_output = str_replace("%active%", "", $this_output);
        }
        $output[$weblog['name']] .= $this_output;
    }
    if ($params['sort'] == "title") {
        ksort($output);
    }
    return stripslashes(implode("\n", $output));
}
/**
 * Output a slideshow feed as a template
 *
 * @param array $params
 * @return string
 */
function smarty_slideshow($params)
{
    global $PIVOTX, $slideshow_config;
    static $slideshowcount = 0;
    $js_insert = <<<EOF
<script type="text/javascript">
jQuery(window).bind("load", function(){
    jQuery("div#pivotx-slideshow-%count%").slideView(%parms%);
    setTimeout('slideNext_%count%()', %timeout%);
});

function slideNext_%count%() {

    if( typeof slideNext_%count%.currentslide == 'undefined' ) {
        slideNext_%count%.currentslide = 0;
    }

    var slidewidth = jQuery("div#pivotx-slideshow-%count%").find("li").find("img").width();
    var amountofslides = %amount% - 1; 

    if (amountofslides > slideNext_%count%.currentslide) {
        slideNext_%count%.currentslide++;
    } else {
        slideNext_%count%.currentslide = 0;
    }

    var xpos = (-slidewidth * slideNext_%count%.currentslide);
    jQuery("div#pivotx-slideshow-%count%").find("ul").animate({ left: xpos}, 1200, "easeInOutExpo");  

    setTimeout('slideNext_%count%()', %timeout%);

}
</script>
EOF;
    $params = clean_params($params);
    foreach (array('timeout', 'folder', 'width', 'height', 'limit', 'orderby', 'popup', 'recursion', 'nicenamewithdirs', 'iptcindex', 'iptcencoding') as $key) {
        if (isset($params[$key])) {
            ${$key} = $params[$key];
        } else {
            ${$key} = getDefault($PIVOTX['config']->get('slideshow_' . $key), $slideshow_config['slideshow_' . $key]);
        }
    }
    $imagefolder = addTrailingSlash($PIVOTX['paths']['upload_base_path'] . $folder);
    $ok_extensions = explode(",", "jpg,jpeg,png,gif");
    if (!file_exists($imagefolder) || !is_dir($imagefolder)) {
        debug("Image folder {$imagefolder} does not exist.");
        echo "Image folder {$imagefolder} does not exist.";
        return "";
    } else {
        if (!is_readable($imagefolder)) {
            debug("Image folder {$imagefolder} is not readable.");
            echo "Image folder {$imagefolder} is not readable.";
            return "";
        }
    }
    $images = array();
    $key = "";
    if ($recursion == 'no') {
        $dirs = array($imagefolder);
    } else {
        $dirs = slideshowGetDirs($imagefolder, $recursion);
        if ($recursion == 'all') {
            array_unshift($dirs, $imagefolder);
        }
    }
    foreach ($dirs as $folder) {
        $dir = dir($folder);
        while (false !== ($entry = $dir->read())) {
            if (in_array(strtolower(getExtension($entry)), $ok_extensions)) {
                if (strpos($entry, ".thumb.") > 0) {
                    continue;
                }
                $entry = $folder . $entry;
                if ($orderby == 'date_asc' || $orderby == 'date_desc') {
                    $key = filemtime($entry) . rand(10000, 99999);
                    $images[$key] = $entry;
                } else {
                    $images[] = $entry;
                }
            }
        }
        $dir->close();
    }
    if ($orderby == 'date_asc') {
        ksort($images);
    } else {
        if ($orderby == 'date_desc') {
            ksort($images);
            $images = array_reverse($images);
        } else {
            if ($orderby == 'alphabet') {
                natcasesort($images);
            } else {
                shuffle($images);
            }
        }
    }
    // Cut it to the desired length..
    $images = array_slice($images, 0, $limit);
    // Built the parms
    $tooltip = getDefault($PIVOTX['config']->get('slideshow_tooltip'), $slideshow_config['slideshow_tooltip']);
    $ttopacity = getDefault($PIVOTX['config']->get('slideshow_ttopacity'), $slideshow_config['slideshow_ttopacity']);
    $uibefore = getDefault($PIVOTX['config']->get('slideshow_uibefore'), $slideshow_config['slideshow_uibefore']);
    $zc = getDefault($PIVOTX['config']->get('slideshow_zc'), $slideshow_config['slideshow_zc']);
    $zcimg = '';
    if (isset($zc)) {
        $zcimg = '&amp;zc=' . $zc;
    }
    if ($tooltip == 1) {
        $parms = "{toolTip: true";
    } else {
        $parms = "{toolTip: false";
    }
    $parms .= ", ttOpacity: " . $ttopacity;
    if ($uibefore == 1) {
        $parms .= ", uiBefore: true}";
    } else {
        $parms .= ", uiBefore: false}";
    }
    $js_insert = str_replace('%timeout%', $timeout, $js_insert);
    $js_insert = str_replace('%count%', $slideshowcount, $js_insert);
    $js_insert = str_replace('%amount%', count($images), $js_insert);
    $js_insert = str_replace('%parms%', $parms, $js_insert);
    $PIVOTX['extensions']->addHook('after_parse', 'insert_before_close_head', $js_insert);
    // If a specific popup type is selected execute the callback.
    if ($popup != 'no') {
        $callback = $popup . "IncludeCallback";
        if (function_exists($callback)) {
            $PIVOTX['extensions']->addHook('after_parse', 'callback', $callback);
        } else {
            debug("There is no function '{$callback}' - the popups won't work.");
        }
    }
    $output = "\n<div id=\"pivotx-slideshow-{$slideshowcount}\" class=\"svw\">\n<ul>\n";
    foreach ($images as $image) {
        $file = $image;
        $image = str_replace($PIVOTX['paths']['upload_base_path'], '', $image);
        $image = str_replace(DIRECTORY_SEPARATOR, '/', $image);
        $nicefilename = formatFilename($image, $nicenamewithdirs);
        $title = false;
        if ($iptcindex) {
            getimagesize($file, $iptc);
            if (is_array($iptc) && $iptc['APP13']) {
                $iptc = iptcparse($iptc['APP13']);
                $title = $iptc[$iptcindex][0];
                if ($iptcencoding) {
                    $title = iconv($iptcencoding, 'UTF-8', $title);
                }
                $title = cleanAttributes($title);
            }
        }
        if (!$title) {
            $title = $nicefilename;
        }
        $line = "<li>\n";
        if ($popup != 'no') {
            $line .= sprintf("<a href=\"%s%s\" class=\"{$popup}\" rel=\"slideshow\" title=\"%s\">\n", $PIVOTX['paths']['upload_base_url'], $image, $title);
        }
        $line .= sprintf("<img src=\"%sincludes/timthumb.php?src=%s&amp;w=%s&amp;h=%s%s\" " . "alt=\"%s\" width=\"%s\" height=\"%s\" />\n", $PIVOTX['paths']['pivotx_url'], rawurlencode($image), $width, $height, $zcimg, $title, $width, $height);
        if ($popup != 'no') {
            $line .= "</a>";
        }
        $line .= "</li>\n";
        $output .= $line;
    }
    $output .= "</ul>\n</div>\n";
    $slideshowcount++;
    return $output;
}
Beispiel #7
0
/**
 * Given raw text (eg typed in by a user), this function cleans it up
 * and removes any nasty tags that could mess up Moodle pages.
 *
 * @uses FORMAT_MOODLE
 * @uses FORMAT_PLAIN
 * @uses ALLOWED_TAGS
 * @param string $text The text to be cleaned
 * @param int $format Identifier of the text format to be used
 *            (FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_WIKI, FORMAT_MARKDOWN)
 * @return string The cleaned up text
 */
function clean_text($text, $format = FORMAT_MOODLE)
{
    global $ALLOWED_TAGS;
    switch ($format) {
        case FORMAT_PLAIN:
        case FORMAT_MARKDOWN:
            return $text;
        default:
            /// Fix non standard entity notations
            $text = preg_replace('/(&#[0-9]+)(;?)/', "\\1;", $text);
            $text = preg_replace('/(&#x[0-9a-fA-F]+)(;?)/', "\\1;", $text);
            /// Remove tags that are not allowed
            $text = strip_tags($text, $ALLOWED_TAGS);
            /// Clean up embedded scripts and , using kses
            $text = cleanAttributes($text);
            /// Again remove tags that are not allowed
            $text = strip_tags($text, $ALLOWED_TAGS);
            /// Remove script events
            $text = eregi_replace("([^a-z])language([[:space:]]*)=", "\\1Xlanguage=", $text);
            $text = eregi_replace("([^a-z])on([a-z]+)([[:space:]]*)=", "\\1Xon\\2=", $text);
            return $text;
    }
}
/**
 * Make a link to an entry's body (if there is a body). If $params['html'] is
 * set to true, the HTML code for the link will be returned.
 *
 * @param array $data
 * @param string $weblog
 * @param array $params
 * @return string
 */
function makeMoreLink($data = "", $weblog = "", $params = array())
{
    global $PIVOTX;
    if ($weblog == "") {
        $weblog = $PIVOTX['weblogs']->getCurrent();
    }
    $weblogdata = $PIVOTX['weblogs']->getWeblog();
    $title = cleanAttributes($params['title']);
    if ('' != $title) {
        $title = 'title="' . $title . '" ';
        $title = str_replace("%title%", $data['title'], $title);
    }
    $anchorname = getDefault($params['anchorname'], 'body-anchor', true);
    $text = getDefault($params['text'], getDefault($weblogdata['read_more'], __('(more)')));
    if (strlen($data['body']) > 5) {
        $morelink = makeFilelink($data['code'], '', $anchorname);
        if ($params['html']) {
            $output = '<a class="pivotx-more-link" href="' . $morelink . "\" {$title}>{$text}</a>";
            $output = str_replace("%title%", $data['title'], $output);
            // Perhaps add the pre- and postfix to the output..
            if (!empty($params['prefix'])) {
                $output = $params['prefix'] . $output;
            }
            if (!empty($params['postfix'])) {
                $output .= $params['postfix'];
            }
        } else {
            $output = $morelink;
        }
    } else {
        $output = '';
    }
    return $output;
}
/**
 * Given raw text (eg typed in by a user), this function cleans it up
 * and removes any nasty tags that could mess up Moodle pages.
 *
 * @uses FORMAT_MOODLE
 * @uses FORMAT_PLAIN
 * @uses ALLOWED_TAGS
 * @param string $text The text to be cleaned
 * @param int $format Identifier of the text format to be used
 *            (FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_WIKI, FORMAT_MARKDOWN)
 * @return string The cleaned up text
 */
function clean_text($text, $format = FORMAT_MOODLE)
{
    global $ALLOWED_TAGS, $CFG;
    if (empty($text) or is_numeric($text)) {
        return (string) $text;
    }
    switch ($format) {
        case FORMAT_PLAIN:
            return $text;
        default:
            if (!empty($CFG->enablehtmlpurifier)) {
                //this is PHP5 only, the lib/setup.php contains a disabler for PHP4
                $text = purify_html($text);
            } else {
                /// Fix non standard entity notations
                $text = preg_replace('/&#0*([0-9]+);?/', "&#\\1;", $text);
                $text = preg_replace('/&#x0*([0-9a-fA-F]+);?/', "&#x\\1;", $text);
                $text = preg_replace('[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]', '', $text);
                /// Remove tags that are not allowed
                $text = strip_tags($text, $ALLOWED_TAGS);
                /// Clean up embedded scripts and , using kses
                $text = cleanAttributes($text);
                /// Again remove tags that are not allowed
                $text = strip_tags($text, $ALLOWED_TAGS);
            }
            /// Remove potential script events - some extra protection for undiscovered bugs in our code
            $text = eregi_replace("([^a-z])language([[:space:]]*)=", "\\1Xlanguage=", $text);
            $text = eregi_replace("([^a-z])on([a-z]+)([[:space:]]*)=", "\\1Xon\\2=", $text);
            return $text;
    }
}