Xataface AJAX Upload Module 0.1
jQuery Ajax Upload Widget for Xataface
/Applications/XAMPP/xamppfiles/htdocs/nanofabrication/modules/ajax_upload/widget.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  * Xataface Ajax Upload Module
00004  * Copyright (C) 2011  Steve Hannah <steve@weblite.ca>
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the
00018  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
00019  * Boston, MA  02110-1301, USA.
00020  *
00021  */
00034 class Dataface_FormTool_ajax_upload  {
00035 
00047         function &buildWidget(&$record, &$field, &$form, $formFieldName, $new=false){
00048                 $factory = Dataface_FormTool::factory();
00049                 $mt = Dataface_ModuleTool::getInstance();
00050                 $mod = $mt->loadModule('modules_ajax_upload');
00051                 //$atts = $el->getAttributes();
00052                 $widget =& $field['widget'];
00053                 $atts = array();
00054                 if ( !@$atts['class'] ) $atts['class'] = '';
00055                 $atts['class'] .= ' xf-ajax-upload';
00056                 if ( !@$atts['data-xf-table'] ){
00057                         $atts['data-xf-table'] = $field['tablename'];
00058                 }
00059                 $atts['data-xf-max-file-size'] = $this->getMaxFileUploadSize($field);
00060                 if ( @$field['allowed_extensions'] ){
00061                         $atts['data-xf-allowed-extensions'] = $field['allowed_extensions'];
00062                 }
00063                 if ( @$field['allowed_mimetypes'] ){
00064                         $atts['data-xf-allowed-mimetypes'] = $field['allowed_mimetypes'];
00065                 }
00066                 
00067                 if ( @$field['disallowed_mimetypes'] ){
00068                         $atts['data-xf-disallowed-mimetypes'] = $field['disallowed_mimetypes'];
00069                 }
00070                 
00071                 if (@$field['disallowed_extensions'] ){
00072                         $atts['data-xf-disallowed-extensions'] = $field['disallowed_extensions'];
00073                 }
00074                 
00075                 $thumbnailWidth = 128;
00076                 if ( @$widget['thumbnail_width'] ) $thumbnailWidth = intval($widget['thumbnail_width']);
00077                 
00078                 $thumbnailHeight = 128;
00079                 if ( @$widget['thumbnail_height'] ) $thumbnailHeight = intval($widget['thumbnail_height']);
00080                 
00081                 $atts['data-xf-thumbnail-width'] = $thumbnailWidth;
00082                 $atts['data-xf-thumbnail-height'] = $thumbnailHeight;
00083                 
00084                 
00085                 $savepath = $field['savepath'];
00086                 $s = DIRECTORY_SEPARATOR;
00087                 $fval = $record->val($field['name']);
00088                 if ( $fval ){
00089                         $fpath = $savepath.$s.basename($fval);
00090                         if ( file_exists($fpath) ){
00091                                 $atts['data-xf-file-size'] = filesize($fpath);
00092                         }
00093                 
00094                 }
00095                 
00096                 
00097                 
00098                 $jt = Dataface_JavascriptTool::getInstance();
00099                 $jt->addPath(dirname(__FILE__).'/js', $mod->getBaseURL().'/js');
00100                 
00101                 $ct = Dataface_CSSTool::getInstance();
00102                 $ct->addPath(dirname(__FILE__).'/css', $mod->getBaseURL().'/css');
00103                 
00104                 // Add our javascript
00105                 $jt->import('xataface/modules/ajax_upload/ajax_upload.js');
00106                 
00107                 
00108                 
00109                 //$el->setAttributes($atts);
00110                 $el = $factory->addElement('text', $formFieldName, $widget['label'], $atts);
00111                 if ( PEAR::isError($el) ) throw new Exception($el->getMessage(), $el->getCode());
00112                 
00113         
00114                 return $el;
00115         }
00116         
00117         
00118         function getMaxFileUploadSize(&$field){
00119                 $max_upload = (int)(ini_get('upload_max_filesize'));
00120                 $max_post = (int)(ini_get('post_max_size'));
00121                 $memory_limit = (int)(ini_get('memory_limit'));
00122                 $upload_mb = min($max_upload, $max_post, $memory_limit);
00123                 //echo "Upload MB: ".$upload_mb;
00124                 $upload_bytes = $upload_mb*1000*1024;
00125                 if ( @$field['max_size'] ){
00126                         $upload_bytes = min(intval($field['max_size']), $upload_bytes);
00127                 }
00128                 return $upload_bytes;
00129         
00130         }
00131         
00132 
00133 }
 All Data Structures Files Functions Variables