Example #1
0
 /**
  * Generate macro output
  *
  * @return     string
  */
 public function render()
 {
     $et = $this->args;
     $sort = '';
     if ($et) {
         $et = strip_tags($et);
         if (strstr($et, ',')) {
             $attribs = explode(',', $et);
             $et = trim($attribs[0]);
             $sort = strtolower(trim($attribs[1]));
         }
         if (strtolower($et) == 'sort=modified' || strtolower($et) == 'sort=created' || strtolower($et) == 'sort=title') {
             $sort = $et;
             $et = '';
         }
     }
     $pages = \Components\Wiki\Models\Page::all()->whereEquals('state', 1);
     if ($et) {
         $pages->whereLike('pagename', strtolower($et) . '%');
     }
     if ($this->domain && substr(strtolower($et), 0, 4) != 'help') {
         $pages->whereEquals('scope', $this->domain);
         $pages->whereEquals('scope_id', $this->domain_id);
     }
     switch ($sort) {
         case 'sort=created':
             $pages->order('created', 'asc');
             break;
         case 'sort=modified':
             $pages->order('modified', 'asc');
             break;
         case 'sort=title':
         default:
             $pages->order('title', 'asc');
             break;
     }
     $rows = $pages->rows();
     // Did we get a result from the database?
     if ($rows) {
         // Build and return the link
         $html = '<ul>';
         foreach ($rows as $row) {
             if ($row->get('pagename') == $this->pagename) {
                 continue;
             }
             if ($row->get('namespace') == 'Help') {
                 $row->set('path', $row->get('path') ? rtrim($this->scope, '/') . '/' . ltrim($row->get('path'), '/') : $this->scope);
                 $row->set('scope', $this->domain);
                 $row->set('scope_id', $this->domain_id);
             }
             $html .= '<li><a href="' . Route::url($row->link()) . '">';
             $html .= stripslashes($row->get('title', $row->get('pagename')));
             $html .= '</a></li>' . "\n";
         }
         $html .= '</ul>';
         return $html;
     }
     // Return error message
     return '(No ' . $et . ' pages to display)';
 }
Example #2
0
 /**
  * Pull a list of records that were created within the time frame ($period)
  *
  * @param      object  $period     Time period to pull results for
  * @param      mixed   $limit      Number of records to pull
  * @param      integer $limitstart Start of records to pull
  * @param      array   $areas      Active area(s)
  * @param      array   $tagids     Array of tag IDs
  * @return     array
  */
 public function onWhatsnew($period, $limit = 0, $limitstart = 0, $areas = null, $tagids = array())
 {
     if (is_array($areas) && $limit) {
         if (!isset($areas[$this->_name]) && !in_array($this->_name, $areas)) {
             return array();
         }
     }
     // Do we have a time period?
     if (!is_object($period)) {
         return array();
     }
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php';
     if (!$limit) {
         return \Components\Wiki\Models\Page::all()->whereEquals('state', \Components\Wiki\Models\Page::STATE_PUBLISHED)->where('created', '>=', $period->cStartDate)->where('created', '<', $period->cEndDate)->order('created', 'desc')->count();
     } else {
         $pages = \Components\Wiki\Models\Page::all()->whereEquals('state', \Components\Wiki\Models\Page::STATE_PUBLISHED)->order('created', 'desc')->where('created', '>=', $period->cStartDate)->where('created', '<', $period->cEndDate)->limit($limit)->start($limitstart)->rows();
         $rows = array();
         foreach ($pages as $page) {
             $row = new stdClass();
             $row->title = $page->title;
             $row->href = Route::url($page->link());
             $row->text = strip_tags($page->version->get('pagehtml'));
             $row->category = $page->get('scope');
             $row->section = $this->_name;
             $rows[] = $row;
         }
         return $rows;
     }
 }
Example #3
0
 /**
  * Generate macro output
  *
  * @return  string
  */
 public function render()
 {
     $limit = 1;
     $cls = '';
     $limitstart = 0;
     if ($this->args) {
         $args = explode(',', $this->args);
         if (isset($args[0])) {
             $args[0] = intval($args[0]);
             if ($args[0]) {
                 $limit = $args[0];
             }
         }
         if (isset($args[1])) {
             $cls = $args[1];
         }
         if (isset($args[2])) {
             $args[2] = intval($args[2]);
             if ($args[2]) {
                 $limitstart = $args[2];
             }
         }
     }
     $pages = \Components\Wiki\Models\Page::all()->whereEquals('state', \Components\Wiki\Models\Page::STATE_PUBLISHED)->order('modified', 'desc')->limit($limit)->start($limitstart);
     if ($this->domain) {
         $pages->whereEquals('scope', $this->domain);
         $pages->whereEquals('scope_id', $this->domain_id);
     }
     $rows = $pages->rows();
     $html = '';
     // Did we get a result from the database?
     if ($rows) {
         foreach ($rows as $row) {
             $txt = strip_tags($row->version->get('pagehtml'));
             $txt = str_replace(array("\n", "\r", "\t", '   '), ' ', $txt);
             $txt = trim($txt);
             $html .= '<div';
             if ($cls) {
                 $html .= ' class="' . $cls . '"';
             }
             $html .= '>' . "\n";
             $html .= "\t" . '<h3><a href="' . Route::url($row->link()) . '">' . stripslashes($row->title) . '</a></h3>' . "\n";
             $html .= "\t" . '<p class="modified-date">';
             if ($row->get('version') > 1) {
                 $html .= Lang::txt('PLG_WIKI_PARSERDEFAULT_MODIFIED_ON', Date::of($row->get('created'))->toLocal(Lang::txt('DATE_FORMAT_HZ1')));
             } else {
                 $html .= Lang::txt('PLG_WIKI_PARSERDEFAULT_CREATED_ON', Date::of($row->get('created'))->toLocal(Lang::txt('DATE_FORMAT_HZ1')));
             }
             $html .= '</p>' . "\n";
             $html .= '<p>' . \Hubzero\Utility\String::truncate($txt, 300) . '</p>' . "\n";
             $html .= "\t" . '<p><a href="' . Route::url($row->link()) . '">' . Lang::txt('PLG_WIKI_PARSERDEFAULT_READ_MORE') . '</a></p>' . "\n";
             $html .= '</div>' . "\n";
         }
     } else {
         $html .= '<p class="warning">' . Lang::txt('PLG_WIKI_PARSERDEFAULT_NO_RESULTS') . '</p>' . "\n";
     }
     return $html;
 }
Example #4
0
 /**
  * Display all pages in the wiki(s)
  *
  * @return  void
  */
 public function displayTask()
 {
     $filters = array('sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'id'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'), 'search' => Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', ''), 'namespace' => Request::getState($this->_option . '.' . $this->_controller . '.namespace', 'namespace', ''), 'scope' => Request::getState($this->_option . '.' . $this->_controller . '.scope', 'scope', ''), 'state' => Request::getState($this->_option . '.' . $this->_controller . '.state', 'state', -1, 'int'), 'access' => Request::getState($this->_option . '.' . $this->_controller . '.access', 'access', 0, 'int'));
     $scopes = Page::all()->select('scope')->select('scope_id')->group('scope, scope_id')->rows();
     $namespaces = Page::all()->select('namespace')->group('namespace')->order('namespace', 'asc')->rows();
     $results = Page::all()->including(['versions', function ($version) {
         $version->select('id')->select('page_id');
     }])->including(['comments', function ($comment) {
         $comment->select('id')->select('page_id');
     }]);
     if ($filters['scope']) {
         if (strstr($filters['scope'], ':')) {
             $bits = explode(':', $filters['scope']);
             $filters['scope'] = $bits[0];
             $filters['scope_id'] = $bits[1];
         }
         $results->whereEquals('scope', $filters['scope']);
         $filters['scope'] .= ':' . $filters['scope_id'];
     }
     if (isset($filters['scope_id'])) {
         $results->whereEquals('scope_id', (int) $filters['scope_id']);
     }
     if ($filters['namespace']) {
         $results->whereEquals('namespace', $filters['namespace']);
     }
     if ($filters['access'] > 0) {
         $results->whereEquals('access', $filters['access']);
     }
     if ($filters['state'] >= 0) {
         $results->whereEquals('state', $filters['state']);
     }
     if ($filters['search']) {
         $filters['search'] = strtolower((string) $filters['search']);
         $results->whereLike('title', $filters['search']);
     }
     // Get records
     $rows = $results->ordered('filter_order', 'filter_order_Dir')->paginated('limitstart', 'limit')->rows();
     // Output the HTML
     $this->view->set('rows', $rows)->set('filters', $filters)->set('scopes', $scopes)->set('namespaces', $namespaces)->display();
 }
Example #5
0
 /**
  * Get a list of page IDs associated with this group
  *
  * @param   integer  $gid
  * @return  array
  */
 public function getPages($gid = NULL)
 {
     // Import needed libraries
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php';
     // Start the log text
     $log = Lang::txt('PLG_GROUPS_WIKI_LOG') . ': ';
     $pages = \Components\Wiki\Models\Page::all()->whereEquals('scope', 'group')->whereEquals('scope_id', $gid)->rows();
     return $pages;
 }
Example #6
0
 /**
  * List children of a page
  *
  * @param   integer  $currentDepth  How far down the tree we are
  * @param   integer  $targetDepth   How far down the tree to go
  * @param   integer  $pageid
  * @return  string   HMTL
  */
 private function listChildren($currentDepth, $targetDepth, $pageid)
 {
     $html = '';
     if ($currentDepth > $targetDepth) {
         return $html;
     }
     $rows = \Components\Wiki\Models\Page::all()->whereEquals('parent', $pageid)->whereEquals('state', 1)->rows();
     if ($rows->count()) {
         $html = '<ul>';
         foreach ($rows as $row) {
             $row = new \Components\Wiki\Models\Page($row);
             $html .= '<li><a href="' . Route::url($row->link()) . '">';
             $html .= stripslashes($row->get('title', $row->get('pagename')));
             $html .= '</a>';
             $html .= $this->listChildren($currentDepth + 1, $targetDepth, $row->get('id'));
             $html .= '</li>' . "\n";
         }
         $html .= '</ul>';
     } elseif ($currentDepth == 1) {
         // Return error message
         return '<p>(No sub-pages to display)</p>';
     }
     return $html;
 }
Example #7
0
 /**
  * Generate macro output
  *
  * @return  string
  */
 public function render()
 {
     $row = \Components\Wiki\Models\Page::all()->whereEquals('scope', $this->domain)->whereEquals('scope_id', $this->domain_id)->whereEquals('state', \Components\Wiki\Models\Page::STATE_PUBLISHED)->order('rand()')->row();
     // Build and return the link
     return '<a href="' . Route::url($row->link()) . '">' . $row->title . '</a>';
 }
Example #8
0
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access.
defined('_HZEXEC_') or die;
Pathway::append(Lang::txt('COM_WIKI_SPECIAL_ALL_PAGES'), $this->page->link());
$dir = strtoupper(Request::getVar('dir', 'ASC'));
if (!in_array($dir, array('ASC', 'DESC'))) {
    $dir = 'ASC';
}
$filters = array('state' => \Components\Wiki\Models\Page::STATE_PUBLISHED);
$namespace = urldecode(Request::getVar('namespace', ''));
if ($namespace) {
    $filters['namespace'] = $namespace;
}
$rows = $this->book->pages($filters)->order('title', $dir)->ordered()->rows();
$namespaces = \Components\Wiki\Models\Page::all()->select('namespace')->whereEquals('state', \Components\Wiki\Models\Page::STATE_PUBLISHED)->whereEquals('scope', $this->book->get('scope'))->whereEquals('scope_id', $this->book->get('scope_id'))->group('namespace')->order('namespace', 'asc')->rows();
?>
<form method="get" action="<?php 
echo Route::url($this->page->link());
?>
">
	<fieldset class="filters">
		<legend><?php 
echo Lang::txt('COM_WIKI_FILTER_LIST');
?>
</legend>

		<label for="field-namespace">
			<?php 
echo Lang::txt('COM_WIKI_FIELD_NAMESPACE');
?>
Example #9
0
 /**
  * Return either a count or an array of the member's contributions
  *
  * @param   object   $member      Current member
  * @param   string   $option      Component name
  * @param   string   $authorized  Authorization level
  * @param   integer  $limit       Number of record to return
  * @param   integer  $limitstart  Record return start
  * @param   string   $sort        Field to sort records on
  * @param   array    $areas       Areas to return data for
  * @return  array
  */
 public function onMembersContributions($member, $option, $limit = 0, $limitstart = 0, $sort, $areas = null)
 {
     if (is_array($areas) && $limit) {
         if (!isset($areas[$this->_name]) && !in_array($this->_name, $areas) && !array_intersect($areas, array_keys($this->onMembersContributionsAreas()))) {
             return array();
         }
     }
     // Do we have a member ID?
     if ($member instanceof \Hubzero\User\User) {
         if (!$member->get('id')) {
             return array();
         } else {
             $uidNumber = $member->get('id');
             $username = $member->get('username');
         }
     } else {
         if (!$member->uidNumber) {
             return array();
         } else {
             $uidNumber = $member->uidNumber;
             $username = $member->username;
         }
     }
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php';
     $versions = \Components\Wiki\Models\Version::all()->whereEquals('created_by', $uidNumber)->whereEquals('approved', 1)->group('page_id')->rows();
     $ids = array();
     foreach ($versions as $version) {
         $ids[] = $version->get('page_id');
     }
     $rows = \Components\Wiki\Models\Page::all()->whereEquals('state', \Components\Wiki\Models\Page::STATE_PUBLISHED)->whereEquals('scope', 'site')->whereIn('id', $ids)->limit($limit)->start($limitstart);
     if (!$limit) {
         return $rows->count();
     } else {
         return $rows->rows();
     }
 }
Example #10
0
 /**
  * Save the new page name
  *
  * @return  void
  */
 public function saverenameTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Check if they are logged in
     if (User::isGuest()) {
         $url = Request::getVar('REQUEST_URI', '', 'server');
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($url), false));
     }
     // Incoming
     $oldpagename = trim(Request::getVar('oldpagename', '', 'post'));
     $newpagename = trim(Request::getVar('newpagename', '', 'post'));
     // Load the page
     $this->page = Page::oneByPath($oldpagename, $this->book->get('scope'), $this->book->get('scope_id'));
     $newpagename = $this->page->normalize($newpagename);
     // Are they just changing case of characters?
     if (strtolower($this->page->get('pagename')) == strtolower($newpagename)) {
         $this->setError(Lang::txt('New name matches old name.'));
         return $this->renameTask();
     }
     // Check that no other pages are using the new title
     $p = Page::oneByPath($newpagename, $this->page->get('scope'), $this->page->get('scope_id'));
     if ($p->exists()) {
         $this->setError(Lang::txt('COM_WIKI_ERROR_PAGE_EXIST') . ' ' . Lang::txt('CHOOSE_ANOTHER_PAGENAME'));
         return $this->renameTask();
     }
     $this->page->set('pagename', $newpagename);
     if (!$this->page->save()) {
         $this->setError($this->page->getError());
         return $this->renameTask();
     }
     $pages = Page::all()->whereEquals('parent', $this->page->get('id'))->rows();
     foreach ($pages as $page) {
         $page->save();
     }
     $this->page->log('page_renamed');
     // Log activity
     $recipients = array(['wiki.site', 1], ['user', $this->page->get('created_by')]);
     if ($this->page->get('scope') != 'site') {
         $recipients[] = [$this->page->get('scope'), $this->page->get('scope_id')];
         $recipients[0] = ['wiki.' . $this->page->get('scope'), $this->page->get('scope_id')];
     }
     Event::trigger('system.logActivity', ['activity' => ['action' => 'updated', 'scope' => 'wiki.page', 'scope_id' => $this->page->get('id'), 'description' => Lang::txt('COM_WIKI_ACTIVITY_PAGE_RENAMED', '<a href="' . Route::url($this->page->link()) . '">' . $this->page->get('title') . '</a>'), 'details' => array('title' => $this->page->get('title'), 'url' => Route::url($this->page->link()), 'name' => $this->page->get('pagename'))], 'recipients' => $recipients]);
     // Redirect to the newly named page
     App::redirect(Route::url($this->page->link()));
 }