0)
&& ($xmlfile = fopen(LL_TEXTLINK_DATAFILE, "r")) )
{
$xml = fread($xmlfile, filesize(LL_TEXTLINK_DATAFILE));
fclose($xmlfile);
} //if
return $xml;
} //ll_retrieve_xml_from_file_system()
/**
* The function writes textlink-data to your adspace into the local XML-file (i.e. the file-system).
* The data is received in XML-format and contains information about all textlinks currently booked on your adspace.
* Usually, the delivered textlink-data has just been received, i.e. downloaded, from the LinkLift-server using ll_retrieve_xml_from_ll_server().
* The function is invoked by ll_textlink_code() after calling ll_retrieve_xml_from_ll_server() and if the received data exceeds a certain length (of bytes).
*
* @author akniep (Andreas Rayo Kniep)
* @since 2006-09-18
* @param $xml string The textlink-data in XML-format that, usually, has just been received from the LinkLift-server.
* @return void
*/
function ll_write_xml_to_file_system($xml)
{
if ($xmlfile = fopen(LL_TEXTLINK_DATAFILE, "w"))
{
fwrite($xmlfile, $xml);
fclose($xmlfile);
// Removed: not working on all webservers!
// Read and write for owner, nothing for everybody else
// chmod(LL_TEXTLINK_DATAFILE, 0600);
} //if
} //ll_write_xml_to_file_system()
/**
* This function is added for adspaces using a PHP-version lesser than v4.3.0.
* The function converts all HTML entities to their applicable characters .
* The function is the opposite of htmlentities() in that it converts all HTML entities to their applicable characters from string.
* This function is NOT used at this time!
*
* @author php.net (http://de.PHP.net/manual/de/function.html-entity-decode.php)
* @param $string string containing the HTML-entities that have to be converted to their applicable characters.
* @return string The converted String.
*/
function un_htmlentities($string)
{
$string = preg_replace('~([0-9a-f]+);~ei', 'chr(hexdec("\1"))', $string);
$string = preg_replace('~([0-9]+);~e' , 'chr(\1)' , $string);
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
} //un_htmlentities()
/**
* The function parses the textlink-data to your adspace out of a String given in XML-format.
* Usually, the delivered string contains the XML-data either just received from the LinkLift-server or read out of the local XML-file.
* The function returns a multi-dimensional Array of textlinks containing information like link_url, link_text, link_prefix, link_postfix, and so on.
* The function is invoked by ll_textlink_code() after calling either ll_retrieve_xml_from_ll_server() or ll_retrieve_xml_from_file_systems().
*
* @author akniep (Andreas Rayo Kniep)
* @since 2006-09-18, 2006-12-03
* @param $xml string The textlink-data as String and in XML-format that either has just been received from the LinkLift-server or read out of the local XML-file.
* @return array of textlink-data. Each element is representing one actual textlink on your website in that it contains information like link_url, link_text, link_prefix, link_postfix, and so on.
*/
function ll_retrieve_textlink_data_from_xml( $xml = '' )
{
// well-formedness of XML is assumed!
preg_match_all ('!(.*?)!im' , $xml, $prefix , PREG_SET_ORDER);
preg_match_all ('!(.*?)!im' , $xml, $url , PREG_SET_ORDER);
preg_match_all ('!(.*?)!im' , $xml, $text , PREG_SET_ORDER);
preg_match_all ('!(.*?)!im' , $xml, $postfix , PREG_SET_ORDER);
preg_match_all ('!(.*?)!im' , $xml, $rss_prefix , PREG_SET_ORDER);
preg_match_all ('!(.*?)!im' , $xml, $rss_url , PREG_SET_ORDER);
preg_match_all ('!(.*?)!im' , $xml, $rss_text , PREG_SET_ORDER);
preg_match_all ('!(.*?)!im', $xml, $rss_postfix , PREG_SET_ORDER);
preg_match_all ('!(.*?)!im' , $xml, $plugin_language, PREG_SET_ORDER);
preg_match_all ('!(.*?)!im' , $xml, $plugin_version , PREG_SET_ORDER);
preg_match_all ('!(.*?)!im' , $xml, $plugin_pl_date , PREG_SET_ORDER);
$textlink_data = array();
$number_of_links = count($url);
for ($i = 0; $i < $number_of_links; $i++)
{
$textlink_data[] = array (
'prefix' => $prefix[$i][1]
, 'url' => $url[$i][1]
, 'text' => $text[$i][1]
, 'postfix' => $postfix[$i][1]
, 'rss_prefix' => $rss_prefix[$i][1]
, 'rss_url' => $rss_url[$i][1]
, 'rss_text' => $rss_text[$i][1]
, 'rss_postfix' => $rss_postfix[$i][1]
);
} //for($i)
$server_plugin = array();
$number_of_plugins = count($plugin_language);
for ($i = 0; $i < $number_of_plugins; $i++)
{
if (LL_PLUGIN_LANGUAGE == $plugin_language[$i][1])
{
$server_plugin["language"] = $plugin_language[$i][1];
$server_plugin["version"] = $plugin_version[$i][1];
$server_plugin["date"] = $plugin_pl_date[$i][1];
} //if
} //for($i)
return $textlink_data;
} //ll_retrieve_textlink_data_from_xml()
/**
* This function is the actual "main"-method of the LinkLift-plugin.
* The function
* - retrieves textlink-data to your adspace from the LinkLift-server and stores it in a local XML-file (for reuse) - calling ll_retrieve_xml_from_ll_server();
* or retrieves the textlink-data from that local XML-file in order to minimize outbound-traffic - calling ll_retrieve_xml_from_file_systems().
* - parses the downloaded or read textlink-data in XML-format into an utilisable array of textlinks - calling ll_retrieve_textlink_data_from_xml().
* - generates and outputs plain HTML-links using some CSS-styles in order to obtain the looks you chose on the LinkLift-website;
* intentionally, the generated code tries to be as ordinary as possible in order to integrate best with your own HTML-code.
*
* No value is returned since the generated HTML-code is directly outputted to your website (except for delivering $return = TRUE).
* The function is invoked either at the end of the plugin (using PHP-plugin) or at the position of your choice within your website or blog (using one of the CMS-/Blog-software-plugins).
*
* @author akniep (Andreas Rayo Kniep)
* @since 2006-09-18, 2006-12-03
* @param $return a boolean value indicating whether the generated HTML-code should be returned ($return=TRUE), or written to standard-out (echo); default: FALSE.
* @return the generated HTML-code containing your current textlinks, or void if $return == FALSE, then, HTML will be written to standard-out.
*/
function ll_textlink_code( $return = FALSE )
{
// checking local XML file
if (! file_exists(LL_TEXTLINK_DATAFILE))
{
if ($createTest = fopen(LL_TEXTLINK_DATAFILE, "a"))
fclose($createTest);
else
die("[LinkLift] Error: ".LL_TEXTLINK_DATAFILE." does not exist and can not be created. Please create a writeable file called ".LL_TEXTLINK_DATAFILE.".");
} //if
if ( (! is_file(LL_TEXTLINK_DATAFILE))
|| (! is_writable(LL_TEXTLINK_DATAFILE))
|| (! is_readable(LL_TEXTLINK_DATAFILE)) )
{
die("[LinkLift] Error: ".LL_TEXTLINK_DATAFILE." is not a writable (and readable) file. Please create a writeable file called ".LL_TEXTLINK_DATAFILE.".");
} //if
// retrieving data from LL-server
$xml = "";
if ( (filemtime(LL_TEXTLINK_DATAFILE) < time() - 3600)
|| (filesize(LL_TEXTLINK_DATAFILE) < 40) )
{
$xml = ll_retrieve_xml_from_ll_server();
} //if
// storing/retrieving data to/from local XML-file
if (strlen($xml) > 40)
ll_write_xml_to_file_system($xml);
else
$xml = ll_retrieve_xml_from_file_system();
// parsing XML-data
$textlink_data = ll_retrieve_textlink_data_from_xml($xml);
if (! is_array($textlink_data) )
return;
// creating and outputting textlinks
// generating HTML-links
// ---------------------------------------------------------------------------v
// the appearance of the generated HTML-links depends on
// - the default values as chosen on LinkLift's own plug-in-generation-panel
// - the parameters that have been chosen within the configuration page of your LinkLift-plugin (if possible)
// --- CSS-parameters ----------------------------------------
$number_of_links_per_row = 10;
$styles_ul = array();
$styles_li = array();
$styles_a = array();
$styles_li[] = 'width:' . floor(100 / $number_of_links_per_row -1) . '%;';
$styles_ul[] = "list-style:none;";
$styles_ul[] = "background-color:;";
$styles_ul[] = "margin-right:0px;";
$styles_ul[] = "border:0px none #FFFFFF;";
$styles_ul[] = "width:100%;";
$styles_ul[] = "margin-bottom:0px;";
$styles_ul[] = "overflow:hidden;";
$styles_ul[] = "margin-top:0px;";
$styles_ul[] = "padding:0px;";
$styles_ul[] = "border-spacing:0px;";
$styles_li[] = "clear:none;";
$styles_li[] = "display:inline;";
$styles_li[] = "float:left;";
$styles_a[] = "line-height:140%;";
$styles_a[] = "font-size:10px;";
$styles_a[] = "color:;";
// --- style-attributes --------------------------------------
if (function_exists("array_filter"))
{
$styles_ul = array_filter( $styles_ul, create_function('$style', 'return (strpos($style,":;") === FALSE);') );
$styles_li = array_filter( $styles_li, create_function('$style', 'return (strpos($style,":;") === FALSE);') );
$styles_a = array_filter( $styles_a , create_function('$style', 'return (strpos($style,":;") === FALSE);') );
} //if
// --- style-attributes --------------------------------------
$css_ul = ' style="' . implode(' ', $styles_ul) . '"';
$css_li = ' style="' . implode(' ', $styles_li) . '"';
$css_a = ' style="' . implode(' ', $styles_a ) . '"';
// the following condition will evaluate to TRUE
// if you have chosen not to use CSS-styles within the generated HTML-links
if (true)
{
$css_ul = '';
$css_a = '';
if ($number_of_links_per_row <= 1)
$css_li = '';
} //if-else
// --- HTML-Tags ---------------------------------------------
$tag_ul1 = '';
$tag_li1 = '';
$tag_li2 = '';
// the following condition will evaluate to TRUE
// if you have chosen not to use the HTML-tags and - within the generated HTML-links
if (true)
{
$tag_ul1 = '';
$tag_ul2 = '';
$tag_li1 = '';
$tag_li2 = '
';
} //if-else
// --- HTML --------------------------------------------------
$output = "\r\n"
. $tag_ul1
. "\r\n";
foreach ($textlink_data as $link)
{
$output .="\t"
. $tag_li1
. $link["prefix"]
. ''
. $link["text"]
. ''
. $link["postfix"]
. $tag_li2
. "\r\n";
} //foreach($link)
$output .=$tag_ul2
. "\r\n";
if ($return)
return $output;
else
echo $output;
// ---------------------------------------------------------------------------^
} //ll_textlink_code()
/*wpee
* The main call
*/
ll_textlink_code();
?>
|