From 2858af42407619fac47f45dc209bda66c834a68f Mon Sep 17 00:00:00 2001 From: robertall Date: Fri, 30 May 2008 02:03:39 +0000 Subject: [PATCH] [MDL-8407] Add new function text_export_supported() or export_text_value() to those "mod/data/field/*/field.class.php" files which need them. The existing code formatting has been cleaned up, too. Merged from MOODLE_19_STABLE. --- mod/data/field/file/field.class.php | 58 +++++-------- mod/data/field/latlong/field.class.php | 93 ++++++++++---------- mod/data/field/picture/field.class.php | 112 +++++++++++-------------- mod/data/field/url/field.class.php | 53 ++++++------ 4 files changed, 143 insertions(+), 173 deletions(-) diff --git a/mod/data/field/file/field.class.php b/mod/data/field/file/field.class.php index 4837e4e27f..b0e2aa809d 100755 --- a/mod/data/field/file/field.class.php +++ b/mod/data/field/file/field.class.php @@ -23,7 +23,6 @@ /////////////////////////////////////////////////////////////////////////// class data_field_file extends data_field_base { - var $type = 'file'; function data_field_file($field=0, $data=0) { @@ -32,7 +31,6 @@ class data_field_file extends data_field_base { function display_add_field($recordid=0) { global $CFG; - if ($recordid){ if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { $contents[0] = $content->content; @@ -41,13 +39,10 @@ class data_field_file extends data_field_base { $contents[0] = ''; $contents[1] = ''; } - $src = empty($contents[0]) ? '' : $contents[0]; $name = empty($contents[1]) ? $src : $contents[1]; $displayname = empty($contents[1]) ? '' : $contents[1]; - $path = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid; - if ($CFG->slasharguments) { $source = $CFG->wwwroot.'/file.php/'.$path; } else { @@ -59,7 +54,6 @@ class data_field_file extends data_field_base { $displayname = ''; $source = ''; } - $str = '
'; $str .= '
'.$this->field->name.''; $str .= ''; @@ -70,8 +64,8 @@ class data_field_file extends data_field_base { $str .= ''; $str .= '
'; $str .= '
'; - - if ($recordid and isset($content) and !empty($content->content)){ // Print icon + if ($recordid and isset($content) and !empty($content->content)) { + // Print icon require_once($CFG->libdir.'/filelib.php'); $icon = mimeinfo('icon', $src); $str .= ''.$icon.''. @@ -81,54 +75,43 @@ class data_field_file extends data_field_base { } function display_search_field($value = '') { - return ''; + return ''; } - + function generate_sql($tablealias, $value) { - return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') "; + return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') "; } - function parse_search_field() { return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS); } function display_browse_field($recordid, $template) { - global $CFG; - if (!$content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { return false; } - $width = $this->field->param1 ? ' width = "'.s($this->field->param1).'" ':' '; $height = $this->field->param2 ? ' height = "'.s($this->field->param2).'" ':' '; - if (empty($content->content)) { return ''; } - require_once($CFG->libdir.'/filelib.php'); - $src = $content->content; $name = empty($content->content1) ? $src : $content->content1; - $source = get_file_url($this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid); - $icon = mimeinfo('icon', $src); $str = ''.$icon.' '. ''.$name.''; - return $str; } -/// content = a ## b where a is the filename, b is the display file name + // content: "a##b" where a is the file name, b is the display name function update_content($recordid, $value, $name) { global $CFG; - if (!$oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) { - /// Quickly make one now! + // Quickly make one now! $oldcontent = new object; $oldcontent->fieldid = $this->field->id; $oldcontent->recordid = $recordid; @@ -136,23 +119,20 @@ class data_field_file extends data_field_base { print_error('cannotinsertempty', 'data'); } } - $content = new object; $content->id = $oldcontent->id; - $names = explode('_',$name); switch ($names[2]) { - case 'file': //file just uploaded - //$course = get_course('course', 'id', $this->data->course); - + case 'file': + // file just uploaded +# $course = get_course('course', 'id', $this->data->course); $filename = $_FILES[$names[0].'_'.$names[1]]; $filename = $filename['name']; $dir = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid; - - //only use the manager if file is present, to avoid "are you sure you selected a file to upload" msg + // only use the manager if file is present, to avoid "are you sure you selected a file to upload" msg if ($filename){ require_once($CFG->libdir.'/uploadlib.php'); - //FIX ME: $course not defined heer!! + // FIX ME: $course not defined here $um = new upload_manager($names[0].'_'.$names[1],true,false,$this->data->course,false,$this->field->param3); if ($um->process_file_uploads($dir)) { $newfile_name = $um->get_new_filename(); @@ -162,7 +142,8 @@ class data_field_file extends data_field_base { } break; - case 'filename': //only changing alt tag + case 'filename': + // only changing alt tag $content->content1 = clean_param($value, PARAM_NOTAGS); update_record('data_content', $content); break; @@ -172,15 +153,20 @@ class data_field_file extends data_field_base { } } - function notemptyfield($value, $name){ + function notemptyfield($value, $name) { $names = explode('_',$name); - if ($names[2] == 'file'){ + if ($names[2] == 'file') { $filename = $_FILES[$names[0].'_'.$names[1]]; - return !empty($filename['name']); //if there's a file in $_FILES, not empty + return !empty($filename['name']); + // if there's a file in $_FILES, not empty } return false; } + function text_export_supported() { + return false; + } + } ?> diff --git a/mod/data/field/latlong/field.class.php b/mod/data/field/latlong/field.class.php index b9e4e9d988..9d7b734f4e 100755 --- a/mod/data/field/latlong/field.class.php +++ b/mod/data/field/latlong/field.class.php @@ -1,4 +1,4 @@ - "http://maps.google.com/maps?q=@lat@,+@long@&iwloc=A&hl=en", "Google Earth" => "@wwwroot@/mod/data/field/latlong/kml.php?d=@dataid@&fieldid=@fieldid@&rid=@recordid@", "Geabios" => "http://www.geabios.com/html/services/maps/PublicMap.htm?lat=@lat@&lon=@long@&fov=0.3&title=Moodle%20data%20item", "OpenStreetMap" => "http://www.openstreetmap.org/index.html?lat=@lat@&lon=@long@&zoom=11", "Multimap" => "http://www.multimap.com/map/browse.cgi?scale=200000&lon=@long@&lat=@lat@&icon=x" - ); + ); // Other map sources listed at http://kvaleberg.com/extensions/mapsources/index.php?params=51_30.4167_N_0_7.65_W_region:earth - - - // Parameter data used: - // "param1" is a comma-separated list of the linkout service names that are enabled for this instance - // "param2" indicates the label that will be used in generating Google Earth KML files: -1 for item #, -2 for lat/long, positive number for the (text) field to use. - - - function data_field_latlong($field=0, $data=0) { parent::data_field_base($field, $data); } - function display_add_field($recordid=0){ + function display_add_field($recordid=0) { global $CFG; - $lat = ''; $long = ''; - - if ($recordid){ + if ($recordid) { if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { $lat = $content->content; $long = $content->content1; } } - $str = '
'; $str .= '
'.$this->field->name.''; $str .= '
'; @@ -72,60 +65,56 @@ class data_field_latlong extends data_field_base { $str .= '
'; $str .= '
'; $str .= '
'; - return $str; } - + function display_search_field($value = '') { global $CFG; $lats = get_records_sql_menu('SELECT id, content from '.$CFG->prefix.'data_content WHERE fieldid='.$this->field->id.' GROUP BY content ORDER BY content'); $longs = get_records_sql_menu('SELECT id, content1 from '.$CFG->prefix.'data_content WHERE fieldid='.$this->field->id.' GROUP BY content ORDER BY content'); $options = array(); if(!empty($lats) && !empty($longs)) { - $options[''] = ''; //Make first index blank. + $options[''] = ''; + // Make first index blank. foreach($lats as $key => $temp) { $options[$temp.','.$longs[$key]] = $temp.','.$longs[$key]; } } return choose_from_menu($options, 'f_'.$this->field->id, $value, 'choose', '', 0, true); } - + function parse_search_field() { return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS); } - + function generate_sql($tablealias, $value) { $latlong[0] = ''; $latlong[1] = ''; $latlong = explode (',', $value, 2); - return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$latlong[0]' AND {$tablealias}.content1 = '$latlong[1]') "; + return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$latlong[0]' AND {$tablealias}.content1 = '$latlong[1]') "; } function display_browse_field($recordid, $template) { global $CFG; - if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){ + if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { $lat = empty($content->content)? '':$content->content; $long = empty($content->content1)? '':$content->content1; - if (empty($lat) or empty($long)) { return ''; } - - if($lat < 0) { - $compasslat = "" . sprintf('%01.4f', 0 - $lat) . '°S'; - } else { - $compasslat = "" . sprintf('%01.4f', $lat) . "°N"; - } - if($long < 0) { - $compasslong = "" . sprintf('%01.4f', 0 - $long) . '°W'; - } else { - $compasslong = "" . sprintf('%01.4f', $long) . "°E"; - } - + if($lat < 0) { + $compasslat = "" . sprintf('%01.4f', 0 - $lat) . '°S'; + } else { + $compasslat = "" . sprintf('%01.4f', $lat) . "°N"; + } + if($long < 0) { + $compasslong = "" . sprintf('%01.4f', 0 - $long) . '°W'; + } else { + $compasslong = "" . sprintf('%01.4f', $long) . "°E"; + } $str = '
'; $str.= "$compasslat, $compasslong"; - // Now let's create the jump-to-services link $servicesshown = explode(',', $this->field->param1); @@ -139,7 +128,7 @@ class data_field_latlong extends data_field_base { '@courseid@'=> $this->data->course, '@fieldid@'=> $content->fieldid, '@recordid@'=> $content->recordid, - ); + ); if(sizeof($servicesshown)==1 && $servicesshown[0]) { $str .= " $servicesshown[0] "; } elseif (sizeof($servicesshown)>1) { $str .= "\n'; @@ -64,7 +58,7 @@ class data_field_picture extends data_field_file { $str .= ' 
'; $str .= ''; - if ($filepath){ + if ($filepath) { $str .= ''; } $str .= ''; @@ -73,37 +67,33 @@ class data_field_picture extends data_field_file { } function display_search_field($value = '') { - return ''; + return ''; } function parse_search_field() { return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS); } - + function generate_sql($tablealias, $value) { - return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') "; + return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') "; } function display_browse_field($recordid, $template) { global $CFG; - if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){ - if (isset($content->content)){ + if (isset($content->content)) { $contents[0] = $content->content; $contents[1] = $content->content1; } - - if (empty($contents[0])) { // Nothing to show + if (empty($contents[0])) { + // Nothing to show return ''; } - $alt = empty($contents[1])? '':$contents[1]; $title = empty($contents[1])? '':$contents[1]; $src = $contents[0]; - $path = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid; $thumbnaillocation = $CFG->dataroot .'/'.$this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid.'/thumb/'.$src; - if ($CFG->slasharguments) { $source = $CFG->wwwroot.'/file.php/'.$path.'/'.$src; $thumbnailsource = file_exists($thumbnaillocation) ? $CFG->wwwroot.'/file.php/'.$path.'/thumb/'.$src : $source; @@ -128,10 +118,8 @@ class data_field_picture extends data_field_file { } function update_field() { - // Get the old field data so that we can check whether the thumbnail dimensions have changed $oldfield = get_record('data_fields', 'id', $this->field->id); - if (!update_record('data_fields', $this->field)) { notify('updating of new field failed!'); return false; @@ -139,16 +127,17 @@ class data_field_picture extends data_field_file { // Have the thumbnail dimensions changed? if ($oldfield && ($oldfield->param4 != $this->field->param4 || $oldfield->param5 != $this->field->param5)) { - // Check through all existing records and update the thumbnail if ($contents = get_records('data_content', 'fieldid', $this->field->id)) { if (count($contents) > 20) { notify(get_string('resizingimages', 'data'), 'notifysuccess'); - echo "\n\n"; // To make sure that ob_flush() has the desired effect + echo "\n\n"; + // To make sure that ob_flush() has the desired effect ob_flush(); } foreach ($contents as $content) { - @set_time_limit(300); // Might be slow! + @set_time_limit(300); + // Might be slow! $this->update_thumbnail($content); } } @@ -158,22 +147,17 @@ class data_field_picture extends data_field_file { function update_content($recordid, $value, $name) { parent::update_content($recordid, $value, $name); - $content = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid); - - $this->update_thumbnail($content); // Regenerate the thumbnail + $this->update_thumbnail($content); + // Regenerate the thumbnail } - /** - * (Re)generate thumbnail image according to the dimensions specified in the field settings. - * If thumbnail width and height are BOTH not specified then no thumbnail is generated, and - * additionally an attempted delete of the existing thumbnail takes place. - */ function update_thumbnail($content) { + // (Re)generate thumbnail image according to the dimensions specified in the field settings. + // If thumbnail width and height are BOTH not specified then no thumbnail is generated, and + // additionally an attempted delete of the existing thumbnail takes place. global $CFG; - require_once($CFG->libdir . '/gdlib.php'); - $datalocation = $CFG->dataroot .'/'.$this->data->course.'/'.$CFG->moddata.'/data/'. $this->data->id.'/'.$this->field->id.'/'.$content->recordid; $originalfile = $datalocation.'/'.$content->content; @@ -181,18 +165,18 @@ class data_field_picture extends data_field_file { return; } if (!file_exists($datalocation.'/thumb')) { - mkdir($datalocation.'/thumb', 0777); + mkdir($datalocation.'/thumb', 0777); + // robertall: Why hardcode 0777?? } $thumbnaillocation = $datalocation.'/thumb/'.$content->content; $imageinfo = GetImageSize($originalfile); $image->width = $imageinfo[0]; $image->height = $imageinfo[1]; $image->type = $imageinfo[2]; - - if (!$image->width || !$image->height) { // Should not happen + if (!$image->width || !$image->height) { + // Should not happen return; } - switch ($image->type) { case 1: if (function_exists('ImageCreateFromGIF')) { @@ -216,42 +200,40 @@ class data_field_picture extends data_field_file { } break; } - - // fix for MDL-7270 $thumbwidth = isset($this->field->param4)?$this->field->param4:''; $thumbheight = isset($this->field->param5)?$this->field->param5:''; - - if ($thumbwidth || $thumbheight) { // Only if either width OR height specified do we want a thumbnail - + if ($thumbwidth || $thumbheight) { + // Only if either width OR height specified do we want a thumbnail $wcrop = $image->width; $hcrop = $image->height; - if ($thumbwidth && !$thumbheight) { $thumbheight = $image->height * $thumbwidth / $image->width; } else if($thumbheight && !$thumbwidth) { $thumbwidth = $image->width * $thumbheight / $image->height; - } else { // BOTH are set - may need to crop if aspect ratio differs + } else { + // BOTH are set - may need to crop if aspect ratio differs $hratio = $image->height / $thumbheight; $wratio = $image->width / $thumbwidth; - if ($wratio > $hratio) { // Crop the width + if ($wratio > $hratio) { + // Crop the width $wcrop = intval($thumbwidth * $hratio); - } elseif($hratio > $wratio) { // Crop the height + } elseif($hratio > $wratio) { + //Crop the height $hcrop = intval($thumbheight * $wratio); } } // At this point both $thumbwidth and $thumbheight are set, and $wcrop and $hcrop + if (function_exists('ImageCreateTrueColor') and $CFG->gdversion >= 2) { $im1 = ImageCreateTrueColor($thumbwidth,$thumbheight); } else { $im1 = ImageCreate($thumbwidth,$thumbheight); } - - // Prevent alpha blending for PNG images if ($image->type == 3) { + // Prevent alpha blending for PNG images imagealphablending($im1, false); } - $cx = $image->width / 2; $cy = $image->height / 2; @@ -261,28 +243,36 @@ class data_field_picture extends data_field_file { ImageCopyBicubic($im1, $im, 0, 0, $cx-$halfwidth, $cy-$halfheight, $thumbwidth, $thumbheight, $halfwidth*2, $halfheight*2); - - // Save alpha transparency for PNG images + if ($image->type == 3) { + // Save alpha transparency for PNG images imagesavealpha($im1, true); } - if (function_exists('ImageJpeg') && $image->type != 3) { - @touch($thumbnaillocation); // Helps in Safe mode + @touch($thumbnaillocation); + // Helps in Safe mode if (ImageJpeg($im1, $thumbnaillocation, 90)) { @chmod($thumbnaillocation, 0666); + // robertall: Why hardcode 0666?? } } elseif (function_exists('ImagePng') && $image->type == 3) { - @touch($thumbnaillocation); // Helps in Safe mode + @touch($thumbnaillocation); + // Helps in Safe mode if (ImagePng($im1, $thumbnaillocation, 9)) { @chmod($thumbnaillocation, 0666); - } + // robertall: Why hardcode 0666?? + } } - - } else { // Try and remove the thumbnail - we don't want thumbnailing active + } else { + // Try to remove the thumbnail - we don't want thumbnailing active @unlink($thumbnaillocation); } } + + function text_export_supported() { + return false; + } + } ?> diff --git a/mod/data/field/url/field.class.php b/mod/data/field/url/field.class.php index 23c9138b4d..6754af116f 100755 --- a/mod/data/field/url/field.class.php +++ b/mod/data/field/url/field.class.php @@ -23,67 +23,62 @@ /////////////////////////////////////////////////////////////////////////// class data_field_url extends data_field_base { - var $type = 'url'; function data_field_text($field=0, $data=0) { parent::data_field_base($field, $data); } - function display_add_field($recordid=0){ + function display_add_field($recordid=0) { global $CFG; - $url = ''; $text = ''; - - if ($recordid){ + if ($recordid) { if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { $url = $content->content; $text = $content->content1; } } - $url = empty($url) ? 'http://' : $url; - + $url = empty($url) ? 'http://' : $url; $str = '
'; if (!empty($this->field->param1) and empty($this->field->param2)) { $str .= ''; $str .= ''; $str .= '
'; $str .= get_string('url','data').':
'.get_string('text','data').':
'; - } else { // Just the URL field + } else { + // Just the URL field $str .= ''; } $str .= '
'; - return $str; } function display_search_field($value = '') { - return ''; + return ''; } - + function parse_search_field() { return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS); } - + function generate_sql($tablealias, $value) { - return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') "; + return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') "; } function display_browse_field($recordid, $template) { - if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){ + if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { $url = empty($content->content)? '':$content->content; $text = empty($content->content1)? '':$content->content1; - if (empty($url) or ($url == 'http://')) { return ''; } - - if (!empty($this->field->param2)) { // param2 forces the text to something + if (!empty($this->field->param2)) { + // param2 forces the text to something $text = $this->field->param2; } - - if ($this->field->param1) { // param1 defines whether we want to autolink the url. + if ($this->field->param1) { + // param1 defines whether we want to autolink the url. if (!empty($text)) { $str = ''.$text.''; } else { @@ -101,13 +96,14 @@ class data_field_url extends data_field_base { $content = new object; $content->fieldid = $this->field->id; $content->recordid = $recordid; - $names = explode('_', $name); - switch ($names[2]){ - case 0: // update link + switch ($names[2]) { + case 0: + // update link $content->content = clean_param($value, PARAM_URL); break; - case 1: // add text + case 1: + // add text $content->content1 = clean_param($value, PARAM_NOTAGS); break; default: @@ -122,15 +118,20 @@ class data_field_url extends data_field_base { } } - function notemptyfield($value, $name){ + function notemptyfield($value, $name) { $names = explode('_',$name); - $value = clean_param($value, PARAM_URL); //clean first - if ($names[2] == '0'){ + $value = clean_param($value, PARAM_URL); + //clean first + if ($names[2] == '0') { return ($value!='http://' && !empty($value)); } return false; } + function export_text_value($record) { + return $record->content . " " . $record->content1; + } + } ?> -- 2.39.5