/**
  * This class implements the Singleton pattern. There is only ever
  * one instance of the this class and it is accessed only via the 
  * ClassName::instance() method.
  * 
  * @return object 
  * @access public
  * @since 5/26/05
  * @static
  */
 public static function instance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new WikiResolver();
     }
     return self::$instance;
 }
<?php

/**
 * Embedded video configuration
 *
 * USAGE: Copy this file to video.conf.php to set custom values.
 *
 * @package segue.config
 * 
 * @copyright Copyright &copy; 2005, Middlebury College
 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
 *
 */
$video = WikiResolver::instance()->getTextTemplate('video');
/*********************************************************
 * YouTube
 *********************************************************/
$service = $video->addService(new Segue_TextTemplates_Video_Service('youtube', '<object width="###WIDTH###" height="###HEIGHT###"><param name="movie" value="http://www.youtube.com/v/###ID###&amp;hl=en&amp;fs=1###FMT###"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/###ID###&amp;hl=en&amp;fs=1###FMT###" type="application/x-shockwave-flash" allowfullscreen="true" width="###WIDTH###" height="###HEIGHT###"></embed></object>'));
$service->setDefaultValue('width', '425');
$service->setDefaultValue('height', '344');
$service->setHtmlPlayerRegex('/http:\\/\\/www\\.youtube\\.com\\/v\\//');
$service->setHtmlIdRegex('/http:\\/\\/www\\.youtube\\.com\\/v\\/([a-z0-9_-]+)/i');
$service->addParam('fmt', '/^[0-9]*$/', '', '&amp;ap=%2526fmt%3D');
$service->setHtmlParamsRegex('/\\&ap=%2526fmt%3D([0-9]+)/', array(1 => 'fmt'));
// Playlists
$service = $video->addService(new Segue_TextTemplates_Video_Service('youtube_playlist', '<object width="###WIDTH###" height="###HEIGHT###"><param name="movie" value="http://www.youtube.com/p/###ID###&amp;hl=en&amp;fs=1###FMT###"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/p/###ID###&amp;hl=en&amp;fs=1###FMT###" type="application/x-shockwave-flash" allowfullscreen="true" width="###WIDTH###" height="###HEIGHT###"></embed></object>'));
$service->setDefaultValue('width', '425');
$service->setDefaultValue('height', '344');
$service->setHtmlPlayerRegex('/http:\\/\\/www\\.youtube\\.com\\/p\\//');
$service->setHtmlIdRegex('/http:\\/\\/www\\.youtube\\.com\\/p\\/([a-z0-9_-]+)/i');
$service->addParam('fmt', '/^[0-9]*$/', '', '&amp;ap=%2526fmt%3D');
Exemple #3
0
<?php

/* $Id$ */
include "output_modules/common.inc.php";
$t = makedownloadbar($o);
$st = convertTagsToInteralLinks($site, $t);
if ($o->getField("texttype") == 'text') {
    $st = nl2br($st);
}
$wikiResolver =& WikiResolver::instance();
$st = $wikiResolver->parseText($st, $site, $section, $page);
printc($st);
if ($o->getField("discuss")) {
    include dirname(__FILE__) . "/discussionLink.inc.php";
}
 /**
  * Answer a element that represents the content for this Block
  * 
  * @return object DOMElement
  * @access protected
  * @since 2/12/08
  */
 protected function getContentElement(DOMElement $mediaElement)
 {
     try {
         $shortTextElement = $this->getSingleSourceElement('./shorttext', $this->sourceElement);
         $shortHtml = $this->getStringValue($shortTextElement);
         // Convert Line returns if needed
         if ($shortTextElement->hasAttribute('text_type') && $shortTextElement->getAttribute('text_type') == 'text') {
             $shortHtml = nl2br($shortHtml);
         }
         $longTextElement = $this->sourceXPath->query('./longertext', $this->sourceElement)->item(0);
         if ($longTextElement) {
             $longHtml = $this->getStringValue($longTextElement);
             if ($longTextElement->hasAttribute('text_type') && $longTextElement->getAttribute('text_type') == 'text') {
                 $longHtml = nl2br($longHtml);
             }
         } else {
             $longHtml = '';
         }
     } catch (MissingNodeException $e) {
         try {
             $shortTextElement = $this->getSingleSourceElement('./text', $this->sourceElement);
             $shortHtml = $this->getStringValue($shortTextElement);
         } catch (MissingNodeException $e) {
             $shortHtml = '';
         }
         $longHtml = '';
     }
     // Replace links to media files with new versions
     $shortHtml = $this->attachMediaFromHtml($shortHtml, $mediaElement);
     $shortHtml = $this->rewriteLocalLinks($shortHtml);
     $longHtml = $this->attachMediaFromHtml($longHtml, $mediaElement);
     $longHtml = $this->rewriteLocalLinks($longHtml);
     // Convert any media to Text-Template markup
     $shortHtml = WikiResolver::instance()->unapplyTextTemplates($shortHtml);
     $longHtml = WikiResolver::instance()->unapplyTextTemplates($longHtml);
     // Clean out any bad html
     $shortHtml = $this->cleanHtml($shortHtml);
     $longHtml = $this->cleanHtml($longHtml);
     $currentVersion = $this->doc->createElement('currentVersion');
     $version = $currentVersion->appendChild($this->doc->createElement('version'));
     if (strlen(trim($longHtml))) {
         $version->appendChild($this->createCDATAElement('content', $shortHtml . "\n<br/><br/>\n" . $longHtml));
         $version->appendChild($this->doc->createElement('abstractLength', str_word_count(strip_tags($shortHtml))));
     } else {
         $version->appendChild($this->createCDATAElement('content', $shortHtml));
         $version->appendChild($this->doc->createElement('abstractLength', 0));
     }
     return $currentVersion;
 }
 /**
  * Parse the wiki-text and replace wiki markup with HTML markup.
  * 
  * @param string $text
  * @param optional $editorSafeOnly If true, only templates that are safe for
  *				working with in a WYSIWIG editor will be applied.
  * @return string
  * @access public
  * @since 7/14/08
  */
 public function applyTextTemplates($text, $editorSafeOnly = false)
 {
     $regexp = "/\n\n(<nowiki>)?\t\t# optional nowiki tag to prevent parsing.\n\n{{\t# The opening template tags\n\n\t\\s*\t\t# optional whitespace\n\t\n\t([a-z0-9_-]+)\t\t# template name\n\t\n\t\\s*\t\t# optional whitespace\n\n\t(?: |([^}]+) )?\t\t# A parameter list\n\n}}\t# The closing template tags\n\n(<\\/nowiki>)?\t# optional closing nowiki tag to prevent parsing.\n\n/xi";
     $paramRegexp = "/\n\n\t\\s*\t\t\t\t\t# optional whitespace\n\t\n\t([a-z0-9_-]+)\t\t# param name\n\t\n\t\\s*\t\t\t\t\t# optional whitespace\n\t\n\t=\t\t\t\t\t# Equals\n\t\n\t\\s*\t\t\t\t\t# optional whitespace\n\n\t([^|]+)\t\t\t\t# param value\n\n/xi";
     WikiResolver::mb_preg_match_all($regexp, $text, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
     // 		printpre($matches);
     // for each wiki template replace it with the HTML version
     $offsetDiff = 0;
     foreach ($matches as $match) {
         $offset = $match[0][1] + $offsetDiff;
         $wikiText = $match[0][0];
         $templateName = strtolower($match[2][0]);
         if (isset($match[3])) {
             $paramString = trim($match[3][0]);
         } else {
             $paramString = '';
         }
         // Ignore markup surrounded by nowiki tags
         if (!strlen($match[1][0]) && (!isset($match[4]) || !strlen($match[4][0]))) {
             try {
                 $template = $this->getTextTemplate($templateName);
                 if (!$editorSafeOnly || $template->isEditorSafe()) {
                     // Build the parameter array
                     $params = array();
                     preg_match_all($paramRegexp, $paramString, $paramMatches);
                     foreach ($paramMatches[1] as $j => $paramName) {
                         if (!isset($params[$paramName])) {
                             $params[$paramName] = $paramMatches[2][$j];
                         } else {
                             if (is_array($params[$paramName])) {
                                 $params[$paramName][] = $paramMatches[2][$j];
                             } else {
                                 $params[$paramName] = array($params[$paramName]);
                                 $params[$paramName][] = $paramMatches[2][$j];
                             }
                         }
                     }
                     // Execute the template
                     try {
                         $output = $template->generate($params);
                         // 						$output .= printpre(htmlentities(print_r($template->getHtmlMatches($output), true)), true);
                         $offsetDiff = $offsetDiff + mb_strlen($output) - mb_strlen($wikiText);
                         $text = substr_replace($text, $output, $offset, mb_strlen($wikiText));
                     } catch (Exception $e) {
                         print $e->getMessage();
                     }
                 }
             } catch (UnknownIdException $e) {
                 if ($e->getCode() != 34563) {
                     throw $e;
                 }
             }
         } else {
             $output = '{{' . $templateName . $paramString . '}}';
             $offsetDiff = $offsetDiff + mb_strlen($output) - mb_strlen($wikiText);
             $text = substr_replace($text, $output, $offset, mb_strlen($wikiText));
         }
     }
     return $text;
 }
Exemple #6
0
 /**
  * Set up text templates to output for wordpress.
  * 
  * @return null
  */
 protected function setupTextTemplates()
 {
     // Initialize the text-templates
     WikiResolver::instance()->getTextTemplate('video');
     // Reconfigure video
     WikiResolver::instance()->replaceTextTemplate('video', new Segue_TextTemplates_video());
     $this->configureTextTemplate('video');
     // Reconfigure audio
     WikiResolver::instance()->replaceTextTemplate('audio', new Segue_TextTemplates_WordpressAudio());
 }
 /**
  * Parse and replace any output HTML that matches two-way text-plugins with their markup. 
  * These are text-plugins that can convert themselves to and from HTML markup.
  * 
  * @param string $text
  * @return string
  * @access public
  * @since 7/15/08
  */
 public final function unapplyTextTemplates($text)
 {
     $wikiResolver = WikiResolver::instance();
     try {
         $text = $wikiResolver->unapplyTextTemplates($text);
     } catch (OperationFailedException $e) {
     }
     return $text;
 }
 function _output($cr, $o)
 {
     global $sid, $error, $showallauthors, $showposts, $uploadurl, $site_owner, $_full_uri;
     $siteOwnerId = db_get_value("user", "user_id", "user_uname='" . addslashes($site_owner) . "'");
     $parentAuthorId = db_get_value("discussion", "FK_author", "discussion_id='" . addslashes($this->parentid) . "'");
     //print $siteOwnerId;
     //printc("author=".$parentAuthorId);
     $siteObj =& $this->storyObj->owningSiteObj;
     $siteLevelEditors = $siteObj->getSiteLevelEditors();
     $isSiteEditor = in_array($_SESSION[auser], $siteLevelEditors);
     if ($showposts == 1 || ($_SESSION[auser] == $this->authoruname || $o == 1 || $isSiteEditor || $site_owner == $this->authoruname && $_SESSION[aid] == $parentAuthorId && $_SESSION[auser] || in_array($this->authoruname, $siteLevelEditors) && $_SESSION[aid] == $parentAuthorId && $_SESSION[auser])) {
         // check to see if we have any info to commit
         $this->_commithttpdata();
         if ($_REQUEST['discuss'] == 'edit' && $_REQUEST['id'] == $this->id) {
             $this->_outputform('edit');
             return true;
         }
         if ($_REQUEST['discuss'] == 'del' && $_REQUEST['id'] == $this->id) {
             $this->_del();
             return true;
         }
         if ($_REQUEST['discuss'] == 'rate' && $_REQUEST['id'] == $this->id) {
             $this->_outputform('rate');
             return true;
         }
         //$script = $_SERVER['SCRIPT_NAME'];
         /******************************************************************************
          * 	Outputs html for displaying posts
          * outputs discussion post info
          ******************************************************************************/
         if (!$this->id) {
             return false;
         }
         printc("\n<tr>");
         $s = "<a href='" . $_full_uri . "/index.php?{$sid}&amp;action=site&amp;" . $this->getinfo . "&amp;expand=" . $this->id . "' name='" . $this->id . "'>" . $this->subject . "</a>\n";
         //	printc ("</form>");
         //		$s = $this->subject;
         //printpre($_SESSION);
         $a = "";
         if ($showallauthors == 1 || $_SESSION[auser] && ($o || $_SESSION[auser] == $this->authoruname || $site_owner == $this->authoruname && $_SESSION[aid] == $parentAuthorId)) {
             if ($this->opt("showauthor")) {
                 $a .= "by <span class='subject'>" . $this->authorfname . "</span>\n";
             }
             if ($this->opt("showauthor") && $this->opt("showtstamp")) {
                 $a .= " on ";
             }
         } else {
             $a .= "posted on ";
         }
         if ($this->opt("showtstamp")) {
             $a .= timestamp2usdate($this->tstamp);
         }
         // Wiki-markup example
         global $storyObj;
         $a .= WikiResolver::getMarkupExample($storyObj->getField("title"), $this->id);
         /******************************************************************************
          * 	 collect possible actions to current post (rely | del | edit | rate)
          ******************************************************************************/
         $b = array();
         if ($cfg['disable_discussion'] != TRUE && ($cfg['disable_discussion'] != TRUE && $_SESSION['ltype'] == 'admin')) {
             if ($cr) {
                 $b[] = "<a href='" . $_full_uri . "/index.php?{$sid}" . $this->getinfo . "&amp;replyto=" . $this->id . "&amp;action=site&amp;discuss=reply#reply'>reply</a>\n";
             }
             if ($o || $_SESSION[auser] == $this->authoruname && !$this->dbcount()) {
                 $b[] = "| <a href='" . $_full_uri . "/index.php?{$sid}" . $this->getinfo . "&amp;action=site&amp;discuss=del&amp;id=" . $this->id . "'>delete</a>\n";
             }
             if ($_SESSION[auser] == $this->authoruname && !$this->dbcount()) {
                 $b[] = " | <a href='" . $_full_uri . "/index.php?{$sid}" . $this->getinfo . "&amp;id=" . $this->id . "&amp;action=site&amp;discuss=edit#" . $this->id . "'>edit</a>\n";
             }
             if ($o) {
                 $ratelink = "<a href='" . $_full_uri . "/index.php?{$sid}" . $this->getinfo . "&amp;id=" . $this->id . "&amp;action=site&amp;discuss=rate#" . $this->id . "'>rate</a>\n";
             }
         }
         /******************************************************************************
          * if there are dicussion actions (reply | del | edit | rate) then print 
          ******************************************************************************/
         if ($a != "" || count($b)) {
             $c = '';
             if (count($b)) {
                 $c .= implode(" ", $b);
             }
             /******************************************************************************
              * discussion post header info (subject=$s, author and timestamp=$a, options=$c)
              ******************************************************************************/
             //printc ("<table width='100%' cellspacing='0px'>\n");
             printc("\n<td class='dheader3'>\n");
             printc("<table width='100%' cellspacing='0px'>\n");
             printc("<tr><td align='left'>\n");
             printc("<span class='subject'>\n");
             // subject
             printc($s);
             // rating
             if ($this->rating !== NULL) {
                 printc(" (Rating: " . $this->rating . ")");
             }
             printc("</span></td>\n");
             // link for rating
             printc("<td align='right'>{$ratelink}</td>\n");
             printc("</tr><tr>\n");
             printc("<td>{$a}\n");
             printc("</td>\n");
             printc("<td align='right' valign='bottom'>{$c}</td>");
             printc("</tr>\n</table>\n");
             /******************************************************************************
              * if there are no dicussion actions (rely | del | edit | rate) then 
              * print subject only
              ******************************************************************************/
         } else {
             printc($s);
         }
         printc("</td></tr>");
         /******************************************************************************
          * 	print discussion post content
          ******************************************************************************/
         if ($this->opt("showcontent")) {
             printc("<tr><td class='dtext'>");
             if ($this->media_tag) {
                 $media_link = "<a href='" . $uploadurl . "/" . $_REQUEST[site] . "/" . $this->media_tag . "' target='media'>" . $this->media_tag . "</a>\n";
                 $mediaRow[media_tag] = $this->media_tag;
                 $mediaRow[slot_name] = $_REQUEST[site];
                 $mediaRow[media_size] = $this->media_size;
                 $audioplayer = printMediaPlayer($mediaRow);
                 $downloadlink = printDownloadLink($mediaRow);
                 //					$citation = printCitation($mediaRow);
                 // if attached file is an .mp3 print out audio player
                 if ($audioplayer) {
                     printc("<table width='100%' cellpadding='2' border='0'>");
                     printc("<tr><td>");
                     printc($downloadlink . "\n");
                     printc($audioplayer . "\n");
                     //						printc ("<div style='clear: left; font-size: smaller; margin-bottom: 10px; '>");
                     //						printc ($citation."\n");
                     //						printc ("</div>");
                     printc("</td></tr>");
                     printc("</table>");
                     // if attached file not .mp3 print out download link only
                 } else {
                     printc("<table width='100%' cellpadding='2' border='0'>");
                     printc("<tr><td>");
                     printc("<div style='clear: left; float: left; '>{$media_link}</div>\n");
                     printc($downloadlink . "\n");
                     printc("</td></tr>");
                     printc("</table>");
                 }
             }
             $content = convertTagsToInteralLinks($_REQUEST[site], stripslashes($this->content));
             $wikiResolver =& WikiResolver::instance();
             $content = $wikiResolver->parseText($content, $_REQUEST[site], $_REQUEST[section], $_REQUEST[page]);
             printc("<div style='clear: both;'>\n");
             printc($content);
             printc("</div>\n");
             //printc ("- [ $c]</td></tr>\n");
             //printc ("<tr><td align='right'>$c</td></tr>\n");
         }
         // done
         // now check if we're replying to this post
         if ($_REQUEST['discuss'] == 'reply' && $_REQUEST['replyto'] == $this->id) {
             $this->_outputform('reply');
         }
         //if ($_REQUEST['discuss'] == 'rate' && $_REQUEST['replyto'] == $this->id) $this->_outputform('rate');
         printc("</td></tr>");
     }
 }
Exemple #9
0
function printContentItem($result, $type, &$siteObj, $search = "")
{
    global $_full_uri, $site_owner;
    $foundSection =& new section($_REQUEST[site], $result['section_id'], $siteObj);
    $foundPage =& new page($_REQUEST[site], $result['section_id'], $result['page_id'], $foundSection);
    $foundContent =& new story($_REQUEST[site], $result['section_id'], $result['page_id'], $result['story_id'], $foundPage);
    if ($foundSection->canview() && $foundPage->canview() && $foundContent->canview() || $_SESSION[auser] == $site_owner) {
        ob_start();
        print "\n\t<tr>";
        $record_tag_tstamp = timestamp2usdate($result[story_updated_tstamp]);
        //if ($record_tag_tstamp != '0000-00-00 00:00:00') {
        //$record_tag_tstamp =& TimeStamp::fromString($record_tag_tstamp);
        //$record_tag_time =& $record_tag_tstamp->asTime();
        //print "<td valign='top' class='listtext'>".$record_tag_tstamp->ymdString()."<br/>".$record_tag_time->string12(false)."</td>";
        //	print "<td valign='top' class='listtext'>".$record_tag_tstamp."</td>";
        print "\n\t\t<td valign='top'><a href='" . $_full_uri . "/index.php?&amp;action=site&amp;site=" . $_REQUEST[site];
        print "&amp;section=" . $result['section_id'];
        print "&amp;page=" . $result['page_id'];
        print "&amp;story=" . $result['story_id'];
        print "&amp;detail=" . $result['story_id'];
        if ($type == "discussion") {
            print "#" . $result['discussion_id'];
        }
        print "'>";
        print stripslashes(urldecode($result['section_title']));
        print " > " . stripslashes(urldecode($result['page_title']));
        if ($result['story_title']) {
            print " > " . stripslashes(urldecode($result['story_title']));
        }
        if ($result['discussion_subject']) {
            print " > " . stripslashes(urldecode($result['discussion_subject']));
            print " (" . $result['user_fname'] . ")";
        }
        print "</a>\n\t\t</td>";
        //	print "<tr><td valign='top' class='contentinfo'>added by".$result['user_fname']." on ".$record_tag_tstamp."</td>";
        print "\n\t</tr>";
        print "\n\t\t<tr>";
        print "\n\t\t\t<td class='list' valign='top'>";
        if ($type == "content") {
            $content = stripslashes(urldecode($result['story_text_short']));
            $content .= stripslashes(urldecode($result['story_text_long']));
        } else {
            if ($type == "discussion") {
                $content = stripslashes(urldecode($result['discussion_content']));
            }
        }
        $wikiResolver =& WikiResolver::instance();
        $content = $wikiResolver->parseText($content, $_REQUEST[site], $result['section_id'], $result['page_id']);
        $content = find_abstract($content, $search);
        if ($type != "page" && $type != "section") {
            print $content;
        }
        print "\n\t\t</td>";
        print "\n\t</tr>";
        //}
        $contentItem = ob_get_clean();
        printc($contentItem);
    }
}