示例#1
0
 function process(&$matches)
 {
     $pageName = WDStringUtils::toUnixName(trim($matches[1]));
     // get page source (if exists)
     $runData = Ozone::getRunData();
     $site = $runData->getTemp("site");
     $page = DB_PagePeer::instance()->selectByName($site->getSiteId(), $pageName);
     if ($page == null) {
         //$output =  $this->wiki->addToken(
         //	$this->rule, array('fromIncludeRule' => true, 'type' => 'error', 'pageName' => $pageName)
         $output = "\n\n" . '[[div class="error-block"]]' . "\n" . sprintf(_('Page to be included %s can not be found!'), htmlspecialchars($pageName)) . "\n" . '[[/div]]' . "\n\n";
         $wiki = $this->wiki;
         if ($wiki->vars['inclusionsNotExist'] == null) {
             $wiki->vars['inclusionsNotExist'] = array();
         }
         $wiki->vars['inclusionsNotExist'][$pageName] = $pageName;
     } else {
         $output = $page->getSource();
         // prepare entry...
         $wiki = $this->wiki;
         if ($wiki->vars['inclusions'] == null) {
             $wiki->vars['inclusions'] = array();
         }
         $wiki->vars['inclusions'][$page->getPageId()] = $page->getPageId();
         // preprocess the output too!!!
         // missed a few rules so far... TODO!!!
         //process the output - make substitutions.
         $subs = $matches[2];
         if ($subs) {
             $subsArray = explode('|', $subs);
             foreach ($subsArray as $sub) {
                 if (strpos($sub, '=') !== false) {
                     $pos = strpos($sub, '=');
                     $var = trim(substr($sub, 0, $pos));
                     $value = trim(substr($sub, $pos + 1));
                     if ($value != '' && $var != '' && preg_match('/^[a-z0-9\\-\\_]+$/i', $var)) {
                         // substitute!!!
                         $output = str_replace('{$' . $var . '}', $value, $output);
                     }
                 }
             }
         }
     }
     // done, place the script output directly in the source
     return "\n\n" . $output . "\n\n";
 }
示例#2
0
 /**
  *
  * Renders a token into text matching the requested format.
  *
  * @access public
  *
  * @param array $options The "options" portion of the token (second
  * element).
  *
  * @return string The text rendered from the token options.
  *
  */
 function token($options)
 {
     $content = $options['content'];
     $hashcode = md5($content);
     $runData = Ozone::getRunData();
     $site = $runData->getTemp('site');
     $dir = $site->getLocalFilesPath() . '/math/inline';
     if (!file_exists($dir)) {
         mkdirfull($dir);
     }
     $tmpDir = WIKIDOT_ROOT . '/tmp/math';
     if (!file_exists($tmpDir)) {
         mkdirfull($tmpDir);
     }
     $imgFile = $hashcode . '.png';
     if (!file_exists($dir . '/' . $imgFile)) {
         $renderer = new LatexRenderer();
         $renderer->setTmpDir($tmpDir);
         $renderer->setOutputDir($dir);
         $renderer->setDensity(110);
         $content2 = '$' . $content . '$';
         $renderer->render($content2, $hashcode);
     }
     if (!file_exists($dir . '/' . $imgFile)) {
         return '<span class="error-inline">' . _('The equation has not been processed correctly. Most prabably it has syntax error(s).') . '	</span>';
     }
     $out = '<img class="math-inline" src="/local--math/inline/' . $imgFile . '" alt="' . htmlentities($content) . '" />';
     return $out;
     $content = $options['content'];
     $hashcode = md5($content);
     $runData = Ozone::getRunData();
     $site = $runData->getTemp('site');
     $dir = $site->getLocalFilesPath() . '/math/inline';
     if (!file_exists($dir)) {
         mkdirfull($dir);
     }
     $imgFile = $hashcode . '.png';
     $imgFile = $hashcode . '.png';
     $out = '<img src="http://' . $site->getDomain() . '/local--math/inline/' . $imgFile . '" alt="' . htmlentities($content) . '" />';
     return $out;
 }
示例#3
0
文件: Math.php 项目: jbzdak/wikidot
 /**
  *
  * Renders a token into text matching the requested format.
  *
  * @access public
  *
  * @param array $options The "options" portion of the token (second
  * element).
  *
  * @return string The text rendered from the token options.
  *
  */
 function token($options)
 {
     $content = $options['content'];
     $type = $options['type'];
     $hashcode = md5($content . '..' . $type);
     $runData = Ozone::getRunData();
     $site = $runData->getTemp('site');
     $dir = $site->getLocalFilesPath() . '/math/eqs';
     if (!file_exists($dir)) {
         mkdirfull($dir);
     }
     $tmpDir = WIKIDOT_ROOT . '/tmp/math';
     if (!file_exists($tmpDir)) {
         mkdirfull($tmpDir);
     }
     $imgFile = $hashcode . '.png';
     if (!file_exists($dir . '/' . $imgFile)) {
         $renderer = new LatexRenderer();
         $renderer->setTmpDir($tmpDir);
         $renderer->setOutputDir($dir);
         if ($type == 'eqnarray') {
             $content2 = "\\begin{eqnarray*}\n" . $content . "\n\\end{eqnarray*}";
         } else {
             $content2 = "\\begin{equation*}\n" . $content . "\n\\end{equation}";
         }
         $renderer->render($content2, $hashcode);
     }
     if (!file_exists($dir . '/' . $imgFile)) {
         return '<div class="error-block">' . _('The equation has not been processed correctly. Most prabably it has syntax error(s).') . '</div>';
     }
     $label = $options['label'];
     $idPrefix = $this->getConf("id_prefix");
     $idString = ' id="equation-' . $idPrefix . $options['id'] . '" ';
     $equationNumberLabel = '<span class="equation-number">(' . $options['id'] . ')</span>';
     $out = '<div class="math-equation"' . $idString . '><img src="/local--math/eqs/' . $imgFile . '" alt="' . htmlentities($content) . '" /></div>';
     return $equationNumberLabel . $out;
 }
示例#4
0
function wikiPageExists($pageName)
{
    if ($GLOBALS['site'] == null) {
        $runData = Ozone::getRunData();
        $siteId = $runData->getTemp("site")->getSiteId();
    } else {
        $siteId = $GLOBALS['site']->getSiteId();
    }
    $q = "SELECT page_id FROM page WHERE unix_name='" . db_escape_string($pageName) . "' AND site_id='" . db_escape_string($siteId) . "' LIMIT 1";
    $db = Database::connection();
    $r = $db->query($q);
    if ($row = $r->nextRow()) {
        return $row['page_id'];
    } else {
        return false;
    }
}
示例#5
0
 public function hasForumPermission($action, $user, $category, $thread = null, $post = null)
 {
     if ($user) {
         if (is_string($user) && is_numeric($user) || is_int($user)) {
             $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($user);
         }
     }
     if ($user && ($user->getSuperAdmin() || $user->getSuperModerator())) {
         return true;
     }
     $site = $GLOBALS['site'];
     // ugly.
     // ban by IP first.
     if ($this->checkIpBlocks) {
         $ips = Ozone::getRunData()->createIpString();
         $blocks = $this->checkIpBlocked($ips, $site);
         if (count($blocks) > 0) {
             if ($this->throwExceptions) {
                 throw new WDPermissionException(_("Sorry, your IP address is blocked from participating in and modifying this site."));
             } else {
                 return false;
             }
         }
     }
     if (strpos($action, "thread")) {
         $authorString = _("author of the thread");
     } else {
         $authorString = _("author of the post");
     }
     //action code
     $ac = self::$forumActions[$action];
     //permission string
     $ps = $category->getPermissionString();
     //throw new WDPermissionException($ps);
     // first try anonymous and registered to save effort
     $uc = self::$userClasses['anonymous'];
     if ($this->permissionLookup($ac, $uc, $ps)) {
         // ok, anyone can.
         // but check ip blocks.
         if ($this->checkUserBlocks && $user) {
             //if(!$user){
             //	$ips = Ozone::getRunData()->createIpString();
             //
             //	$blocks = $this->checkIpBlocked($ips, $site);
             //	if(count($blocks)>0){
             //
             //		if($this->throwExceptions){
             //			throw new WDPermissionException(_("Sorry, your IP address is blocked from participating in and modifying this site."));
             //		}else{
             //			return false;
             //		}
             //	}
             //}
             //if($user){
             $block = $this->checkUserBlocked($user, $site);
             if ($block) {
                 if ($this->throwExceptions) {
                     $message = _("Sorry, you are blocked from participating in and modifying this site. ");
                     if ($block->getReason() && $block->getReason() != '') {
                         $message .= _("The given reason is:") . " <p>" . htmlspecialchars($block->getReason()) . "</p>";
                     }
                     throw new WDPermissionException($message);
                     //throw new WDPermissionException("Sorry, you are blocked from participating in and modifying this site. " .
                     //		"The given reason is: \"".htmlspecialchars($block->getReason())."\"");
                 } else {
                     return false;
                 }
             }
             //}
         }
         return true;
     } elseif (!$user) {
         // anonymous can not and the user is only anonymous. game over.
         //	throw new WDPermissionException($ps);
         $m = $this->generateMessage($action, $uc, $ps, 'forum', array("o" => $authorString));
         $this->handleFalse($m);
         return false;
     }
     // ok, check registered now
     $uc = self::$userClasses['registered'];
     if ($this->permissionLookup($ac, $uc, $ps)) {
         // check blocked users
         if ($this->checkUserBlocks) {
             $block = $this->checkUserBlocked($user, $site);
             if ($block) {
                 if ($this->throwExceptions) {
                     $message = _("Sorry, you are blocked from participating in and modifying this site. ");
                     if ($block->getReason() && $block->getReason() != '') {
                         $message .= _("The given reason is:") . " <p>" . htmlspecialchars($block->getReason()) . "</p>";
                     }
                     throw new WDPermissionException($message);
                     //throw new WDPermissionException("Sorry, you are blocked from participating in and modifying this site. " .
                     //		"The given reason is: \"".htmlspecialchars($block->getReason())."\"");
                 } else {
                     return false;
                 }
             }
         }
         return true;
     }
     // ok, a "premium feature" or what... need to check members now...
     $uc = self::$userClasses['member'];
     if ($this->permissionLookup($ac, $uc, $ps)) {
         // ok, members CAN do this. is the user a member?
         $c = new Criteria();
         $c->add("site_id", $category->getSiteId());
         $c->add("user_id", $user->getUserId());
         $rel = DB_MemberPeer::instance()->selectOne($c);
         if ($rel) {
             return true;
         }
     }
     /*// still nothing. check if owner of the page
     		if($page && $page->getOwnerUserId() && $user->getUserId() == $page->getOwnerUserId()){
     			$uc = self::$userClasses['owner'];
     			if($this->permissionLookup($ac, $uc, $ps)){
     				return true;	
     			}
     		}*/
     $uc = self::$userClasses['owner'];
     if (($post || $thread) && $this->permissionLookup($ac, $uc, $ps)) {
         $o = $post ? $post : $thread;
         if ($o && $o->getUserId() && $user->getUserId() == $o->getUserId()) {
             // check blocked users
             if ($this->checkUserBlocks) {
                 $block = $this->checkUserBlocked($user, $site);
                 if ($block) {
                     if ($this->throwExceptions) {
                         $message = _("Sorry, you are blocked from participating in and modifying this site. ");
                         if ($block->getReason() && $block->getReason() != '') {
                             $message .= _("The given reason is:") . " <p>" . htmlspecialchars($block->getReason()) . "</p>";
                         }
                         throw new WDPermissionException($message);
                         //throw new WDPermissionException("Sorry, you are blocked from participating in and modifying this site. " .
                         //		"The given reason is: \"".htmlspecialchars($block->getReason())."\"");
                     } else {
                         return false;
                     }
                 }
             }
             return true;
         }
     }
     // still nothing. check if moderator of "forum".
     $c = new Criteria();
     $c->add("site_id", $category->getSiteId());
     $c->add("user_id", $user->getUserId());
     $rel = DB_ModeratorPeer::instance()->selectOne($c);
     if ($rel && strpos($rel->getPermissions(), 'f') !== false) {
         return true;
     }
     // still nothing. check if admin.
     $c = new Criteria();
     $c->add("site_id", $category->getSiteId());
     $c->add("user_id", $user->getUserId());
     $rel = DB_AdminPeer::instance()->selectOne($c);
     if ($rel) {
         return true;
     }
     $m = $this->generateMessage($action, $uc, $ps, 'forum', array("o" => $authorString));
     $this->handleFalse($m);
     return false;
 }