' . "\n"; } function fortunate_widget($args) { extract($args); echo $before_widget . $before_title . get_option('fortunate_title') . $after_title . fortunate() . $after_widget; } function fortunate_filter($info,$req) { if($req == 'description') return $info . fortunate(); return $info; } function fortunate_stdout() { echo fortunate(); } function fortunate($root = WPINC, $stats = 0 ) { static $fortunate_done = false; if($fortunate_done) return; $advanced = ((get_option('fortunate_advanced') == '1' ) ? 1 : 0); $showstats = (($stats && $advanced) ? 1 : 0); $database = get_option('fortunate_db'); $db = (($advanced && strlen($database)) ? $database : ''); $type = get_option('fortunate_type'); $typeopt = (($advanced && strlen($type)) ? $type : ''); $expr = get_option('fortunate_regex'); $regex = (($advanced && strlen('expr')) ? $expr : ''); $options = array( 'root' => $root, 'home' => get_option('home'), 'read_timeout' => get_option('fortunate_read_timeout'), 'conn_timeout' => get_option('fortunate_conn_timeout'), 'lang' => get_option('fortunate_lang'), 'length' => get_option('fortunate_length'), 'numlines' => get_option('fortunate_numlines'), 'pattern' => get_option('fortunate_pattern'), 'equal' => get_option('fortunate_equal'), 'regex' => $regex, 'db' => $db, 'type' => $typeopt, 'stats' => $showstats ); $result = '
' . fortunate_fetch($options) . '
' . "\n" ; $fortunate_done = true; return $result; } function fortunate_fetch($opts = NULL) { $haveopts = (is_array($opts)); $root = ((($haveopts) && (array_key_exists('root',$opts))) ? $opts['root'] : WPINC); @include($root . "/class-snoopy.php"); if(class_exists('Snoopy')) { $sn = new Snoopy; $sn->referer = ((($haveopts) && (array_key_exists('home',$opts))) ? $opts['home'] : get_option('home')); $sn->read_timeout = ((($haveopts) && (array_key_exists('read_timeout',$opts))) ? $opts['read_timeout'] : 5); $sn->_fp_timeout = ((($haveopts) && (array_key_exists('conn_timeout',$opts))) ? $opts['conn_timeout'] : 5); $fortunate_url = "http://fortunemod.com/cookie.php?rand=" . mt_rand(); $f = $opts['lang']; if($f != 'en') $fortunate_url .= "&lang=$f"; $f = $opts['type']; if($f) $fortunate_url .= "&off=$f"; $f = intval($opts['length']); if($f) $fortunate_url .= "&length=$f"; $f = intval($opts['numlines']); if($f) $fortunate_url .= "&numlines=$f"; $f = urlencode($opts['pattern']); if(strlen($f)) $fortunate_url .= "&pattern=$f"; $f = urlencode($opts['regex']); if(strlen($f)) $fortunate_url .= "®ex=$f"; $f = intval($opts['equal']); if($f) $fortunate_url .= "&equal=$f"; $f = urlencode($opts['db']); if(strlen($f)) $fortunate_url .= "&db=$f"; $f = intval($opts['stats']); if($f) $fortunate_url .= "&stats=$f"; @$sn->fetch($fortunate_url); $result = $sn->results; return $result; } } function fortunate_plugin_options() { load_plugin_textdomain($fortunate_textdomain, PLUGINDIR . '/' . dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__))); if($_SERVER['REQUEST_METHOD'] == 'POST') { // Save settings update_option('fortunate_lang',$_POST['fortunate_lang']); update_option('fortunate_length',$_POST['fortunate_length']); update_option('fortunate_numlines',$_POST['fortunate_numlines']); update_option('fortunate_location',$_POST['fortunate_location']); update_option('fortunate_title',$_POST['fortunate_title']); update_option('fortunate_pattern',trim($_POST['fortunate_pattern'])); update_option('fortunate_read_timeout', intval($_POST['fortunate_read_timeout'])); update_option('fortunate_conn_timeout', floatval($_POST['fortunate_conn_timeout'])); if($_POST['fortunate_addcss'] == "1") update_option('fortunate_addcss',"1"); else update_option('fortunate_addcss',"0"); if($_POST['fortunate_equal'] == "1") update_option('fortunate_equal',"1"); else update_option('fortunate_equal',"0"); if($_POST['fortunate_advanced'] == "1") { // Don't update these settings unless advanced mode was already in // effect. Otherwise they will get reset to defaults every time you // toggle Advanced mode. if(intval(get_option('fortunate_advanced'))) { update_option('fortunate_db',trim($_POST['fortunate_db'])); update_option('fortunate_regex',trim($_POST['fortunate_regex'])); update_option('fortunate_type',$_POST['fortunate_type']); } update_option('fortunate_advanced',"1"); } else update_option('fortunate_advanced',"0"); echo "

"; echo __('Options saved.', $fortunate_textdomain ); echo "

"; } $fortunate_lang = get_option('fortunate_lang'); $fortunate_type = get_option('fortunate_type'); $fortunate_length = intval(get_option('fortunate_length')); $fortunate_numlines = intval(get_option('fortunate_numlines')); $fortunate_location = get_option('fortunate_location'); $fortunate_title = get_option('fortunate_title'); $fortunate_addcss = get_option('fortunate_addcss'); $fortunate_pattern = get_option('fortunate_pattern'); $fortunate_regex = get_option('fortunate_regex'); $fortunate_equal = intval(get_option('fortunate_equal')); $fortunate_read_timeout = get_option('fortunate_read_timeout'); $fortunate_conn_timeout = get_option('fortunate_conn_timeout'); $fortunate_advanced = get_option('fortunate_advanced'); $fortunate_db = get_option('fortunate_db'); // Now display the options editing screen echo '
'; echo "

" . __( 'Fortunate Random Quote Plugin Options', $fortunate_textdomain ) . "

"; echo "

© Mike Macgirvin

"; // options form echo "
"; $fortunate_lang_text = __('Select a quotation language.', $fortunate_textdomain); echo "

$fortunate_lang_text

"; $langs = array('en' => __('English', $fortunate_textdomain), 'es' => __('Spanish', $fortunate_textdomain), 'it' => __('Italian', $fortunate_textdomain), 'fr' => __('French', $fortunate_textdomain), 'de' => __('German', $fortunate_textdomain), 'ru' => __('Russian', $fortunate_textdomain)); echo __("Language:", $fortunate_textdomain); echo "

"; $fortunate_location_text1 = __('Select a location on the page to display the random quotes. Some locations may require css modifications appropriate to your selected theme.', $fortunate_textdomain); $fortunate_location_text2 = __('Selecting \'Widget\' for the location requires an additional step: once these options are saved, go to your widget administration page and add the widget to the desired location on the sidebar.',$fortunate_textdomain); $fortunate_location_text3 = __('Selecting \'Header - description\' will add the quote text to the blog description, which is generally displayed on your page header. This works best when used with 1 for \'Maximum number of lines\' (below).',$fortunate_textdomain); echo "

$fortunate_location_text1

$fortunate_location_text2

$fortunate_location_text3

"; echo __("Where to display:", $fortunate_textdomain); echo "

"; $fortunate_title_text = __('This setting is only used if you selected \'Widget\' above. It allows you to change the sidebar title to your liking.',$fortunate_textdomain); echo "

$fortunate_title_text

"; echo __("Fortunate Widget Title:", $fortunate_textdomain); echo "

"; $fortunate_css_text = __('Include the wp-content/plugins/fortunate/fortunate.css file? Some page locations may require CSS changes to display exactly as you wish. If you wish to use this feature, copy the supplied \'fortunate-template.css\' to \'fortunate.css\', make any changes you desire; and include the file by checking the box below. Alternatively, your theme may display everything just fine and you might not wish to use the additional CSS file at all.',$fortunate_textdomain); echo "

$fortunate_css_text

"; echo __("Include plugin CSS file:", $fortunate_textdomain); echo "

"; $fortunate_length_text = __('You may restrict results to those that are less than a certain number of characters, as some entries can get quite lengthy. This number is only a guideline as it is applied to the quotation before HTML markup is applied, which might change the length a bit. If you set this in the range of 200-300, you\'ll see more simple quotations and fewer long stories and jokes. For best results, you should probably set this to 0 or something greater than 80.',$fortunate_textdomain); echo "

$fortunate_length_text

"; echo __("Maximum length in bytes:", $fortunate_textdomain); echo "" . __(' 0 is unlimited',$fortunate_textdomain) . "

"; $fortunate_lines_text1 = __('You may also wish to only display results that are limited to a specific number of text lines (ignoring browser wordwrap)*. This is most useful if the setting is 1 or 2 for use in a limited space, such as on a page header or footer with a fixed height. For best results, you should probably set this to 0, 1, or 2.',$fortunate_textdomain); $fortunate_lines_text2 = __('* A single line from a returned quotation may contain up to 80 characters. If the target page region does not provide enough space for 80 column text, some lines may get wrapped or folded.',$fortunate_textdomain); echo "

$fortunate_lines_text1

$fortunate_lines_text2

"; echo __("Maximum number of lines:", $fortunate_textdomain); echo "" . __(' 0 is unlimited',$fortunate_textdomain) . "

"; $fortunate_pattern_text = __('You may also wish to only display quotations containg a specific word. For best results, either leave blank or use a very common word.',$fortunate_textdomain); echo "

$fortunate_pattern_text

"; echo __("Specific word to search for:", $fortunate_textdomain); echo "" . "

"; $fortunate_equal_text = __('For a slight performance penalty you may wish to randomize the quotation categories, which provides equal weight to categories from different data sources on the server, regardless of the number of quotations in that category. This merely adds an extra level of randomization and is not normally required.',$fortunate_textdomain); echo "

$fortunate_equal_text

"; echo __("Randomize categories:", $fortunate_textdomain); echo "

"; $fortunate_timeout_text = __('The following timeouts will allow for graceful failure if the random quotes take too much time to load. Set these to a few seconds so your blog will still display normally in a reasonable period of time (although without Fortunate) should a network disruption occur.',$fortunate_textdomain); echo "

$fortunate_timeout_text

"; echo __("Connect timeout (seconds):", $fortunate_textdomain); echo "" . "

"; echo "

"; echo __("Data timeout (seconds):", $fortunate_textdomain); echo "" . "

"; $fortunate_advanced_text = __('Advanced usage. Select the Advanced mode checkbox and submit this page. You will then have additional options such as choosing offensive (sexual or off-colored quotes), specific databases to search, and the ability to provide a MySQL regular expression for searches. If you deselect this checkbox, any advanced options will be ignored.',$fortunate_textdomain); echo "

$fortunate_advanced_text

"; echo __("Advanced mode:", $fortunate_textdomain); echo "

"; if($fortunate_advanced == "1" ) { echo "

" . __("Advanced Options:", $fortunate_textdomain); $fortunate_off_text = __('By default, assume that this content is for general audiences and do not include quotations and jokes which are overtly sexual, racial, touch on religious sensibilities, or otherwise might be deemed offensive. If you change this setting, be aware that members of your audience may be offended or insulted. You have been warned. This setting currently only applies to English, Spanish, and Italian content. Other languages have not yet been content rated and \'Normal\' is the only setting which will work.',$fortunate_textdomain); echo "

$fortunate_off_text

"; echo __("Quotation Rating:", $fortunate_textdomain); echo "

"; $fortunate_db_text = __('You have the option to choose a specific database (the names of any applicable databases will be shown in the statistics report at the bottom of this form). Changing the search parameters significantly will affect whether or not any quotes are returned from a specific database, so using this feature may require a bit of trial and error. Specifically, if you change the language or quotation ratings, please submit and reload this page (without a selected database) to determine which databases are available with those settings.',$fortunate_textdomain); echo "

$fortunate_db_text

"; echo __("Use this database:", $fortunate_textdomain); echo "" . "

"; $fortunate_regex_text = __('[Very Advanced Usage!] You may also select quotations by using (MySQL) Regular Expressions. Please leave this blank unless you know exactly what you are doing.',$fortunate_textdomain); echo "

$fortunate_regex_text

"; echo __("Regular Expression:", $fortunate_textdomain); echo "" . "

"; } echo "

" . "

"; echo "

" . __("Sample:", $fortunate_textdomain) . fortunate( ABSPATH . WPINC, 1 ) . ""; echo "
"; }