Drawing a graph with GraphViz in PHP - php

Good evening,
I am trying to figure out a way to display simple node/edge graphs from a Neo4J DB in PHP. I had a look at three.js, sigma and alchemy but those tools seem way to complex for such simple tasks. Then I found GraphViz which runs fine when I use the editor. But I was not able to find help when I wanted to use this from PHP. There is a pear package which seems not suitable anymore for PHP >5.0 (tried it and run into lots of errors (e.g. Non-static method System::mktemp() should not be called statically - there is also a thread here about this: Graphviz not working with php 5.3.2) and I found a document http://www.graphviz.org/pdf/gv.3php.pdf - but unfortunately it seems I cant deal with this.
Anybody has an example how to draw e.g. this:
<?php
require_once 'Image/GraphViz.php';
$gv = new Image_GraphViz();
$gv->addEdge(array('wake up' => 'visit bathroom'));
$gv->addEdge(array('visit bathroom' => 'make coffee'));
$gv->image();
?>
(Source:http://pear.php.net/manual/en/package.images.image-graphviz.example.php)
This code is from the pear package example but doesnt run - but maybe someone has an idea how to use this from PHP directly over the gv.php extension from GraphViz?
A GraphViz Example which runs fine in the editor:
graph graphname {
a -- b;
b -- c;
b -- d;
d -- a;
}
But how to get PHP to talk with GraphViz and produce the output?
Any help is very appreciated, thanks.
B

You can also just use a javascript based dot renderer, e.g.
https://github.com/mdaines/viz.js/
https://code.google.com/p/canviz/

Result of my search:
I am using now http://visjs.org/ which suits good to my needs. Here is an example for the code: http://visjs.org/docs/network.html#Example
The problem to assign URLs to nodes has been solved by altering the javascript with a simple location.href on click.

Related

Connecting to the Quickbooks Online SDK from PHP, how do I add a Blue Dot menu?

I have a working PHP app that connects to Quickbooks online, loosely based on code from Pearce (thank you!). I'm using the Intuit PHPv3 SDK (version 2.0.4).
My setup code looks like:
<script type='text/javascript' src='https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js'></script>
<ipp:connectToIntuit></ipp:connectToIntuit>
and then, in Javascript:
intuit.ipp.anywhere.setup({
grantUrl: 'http://mywebsite.com/qbo/oauth'
});
This works fine, but I would like to add a Blue Dot Menu, which I assume gives the ability to disconnect the session and do other things. To do this, I know that the Javascript should really be saying:
intuit.ipp.anywhere.setup({
grantUrl: 'http://mywebsite.com/qbo/oauth',
menuProxy: 'http://mywebsite.com/qbo/blue-dot-menu
});
Trouble is, I have no idea what to put in the implementation code for the blue-dot-menu handler, and I've now spent quite a long time trying to figure this out from Intuit's documentation without success.
Any ideas appreciated!
The implementation of the Blue Dot menu is actually pretty simple -
Make a HTTP GET request to:
https://appcenter.intuit.com/api/v1/account/appmenu
That's OAuth authenticated. Print out the contents of what you get back to the page. Boom, done.
If you want an actual working example, use the open-source DevKit on GitHub - examples are here:
https://github.com/consolibyte/quickbooks-php
Specifically these examples:
https://github.com/consolibyte/quickbooks-php/tree/master/docs/partner_platform/example_app_ipp_v3
Which have a working example of the Blue Dot menu all ready to go for you, wrapped up in a nice OOP wrapper:
https://github.com/consolibyte/quickbooks-php/blob/master/docs/partner_platform/example_app_ipp_v3/menu.php
It's this simple:
<?php
require_once dirname(__FILE__) . '/config.php';
// Display the menu
die($IntuitAnywhere->widgetMenu($the_username, $the_tenant));
You can have a look at the following JAVA implementation.
https://github.com/IntuitDeveloperRelations/IPP_Sample_Code/blob/master/QuickbooksAPI/Java/Spring%20Application/QuickBooksAPI/src/main/java/com/intuit/controller/support/BluedotController.java
You need to make the following call in the PHP way(using the OAuth and Http libs).
final IAPlatformClient pClient = new IAPlatformClient();
final StringBuffer stringBuffer = new StringBuffer();
final List<String> menuList = pClient.getAppMenu(WebUtils.OAUTH_CONSUMER_KEY, WebUtils.OAUTH_CONSUMER_SECRET, accesstoken, accessstokensecret);
Other things are quite straight forward.
Hope it will be helpful.
Thanks

How can I analyze xdebug function-tracing output

I am creating function-tracing xt files with xdebug which are are created with php commands like
xdebug_start_trace('outfile')
... code ...
xdebug_stop_trace();
How can I analyze/visualize the created data?
See the documentation and the answers to this question.
You may be able to use https://github.com/corretge/xdebug-trace-gui. There are also other tools available, such as ValaXdebugTools and XDebugUtils.
And, of course, you can always roll your own solution.

Check if Google Map Point is in polygon from PHP

I've been looking for a way to check if a point is part of a polygon; this polygon is loaded from a file.
All the answers related to this question are solved with javascript, but I require to do this on server-side; this because the result does not need to be shown to the user as a webclient, it needs to be stored and later be used as a parameter to select a group of users (that use the system) inside that area (polygon).
I looked for a Google Maps API for PHP but it looks like it does not exists at all. I found this one, but it is not related to Google and also focuses on the front end.
I also looked for a REST API; it would have been relatively easy to load the content to my php and parse it, but looks like Google put all its efforts on the JS API.
Is there any workaround for this?
Edit 1: As #Spacedman requested, the file format is a KML
Clarification 1: I expected that Google provide a tool for this (as it exists with JS); parsing the file to check via an algorithm is a posibility and I'll have to check if it works properly.
Did you try searching for "php point in polygon" in your favourite search engine? Top hit:
http://assemblysys.com/php-point-in-polygon-algorithm/
It uses a scanline algorithm, and there's some examples. All you need to do is read your polygon file into the right format (you neglected to say what format you have) and call the function.
You can try somthing like this (in php should be similar):
int iCheck=0;
for (i = 0, v = HowManyVecotrsHasThePolygon - 1; i < HowManyVecotrsHasThePolygon; v = i++)
{
if (((vectorPointLatitud[i] > ptoLatitud) != (vectorPointLatitud[v] > ptoLatitud)) && (ptoLongitud < (vectorPointLongitud[v] - vectorPointLongitud[i]) * (ptoLatitud - vectorPointLatitud[i]) / (vectorPointLatitud[v] - vectorPointLatitud[i]) + vectorPointLongitud[i]))
iCheck++;
}
if iCheck is pair the point is outside, even inside
Checkout Polygons Eric Haines. I got the idea from him.
The idea is you've to create a Ray from your point, and check how many intersections between this ray and the Polygons vectors
The algorithm is just a bit of algebra, that you can check in any book.
You could use the PHP V8 PECL extension to execute javascript within PHP. Alternatively, you could call a node.js script using a shell command (which essentially does the same thing).
http://php.net/manual/en/book.v8js.php
http://php.net/manual/en/function.shell-exec.php

Scala Lift - Run PHP file from within scala runtime

I'm not entirely sure the wording for the title is correct, but what I'm attempting to do is run and execute PHP files from within the Lift framework.
I'm not after any url queries to a PHP file residing on a server, more interested in somehow getting the PHP runtime working through my Scala/Lift app.
Use case: I have my app packaged into a .war file, I host this via a cloud provider. I upload code snippets to said app which then runs the php file and does whatever necessary.
I've seen various posts regarding Bianca but am hoping to keep this setup light and require only the PHP binary itself and a little code to get it flying.
Thanks in advance, please let me know if you need me to elaborate :)
“Never say never, because limits, like fears, are often just an
illusion.”
― Michael Jordan
What you really need is an open source (GPL), embeddable, full PHP 5 implementation, written entirely in Java!
Caucho's Quercus PHP Java runtime is just that, and it will let you run PHP within a Java app without external libraries or native code.
Below is a Quercus-PHP-in-Java code sample I found in this answer
import javax.script.ScriptEngine;
import com.caucho.quercus.script.QuercusScriptEngineFactory;
QuercusScriptEngineFactory factory = new QuercusScriptEngineFactory();
ScriptEngine engine = factory.getScriptEngine();
String phpCode = "<?php $foo = strlen('abc'); print $foo; return 'yikes'; ?>"; //PHP Code as String
Object o = engine.eval(phpCode);
System.out.println(o);
It should be little effort to convert this code to idiomatic Scala. Obviously, the 'phpCode' variable could be constructed from external PHP file contents etc.
Let us know how you get on ;-)
That's a bit of an odd requirement, but if it's what you need to do, you can use a ProcessBuilder to execute and interact with your PHP script from the command line.

How to read GTFS protocol buffer in PHP?

I have a GTFS protocol buffer message (VehiclePosition.pb), and the corresponding protocol format (gtfs-realtime.proto), I would like to read the message in PHP alone (is that even possible?).
I looked at Google's python tutorial https://developers.google.com/protocol-buffers/docs/pythontutorial and encoding documentation https://developers.google.com/protocol-buffers/docs/encoding and https://github.com/maxious/ACTBus-ui/tree/master/lib/Protobuf-PHP, but I am having a really hard time conceptualizing what is going on. I think I understand that gtfs-realtime.php is a compiled instruction set of the encoding defined in gtfs-realtime.proto (please correct me if I am wrong), but I have no clue how to get it to decode VehiclePosition.pb. Also, what are the dependencies of gtfs-realtime.php (or the python equivalent for that matter)? Is there anything else I have to compile myself or anything that is not a simple php script if all I want to do is read VehiclePosition.pb?
Thanks.
edmonscommerce and Julian are on the right track.
However, I've gone down the same path and I've found that the PHP implementation of Protocol Buffers is cumbersome (especially in the case of NYCT's MTA feed).
Alternative Method (Command Line + JSON):
If you're comfortable with command line tools and JSON, I wrote a standalone tool that converts GTFS-realtime into simple JSON: https://github.com/harrytruong/gtfs_realtime_json
Just download (no install), and run: gtfs_realtime_json <feed_url>
Here's a sample JSON output.
To use this in PHP, just put gtfs_realtime_json in the same directory as your scripts, and run the following:
<?php
$json = exec('./gtfs_realtime_json "http://developer.mbta.com/lib/GTRTFS/Alerts/VehiclePositions.pb"');
$feed = json_decode($json, TRUE);
var_dump($feed);
You can use the official tool: https://developers.google.com/transit/gtfs-realtime/code-samples#php
It was released very recently. I've been using it for a few days and works like a charm.
I would assume something along the lines of this snippet:
<?php
require_once 'DrSlump\Protobuf.php';
use DrSlump\Protobuf;
$data = file_get_contents('data.pb');
$person = new Tutorial\Person($data);
echo $person->getName();
as taken from the man page: http://drslump.github.io/Protobuf-PHP/protobuf-php.3.html
Before that step, I think you need to generate your PHP classes using the CLI tool as described here: http://drslump.github.io/Protobuf-PHP/protoc-gen-php.1.html
so something along the lines of:
protoc-gen-php gtfs-realtime.proto
Sorry Harry Truong, I tried your executable but it returns always NULL.
What I am doing wrong?
Edit: The problem is that I have no permission to execute in my server. Thanks for your executable.

Categories