private function endValue($item, $implodeOn = '') { if (isset($item) && is_array($item)) { $item = end($item); $item = $item['Value']; } if (!empty($implodeOn)) { $item = implode(JisonParser_Phraser_Handler::sanitizeToWords($item), ','); } return $item; }
static function newestWikiRevision($phrase, $page) { $match = -1; $i = 0; $page = end(TikiLib::fetchAll("SELECT data, version FROM tiki_pages WHERE pageName = ?", array($page))); $page['data'] = TikiLib::lib("parser")->parse_data($page['data']); $match = JisonParser_Phraser_Handler::hasPhrase($page['data'], $phrase) == true ? $page['version'] : -1; if ($match < 0) { foreach (TikiLib::fetchAll("SELECT data, version FROM tiki_history WHERE pageName = ? ORDER BY version DESC", array($page)) as $page) { $match = JisonParser_Phraser_Handler::hasPhrase($page['data'], $phrase) == true ? $page['version'] : -1; if ($match > -1) { break; } } } return (int) $match; }
public function stack($level, $content) { JisonParser_Wiki_Handler::deleteEntities($content); $id = implode('_', JisonParser_Phraser_Handler::sanitizeToWords($content)); if (isset($this->idCount[$id])) { $this->idCount[$id]++; $id .= $this->idCount[$id]; } else { $this->idCount[$id] = 0; } if ($level == 1) { $this->stack[] = array('content' => $content, 'id' => $id, 'children' => array()); } else { $this->addToStack($this->stack, 1, $level, $content, $id); } return $id; }
function appendToContents(&$contents, $item) { global $prefs, $_REQUEST; $replace = false; //lets remove the newentry if it has already been accepted in the past foreach ($contents->entry as $i => $existingEntry) { foreach ($item->feed->entry as $j => $newEntry) { if ($existingEntry->textlink->text == $newEntry->textlink->text && $existingEntry->textlink->href == $newEntry->textlink->href) { unset($item->feed->entry[$j]); } } } //lets check if the hash is correct and that the phrase actually exists within the wiki page $checks = array(); foreach ($item->feed->entry as $i => $newEntry) { $checks[$i] = array(); $checks[$i]['titleHere'] = utf8_encode(implode('', JisonParser_Phraser_Handler::sanitizeToWords($prefs['browsertitle']))); $checks[$i]['phraseThere'] = utf8_encode(implode('', JisonParser_Phraser_Handler::sanitizeToWords($newEntry->forwardlink->text))); $checks[$i]['hashHere'] = hash_hmac('md5', $checks[$i]['titleHere'], $checks[$i]['phraseThere']); $checks[$i]['hashThere'] = $newEntry->forwardlink->hash; $checks[$i]['exists'] = JisonParser_Phraser_Handler::hasPhrase(TikiLib::lib('wiki')->get_parse($_REQUEST['page']), utf8_encode($newEntry->forwardlink->text)); $checks[$i]['reason'] = ''; if ($checks[$i]['hashHere'] != $checks[$i]['hashThere']) { $checks[$i]['reason'] .= '_hash_'; unset($item->feed->entry[$i]); } if ($newEntry->forwardlink->websiteTitle != $prefs['browsertitle']) { $checks[$i]['reason'] .= '_title_'; unset($item->feed->entry[$i]); } if (!$checks[$i]['exists']) { if (empty($checks[$i]['reason'])) { $checks[$i]['reason'] .= '_no_existence_hash_pass_'; } else { $checks[$i]['reason'] .= '_no_existence_'; } unset($item->feed->entry[$i]); } } if ($this->debug) { print_r($checks); } if (count($item->feed->entry) > 0) { $replace = true; $contents->entry += $item->feed->entry; } return $replace; }
static function restorePhrasesInWikiPage(JisonParser_Phraser_Handler $phraser, $phrases) { global $headerlib, $smarty; //TODO - not sure the tablesorter js and css files need to be loaded since they are loaded in tiki-setup $headerlib->add_jsfile('vendor/jquery/plugins/tablesorter/js/jquery.tablesorter.js')->add_cssfile('lib/jquery_tiki/tablesorter/style.css')->add_jq_onready(<<<JQ \t\t\t\t\$('a.forwardlinkA,a.textlinkA') \t\t\t\t\t.css('cursor', 'pointer') \t\t\t\t\t.click(function() { \t\t\t\t\t\tvar me = \$(this), \t\t\t\t\t\tmetadataHere = me.data('metadataHere'), \t\t\t\t\t\tmetadataThere = me.data('metadataThere'); \t\t\t\t\t\tvar table = \$('<table class="tablesorter" style="width: 100%;"/>'); \t\t\t\t\t\tvar thead = \$('<thead><tr /></thead>').appendTo(table); \t\t\t\t\t\tvar tbody = \$('<tbody><tr /></tbody>').appendTo(table); \t\t\t\t\t\tfunction a(head, body) { \t\t\t\t\t\t\t\$('<th />').text(head).appendTo(thead.find('tr')); \t\t\t\t\t\t\t\$('<td />').html(body).appendTo(tbody.find('tr')); \t\t\t\t\t\t} \t\t\t\t\t\ta(tr('Sentence text'), metadataThere.text); \t\t\t\t\t\ta(tr('Date Created'), metadataThere.dateOriginated); \t\t\t\t\t\ta(tr('Date Updated Here'), metadataHere.dateLastUpdated); \t\t\t\t\t\ta(tr('Date Updated There'), metadataThere.dateLastUpdated); \t\t\t\t\t\ta(tr('Click below to read Citing blocks'), '<input type="submit" value="' + tr('Read') + '" />'); \t\t\t\t\t\tvar form = \$('<form method="POST" />') \t\t\t\t\t\t\t.attr('action', metadataThere.href) \t\t\t\t\t\t\t.append(\$('<input type="hidden" name="phrase" />').val(metadataThere.text)) \t\t\t\t\t\t\t.append(table) \t\t\t\t\t\t\t.dialog({ \t\t\t\t\t\t\t\ttitle: tr('Linked to: ') + metadataHere.text, \t\t\t\t\t\t\t\tmodal: true, \t\t\t\t\t\t\t\twidth: \$(window).width() * 0.8 \t\t\t\t\t\t\t}); \t\t\t\t\t\treturn false; \t\t\t\t\t}); JQ , 100); $parsed = $smarty->getTemplateVars('parsed'); if (!empty($parsed)) { $smarty->assign('parsed', $phraser->findPhrases($parsed, $phrases)); } else { $previewd = $smarty->getTemplateVars('previewd'); if (!empty($previewd)) { $previewd = $phraser->findPhrases($previewd, $phrases); $smarty->assign('previewd', $previewd); } } }
function wikiplugin_textlink($data, $params) { global $tikilib, $headerlib, $caching, $page; static $textlinkI = 0; ++$textlinkI; $i = $textlinkI; $params = array_merge(array("clipboarddata" => ""), $params); extract($params, EXTR_SKIP); $clipboarddata = json_decode(stripslashes(trim(urldecode($clipboarddata)))); if (empty($clipboarddata)) return $data; $clipboarddata->href = urldecode($clipboarddata->href); $phraser = new JisonParser_Phraser_Handler(); $id = implode("", $phraser->sanitizeToWords($data)); Feed_ForwardLink_Send::add( array( "page"=> $page, "forwardlink"=> $clipboarddata, "textlink"=> array( "text"=> $data, "href"=> $tikilib->tikiUrl() . "tiki-index.php?page=$page#" . $id, "id"=> $clipboarddata->hash. "_" . $page . "_" . $id ) ) ); $data = addslashes(htmlspecialchars($data)); $date = $tikilib->get_short_date($clipboarddata->date); $clipboarddata->href = addslashes(htmlspecialchars($clipboarddata->href)); $clipboarddata->text = addslashes(htmlspecialchars($clipboarddata->text)); if (!empty($clipboarddata->href)) { $headerlib ->add_jsfile("lib/jquery/tablesorter/jquery.tablesorter.js") ->add_cssfile("lib/jquery_tiki/tablesorter/themes/tiki/style.css") ->add_jq_onready(<<<JQ $('#page-data').bind('rangyDone', function() { $('#$id').click(function() { var table = $('<div><table class="tablesorter">' + '<thead>' + '<tr>' + '<th>' + tr('Date') + '</th>' + '<th>' + tr('Click below to read Citing blocks') + '</th>' + '</tr>' + '</thead>' + '<tbody>' + '<tr>' + '<td>$date</td>' + '<td><a href="$clipboarddata->href" class="read">Read</a></td>' + '</tr>' + '</tbody>' + '</table></div>') .dialog({ title: tr("ForwardLinks To: ") + "$data", modal: true }) .tablesorter(); table.find('.read').click(function() { $('<form action="$clipboarddata->href" method="post">' + '<input type="hidden" name="phrase" value="$clipboarddata->text" />' + '</form>') .appendTo('body') .submit(); return false; }); return false; }); }); JQ ); return "~np~<span class='textlink'>~/np~".$data."~np~</span><a href='" .$clipboarddata->href ."' id='" . $id . "'>*</a>~/np~"; } else { return $data; } }
function appendToContents(&$contents, $item) { global $prefs, $_REQUEST; if ($this->debug == true) { ini_set('error_reporting', E_ALL); ini_set('display_errors', 1); } $this->itemsAdded = false; foreach ($item->feed->entry as $i => $newEntry) { $this->verifications[$i] = array(); $this->verifications[$i]["reason"] = array(); //lets remove the new entry if it has already been accepted in the past foreach ($contents->entry as &$existingEntry) { if ($existingEntry->textlink->text == $newEntry->textlink->text && $existingEntry->textlink->href == $newEntry->textlink->href) { $this->verifications[$i]['reason'][] = 'exists'; unset($item->feed->entry[$i]); } } $revision = Feed_ForwardLink_Search::findWikiRevision($newEntry->forwardlink->text); $this->verifications[$i]["hashBy"] = JisonParser_Phraser_Handler::superSanitize($newEntry->forwardlink->author . $newEntry->forwardlink->authorInstitution . $newEntry->forwardlink->authorProfession); $this->verifications[$i]['foundRevision'] = $revision; $this->verifications[$i]["metadataHere"] = $this->metadata->raw; $this->verifications[$i]["phraseThere"] = JisonParser_Phraser_Handler::superSanitize($newEntry->forwardlink->text); $this->verifications[$i]["hashHere"] = hash_hmac("md5", $this->verifications[$i]["hashBy"], $this->verifications[$i]["phraseThere"]); $this->verifications[$i]["hashThere"] = $newEntry->forwardlink->hash; $this->verifications[$i]['exists'] = JisonParser_Phraser_Handler::hasPhrase($revision['data'], $this->verifications[$i]["phraseThere"]); if ($this->verifications[$i]['hashHere'] != $this->verifications[$i]['hashThere']) { $this->verifications[$i]['reason'][] = 'hash_tampering'; unset($item->feed->entry[$i]); } if ($newEntry->forwardlink->websiteTitle != $prefs['browsertitle']) { $this->verifications[$i]['reason'][] = 'title'; unset($item->feed->entry[$i]); } if ($this->verifications[$i]['exists'] == false) { if (empty($this->verifications[$i]['reason'])) { $this->verifications[$i]['reason'][] = 'no_existence_hash_pass'; } else { $this->verifications[$i]['reason'][] = 'no_existence'; } unset($item->feed->entry[$i]); } foreach ($newEntry->forwardlink as $key => $value) { if (isset(Feed_ForwardLink_Metadata::$acceptableKeys[$key]) && Feed_ForwardLink_Metadata::$acceptableKeys[$key] == true) { //all clear } else { $this->verifications[$i]['reason'][] = 'metadata_tampering' . ($this->debug == true ? $key : ''); unset($item->feed->entry[$i]); } } foreach ($newEntry->textlink as $key => $value) { if (isset(Feed_ForwardLink_Metadata::$acceptableKeys[$key]) && Feed_ForwardLink_Metadata::$acceptableKeys[$key] == true) { //all clear } else { $this->verifications[$i]['reason'][] = 'metadata_tampering' . ($this->debug == true ? $key : ''); unset($item->feed->entry[$i]); } } } if (empty($item->feed->entry) == false) { $this->itemsAdded = true; foreach ($item->feed->entry as &$entry) { Tracker_Query::tracker('Wiki Attributes')->byName()->replaceItem(array('Page' => $this->page, 'Attribute' => '', 'Value' => $entry->forwardlink->text, 'Type' => 'ForwardLink Accepted')); } if (empty($contents->entry) == true) { $contents->entry = array(); } $contents->entry = array_merge($contents->entry, $item->feed->entry); } }