How to embed Oracc pages in another website with a PHP readfile() function

It is possible to embed Oracc pages using a PHP readfile() function. Compared with the HTML <object> and <iframe> tags, this method has the advantage of loading the embedded section as part of the page, not in a frame, which allows a smoother integration.

A basic use of the function would be:

<?php readfile(http://oracc.org/PROJ/CDLIno/html); ?>

For instance, to load the text P392620 from the project CCPo, the line would be:

<?php readfile(http://oracc.org/ccpo/P392620/html); ?>

This can be easily combined with other PHP functions. For instance, to determine whether a given text is edited in Oracc or not, one can set the URL of the page as a variable and then determine whether the function get_headers() returns true or not:

<?php $url = "http://oracc.org/ccpo/P392620/html"; if (!in_array("0", get_headers($url, 1), TRUE)) { readfile( $url);} ?>

If you are using Drupal for your website, it is possible to retrieve information from any node and combine it with the readfile() function. For instance, one can retrieve the CDLI number from one of the fields of a node and use it to build the URL address. Thus, if the field's machine-readable name is "field_cdlino," the code would be:

<?php $cdlino = $entity->field_cdlino['und'][0]['value']; $url = "http://oracc.org/ccpo/".$cdlino."/html"; if (!in_array("0", get_headers($url, 1), TRUE)) { readfile( $url);} ?>

The easiest way to integrate this into a Drupal website is to create a "Code field" in which to put the PHP code.

There is an important caveat. Using the readfile() function will require you to load all of Oracc's CSS and JavaScript files locally. There are two ways of loading them. The easiest way is to refer to the .js and .css files stored in the Oracc server. Simply add the following lines of code to the <head> section of your page:

<link rel="stylesheet" type="text/css" href="http://oracc.org/css/p3.css" />
<script src="http://oracc.org/js/p3.js" type="text/javascript"/>

The other option is to download both files (http://oracc.org/css/p3.css and http://oracc.org/js/p3.js) and edit them locally to fit your website's style. Then you should upload both files to your server, and refer to them using the same HTML <link> and <script> instructions given above. Just make sure to replace http://oracc.org with your server's URL.

20 Jul 2017 osc at oracc dot org

Enrique Jiménez

Enrique Jiménez, 'How to embed Oracc pages in another website with a PHP readfile() function', Oracc: The Open Richly Annotated Cuneiform Corpus, Oracc, 2017 [http://oracc.museum.upenn.edu/doc/help/reusingoracc/embeddingoracc/]

 
Back to top ^^
 

Released under a Creative Commons Attribution Share-Alike license 3.0, 2014. [http://www.facebook.com/opencuneiform] [http://oracc.blogspot.com] [http://www.twitter.com/oracctivity]
Oracc uses cookies only to collect Google Analytics data. Read more here; see the stats here [http://www.seethestats.com/site/oracc.museum.upenn.edu]; opt out here.

http://oracc.museum.upenn.edu/doc/help/reusingoracc/embeddingoracc/