Changeset 36

Show
Ignore:
Timestamp:
07/16/07 17:29:03 (18 months ago)
Author:
aarkerio
Message:

Images

Location:
trunk/app
Files:
13 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/config/sql/karamelo.sql

    r27 r36  
    833833INSERT INTO categories (title, user_id) VALUES ('Book Review', 1); 
    834834 
     835-- Sections blogs 
     836CREATE TABLE themeblogs ( 
     837 id serial PRIMARY KEY, 
     838 title varchar(110) NOT NULL, 
     839 user_id int NOT NULL REFERENCES users(id) ON DELETE CASCADE 
     840); 
     841 
    835842-- entries in the users blogs 
    836843CREATE TABLE entries ( 
     
    838845title varchar(50) NOT NULL, 
    839846body text NOT NULL, 
    840 category_id int REFERENCES categories (id) ON DELETE CASCADE, 
     847subject_id int REFERENCES subjects (id) ON DELETE CASCADE, 
    841848created timestamp(0) with time zone DEFAULT now() NOT NULL, 
    842849status int NOT NULL DEFAULT 0, 
    843 user_id int REFERENCES users (id) ON DELETE CASCADE, 
     850user_id int REFERENCES users(id) ON DELETE CASCADE, 
    844851disc int NOT NULL DEFAULT 0  -- discution, Activ/Desactiv   1/0 
    845852); 
  • trunk/app/controllers/components/adds.php

    r1 r36  
    3232    return substr($password, 0, $length);  
    3333} 
     34//handle images 
     35public function get_extension($imagetype)  
     36{ 
     37      
     38     if ( empty($imagetype) ) 
     39     { 
     40         return false; 
     41     } 
     42      
     43     switch($imagetype) 
     44     { 
     45           case 'image/bmp': return '.bmp'; 
     46           case 'image/cis-cod': return '.cod'; 
     47           case 'image/gif': return '.gif'; 
     48           case 'image/ief': return '.ief'; 
     49           case 'image/jpeg': return '.jpg'; 
     50           case 'image/pipeg': return '.jfif'; 
     51           case 'image/tiff': return '.tif'; 
     52           case 'image/x-cmu-raster': return '.ras'; 
     53           case 'image/x-cmx': return '.cmx'; 
     54           case 'image/x-icon': return '.ico'; 
     55           case 'image/x-portable-anymap': return '.pnm'; 
     56           case 'image/x-portable-bitmap': return '.pbm'; 
     57           case 'image/x-portable-graymap': return '.pgm'; 
     58           case 'image/x-portable-pixmap': return '.ppm'; 
     59           case 'image/x-rgb': return '.rgb'; 
     60           case 'image/x-xbitmap': return '.xbm'; 
     61           case 'image/x-xpixmap': return '.xpm'; 
     62           case 'image/x-xwindowdump': return '.xwd'; 
     63           case 'image/png': return '.png'; 
     64           case 'image/x-jps': return '.jps'; 
     65           case 'image/x-freehand': return '.fh'; 
     66           default: return false; 
     67       } 
     68  } 
    3469 
    3570//validate email format and hosting address 
  • trunk/app/controllers/entries_controller.php

    r34 r36  
    1818   public function results($string)  
    1919   { 
     20       $this->layout = 'portal'; 
    2021        
    21        $conditions = array("Entry.body"=>$string); 
     22       $conditions   = array("Entry.body"=>$string); 
    2223        
    23        $data = $this->Entry->findAll($conditions, $order); 
    24         
    25        $this->set('data', $data); 
     24       $this->set('data', $this->Entry->findAll($conditions, $order)); 
    2625   } 
    2726    
    2827   public function rss($user_id)  
    2928   { 
    30         
    3129       $this->layout    = 'rss'; 
    3230        
    3331       $conditions = array("Entry.status"=>1, "Entry.user_id"=>$user_id); 
    3432        
    35        $fields     = array("id", "title", "body", "created", "category_id", "user_id"); 
     33       $fields     = array("id", "title", "body", "created", "subject_id", "user_id"); 
    3634        
    3735       $data = $this->Entry->findAll($conditions, $fields, "Entry.created", 10, false, 2); 
     
    5755   } 
    5856    
     57   /** ====  ADMIN SECTION ====*/ 
     58    
    5959   public function admin_add() 
    6060   { 
    6161     
    6262    $this->layout    = 'admin'; 
    63     // adds new blog entries  
    64    if ( empty($this->data) )   
    65    { 
    66       
    67      $this->set('categories', $this->Entry->Category->generateList()); 
    68       
    69      $conditions = array("Entry.user_id" => $this->othAuth->user('id')); 
    70       
    71      $fields     = array("id", "title", "body", "disc", "created", "status"); 
    72       
    73      $data = $this->Entry->findAll($conditions, $fields, null, null, null, 1); 
    74       
    75      $this->set('data', $data); 
    76       
    77      //$this->render(); 
    78    } 
     63     
     64    if ( empty($this->data["Entry"]) )   
     65    { 
     66         $this->set('subjects', $this->Entry->Subject->generateList(null,'title')); 
     67    } 
    7968    else 
    80    { 
     69    { 
    8170     
    8271    $this->Sanitize = new Sanitize; 
     
    9281            $this->flash('Database error!', '/admin/entries/listing'); 
    9382      } 
    94    } 
     83    } 
    9584  } 
    96   /** ===  ADMIN SECTION */ 
    97    
     85  
    9886  public function admin_start($order = null) 
    9987  { 
     
    10795         
    10896        $conditions = null; 
    109         $fields     = array("id", "title", "body", "category_id"); 
     97        $fields     = array("id", "title", "body", "subject_id"); 
    11098        $data       = $this->Entry->findAll( $conditions, $fields, $order, null, null, true ); 
    11199         
  • trunk/app/controllers/images_controller.php

    r31 r36  
    11<?php 
    2 /** 
     2/* 
    33*  Karamelo E-Learning Platform 
    44*  Manuel Montoya 2002-2007  
    55*  Chipotle Software 
    6 *  GPLv3 manuel<at>mononeurona.org 
     6*  GPL manuel<at>mononeurona.org 
    77*/  
    88  
     
    1313class ImagesController extends AppController 
    1414{ 
    15     public $helpers       = array('Ajax', 'Form', 'User', 'Gags'); 
    16      
    17     public $components       = array('Security', 'Mypagination'); 
    18      
    19     public function admin_listing() 
     15    public $helpers       = array('Html', 'Javascript', 'Ajax', 'Form', 'User'); 
     16     
     17    public $components    = array('Security', 'Adds'); 
     18     
     19    public function index($id = null) 
     20    { 
     21        $this->pageTitle = 'View Active Users'; 
     22        $this->set('data', $this->User->findAll());  
     23        $this->set('color', 'blue'); 
     24    } 
     25     
     26    public function admin_listing($set = null) 
    2027    {    
    21         $this->layout    = 'admin'; 
    22          
     28        if ($set == null) 
     29        { 
     30             $this->layout    = 'admin'; 
     31             $limit           = 30; 
     32             $this->set('set', null); 
     33        } else { 
     34             $this->layout    = 'popup'; 
     35             $limit           = 15; 
     36             $this->set('set', true); 
     37        } 
    2338        $this->pageTitle = 'Your Images'; 
    2439         
     
    2944        $order      = "Image.id DESC"; 
    3045         
    31         $data       = $this->Image->findAll($conditions, $fields, $order, null, null, 1); 
     46        $data       = $this->Image->findAll($conditions, $fields, $order, $limit); 
    3247         
    3348        $this->set('data', $data); 
    34     } 
    35     
    36     public function admin_listview() 
    37     {    
    38         $this->layout    = 'popup'; 
    39          
    40         $this->pageTitle = 'Your Images'; 
    41          
    42         $conditions = array("user_id"=>$this->othAuth->user('id')); 
    43          
    44         $fields     = array("id", "file", "user_id"); 
    45          
    46         $order      = "Image.id DESC"; 
    47          
    48         $limit      = 20; 
    49          
    50         $data       = $this->Image->findAll($conditions, $fields, $order, null, null, 1); 
    51          
    52         $this->set('data', $data); 
    53          
    54         $this->set('listview', true); 
    5549    } 
    5650    
     
    8983     
    9084    $maxfilesize  = 2097152; /** 2MB max size */ 
     85     
     86    $this->Sanitize = new Sanitize; 
     87     
     88    $this->Sanitize->cleanArray($this->data); 
    9189     
    9290    $imgfile_name = $this->data['Image']['file']['name']; 
     
    108106        /** delete uploaded file  */ 
    109107        unlink($imgfile); 
    110         die($this->flash($ErrMsg,'/admin/images/listing/') ); 
     108        $this->flash($ErrMsg,'/admin/images/listing/'); 
     109        exit(); 
    111110    } 
    112111     
    113112    if ( $imgfile_size > $maxfilesize)  
    114113    { 
    115         $ErrMsg  = "<h1>ERROR</h1> The image is too big.<br>"; 
     114    $ErrMsg  = "<h1>ERROR</h1> The image is too big.<br>"; 
    116115         $ErrMsg .= "<p>Bigger than 2.0 MB <br><br>"; 
    117116         $ErrMsg .= "Current size: " . $imgfile_size ."</p>\n"; 
     
    119118        /** delete uploaded file */ 
    120119        unlink($imgfile); 
    121         die( $this->flash($ErrMsg,'/images/listing/') ); 
    122     } 
    123      
    124     $field       = "id"; 
    125      
    126     $conditions  = array("user_id" =>  $this->othAuth->user('id')); 
    127      
    128     $order       = "Image.id DESC"; 
    129      
    130     $current_id  = $this->Image->field($field, $conditions, $order); 
     120        $this->flash($ErrMsg,'/admin/images/listing/'); 
     121        exit(); 
     122    } 
     123     
     124    $current_id  = $this->Image->field("id", array("Image.id"=>"> 0"), "Image.id DESC"); 
    131125     
    132126    $next_id     = ($current_id + 1); 
    133127     
    134     $extension   = $this->get_extension($type); 
     128    $extension   = $this->Adds->get_extension($type); 
    135129     
    136130    $Name        = $this->othAuth->user('username') . "_" . $next_id . $extension; 
     
    140134    $final_filename = str_replace(" ", "_", $Name); 
    141135     
    142     $newfile = $uploaddir . "/" . $final_filename; 
     136    $newfile        = $uploaddir . "/" . $final_filename; 
    143137     
    144138    /** do extra security check to prevent malicious abuse */ 
     
    155149   } 
    156150    
     151   /*** Create thumb***/ 
     152    if ( $type != 'avatar') 
     153    { 
     154         $this->createThumb($final_filename); 
     155    } 
    157156   /** Database stuff  **/ 
    158157    
    159    $this->data['Image']['file'] = $final_filename; 
     158   $this->data['Image']['file']    = $final_filename; 
     159   $this->data['Image']['user_id'] = $this->othAuth->user('id'); 
    160160    
    161161   if ($this->Image->save($this->data)) 
    162    { 
    163            $this->redirect($this->data['Image']['return']); 
    164     } 
    165      
     162   {      
     163         $this->redirect($this->data['Image']['return']); 
     164         exit(); 
     165   } 
     166    
    166167    /** delete the temporary uploaded file **/ 
    167168    unlink($imgfile); 
    168     
    169169   } 
    170170} 
    171171 
    172 protected function get_extension($imagetype) { 
    173       
    174      if ( empty($imagetype) ) 
    175      { 
    176          return false; 
    177      } 
    178       
    179      switch($imagetype) 
    180      { 
    181            case 'image/bmp': return '.bmp'; 
    182            case 'image/cis-cod': return '.cod'; 
    183            case 'image/gif': return '.gif'; 
    184            case 'image/ief': return '.ief'; 
    185            case 'image/jpeg': return '.jpg'; 
    186            case 'image/pipeg': return '.jfif'; 
    187            case 'image/tiff': return '.tif'; 
    188            case 'image/x-cmu-raster': return '.ras'; 
    189            case 'image/x-cmx': return '.cmx'; 
    190            case 'image/x-icon': return '.ico'; 
    191            case 'image/x-portable-anymap': return '.pnm'; 
    192            case 'image/x-portable-bitmap': return '.pbm'; 
    193            case 'image/x-portable-graymap': return '.pgm'; 
    194            case 'image/x-portable-pixmap': return '.ppm'; 
    195            case 'image/x-rgb': return '.rgb'; 
    196            case 'image/x-xbitmap': return '.xbm'; 
    197            case 'image/x-xpixmap': return '.xpm'; 
    198            case 'image/x-xwindowdump': return '.xwd'; 
    199            case 'image/png': return '.png'; 
    200            case 'image/x-jps': return '.jps'; 
    201            case 'image/x-freehand': return '.fh'; 
    202            default: return false; 
    203        } 
     172  /*** DELETE  **/  
     173  public function admin_delete($id) 
     174  { 
     175    $file = $this->Image->field("Image.file", array("Image.id"=>$id)); 
     176     
     177    $this->Image->del($id); 
     178     
     179    /** delete image and thumb **/ 
     180    unlink("../webroot/img/imgusers/" . $file); 
     181    unlink("../webroot/img/imgusers/thumbs/" . $file); 
     182    $this->redirect($this->data['Image']['return']); 
    204183  } 
    205184   
    206   /*** DELETE  **/  
    207   public function admin_delete($id, $imgfile) 
     185  protected function createThumb($file)  
    208186  { 
    209     $this->Image->del($id); 
    210      
    211     /** delete the uploaded file **/ 
    212     $uploaddir    = "../webroot/img/imgusers/"; 
    213     unlink($uploaddir . $imgfile); 
    214     $this->flash('The image has been deleted.', '/admin/images/listing'); 
     187      
     188     $imgfile        = "../webroot/img/imgusers/"           .  $file;            // system path 
     189      
     190     //exit($imgfile); 
     191     $thumb_img      = "../webroot/img/imgusers/thumbs/"     .  $file;             // system path 
     192      
     193     $new_w          = 100;  //new width 
     194      
     195     /** only resize if the image is larger than 250 x 200 */ 
     196      
     197     $image_stats = getimagesize($imgfile);  // return array 
     198      
     199     $imagewidth  = $image_stats[0]; 
     200      
     201     $imageheight = $image_stats[1]; 
     202      
     203     $img_type    = $image_stats[2];   // 1 = GIF, 2 = JPG, 3 = PNG 
     204      
     205     $ratio       = ($imagewidth / $new_w); 
     206      
     207     $new_h       = round($imageheight / $ratio); 
     208      
     209     /*** Save bandwidth! generate thumbs **/ 
     210     if (!file_exists($thumb_img))  // thumb already exist??   
     211     { 
     212       switch ($img_type)  
     213       { 
     214         case 1; 
     215                   
     216                   $src_img = imagecreatefromgif($imgfile); 
     217                
     218               $dst_img = imagecreatetruecolor($new_w, $new_h); 
     219            
     220           imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h, $imagewidth, $imageheight); 
     221            
     222           imagegif($dst_img, $thumb_img, "100"); 
     223         break; 
     224          
     225         case 2; 
     226                
     227                   $src_img = imagecreatefromjpeg($imgfile); 
     228            
     229           $dst_img = imagecreatetruecolor($new_w, $new_h); 
     230            
     231           imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h, $imagewidth, $imageheight); 
     232            
     233           imagejpeg($dst_img, $thumb_img, "100"); 
     234         break; 
     235                
     236         case 3;    
     237                   $dst_img = imagecreatetruecolor($new_w, $new_h); 
     238                    
     239                   $src_img = ImageCreateFrompng($imgfile); 
     240                    
     241                   imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h, $imagewidth, $imageheight); 
     242                    
     243                   imagepng($dst_img, $thumb_img); 
     244         break; 
     245      } 
     246    } 
    215247  } 
    216    
    217248} 
    218249?> 
  • trunk/app/controllers/news_controller.php

    r35 r36  
    244244    
    245245   public function category($id = null, $order=null)  
    246    {    
     246   {   
     247      $this->layout = 'portal'; 
     248       
    247249      if ($id != null) 
    248250      { 
  • trunk/app/models/entry.php

    r1 r36  
    55{ 
    66    // Its always good practice to include this variable. 
    7     public $name      = 'Entry'; 
    8     public $belongsTo = 'User, Category'; 
     7     
     8    public $belongsTo = 'User, Subject'; 
     9     
    910    public $hasMany   = 'Comment'; 
    10      
    1111     
    1212    public $validate = array( 
  • trunk/app/models/subject.php

    r15 r36  
    99class Subject extends AppModel 
    1010{ 
    11     // Its always good practice to include this variable. 
    12     public $name        = 'Subject'; 
    1311     
    1412    public $hasMany = array('Vclassroom' => 
     
    3230                               'finderQuery'   => '' 
    3331                         ), 
    34                        'News' => 
    35                          array('className'     => 'News', 
     32                       'Entry' => 
     33                         array('className'     => 'Entry', 
    3634                               'conditions'    => null, 
    3735                               'order'         => null, 
  • trunk/app/views/entries/admin_add.thtml

    r14 r36  
    22<?php echo $javascript->link('fckeditor/fckeditor'); ?>  
    33 
    4 <div class="spaced"> 
    5  
    6 <?php echo $html->addCrumb('Control Tools', '/entries/index'); ?>  
    7 <?php echo $html->addCrumb('Entries', '/entries/listing'); ?>  
     4<?php echo $html->addCrumb('Control Tools', '/admin/entries/start'); ?>  
     5<?php echo $html->addCrumb('Entries', '/admin/entries/listing'); ?>  
    86<?php echo $html->getCrumbs(' / '); ?> 
    9  
    10 <?php echo $html->formTag('/entries/add/','post', array("onsubmit"=>"return validateEntry()")); ?> 
    11  
     7<?php echo $html->formTag('/admin/entries/add/','post', array("onsubmit"=>"return validateEntry()")); ?> 
    128<?php echo $html->hiddenTag('Entry/user_id', $othAuth->user('id')) ?> 
    139<fieldset> 
    1410<legend>New Entry</legend> 
    15   <?php echo $form->labelTag( 'Entry/title', 'Title' );?><br />  
    16   <?php echo $html->input('Entry/title', array("size" => 40, "maxlength" => 50)); ?> 
     11 
     12<table style="margin:0 auto 0 auto;"> 
     13<tr><td> 
     14   
     15  <?php echo $form->labelTag( 'Entry/title', 'Title:' );?><br />  
     16  <?php echo $html->input('Entry/title', array("size" => 50, "maxlength" => 50)); ?> 
    1717  <?php echo $html->tagErrorMsg('Entry/title', 'Title is required.'); ?> 
    18   <br /><br /> 
     18  </td> 
    1919   
    20   <p><?php echo $form->labelTag( 'Entry/category_id', 'Category' );?> 
    21   <br /> 
    22       <?php  
    23       /*$html->selectTag( 
    24       $fieldName, 
    25       $optionElements, 
    26       $selected = null, 
    27       $selectAttr = array(), 
    28       $optionAttr = null, 
    29       $showEmpty = true, 
    30       $return = false     
    31       selectTag ($fieldName, $optionElements, $selected=null, $selectAttr=array(), $optionAttr=null, $showEmpty=true, $return=false) 
    32       */ 
    33       echo $html->selectTag('Entry/category_id', $categories, null, $html->tagValue('Entry/category_id'), array("class"=>"formas"), false, false);  
     20  <td> 
     21     <?php echo $form->labelTag( 'Entry/subject_id', 'Subject:' );?><br /> 
     22     <?php  
     23      echo $html->selectTag('Entry/subject_id', $subjects, null, $html->tagValue('Entry/subject_id'), null, false, false);  
    3424       
    35       echo $html->link($html->image('static/add.png', array("alt"=>"Add category", "title"=>"Add category")), '#', array("onclick"=>"javascript:window.open('/categories/listing', 'blank', 'toolbar=no, scrollbars=yes,width=350,height=500')"), null, false); 
     25      /* echo $html->link($html->image('static/add.png', array("alt"=>"Add category", "title"=>"Add category")), '#', array("onclick"=>"javascript:window.open('/admin/categories/listing', 'blank', 'toolbar=no, scrollbars=yes,width=350,height=500')"), null, false);*/ 
    3626      ?> 
    37   </p> 
     27  </td> 
    3828   
    39   <p style="text-align:right;"> 
    40   <?php echo $html->link($html->image('admin/myimages.jpg', array("alt"=>"My Images", "title"=>"My Images")), '#', array("onclick"=>"javascript:window.open('/images/listview', 'blank', 'toolbar=no, scrollbars=yes,width=700,height=500')"), null, false) ?></p> 
    41   <p> 
     29  <td> 
     30  <?php echo $html->link($html->image('admin/myimages.jpg', array("alt"=>"My Images", "title"=>"My Images")), '#', array("onclick"=>"javascript:window.open('/admin/images/listing/set', 'blank', 'toolbar=no, scrollbars=yes,width=700,height=500')"), null, false) ?></p> 
     31  </td> 
     32  </tr> 
     33  <tr><td colspan="3"> 
    4234  <?php echo $form->labelTag( 'Entry/Body', 'Body:' );?><br /> 
    43   <?php echo $html->textarea('Entry/body', array("class"=>"formas", "cols"=>80, "rows"=>45)) ?> 
     35  <?php echo $html->textarea('Entry/body', array("class"=>"formas", "cols"=>80, "rows"=>55)) ?> 
    4436  <?php echo $fck->load('Entry/body', 'Karamelo'); ?>  
    4537  <?php echo $html->tagErrorMsg('Entry/body', 'Body is required.'); ?> 
    46   <br /> 
    47   </p> 
     38  </td></tr> 
    4839   
    49   <p><?php echo $form->labelTag( 'Entry/status', 'Published:' );?><br /> 
    50   <?php echo $html->checkbox('Entry/status'); ?> 
    51   <br /></p> 
     40  <tr> 
     41  <td> 
     42       <?php echo $form->labelTag( 'Entry/status', 'Published:' );?> 
     43       <?php echo $html->checkbox('Entry/status', null, array("value"=>1)); ?> 
     44  </td><td colspan="2"> 
     45     <?php echo $form->labelTag( 'Entry/disc', 'Comments allowed:' );?> 
     46     <?php echo $html->checkbox('Entry/disc', null, array("value"=>1)); ?> 
     47  </td></tr> 
    5248   
    53   <p><?php echo $form->labelTag( 'Entry/disc', 'Comments allowed:' );?><br /> 
    54   <?php echo $html->checkbox('Entry/disc'); ?> 
    55   <br /></p> 
    56     
    57   <br /> 
     49  <tr><td colspan="3"> 
    5850  <?php echo $html->submit('Add'); ?> 
     51</td></tr> 
     52</table> 
     53 
    5954</fieldset> 
    6055</form> 
    61 </div> 
  • trunk/app/views/helpers/fck.php

    r1 r36  
    22class FckHelper extends Helper 
    33{ 
    4    public function load($id, $toolbar = 'Karamelo', $width = 700) { 
     4   public function load($id, $toolbar = 'Karamelo', $width = 700, $height = 450) { 
    55         
    66        $did = ''; 
     
    1717bFCKeditor_$did.ToolbarSet = '$toolbar'; 
    1818bFCKeditor_$did.Width = $width; 
    19 bFCKeditor_$did.Height = 350; 
     19bFCKeditor_$did.Height = $height; 
    2020bFCKeditor_$did.Skin = 'silver'; 
    2121bFCKeditor_$did.ReplaceTextarea(); 
     
    2626    } 
    2727} 
    28 ?>  
     28?> 
  • trunk/app/views/layouts/popup.thtml

    r1 r36  
    55 <head> 
    66  <title>Karamelo: Control Panel</title> 
    7 <? 
     7<?php 
    88if (isset($javascript)): 
    99  echo $html->charsetTag('utf-8'); 
  • trunk/app/views/news/display.thtml

    r35 r36  
    1 <div id="cintillo">Noticias</div>