source: trunk/www.guidonia.net/wp/wp-content/plugins/linklift/linklift_divcom.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 15 years ago
File size: 81.4 KB
RevLine 
[44]1<?php
2/*
3Plugin Name: LinkLift (Widgets)
4Plugin URI: http://www.linklift.it/vendere-text-links/?ref=b173a484859
5Description: Link di testo sulla tua blog che si trasformano direttamente in soldi nelle tue tasche - guadagni fissi indipendenti dai click! <a href="http://www.linklift.it/vendere-text-links/?ref=b173a484859" target="_blank">Registarti ora su LinkLift</a>. Facile da <strong><a href="options-general.php?page=linklift-configuration&" target="_self">configurare</a></strong>.
6Author: Andreas Rayo Kniep
7Version: 1.55
8Author URI: http://www.linklift.it/?ref=b173a484859
9*/
10// tab-size within this source: 4 spaces
11
12
13
14/** This is the plug-in's name that is used by Wordpress
15 * to identify the LinkLift-textlinks-plug-in internally.
16 * You may change this constant in order to change the plug-in's name
17 * as shown in the Wordpress-Widgets-panel.
18 * Names are usually randomised iff they will appear in the generated source-code of the CMS.
19 * Constant names that appear in the source-code increase the detectability of the plug-in!
20 */
21@define( "LL_PLUGIN_NAME" , "divcom" );
22
23@define( "LL_PLUGIN_MENU_FILENAME" , "linklift-configuration" );
24@define( "LL_PLUGIN_REGISTER_LINK_URL" , "https://www.linklift.it/vendere-text-links/?ref=b173a484859" );
25
26
27// variable names of Wordpress-options-keys
28@define( "LL_OPTION_SERVER_VERSION" , "linklift_plugin_wordpress_server_version" );
29@define( "LL_OPTION_SERVER_DATE" , "linklift_plugin_wordpress_server_date" );
30@define( "LL_OPTION_SERVER_LANGUAGE" , "linklift_plugin_wordpress_server_language" );
31
32@define( "LL_OPTION_SERVER_VERSION_CHECK_DATE" , "linklift_plugin_wordpress_server_version_check_date" );
33
34
35/** The following constants contain Wordpress-specific-filenames
36 * that are used within the plug-in in order to generate links between Wordpress-admin-pages.
37 */
38@define( "LL_WORDPRESS_FILE_PLUGINS" , "plugins.php" );
39@define( "LL_WORDPRESS_FILE_OPTIONS_GENERAL" , "options-general.php" );
40@define( "LL_WORDPRESS_FILE_THEME_EDITOR" , "theme-editor.php" );
41@define( "LL_WORDPRESS_FILE_ADMIN_FUNCTIONS" , "admin-functions.php" );
42
43if (file_exists(LL_WORDPRESS_FILE_OPTIONS_GENERAL))
44 @define( "LL_LINKLIFT_CONFIGURATION_PAGE" , LL_WORDPRESS_FILE_OPTIONS_GENERAL . "?page=" . LL_PLUGIN_MENU_FILENAME . "&" );
45elseif (file_exists(LL_WORDPRESS_FILE_PLUGINS))
46 @define( "LL_LINKLIFT_CONFIGURATION_PAGE" , LL_WORDPRESS_FILE_PLUGINS . "?page=" . LL_PLUGIN_MENU_FILENAME . "&" );
47else
48 @define( "LL_LINKLIFT_CONFIGURATION_PAGE" , false );
49
50
51/** Checking for Wordpress-widgets-plug-in ...
52 * - If pre-installed an admin-file "widgets.php" exists.
53 * - If installed as Wordpress-plug-in a respective plug-in exists.
54 */
55if (file_exists("widgets.php"))
56{
57 @define( "LL_WORDPRESS_WIDGETS_INSTALLED" , true );
58 @define( "LL_WORDPRESS_FILE_WIDGETS" , "widgets.php?" );
59
60} else {
61 // the method get_plugins is only accessible if the file admin-functions.php has been included
62 // if it has not yet been included we will try so, now:
63 if (file_exists(LL_WORDPRESS_FILE_ADMIN_FUNCTIONS))
64 @include_once(LL_WORDPRESS_FILE_ADMIN_FUNCTIONS);
65
66 if (function_exists("get_plugins"))
67 $installed_plugins = get_plugins();
68 else
69 $installed_plugins = array();
70
71
72 if (isset($installed_plugins["widgets/widgets.php"]))
73 {
74 @define("LL_WORDPRESS_WIDGETS_INSTALLED", true );
75 @define("LL_WORDPRESS_FILE_WIDGETS" , "themes.php?page=widgets/widgets.php&" );
76
77 } else {
78 // no Wordpress-widgets-plug-in installed!
79 @define("LL_WORDPRESS_WIDGETS_INSTALLED", false );
80 } //if-else
81} //if-else
82
83
84
85
86// default language: english
87$plugin_default_lang = "en";
88
89// trying to extract the installed language out of the Wordpress-constant 'WPLANG':
90if (defined("WPLANG"))
91 $wordpress_language = strtolower( substr( WPLANG, 0, 2 ) );
92else
93 $wordpress_language = $plugin_default_lang;
94
95// language-specific texts
96$language_file_wordpress = dirname(__FILE__) . "/linklift_divcom_lang_" . $wordpress_language . ".inc.php";
97$language_file_default = dirname(__FILE__) . "/linklift_divcom_lang_" . $plugin_default_lang . ".inc.php";
98
99// all not-translated texts will be taken from the english text-file (if existing) ...
100if (file_exists($language_file_wordpress))
101 @include_once( $language_file_wordpress );
102if (file_exists($language_file_default))
103 @include_once( $language_file_default );
104
105
106
107
108/* ****************************************************************
109 * adspace: Your Wordpress Website *
110 * creation date: 2008-06-06 *
111 * contact: supporto@linklift.it *
112 * script-version: 1.552 (2008-05-01) *
113 * ****************************************************************/
114// this PHP-script runs on PHP-engines >= v4.0.6
115// tab-size of this document: 4 spaces
116
117
118
119/** Disabling all error- (, warning-, and notice-) messages...
120 * You may want to un-comment the following lines when testing or debugging this plugin.
121 * At the end of the plugin you may restore the original reporting-level using the following call:
122 * error_reporting( $linklift_saved_reporting_level );
123 *
124 * Note: there is another call of error_reporting() in this plugin's method execute()!
125 *
126 * default: E_ERROR | E_WARNING | E_PARSE
127 * all messages: E_ALL
128 * only errors: E_ERROR
129 * no messages: 0
130 *
131 */
132$linklift_saved_reporting_level = error_reporting();
133// error_reporting( E_ALL );
134
135
136
137
138
139/**
140 * The LinkLift-website-key identifies your website on the LinkLift-marketplace.
141 */
142@define( "LL_WEBSITE_KEY" , "" ); // has to be configured by you (you can use the LinkLift-configuration-page within Wordpress)
143
144
145
146
147/** The script-version-constants are used for checking
148 * if a newer version of your plug-in is available on the LinkLift-server.
149 * Note: the plug-in will not update itself, at this time.
150 */
151@define( "LL_PLUGIN_LANGUAGE" , "wordpress" );
152@define( "LL_PLUGIN_VERSION" , "1.552" ); // italian included
153@define( "LL_PLUGIN_DATE" , "2008-05-01" );
154@define( "LL_PLUGIN_CREATION_DATE" , "20080606125341" );
155
156@define( "LL_UPDATE_CHECK_TIMEFRAME" , "-1 week" );
157
158@define( "LL_PLUGIN_SECRET_BASE" , "linklift_onetime_password" );
159@define( "LL_ONE_TIME_PASSWORD_ANSWER_TAG" , "linklift_onetime_answer" );
160
161
162/** In order to not block the page-load-progrss
163 * a time-limit (in seconds) is set when receiving new data from the LinkLift-server.
164 */
165@define( "LL_DATA_TIMEOUT" , 7 );
166
167
168/**
169 * The server-host to connect to in order to download data from LinkLift-server.
170 */
171@define( "LL_SERVER_HOST" , "external.linklift.net" );
172@define( "LL_SERVER_URL" , "http://" . LL_SERVER_HOST . "/" );
173
174
175
176@define( "LL_OPTION_PLUGIN_SECRET" , "linklift_plugin_secret" );
177// value of linklift-plugin-secret may differ if this plugin is part of a blog-hoster or multi-blog-system
178$linklift_plugin_secret = get_option( LL_OPTION_PLUGIN_SECRET );
179if (empty($linklift_plugin_secret))
180 @define( "LL_PLUGIN_SECRET" , LL_PLUGIN_SECRET_BASE );
181else
182 @define( "LL_PLUGIN_SECRET" , $linklift_plugin_secret );
183
184
185
186
187
188
189// if the plugin's individual "secret" is delivered the plugin's so-called SECRET-MODE is entered. Necessary for entering the plugin's DEBUG_MODE.
190if ( ( (! empty($_REQUEST["ls"]))
191 && (LL_PLUGIN_SECRET === $_REQUEST["ls"])
192 )
193 || ( (! empty($_SERVER["REQUEST_URI"]))
194 && (preg_match('@ls.' . LL_PLUGIN_SECRET . '@', $_SERVER["REQUEST_URI"]))
195 )
196 )
197{
198 @define( "LL_SECRET_MODE" , true );
199} else {
200 @define( "LL_SECRET_MODE" , false );
201} //if-else
202
203
204/** a possible debug-mode helping to analyse problems and functionality of the plugin
205 * existing LL_DEBUG_MODEs:
206 * 1: Display internal testlink with maximum length and umlauts
207 * 2: Display the object's / plugin's current data / state
208 * 3: Display the current XML-cache
209 * 4: Displays some "internal values" like values of LinkLift-constants or the surrounding CMS' resolved language.
210 * 5: Update the XML-cache (externally forced update)
211 * 10: Displays the running script's filename
212 * 99: Known debug-modes
213 */
214if ( (LL_SECRET_MODE)
215 &&
216 ( ( (! empty($_REQUEST["ld"]))
217 && (is_numeric($_REQUEST["ld"]))
218 )
219 || ( (! empty($_SERVER["REQUEST_URI"]))
220 && (preg_match('@ld.(\d\d?)@', $_SERVER["REQUEST_URI"], $debug_mode_matches))
221 )
222 )
223 )
224{
225 if (isset($debug_mode_matches[1]))
226 @define( "LL_DEBUG_MODE" , $debug_mode_matches[1] );
227 else
228 @define( "LL_DEBUG_MODE" , $_REQUEST["ld"] );
229
230} else {
231 @define( "LL_DEBUG_MODE" , false );
232} //if-else
233
234
235
236
237
238
239if (! class_exists("LinkLiftPlugin"))
240{
241
242class LinkLiftPlugin
243{
244
245
246
247
248
249// A LinkLift-website-key other than the class' constant LL_WEBSITE_KEY that should be used for updating the locally cached XML-data.
250var $linklift_website_key;
251// A XML-filename other then the class' constant above. This property will have no effect if your plugin uses a local database for caching.
252var $xml_filename = "";
253// An array of integers representing the textlinks of the current textlink-data-array that should be generated and printed. You may want to use this property in order to distribute your textlinks on different locations of your website, to give an example. E.g: $links_to_show = array(1,3,5,7,9).
254var $links_to_show;
255
256// the current XML-cache
257var $xml_cache;
258// the last time the XML-cache has been updated
259var $xml_cache_time;
260
261// other variables, mainly copying linklift-constants
262var $data_timeout = LL_DATA_TIMEOUT;
263var $plugin_language = LL_PLUGIN_LANGUAGE;
264var $plugin_version = LL_PLUGIN_VERSION;
265var $plugin_date = LL_PLUGIN_DATE;
266var $plugin_creation_date = LL_PLUGIN_CREATION_DATE;
267
268
269
270
271
272/**
273 * Usually, instances of the LinkLift-plugin's class do not need an (individual) state.
274 * Thus, in general, we will need at most one instance of the plugin-class in order to generate HTML-output out of external data (XML-textlink-data).
275 *
276 * The class-method will always return the same object (singleton) or create a new one for you if none exists.
277 *
278 * Note: Since the method returns a reference you have to de-reference the result; e.g.:
279 * $new_instance =& LinkLiftPlugin::getInstance();
280 *
281 * @author akniep (Andreas Rayo Kniep)
282 * @since 2007-10-26
283 * @return instance-reference on the class's singleton
284 */
285function &getInstance()
286{
287 static $singleton;
288
289 if ( (! is_object($singleton))
290 || (null == $singleton)
291 || (empty($singleton->linklift_website_key)) )
292 {
293 $singleton = new LinkLiftPlugin();
294 } //if
295
296 return $singleton;
297} //getInstance()
298
299/**
300 * Using the class' constructor you can obtain an instances of the LinkLift-plugin's having an individual state.
301 *
302 * @author akniep (Andreas Rayo Kniep)
303 * @since 2007-10-26, 2007-12-10
304 * @param $linklift_website_key string The LinkLift-website-key that should be used for updating the locally cached XML-data. If empty the method will use the default website-key that you can either find as a constant above or as value in your local database. Usually, this parameter is unused and empty!
305 * @param $xml_filename string The filename of the local XML-file that should be used for caching textlink-data iff your plugin does not use a local database for caching. If empty the method will use the default XML-filename that you can find as constant above. Usually, this parameter is unused and empty!
306 * @param $links_to_show array of integers representing the textlinks of the current textlink-data-array that should be generated and printed by this instance. You may want to use this parameter in order to distribute your textlinks on different locations of your website, to give an example. E.g.: $links_to_show = array(0,2,4,6,8). Usually, this parameter is unused and empty!
307 * @return new instance of the LinkLift-plugin-class LinkLiftPlugin
308 */
309function LinkLiftPlugin( $linklift_website_key = "", $xml_filename = "", $links_to_show = array() )
310{
311 if (empty($linklift_website_key))
312 {
313 // plugin-specific saving and loading
314 $linklift_website_key = LinkLiftPlugin::ll_get_option("linklift_website_key", "");
315 if (empty($linklift_website_key))
316 $linklift_website_key = LinkLiftPlugin::ll_translate( "LINKLIFT_WEBSITE_KEY" );
317
318 } //if
319
320 $instance_linklift_website_key = ( (! empty($linklift_website_key)) ? ($linklift_website_key) : (LL_WEBSITE_KEY) );
321
322
323
324 if ( (empty($xml_filename))
325 && (defined("LL_TEXTLINK_DATAFILE")) )
326 {
327 $xml_filename = LL_TEXTLINK_DATAFILE;
328 } //if-else
329
330
331
332 // saving instance-properties
333 $this->setWebsiteKey( $instance_linklift_website_key );
334 $this->setXmlFilename( $xml_filename );
335 $this->setLinksToShow( $links_to_show );
336
337
338
339 if (file_exists( $this->getXmlFilename() ))
340 $this->setXmlCacheTime( filemtime($this->getXmlFilename()) );
341} //__construct()
342
343
344/**
345 * This method creates an instance of class LinkLiftPlugin and invokes its main-function ll_textlink_code
346 * in order to generate and output HTML-code with your textlinks (to standard-out) using the default linklift-website-key.
347 *
348 * This method wraps the calls of getInstance() and ll_textlink_code() and contains no further logic.
349 *
350 * class-method ("static")
351 *
352 * @author akniep (Andreas Rayo Kniep)
353 * @since 2007-12-17
354 * @param $return boolean, Indicating whether the generated HTML-code should be returned ($return == true), or written to standard-out (echo); default: false.
355 * @return void
356 */
357function execute( $return = false )
358{
359 // not displaying error-messages while executing the LinkLift-plugin
360 $linklift_saved_reporting_level = error_reporting();
361 error_reporting( 0 );
362
363
364 $linklift_plugin_instance =& LinkLiftPlugin::getInstance();
365 $textlink_code =& $linklift_plugin_instance->ll_textlink_code( $return );
366
367
368 // restoring original error-reporting-level
369 error_reporting( $linklift_saved_reporting_level );
370
371
372 return $textlink_code;
373} //execute()
374
375
376/**
377 * Detects and returns the given string's encoding using mb_detect_encoding.
378 * class-method ("static")
379 *
380 * @author akniep (Andreas Rayo Kniep)
381 * @since 2007-12-10
382 * @param $string string, the encoding of which should be deteceted.
383 * @return string the detected encoding or an empty string of no encoding could have been detected.
384 */
385function ll_mb_detect_encoding( $string )
386{
387 if (function_exists("mb_detect_encoding"))
388 return mb_detect_encoding( $string
389 , $encoding_list = array( "UTF-8", "ISO-8859-1", "ISO-8859-15", "ASCII" )
390 );
391 else
392 return "";
393} //ll_mb_detect_encoding()
394
395/**
396 * Calls a given string-function with the given
397 * Unlike strtolower, this method tries to detect the given string's encoding (calling ll_mb_detect_encoding())
398 * and convert using mb_strtolower protecting special characters (e.g. umlauts).
399 *
400 * If the needed functions for detection and conversion are not available
401 * strtolower is used in order to convert the given string.
402 * class-method ("static")
403 *
404 * @author akniep (Andreas Rayo Kniep)
405 * @since 2007-12-10
406 * @param $string_function string, (not callback!) the string-function to be either called directly or after prepending the "mb_"-prefix
407 * @param $param_arr array, of parameters being passed to the $string_function, the first parameter is assumed to be the string to apply the $string_function to
408 * @return mixed the result of the called $string_function or false if a faulty array of parameters was delivered
409 */
410function ll_call_str_function_encoding_dependent( $string_function, $param_arr )
411{
412 if ( (empty($param_arr))
413 || (! is_array($param_arr)) )
414 {
415 return false;
416 } //if
417
418
419 if (function_exists("mb_" . $string_function))
420 {
421 // the first given parameter is assumed to be the string to apply the $string_function to
422 $string = $param_arr[0];
423 $string_encoding = LinkLiftPlugin::ll_mb_detect_encoding( $string );
424
425 if (! empty($string_encoding))
426 {
427 $param_arr[] = $string_encoding;
428
429 // calling the corresponding multibyte PHP-function
430 return call_user_func_array("mb_" . $string_function, $param_arr);
431 } //if
432 } //if
433
434 // calling the original PHP-function working with strings in ASCII-format
435 return call_user_func_array($string_function, $param_arr);
436} //ll_call_str_function_encoding_dependent()
437
438
439/**
440 * The method tries to connect to a given $server_host in order to open a server-socket-connection on port 80
441 * and write the given $request-string to it.
442 * The given $request is expected to be a valid HTTP-request like typical GET- or POST-requests.
443 * The data returned from the $server_host and received within a fixed timeframe will be returned.
444 * The method is invoked by get_404_page() and ll_retrieve_xml_from_ll_server() or ll_send_ping_signal(), respectively (depending on your plugin-type).
445 * class-method ("static")
446 *
447 * @author akniep (Andreas Rayo Kniep)
448 * @since 2006-09-18, 2007-03-12, 2007-12-17
449 * @return $server_host string the host of the server to connect to and send the given $request to.
450 * @return $request string the HTTP-request to be written to the server-socket-connection that is tried to be established with the given $server_host.
451 * @return string the data received from the $server_host after writing the given $request to the opened server-socket-connection, or false if an error occurred.
452 */
453function get_page_content( $server_host, $request, $data_timeout = LL_DATA_TIMEOUT )
454{
455 if ( ($server = fsockopen($server_host, 80, $errno, $errstr, $data_timeout))
456 && (is_resource( $server )) )
457 {
458 if (function_exists("stream_set_blocking"))
459 stream_set_blocking($server, false);
460
461 if (function_exists("stream_set_timeout"))
462 stream_set_timeout( $server, $data_timeout );
463 else
464 socket_set_timeout( $server, $data_timeout );
465
466
467 $connection_start_time = time();
468
469
470 $write_result = fwrite( $server, $request );
471
472 // unable to write to open socket.
473 if (! $write_result)
474 return false;
475
476
477
478 $data = "";
479
480 while (! feof($server))
481 {
482 $data_before = $data;
483 $data .= fread($server, 10000);
484
485 // if no data was received (yet) ...
486 if ($data_before == $data)
487 {
488 // if no data was received and the the data-timout was reached
489 // the download-process will be stopped.
490 if ($data_timeout < time() - $connection_start_time)
491 {
492 $data = "";
493 break;
494 } //if
495
496 // ... go to sleep for 10 ms, waiting for data.
497 // usleep() works on Linux-like servers!
498 // On other systems usleep may have no effect
499 // PHP 5.0.0 claims that usleep works on Windows-systems, as well ...
500 // ... the effect on the system's processor, however, is not known to the writer.
501 if (function_exists("usleep"))
502 usleep($micro_seconds = 10 * 1000); // 10 * 1000 micro seconds = 10 milli seconds = 0.01 seconds
503 } //if
504 } //while
505
506
507 fclose($server);
508
509
510 return $data;
511
512
513 } else {
514 return false;
515 } //if-else
516} //get_page_content()
517
518/**
519 * Downloads the current-plugin-info for the installed plugin from the LinkLift-server.
520 * The method will return an associative array of plugin_data containing (at least) the following fields:
521 * - plugin-version: the current plugin-version of the delivered plugin-language on the LinkLift-server
522 * - plugin-date: the rlease-date of the current plugin-version
523 * - plugin-language: the plugin-language of the plugin-version
524 *
525 * class-method ("static")
526 *
527 * @author akniep (Andreas Rayo Kniep)
528 * @since 2008-02-16
529 * @return $cms_info string additional CMS-info to be sent to the LinkLift-server; usually this contains the version of the CMS this plugin is used in; default: "".
530 * @return array, associative array of plugin-data, see above for more information <OR> false if an error occurred.
531 */
532function ll_get_current_plugin_info( $cms_info = "" )
533{
534 $server_host = LL_SERVER_HOST;
535
536
537 $linklift_website_key = urlencode(LL_WEBSITE_KEY);
538 $linklift_secret = urlencode(LL_PLUGIN_SECRET);
539 $linklift_method = urlencode("current_plugin_version");
540 $cms_info_encoded = urlencode($cms_info);
541
542 $request = "GET /external/external_info.php5"
543 . "?website_key" . "=" . $linklift_website_key
544 . "&linklift_secret" . "=" . $linklift_secret
545 . "&method" . "=" . $linklift_method
546 . "&plugin_language" . "=" . urlencode(LL_PLUGIN_LANGUAGE)
547 . "&plugin_version" . "=" . urlencode(LL_PLUGIN_VERSION)
548 . "&plugin_date" . "=" . urlencode(LL_PLUGIN_DATE)
549 . "&cms_info" . "=" . $cms_info_encoded
550 . " "
551
552 . "HTTP/1.0\n"
553 . "Host: " . $server_host . "\n"
554 . "Connection: Close\n"
555 . "\n"
556
557 . "";
558
559
560 $plugin_info_raw = LinkLiftPlugin::get_page_content( $server_host, $request );
561
562
563 if (empty($plugin_info_raw))
564 return false;
565
566
567
568
569 // splits the received page in header and content
570 $file_parts = preg_split( $pattern = '@\r?\n\r?\n@', $subject = $plugin_info_raw, $limit = 2 );
571
572 $body =& $file_parts[1];
573
574 // every line of the page's body is expected to contain one information
575 $plugin_info_lines = preg_split( $pattern = '@\r?\n@', $subject = $body );
576
577 // every valid information is put into an associative array $plugin_info
578 $plug_info = array();
579 foreach ($plugin_info_lines as $line)
580 {
581 $line_parts = explode( ":", $line, $limit = 2 );
582
583 if (2 === count($line_parts))
584 $plug_info[ $line_parts[0] ] = $line_parts[1];
585 } //foreach($line)
586
587
588
589 return $plug_info;
590} //ll_get_current_plugin_info()
591
592/**
593 * Returns a URL that this plugin can be updated with.
594 *
595 * class-method ("static")
596 *
597 * @author akniep (Andreas Rayo Kniep)
598 * @since 2008-02-16
599 * @return string the URL to call in order to update this plugin
600 */
601function ll_get_update_plugin_url()
602{
603 $linklift_website_key = urlencode(LL_WEBSITE_KEY);
604 $linklift_secret = urlencode(LL_PLUGIN_SECRET);
605 $linklift_method = urlencode("current_plugin_download");
606
607 $request = LL_SERVER_URL
608 . "/external/external_info.php5"
609 . "?website_key" . "=" . $linklift_website_key
610 . "&linklift_secret" . "=" . $linklift_secret
611 . "&method" . "=" . $linklift_method
612 . "&plugin_language" . "=" . urlencode(LL_PLUGIN_LANGUAGE)
613 . "&plugin_version" . "=" . urlencode(LL_PLUGIN_VERSION)
614
615 . "";
616
617
618 return $request;
619} //ll_get_update_plugin_url()
620
621/**
622 * The method returns the server's very own 404-page including the page's headers as string!
623 * Therefor, a not-existing page is requested from the local server using the same accapt-language as the one delivered to this request.
624 * The method is invoked by return_error().
625 * class-method ("static")
626 *
627 * @author akniep (Andreas Rayo Kniep)
628 * @since 2007-12-17
629 * @return string the server's very own 404-page including the page's headers
630 */
631function get_404_page()
632{
633 $server_host = $_SERVER["SERVER_NAME"];
634
635
636 $language = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
637
638 // asking for the same language that was delivered to this request
639 if (! empty($language))
640 $acceptLanguage = "Accept-Language: " . $language . "\r\n";
641 else
642 $acceptLanguage = "";
643
644 // using carriage returns since Windows-servers may not understand simple newlines (while Linux-servers do not seem to have problems with carriage returns)
645 $request = "GET /this_file_does_not_exist.php "
646
647 . "HTTP/1.0\r\n"
648 . "Host: " . $server_host . "\r\n"
649 . $acceptLanguage
650 . "Connection: Close\r\n"
651 . "\r\n"
652
653 . "";
654
655 // possible errors ignored!
656 $page404 = LinkLiftPlugin::get_page_content( $server_host, $request );
657
658
659 return $page404;
660} //get_404_page()
661
662/**
663 * The method returns an error-page to a faulty or malicious request.
664 * For $errorCode 404 the local server's very own 404-page is requested and returned.
665 * The method does not return any value, but set headers and print the generated page's body to standard-out, automatically.
666 * class-method ("static")
667 *
668 * @author akniep (Andreas Rayo Kniep)
669 * @since 2007-12-17
670 * @param $error_code int The HTTP-Code to be returned and set as page-header; default: 404.
671 * @param $error_message string The main error-message to be returned as the page's body; default: "Illegal Request".
672 * @param $headers_to_set array, associative array of strings containing headers to be set when exiting
673 * @return void
674 */
675function return_error( $error_code = 404, $error_message = "Illegal Request", $headers_to_set = array() )
676{
677 $error_strings = array (
678 400 => "Bad Request"
679 , 401 => "Unauthorized"
680 , 404 => "Not Found"
681 , 405 => "Method Not Allowed"
682 , 406 => "Not Acceptable"
683 , 409 => "Conflict"
684 , 500 => "Internal Server Error"
685 );
686
687
688 if (404 == $error_code)
689 {
690 $page404 = LinkLiftPlugin::get_404_page();
691
692 // splits the received 404-page in header and content
693 $file_parts = preg_split( $pattern = '@\r?\n\r?\n@', $subject = $page404, $limit = 2 );
694
695 $headers = $file_parts[0];
696 $body = $file_parts[1];
697
698
699 // setting HTTP-headers individually
700 $headers_array = explode("\n", $headers);
701 foreach ($headers_array as $header)
702 header( $header );
703
704
705 // writing the page's body
706 die( $body );
707 } //if
708
709
710
711 $error_string = ( (isset($error_strings[$error_code])) ? (" " . $error_strings[$error_code]) : ("") );
712
713 header("HTTP/1.x " . $error_code . $error_string );
714
715
716 foreach ($headers_to_set as $header => $value)
717 header( $header . ": " . $value );
718
719
720
721 die( $error_message );
722} //return_error()
723
724/**
725 * This plugin is not supposed to be called directly, but to be used as inclusion or part of a surrounding CMS.
726 * Direct requests will be responded to with an error, protecting this plugin from prying eyes.
727 * The method does not return any value, but set headers and print the generated page's body to standard-out, automatically.
728 * class-method ("static")
729 *
730 * @author akniep (Andreas Rayo Kniep)
731 * @since 2007-12-17
732 * @param $check_this_file boolean Set this flag if the check-routine should also disallow direct request to the file this script is a part of (if you have included the LinkLift-plugin in a bigger PHP-script set this parameter to false, for usage within a CSS you can set this flag to true); default: false.
733 * @return void
734 */
735function check_request( $check_this_file = false )
736{
737 // direct access to the LinkLift-plugin-file is not wanted!
738 if ( ( (false !== strpos( strtolower($_SERVER["SCRIPT_FILENAME"]) , strtolower("linklift_divcom.php") ))
739 || (false !== strpos( strtolower(getenv("SCRIPT_NAME")) , strtolower("linklift_divcom.php") ))
740 )
741 && (! LL_SECRET_MODE)
742 )
743 {
744 LinkLiftPlugin::return_error( $errorCode = 404 );
745 } //if
746
747 if ($check_this_file)
748 {
749 // direct access to the LinkLift-plugin-file is not wanted!
750 if ( ( (false !== strpos( strtolower($_SERVER["SCRIPT_FILENAME"]) , strtolower( basename(__FILE__) ) ))
751 || (false !== strpos( strtolower(getenv("SCRIPT_NAME")) , strtolower( basename(__FILE__) ) ))
752 )
753 && (! LL_SECRET_MODE)
754 )
755 {
756 LinkLiftPlugin::return_error( $errorCode = 404 );
757 } //if
758 } //if
759} //check_request()
760
761
762
763
764
765/**
766 * Setter-method for property "linklift_website_key".
767 * The class'-properties are private in PHP5.
768 *
769 * The method is invoked by the class' constructor.
770 *
771 * @author akniep (Andreas Rayo Kniep)
772 * @since 2008-01-02
773 * @param $instance_linklift_website_key string The new linklift-website-key for this instance.
774 * @return string The former value of the property "linklift_website_key".
775 */
776function setWebsiteKey( $instance_linklift_website_key )
777{
778 $current_linklift_website_key = $this->getWebsiteKey();
779
780 $this->linklift_website_key = $instance_linklift_website_key;
781
782 return $current_linklift_website_key;
783} //setWebsiteKey()
784
785/**
786 * Getter-method for property "linklift_website_key".
787 * The class'-properties are private in PHP5.
788 *
789 * Usually, the property is set once by the constructor and remains unchanged afterwards.
790 *
791 * @author akniep (Andreas Rayo Kniep)
792 * @since 2007-12-10
793 * @return string The current value of the linklift_website_key-property.
794 */
795function getWebsiteKey()
796{
797 return $this->linklift_website_key;
798} //getWebsiteKey()
799
800/**
801 * Setter-method for property "xml_filename".
802 * The class'-properties are private in PHP5.
803 *
804 * The method checks wether a linklift-website-key is defined for this instance
805 * and extends the given filename by adding the current linklift-website-key as postfix.
806 * Thus, one plugin may work with and cache textlink-data belonging to different linklift-website-keys.
807 *
808 * The method is invoked by the class' constructor.
809 *
810 * @author akniep (Andreas Rayo Kniep)
811 * @since 2008-01-02
812 * @param $instance_xml_filename string The new XML-filename that is used when textlink-data that has been downloaded from the LinkLift-server is cached.
813 * @return string The former value of the property "xml_filename".
814 */
815function setXmlFilename( $instance_xml_filename = "" )
816{
817 $current_xml_filename = $this->getXmlFilename();
818
819 $instance_linklift_website_key = $this->getWebsiteKey();
820
821 if (! empty($instance_linklift_website_key))
822 {
823 $xml_filename_length = LinkLiftPlugin::ll_call_str_function_encoding_dependent("strlen", array($instance_xml_filename));
824
825 if ( ( 0 >= $xml_filename_length)
826 || ( false === ($file_format_start = LinkLiftPlugin::ll_call_str_function_encoding_dependent("strrpos", array($instance_xml_filename, ".") )) )
827 )
828 {
829 $file_format_start = $xml_filename_length;
830 } //if
831
832 $instance_xml_filename = LinkLiftPlugin::ll_call_str_function_encoding_dependent("substr", array($instance_xml_filename, 0, $file_format_start))
833 . ( (0 < $file_format_start) ? ("_") : ("") )
834 . $instance_linklift_website_key
835 . LinkLiftPlugin::ll_call_str_function_encoding_dependent("substr", array($instance_xml_filename, $file_format_start, $xml_filename_length))
836 . "";
837 } //if
838
839 $this->xml_filename = $instance_xml_filename;
840
841 return $current_xml_filename;
842} //setXmlFilename()
843
844/**
845 * Getter-method for property "xml_filename".
846 * The class'-properties are private in PHP5.
847 *
848 * Usually, the property is set once by the constructor and remains unchanged afterwards.
849 * Some CMS-plugins, though, will set the XML-filename later when having access to the CMS'-database.
850 *
851 * @author akniep (Andreas Rayo Kniep)
852 * @since 2008-01-02
853 * @return string The current value of the xml_filename-property.
854 */
855function getXmlFilename()
856{
857 return $this->xml_filename;
858} //getXmlFilename()
859
860/**
861 * Setter-method for property "links_to_show".
862 * The class'-properties are private in PHP5.
863 *
864 * The method checks wether the given value is an array. If not an empty array is used as new value.
865 *
866 * The method is invoked by the class' constructor.
867 *
868 * @author akniep (Andreas Rayo Kniep)
869 * @since 2008-01-02
870 * @param $instance_links_to_show array Array of integers, holding the new value of links to be shown by this instance.
871 * @return array The former value of the property "links_to_show".
872 */
873function setLinksToShow( $instance_links_to_show = "" )
874{
875 $current_instance_links_to_show = $this->getLinksToShow();
876
877 $this->links_to_show = ( (is_array($instance_links_to_show)) ? ($instance_links_to_show) : (array()) );
878
879 return $current_instance_links_to_show;
880} //setLinksToShow()
881
882/**
883 * Getter-method for property "links_to_show".
884 * The class'-properties are private in PHP5.
885 *
886 * Usually, the property is set once by the constructor and remains unchanged afterwards.
887 *
888 * @author akniep (Andreas Rayo Kniep)
889 * @since 2008-01-02
890 * @return string The current value of the links_to_show-property.
891 */
892function getLinksToShow()
893{
894 return $this->links_to_show;
895} //getLinksToShow()
896
897/**
898 * Setter-method for property "xml_cache_time".
899 *
900 * @author akniep (Andreas Rayo Kniep)
901 * @since 2007-12-17
902 * @param $xml_cache_time int The time the cached XML has been updated for the last time; default: NOW / time().
903 * @return void
904 */
905function setXmlCacheTime( $xml_cache_time = -1 )
906{
907 if (0 > $xml_cache_time)
908 $xml_cache_time = time();
909
910 $this->xml_cache_time = $xml_cache_time;
911} //setXmlCacheTime()
912
913/**
914 * Getter-method for property "xml_cache_time".
915 * Note: in LL_DEBUG_MODE = 3 this method will always return 0 in order to force an update of the XML-cache.
916 *
917 * @author akniep (Andreas Rayo Kniep)
918 * @since 2007-12-17
919 * @return int The time the cached XML has been updated for the last time.
920 */
921function getXmlCacheTime()
922{
923 if (5 == LL_DEBUG_MODE)
924 return 0;
925 else
926 return $this->xml_cache_time;
927} //getXmlCacheTime()
928
929/**
930 * Setter-method for property "xml_cache".
931 *
932 * @author akniep (Andreas Rayo Kniep)
933 * @since 2007-12-17
934 * @param $xml_cache string The XML-string to be cached / that is cached.
935 * @param $update_time boolean Set this flag in order to let the method update the xml_cache_time to NOW / time(); default: false.
936 * @return void
937 */
938function setXmlCache( $xml_cache, $update_time = false )
939{
940 $this->xml_cache = $xml_cache;
941
942 if ($update_time)
943 $this->setXmlCacheTime();
944} //setXmlCache()
945
946/**
947 * Getter-method for property "xml_cache".
948 * Note: in LL_DEBUG_MODE = 3 this method will always return 0 in order to force an update of the XML-cache.
949 *
950 * @author akniep (Andreas Rayo Kniep)
951 * @since 2007-12-17
952 * @return string The currently cached XML.
953 */
954function getXmlCache()
955{
956 return $this->xml_cache;
957} //getXmlCache()
958
959
960/**
961 * This method outputs an instance's current state by returning the values of its fields and constants.
962 * Use it for debugging-information.
963 *
964 * @author akniep (Andreas Rayo Kniep)
965 * @since 2007-12-17
966 * @return string, the object's current state as string
967 */
968function __toString()
969{
970 $seperator = " / ";
971
972 $return_array = array();
973
974 $return_array[] = "LinkLift Plugin";
975 $return_array[] = "Linklift-Website-Key: " . $this->getWebsiteKey();
976 $return_array[] = "XML-Filename: " . $this->getXmlFilename();
977 $return_array[] = "Links to show: " . implode(",", $this->getLinksToShow());
978 $return_array[] = "XML-cache update time: " . $this->getXmlCacheTime() . " (" . date("Y-m-d H:i:s", $this->getXmlCacheTime()). ")";
979 $return_array[] = "Data Timeout: " . $this->data_timeout;
980 $return_array[] = "Plugin Language: " . $this->plugin_language;
981 $return_array[] = "Plugin Version: " . $this->plugin_version;
982 $return_array[] = "Plugin Date: " . $this->plugin_date;
983
984 $return_str = implode($seperator, $return_array);
985
986 return $return_str;
987} //__toString()
988
989
990/**
991 * The method retrieves textlink-data to your adspace from the LinkLift-server.
992 * The data is received in XML-format and contains information about all textlinks currently booked on your adspace.
993 * The received XML is saved as instance-property xml_cache.
994 * The method is invoked by ll_textlink_code() if the local XML-file is not existent or out-of-date.
995 *
996 * @author akniep (Andreas Rayo Kniep)
997 * @since 2006-09-18
998 * @return void
999 */
1000function ll_retrieve_xml_from_ll_server()
1001{
1002 $server_host = LL_SERVER_HOST;
1003
1004
1005 $linklift_website_key = urlencode($this->getWebsiteKey());
1006 $linklift_secret = urlencode(LL_PLUGIN_SECRET);
1007
1008 $request = "GET /external/textlink_data.php5"
1009 . "?website_key" . "=" . $linklift_website_key
1010 . "&linklift_secret" . "=" . $linklift_secret
1011 . "&plugin_language" . "=" . urlencode($this->plugin_language)
1012 . "&plugin_version" . "=" . urlencode($this->plugin_version)
1013 . "&plugin_date" . "=" . urlencode($this->plugin_date)
1014 . "&plugin_creation_date" . "=" . urlencode($this->plugin_creation_date)
1015 . "&http_request_uri" . "=" . ( (isset($_SERVER["REQUEST_URI"]) ) ? (urlencode($_SERVER["REQUEST_URI"]) ) : ("") )
1016 . "&http_user_agent" . "=" . ( (isset($_SERVER["HTTP_USER_AGENT"])) ? (urlencode($_SERVER["HTTP_USER_AGENT"])) : ("") )
1017 . "&linklift_title" . "=" . urlencode(LinkLiftPlugin::ll_get_option( "linklift_title_" . $linklift_website_key , ""))
1018 . "&condition_no_css" . "=" . ( (LinkLiftPlugin::ll_get_option( "linklift_no_css_use_theme_" . $linklift_website_key , true)) ? ("1") : ("0") )
1019 . "&condition_no_html_tags" . "=" . ( (LinkLiftPlugin::ll_get_option( "linklift_no_html_tags_" . $linklift_website_key , false)) ? ("1") : ("0") )
1020 . " "
1021
1022 . "HTTP/1.0\n"
1023 . "Host: " . $server_host . "\n"
1024 . "Connection: Close\n"
1025 . "\n"
1026
1027 . "";
1028
1029
1030 // possible errors lead to the xmlCache not being (re-)set
1031 $xml = LinkLiftPlugin::get_page_content( $server_host, $request );
1032
1033
1034
1035 // Server returned an answer to a one-time-password-request.
1036 if (preg_match( '@<' . LL_ONE_TIME_PASSWORD_ANSWER_TAG . '_' . $linklift_website_key . '>([^<]*)</' . LL_ONE_TIME_PASSWORD_ANSWER_TAG . '_' . $linklift_website_key . '>@i'
1037 , $xml
1038 , $matches
1039 ))
1040 {
1041 $plugin_secret = trim( $matches[1] );
1042
1043 // a plugin-secret could be extracted and is saved to the database.
1044 if ( ($plugin_secret)
1045 && ($plugin_secret !== LL_PLUGIN_SECRET) )
1046 {
1047 LinkLiftPlugin::ll_set_option( LL_OPTION_PLUGIN_SECRET, $plugin_secret );
1048
1049 // there is no need for another request, since, the next visitor should trigger the next try with the correct password.
1050 $xml = "";
1051 } //if
1052 } //if
1053
1054
1055
1056 // saving the received XML to instance-property "xml_cache"
1057 if (false !== strpos($xml, "<?xml"))
1058 $this->setXmlCache( strstr($xml, "<?xml"), $update_time = true );
1059} //ll_retrieve_xml_from_ll_server()
1060
1061/**
1062 * The method parses the textlink-data to your adspace out of a String given in XML-format.
1063 * Usually, the delivered string contains the XML-data either just received from the LinkLift-server or read out of the local XML-file.
1064 * The method returns a multi-dimensional Array of textlinks containing information like link_url, link_text, link_prefix, link_postfix, and so on.
1065 * The method is invoked by ll_textlink_code() after calling either ll_retrieve_xml_from_ll_server() or ll_retrieve_xml_from_file_systems().
1066 *
1067 * @author akniep (Andreas Rayo Kniep)
1068 * @since 2006-09-18, 2006-12-03, 2007-12-10
1069 * @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, may be left empty in order to save the instance's xml_cache.
1070 * @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.
1071 */
1072function ll_retrieve_textlink_data_from_xml( $xml = "" )
1073{
1074 if (empty($xml))
1075 $xml = $this->getXmlCache();
1076
1077
1078 // well-formedness of XML is assumed!
1079 $textlink_data_fields =
1080 array(
1081 "prefix"
1082 , "url"
1083 , "text"
1084 , "postfix"
1085
1086 , "rss_prefix"
1087 , "rss_url"
1088 , "rss_text"
1089 , "rss_postfix"
1090 );
1091
1092 $plugin_fields =
1093 array(
1094 "language"
1095 , "version"
1096 , "pl_date"
1097 );
1098
1099 $xml_fields = array_merge($textlink_data_fields, $plugin_fields);
1100
1101
1102
1103 $parsed_xml_array = array();
1104 foreach ($xml_fields as $field)
1105 {
1106 preg_match_all ('!<' . $field . '[^>]*>(.*?)</' . $field . '>!im', $xml, $parsed_xml_array[$field], PREG_SET_ORDER);
1107 } //foreach($field)
1108
1109
1110
1111 // ### Extracting plugin-data #################################################
1112
1113 $server_plugin = array();
1114 $plugin_to_save = -1;
1115 foreach ($plugin_fields as $field)
1116 {
1117 foreach ($parsed_xml_array[$field] as $nr => $value)
1118 {
1119 if ( ("language" == $field)
1120 && ($this->plugin_language == $value[1]) )
1121 {
1122 $plugin_to_save = $nr;
1123 } //if;
1124
1125 $server_plugin[$nr][$field] = $value[1];
1126 } //foreach($value)
1127 } //foreach($field)
1128
1129 if (! empty($server_plugin[$plugin_to_save]))
1130 LinkLiftPlugin::ll_save_plugin_data( $server_plugin[$plugin_to_save] );
1131
1132
1133
1134 // ### Extracting textlink-data ###############################################
1135
1136 $textlink_data = array();
1137 foreach ($textlink_data_fields as $field)
1138 {
1139 foreach ($parsed_xml_array[$field] as $nr => $value)
1140 {
1141 $parsed_value = $value[1];
1142
1143 // LinkLift may use CData-elements in its XML-feeds that can be recognised by XML-parsers.
1144 $parsed_value = str_replace(array("<![CDATA[", "]]>"), "", $parsed_value);
1145
1146 $textlink_data[$nr][$field] = $parsed_value;
1147 } //foreach($value)
1148 } //foreach($field)
1149
1150
1151 return $textlink_data;
1152} //ll_retrieve_textlink_data_from_xml()
1153
1154/**
1155 * The method retrieves textlink-data to your adspace from the local XML-file (i.e. the file-system).
1156 * The data is read in XML-format and contains information about all textlinks currently booked on your adspace.
1157 * Usually, the local XML-file gets updated after a certain period of time by calling ll_retrieve_xml_from_ll_server().
1158 * The read XML is saved as instance-property xml_cache.
1159 * The method is invoked by ll_textlink_code() if there is a local XML-file and it is not out-of-date.
1160 *
1161 * @author akniep (Andreas Rayo Kniep)
1162 * @since 2006-09-18
1163 * @return void
1164 */
1165function ll_retrieve_xml_from_file_system()
1166{
1167 $xml = "";
1168
1169 $xml_filename = $this->getXmlFilename();
1170
1171 if ( (file_exists($xml_filename))
1172 && (is_readable($xml_filename))
1173 && ($xmlfile = fopen($xml_filename, "r")) )
1174 {
1175 $xml = fread($xmlfile, filesize($xml_filename));
1176 fclose($xmlfile);
1177
1178
1179 $this->setXmlCache( $xml, $update_time = false );
1180 } //if
1181} //ll_retrieve_xml_from_file_system()
1182
1183/**
1184 * The method writes textlink-data to your adspace into the local XML-file (i.e. the file-system).
1185 * The data is received in XML-format and contains information about all textlinks currently booked on your adspace.
1186 * Usually, the delivered textlink-data has just been received, i.e. downloaded, from the LinkLift-server using ll_retrieve_xml_from_ll_server().
1187 * The method 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).
1188 *
1189 * @author akniep (Andreas Rayo Kniep)
1190 * @since 2006-09-18
1191 * @param $xml string The textlink-data in XML-format that, usually, has just been received from the LinkLift-server, may be left empty in order to save the instance's xml_cache.
1192 * @return void
1193 */
1194function ll_write_xml_to_file_system( $xml = "" )
1195{
1196 if (empty($xml))
1197 $xml = $this->getXmlCache();
1198
1199 $xml_filename = $this->getXmlFilename();
1200
1201 if ($xmlfile = fopen($xml_filename, "w"))
1202 {
1203 fwrite($xmlfile, $xml);
1204 fclose($xmlfile);
1205 } //if
1206} //ll_write_xml_to_file_system()
1207
1208/**
1209 * The method generates a textlink-array like the one created by ll_retrieve_textlink_data_from_xml() out of LinkLift's XML-feed.
1210 * If no debug-mode is active the generated array will be empty, otherwise, contain a textlink depending on the current debug-mode.
1211 * The method is invoked by ll_textlink_code().
1212 *
1213 * @author akniep (Andreas Rayo Kniep)
1214 * @since 2007-12-17
1215 * @return array associative array containing textlinks that can be displayed within the generated HTML-code
1216 */
1217function get_debug_links()
1218{
1219 $debug_links = array();
1220
1221 if ( LL_DEBUG_MODE )
1222 {
1223 if (function_exists( "md5" ))
1224 $md5_answer = md5( LL_PLUGIN_SECRET );
1225 else
1226 $md5_answer = "";
1227
1228 // displaying an "answer" to the DEBUG_MODE-request
1229 if (1 != LL_DEBUG_MODE)
1230 $debug_links[] = array("text" => "Debug-Mode {" . LL_DEBUG_MODE . "} - (" . $md5_answer . ")", "url" => "http://www.linklift.com/", "prefix" => "[-- ", "postfix" => " --]");
1231
1232
1233
1234 // see above for the purposes of the following debug-modes
1235 switch( LL_DEBUG_MODE )
1236 {
1237 case (1):
1238 $debug_links[] = array("text" => "30 Chars TextLink text - &#228;&#223;&#263;&#322;&#261;", "url" => "http://www.linklift.com/", "prefix" => "", "postfix" => "");
1239 break;
1240
1241
1242 case (2):
1243 $debug_links[] = array("text" => "<!--" . $this->__toString() . "-->", "url" => "http://www.linklift.com/somefolder/someSecondFolder/some-third-folder/someFile.php?somequery=1&someQuery=value&some-query=true&", "prefix" => "", "postfix" => "");
1244 break;
1245
1246
1247 case (3):
1248 $debug_links[] = array("text" => "<!--" . $this->getXmlCache() . "-->", "url" => "http://www.linklift.com/", "prefix" => "", "postfix" => "");
1249 break;
1250
1251
1252 case (4):
1253 $external_array = array( "LL_WEBSITE_KEY"
1254 , "LL_PLUGIN_LANGUAGE"
1255 , "LL_PLUGIN_VERSION"
1256 , "LL_PLUGIN_DATE"
1257 , "LL_PLUGIN_CREATION_DATE"
1258 , "LL_PLUGIN_SECRET"
1259 , "LL_DATA_TIMEOUT"
1260 );
1261 $external_array = array_map( create_function('$element', 'return $element . "=" . constant($element);'), $external_array );
1262
1263 $external_data = implode( " / ", $external_array );
1264
1265
1266 $debug_links[] = array("text" => "<!--" . $external_data . "-->", "url" => "http://www.linklift.com/", "prefix" => "", "postfix" => "");
1267 break;
1268
1269
1270 case (10):
1271 $debug_links[] = array("text" => "<!--" . __FILE__ . "-->", "url" => "http://www.linklift.com/", "prefix" => "", "postfix" => "");
1272 break;
1273
1274
1275
1276
1277
1278 case (99):
1279 $debug_links[] = array("text" => "1,2,3,4,5,10,99", "url" => "http://www.linklift.com/", "prefix" => "", "postfix" => "");
1280 break;
1281
1282 } //switch(LL_DEBUG_MODE)
1283 } //if
1284
1285 return $debug_links;
1286} //get_debug_links()
1287
1288/**
1289 * This method is the actual "main"-method of the LinkLift-plugin.
1290 * The method
1291 * - 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();
1292 * or retrieves the textlink-data from that local XML-file in order to minimize outbound-traffic - calling ll_retrieve_xml_from_file_systems().
1293 * - parses the downloaded or read textlink-data in XML-format into an utilisable array of textlinks - calling ll_retrieve_textlink_data_from_xml().
1294 * - generates and outputs plain HTML-links using some CSS-styles in order to obtain the looks you chose on the LinkLift-website;
1295 * intentionally, the generated code tries to be as ordinary as possible in order to integrate best with your own HTML-code.
1296 *
1297 * No value is returned since the generated HTML-code is directly outputted to your website (except for delivering $return = true).
1298 * The method 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).
1299 *
1300 * @author akniep (Andreas Rayo Kniep)
1301 * @since 2006-09-18, 2006-12-03, 2007-10-26
1302 * @param $return boolean Indicating whether the generated HTML-code should be returned ($return == true), or written to standard-out (echo); default: false.
1303 * @return the generated HTML-code containing your current textlinks, or void if ($return == false), then, HTML will be written to standard-out.
1304 */
1305function ll_textlink_code( $return = false )
1306{
1307 $linklift_website_key = $this->getWebsiteKey();
1308
1309
1310 $this->setXmlCache( LinkLiftPlugin::ll_get_option("linklift_data_" . $this->getWebsiteKey(), "") );
1311 $this->setXmlCacheTime( LinkLiftPlugin::ll_get_option("linklift_time_" . $this->getWebsiteKey(), 0) );
1312
1313 // retrieving data from LL-server
1314 if ( ($this->getXmlCacheTime() < time() - 3600)
1315 || (40 > strlen( $this->getXmlCache() )) )
1316 {
1317 $this->ll_retrieve_xml_from_ll_server();
1318
1319 update_option("linklift_data_" . $this->getWebsiteKey(), $this->getXmlCache());
1320 update_option("linklift_time_" . $this->getWebsiteKey(), $this->getXmlCacheTime());
1321 } //if
1322
1323
1324
1325
1326 // parsing XML-data
1327 $textlink_data = $this->ll_retrieve_textlink_data_from_xml();
1328
1329 if (! is_array($textlink_data))
1330 return "";
1331
1332 // a possible debug-mode helping to analyse problems or functionality of the plugin
1333 $debug_links = $this->get_debug_links();
1334 $textlink_data = array_merge( $debug_links, $textlink_data );
1335
1336 // filtering testlinks, links that should not be shown or are shown elsewhere, and special LinkLift-links
1337 foreach ($textlink_data as $key => $link)
1338 {
1339 // if a certain subset of textlinks has been specified by links_to_show, the current textlink has to be part of it in order to be shown
1340 $links_to_show = $this->getLinksToShow();
1341 if ( (! empty($links_to_show))
1342 && (! in_array($key, $links_to_show)) )
1343 {
1344 unset($textlink_data[$key]);
1345 } //if
1346
1347 // filtering testlinks and special LinkLift-links, these are links containing the plugin's secret in their URL ...
1348 if ( (0 < strlen(LL_PLUGIN_SECRET))
1349 && (false !== strpos($link["url"], LL_PLUGIN_SECRET))
1350 && (! LL_SECRET_MODE) )
1351 {
1352 unset($textlink_data[$key]);
1353 } //if
1354 } //foreach($link)
1355
1356 // if there are no textlinks at this time the plugin will not display anything.
1357 if (0 >= count($textlink_data))
1358 return "";
1359
1360
1361
1362
1363 // creating and outputting textlinks
1364 // generating HTML-links
1365 // ---------------------------------------------------------------------------v
1366
1367 // the appearance of the generated HTML-links depends on
1368 // - the default values as chosen on LinkLift's own plug-in-generation-panel
1369 // - the parameters that have been chosen within the configuration page of your LinkLift-plugin (if possible)
1370 // --- CSS-parameters ----------------------------------------
1371 $number_of_links_per_row = LinkLiftPlugin::ll_get_option( "linklift_links_per_row_" . $linklift_website_key , 1);
1372
1373 $styles_ul = array();
1374 $styles_li = array();
1375 $styles_a = array();
1376
1377 if (1 < $number_of_links_per_row)
1378 {
1379 $styles_li[] = 'width:' . floor(100 / $number_of_links_per_row -1) . '%;';
1380 $styles_li[] = 'float:left;';
1381 } //if
1382
1383 $styles_ul[] = "background-color:" . LinkLiftPlugin::ll_get_option( "linklift_css_background_color_" . $linklift_website_key , "") . ";";
1384 $styles_ul[] = "border:0px none #FFFFFF;";
1385
1386
1387
1388
1389 $styles_a[] = "color:" . LinkLiftPlugin::ll_get_option( "linklift_css_color_" . $linklift_website_key , "") . ";";
1390 $styles_a[] = "font-size:" . LinkLiftPlugin::ll_get_option( "linklift_css_font_size_" . $linklift_website_key , "12px") . ";";
1391
1392
1393
1394
1395
1396
1397 // --- style-attributes --------------------------------------
1398 if (function_exists("array_filter"))
1399 {
1400 $styles_ul = array_filter( $styles_ul, create_function('$style', 'return (strpos($style,":;") === false);') );
1401 $styles_li = array_filter( $styles_li, create_function('$style', 'return (strpos($style,":;") === false);') );
1402 $styles_a = array_filter( $styles_a , create_function('$style', 'return (strpos($style,":;") === false);') );
1403 } //if
1404
1405 // --- style-attributes --------------------------------------
1406 $css_ul = ' style="' . implode(' ', $styles_ul) . '"';
1407 $css_li = ' style="' . implode(' ', $styles_li) . '"';
1408 $css_a = ' style="' . implode(' ', $styles_a ) . '"';
1409
1410 // the following condition will evaluate to true
1411 // if you have chosen not to use CSS-styles within the generated HTML-links
1412 if (LinkLiftPlugin::ll_get_option( "linklift_no_css_use_theme_" . $linklift_website_key , true))
1413 {
1414 $css_ul = '';
1415 $css_a = '';
1416
1417 if (1 >= $number_of_links_per_row)
1418 $css_li = '';
1419 } //if-else
1420
1421
1422
1423 // --- HTML-Tags ---------------------------------------------
1424 $tag_ul1 = '<ul' . $css_ul . '>';
1425 $tag_ul2 = '</ul>';
1426 $tag_li1 = '<li' . $css_li . '>';
1427 $tag_li2 = '</li>';
1428
1429 // the following condition will evaluate to true
1430 // if you have chosen not to use the HTML-tags <ul> and <li> within the generated HTML-links
1431 if (LinkLiftPlugin::ll_get_option( "linklift_no_html_tags_" . $linklift_website_key , false))
1432 {
1433 $tag_ul1 = '';
1434 $tag_ul2 = '';
1435 $tag_li1 = '';
1436
1437 if (1 >= $number_of_links_per_row)
1438 $tag_li2 = '<br />';
1439 else
1440 $tag_li2 = '';
1441 } //if-else
1442
1443
1444
1445 // --- HTML --------------------------------------------------
1446 $line_break = "\n";
1447 $indentation = "";
1448
1449 $output = $line_break
1450 . $indentation
1451
1452 . $tag_ul1
1453 . $line_break;
1454
1455 $link_counter = 0;
1456 foreach ($textlink_data as $key => $link)
1457 {
1458 $output .= $indentation
1459 . ( (empty($line_break)) ? ("") : ("\t") ) // no indentation if there are no linebreaks
1460
1461 . $tag_li1
1462 . $link["prefix"]
1463 . '<a' . $css_a . ' href="'.$link["url"].'">' // you may add target="_self" in order to give the link full strength
1464 . $link["text"]
1465 . '</a>'
1466 . $link["postfix"]
1467 . $tag_li2
1468
1469 // adding a line-break if a certain number of links should stand together in a row
1470 . ( ( (LinkLiftPlugin::ll_get_option( "linklift_no_html_tags_" . $linklift_website_key , false))
1471 && (1 < $number_of_links_per_row)
1472 && (0 == ++$link_counter % $number_of_links_per_row)
1473 ) ? ("<br />") : ("") )
1474
1475 . $line_break;
1476 } //foreach($link)
1477
1478 $output .= $indentation
1479
1480 . $tag_ul2
1481 . $line_break;
1482
1483 // ---------------------------------------------------------------------------^
1484
1485
1486
1487 // usually, the generated HTML-content is written to standard-out
1488 // however, you may choose that the method returns the code
1489 if ($return)
1490 return $output;
1491 else
1492 echo $output;
1493
1494} //ll_textlink_code()
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504/**
1505 * The method adds another action on thw Wordpress "admin_menu"-signal.
1506 *
1507 * The method gets invoked as an action on the Wordpress "init"-signal.
1508 * class-method ("static")
1509 *
1510 * @author akniep (Andreas Rayo Kniep)
1511 * @since 2007-05-04
1512 * @return void
1513 */
1514function linklift_init()
1515{
1516 // adding a new submenu-page to the admin's menu
1517 add_action( "admin_menu", array("LinkLiftPlugin", "linklift_config_page") );
1518} //linklift_init()
1519
1520/**
1521 * Adds a new submenu-page to the admin-panel within Wordpress.
1522 * The new submenu-page contains the LinkLift-plugin-configuration-page
1523 * created by the method linklift_configuration().
1524 *
1525 * The method gets invoked as an action on the Wordpress "admin_menu"-signal.
1526 * class-method ("static")
1527 *
1528 * @author akniep (Andreas Rayo Kniep)
1529 * @since 2007-05-04
1530 * @return void
1531 */
1532function linklift_config_page()
1533{
1534 // adding the LinkLift-configuration page to ...
1535 if ( function_exists("add_submenu_page") )
1536 {
1537 // ... plugins-menu / -tab
1538 if (file_exists(LL_WORDPRESS_FILE_PLUGINS))
1539 {
1540 add_submenu_page( $parent = LL_WORDPRESS_FILE_PLUGINS
1541 , $page_title = LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_TAB_TITLE')
1542 , $menu_title = LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_TAB_TITLE')
1543 , $access_level = "manage_options"
1544 , $file = LL_PLUGIN_MENU_FILENAME
1545 , $function = array("LinkLiftPlugin", "linklift_configuration")
1546 );
1547 } //if
1548
1549 // ... the general options-menu / -tab
1550 if (file_exists(LL_WORDPRESS_FILE_OPTIONS_GENERAL))
1551 {
1552 add_submenu_page( $parent = LL_WORDPRESS_FILE_OPTIONS_GENERAL
1553 , $page_title = LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_TAB_TITLE')
1554 , $menu_title = LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_TAB_TITLE')
1555 , $access_level = "manage_options"
1556 , $file = LL_PLUGIN_MENU_FILENAME
1557 , $function = array("LinkLiftPlugin", "linklift_configuration")
1558 );
1559 } //if
1560 } //if
1561} //linklift_config_page()
1562
1563/**
1564 * Returns the localised text (or value) of a given text-key.
1565 * If the (Wordpress/CMS-) software's preset language is available to the plug-in
1566 * the returned translation will be language-specific, otherwise english.
1567 *
1568 * The method also replaces type_specifiers (like knwon from sprintf) within the localised text.
1569 * Thus, you can fill the localised texts with dynamic (language-independent) values.
1570 * The replacements have to be delivered as String-array.
1571 * If the localised text does not contain enough type-specifiers for all given replacements the remaining will be omitted.
1572 * class-method ("static")
1573 *
1574 * @author akniep (Andreas Rayo Kniep)
1575 * @since 2007-05-02, 2007-06-10
1576 * @param $key_text string, the text to be translated
1577 * @param $replacements array of string-replacements, replacing type_specifiers in the localised text; default: empty array
1578 * @return string, translated text of input-parameter
1579 */
1580function ll_translate( $key_text, $replacements = array() )
1581{
1582 $type_specifier = "%s";
1583
1584
1585 if (defined($key_text))
1586 $localised_text = constant($key_text);
1587 else
1588 $localised_text = $key_text;
1589
1590
1591 // if a string is given instead of an array ...
1592 if (! is_array($replacements))
1593 $replacements = array( $replacements );
1594
1595 // avoiding a warning by vsprintf
1596 while (count($replacements) < substr_count($localised_text, $type_specifier))
1597 $replacements[] = "";
1598
1599
1600 // the actual replacement of %s-placeholders
1601 $localised_text = vsprintf( $localised_text, $replacements );
1602
1603
1604 return $localised_text;
1605} //ll_translate()
1606
1607/**
1608 * Returns the value to a given key of the Wordpress-option-table (wp_options).
1609 * Other than Wordpress' own function get_option()
1610 * this method will return a default_value rather than FALSE if the given key is undefined in the Wordpress-options-table (wp_options).
1611 * The default value can be delivered as second parameter.
1612 * class-method ("static")
1613 *
1614 * @author akniep (Andreas Rayo Kniep)
1615 * @since 2007-06-10
1616 * @param $options_table_key string, the key of the value to be retrieved from the Wordpress-options-table (wp_options)
1617 * @param $default_value mixed, the default value that should be returned if the given key is undefined in the Wordpress-options-table (wp_options), default: "" (empty string)
1618 * @return mixed, the value to the given key retrieved from the Wordpress-options-table (wp_options), or $default_value if the given key is undefined
1619 */
1620function ll_get_option( $options_table_key, $default_value = "" )
1621{
1622 $options_table_value = get_option($options_table_key);
1623
1624 // if a given key does not exist in the Wordpress-options-table
1625 // get_option returns false
1626 if (false === $options_table_value)
1627 return $default_value;
1628 else
1629 return $options_table_value;
1630} //ll_get_option()
1631
1632/**
1633 * Persists a variable value to the CMS-database, such that it can be retrieved when the plugin runs again.
1634 * Note: If the given variable-name already exists it will be overridden, returning the former value
1635 * otherwise it will be created with the given value.
1636 * Note: The given value can be of any type, but must be serializable.
1637 * CMS-specific-plugin-function.
1638 *
1639 * @author akniep (Andreas Rayo Kniep)
1640 * @since 2008-01-21
1641 * @param $options_table_key string, the variable-name, the given value can be retrieved again with
1642 * @param $new_value mixed, the variable-value to be persisted in the CMS-database
1643 * @return mixed, the former value of the variable, or false if the variable did not exist before
1644 */
1645function ll_set_option( $options_table_key, $new_value = "" )
1646{
1647 $former_value_default = false;
1648
1649 $former_value = LinkLiftPlugin::ll_get_option( $options_table_key, $former_value_default );
1650
1651
1652 update_option( $options_table_key, $new_value );
1653
1654 return $former_value;
1655} //ll_set_option()
1656
1657
1658/**
1659 * Saves new values of LinkLift's configuration-page to the Wordress-database, delivered by POST-request.
1660 *
1661 * The method gets invoked by the methods linklift_configuration() and widget_linklift_control().
1662 * class-method ("static")
1663 *
1664 * @author akniep (Andreas Rayo Kniep)
1665 * @since 2007-05-04
1666 * @param $force_saving boolean, an optional parameter, deliver true if you do not want the method to check wether a Wordpress-form has sent the information; default: false.
1667 * @return void
1668 */
1669function ll_update_plugin( $force_saving = false )
1670{
1671 if ( (isset($_POST['submit']) )
1672 || ($force_saving) )
1673 {
1674 // possible values of the LinkLift-plug-in's configuration page
1675 $options_array = array(
1676 "linklift_website_key"
1677 , "linklift_title"
1678 , "linklift_no_css_use_theme"
1679 , "linklift_no_html_tags"
1680 , "linklift_links_per_row"
1681 , "linklift_css_font_size"
1682 , "linklift_css_color"
1683 , "linklift_css_background_color"
1684 );
1685
1686 $linklift_website_key = ( (! empty($_POST["linklift_website_key"])) ? ($_POST["linklift_website_key"]) : ("") );
1687
1688
1689 foreach ( $options_array as $option )
1690 {
1691 // checkbox-values may not be delivered if the checkbox was left empty ...
1692 // in order to distinguish between forms that did not contain the checkbox and forms where the checkbox was left empty
1693 // another hidden field gives us the hint that the field was part of the form and was left empty (on purpose)
1694 if ( (in_array($option, array("linklift_no_css_use_theme", "linklift_no_html_tags"), $strict = true))
1695 && (isset($_POST[$option . "_modified"]))
1696 && (! isset($_POST[$option])) )
1697 {
1698 $_POST[$option] = 0;
1699 } //if
1700
1701 if (isset($_POST[$option]))
1702 {
1703 if ("linklift_website_key" != $option)
1704 $option_postfix = "_" . $linklift_website_key;
1705 else
1706 $option_postfix = "";
1707
1708 update_option( $option . $option_postfix, $_POST[$option] );
1709 } //if
1710 } //foreach($option)
1711
1712 } //if
1713} //ll_update_plugin()
1714
1715/**
1716 * Saves the latest server-properties (e.g. plugin-version) of the plugin extracted from the received textlink-data-XML-feed.
1717 * At this time, the method expects the delivered associative array to contain the following fields:
1718 * - language: the plugin's programming-/code-language
1719 * - version: the plugin's current version on the LinkLift-server
1720 * - date: the release-date of the latest plugin's version
1721 *
1722 * The method will ignore empty values (properties).
1723 *
1724 * The method gets invoked by the method ll_retrieve_textlink_data_from_xml().
1725 * class-method ("static")
1726 *
1727 * @author akniep (Andreas Rayo Kniep)
1728 * @since 2007-12-10
1729 * @param $server_plugin array, associative array containing the plugin's properties / data; default: array().
1730 * @return void
1731 */
1732function ll_save_plugin_data( $server_plugin = array() )
1733{
1734 if (! empty($server_plugin["language"]))
1735 update_option(LL_OPTION_SERVER_LANGUAGE, $server_plugin["language"]);
1736
1737 if (! empty($server_plugin["version"]))
1738 update_option(LL_OPTION_SERVER_VERSION , $server_plugin["version"]);
1739
1740 if (! empty($server_plugin["date"]))
1741 update_option(LL_OPTION_SERVER_DATE , $server_plugin["date"]);
1742} //ll_save_plugin_data()
1743
1744/**
1745 * Creates the HTML-code for LinkLift's configuration-page within the Wordpress-admin-menu.
1746 * After the user makes changes to the configuration the values will be saved to the Wordpress-database.
1747 * class-method ("static")
1748 *
1749 * @author akniep (Andreas Rayo Kniep)
1750 * @since 2007-05-04
1751 * @return void
1752 */
1753function linklift_configuration()
1754{
1755 LinkLiftPlugin::ll_update_plugin();
1756
1757
1758 $fieldset_style = " BORDER:1px solid #CCC; PADDING:12px";
1759 $field_key_style = " MARGIN-BOTTOM:5px";
1760 $field_key_style_tiny = " MARGIN-BOTTOM:0px";
1761 $field_value_style = " MARGIN-TOP:5px";
1762
1763 $field_text_style = " FONT-FAMILY:'Courier New', Courier, mono; FONT-SIZE:1.5em;";
1764 $field_text_style_tiny = " FONT-FAMILY:'Courier New', Courier, mono; FONT-SIZE:1.2em;";
1765
1766 $css_top_padding = " PADDING-TOP:30px; MARGIN-TOP:30px";
1767
1768 $field_text_maxlength = "15";
1769 $field_text_size = "15";
1770
1771
1772 if (! empty($_GET["linklift_website_key"]))
1773 {
1774 $linklift_website_key = $_GET["linklift_website_key"];
1775 } else {
1776 // loads variable $linklift_website_key
1777 $linklift_website_key = LinkLiftPlugin::ll_get_option("linklift_website_key", "");
1778 if (empty($linklift_website_key))
1779 $linklift_website_key = LinkLiftPlugin::ll_translate( "LINKLIFT_WEBSITE_KEY" );
1780
1781 } //if-else
1782
1783
1784 // used at least twice:
1785 $register_link_to_linklift = '<a href="' . LL_PLUGIN_REGISTER_LINK_URL . '" target="_blank" rel="nofollow">';
1786?>
1787
1788 <?php if (! empty($_POST) ) : ?>
1789 <div id="message" class="updated fade">
1790 <p>
1791 <strong>
1792 <?php _e("Options saved."); ?>
1793 </strong>
1794 </p>
1795 </div>
1796 <?php endif; ?>
1797
1798
1799
1800 <div class="wrap">
1801 <h2>
1802 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_TITLE'); ?>
1803 </h2>
1804 <div>
1805 <p>
1806 <?php
1807 echo LinkLiftPlugin::ll_translate('LINKLIFT_PLUGIN_DESCRIPTION_1', array($register_link_to_linklift, '</a>') );
1808 ?>
1809 </p>
1810
1811 <p>
1812 <span style="FONT-WEIGHT:bold;">
1813 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_PLUGIN_DESCRIPTION_2'); ?>
1814 </span>
1815 <br />
1816
1817 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_PLUGIN_DESCRIPTION_3'); ?>
1818 </p>
1819
1820 <p>
1821 <?php
1822 if (LL_WORDPRESS_WIDGETS_INSTALLED)
1823 $link_url_to_widgets = LL_WORDPRESS_FILE_WIDGETS . "linklift_website_key=" . $linklift_website_key . "&";
1824 else
1825 $link_url_to_widgets = "http://automattic.com/code/widgets/";
1826
1827
1828
1829 $link_to_widgets = '<a href="' . $link_url_to_widgets . '" target="_self">'
1830 . 'Widgets'
1831 . '</a>'
1832 . '';
1833
1834 $linklift_widget_name = '<span style="FONT-WEIGHT:bold;">'
1835 . '&quot;'
1836 . LL_PLUGIN_NAME
1837 . '&quot;'
1838 . '</span>'
1839 . '';
1840 ?>
1841
1842 <span style="FONT-WEIGHT:bold;">
1843 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_INSTALLATION_INSTRUCTIONS_1'); ?>
1844 </span>
1845
1846 </p>
1847
1848
1849 <ol>
1850 <li>
1851 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_INSTALLATION_INSTRUCTIONS_2', array($link_to_widgets, $linklift_widget_name) ); ?>
1852 <br />
1853 <br />
1854 </li>
1855
1856 <li>
1857 <?php
1858 $link_to_theme_editor = '<a href="' . LL_WORDPRESS_FILE_THEME_EDITOR . '" target="_self">'
1859 . 'Themes/Theme-Editor'
1860 . '</a>'
1861 . '';
1862 $code_snippet_to_paste = htmlspecialchars('<?php if (is_callable(array("LinkLiftPlugin", "execute"))) LinkLiftPlugin::execute(); ?>', ENT_QUOTES);
1863 ?>
1864
1865
1866 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_INSTALLATION_INSTRUCTIONS_3', array($link_to_theme_editor) ); ?>
1867 <br />
1868 <br />
1869
1870 <span style="COLOR:#FF0000; FONT-WEIGHT:bold;">
1871 <?php echo $code_snippet_to_paste; ?>
1872 </span>
1873 <br />
1874 <br />
1875
1876 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_INSTALLATION_INSTRUCTIONS_4'); ?>
1877 </li>
1878 </ol>
1879
1880
1881 <p>
1882 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_INSTALLATION_INSTRUCTIONS_5'); ?>
1883 <br />
1884 </p>
1885
1886
1887
1888
1889 <form action="" method="post" id="linklift-conf" style="MARGIN-TOP:30Px;">
1890
1891 <fieldset style="<?php echo $fieldset_style; ?>">
1892 <legend>
1893 <b>
1894 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_HEADLINE_GENERAL'); ?>
1895 </b>
1896 </legend>
1897
1898
1899 <h3 style="<?php echo $field_key_style; ?>">
1900 <label for="key">
1901 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_TITLE_WEBSITE_KEY'); ?>
1902 </label>
1903 </h3>
1904
1905 <p style="<?php echo $field_value_style; ?>">
1906 <input id="linklift_website_key" name="linklift_website_key" type="text" size="15" maxlength="15" value="<?php echo $linklift_website_key; ?>" style="<?php echo $field_text_style; ?>" />
1907
1908 <?php
1909 $linklift_url_linklift_website_key = "http://www.linklift.it/faq/website-key-linklift/?ref=b173a484859";
1910 ?>
1911 (<a href="<?php echo $linklift_url_linklift_website_key; ?>" target="_blank" rel="nofollow">
1912 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_WEBSITE_KEY_EXPLANATION_LINK'); ?>
1913 </a>)
1914
1915 <div class="description">
1916 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_DESCRIPTION_WEBSITE_KEY'); ?>
1917 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_DESCRIPTION_WEBSITE_KEY_2', array($register_link_to_linklift, '</a>') ); ?>
1918 </div>
1919 </p>
1920
1921
1922 <h3 style="<?php echo $field_key_style; ?>">
1923 <label for="key">
1924 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_TITLE_PLUGIN_HEADLINE'); ?>
1925 </label>
1926 </h3>
1927
1928 <p style="<?php echo $field_value_style; ?>">
1929 <input id="linklift_title" name="linklift_title" type="text" size="30" value="<?php echo LinkLiftPlugin::ll_get_option("linklift_title_" . $linklift_website_key, ""); ?>" style="<?php echo $field_text_style; ?>" />
1930
1931 <?php
1932 $linklift_url_link_marking = "http://www.linklift.it/faq/link-marking/?ref=b173a484859";
1933 $link_to_linklift_faq_link_marking = '<a href="' . $linklift_url_link_marking . '" target="_blank" rel="nofollow">';
1934 ?>
1935 <div class="description">
1936 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_DESCRIPTION_PLUGIN_HEADLINE'); ?>
1937 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_DESCRIPTION_PLUGIN_HEADLINE_2', array($link_to_linklift_faq_link_marking, '</a>') ); ?>
1938 </div>
1939 </p>
1940 </fieldset>
1941
1942
1943
1944
1945
1946 <fieldset style="<?php echo $fieldset_style; ?> <?php echo $css_top_padding; ?>">
1947 <legend>
1948 <b>
1949 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_HEADLINE_OPTIONAL'); ?>
1950 </b>
1951 </legend>
1952
1953 <p>
1954 <?php
1955 echo LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_TEXT_OPTIONAL_VALUES');
1956 ?>
1957 </p>
1958
1959
1960 <?php
1961 $form = array();
1962
1963 $form["linklift_no_css_use_theme"]
1964 = array(
1965 "#type" => "checkbox"
1966 , "#default_value" => LinkLiftPlugin::ll_get_option( "linklift_no_css_use_theme_" . $linklift_website_key , true)
1967 , "#title" => LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_TITLE_NO_CSS')
1968 , "#description" => LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_DESCRIPTION_NO_CSS')
1969 );
1970
1971 $form["linklift_no_html_tags"]
1972 = array(
1973 "#type" => "checkbox"
1974 , "#default_value" => LinkLiftPlugin::ll_get_option( "linklift_no_html_tags_" . $linklift_website_key , false)
1975 , "#title" => LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_TITLE_NO_HTML')
1976 , "#description" => LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_DESCRIPTION_NO_HTML')
1977 );
1978
1979 $form["linklift_links_per_row"]
1980 = array(
1981 "#type" => "select"
1982 , "#options" => array (1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 10 => 10)
1983 , "#default_value" => LinkLiftPlugin::ll_get_option( "linklift_links_per_row_" . $linklift_website_key , 1)
1984 , "#title" => LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_TITLE_LINKS_PER_ROW')
1985 , "#description" => LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_DESCRIPTION_LINKS_PER_ROW')
1986 );
1987
1988
1989 $font_sizes = array();
1990 for ($i = 10; $i <= 18; $i++)
1991 $font_sizes[$i . "px"] = $i . "px";
1992
1993 $form["linklift_css_font_size"]
1994 = array(
1995 "#type" => "select"
1996 , "#options" => $font_sizes
1997 , "#default_value" => LinkLiftPlugin::ll_get_option( "linklift_css_font_size_" . $linklift_website_key , "12px")
1998 , "#title" => LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_TITLE_FONT_SIZE')
1999 , "#description" => LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_DESCRIPTION_FONT_SIZE')
2000 );
2001
2002 $form["linklift_css_color"]
2003 = array(
2004 "#type" => "textfield"
2005 , "#size" => 20
2006 , "#maxlength" => 20
2007 , "#default_value" => LinkLiftPlugin::ll_get_option( "linklift_css_color_" . $linklift_website_key , "")
2008 , "#title" => LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_TITLE_LINK_COLOR')
2009 , "#description" => LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_DESCRIPTION_LINK_COLOR')
2010 );
2011
2012 $form["linklift_css_background_color"]
2013 = array(
2014 "#type" => "textfield"
2015 , "#size" => 20
2016 , "#maxlength" => 20
2017 , "#default_value" => LinkLiftPlugin::ll_get_option( "linklift_css_background_color_" . $linklift_website_key , "")
2018 , "#title" => LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_TITLE_BG_COLOR')
2019 , "#description" => LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_DESCRIPTION_BG_COLOR')
2020 );
2021
2022
2023 foreach ($form as $name => $element)
2024 {
2025 ?>
2026 <h5 style="<?php echo $field_key_style_tiny; ?>">
2027 <label for="key">
2028 <?php echo $element["#title"]; ?>
2029 </label>
2030 </h5>
2031
2032 <p style="<?php echo $field_value_style; ?>">
2033 <?php
2034
2035 $current_value = LinkLiftPlugin::ll_get_option($name . "_" . $linklift_website_key, $element["#default_value"]);
2036
2037
2038 switch ($element["#type"])
2039 {
2040 case ("textfield"):
2041 {
2042 ?>
2043 <input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo $current_value; ?>" size="<?php echo ( (isset($element["#size"])) ? ($element["#size"]) : ($field_text_size) ); ?>" maxlength="<?php echo ( (isset($element["#maxlength"])) ? ($element["#size"]) : ($field_text_maxlength) ); ?>" style="<?php echo $field_text_style_tiny; ?>" />
2044 <?php
2045
2046 break;
2047 } //case()
2048
2049 case ("select"):
2050 {
2051 ?>
2052 <select name="<?php echo $name; ?>" id="<?php echo $name; ?>">
2053 <?php foreach ($element["#options"] as $key => $value) : ?>
2054 <option value="<?php echo $key; ?>" <?php echo ( ($key == $current_value) ? ('selected="selected"') : ('') ); ?>>
2055 <?php echo $value; ?>
2056 </option>
2057 <?php endforeach; ?>
2058 </select>
2059 <?php
2060
2061 break;
2062 } //case()
2063
2064 case ("checkbox"):
2065 {
2066 ?>
2067 <input type="checkbox" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="1" <?php echo ( ($current_value) ? ('checked="checked"') : ('') ); ?> />
2068 <input type="hidden" name="<?php echo $name; ?>_modified" id="<?php echo $name; ?>_modified" value="1" />
2069 <?php
2070
2071 break;
2072 } //case()
2073
2074 } //switch($element["#type"])
2075
2076 ?>
2077 <div class="description">
2078 <?php echo $element["#description"]; ?>
2079 </div>
2080 </p>
2081 <?php
2082
2083 } //foreach($element)
2084
2085 ?>
2086
2087
2088 <br />
2089 </fieldset>
2090
2091
2092
2093 <p class="submit" style="text-align:left;">
2094 <input type="submit" name="submit" value="<?php _e('Update options &raquo;'); ?>" />
2095 </p>
2096
2097 </form>
2098
2099
2100 <p style="<?php echo $css_top_padding; ?>">
2101 LinkLift Plugin
2102 <?php
2103 echo '(', LL_PLUGIN_LANGUAGE, ')';
2104 ?>,
2105 Version
2106 <?php
2107 echo LL_PLUGIN_VERSION;
2108 ?>
2109 <?php
2110 echo '(', LL_PLUGIN_DATE, ')';
2111 ?>.
2112 <br />
2113
2114 <?php
2115 // do you (still) own the latest version?
2116 $server_plugin_version = LinkLiftPlugin::ll_get_option( LL_OPTION_SERVER_VERSION, 0 );
2117
2118 if ($server_plugin_version > LL_PLUGIN_VERSION)
2119 echo LinkLiftPlugin::ll_translate('LINKLIFT_PLUGIN_OUT_OF_DATE');
2120 elseif ($server_plugin_version == LL_PLUGIN_VERSION)
2121 echo LinkLiftPlugin::ll_translate('LINKLIFT_PLUGIN_UP_TO_DATE');
2122 ?>
2123 </p>
2124 </div>
2125 </div>
2126
2127<?php
2128
2129} //linklift_configuration()
2130
2131/**
2132 * Update-hook for the LinkLift-Wordpress-Textlink-plugin.
2133 * Checks if there is a newer version of thie plugin available on the LinkLift-server
2134 * and offers a download-link.
2135 * Prints data to standard-out if you do not own the latest version of this LinkLift-plugin.
2136 * class-method ("static")
2137 *
2138 * @author akniep (Andreas Rayo Kniep)
2139 * @since 2008-02-16
2140 * @return void
2141 */
2142function ll_update_nag()
2143{
2144 global $wp_version, $pagenow;
2145
2146
2147 // update-information of this plugin is only shown on the Wordpress-plugins-page!
2148 if ( (false === strpos( strtolower($pagenow) , "plugins" ))
2149 && (false === strpos( strtolower($_SERVER["REQUEST_URI"]) , "plugins.php" )) )
2150 {
2151 return;
2152 } //if
2153
2154
2155
2156 // the LinkLift-server may have been checked before
2157 $server_plugin_version = LinkLiftPlugin::ll_get_option( LL_OPTION_SERVER_VERSION, 0 );
2158 // date of the last check
2159 $server_plugin_version_check_date = LinkLiftPlugin::ll_get_option( LL_OPTION_SERVER_VERSION_CHECK_DATE, 0 );
2160
2161
2162 // no need to check more than once a week!
2163 if ( (LL_PLUGIN_VERSION >= $server_plugin_version)
2164 && ($server_plugin_version_check_date < strtotime(LL_UPDATE_CHECK_TIMEFRAME)) )
2165 {
2166 $plugin_info = LinkLiftPlugin::ll_get_current_plugin_info( "WordPress/" . $wp_version . "; " . get_bloginfo("url") );
2167
2168 if ( (empty($plugin_info))
2169 || (! isset($plugin_info["plugin_version"])) )
2170 {
2171 return;
2172 } //if
2173
2174
2175 $server_plugin_version = $plugin_info["plugin_version"];
2176
2177 // ignore minor updates:
2178 $server_plugin_version = round( floor($server_plugin_version * 10) / 10, 1 );
2179
2180 LinkLiftPlugin::ll_set_option( LL_OPTION_SERVER_VERSION , $server_plugin_version );
2181 LinkLiftPlugin::ll_set_option( LL_OPTION_SERVER_VERSION_CHECK_DATE , time() );
2182 } //if
2183
2184
2185
2186 // a new version of this plugin is available on the LinkLift-server!
2187 if (LL_PLUGIN_VERSION < $server_plugin_version)
2188 {
2189 // is admin user?
2190 if ( current_user_can("manage_options") )
2191 {
2192 $download_url = LinkLiftPlugin::ll_get_update_plugin_url();
2193 $opening_link_tag = sprintf('<a href="%s">', $download_url);
2194 $closing_link_tag = "</a>";
2195
2196
2197 $msg = sprintf( LinkLiftPlugin::ll_translate( "LINKLIFT_PLUGIN_OUT_OF_DATE_COMPLETE_ADMIN", array($opening_link_tag, $closing_link_tag)) );
2198
2199 } else {
2200 $msg = LinkLiftPlugin::ll_translate( "LINKLIFT_PLUGIN_OUT_OF_DATE_COMPLETE_USER" );
2201 } //if-else
2202
2203
2204 echo sprintf( '<div id="update-nag">%s</div>', $msg );
2205 } //if
2206} //ll_update_nag()
2207
2208
2209
2210
2211/**
2212 * The widget-controller (Wordpress-Widget-Plugin) calls this method to generate the plugin's output.
2213 * The method extracts the plugin's title out of the Wordpress-database (options-table)
2214 * and calls the plugin's main-function in order to generate your textlinks and the widget's body around.
2215 *
2216 * The method is invoked by divcom().
2217 * class-method ("static")
2218 *
2219 * @author tomk32 (Thomas R. Koll), akniep (Andreas Rayo Kniep)
2220 * @since 2007-03-06
2221 * @param $args array, an associative array delivered by the Wordpress Plugin 'Wordpress Widgets'
2222 * @return void, the widget's body including your textlinks is written to standard-out
2223 */
2224function widget_linklift_main( $args )
2225{
2226 // extracts out of the given array of parameters the variables that are used below
2227 extract($args);
2228
2229
2230 $linklift_plugin_instance =& LinkLiftPlugin::getInstance();
2231 $generated_html_code = $linklift_plugin_instance->ll_textlink_code( $return = true );
2232
2233
2234 // if there is no content at this time the widget will not display anything.
2235 if (empty($generated_html_code))
2236 return;
2237
2238
2239 $linklift_website_key = $linklift_plugin_instance->getWebsiteKey();
2240
2241 $linklift_title = LinkLiftPlugin::ll_get_option("linklift_title_" . $linklift_website_key, "");
2242
2243
2244 echo $before_widget
2245 , "\n"
2246 , $before_title
2247 , $linklift_title
2248 , $after_title
2249
2250 , $generated_html_code
2251
2252 , $after_widget;
2253} //widget_linklift_main()
2254
2255/**
2256 * The method generates an interface for editing the plugin's attributes / perameters.
2257 * At this time you can only manipulate the widget's title.
2258 *
2259 * The method is invoked by the widget-controller.
2260 * class-method ("static")
2261 *
2262 * @author tomk32 (Thomas R. Koll), akniep (Andreas Rayo Kniep)
2263 * @since 2007-03-06
2264 * @return void, the interface is directly outputted to your website
2265 */
2266function widget_linklift_control()
2267{
2268 LinkLiftPlugin::ll_update_plugin($force_saving = TRUE);
2269
2270
2271 $field_key_style_tiny = " MARGIN-BOTTOM:0px";
2272 $field_value_style = " MARGIN-TOP:5px";
2273 $field_text_style_tiny = " FONT-FAMILY:'Courier New', Courier, mono; FONT-SIZE:1.2em;";
2274 $field_text_maxlength = "15";
2275 $field_text_size = "15";
2276
2277
2278 if (! empty($_GET["linklift_website_key"]))
2279 {
2280 $linklift_website_key = $_GET["linklift_website_key"];
2281 } else {
2282 // loads variable $linklift_website_key
2283 $linklift_website_key = LinkLiftPlugin::ll_get_option("linklift_website_key", "");
2284 if (empty($linklift_website_key))
2285 $linklift_website_key = LinkLiftPlugin::ll_translate( "LINKLIFT_WEBSITE_KEY" );
2286
2287 } //if-else
2288
2289?>
2290 <?php
2291 if (LL_LINKLIFT_CONFIGURATION_PAGE) :
2292
2293 $link_to_configuration = '<a href="' . LL_LINKLIFT_CONFIGURATION_PAGE . 'linklift_website_key=' . $linklift_website_key . '&" target="_self">'
2294 . 'LinkLift'
2295 . '</a>'
2296 . '';
2297 $linklift_widget_name = '<span style="FONT-WEIGHT:bold;">'
2298 . LL_PLUGIN_NAME
2299 . '</span>'
2300 . '';
2301 ?>
2302 <p>
2303 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_WIDGETS_CONFIG_REMARK', array($link_to_configuration) ); ?>
2304 <br />
2305 <br />
2306 </p>
2307 <?php
2308 endif;
2309 ?>
2310
2311 <h5 style="<?php echo $field_key_style_tiny; ?>">
2312 <label for="key">
2313 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_TITLE_PLUGIN_HEADLINE'); ?>
2314 </label>
2315 </h5>
2316
2317 <p style="<?php echo $field_value_style; ?>">
2318 <input id="linklift_website_key" name="linklift_website_key" type="hidden" value="<?php echo( $linklift_website_key ); ?>" />
2319 <input id="linklift_title" name="linklift_title" type="text" value="<?php echo LinkLiftPlugin::ll_get_option("linklift_title_" . $linklift_website_key, ""); ?>" size="<?php echo ( (isset($element["#size"])) ? ($element["#size"]) : ($field_text_size) ); ?>" maxlength="<?php echo ( (isset($element["#maxlength"])) ? ($element["#size"]) : ($field_text_maxlength) ); ?>" style="<?php echo $field_text_style_tiny; ?>" />
2320
2321 <div class="description">
2322 <?php echo LinkLiftPlugin::ll_translate('LINKLIFT_CONFIG_DESCRIPTION_PLUGIN_HEADLINE'); ?>
2323 </div>
2324 </p>
2325<?php
2326
2327} //widget_linklift_control()
2328
2329/**
2330 * The method registers the LinkLift-plugin (-widget) with your widget-controller.
2331 * The widget controller is realised by the "Wordpress Widget-Plugin".
2332 *
2333 * The method is invoked by the widget-controller, the action is added at the end of this plugin.
2334 * class-method ("static")
2335 *
2336 * @author tomk32 (Thomas R. Koll), akniep (Andreas Rayo Kniep)
2337 * @since 2007-03-06
2338 * @return void
2339 */
2340function widget_linklift_init()
2341{
2342 if ( (! function_exists( "register_sidebar_widget" ))
2343 || (! function_exists( "register_widget_control" )) )
2344 return;
2345
2346 register_sidebar_widget( LL_PLUGIN_NAME, LL_PLUGIN_NAME );
2347 register_widget_control( LL_PLUGIN_NAME, array("LinkLiftPlugin", "widget_linklift_control") );
2348} //widget_linklift_init()
2349
2350
2351
2352} // class LinkLiftPlugin
2353
2354} //if (! class_exists("LinkLiftPlugin"))
2355
2356
2357if (! function_exists("divcom"))
2358{
2359
2360/**
2361 * The widget-controller (Wordpress-Widget-Plugin) calls this method to generate the plugin's output.
2362 * This method wraps the plugin's widget-main-method LinkLiftPlugin::widget_linklift_main()
2363 * in order to generate the widget's content.
2364 *
2365 * @author akniep (Andreas Rayo Kniep)
2366 * @since 2008-01-02
2367 * @param $args array, an associative array delivered by the Wordpress Plugin 'Wordpress Widgets'
2368 * @return void
2369 */
2370function divcom( $args )
2371{
2372 return LinkLiftPlugin::widget_linklift_main( $args );
2373} //divcom()
2374
2375} //if (! function_exists("divcom"))
2376
2377
2378
2379
2380
2381if (is_callable("LinkLiftPlugin", "check_request"))
2382 LinkLiftPlugin::check_request($check_this_file = true);
2383
2384// registering the LinkLift-plugin (mainly its configuration-page(s)) with the Wordpress-admin-menu
2385add_action( "init" , array("LinkLiftPlugin", "linklift_init") );
2386// registering the LinkLift-widget with the widget-controller ("Wordpress Widget-Plugin")
2387add_action( "widgets_init" , array("LinkLiftPlugin", "widget_linklift_init") );
2388
2389
2390// LinkLift-Update-Feature, introduced in Plugin v1.5 - Note: only working with Wordpress version v2.0.2 or above
2391add_action( "admin_notices" , array("LinkLiftPlugin", "ll_update_nag") );
2392
2393?>
Note: See TracBrowser for help on using the repository browser.