Changeset 557

Show
Ignore:
Timestamp:
05/23/08 16:39:28 (6 months ago)
Author:
aarkerio
Message:

Shares improved

Location:
trunk/app
Files:
2 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/controllers/shares_controller.php

    r540 r557  
    2323 {              
    2424        $this->pageTitle = 'Share'; 
    25          
     25        $this->layout    = 'ajax'; 
    2626        $conditions      = array("Share.secret"=>$secret, "Share.public"=>1); 
    2727         
    2828        $file            =  $this->Share->field('file', $conditions); 
    2929         
    30         if (!$file) 
    31     { 
    32              $this->redirect('/'); 
    33         } 
    34     else 
    35         { 
    36             $this->redirect("/files/userfiles/".$file); 
    37     } 
     30        if (!$file): 
     31              $this->redirect('/'); 
     32    else: 
     33             $this->set('file', 'files/userfiles/'.$file); 
     34    endif; 
    3835  } 
    3936   
     
    106103     
    107104    /** Security: checks to see if file is an image, if not do not allow upload ==*/ 
    108     if ( $type == "application/x-php") // .php is not a valid file!!!  
    109     {    
    110         $ErrMsg  = "<h1>ERROR</h1> the file ". $file_name . " is not valid.<br>"; 
    111         $ErrMsg .= "<p>no se pueden agregar archivos .php, subelo como .txt<br /><br />"; 
    112     $ErrMsg .= '<a href="upload_1.php"> &gt;&gt; Regresar </a>'; 
     105    if ( $type == "application/x-php"): // .php is not a valid file!!!     
     106        $msg = 'Error the file '. $file_name . ' is not valid. No se pueden agregar archivos .php, subelo como .txt'; 
    113107        /**  delete uploaded file ==*/ 
    114108        unlink($file); 
    115         exit($ErrMsg); 
    116     } 
    117      
    118     if ( $file_size > $maxfilesize)  
    119     { 
    120      $ErrMsg  = "<h1>ERROR</h1> The image is too big.<br>"; 
    121          $ErrMsg .= "<p>Bigger than 30 MB <br><br>"; 
    122          $ErrMsg .= "The current size: " . $file_size ."</p>\n"; 
     109        $this->flash($msg, '/admin/shares/listing'); 
     110        return false; 
     111    endif; 
     112     
     113    if ( $file_size > $maxfilesize): 
     114     $msg  = 'Error. The image is too big. Bigger than 30 MB. The current size: ' . $file_size ; 
    123115         
    124         /** delete uploaded file */ 
     116        /**  delete uploaded file ==*/ 
    125117        unlink($file); 
    126         exit($ErrMsg); 
    127     } 
     118        $this->flash($msg, '/admin/shares/listing'); 
     119        return false; 
     120    endif; 
    128121     
    129122    $conditions  = array("user_id" =>  $this->Auth->user('id')); 
     
    139132    $allowed     = array("pdf", "doc", "xls", "xcf", "ppt", "sxw", "odt", "odc", "ods", "odp", "abw", "html", "zip", "rar", "gz", "png", "jpg", "gif", "svg", "mp3", "ogg", "flac", "txt"); 
    140133     
    141     if ( !in_array($extension, $allowed) ) 
    142     { 
    143     die("This does not look like one allowed file ". $extension); 
    144     } 
     134    if ( !in_array($extension, $allowed) ): 
     135            die("This does not look like one allowed file ". $extension); 
     136    endif; 
    145137     
    146138    $Name        = $this->Auth->user('username') . "_" . $next_id . '.'. $extension; 
     
    153145     
    154146    /** do extra security check to prevent malicious abuse */ 
    155     if (is_uploaded_file($file)) 
    156     { 
     147    if (is_uploaded_file($file)): 
    157148       /** move file to proper directory ==*/ 
    158        if (!move_uploaded_file($file, $newfile)) 
    159        { 
     149      if (!move_uploaded_file($file, $newfile)): 
    160150          /** if an error occurs the file could not 
    161151               be written, read or possibly does not exist ==*/ 
    162152          
    163153         exit('Error Uploading File.'); 
    164        } 
    165    } 
     154       endif; 
     155    endif; 
    166156   
    167157     
     
    172162   $this->data['Share']['user_id']  = $this->Auth->user('id'); 
    173163    
    174    if ($this->Share->save($this->data["Share"])) 
    175    { 
    176        $this->msgFlash('File saved','/admin/shares/listing'); 
    177    } 
    178  } 
    179  
     164   if ($this->Share->save($this->data["Share"])): 
     165        $this->msgFlash('File saved','/admin/shares/listing'); 
     166   endif; 
     167  } 
    180168 } 
    181169 
     
    187175     $this->data['Share']['id']     = $id; 
    188176      
    189      if ($this->Share->save($this->data['Share'])) 
    190      { 
     177     if ($this->Share->save($this->data['Share'])): 
    191178           $this->msgFlash('Share changed', '/admin/shares/listing'); 
    192      } 
     179     endif; 
    193180 } 
    194181 public function admin_delete($id)  
  • trunk/app/views/shares/display.ctp

    r329 r557  
    1 <div style="font-size:18pt;padding:5px;boder:1px solid #c0c0c0"> <?php echo $blog["User"]["username"]; ?>'s Files</div> 
    21<?php 
    32//die(print_r($data)); 
    4 if ( count($data) < 1) 
    5 { 
     3 
     4echo $html->div(null, $blog['User']['username'] . '\'s Files', array('style'=>'font-size:18pt;padding:5px;boder:1px solid #c0c0c0')); 
     5 
     6if ( count($data) < 1): 
    67  echo $html->para('title', 'Teacher does not have any resource');  
    7 } 
     8endif; 
    89 
    9 foreach ($data as $v) 
    10 { 
    11   echo '<div style="padding:6px;margin:4px;height:30px;border:1px dotted orange;vertical-align:middle;">'; 
    12   echo  $html->link($v["Share"]["description"], '/shares/download/'.$v["Share"]["secret"]); 
    13   echo  $html->link($html->image('static/button_download.gif', array("alt"=>$v["Share"]["description"], "alt"=>$v["Share"]["description"])), '/shares/show/'.$v["Share"]["secret"], null, null, false);  
    14   echo '</div>';  
    15 } 
     10foreach ($data as $v): 
     11  $tmp  = $html->link($html->image('static/shares-icon.png', array('alt'=>'Download', 'title'=>'Download')),'/shares/download/'.$v["Share"]["secret"], null, null, false).'<br />'; 
     12  $tmp .= $html->link($v["Share"]["description"], '/shares/download/'.$v["Share"]["secret"]); 
     13  $tmp .= $html->link($html->image('static/button_download.gif', array("alt"=>$v["Share"]["description"], "alt"=>$v["Share"]["description"])), '/shares/download/'.$v["Share"]["secret"], null, null, false);  
     14 
     15  echo $html->div(null,$tmp,array('style'=>'padding:6px;margin:4px;border:1px dotted orange;vertical-align:middle;width:90%;'));  
     16endforeach; 
    1617?>