Closed (fixed)
Project:
JS Callback Handler
Version:
6.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
13 Nov 2010 at 15:12 UTC
Updated:
18 Dec 2012 at 23:00 UTC
Jump to comment: Most recent file
Comments
Comment #1
sunNot sure yet. Time will tell.
Comment #2
electblake commentedI might give it a try as it really do need it for D7 (and I haven't seen many alternatives) but Dries was talking 'bout this as well - http://chicago2011.drupal.org/keynote-dries-buytaert. I bet if this gets stable D7 it goes core in D8.
But lets stay on topic - D7 port?
Comment #3
Fidelix commentedSubscribing...
Comment #4
carvalhar commentedis there any alternative for D7?
Comment #5
bibo commentedI'm also wondering if anyone is working on this or a similar release for D7?
Comment #6
sunThe primary challenge for js.php in D7 is that D7 dynamically caches run-time information based on page callbacks. A reduced list of loaded modules may unintentionally break normally expected loaded modules and their information on regular index.php page loads.
I mean, we can happily try. Porting the current code shouldn't be too hard. Any takers?
Comment #7
doitDave commentedAs there are more challenges (see #1103394: filter_xss_bad_protocol collides with "filter" dependency) to address and not only the ones for D7, probably a generally revised design which disconnects from basically imitating a Drupal bootstrap/running a reduced one anyhow but instead represents a dedicated Ajax callback API with its own permissions might be really worth a try. Not just for the D7 branch.
I am not familiar with what is being planned for D8 but it seems likely to me that there will be some generic implementation focusing on lightweight Ajax processing, sun should know that better as he is involved in development AFAIK. As Ajax implementations grow and grow as does the number of 3rd party JS app bridges, Drupal really needs performant JS support at least for all D6/7/8.
However, as I already had to work around some restrictions of js.module for other projects (by launching a clone for D6 which slightly extends it ;see js_callback.module) anyhow, I would really like to help maintaining the original and, as a consequence, drop the clone asap, as such a duplication is not really what I like.
@sun: Just let me know if you'd like me to. Would be a pleasure to support this one.
Comment #8
alexweber commentedJust reiterating, with D7 now so stable and performance modules like Boost getting stable releases this would be awesome to have! :)
Comment #9
bibo commentedsun:
doitDave:
I vote for doitDave, don't see that many other takers ;)
Comment #10
michielnugter commentedI wanted this feature for a Drupal 7 project I'm working on and decided to make an effort at porting it. Attached is my attempt that I got to work nicely with entityreference (additional code required, I can post the example if anyone is interested). It still doesn't have any access checks so anyone can access the /js url's. It's a 1-1 port with some minor additions:
Some feedback would be great!
ps: I added myself and my company (who sponsored this) in the Readme.txt, I know this might be a bit premature but if the patch will be published as the Drupal 7 version it would be nice if it's mentioned.
Comment #11
thoraxou commentedPlease, make a D7 module
Comment #12
alexweber commented@michielnugter thanks for the effort and patch! I haven't had a chance to test it but it seems promising.
Comment #13
michielnugter commented@thoraxou I created a zipfile of the module after it's patched, I hope it helps out in testing it.
Comment #14
thoraxou commentedThanks for your feedback.
I followed the readme.txt but when I try to test with
subdomain.mysite.com/js/example/somefunction
I get a 403 Forbidden
Am I doing something wrong ? Am I supposed to customize js.module too ?
Attached the example module I use.
Comment #15
michielnugter commentedI installed your module and got it to work. Have you done all the steps indicated in the installation description?
* Copy js.php to the root directory of your Drupal installation.
* Enable clean URLs.
* Add the following lines in front of the existing RewriteRules in your
.htaccess file:
I did change the required modules to also include the system module, it's required by the locale menu.
Comment #16
michielnugter commentedbtw, if the current maintainers are interested I'd have no problem beeing co-maintainer for this module, please let me know if this is an option.
Comment #17
thoraxou commentedThanks for your time michielnugter
* Copy js.php to the root directory of your Drupal installation.
js.php is in /www/drupal/
which is the same directory as index.php
* Enable clean URLs.
Enabled in /admin/config/search/clean-urls
* Add the following lines in front of the existing RewriteRules in your .htaccess file:
See below
#
# Apache/PHP/Drupal settings:
#
# Protect files and directories from prying eyes.
Order allow,deny
# Don't show directory listings for URLs which map to a directory.
Options -Indexes
# Follow symbolic links in this directory.
Options +FollowSymLinks
# Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php index.html index.htm
# Override PHP settings that cannot be changed at runtime. See
# sites/default/default.settings.php and drupal_initialize_variables() in
# includes/bootstrap.inc for settings that can be changed at runtime.
# PHP 5, Apache 1 and 2.
php_flag magic_quotes_gpc off
php_flag magic_quotes_sybase off
php_flag register_globals off
php_flag session.auto_start off
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_flag mbstring.encoding_translation off
# Requires mod_expires to be enabled.
# Enable expirations.
ExpiresActive On
# Cache all files for 2 weeks after access (A).
ExpiresDefault A1209600
# Do not allow PHP scripts to be cached unless they explicitly send cache
# headers themselves. Otherwise all scripts would have to overwrite the
# headers set by mod_expires if they want another caching behavior. This may
# fail if an error occurs early in the bootstrap process, and it may cause
# problems if a non-Drupal PHP file is installed in a subdirectory.
ExpiresActive Off
# Various rewrite rules.
RewriteEngine on
# Block access to "hidden" directories whose names begin with a period. This
# includes directories used by version control systems such as Subversion or
# Git to store control files. Files whose names begin with a period, as well
# as the control files used by CVS, are protected by the FilesMatch directive
# above.
#
# NOTE: This only works when mod_rewrite is loaded. Without mod_rewrite, it is
# not possible to block access to entire directories from .htaccess, because
# is not allowed here.
#
# If you do not have mod_rewrite installed, you should remove these
# directories from your webroot or otherwise protect them from being
# downloaded.
RewriteRule "(^|/)\." - [F]
# If your site can be accessed both with and without the 'www.' prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
#
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# uncomment the following:
# RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment the following:
# RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
# RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
# For example if your site is at http://example.com/drupal uncomment and
# modify the following line:
# RewriteBase /drupal
#
# If your site is running in a VirtualDocumentRoot at http://example.com/,
# uncomment the following line:
RewriteBase /
# Rewrite JavaScript callback URLs of the form 'js.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^\/js\/.*
RewriteRule ^(.*)$ js.php?q=$1 [L,QSA]
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
# Rules to correctly serve gzip compressed CSS and JS files.
# Requires both mod_rewrite and mod_headers to be enabled.
# Serve gzip compressed CSS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.css $1\.css\.gz [QSA]
# Serve gzip compressed JS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.js $1\.js\.gz [QSA]
# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
# Serve correct encoding type.
Header set Content-Encoding gzip
# Force proxies to cache gzipped & non-gzipped css/js files separately.
Header append Vary Accept-Encoding
* Modules to activate ?
=> Activated
Locale
User
Filter
System
* Cutomize js module ?
Attached js module as it is in modules
Comment #18
michielnugter commentedYou should definitly not change anything in the js module, it should work without any changes. As a rule of thumb: never change a contrib module for your project, this prevents you from beeing able to update the module if a new release is published. Effectively this means you'll need to maintain a lot of extra code for your project.
How do you access your project in your browser? Is the project in a subdirectory? If so, it should be prefixed in the Rewrite rule. If you access it on localhost/drupal it should be something like this:
Comment #19
thoraxou commentedHow do you access your project in your browser?
usually
http://subdomain.mysite.com/somepage
for testing js module
http://subdomain.mysite.com/js/example/somefunction
Is the project in a subdirectory?
http://subdomain.mysite.com/ pointing to /www/drupal/
Both example and js modules are in :
/www/drupal/sites/all/modules
Should I customize .htaccess ?
A few test to try to figure out the problem :
http://subdomain.mysite.com/js/example/somefunction =>403
http://subdomain.mysite.com/js/example/thereisnosuchfunction =>403
http://subdomain.mysite.com/js/nosuchmodule/whatever => 404
Inside module example
function example_menu()
{
$items[] = array(
'path' => 'js/example/somefunction',
'callback' => 'example_somefunction',
'type' => MENU_CALLBACK,
);
return $items;
}
function example_js() {
return array(
'somefunction' => array(
'callback' => 'example_somefunction',
'includes' => array('theme', 'unicode'),
'dependencies' => array('locale', 'filter', 'user'),
),
);
}
function example_somefunction()
{
echo "kikoo";
}
Comment #20
thoraxou commentedI am a little bit confused with
'page callback' => 'drupal_access_denied',
in the js.module
Is this the reason I get 403 access denied when trying to get a response ?
Comment #21
michielnugter commentedThat is there to make sure the provided js callbacks are actually valid menu hooks so that you can use them in an autocomplete form element.
I actually got your module working in my Drupal install by only adding the system module in your callback in the dependancies
As far as I see the js.php file isn't picked up when opening the link, which it should be. Probably the .htaccess in the root isn't picked up correctly or something like that. Can you verify that your .htaccess is loaded and the same as the attached .htaccess file?
Comment #22
thoraxou commentedJust replaced my htaccess by yours, situation is same as before.
'I actually got your module working in my Drupal install by only adding the system module in your callback in the dependancies'
=>like that ? I also tried, doesn't change anything.
function example_menu()
{
$items[] = array(
'path' => 'js/example/somefunction',
'callback' => 'example_somefunction',
'type' => MENU_CALLBACK,
'dependencies' => array('system'),
);
return $items;
}
In admin/reports/status, I can see
JavaScript callback handler Installed correctly
The JavaScript callback handler has been installed correctly.
Comment #23
thoraxou commentedBy the way for testing, I am trying directly in the browser, not going through links
http://subdomain.mysite.com/js/example/somefunction
Comment #24
thoraxou commentedReinstalled js and example module on a virgin drupal 7 without subdomain, situation is identical.
Comment #25
michielnugter commentedUnfortunatly I can't help you out any better. My attempt was on a freshly downloaded Drupal and the js module from this thread and it works. I think it may have to do something with your apache configuration, I really don't know what else it could be. Check to see if mod_rewrite really is enabled and working and check if the clean url of drupal itself actually works. I haven't applied the apache 1.3 fix btw, can this be the cause of this error? Otherwise check if it runs through the js.php file (use a debugger or just place a die(); statement somewhere). If if doesn't the problem is somewhere in the .htaccess file.
The dependancy should go in the hook_js, not the menu callback:
}
Comment #26
thoraxou commentedThe module was not going through js.php but rather index.php
The following link is going to the right place through js.php
mysite.com/js.php/example/somefunction
The way and back is costing between 0.5 sec to 1.5 seconds while the server is just 0,025 seconds away when making a ping.After removing dependencies and includes, I have a round up around 100 ms (50ms transport + 50ms time processing). Nice !
Comment #27
wiifmCan we get the above module in #17 committed to a new branch (I'm assuming 7.x-2.x).
Working from a zip file download in a comment is nasty.
If this project has been abandoned, I would recommend thoraxou or michielnugter apply to be a maintainer (seeing as they both wrote patches/modules).
Comment #28
michielnugter commentedI have posted a request for git commit access (don't have it yet and without it maintaining a module is quite difficult :)) and I send a message to Sun asking to be co-maintainer.
I also have send some messages back and forth with doitDave, the maintainer of js_callback. If sun doesn't want me be to co-maintainer, which I can understand since I haven't proven myself very much yet within the Drupal community (only a couple of patches posted), I'll try to work together with doitDave to release the version via the js_callback module.
Comment #29
andypost@michielnugter you just need to create a sandbox project and post a link here. Suppose it would be better to proceed with sandbox and merge changes in main module when it's ready
Comment #30
michielnugter commented@andypost I just got commit rights from doitDave for the js_callback module (http://drupal.org/project/js_callback) and am busy making the first dev release for the 7.x-1.x version. I'll continue development there and hope that one day we can merge the js_callback module back to the js module (or the other way around, whichever is the best solution).
Comment #31
michielnugter commentedThe release is published. The beta1 release will show up shortly
Comment #32
alexweber commentedThis is awesome! Thanks!! :)