Example #1
0
 /**
  * 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)';
 }
Example #2
0
 /**
  * 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)';
 }