2006-03-10 21:17:18 +01:00
< ? php
// +-----------------------------------------------------------------------+
2008-04-05 00:57:23 +02:00
// | Piwigo - a PHP based picture gallery |
// +-----------------------------------------------------------------------+
2009-01-05 00:28:36 +01:00
// | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org |
2008-04-05 00:57:23 +02:00
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation |
// | |
// | This program is distributed in the hope that it will be useful, but |
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
2006-03-10 21:17:18 +01:00
// | along with this program; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA. |
// +-----------------------------------------------------------------------+
function check_upgrade ()
{
2008-11-06 15:44:51 +01:00
if ( defined ( 'PHPWG_IN_UPGRADE' ))
2006-03-10 21:17:18 +01:00
{
2008-11-06 15:44:51 +01:00
return PHPWG_IN_UPGRADE ;
2006-03-10 21:17:18 +01:00
}
2008-11-06 15:44:51 +01:00
return false ;
2006-03-10 21:17:18 +01:00
}
2007-09-19 07:26:58 +02:00
// concerning upgrade, we use the default tables
function prepare_conf_upgrade ()
{
2007-09-21 23:23:09 +02:00
global $prefixeTable ;
2007-09-19 07:26:58 +02:00
2007-09-21 23:23:09 +02:00
// $conf is not used for users tables
// define cannot be re-defined
define ( 'CATEGORIES_TABLE' , $prefixeTable . 'categories' );
define ( 'COMMENTS_TABLE' , $prefixeTable . 'comments' );
define ( 'CONFIG_TABLE' , $prefixeTable . 'config' );
define ( 'FAVORITES_TABLE' , $prefixeTable . 'favorites' );
define ( 'GROUP_ACCESS_TABLE' , $prefixeTable . 'group_access' );
define ( 'GROUPS_TABLE' , $prefixeTable . 'groups' );
define ( 'HISTORY_TABLE' , $prefixeTable . 'history' );
define ( 'HISTORY_SUMMARY_TABLE' , $prefixeTable . 'history_summary' );
define ( 'IMAGE_CATEGORY_TABLE' , $prefixeTable . 'image_category' );
define ( 'IMAGES_TABLE' , $prefixeTable . 'images' );
define ( 'SESSIONS_TABLE' , $prefixeTable . 'sessions' );
define ( 'SITES_TABLE' , $prefixeTable . 'sites' );
define ( 'USER_ACCESS_TABLE' , $prefixeTable . 'user_access' );
define ( 'USER_GROUP_TABLE' , $prefixeTable . 'user_group' );
define ( 'USERS_TABLE' , $prefixeTable . 'users' );
define ( 'USER_INFOS_TABLE' , $prefixeTable . 'user_infos' );
define ( 'USER_FEED_TABLE' , $prefixeTable . 'user_feed' );
define ( 'WAITING_TABLE' , $prefixeTable . 'waiting' );
define ( 'RATE_TABLE' , $prefixeTable . 'rate' );
define ( 'USER_CACHE_TABLE' , $prefixeTable . 'user_cache' );
define ( 'USER_CACHE_CATEGORIES_TABLE' , $prefixeTable . 'user_cache_categories' );
define ( 'CADDIE_TABLE' , $prefixeTable . 'caddie' );
define ( 'UPGRADE_TABLE' , $prefixeTable . 'upgrade' );
define ( 'SEARCH_TABLE' , $prefixeTable . 'search' );
define ( 'USER_MAIL_NOTIFICATION_TABLE' , $prefixeTable . 'user_mail_notification' );
define ( 'TAGS_TABLE' , $prefixeTable . 'tags' );
define ( 'IMAGE_TAG_TABLE' , $prefixeTable . 'image_tag' );
define ( 'PLUGINS_TABLE' , $prefixeTable . 'plugins' );
define ( 'OLD_PERMALINKS_TABLE' , $prefixeTable . 'old_permalinks' );
2007-09-19 07:26:58 +02:00
}
2006-03-10 21:17:18 +01:00
2008-11-01 22:19:20 +01:00
// Deactivate all non-standard plugins
function deactivate_non_standard_plugins ()
{
global $page ;
$standard_plugins = array (
'add_index' ,
'admin_advices' ,
'admin_multi_view' ,
'c13y_upgrade' ,
'event_tracer' ,
'language_switch' ,
'LocalFilesEditor'
);
$query = '
SELECT id
FROM '.PREFIX_TABLE.' plugins
WHERE state = " active "
AND id NOT IN ( " ' . implode(' " , " ', $standard_plugins ) . ' " )
; ' ;
$result = pwg_query ( $query );
$plugins = array ();
2009-11-20 15:17:04 +01:00
while ( $row = pwg_db_fetch_assoc ( $result ))
2008-11-01 22:19:20 +01:00
{
array_push ( $plugins , $row [ 'id' ]);
}
if ( ! empty ( $plugins ))
{
$query = '
UPDATE '.PREFIX_TABLE.' plugins
SET state = " inactive "
WHERE id IN ( " ' . implode(' " , " ', $plugins ) . ' " )
; ' ;
2008-11-19 16:44:04 +01:00
pwg_query ( $query );
2008-11-01 22:19:20 +01:00
2008-11-03 20:52:33 +01:00
array_push ( $page [ 'infos' ],
2010-03-02 15:54:22 +01:00
l10n ( 'As a precaution, following plugins have been deactivated. You must check for plugins upgrade before reactiving them:' ) . '<p><i>' . implode ( ', ' , $plugins ) . '</i></p>' );
2008-11-01 22:19:20 +01:00
}
}
2008-11-06 15:44:51 +01:00
// Check access rights
function check_upgrade_access_rights ( $current_release , $username , $password )
{
global $conf , $page ;
2009-10-09 16:41:30 +02:00
if ( !@ get_magic_quotes_gpc ())
2008-11-07 14:54:35 +01:00
{
2009-11-20 15:17:04 +01:00
$username = pwg_db_real_escape_string ( $username );
2008-11-07 14:54:35 +01:00
}
2008-11-23 00:33:17 +01:00
if ( version_compare ( $current_release , '2.0' , '<' ))
{
$username = utf8_decode ( $username );
$password = utf8_decode ( $password );
}
if ( version_compare ( $current_release , '1.5' , '<' ))
2008-11-06 15:44:51 +01:00
{
$query = '
SELECT password , status
2008-11-07 14:54:35 +01:00
FROM '.USERS_TABLE.'
2008-11-06 15:44:51 +01:00
WHERE username = " '. $username .' "
; ' ;
}
else
{
$query = '
SELECT u . password , ui . status
2009-11-16 20:17:01 +01:00
FROM '.USERS_TABLE.' AS u
2008-11-07 14:54:35 +01:00
INNER JOIN '.USER_INFOS_TABLE.' AS ui
ON u . '.$conf[' user_fields '][' id '].' = ui . user_id
2008-11-06 15:44:51 +01:00
WHERE '.$conf[' user_fields '][' username '].' = " '. $username .' "
; ' ;
}
2009-11-20 15:17:04 +01:00
$row = pwg_db_fetch_assoc ( pwg_query ( $query ));
2008-11-06 15:44:51 +01:00
if ( ! isset ( $conf [ 'pass_convert' ]))
{
$conf [ 'pass_convert' ] = create_function ( '$s' , 'return md5($s);' );
}
2008-11-23 00:33:17 +01:00
if ( $row [ 'password' ] != $conf [ 'pass_convert' ]( $password ))
2008-11-06 15:44:51 +01:00
{
2010-03-02 15:54:22 +01:00
array_push ( $page [ 'errors' ], l10n ( 'Invalid password!' ));
2008-11-06 15:44:51 +01:00
}
elseif ( $row [ 'status' ] != 'admin' and $row [ 'status' ] != 'webmaster' )
{
array_push ( $page [ 'errors' ], l10n ( 'You do not have access rights to run upgrade' ));
}
else
{
define ( 'PHPWG_IN_UPGRADE' , true );
}
}
2009-02-13 14:01:03 +01:00
/**
* which upgrades are available ?
*
* @ return array
*/
function get_available_upgrade_ids ()
{
$upgrades_path = PHPWG_ROOT_PATH . 'install/db' ;
$available_upgrade_ids = array ();
if ( $contents = opendir ( $upgrades_path ))
{
while (( $node = readdir ( $contents )) !== false )
{
if ( is_file ( $upgrades_path . '/' . $node )
and preg_match ( '/^(.*?)-database\.php$/' , $node , $match ))
{
array_push ( $available_upgrade_ids , $match [ 1 ]);
}
}
}
natcasesort ( $available_upgrade_ids );
return $available_upgrade_ids ;
}
/**
* returns true if there are available upgrade files
*/
function check_upgrade_feed ()
{
// retrieve already applied upgrades
$query = '
SELECT id
FROM '.UPGRADE_TABLE.'
; ' ;
$applied = array_from_query ( $query , 'id' );
// retrieve existing upgrades
$existing = get_available_upgrade_ids ();
// which upgrades need to be applied?
return ( count ( array_diff ( $existing , $applied )) > 0 );
}
?>