WordPress.org

Plugin Directory


Ignore:
Timestamp:
07/30/08 23:44:55 (6 years ago)
Author:
mark8barnes
Message:
 
Location:
sermon-browser/branches/0.10-0.23
Files:
18 added
2 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • sermon-browser/branches/0.10-0.23/datePicker.js

    r57035 r57037  
    55 * Copyright (c) 2006 Kelvin Luck (kelvinluck.com) 
    66 * Licensed under the MIT License: 
    7  *   http://www.opensource.org/licenses/mit-license.php 
     7 * http://www.opensource.org/licenses/mit-license.php 
    88 * 
    9  * $LastChangedDate: 2007-09-22 14:56:10 +0100 (Sat, 22 Sep 2007) $ 
    10  * $Rev: 3436 $ 
     9 * $LastChangedDate: 2007-04-12 10:01:01 +0100 (Thu, 12 Apr 2007) $ 
     10 * $Rev: 1672 $ 
    1111 */ 
    12 jQuery.datePicker=function(){if(window.console==undefined){window.console={log:function(){}}}var months=['January','February','March','April','May','June','July','August','September','October','November','December'];var days=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];var navLinks={p:'Prev',n:'Next',c:'Close',b:'Choose date'};var dateFormat='dmy';var dateSeparator="/";var _drawingMonth=false;var _firstDayOfWeek;var _firstDate;var _lastDate;var _selectedDate;var _openCal;var _zeroPad=function(num){var s='0'+num;return s.substring(s.length-2)};var _strToDate=function(dIn){switch(dateFormat){case'ymd':dParts=dIn.split(dateSeparator);return new Date(dParts[0],Number(dParts[1])-1,dParts[2]);case'dmy':dParts=dIn.split(dateSeparator);return new Date(dParts[2],Number(dParts[1])-1,Number(dParts[0]));case'dmmy':dParts=dIn.split(dateSeparator);for(var m=0;m<12;m++){if(dParts[1].toLowerCase()==months[m].substr(0,3).toLowerCase()){return new Date(Number(dParts[2]),m,Number(dParts[0]))}}return undefined;case'mdy':default:var parts=parts?parts:[2,1,0];dParts=dIn.split(dateSeparator);return new Date(dParts[2],Number(dParts[0])-1,Number(dParts[1]))}};var _dateToStr=function(d){var dY=d.getFullYear();var dM=_zeroPad(d.getMonth()+1);var dD=_zeroPad(d.getDate());switch(dateFormat){case'ymd':return dY+dateSeparator+dM+dateSeparator+dD;case'dmy':return dD+dateSeparator+dM+dateSeparator+dY;case'dmmy':return dD+dateSeparator+months[d.getMonth()].substr(0,3)+dateSeparator+dY;case'mdy':default:return dM+dateSeparator+dD+dateSeparator+dY}};var _getCalendarDiv=function(dIn){var today=new Date();if(dIn==undefined){d=new Date(today.getFullYear(),today.getMonth(),1)}else{d=dIn;d.setDate(1)}if((d.getMonth()<_firstDate.getMonth()&&d.getFullYear()==_firstDate.getFullYear())||d.getFullYear()<_firstDate.getFullYear()){d=new Date(_firstDate.getFullYear(),_firstDate.getMonth(),1)}else if((d.getMonth()>_lastDate.getMonth()&&d.getFullYear()==_lastDate.getFullYear())||d.getFullYear()>_lastDate.getFullYear()){d=new Date(_lastDate.getFullYear(),_lastDate.getMonth(),1)}var jCalDiv=jQuery("<div></div>").attr('class','popup-calendar');var firstMonth=true;var firstDate=_firstDate.getDate();var prevLinkDiv='';if(!(d.getMonth()==_firstDate.getMonth()&&d.getFullYear()==_firstDate.getFullYear())){firstMonth=false;var lastMonth=d.getMonth()==0?new Date(d.getFullYear()-1,11,1):new Date(d.getFullYear(),d.getMonth()-1,1);var prevLink=jQuery("<a></a>").attr('href','javascript:;').html(navLinks.p).click(function(){jQuery.datePicker.changeMonth(lastMonth,this);return false});prevLinkDiv=jQuery("<div></div>").attr('class','link-prev').html('&lt;').append(prevLink)}var finalMonth=true;var lastDate=_lastDate.getDate();nextLinkDiv='';if(!(d.getMonth()==_lastDate.getMonth()&&d.getFullYear()==_lastDate.getFullYear())){finalMonth=false;var nextMonth=new Date(d.getFullYear(),d.getMonth()+1,1);var nextLink=jQuery("<a></a>").attr('href','javascript:;').html(navLinks.n).click(function(){jQuery.datePicker.changeMonth(nextMonth,this);return false});nextLinkDiv=jQuery("<div></div>").attr('class','link-next').html('&gt;').prepend(nextLink)}var closeLink=jQuery("<a></a>").attr('href','javascript:;').html(navLinks.c).click(function(){jQuery.datePicker.closeCalendar()});jCalDiv.append(jQuery("<div></div>").attr('class','link-close').append(closeLink),jQuery("<h3></h3>").html(months[d.getMonth()]+' '+d.getFullYear()));var headRow=jQuery("<tr></tr>");for(var i=_firstDayOfWeek;i<_firstDayOfWeek+7;i++){var weekday=i%7;var day=days[weekday];headRow.append(jQuery("<th></th>").attr({'scope':'col','abbr':day,'title':day,'class':(weekday==0||weekday==6?'weekend':'weekday')}).html(day.substr(0,1)))}var tBody=jQuery("<tbody></tbody>");var lastDay=(new Date(d.getFullYear(),d.getMonth()+1,0)).getDate();var curDay=_firstDayOfWeek-d.getDay();if(curDay>0)curDay-=7;var todayDate=(new Date()).getDate();var thisMonth=d.getMonth()==today.getMonth()&&d.getFullYear()==today.getFullYear();var w=0;while(w++<6&&curDay<lastDay){var thisRow=jQuery("<tr></tr>");for(var i=0;i<7;i++){var weekday=(_firstDayOfWeek+i)%7;var atts={'class':(weekday==0||weekday==6?'weekend ':'weekday ')};if(curDay<0||curDay>=lastDay){dayStr=' '}else if(firstMonth&&curDay<firstDate-1){dayStr=curDay+1;atts['class']+='inactive'}else if(finalMonth&&curDay>lastDate-1){dayStr=curDay+1;atts['class']+='inactive'}else{d.setDate(curDay+1);var dStr=_dateToStr(d);dayStr=jQuery("<a></a>").attr({'href':'javascript:;','rel':dStr}).html(curDay+1).click(function(e){jQuery.datePicker.selectDate(jQuery.attr(this,'rel'),this);return false})[0];if(_selectedDate&&_selectedDate==dStr){jQuery(dayStr).attr('class','selected')}}if(thisMonth&&curDay+1==todayDate){atts['class']+=' today'}thisRow.append(jQuery("<td></td>").attr(atts).append(dayStr));curDay++}tBody.append(thisRow)}jCalDiv.append(jQuery("<table></table>").attr('cellspacing',2).append("<thead></thead>").find("thead").append(headRow).parent().append(tBody.children())).append(prevLinkDiv).append(nextLinkDiv);if(jQuery.browser.msie){var iframe=['<iframe class="bgiframe" tabindex="-1" src="blank.html" ','style="display:block; position:absolute;','top: 0;','left:0;','z-index:-1; filter:Alpha(Opacity=\'0\');','width:3000px;','height:3000px"/>'].join('');jCalDiv.append(document.createElement(iframe))}jCalDiv.css({'display':'block'});return jCalDiv[0]};var _draw=function(c){jQuery('div.popup-calendar a',_openCal[0]).unbind();jQuery('div.popup-calendar',_openCal[0]).empty();jQuery('div.popup-calendar',_openCal[0]).remove();_openCal.append(c)};var _closeDatePicker=function(){jQuery('div.popup-calendar a',_openCal).unbind();jQuery('div.popup-calendar',_openCal).empty();jQuery('div.popup-calendar',_openCal).css({'display':'none'});jQuery(document).unbind('mousedown',_checkMouse);delete _openCal;_openCal=null};var _handleKeys=function(e){var key=e.keyCode?e.keyCode:(e.which?e.which:0);if(key==27){_closeDatePicker()}return false};var _checkMouse=function(e){if(!_drawingMonth){var target=jQuery.browser.msie?window.event.srcElement:e.target;var cp=jQuery(target).findClosestParent('div.popup-calendar-wrapper');if(cp.get(0).className!='date-picker-holder'){_closeDatePicker()}}};return{getChooseDateStr:function(){return navLinks.b},show:function(){if(_openCal){_closeDatePicker()}this.blur();var input=jQuery('input',jQuery(this).findClosestParent('input')[0])[0];_firstDate=input._startDate;_lastDate=input._endDate;_firstDayOfWeek=input._firstDayOfWeek;_openCal=jQuery(this).parent().find('>div.popup-calendar-wrapper');var d=jQuery(input).val();if(d!=''){if(_dateToStr(_strToDate(d))==d){_selectedDate=d;_draw(_getCalendarDiv(_strToDate(d)))}else{_selectedDate=false;_draw(_getCalendarDiv())}}else{_selectedDate=false;_draw(_getCalendarDiv())}jQuery(document).bind('mousedown',_checkMouse)},changeMonth:function(d,e){_drawingMonth=true;_draw(_getCalendarDiv(d));_drawingMonth=false},selectDate:function(d,ele){selectedDate=d;var $theInput=jQuery('input',jQuery(ele).findClosestParent('input')[0]);$theInput.val(d);$theInput.trigger('change');_closeDatePicker(ele)},closeCalendar:function(){_closeDatePicker(this)},setInited:function(i){i._inited=true},isInited:function(i){return i._inited!=undefined},setDateFormat:function(format,separator){dateFormat=format.toLowerCase();dateSeparator=separator?separator:"/"},setLanguageStrings:function(aDays,aMonths,aNavLinks){days=aDays;months=aMonths;navLinks=aNavLinks},setDateWindow:function(i,w){if(w==undefined)w={};if(w.startDate==undefined){i._startDate=new Date()}else{i._startDate=_strToDate(w.startDate)}if(w.endDate==undefined){i._endDate=new Date();i._endDate.setFullYear(i._endDate.getFullYear()+5)}else{i._endDate=_strToDate(w.endDate)};i._firstDayOfWeek=w.firstDayOfWeek==undefined?0:w.firstDayOfWeek}}}();jQuery.fn.findClosestParent=function(s){var ele=this;while(true){if(jQuery(s,ele[0]).length>0){return(ele)}ele=ele.parent();if(ele[0].length==0){return false}}};jQuery.fn.datePicker=function(a){this.each(function(){if(this.nodeName.toLowerCase()!='input')return;jQuery.datePicker.setDateWindow(this,a);if(!jQuery.datePicker.isInited(this)){var chooseDate=jQuery.datePicker.getChooseDateStr();var calBut;if(a&&a.inputClick){calBut=jQuery(this).attr('title',chooseDate).addClass('date-picker')}else{calBut=jQuery("<a></a>").attr({'href':'javascript:;','class':'date-picker','title':chooseDate}).append("<span>"+chooseDate+"</span>")}jQuery(this).wrap('<div class="date-picker-holder"></div>').after(jQuery('<div></div>').attr('class','popup-calendar-wrapper').append(jQuery("<div></div>").attr({'class':'popup-calendar'})),calBut);calBut.bind('click',jQuery.datePicker.show);jQuery.datePicker.setInited(this)}});return this}; 
     12 
     13jQuery.datePicker = function() 
     14{ 
     15    // so that firebug console.log statements don't break IE 
     16    if (window.console == undefined) { window.console = {log:function(){}}; } 
     17 
     18    var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; 
     19    var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; 
     20    var navLinks = {p:'Prev', n:'Next', c:'Close', b:'Choose date'}; 
     21    var dateFormat = 'dmy'; 
     22    var dateSeparator = "/"; 
     23    var _drawingMonth = false; 
     24    var _firstDayOfWeek; 
     25    var _firstDate; 
     26    var _lastDate; 
     27 
     28    var _selectedDate; 
     29    var _openCal; 
     30 
     31    var _zeroPad = function(num) { 
     32        var s = '0'+num; 
     33        return s.substring(s.length-2) 
     34        //return ('0'+num).substring(-2); // doesn't work on IE :( 
     35    }; 
     36    var _strToDate = function(dIn) 
     37    { 
     38        switch (dateFormat) { 
     39            case 'ymd': 
     40                dParts = dIn.split(dateSeparator); 
     41                return new Date(dParts[0], Number(dParts[1])-1, dParts[2]); 
     42            case 'dmy': 
     43                dParts = dIn.split(dateSeparator); 
     44                return new Date(dParts[2], Number(dParts[1])-1, Number(dParts[0])); 
     45            case 'dmmy': 
     46                dParts = dIn.split(dateSeparator); 
     47                for (var m=0; m<12; m++) { 
     48                    if (dParts[1].toLowerCase() == months[m].substr(0,3).toLowerCase())  { 
     49                        return new Date(Number(dParts[2]), m, Number(dParts[0])); 
     50                    } 
     51                } 
     52                return undefined; 
     53            case 'mdy': 
     54            default: 
     55                var parts = parts ? parts : [2, 1, 0]; 
     56                dParts = dIn.split(dateSeparator); 
     57                return new Date(dParts[2], Number(dParts[0])-1, Number(dParts[1])); 
     58        } 
     59    }; 
     60    var _dateToStr = function(d) 
     61    { 
     62        var dY = d.getFullYear(); 
     63        var dM = _zeroPad(d.getMonth()+1); 
     64        var dD = _zeroPad(d.getDate()); 
     65        switch (dateFormat) { 
     66            case 'ymd': 
     67                return dY + dateSeparator + dM + dateSeparator + dD; 
     68            case 'dmy': 
     69                return dD + dateSeparator + dM + dateSeparator + dY; 
     70            case 'dmmy': 
     71                return dD + dateSeparator + months[d.getMonth()].substr(0,3) + dateSeparator + dY; 
     72            case 'mdy': 
     73            default: 
     74                return dM + dateSeparator + dD + dateSeparator + dY; 
     75        } 
     76    }; 
     77 
     78    var _getCalendarDiv = function(dIn) 
     79    { 
     80        var today = new Date(); 
     81        if (dIn == undefined) { 
     82            // start from this month. 
     83            d = new Date(today.getFullYear(), today.getMonth(), 1); 
     84        } else { 
     85            // start from the passed in date 
     86            d = dIn; 
     87            d.setDate(1); 
     88        } 
     89        // check that date is within allowed limits: 
     90        if ((d.getMonth() < _firstDate.getMonth() && d.getFullYear() == _firstDate.getFullYear()) || d.getFullYear() < _firstDate.getFullYear()) { 
     91            d = new Date(_firstDate.getFullYear(), _firstDate.getMonth(), 1);; 
     92        } else if ((d.getMonth() > _lastDate.getMonth() && d.getFullYear() == _lastDate.getFullYear()) || d.getFullYear() > _lastDate.getFullYear()) { 
     93            d = new Date(_lastDate.getFullYear(), _lastDate.getMonth(), 1);; 
     94        } 
     95 
     96        var jCalDiv = jQuery("<div></div>").attr('class','popup-calendar'); 
     97        var firstMonth = true; 
     98        var firstDate = _firstDate.getDate(); 
     99 
     100        // create prev and next links 
     101        var prevLinkDiv = ''; 
     102        if (!(d.getMonth() == _firstDate.getMonth() && d.getFullYear() == _firstDate.getFullYear())) { 
     103            // not in first display month so show a previous link 
     104            firstMonth = false; 
     105            var lastMonth = d.getMonth() == 0 ? new Date(d.getFullYear()-1, 11, 1) : new Date(d.getFullYear(), d.getMonth()-1, 1); 
     106            var prevLink = jQuery("<a></a>").attr('href', 'javascript:;').html(navLinks.p).click(function() 
     107            { 
     108                jQuery.datePicker.changeMonth(lastMonth, this); 
     109                return false; 
     110            }); 
     111            prevLinkDiv = jQuery("<div></div>").attr('class','link-prev').html('&lt;').append(prevLink); 
     112        } 
     113 
     114        var finalMonth = true; 
     115        var lastDate = _lastDate.getDate(); 
     116        nextLinkDiv = ''; 
     117        if (!(d.getMonth() == _lastDate.getMonth() && d.getFullYear() == _lastDate.getFullYear())) { 
     118            // in the last month - no next link 
     119            finalMonth = false; 
     120            var nextMonth = new Date(d.getFullYear(), d.getMonth()+1, 1); 
     121            var nextLink = jQuery("<a></a>").attr('href', 'javascript:;').html(navLinks.n).click(function() 
     122            { 
     123                jQuery.datePicker.changeMonth(nextMonth, this); 
     124                return false; 
     125            }); 
     126            nextLinkDiv = jQuery("<div></div>").attr('class','link-next').html('&gt;').prepend(nextLink); 
     127        } 
     128 
     129        var closeLink = jQuery("<a></a>").attr('href','javascript:;').html(navLinks.c).click(function() 
     130        { 
     131            jQuery.datePicker.closeCalendar(); 
     132        }); 
     133 
     134        jCalDiv.append( 
     135            jQuery("<div></div>").attr('class', 'link-close').append(closeLink), 
     136            jQuery("<h3></h3>").html(months[d.getMonth()] + ' ' + d.getFullYear()) 
     137        ).append(prevLinkDiv).append(nextLinkDiv).append("<br/>"); 
     138        var headRow = jQuery("<tr></tr>"); 
     139        for (var i=_firstDayOfWeek; i<_firstDayOfWeek+7; i++) { 
     140            var weekday = i%7; 
     141            var day = days[weekday]; 
     142            headRow.append( 
     143                jQuery("<th></th>").attr({'scope':'col', 'abbr':day, 'title':day, 'class':(weekday == 0 || weekday == 6 ? 'weekend' : 'weekday')}).html(day.substr(0, 1)) 
     144            ); 
     145        } 
     146 
     147        var tBody = jQuery("<tbody></tbody>"); 
     148 
     149        var lastDay = (new Date(d.getFullYear(), d.getMonth()+1, 0)).getDate(); 
     150        var curDay = _firstDayOfWeek - d.getDay(); 
     151        if (curDay > 0) curDay -= 7; 
     152 
     153        var todayDate = (new Date()).getDate(); 
     154        var thisMonth = d.getMonth() == today.getMonth() && d.getFullYear() == today.getFullYear(); 
     155 
     156        var w = 0; 
     157        while (w++<6) { 
     158            var thisRow = jQuery("<tr></tr>"); 
     159            for (var i=0; i<7; i++) { 
     160                var weekday = (_firstDayOfWeek + i) % 7; 
     161                var atts = {'class':(weekday == 0 || weekday == 6 ? 'weekend ' : 'weekday ')}; 
     162 
     163                if (curDay < 0 || curDay >= lastDay) { 
     164                    dayStr = ' '; 
     165                } else if (firstMonth && curDay < firstDate-1) { 
     166                    dayStr = curDay+1; 
     167                    atts['class'] += 'inactive'; 
     168                } else if (finalMonth && curDay > lastDate-1) { 
     169                    dayStr = curDay+1; 
     170                    atts['class'] += 'inactive'; 
     171                } else { 
     172                    d.setDate(curDay+1); 
     173                    var dStr = _dateToStr(d); 
     174                    dayStr = jQuery("<a></a>").attr({'href':'javascript:;', 'rel':dStr}).html(curDay+1).click(function(e) 
     175                    { 
     176                        jQuery.datePicker.selectDate(jQuery.attr(this, 'rel'), this); 
     177                        return false; 
     178                    })[0]; 
     179                    if (_selectedDate && _selectedDate==dStr) { 
     180                        jQuery(dayStr).attr('class','selected'); 
     181                    } 
     182                } 
     183 
     184                if (thisMonth && curDay+1 == todayDate) { 
     185                    atts['class'] += 'today'; 
     186                } 
     187                thisRow.append(jQuery("<td></td>").attr(atts).append(dayStr)); 
     188                curDay++; 
     189            } 
     190            tBody.append(thisRow); 
     191        } 
     192 
     193        jCalDiv.append( 
     194            jQuery("<table></table>").attr('cellspacing',2).append("<thead></thead>") 
     195            .find("thead").append(headRow).parent().append(tBody.children()) 
     196        ); 
     197         
     198        if (jQuery.browser.msie) { 
     199 
     200            // we put a styled iframe behind the calendar so HTML SELECT elements don't show through 
     201            var iframe = [  '<iframe class="bgiframe" tabindex="-1" src="blank.html" ', 
     202                            'style="display:block; position:absolute;', 
     203                            'top: 0;', 
     204                            'left:0;', 
     205                            'z-index:-1; filter:Alpha(Opacity=\'0\');', 
     206                            'width:3000px;', 
     207                            'height:3000px"/>'].join(''); 
     208            jCalDiv.append(document.createElement(iframe)); 
     209        } 
     210         
     211        jCalDiv.css({'display':'block'}); 
     212        return jCalDiv[0]; 
     213    }; 
     214    var _draw = function(c) 
     215    { 
     216        // explicitly empty the calendar before removing it to reduce the (MASSIVE!) memory leak in IE 
     217        // still not perfect but a lot better! 
     218        // Strangely if you chain the methods it reacts differently - when chained opening the calendar on 
     219        // IE uses a bunch of memory and pressing next/prev doubles this memory. When you close the calendar 
     220        // the memory is freed. If they aren't chained then pressing next or previous doesn't double the used 
     221        // memory so only one chunk of memory is used when you open the calendar (which is also freed when you 
     222        // close the calendar). 
     223        jQuery('div.popup-calendar a', _openCal[0]).unbind(); 
     224        jQuery('div.popup-calendar', _openCal[0]).empty(); 
     225        jQuery('div.popup-calendar', _openCal[0]).remove(); 
     226        _openCal.append(c); 
     227    }; 
     228    var _closeDatePicker = function() 
     229    { 
     230        jQuery('div.popup-calendar a', _openCal).unbind(); 
     231        jQuery('div.popup-calendar', _openCal).empty(); 
     232        jQuery('div.popup-calendar', _openCal).css({'display':'none'}); 
     233 
     234        /* 
     235        if (jQuery.browser.msie) { 
     236            _openCal.unbind('keypress', _handleKeys); 
     237        } else { 
     238            jQuery(window).unbind('keypress', _handleKeys); 
     239        } 
     240        */ 
     241        jQuery(document).unbind('mousedown', _checkMouse); 
     242        delete _openCal; 
     243        _openCal = null; 
     244    }; 
     245    var _handleKeys = function(e) 
     246    { 
     247        var key = e.keyCode ? e.keyCode : (e.which ? e.which: 0); 
     248        //console.log('KEY!! ' + key); 
     249        if (key == 27) { 
     250            _closeDatePicker(); 
     251        } 
     252        return false; 
     253    }; 
     254    var _checkMouse = function(e) 
     255    { 
     256        if (!_drawingMonth) { 
     257            var target = jQuery.browser.msie ? window.event.srcElement : e.target; 
     258            //console.log(jQuery(target)); 
     259            var cp = jQuery(target).findClosestParent('div.popup-calendar-wrapper'); 
     260            if (cp.get(0).className != 'date-picker-holder') { 
     261                _closeDatePicker(); 
     262            } 
     263        } 
     264    }; 
     265 
     266    return { 
     267        getChooseDateStr: function() 
     268        { 
     269            return navLinks.b; 
     270        }, 
     271        show: function() 
     272        { 
     273            if (_openCal) { 
     274                _closeDatePicker(); 
     275            } 
     276            this.blur(); 
     277            var input = jQuery('input', jQuery(this).findClosestParent('input')[0])[0]; 
     278             
     279            _firstDate = input._startDate; 
     280            _lastDate = input._endDate; 
     281            _firstDayOfWeek = input._firstDayOfWeek; 
     282            _openCal = jQuery(this).parent().find('>div.popup-calendar-wrapper'); 
     283             
     284            var d = jQuery(input).val(); 
     285            if (d != '') { 
     286                if (_dateToStr(_strToDate(d)) == d) { 
     287                    _selectedDate = d; 
     288                    _draw(_getCalendarDiv(_strToDate(d))); 
     289                } else { 
     290                    // invalid date in the input field - just default to this month 
     291                    _selectedDate = false; 
     292                    _draw(_getCalendarDiv()); 
     293                } 
     294            } else { 
     295                _selectedDate = false; 
     296                _draw(_getCalendarDiv()); 
     297            } 
     298            /* 
     299            if (jQuery.browser == "msie") { 
     300                _openCal.bind('keypress', _handleKeys); 
     301            } else { 
     302                jQuery(window).bind('keypress', _handleKeys); 
     303            } 
     304            */ 
     305            jQuery(document).bind('mousedown', _checkMouse); 
     306        }, 
     307        changeMonth: function(d, e) 
     308        { 
     309            _drawingMonth = true; 
     310            _draw(_getCalendarDiv(d)); 
     311            _drawingMonth = false; 
     312        }, 
     313        selectDate: function(d, ele) 
     314        { 
     315            selectedDate = d; 
     316            var $theInput = jQuery('input', jQuery(ele).findClosestParent('input')[0]); 
     317            $theInput.val(d); 
     318            $theInput.trigger('change'); 
     319            _closeDatePicker(ele); 
     320        }, 
     321        closeCalendar: function() 
     322        { 
     323            _closeDatePicker(this); 
     324        }, 
     325        setInited: function(i) 
     326        { 
     327            i._inited = true; 
     328        }, 
     329        isInited: function(i) 
     330        { 
     331            return i._inited != undefined; 
     332        }, 
     333        setDateFormat: function(format,separator) 
     334        { 
     335            // set's the format that selected dates are returned in. 
     336            // options are 'dmy' (european), 'mdy' (americian) and 'ymd' (unicode) 
     337            dateFormat = format.toLowerCase(); 
     338            dateSeparator = separator?separator:"/"; 
     339        }, 
     340        /** 
     341        * Function: setLanguageStrings 
     342        * 
     343        * Allows you to localise the calendar by passing in relevant text for the english strings in the plugin. 
     344        * 
     345        * Arguments: 
     346        * days      -   Array, e.g. ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] 
     347        * months    -   Array, e.g. ['January', 'Febuary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; 
     348        * navLinks  -   Object, e.g. {p:'Prev', n:'Next', c:'Close', b:'Choose date'} 
     349        **/ 
     350        setLanguageStrings: function(aDays, aMonths, aNavLinks) 
     351        { 
     352            days = aDays; 
     353            months = aMonths; 
     354            navLinks = aNavLinks; 
     355        }, 
     356        /** 
     357        * Function: setDateWindow 
     358        * 
     359        * Used internally to set the start and end dates for a given date select 
     360        * 
     361        * Arguments: 
     362        * i         -   The id of the INPUT element this date window is for 
     363        * w         -   The date window - an object containing startDate and endDate properties 
     364        *               each in the current format as set in a call to setDateFormat (or in the 
     365        *               default format dmy if setDateFormat hasn't been called). 
     366        *               e.g. {startDate:'01/03/2006', endDate:'11/04/2006} 
     367        **/ 
     368        setDateWindow: function(i, w) 
     369        { 
     370            if (w == undefined) w = {}; 
     371            if (w.startDate == undefined) { 
     372                i._startDate = new Date(); 
     373            } else { 
     374                i._startDate = _strToDate(w.startDate); 
     375            } 
     376            if (w.endDate == undefined) { 
     377                i._endDate = new Date(); 
     378                i._endDate.setFullYear(i._endDate.getFullYear()+5); 
     379            } else { 
     380                i._endDate = _strToDate(w.endDate); 
     381            }; 
     382            i._firstDayOfWeek = w.firstDayOfWeek == undefined ? 0 : w.firstDayOfWeek; 
     383        } 
     384    }; 
     385}(); 
     386jQuery.fn.findClosestParent = function(s) 
     387{ 
     388    var ele = this; 
     389    while (true) { 
     390        if (jQuery(s, ele[0]).length > 0) { 
     391            return (ele); 
     392        } 
     393        ele = ele.parent(); 
     394        if(ele[0].length == 0) { 
     395            return false; 
     396        } 
     397    } 
     398}; 
     399jQuery.fn.datePicker = function(a) 
     400{ 
     401    this.each(function() { 
     402        if(this.nodeName.toLowerCase() != 'input') return; 
     403        jQuery.datePicker.setDateWindow(this, a); 
     404        if (!jQuery.datePicker.isInited(this)) { 
     405            var chooseDate = jQuery.datePicker.getChooseDateStr(); 
     406            var calBut; 
     407            if(a && a.inputClick){ 
     408                calBut = jQuery(this).attr('title', chooseDate).addClass('date-picker'); 
     409            } 
     410            else { 
     411                calBut = jQuery("<a></a>").attr({'href':'javascript:;', 
     412'class':'date-picker', 'title':chooseDate}) 
     413                .append("<span>" + chooseDate + "</span>"); 
     414            } 
     415            jQuery(this).wrap( 
     416                '<div class="date-picker-holder"></div>' 
     417            ).after( 
     418                jQuery('<div></div>').attr('class', 'popup-calendar-wrapper').append( 
     419                    jQuery("<div></div>").attr({'class':'popup-calendar'}) 
     420                ), 
     421                calBut 
     422            ); 
     423            calBut.bind('click', jQuery.datePicker.show); 
     424            jQuery.datePicker.setInited(this); 
     425        } 
     426    }); 
     427    return this; 
     428}; 
  • sermon-browser/branches/0.10-0.23/datepicker.css

    r57035 r57037  
    1 select, input { 
     1#date select, #date input, #enddate select, #enddate input { 
    22    width: 200px; 
    33} 
    4 input.gray { 
     4#date input.gray, #enddate input.gray { 
    55    color: gray; 
    66} 
  • sermon-browser/branches/0.10-0.23/dictionary.php

    r57035 r57037  
    44    '[filters_form]' => '<?php bb_print_filters() ?>', 
    55    '[sermons_count]' => '<?php bb_print_sermons_count() ?>', 
    6     '[sermons_loop]' => '<?php foreach ($sermons as $sermon): ?>', 
     6    '[sermons_loop]' => '<?php foreach ($sermons as $sermon): ?><?php $stuff = bb_get_stuff($sermon) ?>', 
    77    '[/sermons_loop]' => '<?php endforeach ?>', 
    88    '[sermon_title]' => '<a href="<?php bb_print_sermon_link($sermon) ?>"><?php echo stripslashes($sermon->title) ?></a>', 
     
    1111    '[service_link]' => '<a href="<?php bb_print_service_link($sermon) ?>"><?php echo stripslashes($sermon->service) ?></a>',    
    1212    '[date]' => '<?php echo date("j F Y", strtotime($sermon->date)) ?>', 
    13     '[first_bible_passage]' => '<?php $foo = unserialize($sermon->start); $bar = unserialize($sermon->end); echo $foo[0]["book"] ?>, <?php echo $foo[0]["chapter"] ?> : <?php echo $foo[0]["verse"] ?> - <?php echo $bar[0]["book"] ?>, <?php echo $bar[0]["chapter"] ?> : <?php echo $bar[0]["verse"] ?>', 
    14     '[files_loop]' => '<?php $files = bb_get_files($sermon) ?><?php foreach ($files as $file): ?>', 
     13    '[first_passage]' => '<?php $foo = unserialize($sermon->start); $bar = unserialize($sermon->end); echo bb_get_books($foo[0], $bar[0]) ?>', 
     14    '[files_loop]' => '<?php foreach ((array) $stuff["Files"] as $file): ?>', 
    1515    '[/files_loop]' => '<?php endforeach ?>', 
    16     '[file]' => '<?php bb_print_file($file->name) ?>', 
     16    '[file]' => '<?php bb_print_file($file) ?>', 
     17    '[urls_loop]' => '<?php foreach ((array) $stuff["URLs"] as $url): ?>', 
     18    '[/urls_loop]' => '<?php endforeach ?>', 
     19    '[url]' => '<?php bb_print_url($url) ?>', 
     20    '[embed_loop]' => '<?php foreach ((array) $stuff["Code"] as $code): ?>', 
     21    '[/embed_loop]' => '<?php endforeach ?>', 
     22    '[embed]' => '<?php bb_print_code($code) ?>', 
    1723    '[next_page]' => '<?php bb_print_next_page_link() ?>', 
    1824    '[previous_page]' => '<?php bb_print_prev_page_link() ?>',   
     25    '[podcast_for_search]' => '<?php bb_print_podcast_url() ?>', 
     26    '[podcast]' => '<?php echo get_option("sb_podcast") ?>', 
     27    '[podcasticon]' => '<img alt="Subscribe to full podcast" title="Subscribe to full podcast" class="podcasticon" src="<?php echo get_bloginfo("wpurl") ?>/wp-content/plugins/sermonbrowser/icons/podcast.png"/>', 
     28    '[podcasticon_for_search]' => '<img alt="Subscribe to custom podcast" title="Subscribe to custom podcast" class="podcasticon" src="<?php echo get_bloginfo("wpurl") ?>/wp-content/plugins/sermonbrowser/icons/podcast_custom.png"/>', 
     29    '[creditlink]' => '<div id="poweredbysermonbrowser">Powered by <a href="http://www.4-14.org.uk/sermon-browser">Sermon Browser</a></div>', 
    1930); 
    2031 
     
    2233    '[sermon_title]' => '<?php echo stripslashes($sermon["Sermon"]->title) ?>', 
    2334    '[preacher_link]' => '<a href="<?php bb_print_preacher_link($sermon["Sermon"]) ?>"><?php echo stripslashes($sermon["Sermon"]->preacher) ?></a>', 
     35    '[preacher_description]' => '<?php echo stripslashes($sermon["Sermon"]->preacher_description) ?>', 
     36    '[preacher_image]' => '<img src=\'<?php echo get_bloginfo("wpurl") ?>/wp-content/plugins/sermonbrowser/preachers/<?php echo $sermon["Sermon"]->image ?>\'', 
    2437    '[series_link]' => '<a href="<?php bb_print_series_link($sermon["Sermon"]) ?>"><?php echo stripslashes($sermon["Sermon"]->series) ?></a>', 
    2538    '[service_link]' => '<a href="<?php bb_print_service_link($sermon["Sermon"]) ?>"><?php echo stripslashes($sermon["Sermon"]->service) ?></a>', 
     
    2740    '[passages_loop]' => '<?php for ($i = 0; $i < count($sermon["Sermon"]->start); $i++): ?>', 
    2841    '[/passages_loop]' => '<?php endfor ?>', 
    29     '[start_passage]' => '<?php echo $sermon["Sermon"]->start[$i]["book"] ?>, <?php echo $sermon["Sermon"]->start[$i]["chapter"] ?> : <?php echo $sermon["Sermon"]->start[$i]["verse"] ?>', 
    30     '[end_passage]' => '<?php echo $sermon["Sermon"]->end[$i]["book"] ?>, <?php echo $sermon["Sermon"]->end[$i]["chapter"] ?> : <?php echo $sermon["Sermon"]->end[$i]["verse"] ?>', 
    31     '[files_loop]' => '<?php foreach ($sermon["Files"] as $file): ?>', 
     42    '[passage]' => '<?php echo bb_get_books($sermon["Sermon"]->start[$i], $sermon["Sermon"]->end[$i]) ?>', 
     43    '[files_loop]' => '<?php foreach ((array) $sermon["Files"] as $file): ?>', 
    3244    '[/files_loop]' => '<?php endforeach ?>', 
    33     '[file]' => '<?php bb_print_file($file->name) ?>', 
     45    '[file]' => '<?php bb_print_file($file) ?>', 
     46    '[urls_loop]' => '<?php foreach ((array) $sermon["URLs"] as $url): ?>', 
     47    '[/urls_loop]' => '<?php endforeach ?>', 
     48    '[url]' => '<?php bb_print_url($url) ?>', 
     49    '[embed_loop]' => '<?php foreach ((array) $sermon["Code"] as $code): ?>', 
     50    '[/embed_loop]' => '<?php endforeach ?>', 
     51    '[embed]' => '<?php bb_print_code($code) ?>', 
    3452    '[next_sermon]' => '<?php bb_print_next_sermon_link($sermon["Sermon"]) ?>', 
    3553    '[prev_sermon]' => '<?php bb_print_prev_sermon_link($sermon["Sermon"]) ?>', 
    3654    '[sameday_sermon]' => '<?php bb_print_sameday_sermon_link($sermon["Sermon"]) ?>', 
     55    '[tags]' => '<?php bb_print_tags($sermon["Tags"]) ?>', 
     56    '[esvtext]' => '<?php for ($i = 0; $i < count($sermon["Sermon"]->start); $i++): echo add_esv_text ($sermon["Sermon"]->start[$i], $sermon["Sermon"]->end[$i]); endfor ?>', 
     57    '[biblepassage]' => '<?php for ($i = 0; $i < count($sermon["Sermon"]->start); $i++): print_bible_passage ($sermon["Sermon"]->start[$i], $sermon["Sermon"]->end[$i]); endfor ?>', 
     58    '[creditlink]' => '<div id="poweredbysermonbrowser">Powered by <a href="http://www.4-14.org.uk/sermon-browser">Sermon Browser</a></div>', 
    3759); 
    3860 
     61 
    3962?> 
  • sermon-browser/branches/0.10-0.23/filetypes.php

    r57035 r57037  
    1010$filetypes = array( 
    1111    'mp3' => array( 
    12         'name' => 'MP3', 
    13         'icon' => 'mp3.png', 
     12        'name' => 'mp3', 
     13        'icon' => 'audio.png', 
    1414    ),       
    1515    'doc' => array( 
     
    2121        'icon' => 'doc.png', 
    2222    ),       
     23    'rtf' => array( 
     24        'name' => 'Rich Text Format', 
     25        'icon' => 'doc.png', 
     26    ),       
    2327    'ppt' => array( 
     28        'name' => 'Powerpoint', 
     29        'icon' => 'ppt.png', 
     30    ),       
     31    'pptx' => array( 
    2432        'name' => 'Powerpoint', 
    2533        'icon' => 'ppt.png', 
     
    2937        'icon' => 'pdf.png', 
    3038    ),       
     39    'iso' => array( 
     40        'name' => 'Disk image', 
     41        'icon' => 'iso.png', 
     42    ),       
     43    'wma' => array( 
     44        'name' => 'Windows Media Audio', 
     45        'icon' => 'audio.png', 
     46    ),       
     47    'txt' => array( 
     48        'name' => 'Text', 
     49        'icon' => 'txt.png', 
     50    ),       
     51    'wma' => array( 
     52        'name' => 'Windows Media Audio', 
     53        'icon' => 'audio.png', 
     54    ),       
     55    'wmv' => array( 
     56        'name' => 'Windows Media Video', 
     57        'icon' => 'video.png', 
     58    ),       
     59    'mov' => array( 
     60        'name' => 'Quicktime Video', 
     61        'icon' => 'video.png', 
     62    ),       
     63    'divx' => array( 
     64        'name' => 'DivX Video', 
     65        'icon' => 'video.png', 
     66    ),       
     67    'avi' => array( 
     68        'name' => 'Video', 
     69        'icon' => 'video.png', 
     70    ),       
     71    'xls' => array( 
     72        'name' => 'Microsoft Excel', 
     73        'icon' => 'xls.png', 
     74    ),       
     75    'xlsx' => array( 
     76        'name' => 'Microsoft Excel', 
     77        'icon' => 'xls.png', 
     78    ),       
     79    'zip' => array( 
     80        'name' => 'Zip file', 
     81        'icon' => 'zip.png', 
     82    ),       
     83    'gz' => array( 
     84        'name' => 'Gzip file', 
     85        'icon' => 'zip.png', 
     86    ),       
    3187); 
    3288 
    33 $default_icon = 'file.png'; 
     89$siteicons = array( 
     90    'http://google.com' => 'url.png', 
     91); 
     92 
     93$default_file_icon = 'unknown.png'; 
     94 
     95$default_site_icon = 'url.png'; 
    3496 
    3597?> 
  • sermon-browser/branches/0.10-0.23/frontend.php

    r57035 r57037  
    11<?php  
    22 
     3// we need the translator first 
    34require_once('dictionary.php'); 
    4 $sef = "/sermons"; 
    5 $wl = array('preacher', 'title', 'date', 'enddate', 'series', 'service', 'sortby', 'dir', 'page', 'sermon_id'); 
    6  
     5 
     6require_once('widget.php'); 
     7 
     8// word list for URL building purpose 
     9$wl = array('preacher', 'title', 'date', 'enddate', 'series', 'service', 'sortby', 'dir', 'page', 'sermon_id', 'book', 'stag', 'podcast'); 
     10 
     11// hooks & filters 
     12add_action('template_redirect', 'bb_hijack'); 
    713add_action('wp_head', 'bb_print_header'); 
    814add_filter('the_content', 'bb_sermons_filter'); 
    9  
     15add_action('widgets_init', 'widget_sermon_init'); 
     16 
     17//Add ESV text 
     18function add_esv_text ($start, $end) { 
     19    $r1 = $start['book']; 
     20    $r2 = $start['chapter']; 
     21    $r3 = $start['verse']; 
     22    $r4 = $end['book']; 
     23    $r5 = $end['chapter']; 
     24    $r6 = $end['verse']; 
     25    if (empty($start['book'])) { 
     26        return ''; 
     27    } 
     28    if ($start['book'] == $end['book']) { 
     29        if ($start['chapter'] == $end['chapter']) { 
     30            $reference = "$r1 $r2:$r3-$r6"; 
     31        } 
     32        else $reference = "$r1 $r2:$r3-$r5:$r6"; 
     33    }    
     34    else $reference =  "$r1 $r2:$r3 - $r4 $r5:$r6"; 
     35    // If you are experiencing errors, you should sign up for an ESV API key, and insert the name of your key in place of the letters IP in the URL below (.e.g. ...passageQuery?key=YOURAPIKEY&passage=...) 
     36    $handle = @fopen ('http://www.esvapi.org/v2/rest/passageQuery?key=IP&passage='.urlencode($reference).'&include-headings=false&include-footnotes=false', 'r'); 
     37    if ($handle) { 
     38        stream_set_blocking($handle, TRUE ); 
     39        stream_set_timeout($handle, 2); 
     40        $info = socket_get_status($handle); 
     41        while (!feof($handle) && !$info['timed_out']) { 
     42            $contents .= fread($handle, 8192); 
     43            $info = socket_get_status($handle); 
     44        } 
     45    fclose($handle); 
     46    } 
     47    return $contents; 
     48} 
     49 
     50//Print unstyled bible passage 
     51function print_bible_passage ($start, $end) { 
     52    $r1 = $start['book']; 
     53    $r2 = $start['chapter']; 
     54    $r3 = $start['verse']; 
     55    $r4 = $end['book']; 
     56    $r5 = $end['chapter']; 
     57    $r6 = $end['verse']; 
     58    if (empty($start['book'])) { 
     59        return ''; 
     60    } 
     61    if ($start['book'] == $end['book']) { 
     62        if ($start['chapter'] == $end['chapter']) { 
     63            $reference = "$r1 $r2:$r3-$r6"; 
     64        } 
     65        else $reference = "$r1 $r2:$r3-$r5:$r6"; 
     66    }    
     67    else $reference =  "$r1 $r2:$r3 - $r4 $r5:$r6"; 
     68    echo "<p class='bible-passage'>".$reference."</p>"; 
     69} 
     70 
     71// podcast 
     72function bb_hijack() { 
     73    global $wordpressRealPath; 
     74    if (isset($_REQUEST['podcast'])) { 
     75        $sermons = bb_get_sermons(array( 
     76            'title' => $_REQUEST['title'], 
     77            'preacher' => $_REQUEST['preacher'], 
     78            'date' => $_REQUEST['date'], 
     79            'enddate' => $_REQUEST['enddate'], 
     80            'series' => $_REQUEST['series'], 
     81            'service' => $_REQUEST['service'], 
     82            'book' => $_REQUEST['book'], 
     83            'tag' => $_REQUEST['stag'], 
     84        ), 
     85        array( 
     86            'by' => $_REQUEST['sortby'] ? $_REQUEST['sortby'] : 'm.date', 
     87            'dir' => $_REQUEST['dir'], 
     88        ), 
     89        $_REQUEST['page'] ? $_REQUEST['page'] : 1,  
     90        1000000          
     91        ); 
     92        header('Content-Type: application/rss+xml'); 
     93        echo '<?xml version="1.0" encoding="UTF-8"?>'; 
     94        include($wordpressRealPath.'/wp-content/plugins/sermonbrowser/podcast.php'); 
     95        die(); 
     96    } 
     97} 
     98 
     99// main entry 
    10100function bb_sermons_filter($content) { 
    11101    global $wpdb, $clr; 
    12102    global $wordpressRealPath; 
    13      
     103    if (!strstr($content, '[sermons]')) return $content; 
    14104    ob_start(); 
    15105     
     
    27117            'series' => $_REQUEST['series'], 
    28118            'service' => $_REQUEST['service'], 
     119            'book' => $_REQUEST['book'], 
     120            'tag' => $_REQUEST['stag'], 
    29121        ), 
    30122        array( 
     
    34126        $_REQUEST['page'] ? $_REQUEST['page'] : 1            
    35127        ); 
    36         include($wordpressRealPath.'/wp-content/plugins/sermonbrowser/multi.php'); 
     128        include($wordpressRealPath.'/wp-content/plugins/sermonbrowser/multi.php');       
    37129    }            
    38130    $content = str_replace('[sermons]', ob_get_contents(), $content); 
     
    44136 
    45137function bb_build_url($arr, $clear = false) { 
    46     global $wl, $sef; 
     138    global $wl, $post; 
     139    $id = ($post->ID) ? $post->ID : $post; 
     140    $sef = substr(get_permalink($id),0,-1); 
    47141    $foo = array_merge((array) $_GET, (array) $_POST, $arr); 
    48142    foreach ($foo as $k => $v) { 
     
    50144            $bar[] = "$k=$v"; 
    51145        } 
    52     }    
    53     if ($sef != "") return get_bloginfo('url') . $sef.'/?' . implode('&', $bar); 
     146    } 
     147    if ($sef != "") return $sef.'?' . implode('&', $bar); 
    54148    return get_bloginfo('url') . '?' . implode('&', $bar); 
    55      
    56149} 
    57150 
    58151function bb_print_header() { 
     152    global $sermon_domain; 
    59153    $url = get_bloginfo('wpurl'); 
    60154?> 
    61     <link rel="stylesheet" href="<?php echo $url ?>/wp-content/plugins/sermonbrowser/datepicker.css" type="text/css"> 
    62     <link rel="stylesheet" href="<?php echo $url ?>/wp-content/plugins/sermonbrowser/style.css" type="text/css"> 
     155    <link rel="alternate" type="application/rss+xml" title="<?php _e('Sermon podcast', $sermon_domain) ?>" href="<?php echo get_option('sb_podcast') ?>" /> 
     156    <link rel="stylesheet" href="<?php echo $url ?>/wp-content/plugins/sermonbrowser/datepicker.css" type="text/css"/> 
     157    <link rel="stylesheet" href="<?php echo $url ?>/wp-content/plugins/sermonbrowser/style.css" type="text/css"/> 
    63158    <script type="text/javascript" src="<?php echo $url ?>/wp-includes/js/jquery/jquery.js"></script> 
    64159    <script type="text/javascript" src="<?php echo $url ?>/wp-content/plugins/sermonbrowser/datePicker.js"></script> 
     
    66161} 
    67162 
     163// pretty books 
     164function bb_get_books($start, $end) { 
     165    $r1 = '<a href="'.bb_get_book_link($start['book']).'">'.$start['book'].'</a>'; 
     166    $r2 = $start['chapter']; 
     167    $r3 = $start['verse']; 
     168     
     169    $r4 = '<a href="'.bb_get_book_link($end['book']).'">'.$end['book'].'</a>'; 
     170    $r5 = $end['chapter']; 
     171    $r6 = $end['verse']; 
     172     
     173    if (empty($start['book'])) { 
     174        return ''; 
     175    } 
     176     
     177    if ($start['book'] == $end['book']) { 
     178        if ($start['chapter'] == $end['chapter']) { 
     179            if($start['verse'] == $end['verse']){ 
     180                return "$r1 $r2:$r3"; 
     181            } 
     182            return "$r1 $r2:$r3-$r6"; 
     183        } 
     184        return "$r1 $r2:$r3-$r5:$r6"; 
     185    }    
     186    return "$r1 $r2:$r3 - $r4 $r5:$r6"; 
     187} 
     188 
     189function bb_print_podcast_url() { 
     190    echo str_replace(' ', '%20', bb_build_url(array('podcast' => 1))); 
     191} 
     192 
     193function bb_print_first_mp3($sermon) { 
     194    $stuff = bb_get_stuff($sermon); 
     195    foreach ((array) $stuff['Files'] as $file) { 
     196        $ext = substr($file, strrpos($file, '.') + 1); 
     197        if (strtolower($ext) == 'mp3') { 
     198            echo str_replace(' ', '%20', get_option('sb_sermon_upload_url').$file); 
     199            break; 
     200        } 
     201    } 
     202} 
     203 
    68204function bb_print_sermon_link($sermon) { 
    69205    echo bb_build_url(array('sermon_id' => $sermon->id), true); 
     
    83219    global $clr; 
    84220    echo bb_build_url(array('service' => $sermon->sid), $clr); 
     221} 
     222 
     223function bb_get_book_link($book_name) { 
     224    global $clr; 
     225    return bb_build_url(array('book' => $book_name), $clr); 
     226} 
     227 
     228function bb_get_tag_link($tag) { 
     229    global $clr; 
     230    return bb_build_url(array('stag' => $tag), $clr); 
     231} 
     232 
     233function bb_print_tags($tags) { 
     234    foreach ((array) $tags as $tag) { 
     235        $out[] = '<a href="'.bb_get_tag_link($tag).'">'.$tag.'</a>'; 
     236    } 
     237    $tags = implode(', ', (array) $out); 
     238    echo $tags; 
     239} 
     240 
     241function bb_print_tag_clouds() { 
     242    global $wpdb; 
     243    $rawtags = $wpdb->get_results("SELECT name FROM {$wpdb->prefix}sb_tags as t RIGHT JOIN {$wpdb->prefix}sb_sermons_tags as st ON t.id = st.tag_id"); 
     244    foreach ($rawtags as $tag) { 
     245        $cnt[$tag->name]++; 
     246    } 
     247     
     248    $minfont = 10; 
     249    $maxfont = 26; 
     250    $fontrange = $maxfont - $minfont; 
     251    $maxcnt = 0; 
     252    $mincnt = 1000000; 
     253    foreach ($cnt as $cur) { 
     254        if ($cur > $maxcnt) $maxcnt = $cur; 
     255        if ($cur < $mincnt) $minct = $cur;  
     256    } 
     257    $cntrange = $maxcnt + 1 - $mincnt; 
     258     
     259    $minlog = log($mincnt); 
     260    $maxlog = log($maxcnt); 
     261    $logrange = $maxlog == $minlog ? 1 : $maxlog - $minlog; 
     262    arsort($cnt); 
     263     
     264    foreach ($cnt as $tag => $count) { 
     265        $size = $minfont + $fontrange * (log($count) - $minlog) / $logrange; 
     266        $out[] = '<a style="font-size:'.(int) $size.'px" href="'.bb_get_tag_link($tag).'">'.$tag.'</a>'; 
     267    } 
     268    echo implode(' ', $out); 
    85269} 
    86270 
     
    104288 
    105289function bb_print_file($name) { 
    106     global $filetypes, $default_icon; 
     290    //global $filetypes, $default_file_icon; 
     291    //$icon_url = get_bloginfo('wpurl').'/wp-content/plugins/sermonbrowser/icons/'; 
     292    $file_url = get_option('sb_sermon_upload_url').$name; 
     293    /*$ext = substr($name, strrpos($name, '.') + 1); 
     294    if (strtolower($ext) == 'mp3' && function_exists('ap_insert_player_widgets')) { 
     295        echo '<div class="audioplayer">'.ap_insert_player_widgets('[audio:'.$file_url.$name.']').'</div>'; 
     296    } elseif (isset($filetypes[$ext]['icon'])) { 
     297        echo '<a href="'.$file_url.$name.'"><img class="sermon-icon" alt="'.$name.'" title="'.$name.'" src="'.$icon_url.$filetypes[$ext]['icon'].'"></a>'; 
     298    } else { 
     299        echo '<a href="'.$file_url.$name.'"><img class="sermon-icon" alt="'.$name.'" title="'.$name.'" src="'.$icon_url.$default_file_icon.'"></a>'; 
     300    }*/ 
     301    bb_print_url($file_url); 
     302} 
     303 
     304function bb_print_iso_date($sermon) { 
     305    echo date('d M Y H:i:s O', strtotime($sermon->date.' '.$sermon->time)); 
     306} 
     307 
     308function bb_print_url($url) { 
     309    global $siteicons, $default_site_icon ,$filetypes; 
    107310    $icon_url = get_bloginfo('wpurl').'/wp-content/plugins/sermonbrowser/icons/'; 
    108     $file_url = get_option('sb_sermon_upload_url'); 
    109     $ext = substr($name, strrpos($name, '.') + 1); 
     311    $uicon = $default_site_icon; 
     312    foreach ($siteicons as $site => $icon) { 
     313        if (strpos($url, $site) !== false) { 
     314            $uicon = $icon; 
     315            break; 
     316        } 
     317    } 
     318    $pathinfo = pathinfo($url); 
     319    $ext = $pathinfo['extension']; 
     320    $uicon = isset($filetypes[$ext]['icon']) ? $filetypes[$ext]['icon'] : $uicon; 
    110321    if (strtolower($ext) == 'mp3' && function_exists('ap_insert_player_widgets')) { 
    111         echo ap_insert_player_widgets('[audio:'.$file_url.$name.']'); 
    112     } elseif (isset($filetypes[$ext]['icon'])) { 
    113         echo '<a href="'.$file_url.$name.'"><img class="sermon-icon" alt="'.$name.'" src="'.$icon_url.$filetypes[$ext]['icon'].'"></a>'; 
     322        echo '<div class="audioplayer">'.ap_insert_player_widgets('[audio:'.$url.']').'</div>'; 
    114323    } else { 
    115         echo '<a href="'.$file_url.$name.'"><img class="sermon-icon" alt="'.$name.'" src="'.$icon_url.$default_icon.'"> '.$name.'</a>'; 
    116     }    
     324        echo '<a href="'.$url.'"><img class="site-icon" alt="'.$url.'" title="'.$url.'" src="'.$icon_url.$uicon.'"></a>'; 
     325    } 
     326     
     327} 
     328 
     329function bb_print_code($code) { 
     330    echo base64_decode($code); 
    117331} 
    118332 
     
    123337    echo '<a href="'; 
    124338    bb_print_sermon_link($next); 
    125     echo '">'.$next->title.' &raquo;</a>'; 
     339    echo '">'.stripslashes($next->title).' &raquo;</a>'; 
    126340} 
    127341 
     
    132346    echo '<a href="'; 
    133347    bb_print_sermon_link($prev); 
    134     echo '">&laquo; '.$prev->title.'</a>'; 
     348    echo '">&laquo; '.stripslashes($prev->title).'</a>'; 
    135349} 
    136350 
     
    145359        echo '<a href="'; 
    146360        bb_print_sermon_link($cur); 
    147         echo '">'.$cur->title.'</a>'; 
     361        echo '">'.stripslashes($cur->title).'</a>'; 
    148362    } 
    149363} 
     
    153367    $id = (int) $id; 
    154368    $sermon = $wpdb->get_row("SELECT m.id, m.title, m.date, m.start, m.end, p.id as pid, p.name as preacher, s.id as sid, s.name as service, ss.id as ssid, ss.name as series FROM {$wpdb->prefix}sb_sermons as m, {$wpdb->prefix}sb_preachers as p, {$wpdb->prefix}sb_services as s, {$wpdb->prefix}sb_series as ss where m.preacher_id = p.id and m.service_id = s.id and m.series_id = ss.id and m.id = $id"); 
    155     $files = $wpdb->get_results("SELECT f.name FROM {$wpdb->prefix}sb_sermon_files as f WHERE sermon_id = $id ORDER BY id desc"); 
     369    $stuff = $wpdb->get_results("SELECT f.type, f.name FROM {$wpdb->prefix}sb_stuff as f WHERE sermon_id = $id ORDER BY id desc");   
     370    $rawtags = $wpdb->get_results("SELECT t.name FROM {$wpdb->prefix}sb_sermons_tags as st LEFT JOIN {$wpdb->prefix}sb_tags as t ON st.tag_id = t.id WHERE st.sermon_id = $sermon->id ORDER BY t.name asc"); 
     371    foreach ($rawtags as $tag) { 
     372        $tags[] = $tag->name; 
     373    } 
     374    foreach ($stuff as $cur) { 
     375        ${$cur->type}[] = $cur->name; 
     376    } 
    156377    $sermon->start = unserialize($sermon->start); 
    157378    $sermon->end = unserialize($sermon->end); 
    158379    return array(        
    159380        'Sermon' => $sermon, 
    160         'Files' => $files, 
     381        'Files' => $file, 
     382        'URLs' => $url, 
     383        'Code' => $code, 
     384        'Tags' => $tags, 
    161385    ); 
    162386} 
     
    170394        'series' => $_REQUEST['series'], 
    171395        'service' => $_REQUEST['service'], 
     396        'book' => $_REQUEST['book'], 
     397        'tag' => $_REQUEST['stag'], 
    172398    )); 
    173399} 
     
    180406        'enddate' => $_REQUEST['enddate'], 
    181407        'series' => $_REQUEST['series'], 
    182         'service' => $_REQUEST['service'],       
     408        'service' => $_REQUEST['service'],   
     409        'book' => $_REQUEST['book'],         
     410        'tag' => $_REQUEST['stag'],      
    183411    )); 
    184412    return ceil($total / $limit); 
     
    194422        'series' => 0, 
    195423        'service' => 0, 
     424        'book' => '', 
     425        'tag' => '', 
    196426    );   
    197427    $filter = array_merge($default_filter, $filter);     
     
    214444        $cond .= 'AND m.service_id = ' . (int) $filter['service'] . ' '; 
    215445    }        
    216     $query = "SELECT COUNT(*) FROM {$wpdb->prefix}sb_sermons as m, {$wpdb->prefix}sb_preachers as p, {$wpdb->prefix}sb_services as s, {$wpdb->prefix}sb_series as ss where m.preacher_id = p.id and m.service_id = s.id and m.series_id = ss.id $cond";  
    217     return $wpdb->get_var($query); 
    218 } 
    219  
    220 function bb_get_sermons($filter, $order, $page = 1, $limit = 15) { 
     446    if ($filter['book'] != '') { 
     447        $cond .= 'AND bs.book_name = "' . mysql_real_escape_string($filter['book']) . '" '; 
     448    } else { 
     449        $bs = "AND bs.order = 0 AND bs.type= 'start' "; 
     450    } 
     451    if ($filter['tag'] != '') { 
     452        $cond .= 'AND t.name LIKE "%' . mysql_real_escape_string($filter['tag']) . '%" '; 
     453    } 
     454    $query = "SELECT DISTINCT m.id  
     455        FROM {$wpdb->prefix}sb_sermons as m  
     456        LEFT JOIN {$wpdb->prefix}sb_preachers as p ON m.preacher_id = p.id  
     457        LEFT JOIN  {$wpdb->prefix}sb_services as s ON m.service_id = s.id  
     458        LEFT JOIN {$wpdb->prefix}sb_series as ss ON m.series_id = ss.id  
     459        LEFT JOIN {$wpdb->prefix}sb_books_sermons as bs ON bs.sermon_id = m.id $bs  
     460        LEFT JOIN {$wpdb->prefix}sb_books as b ON bs.book_name = b.name  
     461        LEFT JOIN {$wpdb->prefix}sb_sermons_tags as st ON st.sermon_id = m.id  
     462        LEFT JOIN {$wpdb->prefix}sb_tags as t ON t.id = st.tag_id  
     463        WHERE 1 = 1 $cond"; 
     464    return count($wpdb->get_results($query)); 
     465} 
     466 
     467function bb_get_sermons($filter, $order, $page = 1, $limit = 10) { 
    221468    global $wpdb; 
    222469    $default_filter = array( 
     
    227474        'series' => 0, 
    228475        'service' => 0, 
     476        'book' => '', 
     477        'tag' => '', 
    229478    ); 
    230479    $default_order = array( 
     
    232481        'dir' => 'desc', 
    233482    ); 
     483    $bs = ''; 
    234484    $filter = array_merge($default_filter, $filter); 
    235485    $order = array_merge($default_order, $order); 
     486     
    236487    $page = (int) $page; 
    237488    if ($filter['title'] != '') { 
     
    253504        $cond .= 'AND m.service_id = ' . (int) $filter['service'] . ' '; 
    254505    }    
     506    if ($filter['book'] != '') { 
     507        $cond .= 'AND bs.book_name = "' . mysql_real_escape_string($filter['book']) . '" '; 
     508    } else { 
     509        $bs = "AND bs.order = 0 AND bs.type= 'start' "; 
     510    } 
     511    if ($filter['tag'] != '') { 
     512        $cond .= 'AND t.name LIKE "%' . mysql_real_escape_string($filter['tag']) . '%" '; 
     513    } 
    255514    $offset = $limit * ($page - 1); 
    256     $query = "SELECT m.id, m.title, m.date, m.start, m.end, p.id as pid, p.name as preacher, s.id as sid, s.name as service, ss.id as ssid, ss.name as series  FROM {$wpdb->prefix}sb_sermons as m, {$wpdb->prefix}sb_preachers as p, {$wpdb->prefix}sb_services as s, {$wpdb->prefix}sb_series as ss where m.preacher_id = p.id and m.service_id = s.id and m.series_id = ss.id $cond ORDER BY ". $order['by'] . " " . $order['dir'] . " LIMIT " . $offset . ", " . $limit; 
     515    if ($order['by'] == 'm.date' ) { 
     516        if(!isset($order['dir'])) $order['dir'] = 'desc'; 
     517        $order['by'] = 'm.date '.$order['dir'].', s.time'; 
     518    } 
     519    if ($order['by'] == 'b.id' ) { 
     520        $order['by'] = 'b.id '.$order['dir'].', bs.chapter '.$order['dir'].', bs.verse'; 
     521    } 
     522    $query = "SELECT DISTINCT m.id, m.title, m.description, m.date, m.time, m.start, m.end, p.id as pid, p.name as preacher, p.description as preacher_description, p.image, s.id as sid, s.name as service, ss.id as ssid, ss.name as series  
     523        FROM {$wpdb->prefix}sb_sermons as m  
     524        LEFT JOIN {$wpdb->prefix}sb_preachers as p ON m.preacher_id = p.id  
     525        LEFT JOIN  {$wpdb->prefix}sb_services as s ON m.service_id = s.id  
     526        LEFT JOIN {$wpdb->prefix}sb_series as ss ON m.series_id = ss.id  
     527        LEFT JOIN {$wpdb->prefix}sb_books_sermons as bs ON bs.sermon_id = m.id $bs  
     528        LEFT JOIN {$wpdb->prefix}sb_books as b ON bs.book_name = b.name  
     529        LEFT JOIN {$wpdb->prefix}sb_sermons_tags as st ON st.sermon_id = m.id  
     530        LEFT JOIN {$wpdb->prefix}sb_tags as t ON t.id = st.tag_id  
     531        WHERE 1 = 1 $cond ORDER BY ". $order['by'] . " " . $order['dir'] . " LIMIT " . $offset . ", " . $limit; 
    257532    return $wpdb->get_results($query); 
    258533} 
    259534 
    260 function bb_get_files($sermon) { 
     535function bb_get_stuff($sermon) { 
    261536    global $wpdb; 
    262     return $wpdb->get_results("SELECT f.name FROM {$wpdb->prefix}sb_sermon_files as f WHERE sermon_id = $sermon->id ORDER BY id desc"); 
     537    $stuff = $wpdb->get_results("SELECT f.type, f.name FROM {$wpdb->prefix}sb_stuff as f WHERE sermon_id = $sermon->id ORDER BY id desc"); 
     538    foreach ($stuff as $cur) { 
     539        ${$cur->type}[] = $cur->name; 
     540    } 
     541    return array(        
     542        'Files' => $file, 
     543        'URLs' => $url, 
     544        'Code' => $code, 
     545    ); 
    263546} 
    264547 
    265548function bb_print_filters() { 
    266     global $wpdb, $sermon_domain; 
     549    global $wpdb, $sermon_domain, $books; 
    267550     
    268551    $url = get_bloginfo('wpurl'); 
     
    276559        'Preacher' => 'preacher', 
    277560        'Date' => 'm.date', 
     561        'Passage' => 'b.id', 
    278562    ); 
    279563     
     
    284568     
    285569    $csb = $_REQUEST['sortby'] ? $_REQUEST['sortby'] : 'm.date'; 
    286     $cd = $_REQUEST['dir'] ? $_REQUEST['dir'] : 'asc';   
     570    $cd = $_REQUEST['dir'] ? $_REQUEST['dir'] : 'desc';  
    287571?>   
    288572    <form method="post" id="sermon-filter"> 
    289573        <div style="clear:both"> 
    290         <div class="half"> 
    291                 <div class="title"><?php _e('Keywords', $sermon_domain) ?></div> 
    292                 <input type="text" id="title" name="title" value="<?php echo mysql_real_escape_string($_REQUEST['title']) ?>" /> 
    293         </div> 
    294         <div class="half"> 
    295                 <div class="title"><?php _e('Preacher', $sermon_domain) ?></div> 
    296                 <select name="preacher" id="preacher"> 
    297                     <option value="0" <?php echo $_REQUEST['preacher'] != 0 ? '' : 'selected="selected"' ?>><?php _e('[All]', $sermon_domain) ?></option> 
    298                     <?php foreach ($preachers as $preacher): ?> 
    299                     <option value="<?php echo $preacher->id ?>" <?php echo $_REQUEST['preacher'] == $preacher->id ? 'selected="selected"' : '' ?>><?php echo $preacher->name ?></option> 
    300                     <?php endforeach ?> 
    301                 </select> 
    302         </div> 
    303         </div> 
    304         <div style="clear:both"> 
    305         <div class="half">       
    306                 <div class="title"><?php _e('Series', $sermon_domain) ?></div> 
    307                 <select name="series" id="series"> 
    308                     <option value="0" <?php echo $_REQUEST['series'] != 0 ? '' : 'selected="selected"' ?>><?php _e('[All]', $sermon_domain) ?></option> 
    309                     <?php foreach ($series as $item): ?> 
    310                     <option value="<?php echo $item->id ?>" <?php echo $_REQUEST['series'] == $item->id ? 'selected="selected"' : '' ?>><?php echo $item->name ?></option> 
    311                     <?php endforeach ?> 
    312                 </select> 
    313         </div> 
    314         <div class="half">       
    315                 <div class="title"><?php _e('Services', $sermon_domain) ?></div> 
    316                 <select name="service" id="service"> 
    317                     <option value="0" <?php echo $_REQUEST['service'] != 0 ? '' : 'selected="selected"' ?>><?php _e('[All]', $sermon_domain) ?></option> 
    318                     <?php foreach ($services as $service): ?> 
    319                     <option value="<?php echo $service->id ?>" <?php echo $_REQUEST['service'] == $service->id ? 'selected="selected"' : '' ?>><?php echo $service->name ?></option> 
    320                     <?php endforeach ?> 
    321                 </select>    
    322         </div> 
    323         </div> 
    324         <div style="clear:both"> 
    325         <div class="half"> 
    326                 <div class="title"><?php _e('Start date', $sermon_domain) ?></div> 
    327                 <input type="text" name="date" id="date" value="<?php echo mysql_real_escape_string($_REQUEST['date']) ?>" /> 
    328         </div> 
    329         <div class="half"> 
    330                 <div class="title"><?php _e('End date', $sermon_domain) ?></div> 
    331                 <input type="text" name="date" id="enddate" value="<?php echo mysql_real_escape_string($_REQUEST['enddate']) ?>" /> 
    332         </div> 
    333         </div> 
    334         <div> 
    335         <div class="half"> 
    336                 <div class="title"><?php _e('Sort by', $sermon_domain) ?></div> 
    337                 <select name="sortby" id="sortby"> 
    338                     <?php foreach ($sb as $k => $v): ?> 
    339                     <option value="<?php echo $v ?>" <?php echo $csb == $v ? 'selected="selected"' : '' ?>><?php _e($k, $sermon_domain) ?></option> 
    340                     <?php endforeach ?> 
    341                 </select> 
    342         </div> 
    343         <div class="half"> 
    344                 <div class="title"><?php _e('Sorting direction', $sermon_domain) ?></div> 
    345                 <select name="dir" id="dir"> 
    346                     <?php foreach ($di as $k => $v): ?> 
    347                     <option value="<?php echo $v ?>" <?php echo $cd == $v ? 'selected="selected"' : '' ?>><?php _e($k, $sermon_domain) ?></option> 
    348                     <?php endforeach ?> 
    349                 </select> 
    350         </div> 
    351         </div> 
    352         <div style="clear:both"> 
    353         <div class="half">&nbsp;</div> 
    354         <div class="half"> 
    355             <div class="title">&nbsp;</div> 
    356             <input type="submit" class="filter" value="<?php _e('Filter &raquo;', $sermon_domain) ?>">           
    357         </div> 
    358         <input type="hidden" name="page" value="1"> 
     574            <table class="sermonbrowser"> 
     575                <tr> 
     576                    <td class="fieldname"><?php _e('Preacher', $sermon_domain) ?></td> 
     577                    <td class="field"><select name="preacher" id="preacher"> 
     578                            <option value="0" <?php echo $_REQUEST['preacher'] != 0 ? '' : 'selected="selected"' ?>><?php _e('[All]', $sermon_domain) ?></option> 
     579                            <?php foreach ($preachers as $preacher): ?> 
     580                            <option value="<?php echo $preacher->id ?>" <?php echo $_REQUEST['preacher'] == $preacher->id ? 'selected="selected"' : '' ?>><?php echo $preacher->name ?></option> 
     581                            <?php endforeach ?> 
     582                        </select> 
     583                    </td> 
     584                    <td class="fieldname rightcolumn"><?php _e('Services', $sermon_domain) ?></td> 
     585                    <td class="field"><select name="service" id="service"> 
     586                            <option value="0" <?php echo $_REQUEST['service'] != 0 ? '' : 'selected="selected"' ?>><?php _e('[All]', $sermon_domain) ?></option> 
     587                            <?php foreach ($services as $service): ?> 
     588                            <option value="<?php echo $service->id ?>" <?php echo $_REQUEST['service'] == $service->id ? 'selected="selected"' : '' ?>><?php echo $service->name ?></option> 
     589                            <?php endforeach ?> 
     590                        </select> 
     591                    </td> 
     592                </tr> 
     593                <tr> 
     594                    <td class="fieldname"><?php _e('Book', $sermon_domain) ?></td> 
     595                    <td class="field"><select name="book"> 
     596                            <option value=""><?php _e('[All]', $sermon_domain) ?></option> 
     597                            <?php foreach ($books as $book): ?> 
     598                            <option value="<?php echo $book ?>" <?php echo $_REQUEST['book'] == $book ? 'selected=selected' : '' ?>><?php echo $book ?></option> 
     599                            <?php endforeach ?> 
     600                        </select> 
     601                    </td> 
     602                    <td class="fieldname rightcolumn"><?php _e('Series', $sermon_domain) ?></td> 
     603                    <td class="field"><select name="series" id="series"> 
     604                            <option value="0" <?php echo $_REQUEST['series'] != 0 ? '' : 'selected="selected"' ?>><?php _e('[All]', $sermon_domain) ?></option> 
     605                            <?php foreach ($series as $item): ?> 
     606                            <option value="<?php echo $item->id ?>" <?php echo $_REQUEST['series'] == $item->id ? 'selected="selected"' : '' ?>><?php echo $item->name ?></option> 
     607                            <?php endforeach ?> 
     608                        </select> 
     609                    </td> 
     610                </tr> 
     611                <tr> 
     612                    <td class="fieldname"><?php _e('Start date', $sermon_domain) ?></td> 
     613                    <td class="field"><input type="text" name="date" id="date" value="<?php echo mysql_real_escape_string($_REQUEST['date']) ?>" /></td> 
     614                    <td class="fieldname rightcolumn"><?php _e('End date', $sermon_domain) ?></td> 
     615                    <td class="field"><input type="text" name="date" id="enddate" value="<?php echo mysql_real_escape_string($_REQUEST['enddate']) ?>" /></td> 
     616                </tr> 
     617                <tr> 
     618                    <td class="fieldname"><?php _e('Keywords', $sermon_domain) ?></td> 
     619                    <td class="field" colspan="3"><input style="width: 98.5%" type="text" id="title" name="title" value="<?php echo mysql_real_escape_string($_REQUEST['title']) ?>" /></td> 
     620                </tr> 
     621                <tr> 
     622                    <td class="fieldname"><?php _e('Sort by', $sermon_domain) ?></td> 
     623                    <td class="field"><select name="sortby" id="sortby"> 
     624                            <?php foreach ($sb as $k => $v): ?> 
     625                            <option value="<?php echo $v ?>" <?php echo $csb == $v ? 'selected="selected"' : '' ?>><?php _e($k, $sermon_domain) ?></option> 
     626                            <?php endforeach ?> 
     627                        </select> 
     628                    </td> 
     629                    <td class="fieldname rightcolumn"><?php _e('Direction', $sermon_domain) ?></td> 
     630                    <td class="field"><select name="dir" id="dir"> 
     631                            <?php foreach ($di as $k => $v): ?> 
     632                            <option value="<?php echo $v ?>" <?php echo $cd == $v ? 'selected="selected"' : '' ?>><?php _e($k, $sermon_domain) ?></option> 
     633                            <?php endforeach ?> 
     634                        </select> 
     635                    </td> 
     636                </tr> 
     637                <tr> 
     638                    <td colspan="3">&nbsp;</td> 
     639                    <td class="field"><input type="submit" class="filter" value="<?php _e('Filter &raquo;', $sermon_domain) ?>">            </td> 
     640                </tr> 
     641            </table> 
     642            <input type="hidden" name="page" value="1"> 
    359643        </div> 
    360644    </form> 
  • sermon-browser/branches/0.10-0.23/multi.php

    r57035 r57037  
     1<a style="font-weight:bold; font-size: 120%" href="<?php echo get_option("sb_podcast") ?>">Subscribe to our podcast</a><br />(automatically downloads <b>all</b> new sermons to your computer, iPod or MP3 player). 
     2 
    13<div class="sermon-browser"> 
    2  
    3  
    4  
    54    <h2>Filters</h2>         
    6  
    7  
    8  
    9    <?php bb_print_filters() ?> 
    10  
    11  
    12  
    13    <h2>Sermons (<?php bb_print_sermons_count() ?>)</h2>      
    14  
    15  
    16  
    17    <?php foreach ($sermons as $sermon): ?>   
    18  
    19  
    20  
    21         <h3><a href="<?php bb_print_sermon_link($sermon) ?>"><?php echo stripslashes($sermon->title) ?></a></h3>     
    22  
    23  
    24  
    25         Preacher: <a href="<?php bb_print_preacher_link($sermon) ?>"><?php echo stripslashes($sermon->preacher) ?></a><br />     
    26  
    27  
    28  
    29         Series: <a href="<?php bb_print_series_link($sermon) ?>"><?php echo stripslashes($sermon->series) ?></a><br />   
    30  
    31  
    32  
    33         Service: <a href="<?php bb_print_service_link($sermon) ?>"><?php echo stripslashes($sermon->service) ?></a><br />    
    34  
    35  
    36  
    37         Date: <?php echo date("j F Y", strtotime($sermon->date)) ?><br /> 
    38  
    39  
    40  
    41         Passage: <?php $foo = unserialize($sermon->start); $bar = unserialize($sermon->end); echo $foo[0]["book"] ?>, <?php echo $foo[0]["chapter"] ?> : <?php echo $foo[0]["verse"] ?> - <?php echo $bar[0]["book"] ?>, <?php echo $bar[0]["chapter"] ?> : <?php echo $bar[0]["verse"] ?><br /> 
    42  
    43  
    44  
    45         Files:<br /> 
    46  
    47  
    48  
    49         <?php $files = bb_get_files($sermon) ?><?php foreach ($files as $file): ?>   
    50  
    51  
    52  
    53             <?php bb_print_file($file->name) ?> 
    54  
    55  
    56  
    57         <?php endforeach ?>  
    58  
    59  
    60  
     5    <?php bb_print_filters() ?> 
     6    <h2>Sermons (<?php bb_print_sermons_count() ?>)</h2>     
     7    <div class="floatright"><?php bb_print_next_page_link() ?></div> 
     8    <div class="floatleft"><?php bb_print_prev_page_link() ?></div> 
     9    <div style="clear:both"><a href="<?php bb_print_podcast_url() ?>">Subscribe to a podcast for this search</a><br />(automatically downloads sermons <b>that match this search</b> to your computer, iPod or MP3 player).</div> 
     10    <table class="sermons"> 
     11    <?php foreach ($sermons as $sermon): ?><?php $stuff = bb_get_stuff($sermon) ?>   
     12        <tr> 
     13            <td class="sermon-title"><a href="<?php bb_print_sermon_link($sermon) ?>"><?php echo stripslashes($sermon->title) ?></a></td> 
     14        </tr> 
     15        <tr> 
     16            <td class="sermon-passage"><?php $foo = unserialize($sermon->start); $bar = unserialize($sermon->end); echo bb_get_books($foo[0], $bar[0]) ?> (Part of the <a href="<?php bb_print_series_link($sermon) ?>"><?php echo stripslashes($sermon->series) ?></a> series).</td> 
     17        </tr> 
     18        <tr> 
     19            <td class="files"><?php foreach ((array) $stuff["Files"] as $file): ?><?php bb_print_file($file) ?><?php endforeach ?></td> 
     20        </tr> 
     21        <tr> 
     22            <td class="urls"><?php foreach ((array) $stuff["URLs"] as $url): ?><?php bb_print_url($url) ?><?php endforeach ?></td> 
     23        </tr> 
     24        <tr> 
     25            <td class="embed"><?php foreach ((array) $stuff["Code"] as $code): ?><?php bb_print_code($code) ?><?php endforeach ?></td> 
     26        </tr> 
     27        <tr> 
     28            <td class="preacher">Preached by <a href="<?php bb_print_preacher_link($sermon) ?>"><?php echo stripslashes($sermon->preacher) ?></a> on <?php echo date("j F Y", strtotime($sermon->date)) ?> (<a href="<?php bb_print_service_link($sermon) ?>"><?php echo stripslashes($sermon->service) ?></a>).</td> 
     29        </tr> 
    6130    <?php endforeach ?> 
    62  
    63  
    64  
    65     <?php bb_print_next_page_link() ?> 
    66  
    67  
    68  
    69     <?php bb_print_prev_page_link() ?> 
    70  
    71  
    72  
     31    </table> 
     32    <div class="floatright"><?php bb_print_next_page_link() ?></div> 
     33    <div class="floatleft"><?php bb_print_prev_page_link() ?></div> 
    7334</div> 
  • sermon-browser/branches/0.10-0.23/sermon.php

    r57035 r57037  
    55Description: Add sermons to your Wordpress blog. Coding by <a href="http://codeandmore.com/">Tien Do Xuan</a>. Design  
    66Author: Mark Barnes 
    7 Version: 0.1 
     7Version: 0.2 
    88Author URI: http://www.4-14.org.uk/ 
    99 
    10 This work is licenced under the Creative Commons Attribution 2.0 UK: England & Wales License. 
    11 To view a copy of this licence, visit http://creativecommons.org/licenses/by/2.0/uk/ or send a 
    12 letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. 
     10Copyright (c) 2008 Mark Barnes 
     11 
     12This program is free software: you can redistribute it and/or modify 
     13it under the terms of the GNU General Public License as published by 
     14the Free Software Foundation, either version 3 of the License, or 
     15(at your option) any later version. 
     16 
     17This program is distributed in the hope that it will be useful, 
     18but WITHOUT ANY WARRANTY; without even the implied warranty of 
     19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     20GNU General Public License for more details. 
     21 
     22You should have received a copy of the GNU General Public License 
     23along with this program.  If not, see <http://www.gnu.org/licenses/>. 
    1324 
    1425*/ 
    1526 
     27// localization stuff 
    1628$sermon_domain = 'tdxsm'; 
    1729$sermon_is_setup = 0; 
     
    3042} 
    3143 
     44// user-defined icons 
    3245include_once('filetypes.php'); 
     46 
     47// URLs and paths 
     48$ser_ver = '1.1'; 
     49 
    3350$url = get_bloginfo('wpurl'); 
    3451global $wordpressRealPath; 
    3552$wordpressRealPath = str_replace("\\", "/", dirname(dirname(dirname(dirname(__FILE__))))); 
    3653global $defaultSermonPath; 
    37 $defaultSermonPath = "/wp-content/plugins/sermonbrowser/files/"; 
    38 $defaultSermonURL = get_bloginfo('url')."/wp-content/plugins/sermonbrowser/files/"; 
    39  
     54$defaultSermonPath = '/'.get_option('upload_path').'/sermons/'; 
     55$defaultSermonURL = get_bloginfo('url').'/'.get_option('upload_path').'/sermons/'; 
     56 
     57// install if needed 
    4058sermon_setup(); 
    4159 
     60// Bible books 
    4261$books = array('Genesis', 'Exodus', 'Leviticus', 'Numbers', 'Deuteronomy', 'Joshua', 'Judges', 'Ruth', '1 Samuel', '2 Samuel', '1 Kings', '2 Kings', '1 Chronicles', '2 Chronicles', 'Ezra', 'Nehemiah', 'Esther', 'Job', 'Psalm', 'Proverbs', 'Ecclesiastes', 'Song of Solomon', 'Isaiah', 'Jeremiah', 'Lamentations', 'Ezekiel', 'Daniel', 'Hosea', 'Joel', 'Amos', 'Obadiah', 'Jonah', 'Micah', 'Nahum', 'Habakkuk', 'Zephaniah', 'Haggai', 'Zechariah', 'Malachi', 'Matthew', 'Mark', 'Luke', 'John', 'Acts', 'Romans', '1 Corinthians', '2 Corinthians', 'Galatians', 'Ephesians', 'Philippians', 'Colossians', '1 Thessalonians', '2 Thessalonians', '1 Timothy', '2 Timothy', 'Titus', 'Philemon', 'Hebrews', 'James', '1 Peter', '2 Peter', '1 John', '2 John', '3 John', 'Jude', 'Revelation'); 
    4362 
     63// everything related to front end 
    4464include('frontend.php'); 
    4565 
     66// ajax stuff 
     67// through out this plugin, p stands for preacher, s stands for service and ss stands for series 
    4668if ($_POST['sermon'] == 1) {     
    47     if ($_POST['pname']) { 
     69    if ($_POST['pname']) { // preacher 
    4870        $pname = mysql_real_escape_string($_POST['pname']); 
    4971        if ($_POST['pid']) { 
     
    5678            echo 'done'; 
    5779        } else { 
    58             $wpdb->query("INSERT INTO {$wpdb->prefix}sb_preachers VALUES (null, '$pname');"); 
     80            $wpdb->query("INSERT INTO {$wpdb->prefix}sb_preachers VALUES (null, '$pname', '', '');"); 
    5981            echo $wpdb->insert_id; 
    6082        }        
    61     } elseif ($_POST['sname']) { 
     83    } elseif ($_POST['sname']) { // service 
    6284        $sname = mysql_real_escape_string($_POST['sname']); 
    6385        list($sname, $stime) = split('@', $sname); 
     
    7799            echo $wpdb->insert_id; 
    78100        }        
    79     } elseif ($_POST['ssname']) { 
     101    } elseif ($_POST['ssname']) { // series 
    80102        $ssname = mysql_real_escape_string($_POST['ssname']); 
    81103        if ($_POST['ssid']) { 
     
    91113            echo $wpdb->insert_id; 
    92114        } 
    93     } elseif ($_POST['fname']) {         
     115    } elseif ($_POST['fname']) { // file         
    94116        $fname = mysql_real_escape_string($_POST['fname']); 
    95117        if ($_POST['fid']) { 
     
    98120            if ($_POST['del']) { 
    99121                if (unlink($wordpressRealPath.get_option('sb_sermon_upload_dir').$fname)) { 
    100                     $wpdb->query("DELETE FROM {$wpdb->prefix}sb_sermon_files WHERE id = $fid;"); 
     122                    $wpdb->query("DELETE FROM {$wpdb->prefix}sb_stuff WHERE id = $fid;"); 
    101123                    echo 'deleted'; 
    102124                } else { 
    103125                    echo 'failed'; 
    104126                }                
    105             } else { 
    106                  
     127            } else {                 
    107128                $oname = mysql_real_escape_string($_POST['oname']);  
    108                 // QAD           
    109                 if (rename($wordpressRealPath.get_option('sb_sermon_upload_dir').$oname, $wordpressRealPath.get_option('sb_sermon_upload_dir').$fname)) { 
    110                     $wpdb->query("UPDATE {$wpdb->prefix}sb_sermon_files SET name = '$fname' WHERE id = $fid;"); 
     129                if ($wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}sb_stuff WHERE name = '$fname'") == 0 && rename($wordpressRealPath.get_option('sb_sermon_upload_dir').$oname, $wordpressRealPath.get_option('sb_sermon_upload_dir').$fname)) { 
     130                    $wpdb->query("UPDATE {$wpdb->prefix}sb_stuff SET name = '$fname' WHERE id = $fid;"); 
    111131                    echo 'renamed'; 
    112132                } else {         
     
    115135            }                
    116136        } 
    117     } elseif ($_POST['fetch']) {         
     137    } elseif ($_POST['fetch']) { // ajax pagination (sermon browser)         
    118138        $st = (int) $_POST['fetch'] - 1; 
    119139        if (!empty($_POST['title'])) { 
     
    142162        <?php endforeach ?> 
    143163<?php 
    144     } elseif ($_POST['fetchU'] || $_POST['fetchL'] || $_POST['search']) { 
     164    } elseif ($_POST['fetchU'] || $_POST['fetchL'] || $_POST['search']) { // ajax pagination (uploads) 
    145165        if ($_POST['fetchU']) { 
    146166            $st = (int) $_POST['fetchU'] - 1; 
    147             $abc = $wpdb->get_results("SELECT f.*, s.title FROM {$wpdb->prefix}sb_sermon_files AS f LEFT JOIN {$wpdb->prefix}sb_sermons AS s ON f.sermon_id = s.id WHERE f.sermon_id = 0 ORDER BY f.name LIMIT $st, 15;"); 
     167            $abc = $wpdb->get_results("SELECT f.*, s.title FROM {$wpdb->prefix}sb_stuff AS f LEFT JOIN {$wpdb->prefix}sb_sermons AS s ON f.sermon_id = s.id WHERE f.sermon_id = 0 AND f.type = 'file' ORDER BY f.name LIMIT $st, 15;"); 
    148168        } elseif ($_POST['fetchL']) { 
    149169            $st = (int) $_POST['fetchL'] - 1; 
    150             $abc = $wpdb->get_results("SELECT f.*, s.title FROM {$wpdb->prefix}sb_sermon_files AS f LEFT JOIN {$wpdb->prefix}sb_sermons AS s ON f.sermon_id = s.id WHERE f.sermon_id <> 0 ORDER BY f.name LIMIT $st, 15;"); 
     170            $abc = $wpdb->get_results("SELECT f.*, s.title FROM {$wpdb->prefix}sb_stuff AS f LEFT JOIN {$wpdb->prefix}sb_sermons AS s ON f.sermon_id = s.id WHERE f.sermon_id <> 0 AND f.type = 'file' ORDER BY f.name LIMIT $st, 15;"); 
    151171        } else { 
    152172            $s = mysql_real_escape_string($_POST['search']); 
    153             $abc = $wpdb->get_results("SELECT f.*, s.title FROM {$wpdb->prefix}sb_sermon_files AS f LEFT JOIN {$wpdb->prefix}sb_sermons AS s ON f.sermon_id = s.id WHERE f.name LIKE '%{$s}%' ORDER BY f.name;"); 
     173            $abc = $wpdb->get_results("SELECT f.*, s.title FROM {$wpdb->prefix}sb_stuff AS f LEFT JOIN {$wpdb->prefix}sb_sermons AS s ON f.sermon_id = s.id WHERE f.name LIKE '%{$s}%' AND f.type = 'file' ORDER BY f.name;"); 
    154174        }        
    155175?> 
    156176    <?php if (count($abc) >= 1): ?> 
     177        <?php 
     178        // sync db & upload dir 
     179        $wanted = array(-1); 
     180        foreach ((array) $abc as $k => $file) { 
     181            if (!file_exists($wordpressRealPath.get_option('sb_sermon_upload_dir').$file->name)) { 
     182                $wanted[] = $file->id;               
     183                unset($abc[$k]); 
     184            }            
     185        } 
     186        //$wpdb->query("DELETE FROM {$wpdb->prefix}sb_stuff WHERE id IN (".implode(', ', (array) $wanted).")"); 
     187        ?> 
    157188        <?php foreach ($abc as $file): ?> 
    158             <tr class="file <?php echo (++$i % 2 == 0) ? 'alternate' : '' ?>" id="sfile<?php echo $file->id ?>"> 
     189            <tr class="file <?php echo (++$i % 2 == 0) ? 'alternate' : '' ?>" id="<?php echo $_POST['fetchU'] ? '' : 's' ?>file<?php echo $file->id ?>"> 
    159190                <th style="text-align:center" scope="row"><?php echo $file->id ?></th> 
    160                 <td id="s<?php echo $file->id ?>"><?php echo substr($file->name, 0, strrpos($file->name, '.')) ?></td> 
     191                <td id="<?php echo $_POST['fetchU'] ? '' : 's' ?><?php echo $file->id ?>"><?php echo substr($file->name, 0, strrpos($file->name, '.')) ?></td> 
    161192                <td style="text-align:center"><?php echo isset($filetypes[substr($file->name, strrpos($file->name, '.') + 1)]['name']) ? $filetypes[substr($file->name, strrpos($file->name, '.') + 1)]['name'] : strtoupper(substr($file->name, strrpos($file->name, '.') + 1)) ?></td> 
    162                 <td><?php echo $file->title ?></td> 
     193                <?php if (!empty($file->title)): ?> 
     194                <td><?php echo stripslashes($file->title) ?></td> 
     195                <?php endif ?> 
    163196                <td style="text-align:center"> 
    164197                    <script type="text/javascript" language="javascript"> 
     
    187220} 
    188221 
     222// hooks  
    189223add_action('admin_menu', 'bb_add_pages'); 
    190224register_activation_hook(__FILE__,'sermon_install'); 
    191  
     225//sermon_install(); 
     226 
     227// installer 
    192228function sermon_install () { 
    193    global $wpdb, $mdict, $sdict;     
    194    global $sermon_domain; 
    195    global $sermon_db_version; 
     229   global $wpdb, $mdict, $sdict, $books;     
     230   global $ser_ver; 
     231   global $sermon_domain, $sef; 
    196232   global $wordpressRealPath; 
    197    global $defaultSermonPath, $defaultSermonURL; 
     233   global $defaultSermonPath, $defaultSermonURL, $defaultMultiForm, $defaultSingleForm, $defaultStyle; 
    198234   require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 
    199      
     235    
     236   $fooz = <<<HERE 
     237<div class="sermon-browser"> 
     238    <h2>Filters</h2>         
     239    [filters_form] 
     240    <div style="clear:both"><div class="podcastcustom"><a href="[podcast_for_search]">[podcasticon_for_search]</a><span><a href="[podcast_for_search]">Subscribe to custom podcast</a></span><br />(new sermons that match this <b>search</b>)</div><div class="podcastall"><a href="[podcast]">[podcasticon]</a><span><a href="[podcast]">Subscribe to full podcast</a></span><br />(<b>all</b> new sermons)</div> 
     241</div> 
     242    <h2>Sermons ([sermons_count])</h2>       
     243    <div class="floatright">[next_page]</div> 
     244    <div class="floatleft">[previous_page]</div> 
     245    <table class="sermons"> 
     246    [sermons_loop]   
     247        <tr> 
     248            <td class="sermon-title">[sermon_title]</td> 
     249        </tr> 
     250        <tr> 
     251            <td class="sermon-passage">[first_passage] (Part of the [series_link] series).</td> 
     252        </tr> 
     253        <tr> 
     254            <td class="files">[files_loop][file][/files_loop]</td> 
     255        </tr> 
     256        <tr> 
     257            <td class="urls">[urls_loop][url][/urls_loop]</td> 
     258        </tr> 
     259        <tr> 
     260            <td class="embed">[embed_loop][embed][/embed_loop]</td> 
     261        </tr> 
     262        <tr> 
     263            <td class="preacher">Preached by [preacher_link] on [date] ([service_link]).</td> 
     264        </tr> 
     265    [/sermons_loop] 
     266    </table> 
     267    <div class="floatright">[next_page]</div> 
     268    <div class="floatleft">[previous_page]</div> 
     269    [creditlink] 
     270</div></div>HERE; 
     271    $barz = <<<HERE 
     272<div class="sermon-browser-results"> 
     273    <h2>[sermon_title] <span class="scripture">[passages_loop][passage] [/passages_loop]</span></h2> 
     274    <span style="font-size: 120%">[preacher_link], [date]</span><br /> 
     275    Part of the [series_link] series, preached at a [service_link] service<br /> 
     276    Tags: [tags]<br /> 
     277    [files_loop]     
     278        [file]   
     279    [/files_loop] 
     280    [urls_loop] 
     281        [url]   
     282    [/urls_loop] 
     283    [embed_loop] 
     284        <br />[embed]<br /> 
     285    [/embed_loop] 
     286    <br />   
     287    <table class="nearby-sermons"> 
     288        <tr> 
     289            <th class="earlier">Earlier:</th> 
     290            <th>Same day:</th> 
     291            <th class="later">Later:</th> 
     292        </tr> 
     293        <tr> 
     294            <td class="earlier">[prev_sermon]</td> 
     295            <td>[sameday_sermon]</td> 
     296            <td class="later">[next_sermon]</td> 
     297        </tr> 
     298    </table> 
     299    [esvtext] 
     300    [creditlink] 
     301</div> 
     302        HERE; 
     303 
     304$defaultStyle = <<<HERE 
     305.sermon-browser h2 { 
     306    clear: both; 
     307} 
     308 
     309div.sermon-browser table.sermons { 
     310    width: 100%; 
     311} 
     312 
     313div.sermon-browser table.sermons td.sermon-title { 
     314    font-weight:bold; 
     315    font-size: 140%; 
     316    padding-top: 2em; 
     317} 
     318 
     319div.sermon-browser table.sermons td.sermon-passage { 
     320    font-weight:bold; 
     321    font-size: 110%; 
     322} 
     323 
     324div.sermon-browser table.sermons td.preacher { 
     325    border-bottom: 1px solid #444444; 
     326} 
     327 
     328div.sermon-browser table.sermons td.files img { 
     329    border: none; 
     330    margin-right: 24px; 
     331} 
     332 
     333table.sermonbrowser td.fieldname { 
     334    font-weight:bold; 
     335    padding-right: 10px; 
     336    vertical-align:bottom; 
     337} 
     338 
     339table.sermonbrowser td.field input, table.sermonbrowser td.field select{ 
     340    width: 170px; 
     341} 
     342 
     343table.sermonbrowser td.field  #date, table.sermonbrowser td.field #enddate { 
     344    width: 150px; 
     345} 
     346 
     347table.sermonbrowser td { 
     348    white-space: nowrap; 
     349    padding-top: 5px; 
     350    padding-bottom: 5px; 
     351} 
     352 
     353table.sermonbrowser td.rightcolumn { 
     354    padding-left: 10px; 
     355} 
     356 
     357div.sermon-browser div.floatright { 
     358    float: right 
     359} 
     360 
     361div.sermon-browser div.floatleft { 
     362    float: left 
     363} 
     364 
     365img.sermon-icon , img.site-icon { 
     366    border: none; 
     367} 
     368 
     369div.podcastall { 
     370    float:left; 
     371    border: 2px solid #FC9328; 
     372    background: #fff0c8 url(icons/podcast_background.png) repeat-x; 
     373    padding: 0.3em; 
     374} 
     375 
     376div.podcastall img.podcasticon, div.podcastcustom img.podcasticon { 
     377    float:left; 
     378    margin-right: 1em; 
     379    border: none; 
     380} 
     381 
     382div.podcastall span a{ 
     383    color: #FC9328; 
     384    font-weight: bold; 
     385    font-size:125%; 
     386} 
     387 
     388div.podcastcustom { 
     389    float:right; 
     390    border: 2px solid #b83ee5; 
     391    background: #fce4ff url(icons/podcast_custom_background.png) repeat-x; 
     392    padding: 0.3em; 
     393} 
     394div.podcastcustom span a{ 
     395    color: #b83ee5; 
     396    font-weight: bold; 
     397    font-size:125%; 
     398} 
     399 
     400div.esv span.chapter-num { 
     401    font-weight: bold; 
     402    font-size: 150%; 
     403} 
     404 
     405div.esv span.verse-num { 
     406    vertical-align:super; 
     407    line-height: 1em; 
     408    font-size: 65%; 
     409} 
     410 
     411#poweredbysermonbrowser { 
     412    float:right; 
     413} 
     414HERE; 
     415   $defaultMultiForm = $fooz; $defaultSingleForm = $barz; 
     416    
     417    if (get_option('sb_sermon_db_version') == '1.2') { 
     418        return; 
     419    } 
     420    
     421   $sermonUploadDir = $defaultSermonPath; 
     422 
     423//Try to create the folder if not exist 
     424   if (!is_dir($wordpressRealPath.$sermonUploadDir)) { 
     425      //Create that folder 
     426      if (@mkdir($wordpressRealPath.$sermonUploadDir)) { 
     427         //try CHMOD it to 777 
     428         @chmod($wordpressRealPath.$sermonUploadDir, 0777);           
     429      } 
     430   } 
     431 
     432    switch (get_option('sb_sermon_db_version')) { 
     433        case '1.0': 
     434            // db 
     435             
     436            // move files 
     437            $oldSermonPath = "/wp-content/plugins/sermonbrowser/files/"; 
     438            $files = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_stuff WHERE type = 'file' ORDER BY name asc");  
     439            foreach ((array)$files as $file) { 
     440                @chmod($wordpressRealPath.$oldSermonPath.$file->name, 0777); 
     441                @rename($wordpressRealPath.$oldSermonPath.$file->name, $wordpressRealPath.$defaultSermonPath.$file->name); 
     442            } 
     443            //Now alter tables 
     444            $table_name = $wpdb->prefix . "sb_preachers"; 
     445            if($wpdb->get_var("show tables like '$table_name'") == $table_name) {             
     446                  $sql = "ALTER TABLE " . $table_name . " ADD `description` TEXT NOT NULL, ADD `image` VARCHAR( 255 ) NOT NULL ;"; 
     447                  dbDelta($sql); 
     448            } 
     449             
     450            update_option('sb_sermon_db_version', '1.1');        
     451            return; 
     452            break; 
     453        case '1.1': 
     454            add_option('sb_sermon_style', base64_encode($defaultStyle)); 
     455            update_option('sb_sermon_db_version', '1.2');    
     456            return; 
     457            break; 
     458        default: 
     459            update_option('sb_sermon_db_version', '1.2'); 
     460            break; 
     461    }        
     462 
    200463   $table_name = $wpdb->prefix . "sb_preachers"; 
    201464   if($wpdb->get_var("show tables like '$table_name'") != $table_name) {             
     
    203466        `id` INT( 10 ) NOT NULL AUTO_INCREMENT , 
    204467        `name` VARCHAR( 30 ) NOT NULL , 
     468        `description` TEXT NOT NULL , 
     469        `image` VARCHAR( 255 ) NOT NULL, 
    205470        PRIMARY KEY ( `id` ) 
    206471        );"; 
    207472      dbDelta($sql); 
    208       $sql = "INSERT INTO " . $table_name . "(name) VALUES ( 'C H Spurgeon' );"; 
     473      $sql = "INSERT INTO " . $table_name . "(name, description, image) VALUES ( 'C H Spurgeon', '', '' );"; 
    209474      dbDelta($sql); 
    210       $sql = "INSERT INTO " . $table_name . "(name) VALUES ( 'Martyn Lloyd-Jones' );"; 
     475      $sql = "INSERT INTO " . $table_name . "(name, description, image) VALUES ( 'Martyn Lloyd-Jones', '', '' );"; 
    211476      dbDelta($sql); 
    212477   } 
     
    263528      dbDelta($sql); 
    264529   } 
    265     
    266    $table_name = $wpdb->prefix . "sb_sermon_files"; 
    267    if($wpdb->get_var("show tables like '$table_name'") != $table_name) {       
    268       $sql = "CREATE TABLE " . $table_name . " ( 
    269         `id` INT( 10 ) NOT NULL AUTO_INCREMENT , 
    270         `name` VARCHAR( 255 ) NOT NULL , 
     530 
     531    $table_name = $wpdb->prefix . "sb_books_sermons"; 
     532    if($wpdb->get_var("show tables like '$table_name'") != $table_name) {       
     533      $sql = "CREATE TABLE " . $table_name . " (         
     534        `id` INT(10) NOT NULL AUTO_INCREMENT, 
     535        `book_name` VARCHAR( 30 ) NOT NULL ,         
     536        `chapter` INT(10) NOT NULL, 
     537        `verse` INT(10) NOT NULL, 
     538        `order` INT(10) NOT NULL, 
     539        `type` VARCHAR ( 30 ),  
    271540        `sermon_id` INT( 10 ) NOT NULL , 
    272541        PRIMARY KEY ( `id` ) 
     
    274543      dbDelta($sql); 
    275544   } 
     545 
     546    $table_name = $wpdb->prefix . "sb_books"; 
     547    if($wpdb->get_var("show tables like '$table_name'") != $table_name) {       
     548      $sql = "CREATE TABLE " . $table_name . " (         
     549        `id` INT(10) NOT NULL AUTO_INCREMENT, 
     550        `name` VARCHAR( 30 ) NOT NULL , 
     551        PRIMARY KEY ( `id` ) 
     552        );"; 
     553      dbDelta($sql); 
     554   } 
     555    
     556   $table_name = $wpdb->prefix . "sb_stuff"; 
     557   if($wpdb->get_var("show tables like '$table_name'") != $table_name) {       
     558      $sql = "CREATE TABLE " . $table_name . " ( 
     559        `id` INT( 10 ) NOT NULL AUTO_INCREMENT , 
     560        `type` VARCHAR( 30 ) NOT NULL , 
     561        `name` TEXT NOT NULL , 
     562        `sermon_id` INT( 10 ) NOT NULL , 
     563        PRIMARY KEY ( `id` ) 
     564        );"; 
     565      dbDelta($sql); 
     566   } 
     567 
     568    $table_name = $wpdb->prefix . "sb_tags"; 
     569       if($wpdb->get_var("show tables like '$table_name'") != $table_name) {       
     570          $sql = "CREATE TABLE " . $table_name . " ( 
     571            `id` INT( 10 ) NOT NULL AUTO_INCREMENT , 
     572            `name` TEXT NOT NULL , 
     573            PRIMARY KEY ( `id` ) 
     574            );"; 
     575          dbDelta($sql); 
     576       } 
     577     
     578    $table_name = $wpdb->prefix . "sb_sermons_tags"; 
     579       if($wpdb->get_var("show tables like '$table_name'") != $table_name) {       
     580          $sql = "CREATE TABLE " . $table_name . " ( 
     581            `id` INT( 10 ) NOT NULL AUTO_INCREMENT , 
     582            `sermon_id` INT( 10 ) NOT NULL , 
     583            `tag_id` INT( 10 ) NOT NULL , 
     584            PRIMARY KEY ( `id` ) 
     585            );"; 
     586          dbDelta($sql); 
     587       } 
    276588   $welcome_name = __('Delete', $sermon_domain); 
    277    $welcome_text = __('Congratulations, you just completed the installation!', $sermon_domain); 
    278     
    279    $sermon_db_version = "1.0"; 
    280    add_option('sb_sermon_db_version', $sermon_db_version); 
    281    $sermonUploadDir = $defaultSermonPath;    
     589   $welcome_text = __('Congratulations, you just completed the installation!', $sermon_domain);  
    282590   add_option('sb_sermon_upload_dir', $sermonUploadDir); 
    283591   add_option('sb_sermon_upload_url', $defaultSermonURL); 
    284    $fooz = '<div class="sermon-browser"> 
    285     <h2>Filters</h2>         
    286     [filters_form] 
    287     <h2>Sermons ([sermons_count])</h2>       
    288     <table class="sermons"> 
    289     [sermons_loop]   
    290         <tr> 
    291             <td class="sermon-title">[sermon_title]</td> 
    292         </tr> 
    293         <tr> 
    294             <td class="sermon-passage">[first_bible_passage] (Part of the [series_link] series).</td> 
    295         </tr> 
    296         <tr> 
    297             <td class="files">[files_loop][file][/files_loop]</td> 
    298         </tr> 
    299         <tr> 
    300             <td class="preacher">Preached by [preacher_link] on [date] ([service_link]).</td> 
    301         </tr> 
    302     [/sermons_loop] 
    303     </table> 
    304     [next_page] 
    305  
    306     [previous_page] 
    307  
    308 </div>'; 
    309     $barz = <<<HERE 
    310 <div class="sermon-browser-results"> 
    311     <h2>View single sermon</h2> 
    312     Title: [sermon_title]<br /> 
    313     Preacher: [preacher_link]<br /> 
    314     Series: [series_link]<br /> 
    315     Service: [service_link]<br /> 
    316     Date: [date]<br /> 
    317     [passages_loop]  
    318         [start_passage] - [end_passage]<br /> 
    319     [/passages_loop] 
    320     Files:<br /> 
    321     [files_loop]     
    322         [file] 
    323     [/files_loop] 
    324     [next_sermon] 
    325     [prev_sermon] 
    326     Same day: [sameday_sermon] 
    327 </div>       
    328 HERE; 
     592    add_option('sb_podcast', get_bloginfo('url').$sef.'/?podcast'); 
     593    
     594     
    329595    delete_option('sb_sermon_multi_form'); 
    330596    add_option('sb_sermon_multi_form', base64_encode($fooz)); 
    331597    delete_option('sb_sermon_single_form'); 
    332598    add_option('sb_sermon_single_form', base64_encode($barz)); 
     599     
     600 
     601     
     602    for ($i=0; $i < count($books); $i++) {  
     603        $wpdb->query("INSERT INTO {$wpdb->prefix}sb_books VALUES (null, '$books[$i]');"); 
     604    } 
     605 
    333606    
    334    //Try to create the folder if not exist 
    335    if (!is_dir($wordpressRealPath.$sermonUploadDir)) { 
    336       //Create that folder 
    337       if (@mkdir($wordpressRealPath.$sermonUploadDir)) { 
    338          //try CHMOD it to 777 
    339          @chmod($wordpressRealPath.$sermonUploadDir, 0777);           
    340       } 
    341    } 
    342607/* 
    343608    $fh = fopen($wordpressRealPath.'/wp-content/plugins/sermonbrowser/multi.php', 'w'); 
     
    356621} 
    357622 
     623// admin cp pages 
    358624function bb_add_pages() { 
    359625    global $sermon_domain; 
     
    361627    add_submenu_page(__FILE__, __('Sermons', $sermon_domain), __('Sermons', $sermon_domain), 8, __FILE__, 'bb_manage_sermons'); 
    362628    add_submenu_page(__FILE__, __('New Sermon', $sermon_domain), __('New Sermon', $sermon_domain), 8, 'sermonbrowser/new_sermon.php', 'bb_new_sermon'); 
    363     add_submenu_page(__FILE__, __('Manage', $sermon_domain), __('Manage', $sermon_domain), 8, 'sermonbrowser/manage.php', 'bb_manage_everything'); 
     629    add_submenu_page(__FILE__, __('Preachers', $sermon_domain), __('Preachers', $sermon_domain), 8, 'sermonbrowser/preachers.php', 'bb_manage_preachers'); 
     630    add_submenu_page(__FILE__, __('Series &amp; Services', $sermon_domain), __('Series &amp; Services', $sermon_domain), 8, 'sermonbrowser/manage.php', 'bb_manage_everything'); 
    364631    add_submenu_page(__FILE__, __('Uploads', $sermon_domain), __('Uploads', $sermon_domain), 8, 'sermonbrowser/uploads.php', 'bb_uploads'); 
    365632    add_submenu_page(__FILE__, __('Options', $sermon_domain), __('Options', $sermon_domain), 8, 'sermonbrowser/options.php', 'bb_options'); 
     
    367634} 
    368635 
     636// textarea @ option 
     637// dirty trick, i know 
    369638function bb_build_textarea($name, $html) { 
    370     $out = '<textarea name="'.$name.'" cols="50" rows="5">'; 
     639    $out = '<textarea name="'.$name.'" cols="75" rows="15">'; 
    371640    $out .= stripslashes(str_replace('\r\n', "\n", base64_decode($html)));  
    372641    $out .= '</textarea>'; 
     
    374643} 
    375644 
     645// configuration 
    376646function bb_options() { 
    377     global $wpdb, $sermon_domain, $mdict, $sdict; 
     647    global $wpdb, $sermon_domain, $mdict, $sdict, $sef; 
    378648    global $wordpressRealPath; 
    379     global $defaultSermonPath, $defaultSermonURL; 
     649    global $defaultSermonPath, $defaultSermonURL, $defaultMultiForm, $defaultSingleForm, $defaultStyle; 
    380650    if ($_POST['resetdefault']) { 
    381651        $dir = $defaultSermonPath; 
     652        update_option('sb_podcast', get_bloginfo('url').$sef.'/?podcast'); 
    382653        update_option('sb_sermon_upload_dir', $defaultSermonPath); 
    383654        update_option('sb_sermon_upload_url', $defaultSermonURL); 
     
    410681    if ($_POST['save']) { 
    411682        $dir = rtrim(str_replace("\\", "/", $_POST['dir']), "/")."/"; 
     683        update_option('sb_podcast', $_POST['podcast']); 
    412684        update_option('sb_sermon_upload_dir', $dir); 
    413685        update_option('sb_sermon_upload_url', get_bloginfo('url').$dir);         
     
    438710       } 
    439711    } 
    440     if ($_POST['save2']) { 
     712     
     713    if ($_POST['save2'] || $_POST['resetdefault2']) { 
    441714        $multi = $_POST['multi']; 
    442715        $single = $_POST['single']; 
     716        $style = $_POST['style']; 
     717        if($_POST['resetdefault2']){ 
     718            $multi = $defaultMultiForm; 
     719            $single = $defaultSingleForm; 
     720            $style = $defaultStyle; 
     721        } 
    443722        //* 
    444723        update_option('sb_sermon_multi_form', base64_encode($multi)); 
    445724        update_option('sb_sermon_single_form', base64_encode($single)); 
     725        update_option('sb_sermon_style', base64_encode($style)); 
    446726        //*/ 
    447727        $checkSermonUpload = checkSermonUploadable(); 
     
    477757                echo '</b></div>';           
    478758            } 
     759            $fh = @fopen($wordpressRealPath.'/wp-content/plugins/sermonbrowser/style.css', 'w'); 
     760            if ($fh) { 
     761                fwrite($fh, $style); 
     762                fclose($fh); 
     763            } else { 
     764                echo '<div id="message" class="updated fade"><p><b>'; 
     765                _e('Could not save style template. Please check permission for stlye.css in plugin folder', $sermon_domain); 
     766                echo '</b></div>';           
     767            } 
    479768        //*/     
    480769            echo '<div id="message" class="updated fade"><p><b>'; 
     
    505794        $table_name = $wpdb->prefix."sb_sermons"; 
    506795        if ($wpdb->get_var("show tables like '$table_name'") == $table_name) $wpdb->query("DROP TABLE $table_name"); 
    507         $table_name = $wpdb->prefix."sb_sermon_files"; 
     796        $table_name = $wpdb->prefix."sb_stuff"; 
    508797        if ($wpdb->get_var("show tables like '$table_name'") == $table_name) $wpdb->query("DROP TABLE $table_name"); 
    509798        delete_option('sb_sermon_upload_dir'); 
     
    522811                <td align="right"><?php _e('Upload directory', $sermon_domain) ?>: </td> 
    523812                <td><input type="text" name="dir" value="<?php echo get_option('sb_sermon_upload_dir') ?>" style="width:300px"></td> 
     813            </tr> 
     814            <tr> 
     815                <td align="right"><?php _e('Public podcast feed', $sermon_domain) ?>: </td> 
     816                <td><input type="text" name="podcast" value="<?php echo get_option('sb_podcast') ?>" style="width:300px"></td> 
     817            </tr> 
     818            <tr> 
     819                <td align="right"><?php _e('Private podcast feed', $sermon_domain) ?>: </td> 
     820                <td><?php echo get_bloginfo('url').$sef.'/?podcast' ?></td> 
    524821            </tr> 
    525822        </table>         
     
    540837                    <?php bb_build_textarea('single', get_option('sb_sermon_single_form')) ?> 
    541838                </td> 
     839            </tr> 
     840            <tr> 
     841                <td align="right"><?php _e('Style', $sermon_domain) ?>: </td> 
     842                <td> 
     843                    <?php bb_build_textarea('style', get_option('sb_sermon_style')) ?> 
     844                </td> 
    542845            </tr>            
    543846        </table>                 
    544         <p class="submit"><input type="submit" name="save2" value="<?php _e('Save', $sermon_domain) ?> &raquo;" /></p>  
     847        <p class="submit"><input type="submit" name="resetdefault2" value="<?php _e('Reset to defaults', $sermon_domain) ?>"  />&nbsp;<input type="submit" name="save2" value="<?php _e('Save', $sermon_domain) ?> &raquo;" /></p>  
    545848    </div>       
    546849    <div class="wrap"> 
     
    557860} 
    558861 
     862// manual 
    559863function bb_help() { 
    560864?>   
     865    <style>div.wrap h3, div.wrap h4, div.wrap h5 {margin-bottom: 0; margin-top: 2em} div.wrap p {margin-left: 2em; margin-top: 0.5em} div.wrap h3 {border-top: 1px solid #555555; padding-top: 0.5em}</style> 
    561866    <div class="wrap"> 
    562867        <h2><?php _e('Help page', $sermon_domain) ?></h2> 
    563         <table border="0" class="widefat"> 
    564             <tr> 
    565                 <td>Just help page</td> 
    566             </tr> 
    567         </table> 
     868        <h3>Screencasts</h3> 
     869        <p>If you need help with using sermonbrowser for the first time, these five minute screencast tutorials should be your first port of call:</p> 
     870        <ul> 
     871            <li><a href="http://www.4-14.org.uk/sermonbrowser-tutorial/tutorial-1.html" target="_blank">Installation and Overview</a>.</li> 
     872            <li><a href="http://www.4-14.org.uk/sermonbrowser-tutorial/tutorial-2.html" target="_blank">Basic Options</a>.</li> 
     873            <li><a href="http://www.4-14.org.uk/sermonbrowser-tutorial/tutorial-3.html" target="_blank">Preachers, Series and Services</a>.</li> 
     874            <li><a href="http://www.4-14.org.uk/sermonbrowser-tutorial/tutorial-4.html" target="_blank">Entering a new sermon</a>.</li> 
     875            <li><a href="http://www.4-14.org.uk/sermonbrowser-tutorial/tutorial-5.html" target="_blank">Editing a sermon and adding embedded video</a>.</li> 
     876        </ul> 
     877        <h4>Template tags</h4> 
     878        <p>If you want to change the way SermonBrowser displays on your website, you'll need to edit the templates and/or CSS file. Check out <a href="#templatetags">this guide to the template tags</a>.</p> 
     879        <h3>Frequently asked questions</h3> 
     880        <ul> 
     881            <li><a href="#nosermons">I've activated the plugin, and entered in a few sermons, but they are not showing up to my website users. Where are they?</a></li> 
     882            <li><a href="#chmod">What does the error message "Error: The upload folder is not writeable. You need to CHMOD the folder to 666 or 777." mean?</a></li> 
     883            <li><a href="#uploaderrors">SermonBrowser spends a long time attempting to upload files, but the file is never uploaded. What's happening?</a></li> 
     884            <li><a href="#audioplayer">Why are my MP3 files are appearing as an icon, rather than as a player, as I've seen on other SermonBrowser sites?</a></li> 
     885            <li><a href="#differentversions">Can I have different bible versions from the ESV?</a></li> 
     886            <li><a href="#chipmunk">When using the 1pixelout audio player, my pastor sounds like a chipmunk! What's going on?</a> 
     887            <li><a href="#sidebar">How do I get recent sermons to display in my sidebar?</a></li> 
     888            <li><a href="#diskspace">My host only allows me a certain amount of disk space, and I have so many sermons uploaded, I've run out of space! What can I do?</a></li> 
     889            <li><a href="#videos">How do I upload videos to SermonBrowser?</a></li> 
     890            <li><a href="#poweredby">Can I turn off the "Powered by Sermonbrowser" link?</a></li> 
     891            <li><a href="#publicprivate">What is the difference between the public and private podcast feeds?</a></li> 
     892            <li><a href="#differentpodcasts">On the sermons page, what is the difference between subscribing to our podcast, and subscribing to a podcast for this search?</a></li> 
     893            <li><a href="#sortorder">Can I change the default sort order of the sermons?</a></li> 
     894            <li><a href="#pagenotfound">Why do I get a page not found error when I click on my podcast feed?</a></li> 
     895            <li><a href="#changedisplay">Can I change the way sermons are displayed?</a></li> 
     896            <li><a href="#changesearchform">The search form is too big/too small for my layout. How do I make it narrower/wider?</a></li> 
     897            <li><a href="#esvtextmissing">Why is sometimes the ESV Bible text missing?</a></li> 
     898            <li><a href="#exceededquota">Why does my sermon page say I have exceeded my quota for ESV lookups?</a></li> 
     899            <li><a href="#icons">How can I change the icons that Sermon Browser uses, or add new icons?</a></li> 
     900        </ul> 
     901        <hr style="width: 50%"> 
     902        <h4 id="nosermons">I've activated the plugin, and entered in a few sermons, but they are not showing up to my website users. Where are they?</h4> 
     903        <p>SermonBrowser only displays your sermons where you choose. You need to create the page/post where you want the sermons to appear (or edit an existing one), and add <b>[sermons]</b> to the page/post. You can also add some explantory text if you wish. If you do so, the text will appear on <i>all</i> your sermons pages. If you want your text to only appear on the list of sermons, not on individual sermon pages, you need to edit the SermonBrowser templates (see below).</p> 
     904        <h4 id="chmod">What does the error message "Error: The upload folder is not writeable. You need to CHMOD the folder to 666 or 777." mean?</h4> 
     905        <p>SermonBrowser tries to set the correct permissions on your folders for you, but sometimes restrictions mean that you have to do it yourself. You need to make sure that SermonBrowser is able to write to your sermons upload folder (usually /wp-content/uploads/sermons/). <a href="http://samdevol.com/wordpress-troubleshooting-permissions-chmod-and-paths-oh-my/" target="_blank">This tutorial</a> explains how to use the free FileZilla FTP software to do this.</p> 
     906        <h4 id="uploaderrors">SermonBrowser spends a long time attempting to upload files, but the file is never uploaded. What's happening?</h4> 
     907        <p>The most likely cause is that you're reaching either the maximum filesize that can be uploaded, or the maximum time a PHP script can run for. <a href="http://articles.techrepublic.com.com/5100-10878_11-5272345.html" target="_blank">Editing your php.ini</a> may help overcome these problems - but if you're on shared hosting, it's possible your host has set maximum limits you cannot change. If that's the case, you should upload your files via FTP. This is generally a better option than using your browser, particularly if you have several files to upload. If you do edit your php.ini file, these settings should be adequate:</p> 
     908        <p style="font-family:monospace">file_uploads = On<br /> 
     909        upload_max_filesize = 15M<br /> 
     910        post_max_size = 15M<br /> 
     911        max_execution_time = 600<br/> 
     912        max_input_time = 600<br /> 
     913        memory_limit = 16M<br /></p> 
     914        <h4 id="audioplayer">Why are my MP3 files are appearing as an icon, rather than as a player, as I've seen on other SermonBrowser sites?</h4> 
     915        <p>You need to install and activate the <a href="http://www.1pixelout.net/code/audio-player-wordpress-plugin/">1pixelout audio player</a> plugin. You can also customise the plugin so that its colours match your site.</p> 
     916        <h4 id="differentversions">Can I have different bible versions from the ESV?</h4> 
     917        <p>The ESV translation is the only one that provides an API which allows for this functionality. However, if you're desperate to use other versions, you can manage it using other Wordpress plugins (albeit with reduced functionality). The <a href="http://wordpress.org/extend/plugins/ebibleicious/">eBibleicious</a> plugin allows for NASB, MSG, KJV, NKJV, ESV, HCSB, and NCV (use it in 'snippet' mode). However, there are three disadvantages. (1) To use it, you'll need to register for an API key (although it is free). (2) It uses Javascript so search engines won't see the Bible text, and nor will users with javascript turned off. (3) Most importantly, it only shows a maximum of four verses (the ESV shows up to 500 verses!). 
     918        <p>You can also use the <a href="http://www.logos.com/reftagger">RefTagger</a> plugin, though this shows even few verses. Even worse (for our purposes) the bible passage only shows when you hover over a special link with your mouse. It does, however, provide an even longer list of translations. Please be aware that both RefTagger and eBibleicious will add bible text to bible references across your whole website, not just your sermons pages.</p> 
     919        <p>To use either of these alternatives, just download, install and activate them as you would for any other plugin. Check their settings (make sure you enter get an API key if you're using eBiblicious). You then need to make one change to your SermonBrowser options. In the <i>Single Sermon form</i>, look for <b>[esvtext]</b> and replace it with <b>[biblepassage]</b>. (By default it's right at the end of the code.)</p> 
     920        <h4 id="chipmunk">When using the 1pixelout audio player, my pastor sounds like a chipmunk! What's going on?</h4> 
     921        <p>This 'feature' is caused by a well-known bug in Adobe flash. In order for the files to play correctly, when they are saved, the sample rate needs to be set at a multiple of 11.025kHz (i.e. 11.025, 22.05 or 44.1).</p> 
     922        <h4 id="sidebar">How do I get recent sermons to display in my sidebar?</h4> 
     923        <p>If your WordPress theme supports widgets, just go to Design and choose <a href="widgets.php">Widgets</a>. There you easily can add the Sermons widget to your sidebar. If your theme doesn't support widgets, you'll need to edit your theme manually. Usually, you'll be editing a file called <b>sidebar.php</b>, but your theme may give it a different name. Add the following code:</p> 
     924            <p style="font-family:monospace">&lt;?php if (function_exists('display_sermons')) display_sermons(array('display_preacher' => 0, 'display_passage' => 1, 'preacher' => 0, 'service' => 0, 'series' => 0, 'limit' => 5)) ?></code> 
     925        <p>Each of the numbers in that line can be changed. <b>display_preacher</b> and <b>display_passage</b> affect what is displayed (0 is off, 1 is on). <b>preacher</b>, <b>service</b> and <b>series</b> allow you to limit the output to a particular preacher, service or series. Simply change the number of the ID of the preacher/services/series you want to display. You can get the ID from the Preachers page, or the Series & Services page. 0 shows all preachers/services/series. <b>limit</b> is simply the maximum number of sermons you want displayed.</p> 
     926        <h4 id="diskspace">My host only allows me a certain amount of disk space, and I have so many sermons uploaded, I've run out of space! What can I do?</h4> 
     927        <p>You could, of course, change your host to someone a little more generous! I use <a href="http://www.vortechhosting.com/shared/windows.php">VortechHosting</a> for low traffic sites (5Gb of disk space for less than $10 a month), and <a href="https://www.liquidweb.com/cart/content/vps/">LiquidWeb VPS</a> for higher traffic sites (20Gb disk space for $60 a month). You should also make sure you encode your sermons at a medium to high compression. Usually, 22.05kHz, 48kbps mono is more than adequate (you could probably go down to 32kbps for even higher compression). 48kbps means every minute of recording takes up 360kb of disk space, so a thirty minute sermon will just over 10Mb. At this setting, 5Gb would be enough for over 450 sermons.</p> 
     928        <p>If you can't change your host, you can still use SermonBrowser. You'll just have to upload your sermon files to another site - preferably a free one! We recommend <a href="http://www.odeo.com/" target="blank">Odeo</a>. If you want to use Odeo's audio player on your website, copy the embed code they give you, and when you add your sermon to SermonBrowser, select "Enter embed code:" and paste it in. If you want to use the standard 1pixelout audio player, copy the "Download MP3" link Odeo give you, and when you add your sermon to SermonBrowser, select "Enter an URL" and paste it in.</p> 
     929        <h4 id="videos">How do I upload videos to SermonBrowser?</h4> 
     930        <p>You can't - but you can upload videos to other sites, then embed them in your sermons. You can use any site that allows you to embed your video in other websites, including <a href="http://www.youtube.com/">YouTube</a>, but we recommend <a href="http://video.google.com/videouploadform">GoogleVideo</a> as the most suitable for sermons. That's because most video-sharing sites are designed for relatively short clips of 10 minutes or so, but GoogleVideo will accept videos of any length - and there are no quotas for the maximum size of a video, nor the number of videos you can store. Once your video is uploaded and available on Google Video, you can copy the embed code it gives you, edit your sermon, select "Enter embed code" and paste it in.</p> 
     931        <h4 id="poweredby">Can I turn off the "Powered by Sermonbrowser" link?</h4> 
     932        <p>The link is there so that people from other churches who listen to your sermons can find out about SermonBrowser themselves. But if you'd like to remove the link, just remove <b>[creditlink]</b> from the templates in SermonBrowser Options</a>.</p> 
     933        <h4 id="publicprivate">What is the difference between the public and private podcast feeds?</h4> 
     934        <p>In SermonBrowser options, you are able to change the address of the public podcast feed. This is the feed that is shown on your sermons page, and is usually the same as your private feed. However, if you use a service such as <a href="http://www.feedburner.com/" target="_blank">FeedBurner</a>, you can use your public feed to send data to feedburner, and change your private feed to your Feedburner address. If you do not use a service like Feedburner, just make sure your public and private feeds are the same.</p>  
     935        <h4 id="differentpodcasts">On the sermons page, what is the difference between subscribing to our podcast, and subscribing to a podcast for this search?</h4> 
     936        <p>The link called <strong>subscribe to full podcast</strong> gives a podcast of <em>all</em> sermons that you add to your site through SermonBrowser. But it may be that some people may just want to subscribe to a feed for certain speakers, or for a certain service. If they wish to do this, they should set the search filters and perform their search, then click on the <strong>Subscribe to custom podcast </strong>link. This will give them a podcast according to the filter they selected. You could also copy this link, and display it elsewhere on the site - for example to provide separate feeds for morning and evening services.</p> 
     937        <h4 id="sortorder">Can I change the default sort order of the sermons?</h4> 
     938        <p>Unfortunately not. Unless the viewer specified otherwise, Sermonbrowser always displays the most recent sermons at the top.</p> 
     939        <h4 id="pagenotfound">Why do I get a page not found error when I click on my podcast feed?</h4> 
     940        <p>You've probably changed the address of your public feed. Try changing it back to the same value as your private feed in Sermon Options.</p> 
     941        <h4 id="changedisplay">Can I change the way sermons are displayed?</h4> 
     942        <p>Yes, definately, although you need to know a little HTML and/or CSS. SermonBrowser has a powerful templating function, so you can exclude certain parts of the output (e.g. if you don't want the links to other sermons preached on the same day to be displayed). To edit the templates, go to SermonBrowser Options. Below is a reference for all the <a href="templatetags">template tags</a> you need. If you just want to change the way the output looks, without changing what is displayed, you need to edit the CSS stylesheet, also in SermonBrowser Options. (See one example, below).</p> 
     943        <h4 id="changesearchform">The search form is too big/too small for my layout. How do I make it narrower/wider?</h4> 
     944        <p>The search form is set to roughly 500 pixels, which should be about right for most WordPress templates. To change it, look for a line in the CSS stylesheet that begins <b>table.sermonbrowser td.field input</b>, and change the width specified after it. To make the form narrower, reduce the width. To make it bigger, increase the width. You'll also need to change the width of the date fields on the line below, which should be 20 pixels smaller.</p> 
     945        <h4 id="esvtextmissing">Why is sometimes the ESV Bible text missing?</h4> 
     946        <p>This usually happens for one of three reasons: (1) If the ESV's website is down. If you can't see <a href="http://www.esvapi.org/v2/rest/passageQuery?key=IP&passage=Gen+1&include-headings=false">Genesis 1</a> then the problem is with the ESV website. It's rarely down for long. (2) If you specify an invalid bible passage (e.g. Romans 22). If this is the case your sermon page will display <i>ERROR: No results were found for your search.</i> (3) If your webhost has disabled <b>allow_url_fopen</b>. This is a feature of PHP that some cheaper webhosts have switched off. There is an alternative that can be used - curl - but SermonBrowser doesn't support that method at the moment. If your webhost has disabled <b>allow_url_fopen</b>, but does support curl, leave a message in the <a href="http://www.4-14.org.uk/sermonbrowser#comments">SermonBrowser comments</a>. If there's enough demand, it could perhaps be added.</p> 
     947        <h4 id="exceededquota">Why does my sermon page say I have exceeded my quota for ESV lookups?</h4> 
     948        <p>The ESV website only allows 5,000 lookups per day from each IP address. That should be enough for most users of SermonBrowser. However, if you are using a shared host, there will be hundreds (perhaps thousands) of other websites on the same IP address as you. If any are also using the ESV API, they also get counted towards that total. If you are using less than 5,000 lookups per day (i.e. you are having less than 5,000 pageviews of your sermon pages), and you receive the error message you'll need to do two things in order to continue to display the text. (1) Sign up for an <a href="http://www.esvapi.org/signup">ESV API key</a>. (2) Edit frontend.php (one of the SermonBrowser files). Look for line 66, and replace <i>&hellip;passageQuery?key=<b>IP</b>&passage=&hellip;</i> with <i>&hellip;passageQuery?key=<b>YOURAPIKEY</b>&passage=&hellip;</i>.</p> 
     949        <p>If you <i>are</i> having more than 5,000 page views per day, then this won't help. Instead, leave a message in the <a href="http://www.4-14.org.uk/sermon-browser#comments">SermonBrowser comments</a> explaining your problem. SermonBrowser could probably be modified to provide a caching mechanism to reduce the likelihood of this error occurring, if there is demand.</p> 
     950        <h4 id="icons">How can I change the file icons that Sermon Browser uses, or add new icons?</h4> 
     951        <p>You'll need to edit the <b>filetypes.php</b> file that comes with Sermon Browser. The icon is chosen on the basis of the file extension (or in the case of URLs the file extension then the site address). If you do create new icons for other filetypes, consider sending them to the author so they can be included in future versions of the plugin.</p> 
     952        <h3 id="templatetags">Template tags</h3> 
     953        <p>If you want to change the output of Sermon Browser, you'll need to edit the templates. You'll need to understand the basics of HTML and CSS, and to know the special SermonBrowser template tags. There are two templates, one (called "results page") is used to produce the search results on the main sermons page. The other template (called sermon page) is used to produce the page for single sermon. Most tags can be used in both templates, but some are specific.</p> 
     954        <h4>Results page only</h4> 
     955        <ul> 
     956            <li><b>[filters_form]</b> - The search form which allows filtering by preacher, series, date, etc. <i>multi-sermons page only</i></li> 
     957            <li><b>[sermons_count]</b> - The number of sermons which match the current search critera. </li> 
     958            <li><b>[sermons_loop][/sermons_loop]</b> - These two tags should be placed around the output for one sermon. (That is all of the tags that return data about sermons should come between these two tags.)</li> 
     959            <li><b>[first_passage]</b> - The main bible passage for this sermon</li> 
     960            <li><b>[previous_page]</b> - Displays the link to the previous page of search results (if needed)</li> 
     961            <li><b>[next_page]</b> - Displays the link to the next page of search results (if needed)</li> 
     962            <li><b>[podcast]</b> - Link to the podcast of all sermons</li> 
     963            <li><b>[podcast_for_search]</b> - Link to the podcast of sermons that match the current search</li> 
     964            <li><b>[podcasticon]</b> - Displays the icon used for the main podcast</li> 
     965            <li><b>[podcasticon_for_search]</b> - Displays the icon used for the custom podcast</li> 
     966        </ul> 
     967        <h4>Both results page and sermon page</h4> 
     968        <ul> 
     969            <li><b>[sermon_title]</b> - The title of the sermon</li> 
     970            <li><b>[preacher_link]</b> - The name of the preacher (hyperlinked to his search results)</li> 
     971            <li><b>[series_link]</b> - The name of the series (hyperlinked to search results)</li> 
     972            <li><b>[service_link]</b> - The name of the service (hyperlinked to search results)</li> 
     973            <li><b>[date]</b> - The date of the sermon</li> 
     974            <li><b>[files_loop][/files_loop]</b> - These two tags should be placed around the [file] tag if you want to display all the files linked with to sermon. They are not needed if you only want to display the first file.</li> 
     975            <li><b>[file]</b> - Displays the files and external URLs</li> 
     976            <li><b>[embed_loop][/embed_loop]</b> - These two tags should be placed around the [embed] tag if you want to display all the embedded objects linked to this sermon. They are not needed if you only want to display the first embedded object.</li> 
     977            <li><b>[embed]</b> - Displays an embedded object (e.g. video)</li> 
     978            <li><b>[creditlink]</b> - displays a "Powered by Sermon Browser" link.</li> 
     979        </ul> 
     980        <h4>Sermon page only</h4> 
     981        <ul> 
     982            <li><b>[preacher_description]</b> - The description of the preacher.</li> 
     983            <li><b>[preacher_image]</b> - The photo of the preacher.</li> 
     984            <li><b>[passages_loop][/passages_loop]</b> - These two tags should be placed around the [passage] tag if you want to display all the passages linked with to sermon.</li> 
     985            <li><b>[passage]</b> - Displays the reference of the bible passage with the book name hyperlinked to search results.</li> 
     986            <li><b>[next_sermon]</b> - Displays a link to the next sermon preached (excluding ones preached on the same day)</li> 
     987            <li><b>[prev_sermon]</b> - Displays a link to the previous sermon preached</li> 
     988            <li><b>[sameday_sermon]</b> - Displays a link to other sermons preached on that day</li> 
     989            <li><b>[tags]</b> - Displays the tags for that sermons</li> 
     990            <li><b>[esvtext]</b> - Displays the full text of the ESV Bible for all passages linked to that sermon.</li> 
     991            <li><b>[biblepassage]</b> - Displays the reference of the bible passages for that sermon. Useful for utilising other bible plugins (see <a href="#otherversions">FAQ</a>).</li> 
    568992    </div> 
    569993    </form> 
     
    571995} 
    572996 
     997 
     998function bb_manage_preachers() { 
     999    global $wpdb, $sermon_domain; 
     1000    global $wordpressRealPath; 
     1001     
     1002    $url = get_bloginfo('wpurl'); 
     1003     
     1004    if ($_GET['saved']) { 
     1005        echo '<div id="message" class="updated fade"><p><b>'.__('Preacher saved to database.', $sermon_domain).'</b></div>'; 
     1006    } 
     1007     
     1008    if ($_POST['save']) { 
     1009        $name = mysql_real_escape_string($_POST['name']); 
     1010        $description = mysql_real_escape_string($_POST['description']); 
     1011         
     1012        $pid = (int) $_REQUEST['pid']; 
     1013         
     1014        if (empty($_FILES['upload']['name'])) { 
     1015            $p = $wpdb->get_row("SELECT image FROM {$wpdb->prefix}sb_preachers WHERE id = $pid"); 
     1016            $filename = $p->image; 
     1017        } elseif ($_FILES['upload']['error'] == UPLOAD_ERR_OK) { 
     1018            $filename = basename($_FILES['upload']['name']); 
     1019            $prefix = ''; 
     1020            $dest = $wordpressRealPath.'/wp-content/plugins/sermonbrowser/preachers/'.$filename; 
     1021            if (move_uploaded_file($_FILES['upload']['tmp_name'], $dest)) { 
     1022                $filename = $prefix.mysql_real_escape_string($filename); 
     1023            } 
     1024        } 
     1025         
     1026        if ($pid == 0) { 
     1027            $wpdb->query("INSERT INTO {$wpdb->prefix}sb_preachers VALUES (null, '$name', '$description', '$filename')"); 
     1028        } else { 
     1029            $wpdb->query("UPDATE {$wpdb->prefix}sb_preachers SET name = '$name', description = '$description', image = '$filename' WHERE id = $pid"); 
     1030            if ($_POST['old'] != $filename || isset($_POST['remove'])) { 
     1031                @unlink($wordpressRealPath.'/wp-content/plugins/sermonbrowser/preachers/'.mysql_real_escape_string($_POST['old'])); 
     1032            }            
     1033        } 
     1034        echo "<script>document.location = '$url/wp-admin/admin.php?page=sermonbrowser/preachers.php&saved=true';</script>"; 
     1035    } 
     1036     
     1037    if ($_GET['act'] == 'kill') { 
     1038        $die = (int) $_GET['pid']; 
     1039        if($wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}sb_sermons WHERE preacher_id = $die") > 0){ 
     1040            echo '<div id="message" class="updated fade"><p><b>'.__('You can\'t delete this preacher.', $sermon_domain).'</b></div>'; 
     1041        }else { 
     1042            $p = $wpdb->get_row("SELECT image FROM {$wpdb->prefix}sb_preachers WHERE id = $die"); 
     1043            @unlink($wordpressRealPath.'/wp-content/plugins/sermonbrowser/preachers/'.$p->image); 
     1044            $wpdb->query("DELETE FROM {$wpdb->prefix}sb_preachers WHERE id = $die"); 
     1045        } 
     1046    }    
     1047     
     1048    if ($_GET['act'] == 'new' || $_GET['act'] == 'edit') { 
     1049        if ($_GET['act'] == 'edit') $preacher = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}sb_preachers WHERE id = ".(int) $_GET['pid']); 
     1050?> 
     1051    <div class="wrap"> 
     1052        <h2><?php echo $_GET['act'] == 'new' ? __('Add', $sermon_domain) : __('Edit', $sermon_domain) ?> <?php _e('preacher', $sermon_domain) ?></h2> 
     1053        <form method="post" enctype="multipart/form-data"> 
     1054        <input type="hidden" name="pid" value="<?php echo (int) $_GET['pid'] ?>"> 
     1055        <fieldset> 
     1056            <table class="widefat"> 
     1057                <tr>                     
     1058                    <td> 
     1059                        <strong><?php _e('Name', $sermon_domain) ?></strong> 
     1060                        <div>                            
     1061                            <input type="text" value="<?php echo stripslashes($preacher->name) ?>" name="name" size="60" style="width:400px;" /> 
     1062                        </div> 
     1063                    </td>        
     1064                </tr> 
     1065                <tr> 
     1066                    <td> 
     1067                        <strong><?php _e('Description', $sermon_domain) ?></strong> 
     1068                        <div> 
     1069                            <textarea name="description" cols="100" rows="5"><?php echo stripslashes($preacher->description) ?></textarea> 
     1070                        </div> 
     1071                    </td> 
     1072                </tr> 
     1073                <tr> 
     1074                    <td> 
     1075                        <?php if ($_GET['act'] == 'edit'): ?> 
     1076                        <div><img src="<?php echo $url ?>/wp-content/plugins/sermonbrowser/preachers/<?php echo $preacher->image ?>"></div> 
     1077                        <input type="hidden" name="old" value="<?php echo $preacher->image ?>"> 
     1078                        <?php endif ?> 
     1079                        <strong><?php _e('Image', $sermon_domain) ?></strong> 
     1080                        <div> 
     1081                            <input type="file" name="upload"> 
     1082                            <label>Remove image&nbsp;<input type="checkbox" name="remove" value="true"></label> 
     1083                        </div> 
     1084                    </td> 
     1085                </tr> 
     1086            </table> 
     1087        </fieldset> 
     1088        <p class="submit"><input type="submit" name="save" value="<?php _e('Save', $sermon_domain) ?> &raquo;" /></p>  
     1089        </form> 
     1090    </div> 
     1091<? 
     1092        return; 
     1093    } 
     1094     
     1095    $preachers = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_preachers ORDER BY name asc"); 
     1096?> 
     1097    <div class="wrap"> 
     1098        <h2><?php _e('Manage Preachers', $sermon_domain) ?> (<a href="<?php echo $url ?>/wp-admin/admin.php?page=sermonbrowser/preachers.php&act=new"><?php _e('add new', $sermon_domain) ?></a>)</h2> 
     1099        <table class="widefat"> 
     1100            <thead> 
     1101            <tr> 
     1102                <th scope="col"><div style="text-align:center"><?php _e('ID', $sermon_domain) ?></div></th> 
     1103                <th scope="col"><div style="text-align:center"><?php _e('Name', $sermon_domain) ?></div></th>                
     1104                <th scope="col"><div style="text-align:center"><?php _e('Image', $sermon_domain) ?></div></th>               
     1105                <th scope="col"><div style="text-align:center"><?php _e('Actions', $sermon_domain) ?></div></th> 
     1106            </tr> 
     1107            </thead> 
     1108            <tbody> 
     1109                <?php foreach ((array) $preachers as $preacher): ?> 
     1110                    <tr class="<?php echo (++$i % 2 == 0) ? 'alternate' : '' ?>"> 
     1111                        <td><?php echo $preacher->id ?></td> 
     1112                        <td><?php echo stripslashes($preacher->name) ?></td> 
     1113                        <td><img src="<?php echo empty($preacher->image) ? '' : $url.'/wp-content/plugins/sermonbrowser/preachers/'.$preacher->image ?>"></td> 
     1114                        <td align="center"> 
     1115                            <a href="<?php echo $url ?>/wp-admin/admin.php?page=sermonbrowser/preachers.php&act=edit&pid=<?php echo $preacher->id ?>"><?php _e('Edit', $sermon_domain) ?></a> | <a onclick="return confirm('Are you sure?')" href="<?php echo $url ?>/wp-admin/admin.php?page=sermonbrowser/preachers.php&act=kill&pid=<?php echo $preacher->id ?>"><?php _e('Delete', $sermon_domain) ?></a> 
     1116                        </td> 
     1117                    </tr> 
     1118                <?php endforeach ?> 
     1119            </tbody> 
     1120        </table> 
     1121    </div> 
     1122<?php 
     1123} 
     1124 
     1125// manage <strike>preachers</strike>, services & series 
     1126// lots of ajaxy stuff 
    5731127function bb_manage_everything() { 
    5741128    global $wpdb, $sermon_domain; 
     
    5761130    $url = get_bloginfo('wpurl'); 
    5771131     
    578     $preachers = $wpdb->get_results("SELECT p.*, m.id AS mid FROM {$wpdb->prefix}sb_preachers AS p LEFT OUTER JOIN {$wpdb->prefix}sb_sermons AS m ON p.id = m.preacher_id ORDER BY p.name asc"); 
    5791132    $series = $wpdb->get_results("SELECT ss.*, m.id AS mid FROM {$wpdb->prefix}sb_series AS ss LEFT OUTER JOIN {$wpdb->prefix}sb_sermons AS m ON ss.id = m.series_id ORDER BY ss.name asc");     
    5801133    $services = $wpdb->get_results("SELECT s.*, m.id AS mid FROM {$wpdb->prefix}sb_services AS s LEFT OUTER JOIN {$wpdb->prefix}sb_sermons AS m ON s.id = m.service_id ORDER BY s.name asc"); 
    5811134     
    5821135    $toManage = array( 
    583         'Preachers' => array('data' => $preachers), 
    5841136        'Series' => array('data' => $series), 
    5851137        'Services' => array('data' => $services), 
     
    6141166                } 
    6151167            }); 
    616         } 
    617         function createNewPreachers(s) { 
    618             var p = prompt("New preacher's name?", "Preacher's name"); 
    619             if (p != null) { 
    620                 jQuery.post('<?php echo $url ?>/wp-admin/admin.php?page=sermonbrowser/sermon.php', {pname: p, sermon: 1}, function(r) { 
    621                     if (r) { 
    622                         jQuery('#Preachers-list').append('\ 
    623                             <tr style="display:none" class="Preachers" id="rowPreachers' + r + '">\ 
    624                                 <th style="text-align:center" scope="row">' + r + '</th>\ 
    625                                 <td id="Preachers' + r + '">' + p + '</td>\ 
    626                                 <td style="text-align:center">\ 
    627                                     <a id="linkPreachers' + r + '" href="javascript:renamePreachers(' + r + ', \'' + p + '\')">Rename</a> | <a onclick="return confirm(\'Are you sure?\');" href="javascript:deletePreachers(' + r + ')">Delete</a>\ 
    628                                 </td>\ 
    629                             </tr>\ 
    630                         '); 
    631                         jQuery('#rowPreachers' + r).fadeIn(function() { 
    632                             updateClass('Preachers'); 
    633                         }); 
    634                     }; 
    635                 });  
    636             } 
    637         } 
     1168        }        
    6381169        function createNewServices(s) { 
    6391170            var s = 'lol'; 
     
    6851216            } 
    6861217        } 
    687         function deletePreachers(id) { 
    688             jQuery.post('<?php echo $url ?>/wp-admin/admin.php?page=sermonbrowser/sermon.php', {pname: 'dummy', pid: id, del: 1, sermon: 1}, function(r) { 
    689                 if (r) { 
    690                     jQuery('#rowPreachers' + id).fadeOut(function() { 
    691                         updateClass('Preachers'); 
    692                     }); 
    693                 }; 
    694             }); 
    695         } 
    6961218        function deleteSeries(id) { 
    6971219            jQuery.post('<?php echo $url ?>/wp-admin/admin.php?page=sermonbrowser/sermon.php', {ssname: 'dummy', ssid: id, del: 1, sermon: 1}, function(r) { 
     
    7111233                }; 
    7121234            });          
    713         } 
    714         function renamePreachers(id, old) { 
    715             var p = prompt("New preacher's name?", old); 
    716             if (p != null) { 
    717                 jQuery.post('<?php echo $url ?>/wp-admin/admin.php?page=sermonbrowser/sermon.php', {pid: id, pname: p, sermon: 1}, function(r) { 
    718                     if (r) { 
    719                         jQuery('#Preachers' + id).text(p); 
    720                         jQuery('#linkPreachers' + id).attr('href', 'javascript:renamePreachers(' + id + ', "' + p + '")'); 
    721                         Fat.fade_element('Preachers' + id); 
    722                     }; 
    723                 });  
    724             } 
    7251235        } 
    7261236        function renameSeries(id, old) { 
     
    7391249            var s = 'lol'; 
    7401250            while ((s.indexOf('@') == -1) || (s.match(/(.*?)@(.*)/)[2].match(/[0-9]{1,2}:[0-9]{1,2}/) == null)) { 
    741                 s = prompt("New service's name - default time?", "Service's name @ 18:00");                              
     1251                s = prompt("New service's name - default time?", old);                               
    7421252                if (s == null) { break; } 
    7431253            } 
     
    7601270    <a name="top"></a> 
    7611271    <div id="supersub"> 
    762         <a href="#manage-Preachers"><?php _e('Manage Preachers', $sermon_domain) ?></a> 
    7631272        <a href="#manage-Series"><?php _e('Manage Series', $sermon_domain) ?></a> 
    7641273        <a href="#manage-Services"><?php _e('Manage Services', $sermon_domain) ?></a> 
     
    7741283        <table class="widefat"> 
    7751284            <thead> 
     1285            <tr> 
    7761286                <th scope="col"><div style="text-align:center"><?php _e('ID', $sermon_domain) ?></div></th> 
    7771287                <th scope="col"><div style="text-align:center"><?php _e('Name', $sermon_domain) ?></div></th> 
    7781288                <?php echo $k == 'Services' ? '<th scope="col"><div style="text-align:center">'.__('Default time', $sermon_domain).'</div></th>' : '' ?> 
    7791289                <th scope="col"><div style="text-align:center"><?php _e('Actions', $sermon_domain) ?></div></th> 
     1290            </tr> 
    7801291            </thead>     
    7811292            <tbody id="<?php echo $k ?>-list"> 
     
    8151326} 
    8161327 
     1328// upload page 
    8171329function bb_uploads() { 
    8181330    global $wpdb, $filetypes, $sermon_domain; 
    8191331    global $wordpressRealPath; 
     1332    ini_set('max_input_time','300'); 
     1333    // sync 
    8201334    bb_scan_dir(); 
    8211335     
     
    8271341            $prefix = ''; 
    8281342            $dest = $wordpressRealPath.get_option('sb_sermon_upload_dir').$prefix.$filename; 
    829             if (move_uploaded_file($_FILES['upload']['tmp_name'], $dest)) { 
    830                 $filename = $prefix.mysql_real_escape_string($filename); 
    831                 $query = "INSERT INTO {$wpdb->prefix}sb_sermon_files VALUES (null, '$filename', 0);"; 
    832                 $wpdb->query($query); 
     1343            if($wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}sb_stuff WHERE name = '$filename'") == 0) { 
     1344                if (move_uploaded_file($_FILES['upload']['tmp_name'], $dest)) { 
     1345                    $filename = $prefix.mysql_real_escape_string($filename); 
     1346                    $query = "INSERT INTO {$wpdb->prefix}sb_stuff VALUES (null, 'file', '$filename', 0);"; 
     1347                    $wpdb->query($query); 
     1348                    echo '<div id="message" class="updated fade"><p><b>'.__('Files saved to database.', $sermon_domain).'</b></div>'; 
     1349                } 
     1350            } else { 
     1351                echo '<div id="message" class="updated fade"><p><b>'.__($filename. ' has already existed.', $sermon_domain).'</b></div>'; 
    8331352            } 
    8341353        } 
    835         echo '<div id="message" class="updated fade"><p><b>'.__('Files saved to database.', $sermon_domain).'</b></div>'; 
    8361354    }    
    8371355     
    838     $unlinked = $wpdb->get_results("SELECT f.*, s.title FROM {$wpdb->prefix}sb_sermon_files AS f LEFT JOIN {$wpdb->prefix}sb_sermons AS s ON f.sermon_id = s.id WHERE f.sermon_id = 0 ORDER BY f.name LIMIT 0, 15;"); 
    839     $linked = $wpdb->get_results("SELECT f.*, s.title FROM {$wpdb->prefix}sb_sermon_files AS f LEFT JOIN {$wpdb->prefix}sb_sermons AS s ON f.sermon_id = s.id WHERE f.sermon_id <> 0 ORDER BY f.name LIMIT 0, 15;"); 
    840      
    841     $cntu = $wpdb->get_row("SELECT COUNT(*) as cntu FROM {$wpdb->prefix}sb_sermon_files WHERE sermon_id = 0", ARRAY_A); 
     1356    $unlinked = $wpdb->get_results("SELECT f.*, s.title FROM {$wpdb->prefix}sb_stuff AS f LEFT JOIN {$wpdb->prefix}sb_sermons AS s ON f.sermon_id = s.id WHERE f.sermon_id = 0 AND f.type = 'file' ORDER BY f.name LIMIT 0, 15;"); 
     1357    $linked = $wpdb->get_results("SELECT f.*, s.title FROM {$wpdb->prefix}sb_stuff AS f LEFT JOIN {$wpdb->prefix}sb_sermons AS s ON f.sermon_id = s.id WHERE f.sermon_id <> 0 AND f.type = 'file' ORDER BY f.name LIMIT 0, 15;"); 
     1358     
     1359    if($_POST['clean']) { 
     1360        // sync (but different from last time) 
     1361        $wanted = array(-1); 
     1362     
     1363        foreach ((array) $unlinked as $k => $file) { 
     1364            if (!file_exists($wordpressRealPath.get_option('sb_sermon_upload_dir').$file->name)) { 
     1365                $wanted[] = $file->id; 
     1366                unset($unlinked[$k]); 
     1367            } 
     1368        } 
     1369     
     1370        foreach ((array) $linked as $k => $file) {       
     1371            if (!file_exists($wordpressRealPath.get_option('sb_sermon_upload_dir').$file->name)) {           
     1372                $wanted[] = $file->id; 
     1373                unset($unlinked[$k]); 
     1374            } 
     1375        } 
     1376     
     1377        $wpdb->query("DELETE FROM {$wpdb->prefix}sb_stuff WHERE id IN (".implode(', ', (array) $wanted).")"); 
     1378    } 
     1379     
     1380    $cntu = $wpdb->get_row("SELECT COUNT(*) as cntu FROM {$wpdb->prefix}sb_stuff WHERE sermon_id = 0 AND type = 'file' ", ARRAY_A); 
    8421381    $cntu = $cntu['cntu'];       
    843     $cntl = $wpdb->get_row("SELECT COUNT(*) as cnt1 FROM {$wpdb->prefix}sb_sermon_files WHERE sermon_id <> 0", ARRAY_A); 
    844     $cntl = $cntl['cnt1'];       
     1382    $cntl = $wpdb->get_row("SELECT COUNT(*) as cntl FROM {$wpdb->prefix}sb_stuff WHERE sermon_id <> 0 AND type = 'file' ", ARRAY_A); 
     1383    $cntl = $cntl['cntl'];       
    8451384?> 
    8461385    <style> 
     
    9671506        <table class="widefat"> 
    9681507            <thead> 
     1508                <tr> 
    9691509                <th scope="col"><div style="text-align:center"><?php _e('ID', $sermon_domain) ?></div></th> 
    9701510                <th scope="col"><div style="text-align:center"><?php _e('File name', $sermon_domain) ?></div></th> 
    9711511                <th scope="col"><div style="text-align:center"><?php _e('File type', $sermon_domain) ?></div></th> 
    9721512                <th scope="col"><div style="text-align:center"><?php _e('Actions', $sermon_domain) ?></div></th> 
     1513                </tr> 
    9731514            </thead>     
    9741515            <tbody id="the-list-u"> 
     
    9761517                    <?php foreach ($unlinked as $file): ?>                               
    9771518                        <tr class="file <?php echo (++$i % 2 == 0) ? 'alternate' : '' ?>" id="file<?php echo $file->id ?>"> 
    978                             <th style="text-align:center" scope="row"><?php echo $file->id ?></th> 
    979                             <td id="<?php echo $file->id ?>"><?php echo substr($file->name, 0, strrpos($file->name, '.')) ?></td> 
    980                             <td style="text-align:center"><?php echo isset($filetypes[substr($file->name, strrpos($file->name, '.') + 1)]['name']) ? $filetypes[substr($file->name, strrpos($file->name, '.') + 1)]['name'] : strtoupper(substr($file->name, strrpos($file->name, '.') + 1)) ?></td> 
    981                             <td style="text-align:center"> 
     1519                            <th width="10%" style="text-align:center" scope="row"><?php echo $file->id ?></th> 
     1520                            <td width="50%" id="<?php echo $file->id ?>"><?php echo substr($file->name, 0, strrpos($file->name, '.')) ?></td> 
     1521                            <td width="20%" style="text-align:center"><?php echo isset($filetypes[substr($file->name, strrpos($file->name, '.') + 1)]['name']) ? $filetypes[substr($file->name, strrpos($file->name, '.') + 1)]['name'] : strtoupper(substr($file->name, strrpos($file->name, '.') + 1)) ?></td> 
     1522                            <td width="20%" style="text-align:center"> 
    9821523                                <?php if (is_writable($wordpressRealPath.get_option('sb_sermon_upload_dir').$file->name)): ?> 
    9831524                                <a id="link<?php echo $file->id ?>" href="javascript:rename(<?php echo $file->id ?>, '<?php echo $file->name ?>')"><?php _e('Rename', $sermon_domain) ?></a> | <a onclick="return confirm('Do you really want to delete <?php echo str_replace("'", '', $file->name) ?>?');" href="javascript:kill(<?php echo $file->id ?>, '<?php echo $file->name ?>');"><?php _e('Delete', $sermon_domain) ?></a>  
     
    10011542        <table class="widefat"> 
    10021543            <thead> 
     1544            <tr> 
    10031545                <th scope="col"><div style="text-align:center"><?php _e('ID', $sermon_domain) ?></div></th> 
    10041546                <th scope="col"><div style="text-align:center"><?php _e('File name', $sermon_domain) ?></div></th> 
     
    10061548                <th scope="col"><div style="text-align:center"><?php _e('Sermon', $sermon_domain) ?></div></th> 
    10071549                <th scope="col"><div style="text-align:center"><?php _e('Actions', $sermon_domain) ?></div></th> 
     1550            </tr> 
    10081551            </thead>     
    10091552            <tbody id="the-list-l"> 
     
    10141557                            <td id="<?php echo $file->id ?>"><?php echo substr($file->name, 0, strrpos($file->name, '.')) ?></td> 
    10151558                            <td style="text-align:center"><?php echo isset($filetypes[substr($file->name, strrpos($file->name, '.') + 1)]['name']) ? $filetypes[substr($file->name, strrpos($file->name, '.') + 1)]['name'] : strtoupper(substr($file->name, strrpos($file->name, '.') + 1)) ?></td> 
    1016                             <td><?php echo $file->title ?></td> 
     1559                            <td><?php echo stripslashes($file->title) ?></td> 
    10171560                            <td style="text-align:center"> 
    10181561                            <script type="text/javascript" language="javascript"> 
     
    10741617            <?php endif ?> 
    10751618            </table> 
    1076             <p class="submit"><input type="submit" name="save" value="<?php _e('Upload', $sermon_domain) ?> &raquo;" /></p>  
     1619            <p class="submit"><input type="submit" name="save" value="<?php _e('Upload', $sermon_domain) ?> &raquo;" />&nbsp;<input type="submit" name="clean" value="<?php _e('Clean up', $sermon_domain) ?>" /></p>  
    10771620        </form> 
    10781621        <?php 
     
    10971640        <table class="widefat"> 
    10981641            <thead> 
     1642            <tr> 
    10991643                <th scope="col"><div style="text-align:center"><?php _e('ID', $sermon_domain) ?></div></th> 
    11001644                <th scope="col"><div style="text-align:center"><?php _e('File name', $sermon_domain) ?></div></th> 
     
    11021646                <th scope="col"><div style="text-align:center"><?php _e('Sermon', $sermon_domain) ?></div></th> 
    11031647                <th scope="col"><div style="text-align:center"><?php _e('Actions', $sermon_domain) ?></div></th> 
     1648            </tr> 
    11041649            </thead>     
    11051650            <tbody id="the-list-s">  
     
    11221667} 
    11231668 
     1669// manage sermon of coz 
    11241670function bb_manage_sermons() { 
    11251671    global $wpdb, $sermon_domain; 
     
    11341680        $mid = (int) $_GET['mid']; 
    11351681        $wpdb->query("DELETE FROM {$wpdb->prefix}sb_sermons WHERE id = $mid;"); 
     1682        $wpdb->query("DELETE FROM {$wpdb->prefix}sb_sermons_tags WHERE sermon_id = $mid;"); 
     1683        $wpdb->query("DELETE FROM {$wpdb->prefix}sb_books_sermons WHERE sermon_id = $mid;"); 
     1684        $wpdb->query("UPDATE {$wpdb->prefix}sb_stuff SET sermon_id = 0 WHERE sermon_id = $mid AND type = 'file';"); 
     1685        $wpdb->query("DELETE FROM {$wpdb->prefix}sb_stuff WHERE sermon_id = $mid AND type <> 'file';"); 
    11361686        echo '<div id="message" class="updated fade"><p><b>'.__('Sermon removed from database.', $sermon_domain).'</b></div>'; 
    11371687    } 
     
    11401690    $cnt = $cnt['COUNT(*)'];         
    11411691             
    1142     $sermons = $wpdb->get_results("SELECT m.id, m.title, m.date, p.name as pname, s.name as sname, ss.name as ssname FROM {$wpdb->prefix}sb_sermons as m, {$wpdb->prefix}sb_preachers as p, {$wpdb->prefix}sb_services as s, {$wpdb->prefix}sb_series as ss where (m.preacher_id = p.id and m.service_id = s.id and m.series_id = ss.id) ORDER BY m.date desc LIMIT 0, 15;");    
     1692    $sermons = $wpdb->get_results("SELECT m.id, m.title, m.date, p.name as pname, s.name as sname, ss.name as ssname FROM {$wpdb->prefix}sb_sermons as m, {$wpdb->prefix}sb_preachers as p, {$wpdb->prefix}sb_services as s, {$wpdb->prefix}sb_series as ss where (m.preacher_id = p.id and m.service_id = s.id and m.series_id = ss.id) ORDER BY m.date desc, s.time desc LIMIT 0, 15;");   
    11431693    $preachers = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_preachers ORDER BY name;");     
    11441694    $series = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_series ORDER BY name;"); 
     
    11981748        <table class="widefat"> 
    11991749            <thead> 
     1750            <tr> 
    12001751                <th scope="col"><div style="text-align:center"><?php _e('ID', $sermon_domain) ?></div></th> 
    12011752                <th scope="col"><div style="text-align:center"><?php _e('Title', $sermon_domain) ?></div></th> 
     
    12051756                <th scope="col"><div style="text-align:center"><?php _e('Series', $sermon_domain) ?></div></th> 
    12061757                <th scope="col"><div style="text-align:center"><?php _e('Actions', $sermon_domain) ?></div></th> 
     1758            </tr> 
    12071759            </thead>     
    12081760            <tbody id="the-list"> 
     
    12111763                    <tr class="<?php echo ++$i % 2 == 0 ? 'alternate' : '' ?>"> 
    12121764                        <th style="text-align:center" scope="row"><?php echo $sermon->id ?></th> 
    1213                         <td><?php echo $sermon->title ?></td> 
    1214                         <td><?php echo $sermon->pname ?></td> 
     1765                        <td><?php echo stripslashes($sermon->title) ?></td> 
     1766                        <td><?php echo stripslashes($sermon->pname) ?></td> 
    12151767                        <td><?php echo $sermon->date ?></td> 
    1216                         <td><?php echo $sermon->sname ?></td> 
    1217                         <td><?php echo $sermon->ssname ?></td> 
     1768                        <td><?php echo stripslashes($sermon->sname) ?></td> 
     1769                        <td><?php echo stripslashes($sermon->ssname) ?></td> 
    12181770                        <td style="text-align:center"> 
    12191771                            <a href="<?php echo $url ?>/wp-admin/admin.php?page=sermonbrowser/new_sermon.php&mid=<?php echo $sermon->id ?>"><?php _e('Edit', $sermon_domain) ?></a> | <a onclick="return confirm('Are you sure?')" href="<?php echo $url ?>/wp-admin/admin.php?page=sermonbrowser/sermon.php&mid=<?php echo $sermon->id ?>"><?php _e('Delete', $sermon_domain) ?></a> 
     
    12371789} 
    12381790 
     1791// new sermon 
     1792// where everything is put together 
    12391793function bb_new_sermon() { 
    12401794    global $wpdb, $books, $sermon_domain; 
    12411795    global $wordpressRealPath; 
     1796    $error = false; 
     1797    // sync 
    12421798    bb_scan_dir(); 
    12431799     
     
    12451801 
    12461802    if ($_POST['save'] && $_POST['title']) {         
     1803        // prepare 
    12471804        $title = mysql_real_escape_string($_POST['title']); 
    12481805        $preacher_id = (int) $_POST['preacher']; 
     
    12521809        for ($foo = 0; $foo < count($_POST['start']); $foo++) {  
    12531810            if (!empty($_POST['start']['chapter'][$foo]) && !empty($_POST['end']['chapter'][$foo]) && !empty($_POST['start']['verse'][$foo]) && !empty($_POST['end']['verse'][$foo])) { 
    1254                 $start[] = array( 
     1811                $startz[] = array( 
    12551812                    'book' => $_POST['start']['book'][$foo], 
    12561813                    'chapter' => $_POST['start']['chapter'][$foo], 
    12571814                    'verse' => $_POST['start']['verse'][$foo],                   
    12581815                ); 
    1259                 $end[] = array( 
     1816                $endz[] = array( 
    12601817                    'book' => $_POST['end']['book'][$foo], 
    12611818                    'chapter' => $_POST['end']['chapter'][$foo], 
     
    12641821            } 
    12651822        } 
    1266         $start = mysql_real_escape_string(serialize($start)); 
    1267         $end = mysql_real_escape_string(serialize($end)); 
     1823        $start = mysql_real_escape_string(serialize($startz)); 
     1824        $end = mysql_real_escape_string(serialize($endz)); 
    12681825        $date = date('Y-m-d', strtotime($_POST['date'])); 
    12691826        $description = mysql_real_escape_string(strip_tags($_POST['description'])); 
    12701827        $override = $_POST['override'] == 'on' ? 1 : 0; 
    1271         if (!$_GET['mid']) { 
     1828        // edit or not edit 
     1829        if (!$_GET['mid']) { // new 
    12721830            $query1 = "INSERT INTO {$wpdb->prefix}sb_sermons VALUES (null, '$title', '$preacher_id', '$date', '$service_id', '$series_id', '$start', '$end', '$description', '$time', '$override')"; 
    12731831            $wpdb->query($query1);               
    12741832            $id = $wpdb->insert_id;              
    1275         } else { 
     1833        } else { // edit 
    12761834            $mid = (int) $_GET['mid']; 
    12771835            $query1 = "UPDATE {$wpdb->prefix}sb_sermons SET title = '$title', preacher_id = '$preacher_id', date = '$date', series_id = '$series_id', start = '$start', end = '$end', description = '$description', time = '$time', service_id = '$service_id', override = '$override' WHERE id = $mid;"; 
    12781836            $wpdb->query($query1); 
    1279             $queryz = "UPDATE {$wpdb->prefix}sb_sermon_files SET sermon_id = 0 WHERE sermon_id = $mid;"; 
     1837            $queryz = "UPDATE {$wpdb->prefix}sb_stuff SET sermon_id = 0 WHERE sermon_id = $mid AND type = 'file' ;"; 
    12801838            $wpdb->query($queryz); 
     1839            $queryz2 = "DELETE FROM {$wpdb->prefix}sb_stuff WHERE sermon_id = $mid AND type <> 'file'; "; 
     1840            $wpdb->query($queryz2); 
    12811841            $id = $mid; 
    1282         }        
     1842        }    
     1843        // deal with books 
     1844        $wpdb->query("DELETE FROM {$wpdb->prefix}sb_books_sermons WHERE sermon_id = $id;");  
     1845        foreach ($startz as $i => $st) { 
     1846            $wpdb->query("INSERT INTO {$wpdb->prefix}sb_books_sermons VALUES(null, '{$st['book']}', '{$st['chapter']}', '{$st['verse']}', $i, 'start', $id);"); 
     1847        } 
     1848        foreach ($endz as $i => $ed) { 
     1849            $wpdb->query("INSERT INTO {$wpdb->prefix}sb_books_sermons VALUES(null, '{$ed['book']}', '{$ed['chapter']}', '{$ed['verse']}', $i, 'end', $id);"); 
     1850        } 
     1851        // now files 
    12831852        foreach ($_POST['file'] as $uid => $file) { 
    12841853            if ($_FILES['upload']['error'][$uid] == UPLOAD_ERR_OK) { 
     
    12861855                $prefix = ''; 
    12871856                $dest = $wordpressRealPath.get_option('sb_sermon_upload_dir').$prefix.$filename; 
    1288                 if (move_uploaded_file($_FILES['upload']['tmp_name'][$uid], $dest)) { 
     1857                if ($wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}sb_stuff WHERE name = '$filename'") == 0 && move_uploaded_file($_FILES['upload']['tmp_name'][$uid], $dest)) { 
    12891858                    $filename = $prefix.mysql_real_escape_string($filename); 
    1290                     $queryz = "INSERT INTO {$wpdb->prefix}sb_sermon_files VALUES (null, '$filename', 0);"; 
    1291                     $wpdb->query($queryz); 
    1292                     $file = $wpdb->insert_id;                
    1293                     $query2 = "UPDATE {$wpdb->prefix}sb_sermon_files SET sermon_id = $id WHERE id = $file;"; 
    1294                     $wpdb->query($query2);                           
     1859                    $queryz = "INSERT INTO {$wpdb->prefix}sb_stuff VALUES (null, 'file', '$filename', $id);"; 
     1860                    $wpdb->query($queryz);                   
     1861                } else { 
     1862                    echo '<div id="message" class="updated fade"><p><b>'.__($filename. ' has already existed.', $sermon_domain).'</b></div>'; 
     1863                    $error = true; 
    12951864                } 
    12961865            } elseif ($file != 0) { 
    1297                 $wpdb->query("UPDATE {$wpdb->prefix}sb_sermon_files SET sermon_id = $id WHERE id = $file;"); 
     1866                $wpdb->query("UPDATE {$wpdb->prefix}sb_stuff SET sermon_id = $id WHERE id = $file;"); 
    12981867            }                
    12991868        } 
    1300         echo "<script>document.location = '$url/wp-admin/admin.php?page=sermonbrowser/sermon.php&saved=true';</script>"; 
     1869        // then URLs 
     1870        foreach ((array) $_POST['url'] as $urlz) { 
     1871            if (!empty($urlz)) { 
     1872                $urlz = mysql_real_escape_string($urlz); 
     1873                $wpdb->query("INSERT INTO {$wpdb->prefix}sb_stuff VALUES(null, 'url', '$urlz', $id);"); 
     1874            }            
     1875        } 
     1876        // embed code next 
     1877        foreach ((array) $_POST['code'] as $code) { 
     1878            if (!empty($code)) { 
     1879                $code = base64_encode(stripslashes($code)); 
     1880                $wpdb->query("INSERT INTO {$wpdb->prefix}sb_stuff VALUES(null, 'code', '$code', $id);"); 
     1881            } 
     1882        } 
     1883        // tags 
     1884        $tags = explode(',', $_POST['tags']); 
     1885        $wpdb->query("DELETE FROM {$wpdb->prefix}sb_sermons_tags WHERE sermon_id = $id;"); 
     1886        foreach ($tags as $tag) { 
     1887            $clean_tag = trim(mysql_real_escape_string($tag)); 
     1888            $wpdb->query("INSERT IGNORE INTO {$wpdb->prefix}sb_tags VALUES (null, '$clean_tag')"); 
     1889            $tag_id = $wpdb->insert_id; 
     1890            $wpdb->query("INSERT INTO {$wpdb->prefix}sb_sermons_tags VALUES (null, $id, $tag_id)"); 
     1891        } 
     1892        // everything is fine, get out of here! 
     1893        if(!$error) echo "<script>document.location = '$url/wp-admin/admin.php?page=sermonbrowser/sermon.php&saved=true';</script>"; 
    13011894    }        
    13021895     
     1896    // load existing data 
    13031897    $preachers = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_preachers ORDER BY name asc"); 
    13041898    $services = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_services ORDER BY name asc"); 
    13051899    $series = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_series ORDER BY name asc"); 
    1306     $files = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_sermon_files WHERE sermon_id = 0 ORDER BY name asc"); 
    1307      
     1900    $files = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_stuff WHERE sermon_id = 0 AND type = 'file' ORDER BY name asc");    
     1901     
     1902    // sync 
     1903    $wanted[] = -1; 
     1904    foreach ((array) $files as $k => $file) { 
     1905        if (!file_exists($wordpressRealPath.get_option('sb_sermon_upload_dir').$file->name)) { 
     1906            $wanted[] = $file->id; 
     1907            unset($files[$k]); 
     1908        } 
     1909    } 
     1910    //$wpdb->query("DELETE FROM {$wpdb->prefix}sb_stuff WHERE id IN (".implode(', ', (array) $wanted).")"); 
     1911     
     1912    // these following code is for js 
    13081913    foreach ($services as $service) { 
    13091914        $serviceId[] = $service->id; 
     
    13181923        $mid = (int) $_GET['mid']; 
    13191924        $curSermon = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}sb_sermons WHERE id = $mid"); 
    1320         $files = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_sermon_files WHERE sermon_id IN (0, $mid) ORDER BY name asc"); 
     1925        $files = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_stuff WHERE sermon_id IN (0, $mid) AND type = 'file' ORDER BY name asc"); 
    13211926        $startArr = unserialize($curSermon->start); 
    13221927        $endArr = unserialize($curSermon->end); 
     1928        $rawtags = $wpdb->get_results("SELECT t.name FROM {$wpdb->prefix}sb_sermons_tags as st LEFT JOIN {$wpdb->prefix}sb_tags as t ON st.tag_id = t.id WHERE st.sermon_id = $mid ORDER BY t.name asc"); 
     1929        $tags = array(); 
     1930        foreach ($rawtags as $tag) { 
     1931            $tags[] = $tag->name; 
     1932        } 
     1933        $tags = implode(', ', (array) $tags); 
    13231934    } 
    13241935?> 
     1936    <link rel="stylesheet" href="<?php echo $url ?>/wp-content/plugins/sermonbrowser/style.css" type="text/css"> 
    13251937    <link rel="stylesheet" href="<?php echo $url ?>/wp-content/plugins/sermonbrowser/datepicker.css" type="text/css"> 
    13261938    <script type="text/javascript" src="<?php echo $url ?>/wp-includes/js/jquery/jquery.js"></script> 
    13271939    <script type="text/javascript" src="<?php echo $url ?>/wp-content/plugins/sermonbrowser/datePicker.js"></script> 
     1940    <script type="text/javascript" src="<?php echo $url ?>/wp-content/plugins/sermonbrowser/64.js"></script> 
    13281941    <script type="text/javascript">      
    13291942        var timeArr = new Array(); 
     
    13972010            });          
    13982011        }        
     2012         
    13992013        function addFile() { 
    14002014            var f = jQuery('#choosefile').clone(); 
    14012015            f.attr('id', 'choose' + gfid); 
    1402             jQuery('tr:first td:first', f).prepend('[<a href="javascript:removeFile(' + gfid++ + ')">x</a>] '); 
     2016            jQuery(".choosefile", f).attr('name', 'choose' + gfid);  
     2017            jQuery("td", f).css('display', 'none'); 
     2018            jQuery("td:first", f).css('display', ''); 
     2019            jQuery('th', f).prepend('[<a href="javascript:removeFile(' + gfid++ + ')">x</a>] '); 
    14032020            jQuery("option[@value='0']", f).attr('selected', 'selected'); 
    1404             jQuery("input[@type='file']", f).val(''); 
    1405             jQuery('.choose:last').after(f);             
     2021            jQuery("input", f).val(''); 
     2022            jQuery('.choose:last').after(f); 
     2023                     
    14062024        } 
    14072025        function removeFile(id) { 
     
    14182036        var gfid = 0; 
    14192037        var gpid = 0; 
     2038         
     2039        function chooseType(id, type){ 
     2040            jQuery("#"+id + " td").css("display", "none"); 
     2041            jQuery("#"+id + " ."+type).css("display", ""); 
     2042            jQuery("#"+id + " td input").val(''); 
     2043            jQuery("#"+id + " td select").val('0'); 
     2044        } 
    14202045    </script> 
    14212046    <div class="wrap"> 
     
    14252050            <table class="widefat"> 
    14262051                <tr> 
    1427                     <td colspan="2"> 
     2052                    <td> 
    14282053                        <strong><?php _e('Title', $sermon_domain) ?></strong> 
    14292054                        <div> 
    1430                             <input type="text" value="<?php echo $curSermon->title ?>" name="title" size="60" style="width:400px;" /> 
     2055                            <input type="text" value="<?php echo stripslashes($curSermon->title) ?>" name="title" size="60" style="width:400px;" /> 
    14312056                        </div> 
    1432                     </td>                    
     2057                    </td>    
     2058                    <td> 
     2059                        <strong><?php _e('Tags (comma separated)', $sermon_domain) ?></strong> 
     2060                        <div> 
     2061                            <input type="text" name="tags" value="<?php echo stripslashes($tags) ?>" style="width:400px" /> 
     2062                        </div> 
     2063                    </td>                
    14332064                </tr> 
    14342065                <tr>                     
     
    14702101                        <strong><?php _e('Description', $sermon_domain) ?></strong> 
    14712102                        <div> 
    1472                             <textarea name="description" cols="50" rows="7"><?php echo $curSermon->description ?></textarea> 
     2103                            <textarea name="description" cols="50" rows="7"><?php echo stripslashes($curSermon->description) ?></textarea> 
    14732104                        </div> 
    14742105                    </td> 
     
    15462177                    </td> 
    15472178                </tr> 
    1548                 <tr id="choosefile" class="choose"> 
    1549                     <td> 
     2179                <tr > 
     2180                    <td colspan="2"> 
    15502181                        <table> 
    1551                             <tr class="choosefile"> 
    1552                                 <td><?php _e('Choose existing file:', $sermon_domain) ?> </td> 
    1553                                 <td id="filelist"> 
     2182                            <tr id="choosefile" class="choose"> 
     2183                                <th> 
     2184                                <select class="choosefile" name="choosefile" onchange="chooseType(this.name, this.value);"> 
     2185                                <option value="filelist"><?php _e('Choose existing file:', $sermon_domain) ?></option> 
     2186                                <option value="newupload"><?php _e('Upload a new one:', $sermon_domain) ?></option> 
     2187                                <option value="newurl"><?php _e('Enter an URL:', $sermon_domain) ?></option> 
     2188                                <option value="newcode"><?php _e('Enter embed code:', $sermon_domain) ?></option> 
     2189                                </select> 
     2190                                </th> 
     2191                                <td class="filelist"> 
    15542192                                    <select id="file" name="file[]">                                     
    15552193                                    <?php echo count($files) == 0 ? '<option value="0">No files found</option>' : '<option value="0"></option>' ?> 
     
    15592197                                    </select>                                    
    15602198                                </td> 
     2199                                <td class="newupload" style="display:none"><input type="file" size="50" name="upload[]"/></td> 
     2200                                <td class="newurl" style="display:none"><input type="text" size="50" name="url[]"/></td> 
     2201                                <td class="newcode" style="display:none"><input type="text" size="92" name="code[]"/></td> 
    15612202                            </tr> 
    15622203                        </table> 
    15632204                    </td> 
    1564                     <?php $wtf = checkSermonUploadable() ?> 
    1565                     <?php if ($wtf == 'writeable'): ?> 
    1566                     <td> 
    1567                         <table> 
    1568                             <tr>                                 
    1569                                 <td><?php _e('Or upload a new one:', $sermon_domain) ?> </td> 
    1570                                 <td><input type="file" name="upload[]"></td> 
    1571                             </tr> 
    1572                         </table>                     
    1573                     </td> 
    1574                     <?php endif ?> 
    15752205                </tr> 
    15762206            </table> 
     
    15782208        <p class="submit"><input type="submit" name="save" value="<?php _e('Save', $sermon_domain) ?> &raquo;" /></p>  
    15792209        </form> 
    1580     </div>       
     2210    </div>           
    15812211    <script type="text/javascript"> 
    15822212        jQuery.datePicker.setDateFormat('ymd','-'); 
     
    15862216        <?php endif ?> 
    15872217        <?php if ($mid): ?> 
    1588             assocFiles = new Array(); 
     2218            stuff = new Array(); 
     2219            type = new Array(); 
    15892220            start1 = new Array(); 
    15902221            start2 = new Array(); 
     
    15942225            end3 = new Array(); 
    15952226             
    1596             <?php $assocFiles = $wpdb->get_results("SELECT id FROM {$wpdb->prefix}sb_sermon_files WHERE sermon_id = $mid ORDER BY name asc;") ?> 
     2227            <?php  
     2228                $assocFiles = $wpdb->get_results("SELECT id FROM {$wpdb->prefix}sb_stuff WHERE sermon_id = $mid AND type = 'file' ORDER BY name asc;"); 
     2229                $assocURLs = $wpdb->get_results("SELECT name FROM {$wpdb->prefix}sb_stuff WHERE sermon_id = $mid AND type = 'url' ORDER BY name asc;"); 
     2230                $assocCode = $wpdb->get_results("SELECT name FROM {$wpdb->prefix}sb_stuff WHERE sermon_id = $mid AND type = 'code' ORDER BY name asc;");     
     2231                $r = false; 
     2232            ?> 
    15972233             
    15982234            <?php for ($lolz = 0; $lolz < count($assocFiles); $lolz++): ?> 
    1599                 <?php if ($lolz != 0): ?> 
    1600                     addFile(); 
    1601                 <?php endif ?> 
    1602                 assocFiles.push(<?php echo $assocFiles[$lolz]->id ?>); 
     2235                <?php $r = true ?> 
     2236                addFile(); 
     2237                stuff.push(<?php echo $assocFiles[$lolz]->id ?>); 
     2238                type.push('file'); 
    16032239            <?php endfor ?> 
     2240             
     2241            <?php for ($lolz = 0; $lolz < count($assocURLs); $lolz++): ?> 
     2242                <?php $r = true ?> 
     2243                addFile(); 
     2244                stuff.push('<?php echo $assocURLs[$lolz]->name ?>'); 
     2245                type.push('url'); 
     2246            <?php endfor ?> 
     2247 
     2248            <?php for ($lolz = 0; $lolz < count($assocCode); $lolz++): ?> 
     2249                <?php $r = true ?> 
     2250                addFile(); 
     2251                stuff.push('<?php echo $assocCode[$lolz]->name ?>'); 
     2252                type.push('code'); 
     2253            <?php endfor ?> 
     2254             
     2255            <?php if ($r): ?> 
     2256            jQuery('.choose:last').remove(); 
     2257            <?php endif ?> 
    16042258             
    16052259            <?php for ($lolz = 0; $lolz < count($startArr); $lolz++): ?> 
     
    16152269            <?php endfor ?> 
    16162270             
    1617             jQuery('.choosefile').each(function(i) { 
    1618                 jQuery("option[@value='" + assocFiles[i] + "']", this).attr('selected', 'selected'); 
     2271            jQuery('.choose').each(function(i) { 
     2272                switch (type[i]) { 
     2273                    case 'file': 
     2274                        jQuery("option[@value='filelist']", this).attr('selected', 'selected'); 
     2275                        jQuery('.filelist', this).css('display',''); 
     2276                        jQuery("option[@value='" + stuff[i] + "']", this).attr('selected', 'selected'); 
     2277                        break; 
     2278                    case 'url': 
     2279                        jQuery('td', this).css('display', 'none'); 
     2280                        jQuery("option[@value='newurl']", this).attr('selected', 'selected'); 
     2281                        jQuery('.newurl ', this).css('display','');          
     2282                        jQuery(".newurl input", this).val(stuff[i]); 
     2283                        break; 
     2284                    case 'code': 
     2285                        jQuery('td', this).css('display', 'none'); 
     2286                        jQuery("option[@value='newcode']", this).attr('selected', 'selected'); 
     2287                        jQuery('.newcode', this).css('display',''); 
     2288                        jQuery(".newcode input", this).val(Base64.decode(stuff[i])); 
     2289                        break; 
     2290                } 
    16192291            });      
    16202292             
     
    16472319} 
    16482320 
     2321// looking for new files 
    16492322function bb_scan_dir() { 
    16502323    global $wpdb; 
    16512324    global $wordpressRealPath; 
    16522325     
    1653     $files = $wpdb->get_results("SELECT name FROM {$wpdb->prefix}sb_sermon_files;"); 
     2326    $files = $wpdb->get_results("SELECT name FROM {$wpdb->prefix}sb_stuff WHERE type = 'file';"); 
    16542327    $bnn = array(); 
    16552328    foreach ($files as $file) { 
     
    16602333    if ($dh = @opendir($dir)) { 
    16612334        while (false !== ($file = readdir($dh))) { 
    1662             if ($file != "." && $file != ".." && !in_array($file, $bnn)) {               
    1663                 $wpdb->query("INSERT INTO {$wpdb->prefix}sb_sermon_files VALUES (null, '$file', 0);"); 
     2335            if ($file != "." && $file != ".." && is_dir($file) && !in_array($file, $bnn)) {              
     2336                $wpdb->query("INSERT INTO {$wpdb->prefix}sb_stuff VALUES (null, 'file', '$file', 0);"); 
    16642337            }    
    16652338        } 
     
    16682341} 
    16692342 
     2343// no need to explain here 
    16702344function checkSermonUploadable() { 
    16712345    global $wordpressRealPath; 
     
    16882362} 
    16892363 
    1690 function nl2br2($string) { 
    1691     $string = str_replace(array("\r\n", "\r", "\n"), "<br />", $string); 
    1692     return $string; 
    1693 } 
    1694  
    16952364?> 
  • sermon-browser/branches/0.10-0.23/single.php

    r57035 r57037  
    11<div class="sermon-browser-results"> 
    2  
    3  
    4  
    5     <h2>View single sermon</h2> 
    6  
    7  
    8  
    9     Title: <?php echo stripslashes($sermon["Sermon"]->title) ?><br /> 
    10  
    11  
    12  
    13     Preacher: <a href="<?php bb_print_preacher_link($sermon["Sermon"]) ?>"><?php echo stripslashes($sermon["Sermon"]->preacher) ?></a><br /> 
    14  
    15  
    16  
    17     Series: <a href="<?php bb_print_series_link($sermon["Sermon"]) ?>"><?php echo stripslashes($sermon["Sermon"]->series) ?></a><br /> 
    18  
    19  
    20  
    21     Service: <a href="<?php bb_print_service_link($sermon["Sermon"]) ?>"><?php echo stripslashes($sermon["Sermon"]->service) ?></a><br /> 
    22  
    23  
    24  
    25     Date: <?php echo date("j F Y", strtotime($sermon["Sermon"]->date)) ?><br /> 
    26  
    27  
    28  
    29     <?php for ($i = 0; $i < count($sermon["Sermon"]->start); $i++): ?>   
    30  
    31  
    32  
    33         <?php echo $sermon["Sermon"]->start[$i]["book"] ?>, <?php echo $sermon["Sermon"]->start[$i]["chapter"] ?> : <?php echo $sermon["Sermon"]->start[$i]["verse"] ?> - <?php echo $sermon["Sermon"]->end[$i]["book"] ?>, <?php echo $sermon["Sermon"]->end[$i]["chapter"] ?> : <?php echo $sermon["Sermon"]->end[$i]["verse"] ?><br /> 
    34  
    35  
    36  
    37     <?php endfor ?> 
    38  
    39  
    40  
    41     Files:<br /> 
    42  
    43  
    44  
    45     <?php foreach ($sermon["Files"] as $file): ?>    
    46  
    47  
    48  
    49         <?php bb_print_file($file->name) ?> 
    50  
    51  
    52  
     2    <h2><?php echo stripslashes($sermon["Sermon"]->title) ?> <span style="font-size: 80%"><?php for ($i = 0; $i < count($sermon["Sermon"]->start); $i++): ?><?php echo bb_get_books($sermon["Sermon"]->start[$i], $sermon["Sermon"]->end[$i]) ?><?php endfor ?></h2> 
     3    <span style="font-size: 120%"><a href="<?php bb_print_preacher_link($sermon["Sermon"]) ?>"><?php echo stripslashes($sermon["Sermon"]->preacher) ?></a>, <?php echo date("j F Y", strtotime($sermon["Sermon"]->date)) ?></span><br /> 
     4    Part of the <a href="<?php bb_print_series_link($sermon["Sermon"]) ?>"><?php echo stripslashes($sermon["Sermon"]->series) ?></a> series, preached at a <a href="<?php bb_print_service_link($sermon["Sermon"]) ?>"><?php echo stripslashes($sermon["Sermon"]->service) ?></a> service<br /> 
     5    Tags: <?php bb_print_tags($sermon["Tags"]) ?><br /> 
     6    <?php foreach ((array) $sermon["Files"] as $file): ?>    
     7        <?php bb_print_file($file) ?>   
    538    <?php endforeach ?> 
    54  
    55  
    56  
    57     <?php bb_print_next_sermon_link($sermon["Sermon"]) ?> 
    58  
    59  
    60  
    61     <?php bb_print_prev_sermon_link($sermon["Sermon"]) ?> 
    62  
    63  
    64  
    65     Same day: <?php bb_print_sameday_sermon_link($sermon["Sermon"]) ?> 
    66  
    67  
    68  
    69 </div>       
    70  
     9    <?php foreach ((array) $sermon["URLs"] as $url): ?> 
     10        <?php bb_print_url($url) ?>   
     11    <?php endforeach ?> 
     12    <?php foreach ((array) $sermon["Code"] as $code): ?> 
     13        <br /><?php bb_print_code($code) ?><br /> 
     14    <?php endforeach ?> 
     15    <br />   
     16    <b>Other sermons preached at a similar time:</b> 
     17    <ul> 
     18        <li>Earlier: <?php bb_print_prev_sermon_link($sermon["Sermon"]) ?></li> 
     19        <li>Same day: <?php bb_print_sameday_sermon_link($sermon["Sermon"]) ?></li> 
     20        <li>Later: <?php bb_print_next_sermon_link($sermon["Sermon"]) ?></li> 
     21    </ul> 
     22    <?php for ($i = 0; $i < count($sermon["Sermon"]->start); $i++): echo add_esv_text ($sermon["Sermon"]->start[$i], $sermon["Sermon"]->end[$i]); endfor ?> 
     23</div> 
  • sermon-browser/branches/0.10-0.23/style.css

    r57035 r57037  
    1 #sermon-filter .half { 
    2     margin-bottom: 4px; 
    3     width: 275px; 
    4     float: left; 
    5 } 
    6 #sermon-filter .title { 
    7     width: 100px; 
    8     float: left; 
    9 } 
    10 #sermon-filter input { 
    11     width: 160px; 
    12 } 
    13 #sermon-filter select { 
    14     width: 160px; 
    15 } 
    16 #sermon-filter input#date, #sermon-filter input#enddate { 
    17     width: 140px !important; 
    18 } 
    19 #sermon-filter input.filter { 
    20     width: 100px; 
    21 } 
    221.sermon-browser h2 { 
    232    clear: both; 
     
    4120div.sermon-browser table.sermons td.files img { 
    4221    border: none; 
    43     margin-right: 12px; 
     22    margin-right: 24px; 
    4423} 
    4524 
     25table.sermonbrowser td.fieldname { 
     26    font-weight:bold; 
     27    padding-right: 10px; 
     28    vertical-align:bottom; 
     29} 
     30 
     31table.sermonbrowser td.field input, table.sermonbrowser td.field select{ 
     32    width: 170px; 
     33} 
     34 
     35table.sermonbrowser td.field  #date, table.sermonbrowser td.field #enddate { 
     36    width: 150px; /* This width should be 20 pixels less than the width above */ 
     37} 
     38 
     39table.sermonbrowser td { 
     40    white-space: nowrap; 
     41    padding-top: 5px; 
     42    padding-bottom: 5px; 
     43} 
     44 
     45table.sermonbrowser td.rightcolumn { 
     46    padding-left: 10px; 
     47} 
     48 
     49div.sermon-browser div.floatright { 
     50    float: right 
     51} 
     52 
     53div.sermon-browser div.floatleft { 
     54    float: left 
     55} 
     56 
     57img.sermon-icon , img.site-icon{ 
     58    border: none; 
     59} 
     60 
     61div.esv span.chapter-num, div.ebSnippet-title, div.chapterHeading, div.paragraphHeading { 
     62    font-weight: bold; 
     63    font-size: 150%; 
     64    margin: 0.75em 0; 
     65} 
     66 
     67div.esv span.verse-num, span.verseNum { 
     68    vertical-align:super; 
     69    line-height: 1em; 
     70    font-size: 65%; 
     71} 
     72 
     73table.nearby-sermons { 
     74    width:100% 
     75} 
     76 
     77table.nearby-sermons th { 
     78    font-weight: bold; 
     79} 
     80 
     81table.nearby-sermons th, table.nearby-sermons td { 
     82    text-align: center; 
     83    line-height: 1.2em; 
     84    padding: 0 1em; 
     85    width: 33%; 
     86    vertical-align: top; 
     87} 
     88 
     89table.nearby-sermons .earlier { 
     90    text-align: left; 
     91    padding: 0; 
     92} 
     93 
     94table.nearby-sermons .later { 
     95    text-align: right; 
     96    padding: 0; 
     97} 
     98 
     99div.sermon-browser-results span.scripture{ 
     100    font-size: 80% 
     101} 
Note: See TracChangeset for help on using the changeset viewer.