Skip to content

Instantly share code, notes, and snippets.

@stypr stypr/patch.py
Last active Aug 3, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.