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.25.3'); $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, 'backend_publish' => true, 'backend_save' => true, 'backend_sidebar_entries_event_display_wikireferences' => true, 'backend_sidebar_entries' => 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'; $conf_array[] = 'reference_match'; $conf_array[] = 'reference_info'; $conf_array[] = 'target_match'; $conf_array[] = 'target_match2'; $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; case 'reference_match': $propbag->add('name', PLUGIN_EVENT_WIKILINKS_REFMATCH_NAME); $propbag->add('description', PLUGIN_EVENT_WIKILINKS_REFMATCH_DESC); $propbag->add('type', 'string'); $propbag->add('default', '.+)["\'])?>(?P.*)'); break; case 'target_match': $propbag->add('name', PLUGIN_EVENT_WIKILINKS_REFMATCHTARGET_NAME); $propbag->add('description', PLUGIN_EVENT_WIKILINKS_REFMATCHTARGET_DESC); $propbag->add('type', 'string'); $propbag->add('default', '{count}'); break; case 'target_match2': $propbag->add('name', PLUGIN_EVENT_WIKILINKS_REFMATCHTARGET2_NAME); $propbag->add('description', PLUGIN_EVENT_WIKILINKS_REFMATCHTARGET2_DESC); $propbag->add('type', 'string'); $propbag->add('default', '
  • {text}
  • '); break; case 'reference_info': $propbag->add('name', PLUGIN_EVENT_WIKILINKS_REFMATCHTARGET2_NAME); $propbag->add('description', PLUGIN_EVENT_WIKILINKS_REFMATCHTARGET2_DESC); $propbag->add('type', 'content'); $propbag->add('default', PLUGIN_EVENT_WIKILINKS_REFDOC); break; case 'db_built': return false; 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 'backend_publish': case 'backend_save': // Purge, so that the data within the entry takes precedence over other changes serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}wikireferences WHERE entryid = " . (int)$eventData['id']); break; case 'backend_sidebar_entries': $this->setupDB(); echo ''; break; case 'backend_sidebar_entries_event_display_wikireferences': $entries = serendipity_db_query("SELECT id, refname FROM {$serendipity['dbPrefix']}wikireferences ORDER BY refname ASC"); echo '

    ' . PLUGIN_EVENT_WIKILINKS_MAINT_DESC . '

    '; echo '
    '; echo ''; echo ''; echo ''; echo ''; echo '

    '; if ($serendipity['POST']['wikireference'] > 0) { if ($serendipity['POST']['saveSubmit']) { serendipity_db_update('wikireferences', array('id' => $serendipity['POST']['wikireference']), array('refname' => $serendipity['POST']['wikireference_refname'], 'ref' => $serendipity['POST']['wikireference_ref'])); echo '
    ' . DONE .': '. sprintf(SETTINGS_SAVED_AT, serendipity_strftime('%H:%M:%S')) . '
    '; } $ref = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}wikireferences WHERE id = " . (int)$serendipity['POST']['wikireference'], true, 'assoc'); $entry = serendipity_fetchEntry('id', $ref['entryid']); echo '
    '; echo '
    '; echo ''; echo ''; echo '
    '; echo '
    '; echo '
    '; echo ''; echo '
    '; echo '
    '; echo ''; echo '' . $entry['title'] . ''; echo '

    ' . EDIT_ENTRY . '

    '; echo '
    '; } echo '
    '; break; case 'frontend_display': $this->out_references = array(); 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']; $is_body = false; if ($element == 'body' || $element == 'extended') { $source =& $this->getFieldReference($element, $eventData); if ($source === '') { // Prevent bug from serendipity 0.9 $source =& $eventData[$element]; } $is_body = true; } else { $source =& $eventData[$element]; } $this->references = $this->refcount = array(); $this->ref_entry = $eventData['id']; $source = preg_replace_callback( '^' . $this->get_config('reference_match') . '^imsU', array($this, '_reference'), $source ); $source = preg_replace_callback( "#(\[\[|\(\(|\{\{)(.+)(\]\]|\)\)|\}\})#isUm", array($this, '_wikify'), $source ); $source .= $this->reference_parse(); if ($is_body) { if (!is_array($eventData['properties']['references'])) $eventData['properties']['references'] = array(); $eventData['properties']['references'] += $this->references; } } } 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; } } function install() { $this->setupDB(); } function setupDB() { global $serendipity; $built = $this->get_config('db_built', null); if (empty($built)) { serendipity_db_schema_import("CREATE TABLE {$serendipity['dbPrefix']}wikireferences ( id {AUTOINCREMENT} {PRIMARY}, entryid int(11) default '0', refname text, ref text)"); serendipity_db_schema_import("CREATE INDEX wikiref_refname ON {$serendipity['dbPrefix']}wikireferences (refname(191));"); serendipity_db_schema_import("CREATE INDEX wikiref_comb ON {$serendipity['dbPrefix']}wikireferences (entryid,refname(191));"); serendipity_db_schema_import("CREATE INDEX wikiref_entry ON {$serendipity['dbPrefix']}wikireferences (entryid);"); $this->set_config('db_built', 1); } } function _reference($buffer) { global $serendipity; static $count = 0; $count++; if (!empty($buffer['ref']) && !empty($buffer['refname']) && !empty($this->ref_entry)) { // New refname, needs to be stored in the database IF NOT CURRENTLY EXISTING $exists = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}wikireferences WHERE refname = '" . serendipity_db_escape_string($buffer['refname']) . "'", true, 'assoc'); if ($exists['entryid'] == $this->ref_entry) { #serendipity_db_update('wikireferences', array('entryid' => $this->ref_entry, 'refname' => $buffer['refname']), array('ref' => $buffer['ref'])); } elseif (empty($exists['entryid'])) { serendipity_db_insert('wikireferences', array('entryid' => $this->ref_entry, 'refname' => $buffer['refname'], 'ref' => $buffer['ref'])); } } if (empty($buffer['ref']) && !empty($buffer['refname'])) { // We found a referenced pattern like , so let's fetch that from the database! $exists = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}wikireferences WHERE refname = '" . serendipity_db_escape_string($buffer['refname']) . "'", true, 'assoc'); $buffer['ref'] = $exists['ref']; } if (empty($buffer['refname'])) { $buffer['refname'] = $count; } $refix = $count; if (isset($this->references[$buffer['refname']])) { if ($this->references[$buffer['refname']] == $buffer['ref']) { $refix = $this->refcount[$buffer['refname']]; } else { $this->references[$buffer['refname'] . $count] = $buffer['ref']; $this->refcount[$buffer['refname'] . $count] = $count; } } else { $this->references[$buffer['refname']] = $buffer['ref']; $this->refcount[$buffer['refname']] = $count; } $result = $this->get_config('target_match'); $result = str_replace( array( '{count}', '{text}', '{refname}' ), array( $refix, (function_exists('serendipity_specialchars') ? serendipity_specialchars($buffer['ref']) : htmlspecialchars($buffer['ref'], ENT_COMPAT, LANG_CHARSET)), (function_exists('serendipity_specialchars') ? serendipity_specialchars($buffer['refname']) : htmlspecialchars($buffer['refname'], ENT_COMPAT, LANG_CHARSET)), ), $result ); return $result; } function reference_parse() { global $serendipity; static $count = 0; static $count2 = 0; $count++; $format = $this->get_config('target_match2'); if ($format == '-') return; if (count($this->references) == 0) return; $block = "\n\n" . '
      ' . "\n"; foreach($this->references AS $key => $buffer) { $count2++; $result = str_replace( array( '{count}', '{text}', '{refname}' ), array( $count2, (function_exists('serendipity_specialchars') ? serendipity_specialchars($buffer) : htmlspecialchars($buffer, ENT_COMPAT, LANG_CHARSET)), $key ), $format ); $block .= $result . "\n"; } $block .= '
    ' . "\n"; return $block; } /** * 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 = '

    ' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($ltitle) : htmlspecialchars($ltitle, ENT_COMPAT, LANG_CHARSET)) . '

    '; $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 : */