1
bitter_end
How to save user ip address when uploading images to extgallery
  • 2009/2/7 14:35

  • bitter_end

  • Just popping in

  • Posts: 3

  • Since: 2009/2/7 1


I'm usnig extgallery module as an image gallry but I need it to save the user ip when uploading a picture.
I have created a field called "IP" in the table in MySQL but don't know hot to make it write the user IP to there. Here is the uploader file code for extgallery

I would be very happy if anyone can help me about this small issue



require '../../mainfile.php';
include_once XOOPS_ROOT_PATH.'/modules/extgallery/class/publicPerm.php';
include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
include_once XOOPS_ROOT_PATH.'/class/uploader.php';

if(isset($_POST['step'])) {
$step = $_POST['step'];
} else {
$step = 'default';
}

$permHandler = ExtgalleryPublicPermHandler::getHandler();
if(count($permHandler->getAuthorizedPublicCat($xoopsUser, 'public_upload')) < 1) {
redirect_header("index.php", 3, _MD_EXTGALLERY_NOPERM);
exit;
}

switch($step) {

case 'enreg':

include_once XOOPS_ROOT_PATH.'/modules/extgallery/class/php-captcha.inc.php';

// Enable captcha only if GD is Used
if($xoopsModuleConfig['graphic_lib'] == 'GD') {
if (!PhpCaptcha::Validate($_POST['captcha'])) {
redirect_header("public-photo.php?photoId=".$photoId."#photoNav", 3, _MD_EXTGALLERY_CAPTCHA_ERROR);
exit;
}
}

include_once XOOPS_ROOT_PATH.'/modules/extgallery/class/pear/Image/Transform.php';

$catHandler = xoops_getmodulehandler('publiccat', 'extgallery');
$photoHandler = xoops_getmodulehandler('publicphoto', 'extgallery');

$catId = intval($_POST['cat_id']);

// If isn't an album when stop the traitment
$cat = $catHandler->getCat($catId);
if($cat->getVar('nright') - $cat->getVar('nleft') != 1) {
redirect_header("photo.php", 3, _MD_EXTGALLERY_NOT_AN_ALBUM);
exit;
}

$allowedMimeTypes = array('image/jpeg','image/gif','image/png');
$uploadDir = XOOPS_ROOT_PATH."/uploads/extgallery/public-photo/";

$uploader = new XoopsMediaUploader($uploadDir, $allowedMimeTypes, 3145728, 5000, 5000);

foreach($_FILES as $file => $fileArray) {

// Test if there is an error during upload
if($fileArray['error'] != 0) {
redirect_header("public-upload.php", 3, _MD_EXTGALLERY_UPLOAD_ERROR);
exit;
}

if ($uploader->fetchMedia($file)) {

if (!$uploader->upload()) {
echo $uploader->getErrors();
} else {
$extra = isset($_POST['photo_extra']) ? $_POST['photo_extra'] : "";
$photoStatus = $photoHandler->addLocalPhoto($catId,$uploader->getSavedFileName(),$_POST['photo_title']);
$cat = $catHandler->getCat($catId);
$cat->setVar('cat_isalbum',1);
$catHandler->insert($cat);

$notification_handler =& xoops_gethandler('notification');
$extraTags = array(
'X_ITEM_CAT'=>$cat->getVar('cat_name'),
'X_ITEM_NBPHOTO'=>1
);
if($photoStatus == 1) {
$extraTags['X_ITEM_URL'] = XOOPS_URL."/modules/extgallery/public-album.php?id=".$cat->getVar('cat_id');
$notification_handler->triggerEvent('global', 0, 'new_photo',$extraTags);
$notification_handler->triggerEvent('album', $cat->getVar('cat_id'), 'new_photo_album',$extraTags);

// Update album count
if($cat->getVar('cat_nb_photo') == 0) {
$criteria = new CriteriaCompo();
$criteria->add(new Criteria('nleft',$cat->getVar('nleft'),'<'));
$criteria->add(new Criteria('nright',$cat->getVar('nright'),'>'));
$catHandler->updateFieldValue('cat_nb_album', 'cat_nb_album + 1', $criteria);
}

// Update photo count
$criteria = new CriteriaCompo();
$criteria->add(new Criteria('nleft',$cat->getVar('nleft'),'<='));
$criteria->add(new Criteria('nright',$cat->getVar('nright'),'>='));
$catHandler->updateFieldValue('cat_nb_photo', 'cat_nb_photo + 1', $criteria);

echo "SUCCESS\n";

redirect_header("public-album.php?id=1", 3, _MD_EXTGALLERY_PHOTO_UPLOADED);
} else {
$extraTags['X_ITEM_URL'] = XOOPS_URL."/modules/extgallery/admin/photo.php";
$notification_handler->triggerEvent('global', 0, 'new_photo_pending',$extraTags);

echo "SUCCESS\n";

redirect_header("public-album.php?id=1", 3, _MD_EXTGALLERY_PHOTO_PENDING);
}

}
} else {
echo $uploader->getErrors();
}

}

break;

case 'default':
default:

include_once XOOPS_ROOT_PATH.'/header.php';

$catHandler = xoops_getmodulehandler('publiccat', 'extgallery');

$form = new XoopsThemeForm(_MD_EXTGALLERY_PUBLIC_UPLOAD, 'add_photo', 'public-upload.php', 'post', true);
$form->setExtra('enctype="multipart/form-data"');
$form->addElement(new XoopsFormLabel(_MD_EXTGALLERY_ALBUMS, $catHandler->getLeafSelect('cat_id', false, 0, "", "public_upload")));
$form->addElement(new XoopsFormFile(_MD_EXTGALLERY_PHOTO, 'photo_file', 3145728),false);
if($xoopsModuleConfig['display_extra_field'])
$form->addElement(new XoopsFormTextArea(_MD_EXTGALLERY_EXTRA_INFO, "photo_extra"));
$form->addElement(new XoopsFormHidden("step", 'enreg'));
// Enable captcha only if GD is Used
if($xoopsModuleConfig['graphic_lib'] == 'GD') {
$form->addElement(new XoopsFormText(_MD_EXTGALLERY_SECURITY, 'captcha', '10', '5', ''),false);
}
$form->addElement(new XoopsFormButton("", "submit", _SUBMIT, "submit"));
$form->display();

include(XOOPS_ROOT_PATH."/footer.php");

break;

}

?>

Login

Who's Online

255 user(s) are online (188 user(s) are browsing Support Forums)


Members: 0


Guests: 255


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits