function widget_zenpressed($args) { // $args is an array of strings that help widgets to conform to // the active theme: before_widget, before_title, after_widget, // and after_title are the array keys. Default tags: li and h2. extract($args); // Each widget can store its own options. We keep strings here. $options = get_option('widget_zenpressed'); $title = $options['title']; $conf = zenpressed_conf(); if ($options['select'] != "") { $conf['select'] = $options['select']; } if ($options['count'] != "") { $conf['count'] = $options['count']; } if ($options['size'] != "") { $conf['size'] = $options['size']; } if ($options['album'] != "") { $conf['album'] = $options['album']; } $conf['showtitle'] = $options['showtitle'] ? "on" : "off"; $conf['showdescription'] = $options['showdescription'] ? "on" : "off"; $conf['showalbumtitle'] = $options['showalbumtitle'] ? "on" : "off"; $conf['showalbumdescription'] = $options['showalbumdescription'] ? "on" : "off"; $conf['lightbox'] = $options['lightbox'] ? "on" : "off"; if ($options['lightbox_size'] != "") { $conf['lightbox_size'] = $options['lightbox_size']; } // These lines generate our output. Widgets can be very complex // but as you can see here, they can also be very, very simple. echo $before_widget . $before_title . $title . $after_title; zenpressed_photos($conf['album'], $conf); echo $after_widget; }
function zenpressed_replace($text) { // find all zen tags preg_match_all('!<zen([^>]*)[ ]*[/]*>!imU', $text, $tags, PREG_SET_ORDER); foreach ($tags as $tag) { // find all attributes preg_match_all('!(url|album|image|id|size|showlink|showtitle|showdescription|title|description|select|count|showalbumtitle|showalbumdescription|class|lightbox|lightbox_size)="([^"]*)"!i', $tag[0], $attributes, PREG_SET_ORDER); $conf = array(); foreach ($attributes as $attribute) { $conf[$attribute[1]] = $attribute[2]; } if (isset($conf["url"])) { $conf["album"] = substr($conf["url"], 0, strpos($conf["url"], "/")); $conf["image"] = substr(strrchr($conf["url"], '/'), 1); $conf["url"] = null; } $conf = zenpressed_conf($conf); // generate replacement code $conf["string"] = "true"; if (isset($conf["id"])) { $c = zenpressed_photobyid($conf["id"], $conf); } if (isset($conf["image"])) { $c = zenpressed_photo($conf["image"], $conf["album"], $conf); } else { $c = zenpressed_photos($conf["album"], $conf); } // replace tag with html */ $text = str_replace($tag[0], $c, $text); } return $text; }