/** * 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)'; }
/** * Delete a file in the wiki * * @return void */ public function deletefileTask() { // Check if they're logged in if (User::isGuest()) { return $this->displayTask(); } // Incoming $listdir = Request::getInt('listdir', 0, 'get'); if (!$listdir) { $this->setError(Lang::txt('COM_WIKI_NO_ID')); return $this->displayTask(); } // Incoming file $file = trim(Request::getVar('file', '', 'get')); if (!$file) { $this->setError(Lang::txt('COM_WIKI_NO_FILE')); return $this->displayTask(); } $attachment = Attachment::oneByFilename($file, $listdir); // Delete the file if (!$attachment || !$attachment->get('id')) { // No database record for some reason // Set some data so the model can still remove the file $attachment->set('page_id', $listdir); $attachment->set('filename', $file); } // Attempt to delete the file // Delete the database entry for the file if (!$attachment->destroy()) { $this->setError($attachment->getError()); } // Push through to the media view if (Request::getVar('no_html', 0)) { return $this->listTask(); } $this->displayTask(); }