add('name', PLUGIN_EVENT_WIKILINKS_NAME); $propbag->add('description', PLUGIN_EVENT_WIKILINKS_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Garvin Hicking, Grischa Brockhaus'); $propbag->add('version', '0.18'); $propbag->add('requirements', array( 'serendipity' => '1.0', 'smarty' => '2.6.7', 'php' => '4.1.0' )); $propbag->add('groups', array('MARKUP')); $propbag->add('event_hooks', array( 'frontend_display' => true, 'backend_entry_toolbar_extended' => true, 'backend_entry_toolbar_body' => true, 'external_plugin' => true )); $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', ) ); $conf_array = array(); foreach($this->markup_elements as $element) { $conf_array[] = $element['name']; } $conf_array[] = 'imgpath'; $conf_array[] = 'generate_draft_links'; $conf_array[] = 'generate_future_links'; $propbag->add('configuration', $conf_array); } function generate_content(&$title) { $title = $this->title; } function introspect_config_item($name, &$propbag) { global $serendipity; switch($name) { case 'imgpath': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_EVENT_WIKILINKS_IMGPATH); $propbag->add('description', PLUGIN_EVENT_WIKILINKS_IMGPATH_DESC); $propbag->add('default', $serendipity['serendipityHTTPPath'] . 'plugins/serendipity_event_wikilinks/'); break; case 'generate_draft_links': $propbag->add('name', PLUGIN_EVENT_WIKILINKS_SHOWDRAFTLINKS_NAME); $propbag->add('description', PLUGIN_EVENT_WIKILINKS_SHOWDRAFTLINKS_DESC); $propbag->add('type', 'boolean'); $propbag->add('default', 'true'); break; case 'generate_future_links': $propbag->add('name', PLUGIN_EVENT_WIKILINKS_SHOWFUTURELINKS_NAME); $propbag->add('description', PLUGIN_EVENT_WIKILINKS_SHOWFUTURELINKS_DESK); $propbag->add('type', 'boolean'); $propbag->add('default', 'true'); break; default: $propbag->add('type', 'boolean'); $propbag->add('name', constant($name)); $propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name))); $propbag->add('default', 'true'); } return true; } function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks = &$bag->get('event_hooks'); if (isset($hooks[$event])) { switch($event) { case 'frontend_display': foreach ($this->markup_elements as $temp) { if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) && !$eventData['properties']['ep_disable_markup_' . $this->instance] && !isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) { $element = $temp['element']; if ($element == 'body' || $element == 'extended') { $source =& $this->getFieldReference($element, $eventData); if ($source === '') { // Prevent bug from serendipity 0.9 $source =& $eventData[$element]; } } else { $source =& $eventData[$element]; } $source = preg_replace_callback( "#(\[\[|\(\(|\{\{)(.+)(\]\]|\)\)|\}\})#isUm", array($this, '_wikify'), $source ); } } return true; break; case 'external_plugin': $what = ''; if ($eventData == 'popup_choose_entry') { $what = 'body'; } elseif ($eventData == 'popup_choose_entrybody') { $what = 'body'; } elseif ($eventData == 'popup_choose_entryextended') { $what = 'extended'; } elseif (preg_match('/^popup_choose_entry(.*)$/i', $eventData, $matches)) { // get the custom thing that is to be selected, for example a nugget $what = $matches[1]; } if (empty($what)) { return false; } ?> <?php echo PLUGIN_EVENT_WIKILINKS_LINKENTRY; ?>

'; return true; default: return false; } } else { return false; } } /** * Wikifies: * [[ENTRY|DESC]] is an internal link * ((ENTRY|DESC)) is a staticpage link. */ function _wikify($buffer) { global $serendipity; $debug = true; $$admin_url = false; $cidx = 2; if ($buffer[1] == '((') { $type = $otype = 'staticpage'; } elseif ($buffer[1] == '{{') { $type = $otype = 'mixed'; } else { $type = $otype = 'internal'; } $parts = explode('|', $buffer[$cidx]); if (isset($parts[1])) { $desc = $parts[1]; $ltitle = $parts[0]; } else { $desc = $ltitle = $buffer[$cidx]; } // ltitle might contain entities, convert them: $ltitle = @html_entity_decode($ltitle, ENT_COMPAT, LANG_CHARSET); $sql = ''; if ($type == 'staticpage') { $entry = serendipity_db_query("SELECT id, permalink FROM {$serendipity['dbPrefix']}staticpages WHERE headline = '" . serendipity_db_escape_string($ltitle) . "'" . " ORDER BY timestamp DESC LIMIT 1", true, 'assoc'); } elseif ($type == 'mixed') { $entry = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}entries WHERE title = '" . serendipity_db_escape_string($ltitle) . "'" . " ORDER BY timestamp DESC LIMIT 1", true, 'assoc'); $type = 'internal'; if (!is_array($entry)) { $entry = serendipity_db_query("SELECT id, permalink FROM {$serendipity['dbPrefix']}staticpages WHERE headline = '" . serendipity_db_escape_string($ltitle) . "'" . " ORDER BY timestamp DESC LIMIT 1", true, 'assoc'); $type = 'staticpage'; } } else { $entry = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}entries WHERE title = '" . serendipity_db_escape_string($ltitle) . "'" . " ORDER BY timestamp DESC LIMIT 1", true, 'assoc'); } if (is_array($entry)) { // The entry exists. // check, wether we don't want draft or future links: //if (serendipity_db_bool($this->get_config('generate_draft_links', false)) || !$entry['isdraft']){ if (serendipity_db_bool($this->get_config('generate_future_links', false)) || $entry['timestamp']<=serendipity_db_time()){ if ($type == 'staticpage') { $entry_url = $entry['permalink']; } else { $entry_url = serendipity_archiveURL($entry['id'], $entry['title'], 'serendipityHTTPPath', true, array('timestamp' => $entry['timestamp'])); } } if (serendipity_userLoggedIn()) { $mode = 'edit'; if ($type == 'staticpage') { $admin_url = $serendipity['baseURL'] .'serendipity_admin.php?serendipity[adminModule]=event_display&serendipity[adminAction]=staticpages&serendipity[staticid]='. $entry['id']; $admin_title = PLUGIN_EVENT_WIKILINKS_EDIT_STATICPAGE; } else { $admin_url = $serendipity['baseURL'] .'serendipity_admin.php?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=edit&serendipity[id]='. $entry['id']; $admin_title = PLUGIN_EVENT_WIKILINKS_EDIT_INTERNAL; } } } else { // The entry does not yet exist. $entry_url = ''; if (serendipity_userLoggedIn()) { $mode = 'create'; $title = urlencode($ltitle); $body = '

' . htmlspecialchars($ltitle) . '

'; $admin_url2 = $serendipity['baseURL'] . 'serendipity_admin.php?serendipity[adminModule]=event_display&serendipity[adminAction]=staticpages&serendipity[pre][headline]=' . $title . '&serendipity[pre][content]=' . $body . '&serendipity[pre][pagetitle]=' . $title; if ($otype == 'staticpage') { $admin_url = $serendipity['baseURL'] . 'serendipity_admin.php?serendipity[adminModule]=event_display&serendipity[adminAction]=staticpages&serendipity[staticpagecategory]=pages&serendipity[pre][headline]=' . $title . '&serendipity[pre][content]=' . $body . '&serendipity[pre][pagetitle]=' . $title; $admin_title = PLUGIN_EVENT_WIKILINKS_CREATE_STATICPAGE; } elseif ($otype == 'mixed') { $admin_url = $serendipity['baseURL'] . 'serendipity_admin.php?serendipity[adminModule]=entries&serendipity[adminAction]=new&serendipity[title]=' . $title . '&serendipity[body]=' . $body; $admin_title = PLUGIN_EVENT_WIKILINKS_CREATE_INTERNAL; } else { $admin_url = $serendipity['baseURL'] . 'serendipity_admin.php?serendipity[adminModule]=entries&serendipity[adminAction]=new&serendipity[title]=' . $title . '&serendipity[body]=' . $body; $admin_title = PLUGIN_EVENT_WIKILINKS_CREATE_INTERNAL; } } else { $ltitle .= '?'; } } $out = ''; if ($entry_url) { $out .= ''; } $out .= $desc; if ($entry_url) { $out .= ''; } if ($admin_url) { if ($otype == 'mixed') { $imgurl = $this->get_config('imgpath') . $mode . '_internal.png'; $img1 = '?'; $out .= '' . $img1 . ''; if ($admin_url2) { $imgurl = $this->get_config('imgpath') . $mode . '_staticpage.png'; $img2 = '?'; $out .= '' . $img2 . ''; } } else { $imgurl = $this->get_config('imgpath') . $mode . '_' . $type . '.png'; $img = '?'; $out .= '' . $img . ''; } } $out .= ''; return $out; } } /* vim: set sts=4 ts=4 expandtab : */