Added support for php4 sites short urls on 4-chars initials and on custom named test...
authorKristian Kræmmer Nielsen <jkkn@jkkn.dk>
Thu, 20 Dec 2007 00:35:16 +0000 (01:35 +0100)
committerKristian Kræmmer Nielsen <jkkn@jkkn.dk>
Thu, 20 Dec 2007 00:35:16 +0000 (01:35 +0100)
Made php5 sites customizable in options dialog

content/options.js
content/options.xul
content/tv2developer-quickbox.js
content/tv2developer-util.js
content/tv2developer.js
defaults/preferences/tv2developer.js
locale/da-DK/tv2developer.dtd
locale/da-DK/tv2developer.properties
locale/en-US/tv2developer.dtd
locale/en-US/tv2developer.properties
version

index 1db758f455aebd38e0fa76b00109f6b2d09599a3..dc7e658df276ad59bca29d0a8b73d938371b75a5 100755 (executable)
@@ -9,7 +9,7 @@ var TV2Options = {
         var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
         this._keyBranch = prefs.getBranch('ui.key.');
         this._prefBranch = prefs.getBranch('browser.preferences.');
-        // we show the options for hacing accesskeys if user has set a preference or accesskeys are disabled
+        // we show the options for hacking accesskeys if user has set a preference or accesskeys are disabled
         this._hackEnabled =
             this._keyBranch.prefHasUserValue('menuAccessKey') ||
             (this._keyBranch.getIntPref('menuAccessKey') == 0);
@@ -19,6 +19,74 @@ var TV2Options = {
             document.getElementById('mac-accesskeys').checked =
                 (this._keyBranch.getIntPref('menuAccessKey') != 0);
         }
+        // fill in php5 sites
+        document.getElementById('php5auto').selectedIndex =
+            (TV2Util.hasPref('php5sites') ? 1 : 0);
+        this.php5sitesFillIn(TV2Util.getPref('php5sites', ''));
+    },
+    
+    /* fill in list */
+    php5sitesFillIn: function(php5set) {
+        var php5sites = php5set.split(',').sort();
+        var php5list = document.getElementById('php5sites');
+        var child = php5list.childNodes;
+        for (var i=child.length-1; i>=0; --i) {
+            if (child[i].tagName == 'listitem') {
+                php5list.removeChild(child[i]);
+            }
+        }
+        for (var i=0; i<php5sites.length; i++) {
+            if (php5sites[i] == '') continue;
+            var php5item = document.createElement('listitem');
+            php5item.setAttribute('label', php5sites[i]);
+            php5list.appendChild(php5item);
+        }
+    },
+    
+    php5sitesSelect: function(obj) {
+        document.getElementById('php5sites_remove').disabled = (obj.selectedItem) ? false : true;
+    },
+    
+    php5sitesAdd: function(obj) {
+        var add = prompt(TV2Util.getStr('optionsDialog.enterphp5site'), '');
+        if (add && add != '') {
+            var php5sites  = document.getElementById('php5sites');
+            var php5childs = php5sites.childNodes;
+            var insertBefore = null;
+            // place at right sorted place in list
+            for (var i=0; i<php5childs.length; i++) {
+                if (php5childs[i].tagName == 'listitem') {
+                    var item = php5childs[i].getAttribute('label');
+                    if (item > add) {
+                        insertBefore = php5childs[i];
+                        break;
+                    }
+                }
+            }
+            var newItem = document.createElement('listitem');
+            newItem.setAttribute('label', add);
+            php5sites.insertBefore(newItem, insertBefore);
+            php5sites.selectedItem = newItem;
+            php5sites.focus();
+        }
+    },
+    
+    php5sitesRemove: function(obj) {
+        var php5sites = document.getElementById('php5sites');
+        php5sites.removeChild(php5sites.selectedItem);
+        php5sites.focus();
+    },
+    
+    php5sitesAuto: function(obj) {
+        var php5sites = document.getElementById('php5sites');
+        var useDefaults = (obj.selectedIndex == 0);
+        if (useDefaults && !php5sites.disabled) {
+            this.php5sitesFillIn(TV2Util.getDefaultPref('php5sites'));
+        } else {
+            php5sites.focus();
+        }
+        php5sites.disabled = useDefaults;
+        document.getElementById('php5sites_add').disabled = useDefaults;
     },
     
     save: function() {
@@ -30,6 +98,22 @@ var TV2Options = {
                 this._keyBranch.clearUserPref('menuAccessKey');
             }
         }
+        // save php5 sites list
+        var php5auto = document.getElementById('php5auto');
+        if (php5auto.selectedIndex == 1) {
+            var php5childs = document.getElementById('php5sites').childNodes;
+            var php5sites = [];
+            for (var i=0; i<php5childs.length; i++) {
+                if (php5childs[i].tagName == 'listitem') {
+                    php5sites.push(php5childs[i].getAttribute('label'));
+                }
+            }
+            TV2Util.setPref('php5sites', php5sites.join(','));
+        } else {
+            if (TV2Util.hasPref('php5sites')) {
+                TV2Util.clearPref('php5sites');
+            }
+        }
     },
     
     update: function() {
index e8f240722ea0cb61f1ee77cd562df56f67c5e0fe..44be2ab22afc1d95487112f6ed3ef608f95cb0c5 100755 (executable)
@@ -7,17 +7,38 @@
                title="&optionsDialog.title;"
                onload="TV2Options.init()"
                ondialogaccept="TV2Options.save()">
-<script type="application/x-javascript" src="options.js" />
-  
+               
+  <script type="application/x-javascript" src="tv2developer-util.js" />
+  <script type="application/x-javascript" src="options.js" />
+        
+  <stringbundleset id="stringbundleset">
+    <stringbundle id="tv2developer_strings" src="chrome://tv2developer/locale/tv2developer.properties"/>
+  </stringbundleset>
+
   <prefpane id="pane1" label="&optionsDialog.options.label;">
     <preferences>
       <preference id="pref_developer-initials" name="tv2developer.developer-initials" type="string"/>
     </preferences>
      
     <groupbox>
-        <label control="developer-initials" value="&developerInitials.description;" />
+        <caption label="&developerInitials.description;" />
         <textbox id="developer-initials" preference="pref_developer-initials" />
     </groupbox>
+    
+    <groupbox>
+        <caption label="&optionsDialog.php5sites.label;" tooltiptext="&optionsDialog.php5sites.tooltiptext;"/>
+        <radiogroup id="php5auto" onselect="TV2Options.php5sitesAuto(this)">
+            <radio label="&optionsDialog.php5sites.defaults;"/>
+            <radio label="&optionsDialog.php5sites.custom;"/>
+        </radiogroup>
+        <listbox id="php5sites" onselect="TV2Options.php5sitesSelect(this)"/>
+        <hbox align="center">
+            <spacer flex="1"/>
+            <button label="&optionsDialog.php5sites.addsite;" accesskey="&optionsDialog.php5sites.addsite.accesskey;" id="php5sites_add" oncommand="TV2Options.php5sitesAdd()" disabled="true"/>
+            <button label="&optionsDialog.php5sites.removesite;" accesskey="&optionsDialog.php5sites.removesite.accesskey;" id="php5sites_remove" oncommand="TV2Options.php5sitesRemove()" disabled="true"/>
+            <spacer flex="1"/>
+        </hbox>
+    </groupbox>
 
     <groupbox id="mac-hacks">
         <checkbox id="mac-accesskeys" label="&optionsDialog.mac.accesskeys;"
index d6e9dd90856171ff3fa58df17eb6e6cc657d0442..39206a1446ffadc2354ec38f1ab582f295e77424 100644 (file)
@@ -12,7 +12,7 @@ var TV2DeveloperQuickBox = {
        },\r
        \r
        _autoChange: false,\r
-       _saveInitials: false, /* safe the alternative initials field */\r
+       _saveInitials: false, /* save the alternative initials field */\r
        \r
        setManuel: function(target) {\r
         if (target.id == 'environment') {\r
@@ -94,12 +94,19 @@ var TV2DeveloperQuickBox = {
                 }\r
 \r
                 // optional username\r
-                if (part.length == 4 && !auto_username) {\r
-                    auto_username = part;\r
-                    if (auto_env == 'live') {\r
-                        auto_env = 'test';\r
+                if (!auto_username) {\r
+                    if (part.length == 5 && part.substr(part.length-1, 1) == '3') {\r
+                        part = part.substr(0, part.length-1); // handle 'jkkn3' as short for php4 site, ...\r
+                        auto_php4 = true;\r
+                        // will also continue into next if-statement since we cut off one character\r
+                    }\r
+                    if (part.length == 4) {\r
+                        auto_username = part;\r
+                        if (auto_env == 'live') {\r
+                            auto_env = 'test';\r
+                        }\r
+                        continue;\r
                     }\r
-                    continue;\r
                 }\r
 \r
                 // detect short sitetype (.o, .op, .opd,.. )\r
@@ -114,6 +121,10 @@ var TV2DeveloperQuickBox = {
 \r
                 // handle other kinds of usernames\r
                 if (!auto_username) {\r
+                    if (part.substr(part.length-1, 1) == '3') {\r
+                        part = part.substr(0, part.length-1); // handle 'certus3' as short for php4 site, ...\r
+                        auto_php4 = true;\r
+                    }\r
                     auto_username = part;\r
                 }\r
           \r
index 0866e76d979b7cbed90512958a070b0783608023..fe6ab5ec43c838b8eb12072664d921dd7c37f019 100644 (file)
@@ -30,6 +30,15 @@ var TV2Util = {
                 Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch('tv2developer.');\r
         return this._prefs;\r
     },\r
+    \r
+    /* default preference functions */\r
+    _defPrefs: null,\r
+    get defPrefs() {\r
+        if (!this._defPrefs)\r
+            this._defPrefs =\r
+                Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getDefaultBranch('tv2developer.');\r
+        return this._defPrefs;\r
+    },\r
 \r
     getPref: function(name, defValue) {\r
         const CI=Components.interfaces.nsIPrefBranch;\r
@@ -62,6 +71,31 @@ var TV2Util = {
           default:\r
             throw new Error('Unsupported type '+typeof(value)+' for preference '+name);\r
         }\r
+    },\r
+    \r
+    hasPref: function(name) {\r
+        return this.prefs.prefHasUserValue(name);\r
+    },\r
+    \r
+    clearPref: function(name) {\r
+        this.prefs.clearUserPref(name);\r
+    },\r
+    \r
+    getDefaultPref: function(name) {\r
+        const CI=Components.interfaces.nsIPrefBranch;\r
+        const prefs=this.defPrefs;\r
+        try {\r
+          switch(prefs.getPrefType(name)) {\r
+            case CI.PREF_STRING:\r
+              return prefs.getCharPref(name);\r
+            case CI.PREF_INT:\r
+              return prefs.getIntPref(name);\r
+            case CI.PREF_BOOL:\r
+              return prefs.getBoolPref(name);\r
+          }\r
+        } catch(e) {alert(e)}\r
+        return defValue;\r
     }\r
     \r
+    \r
 };\r
index 0d5273ef93c90f69b5030ce9cabc735472ed4394..59651c524a101df9aa7a82a6b646a89b6e834b23 100755 (executable)
@@ -156,13 +156,17 @@ var TV2Developer = {
         menu.appendChild(item);
         return def;
     },
+    
+    _isPhp5: function(site) {
+        if (!site) site = 'www';
+        return ((','+TV2Util.getPref('php5sites')+',').indexOf(','+site+',') != -1);
+    },
  
     /* Main function for adding all the links for the menu popup */   
     _reg_tv2: /^https?:\/\/([^/.]*)?([^/]*?)(\.(robot|opdatering|template)\.?)?(\.((test|snapshot)3?)\.)?tv2\.dk((\/[^#\?]*).*)?$/,
     _reg_php: /^(.*\.php)/,
     _reg_nodeid: /([0-9]{2,})/g,
     _reg_i2files: /\/([0-9]+)-/,
-    _reg_php5: /^(www|i2|common|ttvpumpe|1234|nyhederne|krimi)$/,
     _reg_fromviewcvs: /^http:\/\/viewcvs\.tv2.dk:7467\/cgi-bin\/viewvc\.cgi\/([^/]+)\.tv2\.dk\/(webroot|robot|opdatering|template)([^#\?]+)/,
     _reg_fromi2if: /^\/(tango\/(entry|requeue|dynamic)|tool\/pdo_log\/frameset)\.php.*?(\?|&)url=([^&]+)/,
     getLinks: function() {
@@ -186,9 +190,9 @@ var TV2Developer = {
             // Strip -dyn and -static
             if (tv2_sitename) tv2_sitename = tv2_sitename.replace(/-(dyn|static)$/, '');
             if (tv2_user) tv2_user = tv2_user.replace(/^\./, '');
-            
-            // php5 sites
-            var php5 = ((!tv2_sitename) || (this._reg_php5.test(tv2_sitename)));
+
+            // php5 site
+            var php5 = this._isPhp5(tv2_sitename);
             var testType = php5 ? '' : '3';
             
             // Find live, test and snapshot url for current site
@@ -397,8 +401,7 @@ var TV2Developer = {
                 }
 
                 // php5 sites
-                //var php5 = ((!tv2_sitename) || (this._reg_php5.test(tv2_sitename)));
-                var php5 = ((tv2_sitename) && (this._reg_php5.test(tv2_sitename)));
+                var php5 = this._isPhp5(tv2_sitename);
                 var testType = php5 ? '' : '3';
 
                 var live_sitename = (tv2_sitetype=='webroot' && tv2_sitename=='www') ? '': (tv2_sitename+'.');
index 2c9bf722bc35127d89ceda46351760bb155bbd20..c0bb843499b305fe91ebda83b09792d35c2585df 100755 (executable)
@@ -3,3 +3,4 @@
 pref('tv2developer.firstRun', true);
 pref('tv2developer.developer-initials', 'CHANGE-THIS');
 pref('tv2developer.lastaction-linktype', 'tango/entry');
+pref('tv2developer.php5sites', 'www,i2,common,ttvpumpe,1234,nyhederne,krimi,radio');
index e63853eb4f32a9729bdcf12fb6f1eea9d06ce298..09b994257a5788742ab0ae554cfc785152e22501 100755 (executable)
 <!ENTITY optionsDialog.mac.accesskeys "Slå genvejstaster til i Firefox på Mac">
 <!ENTITY optionsDialog.mac.accesskeys.tooltiptext "Ændring af dette felt kræver genstart af Firefox">
 
+<!ENTITY optionsDialog.php5sites.label "PHP 5 konverterede sites">
+<!ENTITY optionsDialog.php5sites.tooltiptext "Sites i denne liste vil blive betragtet som PHP 5 sites.">
+<!ENTITY optionsDialog.php5sites.defaults "Brug standard PHP 5 sites">
+<!ENTITY optionsDialog.php5sites.custom "Vælg manuelt PHP 5 sites:">
+<!ENTITY optionsDialog.php5sites.addsite "Tilføj site">
+<!ENTITY optionsDialog.php5sites.addsite.accesskey "t">
+<!ENTITY optionsDialog.php5sites.removesite "Fjern site">
+<!ENTITY optionsDialog.php5sites.removesite.accesskey "f">
+
 <!ENTITY config.label "Konfigurér">
 <!ENTITY config.accesskey "c">
 
index 6003eb09529273786ab086bfe2c550d099ad4234..6b7508ce461ccf7b42bd85e74ea118608820a3c5 100755 (executable)
@@ -57,15 +57,11 @@ tv2dk.accesskey=t
 
 enterInitials=Indtast tv2.dk initialer (f.eks. jkkn):
 
+# Quickbox dialog
+
 quickbox.menuitem=TV 2 | Quickbox dialog...
 quickbox.accesskey=q
 
-quickbox.live.accesskey=w
-quickbox.test.accesskey=t
-quickbox.snapshot.accesskey=s
-quickbox.live-opdatering.accesskey=o
-quickbox.test-opdatering.accesskey=p
-quickbox.snapshot-opdatering.accesskey=d
-quickbox.live-robot.accesskey=r
-quickbox.test-robot.accesskey=b
-quickbox.snapshot-robot.accesskey=a
+# Options dialog
+
+optionsDialog.enterphp5site=Indtast navn på PHP 5 site:
index 78d1cdc6ec6f7c0db87b75ceb2ec25fe6f6abd5f..c8d5ad73c00c93675e7c852d0fa0a64b1d8439b0 100755 (executable)
 <!ENTITY optionsDialog.mac.accesskeys "Enable accesskeys in Firefox on Mac">
 <!ENTITY optionsDialog.mac.accesskeys.tooltiptext "Changing this requires restart of Firefox">
 
+<!ENTITY optionsDialog.php5sites.label "PHP 5 enabled sites">
+<!ENTITY optionsDialog.php5sites.tooltiptext "Sites listed here will be seen as PHP 5 sites.">
+<!ENTITY optionsDialog.php5sites.defaults "Use default PHP 5 sites">
+<!ENTITY optionsDialog.php5sites.custom "Custom PHP 5 sites:">
+<!ENTITY optionsDialog.php5sites.addsite "Add site">
+<!ENTITY optionsDialog.php5sites.addsite.accesskey "a">
+<!ENTITY optionsDialog.php5sites.removesite "Remove site">
+<!ENTITY optionsDialog.php5sites.removesite.accesskey "r">
+
 <!ENTITY config.label "Configure">
 <!ENTITY config.accesskey "c">
 
index e239c19aac5cf45fdd5dc2d1cea042e1f7636609..1c40dace2c500c203180661bd01e0c32d1f6165f 100755 (executable)
@@ -57,15 +57,11 @@ tv2dk.accesskey=t
 
 enterInitials=Enter TV 2 initials (e.x. jkkn):
 
+# Quickbox dialog
+
 quickbox.menuitem=TV 2 | Quickbox dialog...
 quickbox.accesskey=q
 
-quickbox.live.accesskey=w
-quickbox.test.accesskey=t
-quickbox.snapshot.accesskey=s
-quickbox.live-opdatering.accesskey=o
-quickbox.test-opdatering.accesskey=p
-quickbox.snapshot-opdatering.accesskey=d
-quickbox.live-robot.accesskey=r
-quickbox.test-robot.accesskey=b
-quickbox.snapshot-robot.accesskey=a
+# Options dialog
+
+optionsDialog.enterphp5site=Enter name of PHP 5 site:
diff --git a/version b/version
index 8bd6ba8c5c366585c0343c027cb738d5fdeb8d4d..a3df0a6959e154733da89a5d6063742ce6d5b851 100644 (file)
--- a/version
+++ b/version
@@ -1 +1 @@
-0.7.5
+0.8.0