📄 serendipity_event_contentrewrite.php
字号:
<?php # $Id: serendipity_event_contentrewrite.php,v 1.5.4.3 2004/04/17 12:12:59 garvinhicking Exp $/*******************************************************汉化作者:youngong(http://youngong.blogbus.com) **官方主页:http://www.s9y.corg **我的信箱:youngong@163.com **如果有问题,欢迎和作者及汉化作者联系。 ********************************************************/switch ($serendipity['lang']) { case 'de': @define('PLUGIN_EVENT_CONTENTREWRITE_FROM', 'quelle'); @define('PLUGIN_EVENT_CONTENTREWRITE_TO', 'ziel'); @define('PLUGIN_EVENT_CONTENTREWRITE_NAME', 'Wort-Ersetzer'); @define('PLUGIN_EVENT_CONTENTREWRITE_DESCRIPTION', 'Ersetzt ein Wort mit einem neuen Inhalt, z.B. f黵 Akronyme'); @define('PLUGIN_EVENT_CONTENTREWRITE_NEWTITLE', 'Neuer Titel'); @define('PLUGIN_EVENT_CONTENTREWRITE_NEWTDESCRIPTION', 'Der Akronym-Titel des neuen Eintrages ({quelle})'); @define('PLUGIN_EVENT_CONTENTREWRITE_OLDTITLE', 'Titel #%d'); @define('PLUGIN_EVENT_CONTENTREWRITE_OLDTDESCRIPTION', 'Das Akronym ({quelle})'); @define('PLUGIN_EVENT_CONTENTREWRITE_PTITLE', 'Plugin Titel'); @define('PLUGIN_EVENT_CONTENTREWRITE_PDESCRIPTION', 'Der Name dieses Pligins'); @define('PLUGIN_EVENT_CONTENTREWRITE_NEWDESCRIPTION', 'Neue Beschreibung'); @define('PLUGIN_EVENT_CONTENTREWRITE_NEWDDESCRIPTION', 'Die Beschreibung des neuen Eintrages ({ziel})'); @define('PLUGIN_EVENT_CONTENTREWRITE_OLDDESCRIPTION', 'Beschreibung #%s'); @define('PLUGIN_EVENT_CONTENTREWRITE_OLDDDESCRIPTION', 'Die Beschreibung des Eintrages ({ziel})'); @define('PLUGIN_EVENT_CONTENTREWRITE_REWRITESTRING', 'Umformungsmaske'); @define('PLUGIN_EVENT_CONTENTREWRITE_REWRITESTRINGDESC', 'Ein beliebiger Text der zur Ersetzung verwendet werden soll. F黦en Sie {quelle} und {ziel} irgendwo in diesem Text ein.' . "\n" . 'Beispiel: <acronym title="{quelle}">{ziel}</acronym>'); @define('PLUGIN_EVENT_CONTENTREWRITE_REWRITECHAR', 'Rewrite Zeichen'); @define('PLUGIN_EVENT_CONTENTREWRITE_REWRITECHARDESC', 'Falls es ein besonderes Zeichen geben soll, was die Wort-Ersetzung ausf黨rt, geben Sie es hier an. Falls z.B. nur \'serendipity*\' damit ersetzt werden soll, was Sie als Akronym f黵 \'serendipity\' definiert haben, und das \'*\' soll entfernt werden, dann geben Sie dieses Zeichen an.'); break; case 'cn': @define('PLUGIN_EVENT_CONTENTREWRITE_FROM', '从'); @define('PLUGIN_EVENT_CONTENTREWRITE_TO', '到'); @define('PLUGIN_EVENT_CONTENTREWRITE_NAME', '评论重写'); @define('PLUGIN_EVENT_CONTENTREWRITE_DESCRIPTION', '用新字串替换任何词语 (就象只取首字母的缩写词)'); @define('PLUGIN_EVENT_CONTENTREWRITE_NEWTITLE', '新标题'); @define('PLUGIN_EVENT_CONTENTREWRITE_NEWTDESCRIPTION', '在此输入新项目的缩写标题{从})'); @define('PLUGIN_EVENT_CONTENTREWRITE_OLDTITLE', '标题 #%d'); @define('PLUGIN_EVENT_CONTENTREWRITE_OLDTDESCRIPTION', '在此输入首字母的缩写词({从})'); @define('PLUGIN_EVENT_CONTENTREWRITE_PTITLE', '标题插件'); @define('PLUGIN_EVENT_CONTENTREWRITE_PDESCRIPTION', '这个插件的名称'); @define('PLUGIN_EVENT_CONTENTREWRITE_NEWDESCRIPTION', '新描述'); @define('PLUGIN_EVENT_CONTENTREWRITE_NEWDDESCRIPTION', '在此输入一个新项目的描述({到})'); @define('PLUGIN_EVENT_CONTENTREWRITE_OLDDESCRIPTION', '描述 #%s'); @define('PLUGIN_EVENT_CONTENTREWRITE_OLDDDESCRIPTION', '在此输入描述 ({to})'); @define('PLUGIN_EVENT_CONTENTREWRITE_REWRITESTRING', '重写字串'); @define('PLUGIN_EVENT_CONTENTREWRITE_REWRITESTRINGDESC', '用于重写的字串。 置于取得重写的 {从} 和 {到} 的任意位置。' . "\n" . '例如: <acronym title="{to}">{from}</acronym>'); @define('PLUGIN_EVENT_CONTENTREWRITE_REWRITECHAR', '重写字符'); @define('PLUGIN_EVENT_CONTENTREWRITE_REWRITECHARDESC', '如果你有任意需要强制重写的附加字符,在此输入。 如果只打算用你输入的词语替换 \'serendipity*\' 但不替换\'*\' ,请在此输入字符。'); break; case 'en': case 'es': default: @define('PLUGIN_EVENT_CONTENTREWRITE_FROM', 'from'); @define('PLUGIN_EVENT_CONTENTREWRITE_TO', 'to'); @define('PLUGIN_EVENT_CONTENTREWRITE_NAME', 'Content Rewriter'); @define('PLUGIN_EVENT_CONTENTREWRITE_DESCRIPTION', 'Replaces any word with a new string (like for Acronyms)'); @define('PLUGIN_EVENT_CONTENTREWRITE_NEWTITLE', 'New Title'); @define('PLUGIN_EVENT_CONTENTREWRITE_NEWTDESCRIPTION', 'Enter the acronym-title for a new item here ({from})'); @define('PLUGIN_EVENT_CONTENTREWRITE_OLDTITLE', 'Title #%d'); @define('PLUGIN_EVENT_CONTENTREWRITE_OLDTDESCRIPTION', 'Enter the acronym here ({from})'); @define('PLUGIN_EVENT_CONTENTREWRITE_PTITLE', 'Plugin-Title'); @define('PLUGIN_EVENT_CONTENTREWRITE_PDESCRIPTION', 'The name of this plugin'); @define('PLUGIN_EVENT_CONTENTREWRITE_NEWDESCRIPTION', 'New Description'); @define('PLUGIN_EVENT_CONTENTREWRITE_NEWDDESCRIPTION', 'Enter the description for a new item here ({to})'); @define('PLUGIN_EVENT_CONTENTREWRITE_OLDDESCRIPTION', 'Description #%s'); @define('PLUGIN_EVENT_CONTENTREWRITE_OLDDDESCRIPTION', 'Enter the description here ({to})'); @define('PLUGIN_EVENT_CONTENTREWRITE_REWRITESTRING', 'Rewrite string'); @define('PLUGIN_EVENT_CONTENTREWRITE_REWRITESTRINGDESC', 'The string used to rewrite. Place {from} and {to} anywhere you like to get a rewrite.' . "\n" . 'Example: <acronym title="{to}">{from}</acronym>'); @define('PLUGIN_EVENT_CONTENTREWRITE_REWRITECHAR', 'Rewrite char'); @define('PLUGIN_EVENT_CONTENTREWRITE_REWRITECHARDESC', 'If there is any char you append to force rewriting, enter it here. If you want to only replace \'serendipity*\' with what you entered for that word but want the \'*\' removed, enter that char here.'); break;}class serendipity_event_contentrewrite extends serendipity_event{var $rewrite_from, $rewrite_to; function cleanup() { // Cleanup. Remove all empty configs on SAVECONF-Submit. serendipity_plugin_api::remove_plugin_value($this->instance, array('title', 'description')); return true; } function introspect(&$propbag) { global $serendipity; $propbag->add('name', PLUGIN_EVENT_CONTENTREWRITE_NAME); $propbag->add('description', PLUGIN_EVENT_CONTENTREWRITE_DESCRIPTION); $propbag->add('event_hooks', array( 'frontend_display' => true )); if ($_POST['SAVECONF']) $this->cleanup(); $rows = serendipity_db_query("SELECT name, value FROM {$serendipity['dbPrefix']}config WHERE name LIKE '" . $this->instance . "/%'"); $counter = 0; $values = array(); $values[] = 'title'; $values[] = 'rewrite_string'; $values[] = 'rewrite_char'; $this->title_values = array(); $this->descr_values = array(); $this->rewrite_from = array(); $this->rewrite_to = array(); if (is_array($rows)) { foreach ($rows as $row) { $plugin_value = str_replace($this->instance . '/', '', $row['name']); preg_match('|^(.+)_([0-9]+)$|msU', $plugin_value, $reg_counter); $found = false; if ($reg_counter[1] == 'title') { $this->title_values[] = $plugin_value; $this->rewrite_from[] = $row['value']; $found = true; } elseif ($reg_counter[1] == 'description') { $this->descr_values[] = $plugin_value; $this->rewrite_to[] = $row['value']; $found = true; } if ($found) { $next_counter = $reg_counter[2] + 1; $counter = ($next_counter > $counter ? $next_counter : $counter); } } } $counter = ($counter > 0 ? $counter + 1 : $counter); if (count($this->title_values) == count($this->descr_values)) { foreach($this->title_values AS $key => $val) { $values[] = $this->title_values[$key]; $values[] = $this->descr_values[$key]; } } $values[] = 'title' . '_' . $counter; $values[] = 'description' . '_' . $counter; $this->markup_elements = array( array( 'name' => ENTRY_BODY, 'element' => 'body', ), array( 'name' => EXTENDED_BODY, 'element' => 'extended', ), array( 'name' => COMMENT, 'element' => 'comment', ), array( 'name' => HTML_NUGGET, 'element' => 'html_nugget', ) ); foreach($this->markup_elements as $element) { $values[] = $element['name']; } $propbag->add('configuration', $values); $this->counter = $counter; } function introspect_config_item($name, &$propbag) { foreach($this->markup_elements as $element) { if ($name==$element['name']) { $propbag->add('type', 'boolean'); $propbag->add('name', $name); $propbag->add('description', sprintf(APPLY_MARKUP_TO, $name)); return true; } } preg_match('|^(.+)_([0-9]+)$|msU', $name, $switch); if (!isset($switch[2])) { $switch[1] = $name; $switch[2] = 'empty'; } switch($switch[1]) { case 'title': if ($switch[2] != 'empty') { $propbag->add('type', 'string'); if ($this->counter == $switch[2]) { $propbag->add('name', PLUGIN_EVENT_CONTENTREWRITE_NEWTITLE); $propbag->add('description', PLUGIN_EVENT_CONTENTREWRITE_NEWTDESCRIPTION); } else { $propbag->add('name', sprintf(PLUGIN_EVENT_CONTENTREWRITE_OLDTITLE, $switch[2])); $propbag->add('description', PLUGIN_EVENT_CONTENTREWRITE_OLDTDESCRIPTION); } } else { $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_EVENT_CONTENTREWRITE_PTITLE); $propbag->add('description', PLUGIN_EVENT_CONTENTREWRITE_PDESCRIPTION); } break; case 'description': $propbag->add('type', 'string'); if ($this->counter == $switch[2]) { $propbag->add('name', PLUGIN_EVENT_CONTENTREWRITE_NEWDESCRIPTION); $propbag->add('description', PLUGIN_EVENT_CONTENTREWRITE_NEWDDESCRIPTION); } else { $propbag->add('name', sprintf(PLUGIN_EVENT_CONTENTREWRITE_OLDDESCRIPTION, $switch[2])); $propbag->add('description', PLUGIN_EVENT_CONTENTREWRITE_OLDDDESCRIPTION); } break; case 'rewrite_string': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_EVENT_CONTENTREWRITE_REWRITESTRING); $propbag->add('description', PLUGIN_EVENT_CONTENTREWRITE_REWRITESTRINGDESC); break; case 'rewrite_char': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_EVENT_CONTENTREWRITE_REWRITECHAR); $propbag->add('description', PLUGIN_EVENT_CONTENTREWRITE_REWRITECHARDESC); break; default: return false; } return true; } function generate_content(&$title) { $title = $this->get_config('title');?><table><?php if (is_array($this->rewrite_from)) { foreach($this->rewrite_from AS $key => $val) {?> <tr> <th style="font-size: 8pt; font-color: white;"><?php echo htmlspecialchars($val); ?></th> <td><?php echo htmlspecialchars($this->rewrite_to[$key]); ?></td> </tr><?php } }?></table><?php } function event_hook($event, &$bag, &$eventData) { global $serendipity; $hooks = &$bag->get('event_hooks'); if (isset($hooks[$event])) { switch($event) { case 'frontend_display': $char = &$this->get_config('rewrite_char'); $string = &$this->get_config('rewrite_string'); foreach($this->rewrite_from AS $nr => $v_from) { $v_to = $this->rewrite_to[$nr]; if ($v_from != '' && $v_to != '') { // Use the supplied rewrite string and replace the {from} and {to} values with the ones we got from the plugin $new = str_replace( array( '{' . PLUGIN_EVENT_CONTENTREWRITE_FROM . '}', '{' . PLUGIN_EVENT_CONTENTREWRITE_TO . '}' ), array( str_replace( $char, '', $v_from ), $v_to ), $string ); // Build a regular expression (ungreedy, multiline) with our quoted value. $val here is the word needing the replacement $regex = '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -