prefix . 'aphorismus'); if (isset($_GET['action'])){ if ($_GET['action'] == 'js'){ ?> /* JavaScript */ var text = ''; document.write(text); 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%%!

'); update_option('aphorismus_template_widget', '

%%title%%

%%text%%!
%%author%%!'); update_option('aphorismus_admin_per_page', '30'); update_option('aphorismus_admin_show', ''); update_option('aphorismus_admin_show_length', '200'); } function aphorismus_init(){ load_locale(); register_sidebar_widget( __ ('Aphorismus', PLUGIN_NAME), 'aphorismus_widget'); register_widget_control( __ ('Aphorismus', PLUGIN_NAME), 'aphorismus_widget_control'); } /** * Add menu items to the admin panel * */ function aphorismus_add_admin(){ $level = 'level_10'; add_menu_page( __ ('Aphorismus', PLUGIN_NAME), __ ('Aphorismus', PLUGIN_NAME), $level, __FILE__, 'aphorismus_admin', get_option('siteurl').'/wp-content/plugins/'.PLUGIN_NAME.'/aphorismus_icon_small.png'); add_submenu_page(__FILE__, __ ('Aphorismus', PLUGIN_NAME), __ ('Add aphorism', PLUGIN_NAME), $level, 'aphorismus_action', 'aphorismus_action'); add_submenu_page(__FILE__, __ ('Aphorismus', PLUGIN_NAME), __ ('Settings', PLUGIN_NAME), $level, 'aphorismus_settings', 'aphorismus_settings'); add_submenu_page(__FILE__, __ ('Aphorismus', PLUGIN_NAME), __ ('Help', PLUGIN_NAME), $level, 'aphorismus_help', 'aphorismus_help'); } /** * Add WP-filter * */ function do_filter(){ add_filter('the_content', 'aphorismus_filter', 1); } /** * Post or Page filter * * @param string $post * @return string */ function aphorismus_filter($post) { if (substr_count($post, '%%aphorismus%%') > 0){ $post = str_replace('%%aphorismus%%', get_aphorismus(), $post); } return $post; } /** * Show widget * * @param array $args */ function aphorismus_widget($args){ extract($args); echo $before_widget; echo get_aphorismus('widget'); echo $after_widget; } /** * Edit widget parameters * */ function aphorismus_widget_control(){ if (isset($_POST['aphorismus_template_submit']) && $_POST['aphorismus_template_submit'] == 'submit'){ if (!get_magic_quotes_gpc()) $template = trim($_POST['aphorismus_template']); else $template = stripslashes(trim($_POST['aphorismus_template'])); update_option('aphorismus_template_widget', $template); } echo "

\n"; echo "" . __ ('Template string', PLUGIN_NAME) . "\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 "

\n"; } /** * Strip HTML-tags without: *
* * * * * @param string $string * @return string */ function aphorismus_strip_tags($string = ''){ if (empty($string)) return false; $tags_array = array('
' => '<br />', '
' => '<br />', '' => '<i>', '' => '</i>', '' => '<b>', '' => '</b>', '' => '<strong>', '' => '</strong>'); return htmlspecialchars_decode(strip_tags(strtr($string, $tags_array)), ENT_NOQUOTES); } /** * Echo aphorism * * @param string $to * @param int $max_length */ function aphorismus($to = '', $max_length = 0, $tags = true){ if ($to == 'array') return false; echo get_aphorismus($to, $max_length, $tags); } /** * Return aphorism string * * @param string $to * @param int $max_length * @return string */ function get_aphorismus($to = '', $max_length = 0, $tags = true){ global $wpdb; $text = ''; $where = ''; if ($max_length > 0) $where .= "WHERE LENGTH(text) < " . $max_length; $result = $wpdb->get_results("SELECT id, text, author FROM ".APHORISMUS_TABLE." ".$where." ORDER BY RAND() LIMIT 1", 'ARRAY_A'); if (empty($result)){ return null; } switch($to){ case 'array': $text = array('id' => $result[0]['id'], 'text' => $result[0]['text'], 'author' => $result[0]['author']); break; case 'notemplate': $text .= $result[0]['text']; break; case 'widget': preg_match("|^(.*?)!(.*?)!(.*?)$|is", get_option('aphorismus_template_widget'), $matches); $text .= str_replace(array('%%text%%', '%%title%%'), array($result[0]['text'], __ ('Aphorismus', PLUGIN_NAME)), $matches[1]); if (!empty($result[0]['author'])) $text .= str_replace("%%author%%", $result[0]['author'], $matches[2]); $text .= $matches[3]; break; default: preg_match("|^(.*?)!(.*?)!(.*?)$|is", get_option('aphorismus_template'), $matches); $text .= str_replace(array('%%text%%', '%%title%%'), array($result[0]['text'], __ ('Aphorismus', PLUGIN_NAME)), $matches[1]); if (!empty($result[0]['author'])) $text .= str_replace("%%author%%", $result[0]['author'], $matches[2]); $text .= $matches[3]; break; } if ($tags == false) return strip_tags($text); else return $text; } /** * Aphorismus control * */ function aphorismus_admin(){ global $wpdb; $where = ''; $search_string = ''; $action = ''; $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0; if (empty($pagenum)) $pagenum = 1; $per_page = get_option('aphorismus_admin_per_page'); if (isset($_GET['action']) || isset($_GET['action2'])){ if ($_GET['action'] == '-1' || !isset($_GET['action'])) $action = $_GET['action2']; else $action = $_GET['action']; if (isset($_POST['aphorism_text'])){ if (!get_magic_quotes_gpc()) $aphorism = aphorismus_strip_tags(trim($_POST['aphorism_text'])); else $aphorism = stripslashes(aphorismus_strip_tags(trim($_POST['aphorism_text']))); $aphorism = str_replace(array("\r", "\n"), array("", " "), $aphorism); } else $aphorism = ''; if (isset($_POST['aphorism_author'])){ if (!get_magic_quotes_gpc()) $author = strip_tags(trim($_POST['aphorism_author'])); else $author = stripslashes(strip_tags(trim($_POST['aphorism_author']))); } else $author = ''; switch ($action){ case 'add': if (!empty($aphorism)){ $wpdb->insert(APHORISMUS_TABLE, array('text' => $aphorism, 'author' => $author), array('%s', '%s')); echo "

" . __ ('Aphorism added', PLUGIN_NAME) . "

\n"; } break; case 'delete': $count = count($_GET['aphorism']); if ($count > 0){ $aphorisms = $_GET['aphorism']; for ($p = 0; $p < $count; $p++){ $wpdb->query("DELETE FROM ".APHORISMUS_TABLE." WHERE id = '".$aphorisms[$p]."';"); } if ($count == 1) echo "

" . __ ('Aphorism deleted', PLUGIN_NAME) . "

\n"; else echo "

" . __ ('Aphorisms deleted', PLUGIN_NAME) . "

\n"; } break; case 'delete_all': $wpdb->query("TRUNCATE TABLE ".APHORISMUS_TABLE.";"); echo "

" . __ ('All aphorisms deleted', PLUGIN_NAME) . "

\n"; break; case 'settings': if (!get_magic_quotes_gpc()) $template = trim($_POST['template']); else $template = stripslashes(trim($_POST['template'])); update_option('aphorismus_template', $template); update_option('aphorismus_admin_per_page', trim($_POST['admin_per_page'])); if (isset($_POST['admin_show'])) update_option('aphorismus_admin_show', $_POST['admin_show']); else update_option('aphorismus_admin_show', ''); update_option('aphorismus_admin_show_length', trim($_POST['admin_show_length'])); $per_page = trim($_POST['admin_per_page']); echo "

" . __ ('Settings saved', PLUGIN_NAME) . "

\n"; break; case 'update': if (!empty($aphorism)){ $id = $_POST['id']; $wpdb->update(APHORISMUS_TABLE, array('text' => $aphorism, 'author' => $author), array('id' => $id), array('%s', '%s'), array('%d')); echo "

" . __ ('Aphorism saved', PLUGIN_NAME) . "

\n"; } break; case 'edit': aphorismus_action($_GET['id']); break; case 'import': if (isset($_FILES['xmlfile']['tmp_name'])){ $upload_path = get_option('upload_path') . '/'; if(strpos($upload_path, ABSPATH) === false){ $upload_path = ABSPATH . $upload_path; } $upload_file = $upload_path . basename($_FILES['xmlfile']['name']); move_uploaded_file($_FILES['xmlfile']['tmp_name'], $upload_file); require_once(dirname(__FILE__).'/includes/import.php'); $aphorismus_importer = new aphorismus_importer($wpdb); if ($aphorismus_importer->aphorismus_importer_result($upload_file)){ echo "

" . sprintf( __ ('Imported aphorisms: %d', PLUGIN_NAME), $aphorismus_importer->get_aphorismus_importer_count()) . "

\n"; } unlink($upload_file); } break; } } if (isset($_GET['s'])){ if (!empty($_GET['s'])){ $search_string = mysql_escape_string(strip_tags(trim($_GET['s']))); $where .= "WHERE text LIKE '%".$search_string."%'"; } } if ($action != 'edit'){ $aphorisms_count = $wpdb->get_var("SELECT count(*) result FROM ".APHORISMUS_TABLE." ".$where.";"); echo "
\n"; echo "

\n"; echo "

" . __ ('Aphorismus', PLUGIN_NAME) . ""; if (!empty($search_string)) echo "" . __ ('Search result') . " «".$search_string."»"; echo "

\n"; echo "
\n"; echo "\n"; echo "

\n"; echo "\n"; echo "\n"; echo "\n"; echo "

\n"; echo "
\n"; if ($aphorisms_count > $per_page){ $num_pages = ceil($aphorisms_count / $per_page); $links_arr = array('base' => get_option('siteurl').'/wp-admin/admin.php?page='.PLUGIN_NAME.'/aphorismus.php%_%', 'format' => '&pagenum=%#%', 'prev_text' => __('«'), 'next_text' => __('»'), 'total' => $num_pages, 'current' => $pagenum); $page_links = paginate_links($links_arr); $page_links_text = sprintf( '' . __('Displaying %s–%s of %s', PLUGIN_NAME) . '%s', number_format_i18n(($pagenum - 1) * $per_page + 1), number_format_i18n(min($pagenum * $per_page, $aphorisms_count)), number_format_i18n($aphorisms_count), $page_links); echo "
\n"; echo $page_links_text; echo "
\n"; } echo "
\n"; echo "\n"; echo " \n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $aphorisms = $wpdb->get_results("SELECT id, text, author FROM ".APHORISMUS_TABLE." ".$where." ORDER BY text LIMIT ".($per_page * ($pagenum - 1)).",".$per_page.";", 'ARRAY_A'); if (!empty($aphorisms)){ foreach ($aphorisms as $aphorism){ echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; } } echo "\n"; echo "
" . __ ('Aphorism text', PLUGIN_NAME) . "" . __ ('Author', PLUGIN_NAME) . "
" . __ ('Aphorism text', PLUGIN_NAME) . "" . __ ('Author', PLUGIN_NAME) . "
" . $aphorism['text'] . "" . $aphorism['author'] . "
\n"; echo "
\n"; if ($aphorisms_count > $per_page){ echo "
\n"; echo $page_links_text; echo "
\n"; } echo "
\n"; echo "\n"; echo " \n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; } } /** * Show aphorismus settings * */ function aphorismus_settings(){ echo "
\n"; echo "

\n"; echo "

" . __ ('Settings', PLUGIN_NAME) . "

\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (get_option('aphorismus_admin_show') == 'true') $checked = 'checked="checked"'; else $checked = ''; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
" . __ ('Template string', PLUGIN_NAME) . "
 

" . __ ('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 "
" . __ ('Count of aphorisms on page', PLUGIN_NAME) . " " . __ ('in the admin panel', PLUGIN_NAME) . "
" . __ ('Show aphorisms in your admin screen', PLUGIN_NAME) . " " . __ ('The plugin "Hello Dolly" should be switched off', PLUGIN_NAME) . "
" . __ ('...Max length', PLUGIN_NAME) . " " . __ ('symbols', PLUGIN_NAME) . "
\n"; echo "
\n"; echo "\n"; echo "
\n"; ?> 0){ $aphorism = $wpdb->get_results("SELECT id, text, author FROM ".APHORISMUS_TABLE." WHERE id = '".$id."';", 'ARRAY_A'); $text = $aphorism[0]['text']; $author = $aphorism[0]['author']; } echo "
\n"; echo "

\n"; if ($id > 0) echo "

" . __ ('Editing aphorism', PLUGIN_NAME) . "

\n"; else echo "

" . __ ('Adding aphorism', PLUGIN_NAME) . "

\n"; if ($id == 0){ echo "
\n"; echo "\n"; echo "
\n"; } if (!isset($_GET['form_import'])){ echo "
0) echo "action=update"; else echo "action=add"; echo "\" style=\"margin-top: 20px;\">\n"; echo "
\n"; echo "
" . __ ('Aphorism text', PLUGIN_NAME) . "
\n"; echo "

" . __ ('You can use following tags:', PLUGIN_NAME) . "
<br />, <i>, <b>, <strong>

\n"; echo "
" . __ ('Author', PLUGIN_NAME) . "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; echo " 0) _e ('Save', PLUGIN_NAME); else _e ('Add', PLUGIN_NAME); echo "\" name=\"doaction\" id=\"doaction\" accesskey=\"a\" class=\"button-primary action\" />\n"; if ($id > 0) echo "\n"; echo "
\n"; } else { echo "
\n"; echo __ ('XML–file', PLUGIN_NAME) . "  \n"; echo "
\n"; } echo "
\n"; } /** * Show help * */ function aphorismus_help(){ echo "
\n"; echo "

\n"; echo "

" . __ ('Help', PLUGIN_NAME) . "

\n"; echo "

" . __ ('Addition of aphorisms', PLUGIN_NAME) . "

\n"; echo sprintf( __ ('

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 "

" . __ ('Installation', 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 "

" . __ ('Arguments', PLUGIN_NAME) . "

\n"; echo "

aphorismus ( [ string \$arg ] [, int \$max_length ] [, bool \$tags ] )

\n"; echo __ ('

aphorismus() echo string.

', PLUGIN_NAME) . "\n"; echo "

get_aphorismus ( [ string \$arg ] [, int \$max_length ] [, bool \$tags ] )

\n"; echo __ ('

get_aphorismus() return string.

', PLUGIN_NAME) . "\n"; echo __ ('

arg values:

', PLUGIN_NAME) . "\n"; echo __ ('

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 __ ('

tags resolve or forbid a conclusion of the text of an aphorism with tags. Default value is true. Value false forbids.

', PLUGIN_NAME) . "\n"; echo "
\n"; echo "
\n"; } /** * Paste style to the admin_head * */ function aphorismus_admin_head(){ ?> 0){ echo "

" . get_aphorismus('notemplate', get_option('aphorismus_admin_show_length')) . "

\n"; } } ?>