Repository: getnikola/nikola

Issue:
Cannot copy file .php in files folder.
Using nikola 7.1.0, I couldn't copy a file contact.php in the default files folder.
This are the error massage:

$ nikola build
Scanning posts............done!
.  copy_files:output/contact.php
###### 

TaskError - taskid:copy_files:output/contact.php
PythonAction Error
Traceback (most recent call last):
  File "/home/binhasan/local/lib/python2.7/site-packages/doit/action.py", line 365, in execute
    returned_value = self.py_callable(_self.args, *_kwargs)
  File "/home/binhasan/local/lib/python2.7/site-packages/nikola/utils.py", line 825, in unlessLink
    action(target)
  File "/home/binhasan/local/lib/python2.7/site-packages/nikola/filters.py", line 67, in f_in_file
    data = f(data)
  File "/home/binhasan/local/lib/python2.7/site-packages/nikola/filters.py", line 183, in php_template_injection
    return phpdata
UnboundLocalError: local variable 'phpdata' referenced before assignment



Discussion:
On 09/08/2014 06:06 AM, binhasan wrote:

> Using nikola 7.1.0, I couldn't copy a file contact.php in the default
> files folder.

That would be my fault. Will look at it later today.

By the by, what is this PHP file? This broke because Nikola now assumes 
all .php files use templates. Just curious about your usecase.

> This are the error massage:
> 
> $ nikola build
> Scanning posts............done!
> . copy_files:output/contact.php
> ########################################
> TaskError - taskid:copy_files:output/contact.php
> PythonAction Error
> Traceback (most recent call last):
> File "/home/binhasan/local/lib/python2.7/site-packages/doit/action.py",
> line 365, in execute
> returned_value = self.py_callable(_self.args, *_kwargs)
> File "/home/binhasan/local/lib/python2.7/site-packages/nikola/utils.py",
> line 825, in unlessLink
> action(target)
> File
> "/home/binhasan/local/lib/python2.7/site-packages/nikola/filters.py",
> line 67, in f_in_file
> data = f(data)
> File
> "/home/binhasan/local/lib/python2.7/site-packages/nikola/filters.py",
> line 183, in php_template_injection
> return phpdata
> 
> ## UnboundLocalError: local variable 'phpdata' referenced before assignment
> 
> Daniel Aleksandersen

There should be differentiation between php files in files/ and posts/ &
stories/.

## 

Chris “Kwpolska” Warrick http://chriswarrick.com/
Sent from my Galaxy S3.
On Sep 8, 2014 8:01 AM, "Daniel Aleksandersen" notifications@github.com
wrote:

> On 09/08/2014 06:06 AM, binhasan wrote:
> 
> > Using nikola 7.1.0, I couldn't copy a file contact.php in the default
> > files folder.
> 
> That would be my fault. Will look at it later today.
> 
> By the by, what is this PHP file? This broke because Nikola now assumes
> all .php files use templates. Just curious about your usecase.
> 
> > This are the error massage:
> > 
> > $ nikola build
> > Scanning posts............done!
> > . copy_files:output/contact.php
> > ########################################
> > TaskError - taskid:copy_files:output/contact.php
> > PythonAction Error
> > Traceback (most recent call last):
> > File "/home/binhasan/local/lib/python2.7/site-packages/doit/action.py",
> > line 365, in execute
> > returned_value = self.py_callable(_self.args, *_kwargs)
> > File "/home/binhasan/local/lib/python2.7/site-packages/nikola/utils.py",
> > line 825, in unlessLink
> > action(target)
> > File
> > "/home/binhasan/local/lib/python2.7/site-packages/nikola/filters.py",
> > line 67, in f_in_file
> > data = f(data)
> > File
> > "/home/binhasan/local/lib/python2.7/site-packages/nikola/filters.py",
> > line 183, in php_template_injection
> > return phpdata
> > 
> > ## UnboundLocalError: local variable 'phpdata' referenced before assignment
> > 
> > Daniel Aleksandersen
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/getnikola/nikola/issues/1403#issuecomment-54779405.

@Aeyoun : I create php script in one file for some forms to contact us.
@Kwpolska : You're right, i think in the files folder we cannot use templates for a .php file


Resolving patch:
diff --git a/nikola/filters.py b/nikola/filters.py
--- a/nikola/filters.py
+++ b/nikola/filters.py
@@ -179,5 +179,6 @@ def php_template_injection(data):
         _META_SEPARATOR = '(' + os.linesep * 2 + '|' + ('\n' * 2) + '|' + ("\r\n" * 2) + ')'
         phpdata = re.split(_META_SEPARATOR, phpdata, maxsplit=1)[-1]
         phpdata = re.sub(template.group(0), phpdata, data)
-
-    return phpdata
+        return phpdata
+    else:
+        return data


Test patch: