00001 <?php
00002
00003 namespace Habari;
00004
00005 if ( !defined( 'HABARI_PATH' ) ) { die( 'No direct access' ); }
00006
00013 class HabariSilo extends Plugin implements MediaSilo
00014 {
00015 protected $root = null;
00016 protected $url = null;
00017
00018 const SILO_NAME = 'Habari';
00019
00020 const DERIV_DIR = '.deriv';
00021
00025 public function action_init()
00026 {
00027 $user_path = HABARI_PATH . '/' . Site::get_path( 'user', true );
00028 $this->root = $user_path . 'files';
00029 $this->url = Site::get_url( 'user', true ) . 'files';
00030 }
00031
00032 public function filter_activate_plugin( $ok, $file )
00033 {
00034 if ( Plugins::id_from_file( $file ) == Plugins::id_from_file( __FILE__ ) ) {
00035 if ( !$this->check_files() ) {
00036 EventLog::log( _t( "Habari Silo activation failed. The web server does not have permission to create the 'files' directory for the Habari Media Silo." ), 'warning', 'plugin' );
00037 Session::error( _t( "Habari Silo activation failed. The web server does not have permission to create the 'files' directory for the Habari Media Silo." ) );
00038 $ok = false;
00039 }
00040
00041 if ( !function_exists( 'imagecreatefromjpeg' ) ) {
00042 EventLog::log( _t( "Habari Silo activation failed. PHP has not loaded the gd imaging library." ), 'warning', 'plugin' );
00043 Session::error( _t( "Habari Silo activation failed. PHP has not loaded the gd imaging library." ) );
00044 $ok = false;
00045 }
00046 }
00047 return $ok;
00048 }
00049
00050 public function action_plugin_activation( $file )
00051 {
00052
00053 ACL::create_token( 'create_directories', 'Create media silo directories', 'Administration' );
00054 ACL::create_token( 'delete_directories', 'Delete media silo directories', 'Administration' );
00055 ACL::create_token( 'upload_media', 'Upload files to media silos', 'Administration' );
00056 ACL::create_token( 'delete_media', 'Delete files from media silos', 'Administration' );
00057 }
00058
00063 public function filter_plugin_config( $actions )
00064 {
00065 $actions['configure'] = _t('Configure');
00066 return $actions;
00067 }
00068
00069 public function action_plugin_ui_configure()
00070 {
00071 $ui = new FormUI( strtolower( get_class( $this ) ) );
00072 $ui->append( FormControlLabel::wrap( _t('Max thumbnail width:'), FormControlText::create( 'max_thumbnail_width', __CLASS__ . '__max_thumbnail_width' ) ) );
00073 $ui->max_thumbnail_width->add_validator('validate_regex', '/^[0-9]*$/', _t('Only numbers may be entered for thumbnail width.'));
00074 $ui->append( FormControlLabel::wrap( _t('Max thumbnail height:'), FormControlText::create( 'max_thumbnail_height', __CLASS__ . '__max_thumbnail_height' ) ) );
00075 $ui->max_thumbnail_height->add_validator('validate_regex', '/^[0-9]*$/', _t('Only numbers may be entered for thumbnail height.'));
00076 $ui->append( FormControlLabel::wrap( _t('Always create square thumbnails (pad with black if not high enough):' ), FormControlCheckbox::create( 'force_square', __CLASS__ . '__force_square_thumbnail' ) ) );
00077 $ui->append(FormControlSubmit::create('save')->set_caption('Save'));
00078 $ui->out();
00079 }
00080
00087 public function filter_token_description_display( $token )
00088 {
00089 $desc = array(
00090 'create_directories' => _t( 'Create media silo directories' ),
00091 'delete_directories' => _t( 'Delete media silo directories' ),
00092 'upload_media' => _t( 'Upload files to media silos' ),
00093 'delete_media' => _t( 'Delete files from media silos' ),
00094 );
00095 return isset( $desc[$token] ) ? $desc[$token] : $token;
00096 }
00097
00105 public function action_plugin_deactivation( $file ) {
00106 $silos = Plugins::get_by_interface( 'MediaSilo' );
00107 if ( count( $silos ) <= 1 ) {
00108 ACL::destroy_token( 'upload_media' );
00109 ACL::destroy_token( 'delete_media' );
00110 ACL::destroy_token( 'create_directories' );
00111 ACL::destroy_token( 'delete_directories' );
00112 }
00113 }
00114
00119 private function check_files() {
00120 $user_path = HABARI_PATH . '/' . Site::get_path( 'user', true );
00121 $this->root = $user_path . 'files';
00122 $this->url = Site::get_url( 'user', true ) . 'files';
00123
00124 if ( !is_dir( $this->root ) ) {
00125 if ( is_writable( $user_path ) ) {
00126 mkdir( $this->root, 0755 );
00127 }
00128 else {
00129 return false;
00130 }
00131 }
00132
00133 return true;
00134 }
00135
00140 public function silo_info()
00141 {
00142 return array(
00143 'name' => self::SILO_NAME,
00144 'icon' => URL::get_from_filesystem( __FILE__ ) . '/icon.png'
00145 );
00146 }
00147
00153 public function silo_dir( $path )
00154 {
00155 if ( !isset( $this->root ) ) {
00156 return array();
00157 }
00158
00159 $path = preg_replace( '%\.{2,}%', '.', $path );
00160 $results = array();
00161
00162 $dir = Utils::glob( $this->root . ( $path == '' ? '' : '/' ) . $path . '/*' );
00163
00164 foreach ( $dir as $item ) {
00165 if ( substr( basename( $item ), 0, 1 ) == '.' ) {
00166 continue;
00167 }
00168 if ( basename( $item ) == 'desktop.ini' ) {
00169 continue;
00170 }
00171
00172 $file = basename( $item );
00173 $props = array(
00174 'title' => basename( $item ),
00175 );
00176 if(is_dir($item)) {
00177 $results[] = new MediaAsset(
00178 self::SILO_NAME . '/' . $path . ($path == '' ? '' : '/') . basename( $item ),
00179 is_dir( $item ),
00180 $props
00181 );
00182 }
00183 else {
00184 $results[] = $this->silo_get( $path . ($path == '' ? '' : '/') . basename( $item ) );
00185 }
00186 }
00187
00188 return $results;
00189 }
00190
00191
00198 public function silo_get( $path, $qualities = null )
00199 {
00200 if ( ! isset( $this->root ) ) {
00201 return false;
00202 }
00203
00204 $path = preg_replace( '%\.{2,}%', '.', $path );
00205
00206 $file = basename( $path );
00207 $props = array(
00208 'title' => basename( $path ),
00209 );
00210 $realfile = $this->root . '/' . $path;
00211
00212 $thumbnail_suffix = HabariSilo::DERIV_DIR . '/' . $file . '.thumbnail.jpg';
00213 $thumbnail_url = $this->url . '/' . dirname( $path ) . ( dirname( $path ) == '' ? '' : '/' ) . $thumbnail_suffix;
00214 $mimetype = preg_replace(' %[^a-z_0-9]%', '_', Utils::mimetype( $realfile ) );
00215 $mtime = '';
00216
00217 if ( !file_exists( dirname( $realfile ) . '/' . $thumbnail_suffix ) ) {
00218
00219 $max_thumbnail_width = Options::get( __CLASS__ . '__max_thumbnail_width', Media::THUMBNAIL_WIDTH );
00220 $max_thumbnail_height = Options::get( __CLASS__ . '__max_thumbnail_height', Media::THUMBNAIL_HEIGHT );
00221 if ( !$this->create_thumbnail( $realfile, $max_thumbnail_width, $max_thumbnail_height ) ) {
00222
00223 $icon_path = Plugins::filter( 'habarisilo_icon_base_path', dirname( $this->get_file() ) . '/icons' );
00224 $icon_url = Plugins::filter( 'habarisilo_icon_base_url', $this->get_url() . '/icons' );
00225
00226 if ( ( $icons = Utils::glob( $icon_path . '/*.{png,jpg,gif,svg}', GLOB_BRACE ) ) && $mimetype ) {
00227 $icon_keys = array_map( function($a) {return pathinfo($a, PATHINFO_FILENAME);}, $icons );
00228 $icons = array_combine( $icon_keys, $icons );
00229 $icon_filter = function($a, $b) use ($mimetype) {
00230 return (((strpos($mimetype, $a)===0) ? (strlen($a) / strlen($mimetype)) : 0) >= (((strpos($mimetype, $b)===0)) ? (strlen($b) / strlen($mimetype)) : 0)) ? $a : $b;
00231 };
00232 $icon_key = array_reduce( $icon_keys, $icon_filter );
00233 if ($icon_key) {
00234 $icon = basename( $icons[$icon_key] );
00235 $thumbnail_url = $icon_url .'/'. $icon;
00236 }
00237 else {
00238
00239 $thumbnail_url = $icon_url .'/default.png';
00240 }
00241 }
00242 }
00243 }
00244
00245
00246 if ( in_array( $mimetype, array( 'image_jpeg', 'image_png', 'image_gif' ) ) ) {
00247 list( $props['width'], $props['height'] ) = getimagesize( $realfile );
00248 $mtime = '?' . filemtime( $realfile );
00249 }
00250 $props = array_merge(
00251 $props,
00252 array(
00253 'url' => $this->url . '/' . dirname( $path ) . ( $path == '' ? '' : '/' ) . $file,
00254 'thumbnail_url' => $thumbnail_url . $mtime,
00255 'filetype' => $mimetype,
00256 )
00257 );
00258
00259 $asset = new MediaAsset( self::SILO_NAME . '/' . $path, false, $props );
00260 if ( file_exists( $realfile ) && is_file( $realfile ) ) {
00261 $asset->content = file_get_contents( $realfile );
00262 }
00263 return $asset;
00264 }
00265
00266
00275 private function create_thumbnail( $src_filename, $max_width = Media::THUMBNAIL_WIDTH, $max_height = Media::THUMBNAIL_HEIGHT )
00276 {
00277
00278 $thumbdir = dirname( $src_filename ) . '/' . HabariSilo::DERIV_DIR . '';
00279 if ( !is_dir( $thumbdir ) ) {
00280
00281 if ( !mkdir( $thumbdir, 0755 ) ) {
00282
00283 return false;
00284 }
00285 }
00286
00287
00288 $isize = @getimagesize( $src_filename );
00289 if(is_array($isize)) {
00290 list( $src_width, $src_height, $type, $attr )= $isize;
00291 }
00292 else {
00293 $type = '';
00294 $src_img = '';
00295 }
00296
00297
00298 switch ( $type ) {
00299 case IMAGETYPE_JPEG:
00300 $src_img = imagecreatefromjpeg( $src_filename );
00301 break;
00302 case IMAGETYPE_PNG:
00303 $src_img = imagecreatefrompng( $src_filename );
00304 break;
00305 case IMAGETYPE_GIF:
00306 $src_img = imagecreatefromgif ( $src_filename );
00307 break;
00308 default:
00309 return false;
00310 }
00311
00312 if ( !$src_img ) {
00313 return false;
00314 }
00315
00316
00317 $y_displacement = 0;
00318 $displace = Options::get( __CLASS__ . '__force_square_thumbnail', true );
00319 if ( $src_width / $src_height > $max_width / $max_height ) {
00320 $thumb_w = $max_width;
00321 $thumb_h = $src_height * $max_width / $src_width;
00322
00323 if($displace) {
00324
00325
00326 $y_displacement = ( $max_height - $thumb_h ) / 2;
00327 }
00328 }
00329 else {
00330 $thumb_w = $src_width * $max_height / $src_height;
00331 $thumb_h = $max_height;
00332 }
00333
00334
00335 $dst_img = ImageCreateTrueColor( $thumb_w, ($displace) ? $max_height : $thumb_h );
00336 imagecopyresampled( $dst_img, $src_img, 0, $y_displacement, 0, 0, $thumb_w, $thumb_h, $src_width, $src_height );
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346 $dst_filename = $thumbdir . '/' . basename( $src_filename ) . ".thumbnail.jpg";
00347
00348
00349 imagejpeg( $dst_img, $dst_filename );
00350
00351
00352 imagedestroy( $dst_img );
00353 imagedestroy( $src_img );
00354
00355 return true;
00356 }
00357
00363 public function silo_new( $path )
00364 {
00365 }
00366
00373 public function silo_put( $path, $filedata )
00374 {
00375 $path = preg_replace('%\.{2,}%', '.', $path);
00376 $file = $this->root . '/' . $path;
00377
00378 $result = $filedata->save( $file );
00379 if ( $result ) {
00380 $max_thumbnail_width = Options::get( __CLASS__ . '__max_thumbnail_width', Media::THUMBNAIL_WIDTH );
00381 $max_thumbnail_height = Options::get( __CLASS__ . '__max_thumbnail_height', Media::THUMBNAIL_HEIGHT );
00382 $this->create_thumbnail( $file, $max_thumbnail_width, $max_thumbnail_height );
00383 }
00384
00385 return $result;
00386 }
00387
00392 public function silo_delete( $path )
00393 {
00394 $file = $this->root . '/' . $path;
00395
00396
00397 $result = unlink( $file );
00398
00399
00400 $thumbdir = dirname( $file ) . '/' . HabariSilo::DERIV_DIR . '';
00401 $thumb = $thumbdir . '/' . basename( $file ) . ".thumbnail.jpg";
00402
00403 if ( file_exists( $thumbdir ) && file_exists( $thumb ) ) {
00404 unlink( $thumb );
00405
00406 if ( self::isEmptyDir( $thumbdir ) ) {
00407 rmdir( $thumbdir );
00408 }
00409 }
00410 return $result;
00411 }
00412
00418 public function silo_highlights()
00419 {
00420 }
00421
00427 public function silo_permissions( $path )
00428 {
00429 }
00430
00438 public function link_path( $path, $title = '' )
00439 {
00440 if ( $title == '' ) {
00441 $title = basename( $path );
00442 }
00443 return '<a href="#" onclick="habari.media.showdir(\''.$path.'\');return false;">' . $title . '</a>';
00444 }
00445
00454 public function link_panel( $path, $panel, $title )
00455 {
00456 return '<a href="#" onclick="habari.media.showpanel(\''.$path.'\', \''.$panel.'\');return false;">' . $title . '</a>';
00457 }
00458
00470 public function filter_media_controls( $controls, $silo, $path, $panelname )
00471 {
00472 $class = __CLASS__;
00473 if ( $silo instanceof $class ) {
00474 $controls[] = $this->link_path( self::SILO_NAME . '/' . $path, _t( 'Browse' ) );
00475 if ( User::identify()->can( 'upload_media' ) ) {
00476 $controls[] = $this->link_panel( self::SILO_NAME . '/' . $path, 'upload', _t( 'Upload' ) );
00477 }
00478 if ( User::identify()->can( 'create_directories' ) ) {
00479 $controls[] = $this->link_panel( self::SILO_NAME . '/' . $path, 'mkdir', _t( 'Create Directory' ) );
00480 }
00481 if ( User::identify()->can( 'delete_directories' ) && ( $path && self::isEmptyDir( $this->root . '/' . $path ) ) ) {
00482 $controls[] = $this->link_panel( self::SILO_NAME . '/' . $path, 'rmdir', _t( 'Delete Directory' ) );
00483 }
00484 }
00485 return $controls;
00486 }
00487
00508 public function filter_media_panels( $panel, $silo, $path, $panelname)
00509 {
00510 $class = __CLASS__;
00511 if ( $silo instanceof $class ) {
00512 switch ( $panelname ) {
00513 case 'mkdir':
00514
00515 $fullpath = self::SILO_NAME . '/' . $path;
00516
00517 $form = new FormUI( 'habarisilomkdir' );
00518 $form->append( FormControlStatic::create( 'ParentDirectory' )->set_static( '<div style="margin: 10px auto;">' . _t( 'Parent Directory:' ) . " <strong>/{$path}</strong></div>" ) );
00519 // add the parent directory as a hidden input for later validation
00520 $form->append( FormControlData::create( 'path' )->set_value( $path ) );
00521 $form->append( FormControlData::create( 'action' )->set_value( $panelname ) );
00522
00523 $form->append( FormControlLabel::wrap( _t('What would you like to call the new directory?'),
00524 FormControlText::create( 'directory' )->add_validator( array( $this, 'mkdir_validator' ) ) ) );
00525 $form->append( FormControlSubmit::create( 'submit' )->set_caption( _t('Submit') ) );
00526 $form->media_panel($fullpath, $panelname, 'habari.media.forceReload();');
00527 $form->on_success( array( $this, 'dir_success' ) );
00528 $panel = $form->get(); /* form submission magicallly happens here */
00529
00530 return $panel;
00531
00532 break;
00533 case 'rmdir':
00534 $fullpath = self::SILO_NAME . '/' . $path;
00535
00536 $form = new FormUI( 'habarisilormdir' );
00537 $form->append( FormControlStatic::create( 'RmDirectory' )->set_static( '<div style="margin: 10px auto;">' . _t( 'Directory:' ) . " <strong>/{$path}</strong></div>" ) );
00538 // add the parent directory as a hidden input for later validation
00539 $form->append( FormControlData::create( 'path')->set_value( $path ) );
00540 $form->append( FormControlData::create( 'action' )->set_value( $panelname ) );
00541 $form->append( FormControlStatic::create( 'directory' )->set_static( _t( 'Are you sure you want to delete this directory?' ) ) );
00542 $form->append( FormControlSubmit::create( 'submit' )->set_caption( _t('Delete') ) );
00543 $form->media_panel( $fullpath, $panelname, 'habari.media.forceReload();' );
00544 $form->on_success( array( $this, 'dir_success' ) );
00545 $panel = $form->get(); /* form submission magicallly happens here */
00546
00547 return $panel;
00548
00549 break;
00550 case 'delete':
00551 $fullpath = self::SILO_NAME . '/' . $path;
00552
00553 $form = new FormUI( 'habarisilodelete' );
00554 $form->append( FormControlStatic::create( 'RmFile' )->set_static( '<div style="margin: 10px auto;">' . _t( 'File:' ) . " <strong>/{$path}</strong></div>" ) );
00555 // add the parent directory as a hidden input for later validation
00556 $form->append( FormControlData::create( 'path')->set_value( $path ) );
00557 $form->append( FormControlStatic::create( 'directory' )->set_static( '<p>' . _t( 'Are you sure you want to delete this file?' ) . '</p>' ) );
00558 $form->append( FormControlSubmit::create( 'submit' )->set_caption( _t('Delete') ) );
00559 $form->media_panel( $fullpath, $panelname, 'habari.media.forceReload();' );
00560 $form->on_success( array( $this, 'do_delete' ) );
00561 $panel = $form->get(); /* form submission magicallly happens here */
00562
00563 return $panel;
00564 break;
00565 case 'upload':
00566 if ( isset( $_FILES['file'] ) ) {
00567 if ( isset( $_POST['token'] ) && isset( $_POST['token_ts'] ) && self::verify_token( $_POST['token'], $_POST['token_ts'] ) ) {
00568 $size = Utils::human_size( $_FILES['file']['size'] );
00569 $panel .= '<div class="span-18" style="padding-top:30px;color: #e0e0e0;margin: 0px auto;"><p>' . _t( 'File: ' ) . $_FILES['file']['name'];
00570 $panel .= ( $_FILES['file']['size'] > 0 ) ? "({$size})" : '';
00571 $panel .= '</p>';
00572
00573 $path = self::SILO_NAME . '/' . preg_replace( '%\.{2,}%', '.', $path ). '/' . $_FILES['file']['name'];
00574 $asset = new MediaAsset( $path, false );
00575 $asset->upload( $_FILES['file'] );
00576
00577 if ( $asset->put() ) {
00578 $msg = _t( 'File uploaded: %s', array( $_FILES['file']['name'] ) );
00579 $panel .= '<p>' . $msg . '</p>';
00580 EventLog::log( $msg, 'info' );
00581 }
00582 else {
00583 $upload_errors = array(
00584 1 => _t( 'The uploaded file exceeds the upload_max_filesize directive in php.ini.' ),
00585 2 => _t( 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.' ),
00586 3 => _t( 'The uploaded file was only partially uploaded.' ),
00587 4 => _t( 'No file was uploaded.' ),
00588 6 => _t( 'Missing a temporary folder.' ),
00589 7 => _t( 'Failed to write file to disk.' ),
00590 8 => _t( 'A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help.' ),
00591 );
00592 $msg = _t( 'File upload failed: %s', array( $_FILES['file']['name'] ) );
00593 $panel .= '<p>' . $msg . '</p>';
00594 $panel .= '<p><strong>' . $upload_errors[ $_FILES['file']['error'] ] . '</strong></p>';
00595 EventLog::log( $msg . ' ' . $upload_errors[ $_FILES['file']['error'] ], 'err' );
00596 }
00597
00598 $panel .= '<p><a href="#" onclick="habari.media.forceReload();habari.media.showdir(\'' . dirname( $path ) . '\');">' . _t( 'Browse the current silo path.' ) . '</a></p></div>';
00599 } else {
00600 $panel .= '<p><strong>' ._t( 'Suspicious behaviour or too much time has elapsed. Please upload your file again.' ) . '</strong></p>';
00601 }
00602 }
00603 else {
00604 $token_ts = time();
00605 $token = self::create_token( $token_ts );
00606 $fullpath = self::SILO_NAME . '/' . $path;
00607 $form_action = URL::get( 'admin_ajax', array( 'context' => 'media_upload' ) );
00608 $panel .= <<< UPLOAD_FORM
00609 <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">
00610 <p style="padding-top:30px;">%s <b style="font-weight:normal;color: #e0e0e0;font-size: 1.2em;">/{$path}</b></p>
00611 <p><input type="file" name="file"><input type="submit" name="upload" value="%s">
00612 <input type="hidden" name="path" value="{$fullpath}">
00613 <input type="hidden" name="panel" value="{$panelname}">
00614 <input type="hidden" name="token" value="{$token}">
00615 <input type="hidden" name="token_ts" value="{$token_ts}">
00616 </p>
00617 </form>
00618 <iframe id="simple_upload_frame" name="simple_upload_frame" style="width:1px;height:1px;" onload="simple_uploaded();"></iframe>
00619 <script type="text/javascript">
00620 var responsedata;
00621 function simple_uploaded() {
00622 if (!$('#simple_upload_frame')[0].contentWindow) return;
00623 var response = $($('#simple_upload_frame')[0].contentWindow.document.body).text();
00624 if (response) {
00625 eval('responsedata = ' + response);
00626 window.setTimeout(simple_uploaded_complete, 500);
00627 }
00628 }
00629 function simple_uploaded_complete() {
00630 habari.media.jsonpanel(responsedata.data);
00631 }
00632 </script>
00633 UPLOAD_FORM;
00634
00635 $panel = sprintf( $panel, _t( "Upload to:" ), _t( "Upload" ) );
00636 }
00637 }
00638 }
00639 return $panel;
00640 }
00641
00650 public function mkdir_validator( $dir, $control, $form )
00651 {
00652 if ( strpos( $dir, '*' ) !== false || preg_match( '%(?:^|/)\.%', $dir ) ) {
00653 return array( _t( "The directory name contains invalid characters: %s.", array( $dir ) ) );
00654 }
00655
00656 $path = preg_replace( '%\.{2,}%', '.', $form->path->value );
00657 $dir = $this->root . ( $path == '' ? '' : '/' ) . $path . '/'. $dir;
00658
00659 if ( !is_writable( $this->root . '/' . $path ) ) {
00660 return array( _t( "Webserver does not have permission to create directory: %s.", array( $dir ) ) );
00661 }
00662 if ( is_dir( $dir ) ) {
00663 return array( _t( "Directory: %s already exists.", array( $dir ) ) );
00664 }
00665
00666 return array();
00667 }
00673 public function dir_success ( $form )
00674 {
00675 $dir = preg_replace( '%\.{2,}%', '.', $form->directory->value );
00676 $path = preg_replace( '%\.{2,}%', '.', $form->path->value );
00677
00678 switch ( $form->action->value ) {
00679 case 'rmdir':
00680 $dir = $this->root . ( $path == '' ? '' : '/' ) . $path;
00681 rmdir( $dir );
00682 $msg = _t( 'Directory deleted: /%s', array( $path ) );
00683 break;
00684 case 'mkdir':
00685 $dir = $this->root . ( $path == '' ? '' : '/' ) . $path . '/'. $dir;
00686 mkdir( $dir, 0755 );
00687 $msg = _t ( 'Directory created: %s', array( $path . '/' . $form->directory->value ) );
00688 break;
00689 }
00690 EventLog::log( $msg, 'info' );
00691 return '<div class="span-18"style="padding-top:30px;color: #e0e0e0;margin: 0px auto;"><p>' . $msg . '</p></div>';
00692 }
00693
00700 public function do_delete ( $form )
00701 {
00702 $path = preg_replace( '%\.{2,}%', '.', $form->path->value );
00703 $result = $this->silo_delete($path);
00704 $panel = '<div class="span-18"style="padding-top:30px;color: #e0e0e0;margin: 0px auto;">';
00705 if ( $result ) {
00706 $msg = _t( 'File deleted: /%s', array( $path ) );
00707 } else {
00708 $msg = _t( 'Failed to delete file: /%s', array( $path ) );
00709 }
00710 $panel .= '<p>' . $msg . '</p>';
00711 $panel .= '<p><a href="#" onclick="habari.media.forceReload();habari.media.showdir(\'' . self::SILO_NAME . '/' . dirname( $path ) . '\');">' . _t( 'Browse the current silo path.' ) . '</a></p></div>';
00712
00713 EventLog::log( $msg, 'info' );
00714 return $panel;
00715 }
00716
00723 private static function isEmptyDir( $dir )
00724 {
00725 return ( ( $files = @scandir( $dir ) ) && count( $files ) <= 2 );
00726 }
00727
00734 private static function create_token( $timestamp )
00735 {
00736 return substr( md5( $timestamp . Options::get( 'public-GUID' ) ), 0, 10 );
00737 }
00738
00749 private static function verify_token( $token, $timestamp )
00750 {
00751 if ( $token == self::create_token( $timestamp ) ) {
00752 if ( ( time() > ( $timestamp ) ) && ( time() < ( $timestamp + 5*60 ) ) ) {
00753 return true;
00754 }
00755 } else {
00756 return false;
00757 }
00758 }
00759
00760 }
00761
00762 ?>