Sharrre PHP script from Rails view partial - php

I'm wondering if anyone has tried to use Julien Hany's Sharrre plugin (http://sharrre.com/) from a Rails app? Specifically, from a view partial? The Google+ portion of the plugin requires a PHP script, which is called from the JavaScript that's in the asset pipeline. How do I execute that script from within the script tags in the view partial? Or if I need to edit Mr Hany's plugin? If so, what might I need to do?
As a side note, I've taken a look at Run a php script in ruby on rails, as well as the Kernel module (http://ruby-doc.org/core-1.9.2/Kernel.html), but I'm not really sure where to start.
Many thanks in advance!

There is no reason to run a php script for this -- you can look at the sharrre.php file in the download and just redo it in ruby, it looks like its using JSON, curl (try the curb gem), and some xpath traversal (try nokogiri or hpricot).

Related

How to run php code inside cordova?

I am new to cordova and want to transfer my existing app build with jquery mobile and php to iOS/Android. Am I correct, that there is no php interpreter inside cordova? That would mean, that the existing app is not transfarable to cordova as php is a central component in building those html files inside the project. This would make it kind of useless for me.
Is there a way to run php code inside cordova?
You cannot use any server-side scripting language (ex: PHP) inside cordova. But using Jquery and AJAX you can call php functions and get data easily.
PHP runs on the server-side; Cordova packages your app into a client-side application.
If you really really want to use your PHP server-generated HTML, rather than static HTML in your client-side app, you can package in an almost empty HTML file, and dynamically fetch HTML from your PHP server, AJAX or otherwise.
In today's age, with AJAX and HTML5 apps, most people will tell you that the server's role should not be to generate HTML files; it should be to generate data (JSON) through APIs. If you switch to such an architecture, you'll find that there are much more tools you can use easily.
Actually, you could use Quercus in Java to feed HTTP parameters to a PHP interpreter, no IP port necessary (you can construct a HTTP-request-holding data object) and for IOS, something like https://github.com/grantjbutler/PHPTest.
There are other embeddable solutions for IOS, I may edit this answer further, in the near future.
Quick search yielded this result: quercus: php in java (open source, 100% java implementation of php) so it should be possible to write plugin that execute your php code, probably with little modification. And then expose it in window.Plugin.method() like other plugins do (like this one cordova-plugin-shell-exec).

How can I use a PHP module in my Python Google Apps Engine

I'm writing a website using Google Apps Engine Python, and a friend has written some code that he has kindly shared with me that I want to use that's written in PHP. Basically it draws diagrams given some code, and should save an image for it if it doesn't exist.
I've got that code stored in my database in a variable called Diagram_Code, and I want the diagram to render on the page. I'm using jinja to do my templating. I expect I'll have two directories somehow, one with the code in it, and another one with the saved diagrams which are an md5(Diagram_Code).jpg.
I've looked at the documentation for the app.yaml, but I don't understand how I should include it there, if I should.
I'm expecting my python might look something like this:
if not "/diagrams",md5(Diagram_Code),".jpg": #Check if diagram exists already
FUNCTION_TO_USE_PHP(Diagram_Code) #Make diagram with some function
img_url="/diagrams/",md5(Diagram_Code),".jpg"
How should I include it in my app.yaml, and how do I call it in my Python code if this is possible? and if not, what might be the best solution to be able to use what is in the PHP?
You need to use the modules feature, more documentation can be found here.
Basically you deploy a PHP module along side your Python application. You use URLFetch from your python code to make a request to the PHP module to render out whatever it is that you want.
See this on how to do the communication between modules.

Simple single ruby file web app

Okay this seems like a real noob question.
I currently have a simple html and javascript news reader running on my MAMP server. You can see it on Github. Everything runs client side except for fetching and caching the feeds which is done by a really small php file. I have an ajax call which requests the news feed from the php script by passing some parameters to it.
I have of late been learning Ruby and have started to redo this simple php script in Ruby. The problem I have is that I can't just request the ruby script via ajax with parameters like I would do with php.
So what would be the simplest steps to take to be able to do this?
I feel like a full blown framework, even as small as Sinatra, would be overkill. So any help would be much appreciated. Am I completely thinking about this the wrong way round? Thanks.
Update
I went the Ruby CGI way in the end. Here's what I did.
In the folder I had my script I added a .htaccess file with the following to make apache execute the .rb file.
AddHandler cgi-script .rb
Options +ExecCGI
Then I started my ruby file off like this.
#!/usr/bin/ruby
require 'cgi'
cgi = CGI.new('html4')
cgi.out {
cgi.html {
"Hello World" #started content here
}
}
I then made sure the file was executable. chmod 774.
Thanks for all your help.
The simplest solution here would be Ruby CGI.
If you think sinatra is still big for you, go deeper and try to write pure Rack app.
For example see this minimal app - https://github.com/stevenwilkin/ip.stevenwilkin.com
Rack needs only 3 elements array like this
[200 , {"Content-Type" => "text/plain"}, [env["REMOTE_ADDR"]]]
[return status , headers hash , body string ]
Rails, Sinatra and a lot of another ruby web frameworks are using Rack inside.
And if you need request params nicely formated, you can just use http://rack.rubyforge.org/doc/classes/Rack/Request.html for example.

How to call a php function within <script> tag from coldfusion 9

I have this nice big Dev Kit written in PHP, but the application I'm currently developing is in CFML.
In an attempt to avoid rewriting the PHP, I'm going to try to just wrap the PHP in CF <script> tags and call the PHP functions when I need them.
Does anyone have any idea how to call one of those PHP functions inline in CF?
There's no built-in way to do this, but using CFGroovy (which allows you to inline any Java Scripting API-compliant language implementation) and Quercus (a PHP implementation in Java), you may be able to pull off what you want/
CFGroovy: http://www.barneyb.com/barneyblog/projects/cfgroovy2/
Quercus: http://www.caucho.com/resin-3.0/quercus/
A simple example including source code:
http://www.barneyb.com/cfgroovy2/
You can't. It's a whole other app engine. You could use CFHTTP to call a PHP page - but it's a bit overkill. You can look at Sean's solution here:
http://corfield.org/entry/ColdFusion_8_running_PHP
Edward M. Smith is right. You may be able to mix PHP and CFML by using Resin as your JVM. While I have not done so, I do believe it is possible to have Resin interpret your PHP code from within the same context as a CFML (ColdFusion) Web site.
A .cfm/.cfc could not contain any PHP and a .php file could not contain any CFML/CFScript;
however, those files could live side by side within your www.something.com domain.
Resin http://www.caucho.com/ is a Web Server/PHP Interpreter that is very fast and written in Java. It is the bundled JVM for the open source CFML project Railo.
Hope this helps.
You can pass data back and forth by having php/coldfusion store/retrieve client array's or variables.
One other choice is to force coldfusion to parse through .php files, for any coldfusion inside there. How it would handle the mixture of coldfusion and php, I am not sure...

Is there such a thing as a converter from php to html?

Don't think that I'm mad, I understand how php works!
That being said. I develop personal website and I usually take advantage of php to avoid repetion during the development phase nothing truly dynamic, only includes for the menus, a couple of foreach and the likes.
When the development phase ends I need to give the website in html files to the client. Is there a tool (crawler?) that can do this for me instead of visiting each page and saving the interpreted html?
You can use wget to download recursively all the pages linked.
You can read more about this here: http://en.wikipedia.org/wiki/Wget#Recursive_download
If you need something more powerful that recursive wget, httrack works pretty well. http://www.httrack.com/
Pavuk offers much finer control than wget. And will rewrite the URLs in the grabbed pages if required.
If you want to use a crawler, I would go for the mighty wget.
Otherwise you could also use some build tool like make.
You need to create a file nameed Makefile in the same folder of your php files.
It should contain this:
all: 1st_page.html 2nd_page.html 3rd_page.html
1st_page.html: 1st_page.php
php command
2nd_page.html: 2nd_page.php
php command
3rd_page.html: 3rd_page.php
php command
Note that the php command is not preceded by spaces but by a tabulation.
(See this page for the php command line syntax.)
After that, whenever you want to update your html files just type
make
in your terminal to automatically generate them.
It could seem a lot of work for just a simple job, but make is a very handy tool that you will find useful to automate other tasks as well.
Maybe, command line will help?
If you're on windows, you can use Free Download Manager to crawl a web-site.

Categories