/** * * * @param moscomprofilerFields $field * @param moscomprofilerUser $user * @param string $reason 'profile' for user profile view, 'edit' for profile edit, 'register' for registration, 'list' for user-lists * @param boolean $displayFieldIcons * @return string HTML: <tag type="$type" value="$value" xxxx="xxx" yy="y" /> */ function _htmlEditForm(&$field, &$user, $reason, $displayFieldIcons = true) { global $_CB_framework, $_CB_database, $ueConfig; if ($field->name == 'avatar' && !($ueConfig['allowAvatarUpload'] || $ueConfig['allowAvatarGallery'])) { return null; } $name = $field->name; $nameapproved = $field->name . 'approved'; $required = $this->_isRequired($field, $user, $reason); $existingAvatar = false; if ($user && $user->id) { // we can not trust the following, as if another field did error out, it's wrong: // $existingAvatar = ( $user->$name != null ); // so load from database: $realDatabaseUser = new moscomprofilerUser($_CB_database); if ($realDatabaseUser->load((int) $user->id)) { $existingAvatar = $realDatabaseUser->{$name} != null; } } $html = '<div>'; $choices = array(); if ($reason == 'register' || $reason == 'edit' && $user->id == 0) { if ($required == 0) { $choices[] = moscomprofilerHTML::makeOption('', _UE_AVATAR_NONE); } } else { if ($existingAvatar || $required == 0) { $choices[] = moscomprofilerHTML::makeOption('', _UE_AVATAR_NO_CHANGE); } } if ($name != 'avatar' || $ueConfig['allowAvatarUpload']) { $choices[] = moscomprofilerHTML::makeOption('upload', $existingAvatar ? _UE_AVATAR_UPLOAD_NEW : _UE_AVATAR_UPLOAD); } if ($name == 'avatar' && $ueConfig['allowAvatarGallery']) { $choices[] = moscomprofilerHTML::makeOption('gallery', _UE_AVATAR_SELECT); } if ($_CB_framework->getUi() == 2 && $existingAvatar && $user->{$nameapproved} == 0) { $choices[] = moscomprofilerHTML::makeOption('approve', _UE_APPROVE_IMAGE); } if ($existingAvatar && $required == 0) { $choices[] = moscomprofilerHTML::makeOption('delete', _UE_DELETE_AVATAR); } $html .= '<div>'; if ($reason != 'register' && $user->id != 0 && $existingAvatar) { $html .= $this->_avatarHtml($field, $user, $reason) . ' '; } if ($reason == 'edit' && $existingAvatar && $user->{$nameapproved} == 0 && isModerator($_CB_framework->myId())) { $html .= $this->_avatarHtml($field, $user, $reason, false, 10) . ' '; } if (count($choices) > 1) { $additional = ' class="inputbox"'; if ($_CB_framework->getUi() == 1 && $reason == 'edit' && $field->readonly) { $additional .= ' disabled="disabled"'; } $html .= moscomprofilerHTML::selectList($choices, $name . '__choice', $additional, 'value', 'text', '', $required, true, false); /* $js = " $('#cbimg_upload_" . $name . ",#cbimg_gallery_" . $name . "').hide();" . "\n $('#" . $name . "__choice').click( function() {" . "\n var choice = $(this).val();" . "\n if ( choice == '' ) {" . "\n $('#cbimg_upload_" . $name . "').slideUp('slow');" . "\n $('#cbimg_gallery_" . $name . "').slideUp('slow');" . "\n } else if ( choice == 'upload' ) {" . "\n $('#cbimg_upload_" . $name . "').slideDown('slow');" . "\n $('#cbimg_gallery_" . $name . "').slideUp('slow');" . "\n } else if ( choice == 'gallery' ) {" . "\n $('#cbimg_upload_" . $name . "').slideUp('slow');" . "\n $('#cbimg_gallery_" . $name . "').slideDown('slow');" . "\n }" . "\n } ).click();" ; */ static $functOut = false; if (!$functOut) { $js = "function cbslideImage(choice,uplodid,galleryid) {" . "\n\tif ( ( choice == '' ) || ( choice == 'approve' ) || ( choice == 'delete' ) ) {" . "\n\t\t\$(uplodid).slideUp('slow');" . "\n\t\t\$(galleryid).slideUp('slow');" . "\n\t} else if ( choice == 'upload' ) {" . "\n\t\t\$(uplodid).slideDown('slow');" . "\n\t\t\$(galleryid).slideUp('slow');" . "\n\t} else if ( choice == 'gallery' ) {" . "\n\t\t\$(uplodid).slideUp('slow');" . "\n\t\t\$(galleryid).slideDown('slow');" . "\n\t}" . "\n}"; $_CB_framework->outputCbJQuery($js); $functOut = true; } $js = "\$('#cbimg_upload_" . $name . ",#cbimg_gallery_" . $name . "').hide();" . "\n\t{" . "\n\t \$('#" . $name . "__choice').click( function() {" . "\n\t\tcbslideImage( \$(this).val(), '#cbimg_upload_" . $name . "', '#cbimg_gallery_" . $name . "' );" . "\n\t } ).click();" . "\n\t \$('#" . $name . "__choice').change( function() {" . "\n\t\tcbslideImage( \$(this).val(), '#cbimg_upload_" . $name . "', '#cbimg_gallery_" . $name . "' );" . "\n\t } );" . "\n\t}"; $_CB_framework->outputCbJQuery($js); } else { $html .= '<input type="hidden" name="' . $name . '__choice" value="' . $choices[0]->value . '" />'; } $html .= $this->_fieldIconsHtml($field, $user, 'htmledit', $reason, 'select', '', null, '', array(), $displayFieldIcons, $required); $html .= '</div>'; if ($name != 'avatar' || $ueConfig['allowAvatarUpload']) { $button = $reason == 'register' ? _UE_REGISTER : ($_CB_framework->getUi() == 2 ? _UE_SAVE : _UE_UPDATE); $saveFieldName = $field->name; $saveFieldRequired = $field->required; $field->name .= '__file'; if ($field->required && $user && isset($user->{$saveFieldName}) && $user->{$saveFieldName}) { $field->required = 0; } $html .= '<div id="cbimg_upload_' . $name . '">' . '<p>' . sprintf(_UE_UPLOAD_DIMENSIONS_AVATAR, $this->_getImageFieldParam($field, 'avatarWidth'), $this->_getImageFieldParam($field, 'avatarHeight'), $this->_getImageFieldParam($field, 'avatarSize')) . '</p>' . '<div>' . _UE_UPLOAD_SELECT_FILE . ' ' . '<input type="file" name="' . $name . '__file" value="" class="inputbox" />' . '</div>' . '<p>' . ($ueConfig['reg_enable_toc'] ? sprintf(_UE_AVATAR_DISCLAIMER_TERMS, $button, "<a href='" . cbSef(htmlspecialchars($ueConfig['reg_toc_url'])) . "' target='_BLANK'> " . _UE_AVATAR_TOC_LINK . "</a>") : sprintf(_UE_AVATAR_DISCLAIMER, $button)) . '</p>' . '</div>'; $field->name = $saveFieldName; $field->required = $saveFieldRequired; } if ($name == 'avatar' && $ueConfig['allowAvatarGallery']) { $live_site = $_CB_framework->getCfg('live_site'); $avatar_gallery_path = $_CB_framework->getCfg('absolute_path') . '/images/comprofiler/gallery'; $avatar_images = array(); $avatar_images = display_avatar_gallery($avatar_gallery_path); $html .= '<div id="cbimg_gallery_' . $name . '">' . "\n\t<table width='100%' border='0' cellpadding='4' cellspacing='2'>" . "\n\t\t<tr align='center' valign='middle'>"; for ($i = 0; $i < count($avatar_images); $i++) { $j = $i + 1; $avatar_name = ucfirst(str_replace('_', ' ', preg_replace('/^(.*)\\..*$/', '\\1', $avatar_images[$i]))); $html .= "\n\t\t\t<td>" . '<input type="radio" name="' . $name . '__gallery" id="' . $name . '__gallery_' . $i . '" value="' . $avatar_images[$i] . '" />' . '<label for="' . $name . '__gallery_' . $i . '">' . '<img src="' . $live_site . '/images/comprofiler/gallery/' . $avatar_images[$i] . '" alt="' . $avatar_name . '" title="' . $avatar_name . '" />' . '</label>' . '</td>'; if (function_exists('fmod')) { if (!fmod($j, 5)) { $html .= "</tr>\n\t\t<tr align=\"center\" valign=\"middle\">"; } } else { if (!fmodReplace($j, 5)) { // PHP < 4.2.0... $html .= "</tr>\n\t\t<tr align=\"center\" valign=\"middle\">"; } } } $html .= "\n\t\t</tr>\n\t\t" . "\n\t</table>" . '</div>'; } $html .= '</div>'; return $html; }
static function userAvatar(&$row, $option, $submitvalue) { global $_CB_framework, $_REQUEST, $ueConfig, $_FILES; outputCbTemplate(1); $title = cbSetTitlePath($row, _UE_UPDATEAVATAR, _UE_EDIT_OTHER_USER_TITLE); ?> <!-- TAB --> <div class="componentheading"><?php echo $title; ?> </div><br /> <?php if ($ueConfig['allowAvatarUpload']) { echo "<div class='contentheading'>" . _UE_UPLOAD_SUBMIT . "</div>"; echo sprintf(_UE_UPLOAD_DIMENSIONS_AVATAR, $ueConfig['avatarWidth'], $ueConfig['avatarHeight'], $ueConfig['avatarSize']); echo "\n<form action='" . cbSef("index.php?option=com_comprofiler&task=userAvatar" . getCBprofileItemid(true)) . "' method='post' name='adminForm' enctype='multipart/form-data'>"; echo "\n\t<input type='hidden' name='do' value='validate' />"; if ($_CB_framework->myId() != $row->id) { echo "\n\t<input type='hidden' name='uid' value='" . $row->id . "' />"; } echo "\n\t<table width='100%' border='0' cellpadding='4' cellspacing='2'>"; echo "\n\t\t<tr align='center' valign='middle'>\n\t\t\t<td align='center' valign='top'>"; //echo " <input type='hidden' name='MAX_FILE_SIZE' value='".$maxAllowed."' />"; echo _UE_UPLOAD_SELECT_FILE . " <input type='file' name='avatar' value='' />"; echo " <input type='submit' class='button' value='" . _UE_UPLOAD_UPLOAD . "' />"; echo "</td>\n\t\t</tr>"; echo "\n\t\t<tr align='center' valign='middle'>\n\t\t\t<td align='center' valign='top'>"; echo $ueConfig['reg_enable_toc'] ? sprintf(_UE_AVATAR_UPLOAD_DISCLAIMER_TERMS, "<a href='" . cbSef(htmlspecialchars($ueConfig['reg_toc_url'])) . "' target='_BLANK'> " . _UE_AVATAR_TOC_LINK . "</a>") : _UE_AVATAR_UPLOAD_DISCLAIMER; echo "</td>\n\t\t</tr>"; echo "</table><br/><br/>"; echo "\n"; echo cbGetSpoofInputTag('userAvatar'); echo "</form>"; } if ($ueConfig['allowAvatarGallery']) { echo "\n<div class='contentheading'>" . _UE_UPLOAD_GALLERY . "</div>"; echo "\n<form action='" . cbSef("index.php?option=com_comprofiler&task=userAvatar" . getCBprofileItemid(true)) . "' method='post' name='adminForm'>"; echo "\n\t<input type='hidden' name='do' value='fromgallery' />"; if ($_CB_framework->myId() != $row->id) { echo "\n\t<input type='hidden' name='uid' value='" . $row->id . "' />"; } echo "\n\t<table width='100%' border='0' cellpadding='4' cellspacing='2'>"; echo "\n\t\t<tr align='center' valign='middle'>"; echo '<td colspan="5"> </td></tr>'; echo "\n\t\t<tr align='center' valign='middle'>"; $live_site = $_CB_framework->getCfg('live_site'); $avatar_gallery_path = $_CB_framework->getCfg('absolute_path') . '/images/comprofiler/gallery'; $avatar_images = display_avatar_gallery($avatar_gallery_path); for ($i = 0; $i < count($avatar_images); $i++) { $j = $i + 1; echo "\n\t\t\t<td>"; $avatar_name = ucfirst(str_replace("_", " ", preg_replace('/^(.*)\\..*$/', '\\1', $avatar_images[$i]))); echo '<img src="' . $live_site . '/images/comprofiler/gallery/' . $avatar_images[$i] . '" alt="' . $avatar_name . '" title="' . $avatar_name . '" />'; echo '<input type="radio" name="newavatar" value="' . $avatar_images[$i] . '" />'; echo '</td>'; if (function_exists('fmod')) { if (!fmod($j, 5)) { echo "</tr>\n\t\t<tr align=\"center\" valign=\"middle\">"; } } else { if (!fmodReplace($j, 5)) { echo "</tr>\n\t\t<tr align=\"center\" valign=\"middle\">"; } } } echo "\n\t\t</tr>\n\t\t"; echo '<tr><td colspan="5" align="center"><input class="button" type="submit" value="' . _UE_UPLOAD_CHOOSE . '" /> '; echo '<input type="button" class="button" name="btncancel" value="' . _UE_CANCEL . '" onclick="window.location=\'' . cbSef("index.php?option=" . htmlspecialchars(cbGetParam($_REQUEST, 'option')) . ($row->id == $_CB_framework->myId() ? '' : '&user='******'\';" />'; echo '</td></tr>'; echo "\n\t</table>"; echo "\n"; echo cbGetSpoofInputTag('userAvatar'); echo "</form>\n"; } }