Skip to content

Instantly share code, notes, and snippets.

@stypr
Last active August 3, 2019 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stypr/f2a4ea2baab0a39c4309e054835cef78 to your computer and use it in GitHub Desktop.
Save stypr/f2a4ea2baab0a39c4309e054835cef78 to your computer and use it in GitHub Desktop.
Migrating old php files to newer versions
#!/usr/bin/python -u
#-*-coding: utf-8-*-
def list_directory(expression):
try:
_c = __import__("glob").glob(expression + "/*")
for i in xrange(len(_c)):
if "uploads" not in _c[i] and "userimage" not in _c[i] and "files" not in _c[i]:
_c.extend(list_directory(_c[i]))
return _c
except:
return []
php_list = filter(lambda x: x.endswith(".php"), list_directory("./"))
for php in php_list:
data=open(php, 'rb').readlines()
for k in xrange(len(data)):
i = data[k]
if "&$" in i and "->" in i and "function" not in i:
try:
_t = i.split("(")[1].split(")")[0]
except IndexError:
continue
if _t.strip() == "":
continue
data[k] = i.replace("&$", "$")
wri=open(php, 'wb')
wri.write("".join(data))
wri.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment