nanoc does not find my PHP files on autocompile - nanoc

I'm using nanoc to build a static website which has a PHP script for sending mails. Simplified structure:
/content/index.html
/content/contact.html
/content/mail.php
However, when I do a nanoc compile everything is fine in my output folder:
index.html
contact/index.html
mail/index.php
But I can't call the PHP script when doing a nanoc autocompile. /contact/ works, but /mail/ does not.
This is a part of my Rules-file:
route '*' do
if item.binary?
# Write item with identifier /foo/ to /foo.ext
original_filename(item)
else
# Write item with identifier /foo/ to /foo/index.extension
item.identifier + "index.#{item[:extension]}"
end
end
PHP is treated as non-binary. Does anyone know how I can get this to work with autocompile?

If anybody is having similar problems: I found the answer:
The autocompiler does not have support for PHP files. If a directory
is requested, the autocompiler looks for an index.html file in it, but
it will ignore an index.php file. The autocompiler can’t find a MIME
type for it, so it sends the file as application/octet-stream back to
the browser.
It's pretty obvious, but I did not have in mind that autocompile runs a light-weight server with no PHP support (of course).

Related

Is there any way to extract a rar file on cpanel

I have a website script, it 212MB and it's in RAR format , I could not upload it via filezilla ftp , it gave me a timeout error after sometime, I could not upload it from the filemanager of cpanel as it also kept showing an error. Then I used a php script to upload it directly from the link but now I can not extract it as its RAR not ZIP. I converted the RAR into ZIP and have it on drop box and google drive but there is no direct link which I can use to upload via the php script, SO, Is there any way to extract the rar file from cpanel or using a php script or some other tweak. I have been working on it for 2 hours now and can not find a way around.
create a php file and extra the .rar with that php file. use the following code
$archive = RarArchive::open('archive.rar');
$entries = $archive->getEntries();
foreach ($entries as $entry) {
$entry->extract('/extract/to/this/path');
}
$archive->close();

Copying folder except for one subfolder in Yeoman

I am working on this Yeoman project, and I am copying some files from a template to my new app directory.
This line is doing the job well:
this.fs.copyTpl(this.templatePath(''),
this.destinationPath(this.project_name_slugified+'/'));
Everything comes from the template folder and goes to the root folder of the project.
But when someone adds a flag '--nr' I want to exclude one subfolder that has been copied. So yo my-gen my_app_name --rf should copy EVERYTHING unless this subfolder.
I tried the !-glob notation, but it's not working. I did something like as first parameter:
[this.templatePath('**'),this.templatePath('!subfolder/subfolder_to_be_excluded')]
So second parameter was set to exclude the subfolder that is not necessary
I also tried deleting (delete method), but it seems that the file is not available immediately.
It's not working anyway. Any ideas? Promisifying the copyTpl would work?
By calling this.templatePath('!subfolder/subfolder_to_be_excluded'), you end up generating a broken path: /absolute/path/!subfolder/etc.
Use it without this.templatePath given you don't need the absolute path to apply the filtering.
this.fs.copyTpl(
[
this.templatePath('**'),
'!subfolder/subfolder_to_be_excluded'
],
this.destinationPath(this.project_name_slugified + '/'),
templateContext
);

404.17 Error showing after adding a Wildcard '*' Mime type (IIS 7)

I am trying to make extensionless url's (domain.com/urlwithoutextension) to be readable by my web server as an .html or .asp file, and all I'm getting is
HTTP Error 404.17 - Not Found
The requested content appears to be script and will not
be served by the static file handler.
Then below the error it says I can try this:
If you want to serve this content as a static file, add an explicit MIME map.
So I added a MIME map in IIS 7..
Extension: *
MIME Type: application/octet-stream
But I'm still getting this error. All I want to do is make it so domain.com/thisurl to be viewed as a .html file, without the .html extension. Help?
I simply changed it to . instead of * for Extension in MIME Type, and it worked perfectly. Thanks to the comments.

Add rewrite rule in plugin: with .htaccess in plugin folder or using WordPress functions

I need add a rewrite rule in my plugin, and distribute it with my code. All works fine if I put the rule in the .htaccess in the WordPress root folder, but I need distribute the plugin with my rule.
I try to put a .htaccess inside the plugin folder and try to use the add_rewrite_rule function but doesn't works either.
Here the .htaccess code that works correctly in WordPress root folder but doesn't works in my plugin folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule my-plugin/pages/tp(.*)\.php$ wp-content/plugins/my-plugin/pages/request.php?pid=$1
</IfModule>
I try the follow code in my plugin but doesn't works either:
add_filter( 'query_vars', 'add_query_vars' );
function add_query_vars( $query_vars )
{
$query_vars[] = 'pid';
return $query_vars;
}
add_action( 'init', 'add_init' );
function add_init()
{
$plugin_url = 'the-path-to-my-plugin-folder';
add_rewrite_rule('my-plugin/pages/tp(.*)\.php'
, $plugin_url . 'pages/request.php?pid=$matches[1]','top');
global $wp_rewrite;
$wp_rewrite->flush_rewrite_rules(); // I know this should be called only one time, but I put it here just to keep simple the sample code
}
But I always get the error that the URL wasn't found.
What I'm doing wrong? How can I do what I need? I searched for similar questions but none solve my problem.
My plugin folder structure is:
Main folder: /wp-content/plugins/my-plugin
------ /pages (sub folder)
-------------/request.php (script that should receive the request)
NOTE: WordPress Rewrite API is not the same as Apache Rewrite module.
WP Rewrite API doesn't redirect a request to another URL, it used to
parse current URL and fill query_vars array.
The issue is in the second parameter of you add_rewrite_rule function call. It has to start from index.php? and then there should be your arguments, like pid, for example:
"index.php?pid=$matches[1]...."
So your add_init function should be like this:
add_action( 'init', 'wpse8170_add_init' );
function wpse8170_add_init()
{
add_rewrite_rule('my-plugin/pages/tp(.*)\.php', 'index.php?pid=$matches[1]', 'top');
}
Don't forget to flush rewrite rules by visiting Settings » Permalinks page.
Further reading:
The Rewrite API: The Basics
The Rewrite API: Post Types & Taxonomies
WP handles the plugins from the /wp-admin directory with a PHP script (admin.php), like this:
http://MyWP.com/wp-admin/admin.php?page=MyPlugin/module.php
Therefore, .htaccess files in the plugin directory are not parsed when the plugin is called. They have to be placed in the wp-admin directory or in the root directory, as you already found out.
Although copying the .htacces file to the root directory when the plugin is installed -and deleting it when it is removed- is possible, I don't think it is the best option. Having .htaccess files in the WP space doesn't seem like a good idea.
Your second approach looks much better: Creating rewrite rules in the main script.
Looking at your code, I think the problem are the pattern (Incoming URL string to match) and possibly the substitution URL path ($plugin_url in your question).
The $rule parameter in the add_rewrite_rule() function should capture a segment of the URL (Above) used to call the plugin's modules.
I can't suggest anything else because you don't supply enough information about the plugin and it's directory tree, except what can be guessed from the regex in the rewrite rule. But, this is a general idea of a way to achieve what you need.

Problems configuring my site to use a custom php.ini file for all directories

PHP 5.2.17
joomla 1.6.4
1and1 Linux shared server
php is running as cgi
Hi, I am trying to use a custom php.ini throughout my website. I know I can put a php.ini file in each folder, but that would not be feasible.
I searched online and found the following method:
1 - create your custom php.ini file and put it inside path/to/your/website/cgi-bin folder
2 - create the following php.cgi file
#!/bin/sh
exec /usr/local/bin/php5 -c path/to/your/website/cgi-bin
3 - upload php.cgi to /path/to/your/website/cgi-bin
4 - chmod +x php.cgi to make it executable
5 - include the following line inside .htaccess in my website root
Action application/x-httpd-php5 /path/to/your/website/cgi-bin/php.cgi
According to my understanding, after doing the above, php scripts on my website would start using my custom php.ini file instead of the default one.
Anyone can help? I spent a better part of the day trying to resolve this issue without success.
By the way, my account root (one level above my website root) has a .htaccess file with the following lines:
AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php
Thank you.
UPDATE 9/2/2011 - 19:37
tried including the following statement in .htaccess
SetEnv PHPRC /path/to/my/website/cgi-bin <- where my custom php.ini file is located.
According to this website it should have worked -> http://support.premiumreseller.com/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=85
But still nothing.
I will keep trying.
Any help appreciated!!!
UPDATE 2 - 9/3/2011 - 0:03 (WORKAROUND)
So, I couldn't find a solution for my problem. I decided to create a small php script to create hard links to php.ini in each directory that has a php script.
See below the code in case you are curious:
<?php
define('ROOT_DIR', $_SERVER['DOCUMENT_ROOT']);
define('FILE_PHPINI', ROOT_DIR . "/cgi-bin/php.ini");
processdir(ROOT_DIR);
function processdir($path)
{
$FlagNoPHP = true;
$localPHPINI = $path . "/php.ini";
foreach ( new DirectoryIterator($path) as $file)
{
if (!($file->isDot()))
{
if ($file->isDir())
{
processdir($path . "/" . $file);
}
else if ($FlagNoPHP && fnmatch("*.php*", $file))
{
$FlagNoPHP = false;
if (!file_exists($localPHPINI))
{
link(FILE_PHPINI, $localPHPINI);
}
}
}
}
if ($FlagNoPHP)
{
if (file_exists($localPHPINI))
{
unlink($localPHPINI);
}
}
}
?>
The above code looks inside each directory in my website and:
1 - if there is a php script and NO php.ini, creates a hard link to php.ini
2 - if there is NO php script and there is a php.ini, deletes the hard link (done in the last if of the function). I included this in order to clean up the filesystem of old php.ini files.
This worked for me.
I am still curious about an answer to my original problem.
I hope this helps someone!
Seems like you're taking the long way. Just modify .bashrc:
export PHPRC="/Volumes/Mac_Daddy/web_curr/public_html/php_osx.ini"
Result:
Configuration File (php.ini) Path: /usr/local/php5/lib
Loaded Configuration File: /Volumes/Mac_Daddy/web_curr/public_html/php_osx.ini
Scan for additional .ini files in: /usr/local/php5/php.d
Additional .ini files parsed: /usr/local/php5/php.d/10-extension_dir.ini
Or create an alias:
alias myphp="/usr/local/php5/bin/php -c /somewhere/someplace/php.ini"
or better yet man php.

Resources