Esempio n. 1
0
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    Shawn Rice <*****@*****.**>
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access.
defined('_HZEXEC_') or die;
$page = \Components\Wiki\Models\Page::getInstance(Request::getVar('page'), Request::getVar('scope'));
$revision = $page->revision(Request::getInt('version', 0));
$yFormat = 'Y';
$apaFormat = 'Y, M d';
$apaFormatRetrieved = 'H:i, M d, Y';
$mlaFormat = 'd M. Y';
$mlaFormatRetrieved = 'd M. Y';
$mhraFormat = 'd M Y H:i';
$mhraFormatRetrieved = 'd M Y';
$cbeFormat = 'Y M d';
$bluebookFormat = 'M. d, Y';
$amaFormat = 'M d, Y, H:i';
$amaFormatRetrieved = 'M d, Y';
$now = Date::toSql();
$permalink = rtrim(Request::base(), '/') . '/' . ltrim(Route::url($page->link() . '&version=' . $revision->get('version')), DS);
?>
Esempio n. 2
0
 /**
  * Set and get a specific page
  *
  * @param   mixed  $id Integer or string of tag to look up
  * @return  object WikiModelPage
  */
 public function page($id = null, $scope = '')
 {
     $scope = $scope ? $scope : $this->_scope;
     $this->_cache['page'] = \Components\Wiki\Models\Page::getInstance($id, $scope);
     return $this->_cache['page'];
 }
Esempio n. 3
0
 /**
  * Display a page
  *
  * @return  void
  */
 public function displayTask()
 {
     $this->view->book = $this->book;
     $this->view->page = $this->page;
     $this->view->config = $this->config;
     $this->view->base_path = $this->_base_path;
     $this->view->sub = $this->_sub;
     // Prep the pagename for display
     $this->view->title = $this->page->get('title');
     //getTitle();
     // Set the page's <title> tag
     if ($this->_sub) {
         Document::setTitle(Document::getTitle() . ': ' . $this->view->title);
     } else {
         Document::setTitle(($this->_sub ? Lang::txt('COM_GROUPS') . ': ' : '') . Lang::txt('COM_WIKI') . ': ' . $this->view->title);
     }
     // Set the pathway
     if (Pathway::count() <= 0) {
         Pathway::append(Lang::txt(strtoupper($this->_name)), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller);
     }
     // Is this a special page?
     if ($this->page->get('namespace') == 'special') {
         // Set the layout
         $this->view->setLayout('special');
         $this->view->layout = $this->page->denamespaced();
         $this->view->page->set('scope', Request::getVar('scope', ''));
         $this->view->page->set('group_cn', $this->_group);
         $this->view->message = $this->_message;
         // Ensure the special page exists
         if (!in_array(strtolower($this->view->layout), $this->book->special())) {
             App::redirect(Route::url('index.php?option=' . $this->_option . '&scope=' . $this->view->page->get('scope')));
             return;
         }
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
         $this->view->display();
         return;
     }
     // Does a page exist for the given pagename?
     if (!$this->page->exists() || $this->page->isDeleted()) {
         if (!$this->page->access('create')) {
             App::abort(404, Lang::txt('COM_WIKI_WARNING_PAGE_DOES_NOT_EXIST'));
         }
         // No! Ask if they want to create a new page
         $this->view->setLayout('doesnotexist');
         if ($this->_group) {
             $this->page->set('group_cn', $this->_group);
             $this->page->set('scope', $this->_group . '/wiki');
         }
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
         $this->view->display();
         return;
     }
     if ($this->page->get('group_cn') && !$this->_group) {
         App::redirect(Route::url('index.php?option=com_groups&scope=' . $this->page->get('scope') . '&pagename=' . $this->page->get('pagename')));
         return;
     }
     // Check if the page is group restricted and the user is authorized
     if (!$this->page->access('view', 'page')) {
         throw new Exception(Lang::txt('COM_WIKI_WARNING_NOT_AUTH'), 403);
     }
     if ($scope = $this->page->get('scope')) {
         $s = array();
         if ($cn = $this->page->get('group_cn')) {
             $scope = substr($scope, strlen($cn . '/wiki'));
             $s[] = $cn;
             $s[] = 'wiki';
         }
         $scope = trim($scope, '/');
         if ($scope) {
             $bits = explode('/', $scope);
             foreach ($bits as $bit) {
                 $bit = trim($bit);
                 if ($bit != '/' && $bit != '') {
                     $p = Article::getInstance($bit, implode('/', $s));
                     if ($p->exists()) {
                         Pathway::append($p->get('title'), $p->link());
                     }
                     $s[] = $bit;
                 }
             }
         }
     }
     Pathway::append($this->view->title, $this->page->link());
     // Retrieve a specific version if given
     $this->view->version = Request::getInt('version', 0);
     $this->view->revision = $this->page->revision($this->view->version);
     if (!$this->view->revision->exists()) {
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
         $this->view->setLayout('nosuchrevision')->display();
         return;
     }
     if (Request::getVar('format', '') == 'raw') {
         Request::setVar('no_html', 1);
         echo nl2br($this->view->revision->get('pagetext'));
         return;
     } elseif (Request::getVar('format', '') == 'printable') {
         echo $this->view->revision->get('pagehtml');
         return;
     }
     // Load the wiki parser
     $wikiconfig = array('option' => $this->_option, 'scope' => $this->page->get('scope'), 'pagename' => $this->page->get('pagename'), 'pageid' => $this->page->get('id'), 'filepath' => '', 'domain' => $this->page->get('group_cn'));
     $p = Parser::getInstance();
     // Parse the text
     if (intval($this->book->config('cache', 1))) {
         // Caching
         if (!($rendered = Cache::get('wiki.r' . $this->view->revision->get('id')))) {
             $rendered = $p->parse($this->view->revision->get('pagetext'), $wikiconfig, true, true);
             Cache::put('wiki.r' . $this->view->revision->get('id'), $rendered, intval($this->book->config('cache_time', 15)));
         }
         $this->view->revision->set('pagehtml', $rendered);
     } else {
         $this->view->revision->set('pagehtml', $p->parse($this->view->revision->get('pagetext'), $wikiconfig, true, true));
     }
     App::get('config')->get('debug') || App::get('config')->get('profile') ? App::get('profiler')->mark('afterWikiParse') : null;
     // Handle display events
     $this->page->event = new \stdClass();
     $results = Event::trigger('wiki.onAfterDisplayTitle', array($this->page, &$this->view->revision, $this->config));
     $this->page->event->afterDisplayTitle = trim(implode("\n", $results));
     $results = Event::trigger('wiki.onBeforeDisplayContent', array(&$this->page, &$this->view->revision, $this->config));
     $this->page->event->beforeDisplayContent = trim(implode("\n", $results));
     $results = Event::trigger('wiki.onAfterDisplayContent', array(&$this->page, &$this->view->revision, $this->config));
     $this->page->event->afterDisplayContent = trim(implode("\n", $results));
     $this->view->message = $this->_message;
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->display();
 }
Esempio n. 4
0
 /**
  * Set and get a specific page
  *
  * @param   mixed  $id Integer or string of tag to look up
  * @return  object WikiModelPage
  */
 public function page($id = null)
 {
     if (!isset($this->_cache['page']) && $id === null) {
         $pagename = trim(Request::getVar('pagename', '', 'default', 'none', 2));
         if (substr(strtolower($pagename), 0, strlen('image:')) != 'image:' && substr(strtolower($pagename), 0, strlen('file:')) != 'file:') {
             $pagename = $this->_tbl->normalize($pagename);
         }
         Request::setVar('pagename', $pagename);
         $scope = Request::getVar('scope', '');
         if ($scope) {
             // Clean the scope. Since scope is built of a chain of pagenames or groups/groupname/wiki
             // the wiki normalize() should strip any nasty stuff out
             $bits = explode('/', $scope);
             foreach ($bits as $i => $bit) {
                 $bits[$i] = $this->_tbl->normalize($bit);
             }
             $scope = implode('/', $bits);
             Request::setVar('scope', $scope);
         }
         $task = trim(Request::getWord('task', ''));
         // No page name given! Default to the home page
         if (!$pagename && $task != 'new') {
             return $this->main();
         }
         // Load the page
         $this->_cache['page'] = new Page($pagename, $scope);
         if (!$this->_cache['page']->exists() && $this->_cache['page']->get('namespace') == 'help') {
             $this->_cache['page'] = new Page($pagename, '');
             $this->_cache['page']->set('scope', $scope);
             if ($this->_scope != '__site__') {
                 $this->_cache['page']->set('group', $this->_scope);
             }
         }
     }
     if (!isset($this->_cache['page']) || $id !== null && (int) $this->_cache['page']->get('id') != $id && (string) $this->_cache['page']->get('pagename') != $this->_tbl->normalize($id)) {
         $this->_cache['page'] = null;
         if (isset($this->_cache['pages']) && $this->_cache['pages'] instanceof ItemList) {
             foreach ($this->_cache['pages'] as $page) {
                 if ((int) $page->get('id') == $id || (string) $page->get('pagename') == $this->_tbl->normalize($id)) {
                     $this->_cache['page'] = $page;
                     break;
                 }
             }
         }
         if (!$this->_cache['page']) {
             $this->_cache['page'] = Page::getInstance($id, Request::getVar('scope', ''));
         }
     }
     return $this->_cache['page'];
 }