Changeset 1507
- Timestamp:
- 03/22/08 15:53:00 (8 months ago)
- Location:
- trunk/htdocs/system
- Files:
-
- 4 modified
-
admin/media.js (modified) (4 diffs)
-
admin/publish.php (modified) (1 diff)
-
classes/formui.php (modified) (4 diffs)
-
plugins/simplefilesilo/simplefilesilo.plugin.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/htdocs/system/admin/media.js
r1300 r1507 17 17 }, 18 18 function(result) { 19 var reload = $('.pathstore.toload', container).size(); 19 20 habari.media.unqueueLoad(); 20 21 $('.pathstore', container).html(result.path); … … 33 34 $('.mediadir', container).html(output); 34 35 } 36 else if(reload) { 37 // only need to reload the current directory 38 $('.media_dirlevel:last', container).remove(); 39 $('.mediadir', container).append(output); 40 } 41 35 42 output = '<table><tr>'; 36 43 var first = ' first'; … … 112 119 }, 113 120 114 submitPanel: function(form) { 115 var query = $(form).serialize(); 121 submitPanel: function(path, panel, form, callback) { 122 var query = $(form).serializeArray(); 123 query.push({name: 'path', value: path}); 124 query.push({name: 'panel', value: panel}); 125 126 $.post( 127 habari.url.habari + '/admin_ajax/media_panel', 128 query, 129 function(result) { 130 $('.media_panel').html(result.panel); 131 if (callback != '') { 132 eval(callback); 133 } 134 }, 135 'json'); 116 136 }, 117 137 … … 124 144 habari.media.output.image(id, this.assets[id]); 125 145 } 146 }, 147 148 clearSelections: function() { 149 var container = $('.mediasplitter:visible') 150 // remove all highlights 151 $('.mediadir .directory', container).removeClass('active'); 152 // remove second level directories 153 $('.mediadir .media_dirlevel', $('.mediasplitter:visible')).nextAll().remove() 126 154 } 127 155 -
trunk/htdocs/system/admin/publish.php
r1336 r1507 41 41 <div class="toload pathstore" style="display:none;"><?php echo $silodir->path; ?></div> 42 42 <div class="splitterinside"> 43 <div class="media_controls"><ul><li><a href="#" onclick="habari.media.showdir('<?php echo $silodir->path; ?>'); return false;">Root</a></li></ul></div>43 <div class="media_controls"><ul><li><a href="#" onclick="habari.media.showdir('<?php echo $silodir->path; ?>');habari.media.clearSelections();return false;">Root</a></li></ul></div> 44 44 <div style="white-space:nowrap;overflow-x:scroll;overflow-y:hidden;" class="media_browser"> 45 45 <div class="mediadir"></div> -
trunk/htdocs/system/classes/formui.php
r1341 r1507 248 248 /** 249 249 * Configure all the options necessary to make this form work inside a media bar panel 250 */ 251 public function media_panel() 250 * @param string $path Identifies the silo 251 * @param string $panel The panel in the silo to submit to 252 * @param string $callback Javascript function to call on form submission 253 */ 254 public function media_panel($path, $panel, $callback) 252 255 { 253 256 $this->options['show_form_on_success'] = false; … … 255 258 $this->options['ajax'] = true; 256 259 $this->options['form_action'] = URL::get('admin_ajax', array('context' => 'media_panel')); 257 $this->options['on_submit'] = 'habari.media.submitPanel();return false;';260 $this->options['on_submit'] = "habari.media.submitPanel('$path', '$panel', this, '{$callback}');return false;"; 258 261 } 259 262 … … 444 447 } 445 448 446 $out= '<div class="' . $class . '"><label>' . $this->caption . '<input type="text" name="' . $this-> field. '" value="' . $this->value . '"></label>';449 $out= '<div class="' . $class . '"><label>' . $this->caption . '<input type="text" name="' . $this->name . '" value="' . $this->value . '"></label>'; 447 450 if(isset($message)) { 448 451 $out.= '<p class="error">' . $message . '</p>'; … … 786 789 } 787 790 791 /** 792 * A hidden field control based on FormControl for output via a FormUI. 793 */ 794 class FormControlHidden extends FormControl 795 { 796 797 /** 798 * Produce HTML output for this hidden control. 799 * 800 * @param boolean $forvalidation True if this control should render error information based on validation. 801 * @return string HTML that will render this control in the form 802 */ 803 public function out($forvalidation) 804 { 805 return '<input type="hidden" name="' . $this->name . '" value="' . $this->default . '">'; 806 } 807 808 } 809 810 788 811 ?> -
trunk/htdocs/system/plugins/simplefilesilo/simplefilesilo.plugin.php
r1300 r1507 9 9 class SimpleFileSilo extends Plugin implements MediaSilo 10 10 { 11 protected $root = null;12 protected $url = null;13 14 const SILO_NAME = 'Local Files';15 16 const DERIV_DIR = '.deriv';11 protected $root= null; 12 protected $url= null; 13 14 const SILO_NAME= 'Local Files'; 15 16 const DERIV_DIR= '.deriv'; 17 17 18 18 /** … … 38 38 public function action_init() 39 39 { 40 $this->root = HABARI_PATH . '/' . Site::get_path('user', true) . 'files'; //Options::get('simple_file_root'); 41 $this->url = Site::get_url('user', true) . 'files'; //Options::get('simple_file_url'); 40 $user_path= HABARI_PATH . '/' . Site::get_path('user', true); 41 $this->root= $user_path . 'files'; //Options::get('simple_file_root'); 42 $this->url= Site::get_url('user', true) . 'files'; //Options::get('simple_file_url'); 43 /* Check for the existence of the files directory */ 44 if ( ! is_dir( $this->root ) ) { 45 if ( is_writable( $user_path ) ) { 46 mkdir( $this->root, 0766 ); 47 } else { 48 Session::error( "Web server does not have permission to create 'files' directory for SimpleFile Media Silo." ); 49 } 50 } 51 42 52 } 43 53 … … 60 70 public function silo_dir( $path ) 61 71 { 62 if( !isset( $this->root )) {72 if( ! isset( $this->root ) ) { 63 73 return array(); 64 74 } 65 75 66 $path = preg_replace('%\.{2,}%', '.', $path);67 $results = array();68 69 $dir = glob($this->root . ($path == '' ? '' : '/') . $path . '/*');70 71 72 foreach( $dir as $item) {73 if( substr( basename($item), 0, 1) == '.' ) {76 $path= preg_replace('%\.{2,}%', '.', $path); 77 $results= array(); 78 79 $dir= glob($this->root . ( $path == '' ? '' : '/' ) . $path . '/*'); 80 81 82 foreach( $dir as $item ) { 83 if( substr( basename( $item ), 0, 1 ) == '.' ) { 74 84 continue; 75 85 } 76 if( basename( $item) == 'desktop.ini' ) {86 if( basename( $item ) == 'desktop.ini' ) { 77 87 continue; 78 88 } 79 89 80 $file = basename( $item);90 $file = basename( $item ); 81 91 $props = array( 82 'title' => basename( $item),92 'title' => basename( $item ), 83 93 ); 84 if( !is_dir($item)) {85 $thumbnail_suffix = SimpleFileSilo::DERIV_DIR . '/' . $file . '.thumbnail.jpg';86 $thumbnail_url = $this->url . '/' . $path . ($path == '' ? '' : '/') . $thumbnail_suffix;87 88 if( !file_exists(dirname($item) . $thumbnail_suffix)) {89 if( !$this->create_thumbnail($item)) {94 if( ! is_dir( $item ) ) { 95 $thumbnail_suffix= SimpleFileSilo::DERIV_DIR . '/' . $file . '.thumbnail.jpg'; 96 $thumbnail_url= $this->url . '/' . $path . ($path == '' ? '' : '/') . $thumbnail_suffix; 97 98 if( ! file_exists( dirname( $item ) . '/' . $thumbnail_suffix ) ) { 99 if( ! $this->create_thumbnail( $item ) ) { 90 100 // Do something if we can't create a thumbnail, like return a default image 91 101 } … … 102 112 103 113 $results[] = new MediaAsset( 104 self::SILO_NAME . '/' . $path . ($path == '' ? '' : '/') . basename( $item),105 is_dir( $item),114 self::SILO_NAME . '/' . $path . ($path == '' ? '' : '/') . basename( $item ), 115 is_dir( $item ), 106 116 $props 107 117 ); … … 120 130 public function silo_get( $path, $qualities = null ) 121 131 { 122 if( !isset( $this->root )) {132 if( ! isset( $this->root ) ) { 123 133 return false; 124 134 } 125 135 126 $path = preg_replace('%\.{2,}%', '.', $path);127 128 $file = $this->root . '/' . $path;129 130 if( file_exists($file)) {131 $asset = new MediaAsset( self::SILO_NAME . '/' . $path );132 $asset->set( file_get_contents($file));136 $path= preg_replace('%\.{2,}%', '.', $path); 137 138 $file= $this->root . '/' . $path; 139 140 if( file_exists( $file ) ) { 141 $asset= new MediaAsset( self::SILO_NAME . '/' . $path ); 142 $asset->set( file_get_contents( $file ) ); 133 143 return $asset; 134 144 } … … 148 158 { 149 159 // Does derivative directory not exist? 150 $thumbdir = dirname( $src_filename) . '/'.SimpleFileSilo::DERIV_DIR.'';151 if( !is_dir($thumbdir)) {160 $thumbdir = dirname( $src_filename ) . '/' . SimpleFileSilo::DERIV_DIR . ''; 161 if( ! is_dir( $thumbdir ) ) { 152 162 // Create the derivative driectory 153 if( !mkdir($thumbdir, 0766)){163 if( ! mkdir( $thumbdir, 0766 ) ){ 154 164 // Couldn't make derivative directory 155 165 return false; … … 158 168 159 169 // Get information about the image 160 list( $src_width, $src_height, $type, $attr)= getimagesize( $src_filename );170 list( $src_width, $src_height, $type, $attr )= getimagesize( $src_filename ); 161 171 162 172 // Load the image based on filetype … … 180 190 181 191 // Calculate the output size based on the original's aspect ratio 192 $y_displacement= 0; 182 193 if ( $src_width / $src_height > $max_width / $max_height ) { 183 $thumb_w = $max_width; 184 $thumb_h = $src_height * $max_width / $src_width; 194 $thumb_w= $max_width; 195 $thumb_h= $src_height * $max_width / $src_width; 196 197 // thumbnail is not full height, position it down so that it will be padded on the 198 // top and bottom with black 199 $y_displacement= ($max_height - $thumb_h) / 2; 185 200 } 186 201 else { 187 $thumb_w = $src_width * $max_height / $src_height;188 $thumb_h = $max_height;202 $thumb_w= $src_width * $max_height / $src_height; 203 $thumb_h= $max_height; 189 204 } 190 205 191 206 // Create the output image and copy to source to it 192 $dst_img = ImageCreateTrueColor( $thumb_w, $thumb_h);193 imagecopyresampled( $dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $src_width, $src_height );207 $dst_img= ImageCreateTrueColor( $thumb_w, $max_height ); 208 imagecopyresampled( $dst_img, $src_img, 0, $y_displacement, 0, 0, $thumb_w, $thumb_h, $src_width, $src_height ); 194 209 195 210 /* Sharpen before save? 196 $sharpenMatrix = array( array(-1, -1, -1), array(-1, 16, -1), array(-1, -1, -1) );197 $divisor = 8;198 $offset = 0;211 $sharpenMatrix= array( array(-1, -1, -1), array(-1, 16, -1), array(-1, -1, -1) ); 212 $divisor= 8; 213 $offset= 0; 199 214 imageconvolution( $dst_img, $sharpenMatrix, $divisor, $offset ); 200 215 //*/ … … 230 245 public function silo_put( $path, $filedata ) 231 246 { 232 $path = preg_replace('%\.{2,}%', '.', $path);233 $file = $this->root . '/' . $path;247 $path= preg_replace('%\.{2,}%', '.', $path); 248 $file= $this->root . '/' . $path; 234 249 235 250 return $filedata->save( $file ); … … 271 286 public function link_path( $path, $title = '' ) 272 287 { 273 if( $title == '') {274 $title = basename( $path);288 if( $title == '' ) { 289 $title = basename( $path ); 275 290 } 276 291 return '<a href="#" onclick="habari.media.showdir(\''.$path.'\');return false;">' . $title . '</a>'; … … 304 319 { 305 320 $class = __CLASS__; 306 if( $silo instanceof $class) {307 $controls[] = $this->link_path(self::SILO_NAME . '/' . $path, 'Current Path');308 if( User::identify()->can('upload_media')) {309 $controls[] = $this->link_panel(self::SILO_NAME . '/' . $path, 'upload', 'Upload');310 } 311 if( User::identify()->can('create_directories')) {312 $controls[] = $this->link_panel(self::SILO_NAME . '/' . $path, 'mkdir', 'Create Directory');321 if( $silo instanceof $class ) { 322 $controls[]= $this->link_path( self::SILO_NAME . '/' . $path, 'Browse' ); 323 if( User::identify()->can( 'upload_media' ) ) { 324 $controls[]= $this->link_panel(self::SILO_NAME . '/' . $path, 'upload', 'Upload'); 325 } 326 if( User::identify()->can( 'create_directories' ) ) { 327 $controls[]= $this->link_panel(self::SILO_NAME . '/' . $path, 'mkdir', 'Create Directory'); 313 328 } 314 329 } … … 339 354 { 340 355 $class = __CLASS__; 341 if( $silo instanceof $class) {342 switch( $panelname) {356 if( $silo instanceof $class ) { 357 switch( $panelname ) { 343 358 case 'mkdir': 344 $form = new FormUI('simplefilesilomkdir'); 345 $form->add('text', 'directory', 'Enter the name of the new directory to create here'); 346 $form->media_panel(); 347 $form->on_success(array(&$this, 'mkdir'), $panel, $silo, $path); 348 return $form->get(); 359 /* catch form submission */ 360 if ( isset( $_POST['directory'] ) ) { 361 $dir= preg_replace('%\.{2,}%', '.', $_POST['directory']); 362 if ( isset( $path ) ) { 363 $dir= $this->root . '/' . $path . '/' . $dir; 364 } else { 365 $dir= $this->root . '/' . $dir; 366 } 367 if ( mkdir( $dir, 0766 ) ) { 368 $panel= "<div class=\"span-18\"style=\"padding-top:30px;color: #e0e0e0;margin: 0px auto;\"><p>Directory Created: {$dir}</p>"; 369 } 370 else { 371 $panel= "<div class=\"span-18\"style=\"padding-top:30px;color: #e0e0e0;margin: 0px auto;\"><p>Failed to create directory: {$dir}. Check that the webserver has write permission in the parent directory</p></div>"; 372 } 373 return $panel; 374 375 } 376 else { 377 $fullpath= self::SILO_NAME . '/' . $path; 378 379 $form= new FormUI( 'simplefilesilomkdir' ); 380 $form->add('static', 'ParentDirectory', "Parent Directory: <strong>/{$path}</strong>"); 381 $form->add('text', 'directory', 'Enter the name of the new directory to create here'); 382 $form->media_panel($fullpath, $panelname, 'habari.media.forceReload();'); 383 return $form->get(); 384 return $panel; 385 } 349 386 break; 350 387 case 'upload': 351 if( isset($_FILES['file'])) {352 $size = Utils::human_size($_FILES['file']['size']);353 $panel .= "<div class=\"span-18\" style=\"padding-top:30px;color: #e0e0e0;margin: 0px auto;\"><p>File Uploaded: {$_FILES['file']['name']} ($size)</p>";354 355 $path = self::SILO_NAME . '/' . preg_replace('%\.{2,}%', '.', $path). '/' . $_FILES['file']['name'];356 $asset = new MediaAsset($path, false);357 $asset->upload( $_FILES['file']);358 359 if( $asset->put()) {360 $panel .= '<p>File added successfully.</p>';388 if( isset( $_FILES['file'] ) ) { 389 $size= Utils::human_size($_FILES['file']['size']); 390 $panel.= "<div class=\"span-18\" style=\"padding-top:30px;color: #e0e0e0;margin: 0px auto;\"><p>File Uploaded: {$_FILES['file']['name']} ($size)</p>"; 391 392 $path= self::SILO_NAME . '/' . preg_replace('%\.{2,}%', '.', $path). '/' . $_FILES['file']['name']; 393 $asset= new MediaAsset($path, false); 394 $asset->upload( $_FILES['file'] ); 395 396 if( $asset->put() ) { 397 $panel.= '<p>File added successfully.</p>'; 361 398 } 362 399 else { 363 $panel .= '<p>File could not be added to the silo.</p>';400 $panel.= '<p>File could not be added to the silo.</p>'; 364 401 } 365 402 366 $panel .= '<p><a href="#" onclick="habari.media.forceReload();habari.media.showdir(\'' . dirname($path) . '\');">Browse the current silo path.</a></p></div>';403 $panel.= '<p><a href="#" onclick="habari.media.forceReload();habari.media.showdir(\'' . dirname($path) . '\');">Browse the current silo path.</a></p></div>'; 367 404 } 368 405 else { 369 406 370 $fullpath = self::SILO_NAME . '/' . $path;371 $form_action = URL::get('admin_ajax', array('context' => 'media_panel'));372 $panel .= <<< UPLOAD_FORM407 $fullpath= self::SILO_NAME . '/' . $path; 408 $form_action= URL::get('admin_ajax', array('context' => 'media_panel')); 409 $panel.= <<< UPLOAD_FORM 373 410 <form enctype="multipart/form-data" method="post" id="simple_upload" target="simple_upload_frame" action="{$form_action}" class="span-10" style="margin:0px auto;text-align: center"> 374 411 <p style="padding-top:30px;">Upload to: <b style="font-weight:normal;color: #e0e0e0;font-size: 1.2em;">/{$path}</b></p> … … 401 438 } 402 439 440 /* this function should convert the virtual path to a real path and 441 * then call php's mkdir function */ 403 442 public function mkdir($form, $panel, $silo, $path) 404 443 { 405 return false; 444 /* check that the regular expression is required for this case */ 445 $path= preg_replace('%\.{2,}%', '.', $path); 446 $dir= $this->root . '/' . $path; 447 return mkdir( $dir ); 406 448 } 407 449
