Drupal flushing "Page requisites" cache also deletes javascript files - drupal

When I delete "Page requisites" cache, my 2 Javascript files that I use for my home page image rotator get deleted.
Here is how I'm adding the javascript for those 2 files into a WYSIWYG editor with PHP code enabled:
<?
drupal_add_js('sites/default/files/js/jquery.jcarousellite.js');
drupal_add_js('sites/default/files/js/cycle.js');
?>
Some html here for the rotator......
Then I also have some JS code added to the home page only using the js Injector .
Any ideas why this is happening?
thanks

You shouldn't have permanent js files located in your files folder. Either they should be in your theme or a module that uses them. The files folder is meant for uploaded files and other files that Drupal creates on the fly.
The reason to your problem is probably that Drupal has write access to the folder where you have placed the files, and it cleans out in it, since it's only used for compressions. You should think twice about which files you let drupal write to. Letting Drupal have write access to a script file you use, is an added security risk.
Generally, you don't want to let Drupal write to js or php files. This is because if a cracker would be able to get Drupal to write to those files, he would be able to more or less gain control over your entire site. This is also why the compressed js files that drupal uses has a long and random name.
So try moving those files into your theme and see if that doesn't fix it. If you want to link to them you can do
drupal_add_js(drupal_get_path('theme', 'name_of_your_theme') . 'path/to/file.js');

Related

Insert plain html/css/js pages and add address (route) to them

Say I have html template https://www.free-css.com/free-css-templates/page244/debut How do I insert them into Drupal correctly so that it works exactly as I if've put these files from archive alongside Drupal...? So that if I open "mysite.com/contact.html" I get exactly the contents of contact.html an everything inside (links to css/js files) works.
If I'm understanding, you want to serve a static HTML file from the same domain as a Drupal site, and not bootstrap Drupal in the process, so the static HTML gets served directly. I'd recommend using the Pathed Files module (https://www.drupal.org/project/pathed_files) which lets you upload a static file or paste its contents into a form, and specify a custom URL for it. Alternatively, if you just put an HTML file in the Drupal files directory (e.g. https://your.website.com/sites/default/files/your-html-file.html), your Web server will happily serve it as is, but you have to live with that /sites/default/files/ path in the URL. Truth be told, you could put it right in the Drupal Web root, alongside index.php, and the Web server will serve it without bootstrapping Drupal. But that's very ugly, and you really, really should not do that.

How would I go about creating a simple file builder?

Forgive me if this doesn't make sense but I'll do my best to explain.
I am looking into creating a piece of software/web app which will generate a package file for website themes including only the options the user would need for their project.
The best example I can think of is the underscores WordPress theme generator. But I would also like to be able to include other files. Like for example a check box that simply says "include x.js library" where if the box is checked it will include that js file or files in the folder. As well as generate the theme name, author name, theme description version number etc.
In other words I need something like underscores, that also has the option to include extra files for the development team to quickly get bespoke WordPress themes up and running whilst also including all the optional assets that we use at the firm.
You can hold the basic logic, opening, reading, editing, closing of files in a php script that's triggered when the user submits a form.
One route to manipulate files on the server with php is to use fopen.
First enable fopen in the directory in which your files you want available for download are stored. Do this by including the following in a .htaccess file in this directory:
php_value allow_url_fopen On
In whatever script you would like triggered on form submit, you can change say the author name with something like the following (you'll obviously want to target where you're writing to, I imagine with FSeek):
$downloadable_theme_index = 'index.php';
$handle = fopen($downloadable_theme_index, 'w') or die('Cannot open file: '.$downloadable_theme_index);
$new_author_name = 'Abe Lincoln';
fwrite($handle, $new_author_name);
The logic for what files are available to download could basically be form logic that provides links to download based on user input.
Additionally, there are download manager plugins available in wordpress.

Sublime Text: Detect non used files in PHP (WordPress) project?

Created a PHP project in Sublime Text 3 that holds PHP, CSS, JS, HTML, and some other files and folders. Other files may be .md, .txt, .ico, images and fonts (.woff, .ttf, ...).
Actually project is WordPress, but the solution should be for all PHP based projects, and specifically I am interested only to check specific folders inside of project (liek theme and plugin files). WordPress core is no interest for me to check.
I would like to detect Files with extensions (.php, .css, .js) that are unused. Is there a smart solution do detect these?
For instance CSS file is not used if no other files references it. The reference may came from another CSS file or from some PHP file, or even JS file.
I am not searching for a perfect solution, but for something that is close to detect these or even for an idea how I may think about these.
In WordPress (PHP) there are require and include instructions, and also wp_enqueue_script/styles that represent the mechanism how to reference files for instance.
So we could create a list of all PHP, CSS, JS files, and then based on file names search for these in the content of all other files. This would be a good start.

How to create cms templates from HTML files via GruntJS?

In my webdesign process i use jade, sass, coffe etc. to generate static files via a GruntJS watch task into a dev folder. And most of the times after the build process is done, a cms comes along and want some templates to work. Thats usually html files with some php/ruby/python tags in it. Let´s say it´s a Wordpress Theme.
The Problem is:
i have to modify my generated files in the dev folder directly
when im modifing my source jade, html, coffee - files, the dev folder would be overwritten
if i clone the static files and move them into the theme folder, i have to apply manually every change i made to the src/dev folder to the cloned theme template files.
that´s very odd. So i´am in need of a grunt task that maybe...
generate the templates for me out of the static files (via a json mapping file)
generate the templates directly from the src files via special attributes, comments or something similar
There´s just one thread i found where the user tries to accomplish the same with jsdom.
Can someone help me to find a existing tool that accomplish such a task or do i have to build it on my own?
Thanks, Robert
Check out grunt-usemin
Replaces references to non-optimized scripts or stylesheets into a set of HTML files (or any templates/views)

Wordpress File Upload Hook

I am trying to hook into the Wordpress file uploader and would like some suggestions. I would like to be able to grab the path of the source file (not WP path; i.e. K:\docs\file.pdf) so I can download another file of the same name (different extension) & path automatically (i.e. K:\docs\file.txt).
Wordpress provides hooks for after the file is uploaded but all path information at that point is internal to wordpress.
Thanks in advance!!
the path information can be obtained from normal php functions like pathinfo() and realpath() for example .
Bit too late to the party but I think what you are asking for is to find the source of the document in the clients system and based on that you want similar files there to be picked up by the browser and then sent to the user.
I think it will be a fairly complex thing to do, firstly you have to get the source of the document being added to the browser (I am not sure it can be done, but if it can be done then it will be via javascript) and then upload all the files one by one to the server hosting wordpress and you can do this by creating a custom page which will add the files uploaded to it as a wordpress attachment and then using something like jquery file uploader to upload files to that location.
But honestly, I think it would be a very complex thing, unless the client and the server are on the same machine.

Resources