| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
function profile_photo_pagesetup() { |
|---|
| 4 |
} |
|---|
| 5 |
|
|---|
| 6 |
function profile_photo_init() { |
|---|
| 7 |
global $CFG; |
|---|
| 8 |
$CFG->display_field_module['profile_photo'] = "profile_photo"; |
|---|
| 9 |
listen_for_event("user","publish","profile_photo_user_publish"); |
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !isset($_POST['profiledetails']['profilephoto']) && isset($_POST['_profile_photo_name'])) |
|---|
| 13 |
{ |
|---|
| 14 |
$_POST['profiledetails']['profilephoto'] = $_POST['_profile_photo_name']; |
|---|
| 15 |
} |
|---|
| 16 |
} |
|---|
| 17 |
|
|---|
| 18 |
function profile_photo_user_publish($object_type, $event, $object) { |
|---|
| 19 |
global $data; |
|---|
| 20 |
if ($object_type == "user" && $event == "publish" && isset($data['profile:details']) && is_array($data['profile:details']) && !empty($data['profile:details'])) { |
|---|
| 21 |
foreach($data['profile:details'] as $profileitem) { |
|---|
| 22 |
if ($profileitem->field_type == "profile_photo") { |
|---|
| 23 |
$profile_data = new stdClass; |
|---|
| 24 |
$profile_data->access = "PUBLIC"; |
|---|
| 25 |
$profile_data->owner = $object->ident; |
|---|
| 26 |
$profile_data->name = $profileitem->internal_name; |
|---|
| 27 |
$profile_data->value = "photo"; |
|---|
| 28 |
} |
|---|
| 29 |
} |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
return $object; |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
function profile_photo_display_input_field($parameter) { |
|---|
| 36 |
global $CFG; |
|---|
| 37 |
$html = ""; |
|---|
| 38 |
if ($parameter[2] == "profile_photo") { |
|---|
| 39 |
$cleanid = ereg_replace("[^A-Za-z0-9_:\\.-]", "__", $parameter[0]); |
|---|
| 40 |
$file = get_record('profile_data','ident',$parameter[4]); |
|---|
| 41 |
if (!$file || $file->value == "photo") { |
|---|
| 42 |
unset($parameter[1]); |
|---|
| 43 |
} |
|---|
| 44 |
if (!empty($parameter[1])) { |
|---|
| 45 |
$html .= "<img src=\"{$CFG->wwwroot}mod/profile_photo/img.php?id={$parameter[4]}&constraint1=w&size1=250&constraint2=h&size2=200\" alt=\"Profile photo\" /><br />"; |
|---|
| 46 |
$html .= "<label for=\"$cleanid\"><input name=\"".$parameter[0]."\" type=\"checkbox\" id=\"$cleanid\" value=\"photo\" />"; |
|---|
| 47 |
$html .= __gettext("Click here to remove this photo."); |
|---|
| 48 |
$html .= "</label>"; |
|---|
| 49 |
$html .= '<input type="hidden" name="_profile_photo_name" value="'.$file->value.'"/>'; |
|---|
| 50 |
} else { |
|---|
| 51 |
$html .= "<input name=\"profile_photo_".$parameter[3]."\" type=\"file\" /><br />"; |
|---|
| 52 |
$html .= "<label for=\"$cleanid\"><input name=\"".$parameter[0]."\" type=\"checkbox\" id=\"$cleanid\" value=\"photo\" />"; |
|---|
| 53 |
$html .= __gettext("Click here to verify that this is a photo of you and that it is not obscene or abusive."); |
|---|
| 54 |
$html .= "</label>"; |
|---|
| 55 |
} |
|---|
| 56 |
} |
|---|
| 57 |
return $html; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
function profile_photo_display_output_field($parameter) { |
|---|
| 61 |
global $CFG, $profile_id; |
|---|
| 62 |
$html = ''; |
|---|
| 63 |
if ($parameter[1] == "profile_photo") { |
|---|
| 64 |
if (!empty($parameter[4]) && $parameter[0] != "photo") { |
|---|
| 65 |
$html .= "<img class=\"profile-photo\" src=\"{$CFG->wwwroot}mod/profile_photo/img.php?id={$parameter[4]}&constraint1=w&size1=250\" alt=\"Profile photo\" />"; |
|---|
| 66 |
} else { |
|---|
| 67 |
$pictureglyph = __gettext("Click here to upload a photo"); |
|---|
| 68 |
$html = <<< END |
|---|
| 69 |
</p> |
|---|
| 70 |
<style type="text/css"> |
|---|
| 71 |
div#default-profile-icon { |
|---|
| 72 |
width:250px; |
|---|
| 73 |
height:200px; |
|---|
| 74 |
background:url({$CFG->wwwroot}mod/profile_photo/default.gif) no-repeat; |
|---|
| 75 |
position:relative; |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
div#default-profile-icon p { |
|---|
| 79 |
position:absolute; |
|---|
| 80 |
top:150px; |
|---|
| 81 |
right:40px; |
|---|
| 82 |
margin:0; |
|---|
| 83 |
padding:0; |
|---|
| 84 |
color:#fff; |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
div#default-profile-icon p a { |
|---|
| 88 |
text-decoration:underline; |
|---|
| 89 |
color:#fff; |
|---|
| 90 |
} |
|---|
| 91 |
</style> |
|---|
| 92 |
|
|---|
| 93 |
<div id="default-profile-icon"> |
|---|
| 94 |
<p><a href="{$CFG->wwwroot}profile/edit.php?profile_id={$profile_id}">{$pictureglyph}</a></p> |
|---|
| 95 |
</div> |
|---|
| 96 |
<p> |
|---|
| 97 |
END; |
|---|
| 98 |
|
|---|
| 99 |
} |
|---|
| 100 |
} |
|---|
| 101 |
return $html; |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
function profile_photo_validate_input_field($parameter) { |
|---|
| 105 |
global $CFG, $messages, $data, $profile_id; |
|---|
| 106 |
|
|---|
| 107 |
$found = false; |
|---|
| 108 |
|
|---|
| 109 |
foreach($data['profile:details'] as $profileitem) { |
|---|
| 110 |
if (is_array($profileitem)) { |
|---|
| 111 |
$fname = $profileitem[1]; |
|---|
| 112 |
$ftype = $profileitem[2]; |
|---|
| 113 |
} else { |
|---|
| 114 |
$fname = $profileitem->internal_name; |
|---|
| 115 |
$ftype = $profileitem->field_type; |
|---|
| 116 |
} |
|---|
| 117 |
if ($fname == $parameter->name) { |
|---|
| 118 |
$found = true; |
|---|
| 119 |
break; |
|---|
| 120 |
} |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
if ($found && $ftype = "profile_photo") { |
|---|
| 124 |
require_once($CFG->dirroot.'lib/uploadlib.php'); |
|---|
| 125 |
require_once($CFG->dirroot.'lib/filelib.php'); |
|---|
| 126 |
$textlib = textlib_get_instance(); |
|---|
| 127 |
$upload_folder = $textlib->substr(user_info("username", $profile_id),0,1); |
|---|
| 128 |
$um = new upload_manager('profile_photo_'.$fname,true,true,false,5000000,true); |
|---|
| 129 |
$reldir = "profile_photos/" . $upload_folder . "/" . user_info("username", $profile_id) . "/" . $parameter->name . "/"; |
|---|
| 130 |
$dir = $CFG->dataroot .$reldir; |
|---|
| 131 |
if ($um->process_file_uploads($dir)) { |
|---|
| 132 |
$parameter->value = $reldir . $um->get_new_filename(); |
|---|
| 133 |
update_record('profile_data',$parameter); |
|---|
| 134 |
} else { |
|---|
| 135 |
$messages[] = $um->get_errors(); |
|---|
| 136 |
} |
|---|
| 137 |
} |
|---|
| 138 |
|
|---|
| 139 |
return true; |
|---|
| 140 |
} |
|---|
| 141 |
|
|---|
| 142 |
?> |
|---|
| 143 |
|
|---|