/** * Generate macro output * * @return string */ public function render() { $et = $this->args; $live_site = rtrim(Request::base(), '/'); // Get resource by ID $attach = \Components\Wiki\Models\Attachment::all()->whereEquals('page_id', $this->pageid); if ($et) { $et = strip_tags($et); $attach->whereLike('filename', strtolower($et) . '%'); } $rows = $attach->rows(); // Did we get a result from the database? if ($rows) { $config = Component::params('com_wiki'); if ($this->filepath != '') { $config->set('filepath', $this->filepath); } $page = \Components\Wiki\Models\Page::oneOrFail($this->pageid); if ($page->get('namespace') == 'help') { $page->set('path', $page->get('path') ? rtrim($this->scope, '/') . '/' . ltrim($page->get('path'), '/') : $this->scope); } // Build and return the link $html = '<ul>'; foreach ($rows as $row) { $page->set('pagename', $page->get('pagename') . '/' . 'File:' . $row->get('filename')); $link = $page->link(); $fpath = $row->filespace() . DS . $this->pageid . DS . $row->get('filename'); $html .= '<li><a href="' . Route::url($link) . '">' . $row->get('filename') . '</a> (' . (file_exists($fpath) ? \Hubzero\Utility\Number::formatBytes(filesize($fpath)) : '-- file not found --') . ') '; $huser = $row->creator(); if ($huser->get('id')) { $html .= '- added by <a href="' . Route::url('index.php?option=com_members&id=' . $huser->get('id')) . '">' . stripslashes($huser->get('name')) . '</a> '; } if ($row->get('created') && $row->get('created') != '0000-00-00 00:00:00') { $html .= Date::of($row->get('created'))->relative() . '. '; } $html .= $row->get('description') ? '<span>"' . stripslashes($row->get('description')) . '"</span>' : ''; $html .= '</li>' . "\n"; } $html .= '</ul>'; return $html; } // Return error message return '(No ' . $et . ' files to display)'; }
*/ // No direct access. defined('_HZEXEC_') or die; Pathway::append(Lang::txt('COM_WIKI_SPECIAL_FILE_LIST'), $this->page->link()); $database = App::get('db'); $sort = strtolower(Request::getVar('sort', 'created')); if (!in_array($sort, array('created', 'filename', 'description', 'created_by'))) { $sort = 'created'; } $dir = strtoupper(Request::getVar('dir', 'DESC')); if (!in_array($dir, array('ASC', 'DESC'))) { $dir = 'DESC'; } $pages = \Components\Wiki\Models\Page::blank()->getTableName(); $attach = \Components\Wiki\Models\Attachment::blank()->getTableName(); $rows = \Components\Wiki\Models\Attachment::all()->select($attach . '.*')->select($pages . '.pagename')->select($pages . '.path')->select($pages . '.scope')->select($pages . '.scope_id')->join($pages, $pages . '.id', $attach . '.page_id')->whereEquals($pages . '.scope', $this->book->get('scope'))->whereEquals($pages . '.scope_id', $this->book->get('scope_id'))->paginated()->rows(); $altdir = $dir == 'ASC' ? 'DESC' : 'ASC'; ?> <form method="get" action="<?php echo Route::url($this->page->link()); ?> "> <p> <?php echo Lang::txt('COM_WIKI_SPECIAL_FILE_LIST_ABOUT'); ?> </p> <div class="container"> <table class="file entries"> <thead> <tr>
/** * Generate macro output based on passed arguments * * @return string HTML image tag on success or error message on failure */ public function render() { $content = $this->args; // args will be null if the macro is called without parenthesis. if (!$content) { return ''; } // Parse arguments // We expect the 1st argument to be a filename $args = explode(',', $content); $file = array_shift($args); $this->attr = array(); $this->attr['href'] = ''; $this->attr['style'] = array(); // Get single attributes // EX: [[Image(myimage.png, nolink, right)]] $argues = preg_replace_callback('/[, ](left|right|top|center|bottom|[0-9]+(px|%|em)?)(?:[, ]|$)/i', array(&$this, 'parseSingleAttribute'), $content); // Get quoted attribute/value pairs // EX: [[Image(myimage.png, desc="My description, contains, commas")]] $argues = preg_replace_callback('/[, ](alt|altimage|desc|title|width|height|align|border|longdesc|class|id|usemap|link)=(?:["\'])([^"]*)(?:["\'])/i', array(&$this, 'parseAttributeValuePair'), $content); // Get non-quoted attribute/value pairs // EX: [[Image(myimage.png, width=100)]] $argues = preg_replace_callback('/[, ](alt|altimage|desc|title|width|height|align|border|longdesc|class|id|usemap|link)=([^"\',]*)(?:[, ]|$)/i', array(&$this, 'parseAttributeValuePair'), $content); $attr = $this->attr; // Get wiki config $this->config = Component::params('com_wiki'); if ($this->filepath != '') { $this->config->set('filepath', $this->filepath); } $imgs = explode(',', $this->config->get('img_ext', 'jpg, jpeg, jpe, gif, png')); $imgs = array_map('trim', $imgs); $imgs = array_map('strtolower', $imgs); $this->imgs = $imgs; $ret = false; // Is it numeric? if (is_numeric($file)) { // Get resource by ID $attach = \Components\Wiki\Models\Attachment::oneOrNew(intval($file)); // Check for file existence if ($attach->get('filename') && file_exists($this->_path($attach->get('filename'))) || file_exists($this->_path($attach->get('filename'), true))) { $attr['desc'] = isset($attr['desc']) ? $attr['desc'] : ''; if (!$attr['desc']) { $attr['desc'] = $attach->get('description', ''); } $ret = true; } } else { if (preg_match("/^(https?:|mailto:|ftp:|gopher:|news:|file:)/", $file)) { $attr['desc'] = $file; $ret = true; } else { if (file_exists($this->_path($file)) || file_exists($this->_path($file, true))) { $attr['desc'] = isset($attr['desc']) ? $attr['desc'] : ''; $ret = true; } } } // Does the file exist? if ($ret) { if (!in_array(strtolower(Filesystem::extension($file)), $this->imgs)) { return '(Image(' . $content . ') failed - File provided is not an allowed image type)'; } // Return HTML return $this->_embed($file, $attr); } // Return error message return '(Image(' . $content . ') failed - File not found)'; }
/** * Generate macro output based on passed arguments * * @return string */ public function render() { $content = $this->args; // args will be null if the macro is called without parenthesis. if (!$content) { return ''; } // Parse arguments // We expect the 1st argument to be a filename $args = explode(',', $content); $file = array_shift($args); $this->attr = array(); $this->attr['href'] = ''; $this->attr['style'] = array(); $this->attr['details'] = true; // Get single attributes // EX: [[Image(myimage.png, nolink, right)]] $argues = preg_replace_callback('/[, ](left|right|top|center|bottom|nodetails|[0-9]+(px|%|em)?)(?:[, ]|$)/i', array(&$this, 'parseSingleAttribute'), $content); // Get quoted attribute/value pairs // EX: [[Image(myimage.png, desc="My description, contains, commas")]] $argues = preg_replace_callback('/[, ](alt|altimage|althref|desc|title|width|height|align|border|longdesc|class|id|usemap|link|rel|details)=(?:["\'])([^"\']*)(?:["\'])/i', array(&$this, 'parseAttributeValuePair'), $content); // Get non-quoted attribute/value pairs // EX: [[Image(myimage.png, width=100)]] $argues = preg_replace_callback('/[, ](alt|altimage|althref|desc|title|width|height|align|border|longdesc|class|id|usemap|link|rel|details)=([^"\',]*)(?:[, ]|$)/i', array(&$this, 'parseAttributeValuePair'), $content); $attr = $this->attr; // Get wiki config $this->config = Component::params('com_wiki'); if ($this->filepath != '') { $this->config->set('filepath', $this->filepath); } $imgs = explode(',', $this->config->get('img_ext', 'jpg, jpeg, jpe, gif, png')); $imgs = array_map('trim', $imgs); $imgs = array_map('strtolower', $imgs); $this->imgs = $imgs; $ret = false; // Is it numeric? if (is_numeric($file)) { include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'attachment.php'; // Get resource by ID $attach = \Components\Wiki\Models\Attachment::oneOrNew(intval($file)); // Check for file existence if ($attach->get('filename') && file_exists($this->_path($attach->get('filename'))) || file_exists($this->_path($attach->get('filename'), true))) { $attr['desc'] = isset($attr['desc']) ? $attr['desc'] : ''; if (!$attr['desc']) { $attr['desc'] = $attach->get('description', ''); } $attr['created'] = $attach->get('created'); $attr['created_by'] = $attach->get('created_by'); $ret = true; } } else { if (file_exists($this->_path($file)) || file_exists($this->_path($file, true))) { include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'attachment.php'; // Get resource by ID $attach = \Components\Wiki\Models\Attachment::oneByFilename($file, $this->pageid); if ($attach->get('filename')) { $attr['created'] = $attach->get('created'); $attr['created_by'] = $attach->get('created_by'); } $attr['desc'] = isset($attr['desc']) ? $attr['desc'] : $file; $ret = true; } } // Does the file exist? if ($ret) { // Return HTML return $this->_embed($file, $attr); } // Return error message return '(file:' . $file . ' not found)'; }
/** * Display a list of files * * @return void */ public function listTask() { // Incoming $listdir = Request::getInt('listdir', 0, 'get'); if (!$listdir) { $this->setError(Lang::txt('COM_WIKI_NO_ID')); } $attachment = Attachment::blank(); $path = $attachment->filespace() . DS . $listdir; $folders = array(); $docs = array(); if (is_dir($path)) { // Loop through all files and separate them into arrays of images, folders, and other $dirIterator = new \DirectoryIterator($path); foreach ($dirIterator as $file) { if ($file->isDot()) { continue; } if ($file->isDir()) { $name = $file->getFilename(); $folders[$path . DS . $name] = $name; continue; } if ($file->isFile()) { $name = $file->getFilename(); if ('cvs' == strtolower($name) || '.svn' == strtolower($name)) { continue; } $docs[$path . DS . $name] = $name; } } ksort($folders); ksort($docs); } $this->view->set('docs', $docs)->set('folders', $folders)->set('config', $this->config)->set('listdir', $listdir)->set('sub', $this->page->get('scope') != 'site')->setErrors($this->getErrors())->setLayout('list')->display(); }
/** * Save a wiki page * * @return void */ public function saveTask() { // 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 revision $revision = $this->page->version; $revision->set('version', $revision->get('version') + 1); $revision->set(Request::getVar('revision', array(), 'post', 'none', 2)); $revision->set('id', 0); // Incoming page $page = Request::getVar('page', array(), 'post', 'none', 2); if (!isset($page['protected']) || !$page['protected']) { $page['protected'] = 0; } $this->page = Page::oneOrNew(intval($revision->get('page_id'))); $this->page->set($page); $this->page->set('pagename', trim(Request::getVar('pagename', '', 'post'))); // Get parameters $params = new \Hubzero\Config\Registry($this->page->get('params', '')); $params->merge(Request::getVar('params', array(), 'post')); $this->page->set('params', $params->toString()); // Get the previous version to compare against if (!$revision->get('page_id')) { // New page - save it to the database $this->page->set('created_by', User::get('id')); $old = Version::blank(); } else { // Get the revision before changes $old = $this->page->version; } // Was the preview button pushed? $this->preview = trim(Request::getVar('preview', '')); if ($this->preview) { // Set the component task if (!$page['id']) { Request::setVar('task', 'new'); $this->_task = 'new'; } else { Request::setVar('task', 'edit'); $this->_task = 'edit'; } // Push on through to the edit form return $this->editTask($revision); } // Check content // First, make sure the pagetext isn't empty if ($revision->get('pagetext') == '') { $this->setError(Lang::txt('COM_WIKI_ERROR_MISSING_PAGETEXT')); return $this->editTask($revision); } // Store new content if (!$this->page->save()) { $this->setError($this->page->getError()); return $this->editTask($revision); } // Get allowed authors if (!Author::setForPage(Request::getVar('authors', '', 'post'), $this->page->get('id'))) { $this->setError(Lang::txt('COM_WIKI_ERROR_SAVING_AUTHORS')); return $this->editTask($revision); } // Get the upload path $path = Attachment::blank()->filespace(); // Rename the temporary upload directory if it exist $lid = Request::getInt('lid', 0, 'post'); if ($lid != $this->page->get('id')) { if (is_dir($path . DS . $lid)) { if (!\Filesystem::move($path . DS . $lid, $path . DS . $this->page->get('id'))) { $this->setError(\Filesystem::move($path . DS . $lid, $path . DS . $this->page->get('id'))); } } foreach (Attachment::all()->whereEquals('page_id', $lid)->rows() as $attachment) { $attachment->set('page_id', $this->page->get('id')); if (!$attachment->save()) { $this->setError($attachment->getError()); } } } $revision->set('page_id', $this->page->get('id')); $revision->set('version', $revision->get('version') + 1); if ($this->page->param('mode', 'wiki') == 'knol') { // Set revisions to NOT approved $revision->set('approved', 0); // If an author or the original page creator, set to approved if ($this->page->get('created_by') == User::get('id') || $this->page->isAuthor(User::get('id'))) { $revision->set('approved', 1); } } else { // Wiki mode, approve revision $revision->set('approved', 1); } // Compare against previous revision // We don't want to create a whole new revision if just the tags were changed if (rtrim($old->get('pagetext')) != rtrim($revision->get('pagetext'))) { // Transform the wikitext to HTML $revision->set('pagehtml', ''); $revision->set('pagehtml', $revision->content($this->page)); if ($this->page->access('manage') || $this->page->access('edit')) { $revision->set('approved', 1); } // Store content if (!$revision->save()) { $this->setError(Lang::txt('COM_WIKI_ERROR_SAVING_REVISION')); return $this->editTask($revision); } $this->page->set('version_id', $revision->get('id')); $this->page->set('modified', $revision->get('created')); } else { $this->page->set('modified', Date::toSql()); } if (!$this->page->save()) { // This really shouldn't happen. $this->setError(Lang::txt('COM_WIKI_ERROR_SAVING_PAGE')); return $this->editTask($revision); } // Process tags $this->page->tag(Request::getVar('tags', '')); // Log activity $recipients = array(['wiki.site', 1], ['user', $this->page->get('created_by')], ['user', $revision->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' => $page['id'] ? 'updated' : 'created', 'scope' => 'wiki.page', 'scope_id' => $this->page->get('id'), 'description' => Lang::txt('COM_WIKI_ACTIVITY_PAGE_' . ($page['id'] ? 'UPDATED' : 'CREATED'), '<a href="' . Route::url($this->page->link()) . '">' . $this->page->title . '</a>'), 'details' => array('title' => $this->page->title, 'url' => Route::url($this->page->link()), 'name' => $this->page->get('pagename'), 'revision' => $revision->get('id'))], 'recipients' => $recipients]); // Redirect App::redirect(Route::url($this->page->link())); }