<?php
/*
+ ----------------------------------------------------------------------------------------------------+
|        e107 website system 
|        Plugin Meta File :  e107_plugins/lightbox/e_meta.php
|        Email: support@free-source.net
|        $Revision: 372 $
|        $Date: 2007-02-12 23:22:29 +0200 (Mon, 12 Feb 2007) $
|        $Author: secretr $
|        Copyright Corllete Lab ( http://www.clabteam.com ) under GNU GPL License (http://gnu.org)
|        Support Sites : http://www.free-source.net/ | http://dev.e107bg.org/
+----------------------------------------------------------------------------------------------------+
*/
if (!defined('e107_INIT')) { exit; }
    //varset fix - varset from 0.77

$lb_path = e_PLUGIN.'lightbox/';
include_lan($lb_path."languages/".e_LANGUAGE.".php");

	echo "\n<script type='text/javascript'>\n";
	echo "<!--\n";
	echo "var fileLoadingImage =        '".$lb_path."src/images/loading.gif';\n";
	echo "var fileBottomNavCloseImage = '".$lb_path."src/images/close.gif';\n";
	echo "var resizeSpeed = ".varsettrue($pref['lightb_rspeed'], 7).";\n";
	echo "var borderSize = ".varset($pref['lightb_bsize'], 10).";\n";
    echo "var overlayOpacity = ".varset($pref['lightb_ovop'], 0.8).";\n";
    echo "var animate = ".varset($pref['lightb_animate'], 1).";\n";
	echo "var lbLan1 = '".LB_LAN_1."';\n";
	echo "var lbLan2 = '".LB_LAN_2."';\n";
	echo "var lbLan3 = '".LB_LAN_3."';\n";
	echo "// -->\n";
	echo "</script>";
	//v1.4	

	if($pref['lightb_enabled']){
    	echo '
    		<!-- Lightbox CSS -->
            <link rel="stylesheet" href="'.$lb_path.'src/css/lightbox.css" type="text/css" media="screen" />
        ';
    }	
	echo '
        <!-- Prototype and Scriptaculous -->
		<script src="'.$lb_path.'src/js/prototype.js" type="text/javascript"></script>
		<script src="'.$lb_path.'src/js/scriptaculous.js?load=effects'.($pref['lightb_window'] ? ',window' : '').'" type="text/javascript"></script>
	';
	//v1.4
	if($pref['lightb_enabled']){
    	echo '
    		<!-- Lightbox JS -->
    		<script src="'.$lb_path.'src/js/lightbox.js" type="text/javascript"></script>
        ';
    }

	//v.1.2
	//server check - detect if dhtml window is available:
	//example: 
    //$lbactive = varsettrue($pref['lightb_window'], false);
	if($pref['lightb_window']) {
    	echo '
    		<!-- Window default CSS (required) -->
    		<link href="'.$lb_path.'src/css/themes/default.css" rel="stylesheet" type="text/css" />
    		<!-- Window theme (optional) -->
    		'.($pref['lightb_wtheme'] ? '<link href="'.$lb_path.'src/css/themes/'.$pref['lightb_wtheme'].'.css" rel="stylesheet" type="text/css" />' : '').'
    		<!-- Lightbox shared JS -->
        ';
    	
        //client check: detect the lb existence with some js code in your plugins
        //exampe: 
        //if(typeof lbWindowLib != 'undefined' && lbWindowLib) 
        //  { your code here; }
        // Window js documentation - http://prototype-window.xilinus.com/documentation.html
        // Aculo's script documentation - http://wiki.script.aculo.us/scriptaculous/
        // Prototype documentation - http://www.prototypejs.org/api
        //
    	echo "
            <script type='text/javascript'>
            <!--
            var lbWindowLib = true; 
            var contentWin=null;
            //f-ajax file; w-window width; ttl - window title
            function e107Window(f,s,w,h,ttl){                
                if (contentWin != null) { 
                	e107alert('','".$tp->toJS(LB_LAN_39)."',200); 
                } else { 
                	if(!w) w=350;
                    if(!h) h=400; 
                    contentWin = new Window('e107_win', 
                							{".($pref['lightb_wtheme'] ? "className: '{$pref['lightb_wtheme']}', " : '')."resizable: true, 
                                                hideEffect:Effect.Fade, showEffect:Effect.Appear, minWidth: w, minHeight: h, zIndex: 6000,
                                                wiredDrag: true, title: ttl,
                                                closeCallback: function() { contentWin = null; return true; }
                                            });
                    if(!s && f) {
                        contentWin.setAjaxContent(f, {method: 'get'});
                    } else {
                        contentWin.getContent().update(s);
                    }
                    contentWin.setDestroyOnClose();
                    contentWin.showCenter(); 
                }
            }
            function e107confirm(f,s,w){               
                if(!s && f) {
                    var fcont = {url: f, options: {method: 'get'}};
                } else {
                    var fcont = s;
                }
                Dialog.confirm(fcont,
                    {   windowParameters: {".($pref['lightb_wtheme'] ? "className: '{$pref['lightb_wtheme']}'," : '' )." width:w},
                        okLabel: '".$tp->toJS(LB_LAN_7)."', cancelLabel: '".$tp->toJS(LB_LAN_8)."',
                        ok: function() {return true;}, cancel: function() {return false;},
                        zIndex: 6000
                       
                    });
            }
            function e107alert(f,s,w){ 
                if(!s && f) {
                    var fcont = {url: f, options: {method: 'get'}};
                } else {
                    var fcont = s;
                }         
                Dialog.alert(fcont,
                    {windowParameters: {".($pref['lightb_wtheme'] ? "className: '{$pref['lightb_wtheme']}'," : '' )." width:w},
                        okLabel: '".$tp->toJS(LB_LAN_7)."',
                        ok: function() {return true;},
                        zIndex: 6000
                        
                    });
            }
            // -->
            </script>
            ";
    } else {
    	//lightbox window lib disabled
        echo "
            <script type='text/javascript'>
            <!--
                var lbWindowLib = false; 
            // -->
            </script>
            ";
    }

   //lighbox window - eval lbBBcode from bbcode handler
   function lbBBcode($class) {
       global $pref, $e107, $tp, $IMAGES_DIRECTORY, $FILES_DIRECTORY, $PLUGINS_DIRECTORY,$ADMIN_DIRECTORY;
       //js - collects all values from the ajax generated window content and creates bbcode insertion string
       //v1.4 - define lbBBcode to prevent parse error if LB not propper updated
       if(!$pref['lightb_enabled'])
            return '';
       if(check_class($class) && $pref['lightb_window']) {       
            $txt = "
                <script type='text/javascript'>
                <!--
                //lightbox bbwindow specific
                function lbBBConfirm(dummy){                
                    if(!lbWindowLib) return;
                    e107Window('".e_PLUGIN."lightbox/ajax_bb.php','',450,370,'".$tp->toJS(LB_LAN_35)."');
                }
                //lightbox add text function
                function addLightbox(mod) {
                    if(!e107_selectedInputArea) {
                        e107alert('','".$tp->toJS(LB_LAN_36)."',350);
                        return false;
                    }
                    var imgurl='';
                    var thurl='';
                    if(mod=='advanced') {
                        var imgid = document.getElementById('lb_imgsel');
                        if(imgid.value){
                            imgurl = imgid.value;
                            imgurl = imgurl.replace('".e_IMAGE_ABS."','{e_IMAGE}');
                            imgurl = imgurl.replace('".e_FILE_ABS."','{e_FILE}');
                            imgurl = imgurl.replace('".e_PLUGIN_ABS."','{e_PLUGIN}');
                            imgurl = imgurl.replace('".e_ADMIN_ABS."','".e_ADMIN."');
                        }
                        var thimgid = document.getElementById('lb_thimgsel');
                        if(thimgid.value) {
                            thurl = thimgid.value;
                            thurl = thurl.replace('".e_IMAGE_ABS."','{e_IMAGE}');
                            thurl = thurl.replace('".e_FILE_ABS."','{e_FILE}');
                            thurl = thurl.replace('".e_PLUGIN_ABS."','{e_PLUGIN}');
                            thurl = thurl.replace('".e_ADMIN_ABS."','".e_ADMIN."');
                        }
                        var lbthtext = document.getElementById('lb_athtext') ? document.getElementById('lb_athtext').value : '';
                        var lbtitle = document.getElementById('lb_atitle') ? document.getElementById('lb_atitle').value : '';
                        var lbg = document.getElementById('lb_agroup') ? document.getElementById('lb_agroup').value : '';
                        var lbf = document.getElementById('lb_afloat') ? document.getElementById('lb_afloat').value : '';
                    } else {
                        var imgid = document.getElementById('lb_img');
                        imgurl = imgid.value ? imgid.value : '';
                        if(imgurl) {
                            imgurl = String(imgurl);
                            if(imgurl.toLowerCase().match('http://')) {
                                imgurl = imgurl.replace('".$e107->http_path.$IMAGES_DIRECTORY."','{e_IMAGE}');
                                imgurl = imgurl.replace('".$e107->http_path.$FILES_DIRECTORY."','{e_FILE}');
                                imgurl = imgurl.replace('".$e107->http_path.$PLUGINS_DIRECTORY."','{e_PLUGIN}');
                                imgurl = imgurl.replace('".$e107->http_path.$ADMIN_DIRECTORY."','".e_ADMIN."');
                            } else {
                                imgurl = imgurl.replace('".e_IMAGE_ABS."','{e_IMAGE}');
                                imgurl = imgurl.replace('".e_FILE_ABS."','{e_FILE}');
                                imgurl = imgurl.replace('".e_PLUGIN_ABS."','{e_PLUGIN}');
                                imgurl = imgurl.replace('".e_ADMIN_ABS."','".e_ADMIN."');
                            }
                        }
                        var thimgid = document.getElementById('lb_thimg');
                        thurl = thimgid.value ? thimgid.value : '';
                        if(thurl) {
                            thurl = String(thurl);
                            
                            if(thurl.toLowerCase().match('".$e107->http_path."')) {
                                thurl = thurl.replace('".$e107->http_path.$IMAGES_DIRECTORY."','{e_IMAGE}');
                                thurl = thurl.replace('".$e107->http_path.$FILES_DIRECTORY."','{e_FILE}');
                                thurl = thurl.replace('".$e107->http_path.$PLUGINS_DIRECTORY."','{e_PLUGIN}');
                                thurl = thurl.replace('".$e107->http_path.$ADMIN_DIRECTORY."','".e_ADMIN."');
                            } else {
                                thurl = thurl.replace('".e_IMAGE_ABS."','{e_IMAGE}');
                                thurl = thurl.replace('".e_FILE_ABS."','{e_FILE}');
                                thurl = thurl.replace('".e_PLUGIN_ABS."','{e_PLUGIN}');
                                thurl = thurl.replace('".e_ADMIN_ABS."','".e_ADMIN."');
                            }
                        }
                        var lbthtext = document.getElementById('lb_thtext') ? document.getElementById('lb_thtext').value : '';
                        var lbtitle = document.getElementById('lb_title') ? document.getElementById('lb_title').value : '';
                        var lbg = document.getElementById('lb_group') ? document.getElementById('lb_group').value : '';
                        var lbf = document.getElementById('lb_float') ? document.getElementById('lb_float').value : '';
                    }

                    if(imgurl == '' || imgurl == 'http://') {
                        e107alert('','".$tp->toJS(LB_LAN_37)."',350);
                        return false;
                    }     
                                         
                    if(!lbthtext) lbthtext = '".str_replace("'", "\'", LB_LAN_35a)."';
                    thurl = thurl? '[img]' + thurl + '[/img]' : lbthtext;
                    addtext('[lightbox=' + imgurl + '|' + lbtitle + '|' + lbg + '|' + lbf + ']' + thurl + '[/lightbox]');
                    return true;
                }
                // -->
                </script>
                ";
        } else {
            //not enough permissions - switch to standart insertion mod
            $txt = "
                <script type='text/javascript'>
                <!--
                //lightbox bbwindow specific
                function lbBBConfirm(dummy){                
                   addtext('[lightbox=image_url|title|group|float][/lightbox]');
                }
                // -->
                </script>
            ";
       }
       return $txt; 
    }
?>