public static function createFromFile($filename, $mime_type, $objAlbum) { $objPicture = new clsPicture(); /* Decide which incoming mime type it is. */ switch ($mime_type) { case 'image/jpeg': $img = ImageCreateFromJpeg($filename); break; case 'image/png': $img = ImageCreateFromPng($filename); break; case 'image/gif': $img = ImageCreateFromGif($filename); break; default: return 'image_filetype'; } list($intWidth, $intHeight) = getImageSize($filename); $intMaxWidth = $objAlbum->get('max_width'); $intMaxHeight = $objAlbum->get('max_height'); if ($intMaxWidth <= 0) { $intMaxWidth = DEFAULT_X; } if ($intMaxHeight <= 0) { $intMaxHeight = DEFAULT_Y; } if ($intWidth > $intMaxWidth || $intHeight > $intMaxHeight) { /* Check whether the image needs to be resized vertically or horizonally more. */ if ($intWidth / $intMaxWidth > $intHeight / $intMaxHeight) { /* Right-left needs to have priority. */ $ratio = $intMaxWidth / $intWidth; } else { /* Up-down needs to have priority. */ $ratio = $intMaxHeight / $intHeight; } $intNewWidth = $intWidth * $ratio; $intNewHeight = $intHeight * $ratio; $imgNew = @ImageCreateTrueColor($intNewWidth, $intNewHeight); if (!@ImageCopyResized($imgNew, $img, 0, 0, 0, 0, $intNewWidth, $intNewHeight, $intWidth, $intHeight)) { return "image_noresize"; } $intWidth = $intNewWidth; $intHeight = $intNewHeight; ImageDestroy($img); $img = $imgNew; } /* This has to be done before setImage() because setImage() needs data from the album. */ $objPicture->set('album_id', $objAlbum->get('id')); $result = $objPicture->setImage($img); ImageDestroy($img); if ($result) { return $result; } $objPicture->set('width', $intWidth); $objPicture->set('height', $intHeight); $objPicture->save(); return $objPicture; }
public static function getThumbnail($objUser, $picture_id, $intWidth, $intHeight, $objAlbum) { if (!is_numeric($picture_id)) { throw new Exception(INVALID_VALUE); } if (!is_numeric($intWidth)) { throw new Exception(INVALID_VALUE); } if (!is_numeric($intHeight)) { throw new Exception(INVALID_VALUE); } /* This prevents the thumbnails from being bigger than the original. */ if (!$objAlbum->isNew()) { $intWidth = min($intWidth, $objAlbum->get('max_width')); $intHeight = min($intHeight, $objAlbum->get('max_height')); } $arrThumbnails = clsDB::getListStatic('thumbnail', "`<<foreign><thumbnail><picture>>`='{$picture_id}' AND `<<thumbnail><width>>`='{$intWidth}' AND `<<thumbnail><height>>`='{$intHeight}'"); if (sizeof($arrThumbnails) == 0) { $objPicture = new clsPicture($picture_id); list($img, $intActualWidth, $intActualHeight) = $objPicture->getResized($objUser, $intWidth, $intHeight); if (is_string($img)) { return $img; } $objThumbnail = new clsThumbnail(); $objThumbnail->set('picture_id', $picture_id); $objThumbnail->set('width', $intWidth); $objThumbnail->set('height', $intHeight); $objThumbnail->set('actual_width', $intActualWidth); $objThumbnail->set('actual_height', $intActualHeight); $objThumbnail->set('date', date('Y-m-d H:i:s')); $result = $objThumbnail->setImage($img); if ($result) { return $result; } $objThumbnail->save(); } else { $objThumbnail = new clsThumbnail($arrThumbnails[0]->get('id')); } return $objThumbnail; }
} if ($strSubAction == 'grouppictures') { $objTemplate->setText('PAGETITLE', "Pictures in " . $objGroup->get('name')); $objBreadcrumbs->add('Groups', 'index.php?action=groups'); $objBreadcrumbs->add($objGroup->get('name'), 'index.php?action=groups&subaction=view&' . $objGroup->getIDPair()); $objBreadcrumbs->add("Pictures", "index.php?action=albums&subaction=userpictures&" . $objMember->getIDPair()); clsPicture::displayPictures(clsGroup::getPicturesByGroup($objUser, $objGroup)); } if ($strSubAction == 'newpictures') { if ($objUser == null) { throw new Exception('exception_accessdenied'); } $objTemplate->setText('PAGETITLE', "New Pictures"); $objMiniMenu->add('Mark all as seen', "index.php?action=albums&subaction=seen"); $objBreadcrumbs->add("New pictures", "index.php?action=albums&subaction=newpictures&" . $objMember->getIDPair()); clsPicture::displayPictures(clsPicture::getNewPictures($objUser)); } if ($strSubAction == 'save') { $blnGood = true; if (!$objUser) { throw new Exception('exception_notloggedin'); } if (!$objAlbum->canEdit($objUser)) { throw new Exception('exception_accessdenied'); } /* Get the user's submitted changes. */ $objAlbum = new clsAlbum(); $objAlbum->getFromRequest(array('id', 'album_id', 'group_id', 'name', 'caption', 'date', 'export_tag', 'max_height', 'max_width', 'mime', 'simple_permissions')); if ($objAlbum->get('max_width') > MAX_X || $objAlbum->get('max_width') <= 0 || !is_numeric($objAlbum->get('max_width'))) { $blnGood = false; $objTemplate->setText('ERROR', "Width must be a number between 1 and " . MAX_X . ".<br>");
<?php require_once 'cls/clsAlbum.php'; require_once 'cls/clsPicture.php'; print "<span class='recentheader'>New Pictures</span>"; $arrPictures = clsPicture::getRecentPictures($objUser, 5); foreach ($arrPictures as $objPicture) { $objPicture = new clsPicture($objPicture->get('id')); $objAlbum = new clsAlbum($objPicture->get('album_id')); print "<p>"; print $objPicture->getHtmlThumbnail(100, 100) . "<br>"; print "<a href='index.php?action=picture&" . $objPicture->getIDPair() . "' class='recentlink'>" . $objPicture->get('title') . "</a> <span class='recentdate'>in</span> <a href='index.php?action=albums&" . $objAlbum->getIDPair() . "' class='recentlink'>" . $objAlbum->get('name') . "</a><br>"; print "<span class='recentdate'>" . $objPicture->getUsername() . "<br>"; print time_to_text(strtotime($objPicture->get('date'))) . "</span>"; print "</p>"; }
} else { if ($strSubAction == 'delete') { if (!$objComment->canDelete($objUser)) { throw new Exception('exception_accessdenied'); } $objComment->delete(); $objComment->save(); header("Location: index.php?action=picture&" . $objPicture->getIDPair()); } else { if ($strSubAction = 'viewnew') { if (!$objUser) { throw new Exception('exception_accessdenied'); } $arrComments = clsComment::getNewComments($objUser); foreach ($arrComments as $objComment) { $objComment = new clsComment($objComment->get('id')); $objPicture = new clsPicture($objComment->get('picture_id')); $objCommentTemplate = new clsTemplate('newcomment'); $objCommentTemplate->setText('IMAGE', "<a href='index.php?action=picture&" . $objPicture->getIDPair() . "'>" . $objPicture->getHtmlThumbnail(128, 128) . "</a>"); $objCommentTemplate->setText('TITLE', $objComment->get('title') . ' ' . $objComment->getNewIcon($objUser)); $objCommentTemplate->setText('USERNAME', $objComment->getUsername()); $objCommentTemplate->setText('DATE', time_to_text(strtotime($objComment->get('date')))); $objCommentTemplate->setText('TEXT', bbcode_format($objComment->get('text'))); print $objCommentTemplate->get(); /* Mark the comment as viewed */ $objComment->setViewed($objUser); } } } } }
require_once 'cls/clsAlbum.php'; require_once 'cls/clsDB.php'; require_once 'cls/clsPicture.php'; require_once 'cls/clsSetting.php'; require_once 'cls/clsThumbnail.php'; require_once 'cls/clsUser.php'; require_once 'include/messages.php'; session_start(); clsSetting::load_settings(); try { if (!isset($_SESSION['objUser'])) { $objUser = clsUser::getCookie(); } else { $objUser = $_SESSION['objUser']; } $objPicture = new clsPicture(); $objPicture->getFromRequest(array('id')); $objPicture->load(); if ($objPicture->isnew()) { throw new Exception('exception_invalidrequest'); } $objAlbum = new clsAlbum($objPicture->get('album_id')); if (!$objAlbum->canView($objUser)) { throw new Exception('exception_invalidrequest'); } if (isset($_REQUEST['tn']) || isset($_REQUEST['action']) && $_REQUEST['action'] == 'tn') { $intWidth = isset($_REQUEST['w']) ? $_REQUEST['w'] : -1; $intHeight = isset($_REQUEST['h']) ? $_REQUEST['h'] : -1; if (!is_numeric($intWidth) || $intWidth < 0 || $intWidth > MAX_X) { throw new Exception('exception_invalidrequest'); }
<?php require_once 'cls/clsAlbum.php'; require_once 'cls/clsComment.php'; require_once 'cls/clsParameters.php'; require_once 'cls/clsPicture.php'; require_once 'cls/clsTemplate.php'; require_once 'cls/clsThumbnail.php'; require_once 'cls/clsUser.php'; require_once 'cls/clsVote.php'; $objBreadcrumbs->add('Albums', 'index.php?action=albums'); $objPicture = new clsPicture(); $objPicture->getFromRequest(); $objPicture->load(); $objPrevPicture = $objPicture->getPrev(); $objNextPicture = $objPicture->getNext(); if ($objPicture->isNew()) { throw new Exception('exception_invalidrequest'); } if (!$objPicture->get('confirmed')) { header("Location: index.php?action=upload&subaction=preview"); die; } /* Check for access. */ $objAlbum = new clsAlbum($objPicture->get('album_id')); if (!$objAlbum->canView($objUser)) { throw new Exception('exception_accessdenied'); } $objAlbum->addBreadcrumbs($objBreadcrumbs); // $strMiniMenu = "<li><a href='index.php?action=picture&subaction=edit&" . $objPicture->getIDPair() . "'>Create Album</a></li>"; // $objTemplate->setText('MINIMENU', "<ul>$strMiniMenu</ul>");
require_once 'cls/clsSetting.php'; require_once 'cls/clsUser.php'; session_start(); clsSetting::load_settings(); try { if (!isset($_SESSION['objUser'])) { $objUser = clsUser::getCookie(); } else { $objUser = $_SESSION['objUser']; } header("Content-type: application/xhtml+xml"); $arrPictures = clsPicture::getRecentPictures($objUser, 10); $url = "http://" . $_SERVER['HTTP_HOST'] . "/" . preg_replace("/\\/[a-zA-Z0-9.]*\$/", "/index.php", $_SERVER['PHP_SELF']); print "<?xml version='1.0' encoding='UTF-8'?>\n<!-- generator='OSPAP2' -->\n<rss version='2.0'\n\txmlns:content='http://purl.org/rss/1.0/modules/content/'\n\txmlns:wfw='http://wellformedweb.org/CommentAPI/'\n\txmlns:dc='http://purl.org/dc/elements/1.1/'\n\t>\n\n<channel>\n\t<title>" . SITE_NAME . "</title>\n\t<link>{$url}</link>\n\t<description>" . SITE_DESCRIPTION . "</description>\n\t<generator>http://www.javaop.com/~ron/ospap2</generator>\n\t<language>en</language>\n"; foreach ($arrPictures as $objPicture) { $objPicture = new clsPicture($objPicture->get('id')); $link = "http://" . $_SERVER['HTTP_HOST'] . "/" . preg_replace("/\\/[a-zA-Z0-9.]*\$/", "/index.php?action=picture&" . $objPicture->getIDPair(), $_SERVER['PHP_SELF']); print "\t<item>\n"; print "\t\t<title>" . $objPicture->get('title') . "</title>\n"; print "\t\t<link>{$link}</link>\n"; print "\t\t<comments>{$link}</comments>\n"; print "\t\t<pubDate>" . date("D M j Y G:i:s T", strtotime($objPicture->get('date'))) . "</pubDate>\n"; print "\t\t<dc:creator>" . $objPicture->getFrom('user', 'username') . "</dc:creator>\n"; print "\t\t<category><![CDATA[" . $objPicture->getFrom('album', 'name') . "]]></category>\n"; print "\t\t<guid isPermaLink=\"true\">{$link}</guid>\n"; print "\t\t<description><![CDATA[" . cut_text($objPicture->get('caption'), 200) . "<br><br>" . $objPicture->getHtmlThumbnail(150, 150) . "]]></description>\n"; print "\t\t<content:encoded><![CDATA[" . $objPicture->get('caption') . "<br><br>" . $objPicture->getHtml() . "]]></content:encoded>\n"; print "\t\t<wfw:commentRss>" . $_SERVER['PHP_SELF'] . "</wfw:commentRss>\n"; print "\t</item>\n"; } print "</channel>\n";
public static function markSeen($objUser, $objAlbum = null) { if (!$objAlbum || $objAlbum->isNew()) { $arrPictures = clsDB::getListStatic('picture'); } else { $arrPictures = $objAlbum->getForeignObjects('picture'); } foreach ($arrPictures as $objPicture) { $objPicture = new clsPicture($objPicture->get('id')); $objPicture->setViewed($objUser); } }
$objAlbum->set('date', date('Y-m-d H:i:s', strtotime($arrResult['date_created']) + $i++), false); /* Adding '$i' here is a bit of a kludge, but it keeps dates sortable (since ospap1 didn't keep track of times). */ $objAlbum->set('user_id', $user_id); $objAlbum->set('mime', 'image/jpeg'); $objAlbum->set('max_width', '640'); $objAlbum->set('max_height', '480'); $objAlbum->setDefaultPolicies($objOwner); $objAlbum->save(); $arrAlbums[$arrResult['category_id']] = $objAlbum; } $objAlbum = $arrAlbums[$arrResult['category_id']]; print "Importing from '" . $objAlbum->get('name') . "'<br>"; $i = 0; $pictureResult = mysql_query("SELECT * FROM pictures WHERE category_id = '" . $arrResult['category_id'] . "' "); while ($arrPictureResult = mysql_fetch_assoc($pictureResult)) { $objPicture = clsPicture::createFromFile($upload_directory . '/' . $arrPictureResult['filename'], 'image/jpeg', $objAlbum); $objPicture->set('user_id', $user_id); $objPicture->set('album_id', $objAlbum->get('id')); $objPicture->set('title', str_replace("<br />", "", html_entity_decode($arrPictureResult['title']))); $objPicture->set('caption', str_replace("<br />", "", html_entity_decode($arrPictureResult['caption']))); $objPicture->set('date', date('Y-m-d H:i:s', strtotime($arrPictureResult['date_added']) + $i++), false); $objPicture->set('confirmed', 1); $objPicture->save(); print "<img src='" . clsThumbnail::getUrl($objPicture, 70, 70) . "'> "; if (++$i % 6 == 0) { print "<br>"; } } print "<br><br>"; } }
<?php require_once 'cls/clsComment.php'; require_once 'cls/clsGroup.php'; require_once 'cls/clsPicture.php'; if ($objUser) { print "Welcome back, <a href='index.php?action=members&subaction=view&" . $objUser->getIDPair() . "'>" . $objUser->get('username') . "</a>! <br>"; print "You have <a href='index.php?action=comment&subaction=viewnew'><strong>" . sizeof(clsComment::getNewComments($objUser)) . "</strong> unread comments</a> on your pictures.<br>"; print "There are <a href='index.php?action=albums&subaction=newpictures'><strong>" . sizeof(clsPicture::getNewPictures($objUser)) . "</strong> new pictures</a>.<br>"; if ($objUser) { $intNum = sizeof(clsGroup::getInvitations($objUser)); if ($intNum > 0) { print "You have invitations to <a href='index.php?action=groups&subaction=invitations'><strong>{$intNum} groups</strong></a>.<br>"; } } } else { print "Welcome, guest! You can <a href='index.php?action=login'>log in</a> or <a href='index.php?action=members&subaction=view'>register</a>.<br><br>"; }
if ($objPicture->get('user_id') != $user_id) { throw new Exception('exception_accessdenied'); } /* Make sure that users can only edit their own pictures. */ $objPicture->delete(); $objPicture->save(); header("Location: index.php?action=upload&subaction=preview"); } if ($strSubAction == 'preview') { $objTemplate->setText('PAGETITLE', "Pending Pictures"); $objBreadcrumbs->add('Upload', 'index.php?action=upload'); $objBreadcrumbs->add('Pending', 'index.php?action=upload&subaction=preview'); $arrPictures = clsPicture::getPending($objUser); print "You have <strong>" . sizeof($arrPictures) . "</strong> pictures waiting for attention" . ($objUser ? "" : " (note: unsaved images from all guests will appear here)") . ":<br><br>"; foreach ($arrPictures as $objPicture) { $objPicture = new clsPicture($objPicture->get('id')); $objAlbum = new clsAlbum($objPicture->get('album_id')); $objTemplate = new clsTemplate('preview'); $objTemplate->setText('HIDDEN', $objPicture->getHiddenField('id')); $objTemplate->setText('ALBUM', $objPicture->getCombo('album_id', clsDB::getOptionsFromList($objAlbum->getPostableAlbums($objUser), 'name', 'id', "Select an album"))); $objTemplate->setText('ID', $objPicture->get('id')); $objTemplate->setText('IMAGE', $objPicture->getHtmlThumbnail(250, 250)); /* TODO: Customizable? */ $objTemplate->setText('NAME', $objPicture->get('original_name')); $objTemplate->setText('WIDTH', $objPicture->get('width')); $objTemplate->setText('HEIGHT', $objPicture->get('height')); $objTemplate->setText('SAVEDELETE', $objPicture->getCombo('subaction', array('confirm' => 'Keep', 'delete' => 'Don\'t keep'), null, true)); $objTemplate->setText('TITLE', $objPicture->getTextField('title')); $objTemplate->setText('CAPTION', $objPicture->getTextArea('caption')); $objTemplate->setText('SUBMIT', $objPicture->getSubmit('Save')); print $objTemplate->get();