From 000cfd76ccd61b8b409713711b6e166d7442aa30 Mon Sep 17 00:00:00 2001 From: Mark Pemberton Date: Mon, 24 Jan 2011 21:49:33 -0500 Subject: [PATCH] More code cleanup --- data/templates/about.tpl.php | 10 +- data/templates/admin.tpl.php | 48 +- .../bookmarkcommondescriptionedit.tpl.php | 14 +- data/templates/bookmarks.tpl.php | 430 +++++++++--------- src/SemanticScuttle/DbService.php | 2 +- src/SemanticScuttle/Model/User.php | 8 +- src/SemanticScuttle/Service.php | 14 +- src/SemanticScuttle/Service/AuthUser.php | 6 +- src/SemanticScuttle/constants.php | 52 +-- src/SemanticScuttle/functions.php | 337 +++++++------- 10 files changed, 470 insertions(+), 451 deletions(-) diff --git a/data/templates/about.tpl.php b/data/templates/about.tpl.php index 7bff98d..2cf1b26 100644 --- a/data/templates/about.tpl.php +++ b/data/templates/about.tpl.php @@ -4,7 +4,7 @@ $this->includeTemplate($GLOBALS['top_include']); @@ -16,9 +16,11 @@ $this->includeTemplate($GLOBALS['top_include']); -isAdmin()): ?> -
  • SemanticScuttle v0.97.0
  • - +isAdmin()) { + echo "
  • SemanticScuttle v0.97.0
  • "; +} +?>

    diff --git a/data/templates/admin.tpl.php b/data/templates/admin.tpl.php index c8d47e8..29e7551 100644 --- a/data/templates/admin.tpl.php +++ b/data/templates/admin.tpl.php @@ -1,35 +1,35 @@ -includeTemplate($GLOBALS['top_include']); echo '

    '.T_('Users management').'

    '; - -echo '
      '; -foreach($users as $user) { - echo '
    1. '."\n"; - - echo ''; +echo '
        '; - if($user->getUsername() != $currentUser->getUsername()) { - echo '
        '; - echo ''.T_('Delete').''; - echo '
        '; - } - - echo ''."\n"; +foreach ($users as $user) { + echo '
      1. '."\n"; + + echo ''; + + if ($user->getUsername() != $currentUser->getUsername()) { + echo '
        '; + echo ''.T_('Delete').''; + echo '
        '; + } + + echo '
      2. '."\n"; } echo '
      '; ?>

      - +

      -includeTemplate('sidebar.tpl'); -$this->includeTemplate($GLOBALS['bottom_include']); - -?> +includeTemplate('sidebar.tpl'); +$this->includeTemplate($GLOBALS['bottom_include']); + +?> diff --git a/data/templates/bookmarkcommondescriptionedit.tpl.php b/data/templates/bookmarkcommondescriptionedit.tpl.php index af5909a..7b7dc68 100644 --- a/data/templates/bookmarkcommondescriptionedit.tpl.php +++ b/data/templates/bookmarkcommondescriptionedit.tpl.php @@ -26,13 +26,13 @@ window.onload = function() { - 0) { - echo T_('Last modification:').' '.$description['cdDatetime'].', '; - $lastUser = $userservice->getUser($description['uId']); - echo ''.$lastUser['username'].''; - } - ?> + 0) { + echo T_('Last modification:').' '.$description['cdDatetime'].', '; + $lastUser = $userservice->getUser($description['uId']); + echo ''.$lastUser['username'].''; + } + ?> diff --git a/data/templates/bookmarks.tpl.php b/data/templates/bookmarks.tpl.php index e32d3c9..d316655 100644 --- a/data/templates/bookmarks.tpl.php +++ b/data/templates/bookmarks.tpl.php @@ -32,12 +32,12 @@ $this->includeTemplate($GLOBALS['top_include']); include('search.menu.php'); ?> - +

      -isAdmin($userid) && $pageName != PAGE_WATCHLIST) : ?> +isAdmin($userid) && $pageName != PAGE_WATCHLIST) : ?>
      @@ -46,31 +46,31 @@ include('search.menu.php');

      getLastTagDescription($currenttag)) { - $cDescription = $cdservice->getLastTagDescription($currenttag); - echo nl2br(filter($cDescription['cdDescription'])); -} elseif(isset($hash) && $cdservice->getLastBookmarkDescription($hash)) { - $cDescription = $cdservice->getLastBookmarkDescription($hash); - echo nl2br(filter($cDescription['cdTitle'])). "
      "; - echo nl2br(filter($cDescription['cdDescription'])). "
      "; +if ($currenttag!= '' && $cdservice->getLastTagDescription($currenttag)) { + $cDescription = $cdservice->getLastTagDescription($currenttag); + echo nl2br(filter($cDescription['cdDescription'])); +} elseif (isset($hash) && $cdservice->getLastBookmarkDescription($hash)) { + $cDescription = $cdservice->getLastBookmarkDescription($hash); + echo nl2br(filter($cDescription['cdTitle'])). "
      "; + echo nl2br(filter($cDescription['cdDescription'])). "
      "; } //common tag description edit -if($userservice->isLoggedOn()) { - if($currenttag!= '' && ($GLOBALS['enableCommonTagDescriptionEditedByAll'] || $currentUser->isAdmin())) { - echo ' '; - echo !is_array($cDescription) || strlen($cDescription['cdDescription'])==0?T_('Edit the common description of this tag'):''; - echo ' '; - } elseif(isset($hash)) { - echo ' ('; - echo T_('Edit the common description of this bookmark').')'; - } +if ($userservice->isLoggedOn()) { + if ($currenttag!= '' && ($GLOBALS['enableCommonTagDescriptionEditedByAll'] || $currentUser->isAdmin())) { + echo ' '; + echo !is_array($cDescription) || strlen($cDescription['cdDescription'])==0?T_('Edit the common description of this tag'):''; + echo ' '; + } elseif (isset($hash)) { + echo ' ('; + echo T_('Edit the common description of this bookmark').')'; + } } ?>

      @@ -78,26 +78,26 @@ if($userservice->isLoggedOn()) { getUserByUsername($user); - if($tagservice->getDescription($currenttag, $userObject['uId'])) { ?> +if ($currenttag!= '' && $user!='') { + $userObject = $userservice->getUserByUsername($user); + if ($tagservice->getDescription($currenttag, $userObject['uId'])) { ?>

      getDescription($currenttag, $userObject['uId']); echo nl2br(filter($pDescription['tDescription'])); //personal tag description edit -if($userservice->isLoggedOn()) { - if($currenttag!= '') { - echo ' '; - echo strlen($pDescription['tDescription'])==0?T_('Edit your personal description of this tag'):''; - echo ' '; - } +if ($userservice->isLoggedOn()) { + if ($currenttag!= '') { + echo ' '; + echo strlen($pDescription['tDescription'])==0?T_('Edit your personal description of this tag'):''; + echo ' '; + } } ?>

      @@ -115,37 +115,37 @@ $dateSort = 'date_desc'; $titleSort = 'title_asc'; $votingSort = 'voting_desc'; -switch(getSortOrder()) { +switch (getSortOrder()) { case 'date_asc': - $dateArrow = ' ↑'; - $dateSort = 'date_desc'; - break; + $dateArrow = ' ↑'; + $dateSort = 'date_desc'; + break; case 'title_asc': - $titleArrow = ' ↑'; - $titleSort = 'title_desc'; - break; + $titleArrow = ' ↑'; + $titleSort = 'title_desc'; + break; case 'title_desc': - $titleArrow = ' ↓'; - $titleSort = 'title_asc'; - break; + $titleArrow = ' ↓'; + $titleSort = 'title_asc'; + break; case 'voting_asc': - $votingArrow = ' ↑'; - $votingSort = 'voting_desc'; - break; + $votingArrow = ' ↑'; + $votingSort = 'voting_desc'; + break; case 'voting_desc': - $votingArrow = ' ↓'; - $votingSort = 'voting_asc'; - break; + $votingArrow = ' ↓'; + $votingSort = 'voting_asc'; + break; case 'date_desc': default: - $dateArrow = ' ↓'; - $dateSort = 'date_asc'; - break; + $dateArrow = ' ↓'; + $dateSort = 'date_asc'; + break; } ?> @@ -159,73 +159,73 @@ default: '; - echo T_('Bookmarks from other users for this tag').''; - //echo T_(' for these tags'); - } else if ($userservice->isLoggedOn()){ - echo ' - '; - echo ''; - echo T_('Only your bookmarks for this tag').''; - //echo T_(' for these tags'); - } + if ($user!= '') { + echo ' - '; + echo ''; + echo T_('Bookmarks from other users for this tag').''; + //echo T_(' for these tags'); + } else if ($userservice->isLoggedOn()){ + echo ' - '; + echo ''; + echo T_('Only your bookmarks for this tag').''; + //echo T_(' for these tags'); + } } ?>

      '. T_('First') .''; - $bprev = ''. T_('Previous') .''; - } else { - $prev = $page - 1; - $prev = 'page='. $prev; - $start = ($page - 1) * $perpage; - $bfirst= ''. T_('First') .''; - $bprev = ''. T_('Previous') .''; - } + // Previous + $perpage = getPerPageCount($currentUser); + if (!$page || $page < 2) { + $page = 1; + $start = 0; + $bfirst = ''. T_('First') .''; + $bprev = ''. T_('Previous') .''; + } else { + $prev = $page - 1; + $prev = 'page='. $prev; + $start = ($page - 1) * $perpage; + $bfirst= ''. T_('First') .''; + $bprev = ''. T_('Previous') .''; + } - // Next - $next = $page + 1; - $totalpages = ceil($total / $perpage); - if (count($bookmarks) < $perpage || $perpage * $page == $total) { - $bnext = ''. T_('Next') .''; - $blast = ''. T_('Last') ."\n"; - } else { - $bnext = ''. T_('Next') .''; - $blast = ''. T_('Last') ."\n"; - } + // Next + $next = $page + 1; + $totalpages = ceil($total / $perpage); + if (count($bookmarks) < $perpage || $perpage * $page == $total) { + $bnext = ''. T_('Next') .''; + $blast = ''. T_('Last') ."\n"; + } else { + $bnext = ''. T_('Next') .''; + $blast = ''. T_('Last') ."\n"; + } - // RSS - $brss = ''; - $size = count($rsschannels); - for ($i = 0; $i < $size; $i++) { - $brss = '' . '' . htmlspecialchars($rsschannels[$i][0]) .'' . ''; - } + } - $pagesBanner = '

      '. $bfirst .' / '. $bprev .' / '. $bnext .' / '. $blast .' / '. sprintf(T_('Page %d of %d'), $page, $totalpages) ." ". $brss ."

      \n"; + $pagesBanner = '

      '. $bfirst .' / '. $bprev .' / '. $bnext .' / '. $blast .' / '. sprintf(T_('Page %d of %d'), $page, $totalpages) ." ". $brss ."

      \n"; - if (getPerPageCount($currentUser) > 10) { - echo $pagesBanner; // display a page banner if too many bookmarks to manage - } + if (getPerPageCount($currentUser) > 10) { + echo $pagesBanner; // display a page banner if too many bookmarks to manage + } ?> @@ -253,87 +253,87 @@ if ($currenttag!= '') { $watchedNames = null; } - foreach ($bookmarks as $key => &$row) { - switch ($row['bStatus']) { - case 0: - $access = ''; - break; - case 1: - $access = ' shared'; - break; - case 2: - $access = ' private'; - break; - } + foreach ($bookmarks as $key => &$row) { + switch ($row['bStatus']) { + case 0: + $access = ''; + break; + case 1: + $access = ' shared'; + break; + case 2: + $access = ' private'; + break; + } - $cats = ''; - $tagsForCopy = ''; - $tags = $row['tags']; - foreach ($tags as $tkey => &$tag) { - $tagcaturl = sprintf( - $cat_url, - filter($row['username'], 'url'), - filter($tag, 'url') - ); - $cats .= sprintf( - ', ', - $tagcaturl, filter($tag) - ); - $tagsForCopy .= $tag . ','; - } - $cats = substr($cats, 0, -2); - if ($cats != '') { - $cats = T_('Tags:') . ' ' . $cats; - } + $cats = ''; + $tagsForCopy = ''; + $tags = $row['tags']; + foreach ($tags as $tkey => &$tag) { + $tagcaturl = sprintf( + $cat_url, + filter($row['username'], 'url'), + filter($tag, 'url') + ); + $cats .= sprintf( + ', ', + $tagcaturl, filter($tag) + ); + $tagsForCopy .= $tag . ','; + } + $cats = substr($cats, 0, -2); + if ($cats != '') { + $cats = T_('Tags:') . ' ' . $cats; + } - // Edit and delete links - $edit = ''; - if ($bookmarkservice->editAllowed($row)) { - $edit = ' - ' + // Edit and delete links + $edit = ''; + if ($bookmarkservice->editAllowed($row)) { + $edit = ' - ' . T_('Edit') . '' . ''; - } + } - // Last update - $update = ' ('. date($GLOBALS['shortdate'], strtotime($row['bModified'])). ') '; + // Last update + $update = ' ('. date($GLOBALS['shortdate'], strtotime($row['bModified'])). ') '; - // User attribution - $copy = ' ' . T_('by') . ' '; - if ($userservice->isLoggedOn() - && $currentUser->getUsername() == $row['username'] + // User attribution + $copy = ' ' . T_('by') . ' '; + if ($userservice->isLoggedOn() + && $currentUser->getUsername() == $row['username'] ) { - $copy .= T_('you'); - } else { - $copy .= '' + $copy .= T_('you'); + } else { + $copy .= '' . $row['username'] . ''; - } + } - // Udders! - if (!isset($hash)) { - $others = $otherCounts[$row['bAddress']]; - $ostart = ''; - $oend = ''; - switch ($others) { - case 0: - break; - case 1: - $copy .= sprintf(T_(' and %s1 other%s'), $ostart, $oend); - break; - default: - $copy .= sprintf(T_(' and %2$s%1$s others%3$s'), $others, $ostart, $oend); - } - } + // Udders! + if (!isset($hash)) { + $others = $otherCounts[$row['bAddress']]; + $ostart = ''; + $oend = ''; + switch ($others) { + case 0: + break; + case 1: + $copy .= sprintf(T_(' and %s1 other%s'), $ostart, $oend); + break; + default: + $copy .= sprintf(T_(' and %2$s%1$s others%3$s'), $others, $ostart, $oend); + } + } - // Copy link - if ($userservice->isLoggedOn() + // Copy link + if ($userservice->isLoggedOn() && ($currentUser->getId() != $row['uId']) && !$existence[$row['bAddress']] ) { - $copy .= ' - getUsername() @@ -341,40 +341,40 @@ if ($currenttag!= '') { . '" title="'.T_('Copy this bookmark to YOUR bookmarks.').'">' . T_('Copy') . ''; - } + } - // Nofollow option - $rel = ''; - if ($GLOBALS['nofollow']) { - $rel = ' rel="nofollow"'; - } + // Nofollow option + $rel = ''; + if ($GLOBALS['nofollow']) { + $rel = ' rel="nofollow"'; + } - $address = filter($row['bAddress']); - $oaddress = $address; - // Redirection option - if ($GLOBALS['useredir']) { - $address = $GLOBALS['url_redir'] . $address; - } + $address = filter($row['bAddress']); + $oaddress = $address; + // Redirection option + if ($GLOBALS['useredir']) { + $address = $GLOBALS['url_redir'] . $address; + } - // Admin specific design - if ($userservice->isAdmin($row['username']) && $GLOBALS['enableAdminColors']) { - $adminBgClass = ' class="adminBackground"'; - $adminStar = ' '; - } else { - $adminBgClass = ''; - $adminStar = ''; - } + // Admin specific design + if ($userservice->isAdmin($row['username']) && $GLOBALS['enableAdminColors']) { + $adminBgClass = ' class="adminBackground"'; + $adminStar = ' '; + } else { + $adminBgClass = ''; + $adminStar = ''; + } - // Private Note (just visible by the owner and his/her contacts) + // Private Note (just visible by the owner and his/her contacts) if ($watchedNames !== null && ($currentUser->getId() == $row['uId'] || in_array($row['username'], $watchedNames) ) ) { - $privateNoteField = $row['bPrivateNote']; - } else { - $privateNoteField = ''; - } + $privateNoteField = $row['bPrivateNote']; + } else { + $privateNoteField = ''; + } if ($GLOBALS['enableVoting'] && $GLOBALS['hideBelowVoting'] !== null && $row['bVoting'] < $GLOBALS['hideBelowVoting'] @@ -382,57 +382,57 @@ if ($currenttag!= '') { $access .= ' below-threshold'; } - // Output - echo '
    2. '."\n"; + // Output + echo '
    3. '."\n"; include 'bookmarks-thumbnail.inc.tpl.php'; include 'bookmarks-vote.inc.tpl.php'; - echo ' ' . "\n"; + echo ' ' . "\n"; - echo ' \n"; - echo "
    4. \n"; - } - ?> + echo " \n"; + } + ?>
    - 7) { - echo '

    '.T_('Top of the page').'

    '; - } - echo $pagesBanner; // display previous and next links pages + RSS link + 7) { + echo '

    '.T_('Top of the page').'

    '; + } + echo $pagesBanner; // display previous and next links pages + RSS link } else { - echo '

    '.T_('No bookmarks available').'

    '; + echo '

    '.T_('No bookmarks available').'

    '; } $this->includeTemplate('sidebar.tpl'); $this->includeTemplate($GLOBALS['bottom_include']); diff --git a/src/SemanticScuttle/DbService.php b/src/SemanticScuttle/DbService.php index 875ee98..c950baf 100644 --- a/src/SemanticScuttle/DbService.php +++ b/src/SemanticScuttle/DbService.php @@ -16,7 +16,7 @@ * * @category Bookmarking * @package SemanticScuttle - * @author Christian Weiske + * @author Christian Weiske * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ diff --git a/src/SemanticScuttle/Model/User.php b/src/SemanticScuttle/Model/User.php index d9b40b5..e4cc638 100644 --- a/src/SemanticScuttle/Model/User.php +++ b/src/SemanticScuttle/Model/User.php @@ -121,7 +121,7 @@ class SemanticScuttle_Model_User public function getHomepage() { // Look for value only if not already set - if(!isset($this->homepage)) { + if (!isset($this->homepage)) { $us = SemanticScuttle_Service_Factory::get('User'); $user = $us->getUser($this->id); $this->homepage = $user['homepage']; @@ -137,7 +137,7 @@ class SemanticScuttle_Model_User public function getContent() { // Look for value only if not already set - if(!isset($this->content)) { + if (!isset($this->content)) { $us = SemanticScuttle_Service_Factory::get('User'); $user = $us->getUser($this->id); $this->content = $user['uContent']; @@ -154,7 +154,7 @@ class SemanticScuttle_Model_User public function getDatetime() { // Look for value only if not already set - if(!isset($this->content)) { + if (!isset($this->content)) { $us = SemanticScuttle_Service_Factory::get('User'); $user = $us->getUser($this->id); $this->datetime = $user['uDatetime']; @@ -170,7 +170,7 @@ class SemanticScuttle_Model_User public function isAdmin() { // Look for value only if not already set - if(!isset($this->isAdmin)) { + if (!isset($this->isAdmin)) { $us = SemanticScuttle_Service_Factory::get('User'); $this->isAdmin = $us->isAdmin($this->username); } diff --git a/src/SemanticScuttle/Service.php b/src/SemanticScuttle/Service.php index 1afb353..5f2090f 100644 --- a/src/SemanticScuttle/Service.php +++ b/src/SemanticScuttle/Service.php @@ -33,8 +33,6 @@ class SemanticScuttle_Service */ protected $db; - - /** * Returns the single service instance * @@ -47,14 +45,14 @@ class SemanticScuttle_Service * * @return SemanticScuttle_Service */ - public static function getInstance($db) + public static function getInstance($db) { - static $instance; - if (!isset($instance)) { + static $instance; + if (!isset($instance)) { $instance = new self($db); } - return $instance; - } + return $instance; + } } -?> \ No newline at end of file +?> diff --git a/src/SemanticScuttle/Service/AuthUser.php b/src/SemanticScuttle/Service/AuthUser.php index 479b68a..05288dd 100644 --- a/src/SemanticScuttle/Service/AuthUser.php +++ b/src/SemanticScuttle/Service/AuthUser.php @@ -86,7 +86,7 @@ class SemanticScuttle_Service_AuthUser extends SemanticScuttle_Service_User /** * Create new instance * - * @var sql_db $db Database object + * @param sql_db $db Database object */ protected function __construct($db) { @@ -208,7 +208,7 @@ class SemanticScuttle_Service_AuthUser extends SemanticScuttle_Service_User } return true; - } + } @@ -229,4 +229,4 @@ class SemanticScuttle_Service_AuthUser extends SemanticScuttle_Service_User } } -?> \ No newline at end of file +?> diff --git a/src/SemanticScuttle/constants.php b/src/SemanticScuttle/constants.php index 95c4384..07111c2 100644 --- a/src/SemanticScuttle/constants.php +++ b/src/SemanticScuttle/constants.php @@ -5,29 +5,29 @@ */ // Debug managament -if(isset($GLOBALS['debugMode'])) { - define('DEBUG_MODE', $GLOBALS['debugMode']); - define('DEBUG_EXTRA', $GLOBALS['debugMode']); // Constant used exclusively into db/ directory +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) { - //we eliminate possible sscuttle subfolders (like gsearch for example) - if ($piece != '' && !strstr($piece, '.php') && $piece != 'gsearch') { - $rootTmp .= $piece .'/'; - } - } - if (($rootTmp != '/') && (substr($rootTmp, -1, 1) != '/')) { - $rootTmp .= '/'; - } + $pieces = explode('/', $_SERVER['SCRIPT_NAME']); + + $rootTmp = '/'; + foreach ($pieces as $piece) { + //we eliminate possible sscuttle subfolders (like gsearch for example) + if ($piece != '' && !strstr($piece, '.php') && $piece != 'gsearch') { + $rootTmp .= $piece .'/'; + } + } + if (($rootTmp != '/') && (substr($rootTmp, -1, 1) != '/')) { + $rootTmp .= '/'; + } - define('ROOT', 'http://'. $_SERVER['HTTP_HOST'] . $rootTmp); + define('ROOT', 'http://'. $_SERVER['HTTP_HOST'] . $rootTmp); } else { - define('ROOT', $GLOBALS['root']); + define('ROOT', $GLOBALS['root']); } // Error codes @@ -49,14 +49,14 @@ define('INSTALLATION_ID', md5($GLOBALS['dbname'].$GLOBALS['tableprefix'])); // Correct bugs with PATH_INFO (maybe for Apache 1 or CGI) -- for 1&1 host... if (isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO'])) { - if(strlen($_SERVER["PATH_INFO"]) diff --git a/src/SemanticScuttle/functions.php b/src/SemanticScuttle/functions.php index 84e9c5f..870079e 100644 --- a/src/SemanticScuttle/functions.php +++ b/src/SemanticScuttle/functions.php @@ -18,34 +18,36 @@ // Converts tags: // - direction = out: convert spaces to underscores; // - direction = in: convert underscores to spaces. -function convertTag($tag, $direction = 'out') { - if ($direction == 'out') { - $tag = str_replace(' ', '_', $tag); - } else { - $tag = str_replace('_', ' ', $tag); - } - return $tag; +function convertTag($tag, $direction = 'out') +{ + if ($direction == 'out') { + $tag = str_replace(' ', '_', $tag); + } else { + $tag = str_replace('_', ' ', $tag); + } + return $tag; } -function filter($data, $type = NULL) { - if (is_string($data)) { - $data = trim($data); - $data = stripslashes($data); - switch ($type) { - case 'url': - $data = rawurlencode($data); - break; - default: - $data = htmlspecialchars($data); - break; - } - } else if (is_array($data)) { - foreach(array_keys($data) as $key) { - $row =& $data[$key]; - $row = filter($row, $type); - } - } - return $data; +function filter($data, $type = null) +{ + if (is_string($data)) { + $data = trim($data); + $data = stripslashes($data); + switch ($type) { + case 'url': + $data = rawurlencode($data); + break; + default: + $data = htmlspecialchars($data); + break; + } + } else if (is_array($data)) { + foreach (array_keys($data) as $key) { + $row =& $data[$key]; + $row = filter($row, $type); + } + } + return $data; } /** @@ -60,63 +62,67 @@ function filter($data, $type = NULL) { */ function getPerPageCount($userObject = null) { - global $defaultPerPage, $defaultPerPageForAdmins; + global $defaultPerPage, $defaultPerPageForAdmins; - if (isset($defaultPerPageForAdmins) - && $userObject != null && $userObject->isAdmin() + if (isset($defaultPerPageForAdmins) + && $userObject != null + && $userObject->isAdmin() ) { - return $defaultPerPageForAdmins; - } else { - return $defaultPerPage; - } + return $defaultPerPageForAdmins; + } else { + return $defaultPerPage; + } } -function getSortOrder($override = NULL) { - global $defaultOrderBy; +function getSortOrder($override = null) +{ + global $defaultOrderBy; - if (isset($_GET['sort'])) { - return preg_replace('/[^a-z_]/', '', $_GET['sort']); - } else if (isset($override)) { - return $override; - } else { - return $defaultOrderBy; - } + if (isset($_GET['sort'])) { + return preg_replace('/[^a-z_]/', '', $_GET['sort']); + } elseif (isset($override)) { + return $override; + } else { + return $defaultOrderBy; + } } -function multi_array_search($needle, $haystack) { - if (is_array($haystack)) { - foreach(array_keys($haystack) as $key) { - $value =& $haystack[$key]; - $result = multi_array_search($needle, $value); - if (is_array($result)) { - $return = $result; - array_unshift($return, $key); - return $return; - } elseif ($result == true) { - $return[] = $key; - return $return; - } - } - return false; - } else { - if ($needle === $haystack) { - return true; - } else { - return false; - } - } +function multi_array_search($needle, $haystack) +{ + if (is_array($haystack)) { + foreach (array_keys($haystack) as $key) { + $value =& $haystack[$key]; + $result = multi_array_search($needle, $value); + if (is_array($result)) { + $return = $result; + array_unshift($return, $key); + return $return; + } elseif ($result == true) { + $return[] = $key; + return $return; + } + } + return false; + } else { + if ($needle === $haystack) { + return true; + } else { + return false; + } + } } -function createURL($page = '', $ending = '') { - global $cleanurls; - if (!$cleanurls && $page != '') { - $page .= '.php'; - } - if(strlen($ending)>0) { - return ROOT . $page .'/'. $ending; - } else { - return ROOT . $page; - } +function createURL($page = '', $ending = '') +{ + global $cleanurls; + if (!$cleanurls && $page != '') { + $page .= '.php'; + } + if (strlen($ending)>0) { + return ROOT . $page .'/'. $ending; + } else { + return ROOT . $page; + } } /** * Creates a "vote for/against this bookmark" URL. @@ -139,116 +145,129 @@ function createVoteURL($for, $bId) } /* Shorten a string like a URL for example by cutting the middle of it */ -function shortenString($string, $maxSize=75) { - $output = ''; - if(strlen($string) > $maxSize) { - $output = substr($string, 0, $maxSize/2).'...'.substr($string, -$maxSize/2); - } else { - $output = $string; - } - return $output; +function shortenString($string, $maxSize=75) +{ + $output = ''; + if (strlen($string) > $maxSize) { + $output = substr($string, 0, $maxSize/2).'...'.substr($string, -$maxSize/2); + } else { + $output = $string; + } + return $output; } /* Check url format and check online if the url is a valid page (Not a 404 error for example) */ -function checkUrl($url, $checkOnline = true) { - //check format - if(!preg_match("#(ht|f)tp(s?)\://\S+\.\S+#i",$url)) { - return false; - } +function checkUrl($url, $checkOnline = true) +{ + //check format + if (!preg_match("#(ht|f)tp(s?)\://\S+\.\S+#i", $url)) { + return false; + } - if($checkOnline) { - //look if the page doesn't return a void or 40X or 50X HTTP code error - $h = @get_headers($url); - if(is_array($h) && strpos($h[0], '40') === false && strpos($h[0], '50') === false) { - return true; - } else { - return false; - } - } else { - return true; - } + if ($checkOnline) { + //look if the page doesn't return a void or 40X or 50X HTTP code error + $h = @get_headers($url); + if (is_array($h) && strpos($h[0], '40') === false && strpos($h[0], '50') === false) { + return true; + } else { + return false; + } + } else { + return true; + } } /* Returns a concatenated String * including all the tags from the array $arrayTags (excepted of the $exceptedTag) * separated by the $separator. * */ -function aggregateTags($arrayTags, $separator = ' + ', $exceptedTag = '') { - $output = ''; +function aggregateTags($arrayTags, $separator = ' + ', $exceptedTag = '') +{ + $output = ''; - for($i = 0; $isql_error(); - $debug_text = ''; + // 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_MODE && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) { + $sql_error = is_null($db) ? '' : $db->sql_error(); + $debug_text = ''; - if ($sql_error['message'] != '') - $debug_text .= '

    '. T_('SQL Error') .' : '. $sql_error['code'] .' '. $sql_error['message']; + if ($sql_error['message'] != '') { + $debug_text .= '

    '. T_('SQL Error') .' : '. $sql_error['code'] .' '. $sql_error['message']; + } - if ($sql_store != '') - $debug_text .= '

    '. $sql_store; + if ($sql_store != '') { + $debug_text .= '

    '. $sql_store; + } - if ($err_line != '' && $err_file != '') - $debug_text .= '

    '. T_('Line') .' : '. $err_line .'
    '. T_('File') .' :'. $err_file; + if ($err_line != '' && $err_file != '') { + $debug_text .= '

    '. T_('Line') .' : '. $err_line .'
    '. T_('File') .' :'. $err_file; + } - debug_print_backtrace(); - } + debug_print_backtrace(); + } - switch($msg_code) { - case GENERAL_MESSAGE: - if ($msg_title == '') - $msg_title = T_('Information'); - break; + switch($msg_code) { + case GENERAL_MESSAGE: + if ($msg_title == '') { + $msg_title = T_('Information'); + } + break; - case CRITICAL_MESSAGE: - if ($msg_title == '') - $msg_title = T_('Critical Information'); - break; + case CRITICAL_MESSAGE: + if ($msg_title == '') { + $msg_title = T_('Critical Information'); + } + break; - case GENERAL_ERROR: - if ($msg_text == '') - $msg_text = T_('An error occured'); + case GENERAL_ERROR: + if ($msg_text == '') { + $msg_text = T_('An error occured'); + } + if ($msg_title == '') { + $msg_title = T_('General Error'); + } + break; - if ($msg_title == '') - $msg_title = T_('General Error'); - break; + case CRITICAL_ERROR: + // Critical errors mean we cannot rely on _ANY_ DB information being + // available so we're going to dump out a simple echo'd statement - case CRITICAL_ERROR: - // Critical errors mean we cannot rely on _ANY_ DB information being - // available so we're going to dump out a simple echo'd statement + if ($msg_text == '') { + $msg_text = T_('An critical error occured'); + } + if ($msg_title == '') { + $msg_title = T_('Critical Error'); + } + break; + } - if ($msg_text == '') - $msg_text = T_('An critical error occured'); + // 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_MODE && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) { + if ($debug_text != '') { + $msg_text = $msg_text . '

    '. T_('DEBUG MODE') .''. $debug_text; + } + } - if ($msg_title == '') - $msg_title = T_('Critical Error'); - break; - } - - // 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_MODE && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) { - if ($debug_text != '') - $msg_text = $msg_text . '

    '. T_('DEBUG MODE') .''. $debug_text; - } - - echo "\n\n". $msg_title ."\n

    \n". $msg_text ."\n"; - exit; + echo "\n\n". $msg_title ."\n

    \n". $msg_text ."\n"; + exit; } ?>