#!/bin/bash
###############################################
# Written by George Liu / eva2000 vbtechsupport.com
###############################################
# Please BACKUP your vB4.x php files before running
# script in ssh telnet using cp command with archive flag
# cp -a /home/username/public_html/forums /home/username/public_html/forums_backupdir
# end up with backup of your vB forum directory with 
# all permissions and user/group permissions intact
# at
# /home/username/public_html/forums_backupdir
###############################################
# run TESTMODE yes first to check the right path and files 
# are being changed
# then set TESTMODE='n' to do a global replace on all 
# your vB php files
# MAKE SURE to set variable VBINSTALLDIR to you vB installation
# directory i.e. /home/username/public_html/vb420pl3
###############################################
TESTMODE='y'
VBINSTALLDIR='/home/username/public_html/vb421'
FILES=$(cd $VBINSTALLDIR; grep -R 'error_reporting(E_ALL & ~E_NOTICE);' * | awk -F ":" '{print $1}')
declare -a array
array=(${FILES})

for i in ${array[@]} 
do
echo "----------------------------------------------------------------------------"
echo "sed -i 's/error_reporting(E_ALL & ~E_NOTICE);/error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_STRICT);/g' ${VBINSTALLDIR}/${i}"

if [ "$TESTMODE" == 'n' ]; then
sed -i 's/error_reporting(E_ALL \& \~E_NOTICE);/error_reporting(E_ALL \& \~E_DEPRECATED \& \~E_NOTICE \& \~E_STRICT);/g' ${VBINSTALLDIR}/${i}
fi
echo "----------------------------------------------------------------------------"
echo "grep 'error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_STRICT);' ${VBINSTALLDIR}/${i}"

if [ "$TESTMODE" == 'n' ]; then
grep 'error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_STRICT);' ${VBINSTALLDIR}/${i}
fi
echo "----------------------------------------------------------------------------"
done

if [ "$TESTMODE" == 'n' ]; then

# thanks Paul for updated fix
echo "fixing vb/ckeditor.php"

sed -i 's/htmlspecialchars($value)/htmlspecialchars_uni($value)/g' ${VBINSTALLDIR}/vb/ckeditor.php

echo "fixing GD compatibility"

sed -i "s/imagejpeg(\$image, '', \$quality);/imagejpeg(\$image, null, \$quality);/g" ${VBINSTALLDIR}/includes/class_image.php

echo "Disable display_errors in init.php"

sed -i "s/ini_set('display_errors', true)/ini_set('display_errors', false)/g" ${VBINSTALLDIR}/install/init.php

fi