]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
Refactoring: improve debug_mode, constants and other stuff
authormensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>
Fri, 21 Nov 2008 10:44:28 +0000 (10:44 +0000)
committermensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>
Fri, 21 Nov 2008 10:44:28 +0000 (10:44 +0000)
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@168 b3834d28-1941-0410-a4f8-b48e95affb8f

18 files changed:
config.inc.php.example
constants.inc.php
debug.inc.php [deleted file]
functions.inc.php
gsearch/context.php
gsearch/index.php
header.inc.php
index.php
jsScuttle.php
rss.php
services/userservice.php
templates/bookmarks.tpl.php
templates/editbookmark.tpl.php
templates/login.tpl.php
templates/sidebar.block.recent.php
templates/toolbar.inc.php
templates/top.inc.php
upgrade.txt

index 47e314ef07bdc81646f12a0a840429dd9b95c181..a8aa84783818a931cd2b86138a9c24f54be2fe8e 100644 (file)
@@ -15,6 +15,7 @@ $usecache           = false; # use cache ? {true,false}
 $dir_cache          = dirname(__FILE__) .'/cache/'; # directory where cache files will be stored
 $cleanurls          = false; # Use mod_rewrite to hide PHP extensions {true,false[default]}
                             # be cautious, doesn't work for all hosts, you may need to modify the .htaccess file
+$debugMode                     = false; # if true, show debug messages                      
 
 #### Database ####
 $dbtype = 'mysql4'; # Database driver {mysql, mysqli, mysql4, oracle, postgres, sqlite, db2, firebird, mssql, mssq-odbc}
@@ -85,5 +86,5 @@ $menu2Tags = array('example', 'of', 'menu', 'tags'); # list of tags used by menu
 $sizeSearchHistory = 10; # number of users' searches that are saved {1..10[Default]..-1[Unlimited]}
 $enableGoogleCustomSearch = true; #Enable Google Search Engine into "gsearch/" folder
 
-include_once('debug.inc.php');
+
 ?>
index 824561f447df50b64704fc89765a46f4022791cc..e779852ed8891ec46fa3e70fbd69e26eda89d6e1 100644 (file)
@@ -1,4 +1,30 @@
 <?php
+/*
+ * Define constants use in all the application.
+ * Some constants are based on variables from configuration file.
+ */
+
+// Debug managament
+if(isset($GLOBALS['debugMode'])) {
+       define('DEBUG_MODE', $GLOBALS['debugMode']);
+       define('DEBUG_EXTRA', $GLOBALS['debugMode']); // Constant used exclusively into db/ directory
+}
+
+// Determine the base URL as ROOT
+if (!isset($GLOBALS['root'])) {
+       $pieces = explode('/', $_SERVER['SCRIPT_NAME']);
+       $rootTmp = '/';
+       foreach($pieces as $piece) {
+               if ($piece != '' && !strstr($piece, '.php')) {
+                       $rootTmp .= $piece .'/';
+               }
+       }
+       if (($rootTmp != '/') && (substr($rootTmp, -1, 1) != '/')) {
+               $rootTmp .= '/';
+       }
+
+       define('ROOT', 'http://'. $_SERVER['HTTP_HOST'] . $rootTmp);
+}
 
 // Error codes
 define('GENERAL_MESSAGE', 200);
@@ -19,7 +45,7 @@ define('INSTALLATION_ID', md5($GLOBALS['dbname'].$GLOBALS['tableprefix']));
 
 // Correct bug with PATH_INFO (maybe for Apache 1)
 if(strlen($_SERVER["PATH_INFO"])<strlen($_SERVER["ORIG_PATH_INFO"])) {
-    $_SERVER["PATH_INFO"] = $_SERVER["ORIG_PATH_INFO"]; 
+       $_SERVER["PATH_INFO"] = $_SERVER["ORIG_PATH_INFO"];
 }
 
 ?>
diff --git a/debug.inc.php b/debug.inc.php
deleted file mode 100644 (file)
index 8bd7f33..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-// Turn debugging on
-define('SCUTTLE_DEBUG',true);
-
-// generic debugging function
-// Sample:
-//     pc_debug(__FILE__, __LINE__, "This is a debug message.");
-
-function pc_debug($file, $line, $message) {
-    if (defined('SCUTTLE_DEBUG') && SCUTTLE_DEBUG) {
-        error_log("---DEBUG-". $sitename .": [$file][$line]: $message");
-    } else {
-        error_log("SCUTTLE_DEBUG disabled");
-    }
-}
-?>
\ No newline at end of file
index 35f0fedaba2170ea185d729ac6cccd9f2e6ff96e..93821fdc1a3a1bab06473539e3fd51b2cd9b3a13 100644 (file)
@@ -85,11 +85,11 @@ function multi_array_search($needle, $haystack) {
 }
 
 function createURL($page = '', $ending = '') {
-    global $cleanurls, $root;
+    global $cleanurls;
     if (!$cleanurls && $page != '') {
         $page .= '.php';
     }
-    return $root . $page .'/'. $ending;
+    return ROOT . $page .'/'. $ending;
 }
 
 /* Shorten a string like a URL for example by cutting the middle of it */
@@ -112,7 +112,7 @@ function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '',
        
        // Get SQL error if we are debugging. Do this as soon as possible to prevent 
        // subsequent queries from overwriting the status of sql_error()
-       if (DEBUG && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) {
+       if (DEBUG_MODE && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) {
                $sql_error = is_null($db) ? '' : $db->sql_error();
                $debug_text = '';
                
@@ -157,10 +157,10 @@ function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '',
                        break;
        }
 
-       // Add on DEBUG info if we've enabled debug mode and this is an error. This
-       // prevents debug info being output for general messages should DEBUG be
+       // Add on DEBUG_MODE info if we've enabled debug mode and this is an error. This
+       // prevents debug info being output for general messages should DEBUG_MODE be
        // set TRUE by accident (preventing confusion for the end user!)
-       if (DEBUG && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) {
+       if (DEBUG_MODE && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) {
                if ($debug_text != '')
                        $msg_text = $msg_text . '<br /><br /><strong>'. T_('DEBUG MODE') .'</strong>'. $debug_text;
        }
index a48179fcf40f4e73db9254c45afd621c5654cd18..1a650636aabd5649b03c177747ea6474929d5a49 100644 (file)
@@ -14,7 +14,7 @@
         </LookAndFeel>
     </CustomSearchEngine>
 
-    <Include type="Annotations" href="<?php echo $GLOBALS['root'];?>api/export_gcs.php?xml=1" />
+    <Include type="Annotations" href="<?php echo ROOT;?>api/export_gcs.php?xml=1" />
 
 
 </GoogleCustomizations>
index d4f596d38885dd7bbcb5b0e75325db825414ed74..e7011bfcd4d5b5434ca05bb37487b3f569480ce3 100644 (file)
@@ -14,7 +14,7 @@ if($GLOBALS['enableGoogleCustomSearch']==false) {
 
 <!-- Google CSE Search Box Begins  -->
 <form id="cref" action="http://www.google.com/cse">
-  <input type="hidden" name="cref" value="<?php echo $GLOBALS['root']?>gsearch/context.php" />
+  <input type="hidden" name="cref" value="<?php echo ROOT;?>gsearch/context.php" />
   <input type="text" name="q" size="40" />
   <input type="submit" name="sa" value="Search" />
 </form>
index 820b5f9c4244a4666131e33a4c3d6ef0c9cb2c7e..f94ce0d6becd6c083859ce7337b17661ff473a97 100644 (file)
@@ -1,35 +1,31 @@
 <?php
-ini_set('display_errors', '1');
-ini_set('mysql.trace_mode', '0');
+if(!file_exists(dirname(__FILE__) .'/config.inc.php')) {
+       die("Please, create the 'config.inc.php' file. You can copy the 'config.inc.php.example' file.");
+}
 
-error_reporting(E_ALL ^ E_NOTICE);
-//error_reporting(E_ALL);
+// First requirements part (before debug management)
+require_once(dirname(__FILE__) .'/config.inc.php');
+require_once(dirname(__FILE__) .'/constants.inc.php'); // some constants are based on variables from config file
 
-define('DEBUG', true);
-session_start();
 
-if(!file_exists(dirname(__FILE__) .'/config.inc.php')) {
-    die("Please, create the 'config.inc.php' file. You can copy the 'config.inc.php.example' file.");
+// Debug Management using constants
+if(DEBUG_MODE) {
+       ini_set('display_errors', '1');
+       ini_set('mysql.trace_mode', '1');
+       error_reporting(E_ALL);
+       //error_reporting(E_ALL^E_NOTICE);
+} else {
+       ini_set('display_errors', '0');
+       ini_set('mysql.trace_mode', '0');
+       error_reporting(0);
 }
 
+
+// Second requirements part which could display bugs (must come after debug management)
 require_once(dirname(__FILE__) .'/services/servicefactory.php');
-require_once(dirname(__FILE__) .'/config.inc.php');
-require_once(dirname(__FILE__) .'/constants.inc.php');
 require_once(dirname(__FILE__) .'/functions.inc.php');
 
-// Determine the base URL
-if (!isset($root)) {
-    $pieces = explode('/', $_SERVER['SCRIPT_NAME']);
-    $root = '/';
-    foreach($pieces as $piece) {
-        if ($piece != '' && !strstr($piece, '.php')) {
-            $root .= $piece .'/';
-        }
-    }
-    if (($root != '/') && (substr($root, -1, 1) != '/')) {
-        $root .= '/';
-    }
-    $root = 'http://'. $_SERVER['HTTP_HOST'] . $root;
-}
+
+session_start();
 
 ?>
index 2b5eda2e6f6d30beae208cd6d9b03abacff61f23..0a2b48391946c182f3edc278b3d1f5ef40882e49 100644 (file)
--- a/index.php
+++ b/index.php
@@ -20,6 +20,7 @@
  ***************************************************************************/
 
 require_once('header.inc.php');
+
 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
 $userservice =& ServiceFactory::getServiceInstance('UserService');
index 53356aafc85b2ba07337c77d4e4265940c781719..222b91d93aa47f5817c55cd280f5ea3cd287f1d5 100644 (file)
@@ -2,7 +2,7 @@
 header('Content-Type: text/javascript');
 require_once('header.inc.php');
 require_once('functions.inc.php');
-$player_root = $root .'includes/player/';
+$player_root = ROOT .'includes/player/';
 ?>
 
 function _playerAdd(anchor) {
@@ -41,7 +41,7 @@ function deleteConfirmed(ele, input, response) {
         post.style.display = 'none';
         deleted = false;
     } else {
-        loadXMLDoc('<?php echo $root; ?>ajaxDelete.php?id=' + input);
+        loadXMLDoc('<?php echo ROOT; ?>ajaxDelete.php?id=' + input);
         post.style.display = 'none';
         
     }
@@ -62,7 +62,7 @@ function isAvailable(input, response){
     username = username.trim();
     var availability = document.getElementById("availability");
     if (username != '') {
-        usernameField.style.backgroundImage = 'url(<?php echo $root; ?>images/loading.gif)';
+        usernameField.style.backgroundImage = 'url(<?php echo ROOT; ?>images/loading.gif)';
         if (response != '') {
             usernameField.style.backgroundImage = 'none';
             if (response == 'true') {
@@ -73,7 +73,7 @@ function isAvailable(input, response){
                 availability.innerHTML = '<?php echo T_('Not Available'); ?>';
             }
         } else {
-            loadXMLDoc('<?php echo $root; ?>ajaxIsAvailable.php?username=' + username);
+            loadXMLDoc('<?php echo ROOT; ?>ajaxIsAvailable.php?username=' + username);
         }
     }
 }
@@ -92,12 +92,12 @@ function useAddress(ele) {
 function getTitle(input, response){
     var title = document.getElementById('titleField');
     if (title.value == '') {
-        title.style.backgroundImage = 'url(<?php echo $root; ?>images/loading.gif)';
+        title.style.backgroundImage = 'url(<?php echo ROOT; ?>images/loading.gif)';
         if (response != null) {
             title.style.backgroundImage = 'none';
             title.value = response;
         } else if (input.indexOf('http') > -1) {
-            loadXMLDoc('<?php echo $root; ?>ajaxGetTitle.php?url=' + input);
+            loadXMLDoc('<?php echo ROOT; ?>ajaxGetTitle.php?url=' + input);
         } else {
             return false;
         }
diff --git a/rss.php b/rss.php
index fc35e40f45109519e4216e5dfc5b96005a08bd9e..476a28dd248d2acb30737c6e871d65ec29c7e9a4 100644 (file)
--- a/rss.php
+++ b/rss.php
@@ -75,7 +75,7 @@ if ($cat) {
 }
 
 $tplVars['feedtitle'] = filter($GLOBALS['sitename'] . (isset($pagetitle) ? $pagetitle : ''));
-$tplVars['feedlink'] = $GLOBALS['root'];
+$tplVars['feedlink'] = ROOT;
 $tplVars['feeddescription'] = sprintf(T_('Recent bookmarks posted to %s'), $GLOBALS['sitename']);
 
 $bookmarks =& $bookmarkservice->getBookmarks(0, 15, $userid, $cat, NULL, getSortOrder(), $watchlist);
index 9b295daf93121d7420d74b9ddd7d8540f3290464..e611cb8d6fb9e65df77dde55c1d3f03111259f97 100644 (file)
@@ -23,8 +23,8 @@ class UserService {
         function UserService(& $db) {
                $this->db =& $db;
                $this->tablename = $GLOBALS['tableprefix'] .'users';
-               $this->sessionkey = $GLOBALS['cookieprefix'].INSTALLATION_ID.'-currentuserid';
-               $this->cookiekey = $GLOBALS['cookieprefix'].INSTALLATION_ID.'-login';
+               $this->sessionkey = INSTALLATION_ID.'-currentuserid';
+               $this->cookiekey = INSTALLATION_ID.'-login';
                $this->profileurl = createURL('profile', '%2$s');
         }
 
@@ -124,10 +124,11 @@ class UserService {
                if (!is_null($newval)) //internal use only: reset currentuser
                $currentuser = $newval;
                else if ($refresh || !isset($currentuser)) {
-                       if ($id = $this->getCurrentUserId())
-                       $currentuser = $this->getUser($id);
-                       else
-                       return null;
+                       if ($id = $this->getCurrentUserId()) {
+                               $currentuser = $this->getUser($id);
+                       } else {
+                               $currentuser = null;
+                       }
                }
                return $currentuser;
         }
index 27dfb6ec3cbafda0749af69df7fcbd131881e210..5567d7b3b027179b574e30477e1673b03f8c1a49 100644 (file)
@@ -257,7 +257,7 @@ window.onload = playerLoad;
     $brss = '';
     $size = count($rsschannels);
     for ($i = 0; $i < $size; $i++) {
-        $brss =  '<a style="background:#FFFFFF" href="'. $rsschannels[$i][1] .'" title="'. $rsschannels[$i][0] .'"><img src="'. $GLOBALS['root'] .'images/rss.gif" width="16" height="16" alt="'. $rsschannels[$i][0] .'" /></a>'; 
+        $brss =  '<a style="background:#FFFFFF" href="'. $rsschannels[$i][1] .'" title="'. $rsschannels[$i][0] .'"><img src="'. ROOT .'images/rss.gif" width="16" height="16" alt="'. $rsschannels[$i][0] .'" /></a>'; 
     }
 
     echo '<p class="paging">'. $bfirst .'<span> / </span>'. $bprev .'<span> / </span>'. $bnext .'<span> / </span>'. $blast .'<span> / </span>'. sprintf(T_('Page %d of %d'), $page, $totalpages) ." ". $brss ." </p>\n";
index f6affc4cf9c622d84c85f7ca9de28198992aca20..c947ec3a154277eb4db10341dfc726cdae9839b7 100644 (file)
@@ -43,7 +43,7 @@ switch ($row['bStatus']) {
 <tr>
     <th align="left"><?php echo T_('Tags'); ?></th>
     <td class="scuttletheme">
-    <span dojoType="dojo.data.ItemFileReadStore" jsId="memberTagStore" url="<?php echo $GLOBALS['root']?>ajax/gettags.php"></span>
+    <span dojoType="dojo.data.ItemFileReadStore" jsId="memberTagStore" url="<?php echo ROOT?>ajax/gettags.php"></span>
     <input type="text" dojoType="dojox.form.MultiComboBox" id="tags" name="tags" size="75" value="<?php echo filter(implode(', ', $row['tags']), 'xml'); ?>" store="memberTagStore" delimiter="," searchAttr="tag" hasDownArrow="false"/></td>
     <td>&larr; <?php echo T_('Comma-separated'); ?></td>
 </tr>
index 6137dc07fc755adc94ad3d414fe32946c51b04eb..def2d725917aad4a4f84570ba1b49a1b52d39ad5 100644 (file)
@@ -27,7 +27,7 @@ window.onload = function() {
         <td></td>
     </tr>
     </table>
-    <p>&raquo; <a href="<?php echo $GLOBALS['root'] ?>password.php"><?php echo T_('Forgotten your password?') ?></p>
+    <p>&raquo; <a href="<?php echo ROOT ?>password.php"><?php echo T_('Forgotten your password?') ?></p>
 </form>
 
 <?php
index a128e70aa64e9a8a50648b7436355e9775daf0da..fef85f2b5b4fd0b6eab79f467242c533119e47da 100644 (file)
@@ -20,11 +20,12 @@ if ($recentTags && count($recentTags) > 0) {
     <?php
     $contents = '<p class="tags">';
 
-    if(strlen($user)==0) {
-       $cat_url = createURL('tags', '%2$s');
+    if(!isset($user)) {
+       $user = '';
+               $cat_url = createURL('tags', '%2$s');
     }
 
-    foreach ($recentTags as $row) {
+    foreach ($recentTags as $row) {            
         $entries = T_ngettext('bookmark', 'bookmarks', $row['bCount']);
         $contents .= '<a href="'. sprintf($cat_url, $user, filter($row['tag'], 'url')) .'" title="'. $row['bCount'] .' '. $entries .'" rel="tag" style="font-size:'. $row['size'] .'">'. filter($row['tag']) .'</a> ';
     }
index 92d8d593bf57be4ca7a50f557277e25cc19751f6..0b052e09832e0da9ff476be4c7b01d170e43399a 100644 (file)
@@ -13,7 +13,7 @@ if ($userservice->isLoggedOn()) {
         <li><a href="<?php echo createURL('watchlist', $cUsername); ?>"><?php echo T_('Watchlist'); ?></a></li>
        <li><a href="<?php echo $userservice->getProfileUrl($cUserId, $cUsername); ?>"><?php echo T_('Profile'); ?></a></li>
         <li><a href="<?php echo createURL('bookmarks', $cUsername . '?action=add'); ?>"><?php echo T_('Add a Bookmark'); ?></a></li>
-        <li class="access"><?php echo $cUsername?><a href="<?php echo $GLOBALS['root']; ?>?action=logout">(<?php echo T_('Log Out'); ?>)</a></li>
+        <li class="access"><?php echo $cUsername?><a href="<?php echo ROOT ?>?action=logout">(<?php echo T_('Log Out'); ?>)</a></li>
         <li><a href="<?php echo createURL('about'); ?>"><?php echo T_('About'); ?></a></li>
        <?php if($isAdmin): ?>\r
         <li><a href="<?php echo createURL('admin', ''); ?>"><?php echo '['.T_('Admin').']'; ?></a></li>\r
index 88a949a0445ca71c388214eb84bc9c607f799972..0d59dfb7fcca6b6b2460b089297b1e5181a692f1 100644 (file)
@@ -5,9 +5,9 @@
 <title><?php echo filter($GLOBALS['sitename'] . (isset($pagetitle) ? ': ' . $pagetitle : '')); ?></title>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <link rel="icon" type="image/png"
-       href="<?php echo $GLOBALS['root']; ?>icon.png" />
+       href="<?php echo ROOT ?>icon.png" />
 <link rel="stylesheet" type="text/css"
-       href="<?php echo $GLOBALS['root']; ?>scuttle.css" />
+       href="<?php echo ROOT ?>scuttle.css" />
 <?php
 if(isset($rsschannels)) {
        $size = count($rsschannels);
@@ -20,7 +20,7 @@ if(isset($rsschannels)) {
 <?php if (isset($loadjs)) :?>
 
 <script type="text/javascript"
-       src="<?php echo $GLOBALS['root']; ?>jsScuttle.php"></script>
+       src="<?php echo ROOT ?>jsScuttle.php"></script>
 
 <link rel="stylesheet" type="text/css"
        href="http://ajax.googleapis.com/ajax/libs/dojo/1.2/dijit/themes/nihilo/nihilo.css">
@@ -50,7 +50,7 @@ if(isset($_GET['popup'])) {
 ?>
 
 <div id="header" <?php echo $headerstyle; ?>>
-<h1><a href="<?php echo $GLOBALS['root']; ?>"><?php echo $GLOBALS['sitename']; ?></a></h1>
+<h1><a href="<?php echo ROOT ?>"><?php echo $GLOBALS['sitename']; ?></a></h1>
 <?php
 if(!isset($_GET['popup'])) {
        $this->includeTemplate('toolbar.inc');
index 6b54428754e4c111d1abdf6d5b8aa07103bb676e..acf6a966d1e9950bf9735db31d3903de7bc3a5c4 100644 (file)
@@ -1,9 +1,19 @@
 ==== UPGRADE instructions ====
 
-=== From version 0.89 to 0.90 ===
+
+=== From version 0.90 to 0.91 ===
 - Backup you database
 - Make a copy from your SemanticScuttle Web directory
 - Upgrade your database by following instructions ONE after ONE (order is important) :
+  * No intructions
+- Upgrade your current configuration file (config.inc.php) with respect to config.inc.php.example
+  * Delete last line : include_once('debug.inc.php');
+  * Add variable: $menu2Tags = array();
+  * Add variable: $debugMode = true; # if true, show debug messages
+
+=== From version 0.89 to 0.90 ===
+- Backup you database
+- Make a copy from your SemanticScuttle Web directory
 
 - Upgrade your current configuration file (config.inc.php) with respect to config.inc.php.example
 # add these lines under $enableWebsiteThumbnails = false; # enableWebsiteThumbnails {true|false}: