/* Plugin Name: Aphorismus Plugin URI: mailto:ovsyannikov.ivan@gmail.com Description: The plug-in allows to deduce the random text block (aphorism) on pages, posts or sidebar. Plugin have the widget. Version: 0.4.0 Author: Ivan Ovsyannikov Author URI: mailto:ovsyannikov.ivan@gmail.com */ define('PLUGIN_NAME', 'aphorismus'); $php_self = $_SERVER['PHP_SELF']; if (empty($php_self)) $_SERVER['PHP_SELF'] = $php_self = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]); if (strpos($php_self, "wp-content/plugins/" . PLUGIN_NAME) !== false){ $dir = str_replace('\\', '/', dirname(__FILE__)); $dir = str_replace(array('wp-content/plugins/' . PLUGIN_NAME, 'aphorismus.php'), array('', ''), $dir); chdir($dir); define('WP_DEBUG', true); require_once('./wp-load.php'); define('APHORISMUS_TABLE', $wpdb->prefix . 'aphorismus'); if (isset($_GET['action'])){ if ($_GET['action'] == 'js'){ ?> /* JavaScript */ var text = ' echo str_replace("'", "\'", get_aphorismus()); ?>'; document.write(text); } } else echo get_aphorismus(); die; } else { global $wpdb; define('APHORISMUS_TABLE', $wpdb->prefix . 'aphorismus'); } if (isset($_GET['action'])){ if ($_GET['action'] == 'export'){ require_once(dirname(__FILE__).'/includes/export.php'); aphorismus_export(); die(); } } register_activation_hook( __FILE__, 'aphorismus_setup' ); add_action('admin_menu', 'aphorismus_add_admin'); add_action('admin_head', 'aphorismus_admin_head'); if (get_option('aphorismus_admin_show') == 'true'){ add_action('admin_footer', 'aphorismus_admin_footer'); } add_action('init', 'do_filter'); add_action('plugins_loaded', 'aphorismus_init'); /** * Enable locale * */ function load_locale(){ $locale = get_locale(); if (empty($locale)) $locale = 'en_US'; $mofile = dirname( __FILE__ )."/locale/".$locale.".mo"; load_textdomain(PLUGIN_NAME, $mofile ); } /** * Aphorismus setup * */ function aphorismus_setup(){ global $wpdb; $create_table = "CREATE TABLE ".APHORISMUS_TABLE." (id int(11) NOT NULL auto_increment, text longtext NOT NULL, author varchar(255), primary key (id) );"; if($wpdb->get_var("SHOW TABLES LIKE '".APHORISMUS_TABLE."';") != APHORISMUS_TABLE){ require_once(ABSPATH.'wp-admin/upgrade-functions.php'); dbDelta($create_table); } update_option('aphorismus_template', '
%%text%%!
%%author%%!
\n";
echo "
\n";
echo "" . __ ('You can use HtMl–tegs. Constants:%%title%% — Deduces plug-in heading%%text%% — Deduces the aphorism text%%author%% — Deduces the author
The field «Author» is not obligatory for filling. Its conclusion should be surrounded by a symbol «!».', PLUGIN_NAME) . "\n";
echo "\n";
echo "
" . __ ('Aphorism added', PLUGIN_NAME) . "
" . __ ('Aphorism deleted', PLUGIN_NAME) . "
" . __ ('Aphorisms deleted', PLUGIN_NAME) . "
" . __ ('All aphorisms deleted', PLUGIN_NAME) . "
" . __ ('Settings saved', PLUGIN_NAME) . "
" . __ ('Aphorism saved', PLUGIN_NAME) . "
" . sprintf( __ ('Imported aphorisms: %d', PLUGIN_NAME), $aphorismus_importer->get_aphorismus_importer_count()) . "
You can use %s for XML-file creation. Open «aphorismus.xls» in MS Excel 2003 SP3 (or higher), fill the table, press «Save as» and will choose XML-data (not a table XML).
', PLUGIN_NAME), '«aphorismus.xls»') . "\n"; echo __ ('Attention! Try to avoid a symbol «&»! :)
', PLUGIN_NAME) . "\n"; echo "The Aphorismus shows aphorisms on pages, in posts or on the sidebar. You can use
', PLUGIN_NAME) . "\n"; echo "%%aphorismus%%
\n"; echo __ ('for display in posts or on pages, or to use
', PLUGIN_NAME) . "\n"; echo "<?php aphorismus(); ?>
\n"; echo __ ('in templates.
At plugin activation, he automatically adds new widget. If in a template of your blog there is a sidebar, you can place on it widget. To make it it is possible in the management widget menu.
', PLUGIN_NAME) . "\n"; echo __ ('You can deduce aphorisms on other sites:
', PLUGIN_NAME) . "\n"; echo "<script type=\"text/javascript\" src=\"" . get_option('siteurl') . "/wp-content/plugins/" . PLUGIN_NAME . "/aphorismus.php?action=js\"></script>
\n"; echo "aphorismus ( [ string \$arg ] [, int \$max_length ] )
\n"; echo __ ('aphorismus() echo string.
', PLUGIN_NAME) . "\n"; echo "get_aphorismus ( [ string \$arg ] [, int \$max_length ] )
\n"; echo __ ('get_aphorismus() return string.
', PLUGIN_NAME) . "\n"; echo __ ('arg values:
If the arg is empty or not set, function will deduce string with a output template.
', PLUGIN_NAME) . "\n"; echo __ ('max_length defines the maximum length of a deduced aphorism. By default is 0, thus the maximum length is not limited.
', PLUGIN_NAME) . "\n"; echo "" . get_aphorismus('notemplate', get_option('aphorismus_admin_show_length')) . "