index 34ab7348282a21299de084f5255dab123b874207..aeb543b7e0c7e89c3243e312f90c2284b6ec1769 100644 (file)
}
+/* Mark the occurance of a string with a span */
+function mark($needle, $haystack, $ignorecase= true)
+{
+ $result= "";
+
+ while (preg_match('/^(.*)('.preg_quote($needle).')(.*)$/i', $haystack, $matches)) {
+ $result.= $matches[1]."<span class='mark'>".$matches[2]."</span>";
+ $haystack= $matches[3];
+ }
+
+ return $result.$haystack;
+}
+
+
+/* Return an image description using the path */
+function image($path, $action= "", $title= "", $align= "middle")
+{
+ global $config;
+ global $BASE_DIR;
+ $label= null;
+
+ // Bail out, if there's no style file
+ if(!session::global_is_set("img-styles")){
+
+ // Get theme
+ if (isset ($config)){
+ $theme= $config->get_cfg_value("theme", "default");
+ } else {
+ # For debuging - avoid that there's no theme set
+ die("config not set!");
+ $theme= "default";
+ }
+
+ if (!file_exists("$BASE_DIR/ihtml/themes/$theme/img.styles")){
+ die ("No img.style for this theme found!");
+ }
+
+ session::global_set('img-styles', unserialize(file_get_contents("$BASE_DIR/ihtml/themes/$theme/img.styles")));
+ }
+ $styles= session::global_get('img-styles');
+
+ /* Extract labels from path */
+ if (preg_match("/\.png\[(.*)\]$/", $path, $matches)) {
+ $label= $matches[1];
+ }
+
+ $lbl= "";
+ if ($label) {
+ if (isset($styles["images/label-".$label.".png"])) {
+ $lbl= "<div style='".$styles["images/label-".$label.".png"]."'></div>";
+ } else {
+ die("Invalid label specified: $label\n");
+ }
+
+ $path= preg_replace("/\[.*\]$/", "", $path);
+ }
+
+ // Non middle layout?
+ if ($align == "middle") {
+ $align= "";
+ } else {
+ $align= ";vertical-align:$align";
+ }
+
+ // Clickable image or not?
+ if ($title != "") {
+ $title= "title='$title'";
+ }
+ if ($action == "") {
+ return "<div class='img' $title style='".$styles[$path]."$align'>$lbl</div>";
+ } else {
+ return "<input type='submit' class='img' id='$action' value='' name='$action' $title style='".$styles[$path]."$align'>";
+ }
+}
+
+
+
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>