Last active
August 3, 2019 16:59
-
-
Save stypr/f2a4ea2baab0a39c4309e054835cef78 to your computer and use it in GitHub Desktop.
Migrating old php files to newer versions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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