Example #1
0
 public function url($data = null, $field = false, $options = array())
 {
     $options += array('style' => 'original', 'urlize' => true);
     list($model, $field) = explode('.', $field);
     if (is_array($data)) {
         if (isset($data[$model])) {
             if (isset($data[$model]['id'])) {
                 $id = $data[$model]['id'];
                 $filename = $data[$model][$field];
             }
         } elseif (isset($data['id'])) {
             $id = $data['id'];
             $filename = $data[$field];
         }
     }
     if (isset($id) && isset($filename)) {
         $paths = UploadBehavior::getPaths($model, $id, $field, $filename, $options['style'], array('webroot' => ''));
         $url = isset($paths['url']) ? $paths['url'] : $paths['path'];
     } else {
         $settings = Interpolation::run($model, null, $field, null, $options['style'], array('webroot' => ''));
         $url = isset($settings['default_url']) ? $settings['default_url'] : null;
     }
     return $options['urlize'] ? $this->Html->url($url) : $url;
 }
Example #2
0
 protected function interpolate(Model $Model, $field, $filename, $style)
 {
     $settings = $this->settings[$Model->alias][$field];
     $keys = array('path', 'url', 'default_url');
     foreach ($keys as $key) {
         if (isset($settings[$key])) {
             $settings[$key] = Interpolation::run($settings[$key], $Model->alias, $Model->id, $field, $filename, $style);
         }
     }
     return $settings;
 }