if (!is_numeric($_GET['month'])) { throw new Exception('Month not numerical.'); } $options['user'] = $_GET['id']; $options['month'] = $_GET['month']; } $options['order-by'] = 'up.date'; $photo = photoblog_photos_fetch($options); echo json_encode($photo); break; case 'comments_fetch': if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { throw new Exception('No Photo-ID or faulty ID recieved'); } $options['photo_id'] = $_GET['id']; $comments = photoblog_comments_fetch($options); $options['use_container'] = false; echo photoblog_comments_list($comments, $options); break; case 'comments_post': if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { throw new Exception('No Photo-ID or faulty ID recieved'); } if (!login_checklogin()) { throw new Exception('Only users can post comments.'); } $options['photo_id'] = $_GET['id']; $options['comment'] = $_POST['comment']; $options['author'] = $_SESSION['login']['id']; photoblog_comments_add($options); break;
$class = ' class="last-image"'; } $out .= '<dd' . $class . '><a title="' . $photo['date'] . '" ' . ($key == $photos_last_index ? 'class="photoblog_active"' : '') . ' href="#image-' . $photo['id'] . '"><img src="' . IMAGE_URL . 'photos/mini/' . floor($photo['id'] / 5000) . '/' . $photo['id'] . '.jpg" title="' . $photo['username'] . '" /></a></dd>'; } $out .= '<dt id="photoblog_nextmonth"><a id="nextmonth" title="Nästa månad" href="#next-month">Nästa månad</a></dt>'; $out .= '</dl>'; $out .= '</div>'; $out .= '</div>'; $out .= '</div>'; $out .= '<div id="photoblog_image">'; $last_photo = $photos[$photos_last_index]; $out .= '<p><img src="' . IMAGE_URL . 'photos/full/' . floor($last_photo['id'] / 5000) . '/' . $last_photo['id'] . '.jpg" alt="" /></p>'; $out .= '</div>'; $out .= '<div id="photoblog_description">'; $out .= '<div id="photoblog_description_text">'; $out .= $last_photo['description']; $out .= '</div>'; $out .= '</div>'; $out .= '<script type="text/javascript">'; $out .= 'hp.photoblog.current_user = {'; $out .= 'id: ' . $user_id; $out .= '};'; $out .= 'hp.photoblog.view.current_id = ' . $last_photo['id']; $out .= '</script>'; // Some test-data /*$comment1 = array('user_id' => 625058, 'username' => 'Lef', 'comment' => 'Din mamma är så fet!'); $comment2 = array('user_id' => 3, 'answer' => 'Jag bryr mig <del>inte</del> visst! Det gör ont när du säger sånt...', 'username' => 'Johan', 'comment' => 'Din med! :( '); $comments = array($comment1, $comment2);*/ $comments = photoblog_comments_fetch(array('photo_id' => $last_photo['id'])); $out .= photoblog_comments_form($options); $out .= photoblog_comments_list($comments);
throw new Exception('No input'); } if (!login_checklogin()) { throw new Exception('Only users can reply to comments.'); } $options['comment_id'] = $_GET['id']; $options['reply'] = $_POST['reply']; $options['author'] = $_SESSION['login']['id']; photoblog_comments_reply($options); break; case 'comments_remove': if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { throw new Exception('No input'); } $photo_options['id'] = $_GET['id']; $photo = photoblog_comments_fetch($photo_options); if (!count($photo)) { throw new Exception('No comment'); } $options['image_owner_id'] = $photo[0]['user']; $options['comment_id'] = $_GET['id']; photoblog_comments_remove($options); break; case 'calendar_render': if (!isset($_GET['user_id'], $_GET['month'], $_GET['year'])) { throw new Exception('No input.'); } if (!is_numeric($_GET['user_id']) || !is_numeric($_GET['month']) || !is_numeric($_GET['year'])) { throw new Exception('Not numerical input.'); } echo photoblog_calendar($_GET['user_id'], $_GET['month'], $_GET['year']);
function photoblog_viewer($options) { global $photoblog_user; $ret = ''; $options['include_dates'] = isset($options['include_dates']) ? $options['include_dates'] : true; $options['load_first'] = isset($options['load_first']) ? $options['load_first'] : false; $options['album_view'] = (bool) $options['album_view']; $active_photo = isset($options['active_id']) && $options['active_id'] ? $options['active_id'] : false; $user_id = $options['user_id']; if ($active_photo) { $current_photo = end(photoblog_photos_fetch(array('id' => $active_photo, 'user' => $user_id))); // something went wrong, photo doesn't exists, not the $user_id's, so go with plain old normal view if (!$current_photo) { $active_photo = false; } else { $options['date'] = date('Ym', strtotime($current_photo['date'])); } } $photo_options = array('user' => $user_id); if (isset($options['date'])) { $photo_options['month'] = $options['date']; } if (isset($options['category'])) { $photo_options['category'] = $options['category']; } $date = isset($options['date']) ? $options['date'] : date('Ym', time()); define('PHOTOBLOG_CURRENT_YEAR', substr($date, 0, 4)); define('PHOTOBLOG_CURRENT_MONTH', substr($date, 4, 2)); define('PHOTOBLOG_CURRENT_USER', $user_id); $photos = !isset($options['photos']) ? photoblog_photos_fetch($photo_options) : $options['photos']; $ret .= '<!--[if lte IE 7]>'; $ret .= '<div class="photoblog_ie_warning">'; $ret .= '<p>Tjena! Som du kanske har märkt så fungerar fotobloggen inte så överdrivet bra med den versionen av Internet Explorer du kör nu! :( Det beror på att det är en dålig webbläsare för oss som gör hemsidor. Men! Du kan alltid uppgradera till en bättre webbläsare, till exempel <a href="http://www.firefox.com/">Firefox</a>, <a href="http://www.apple.com/safari/">Safari</a>, <a href="http://www.google.com/chrome">Google Chrome</a>, <a href="http://www.opera.com/">Opera</a> eller så kan du <a href="http://www.microsoft.com/windows/internet-explorer/">uppgradera till senaste versionen av Internet Explorer</a>. Om du gör något av detta så vinner du en internet!</p>'; $ret .= '</div>'; $ret .= '<![endif]-->'; $is_album = isset($options['is_album']) && $options['is_album']; $ret .= '<div id="photoblog_thumbs">'; $ret .= '<div id="photoblog_thumbs_container">'; $ret .= '<div id="photoblog_thumbs_inner">'; $ret .= '<dl>'; if ($is_album) { list($html, $current_photo) = photoblog_viewer_albums_list($options); $ret .= $html; } else { $ret .= '<dt id="photoblog_prevmonth"><a id="prevmonth" title="Föregående månad" href="#prev-month">Föregående månad</a></dt>'; $is_first = true; $last_day = array('date' => null, 'formatted' => null); if (!count($photos)) { $ret .= '<dt>Här var det tomt...</dt>'; } $photos_last_index = count($photos) - 1; foreach ($photos as $key => $photo) { if ($options['include_dates'] && $last_day['date'] != $photo['date']) { $last_day['date'] = $photo['date']; $last_day['formatted'] = date('j/n', strtotime($photo['date'])); $ret .= '<dt>' . $last_day['formatted'] . '</dt>'; } $class = ' class="'; if ($key == 0) { $class .= 'first-image '; } if ($key == $photos_last_index) { $class .= 'last-image '; } $class .= '"'; if ($active_photo) { $is_current = $active_photo == $photo['id']; } else { $is_current = $options['load_first'] ? $key == 0 : $key == $photos_last_index; } $ret .= '<dd' . $class . '><a title="' . $photo['date'] . '" ' . ($is_current ? 'class="photoblog_active"' : '') . ' href="#image-' . $photo['id'] . '"><img src="' . IMAGE_URL . 'photos/mini/' . floor($photo['id'] / 5000) . '/' . $photo['id'] . '.jpg" title="' . $photo['username'] . '" /></a></dd>'; } if (!$active_photo) { $current_photo = $options['load_first'] ? $photos[0] : $photos[$photos_last_index]; } else { foreach ($photos as $photo) { if ($photo['id'] == $active_photo) { $current_photo = $photo; break; } } } $ret .= '<dt id="photoblog_nextmonth"><a id="nextmonth" title="Nästa månad" href="#next-month">Nästa månad</a></dt>'; } $ret .= '</dl>'; $ret .= '</div>'; $ret .= '</div>'; // Scroller, JS added at domready. $ret .= '<div id="photoblog_thumbs_scroller_outer"><div id="photoblog_thumbs_scroller" class="ui-slider"> <div class="ui-slider-handle" style="width: 100%;" id="photoblog_thumbs_handle"></div> </div></div>'; $ret .= '</div>'; $ret .= '<div id="photoblog_image">'; $ret .= '<p><img src="' . IMAGE_URL . 'photos/full/' . floor($current_photo['id'] / 5000) . '/' . $current_photo['id'] . '.jpg" alt="" /></p>'; $ret .= '</div>'; $ret .= '<div id="photoblog_description">'; if ($current_photo) { $ret .= '<div id="photoblog_description_report">'; $ret .= sprintf('<a class="report_abuse" href="/hamsterpaj/abuse.php?report_type=photo&reference_id=%d">Rapportera bilden</a>', $current_photo['id']); $ret .= '</div>'; } $ret .= '<div id="photoblog_description_text">'; $ret .= $current_photo['description']; $ret .= '</div>'; if (login_checklogin() && $_SESSION['login']['id'] == $user_id) { $ret .= '<div id="photoblog_edit">'; $ret .= '<form action="/ajax_gateways/photoblog.json.php?action=photo_edit" method="post">'; $ret .= '<a href="#photoblog_edit_actions">Ändra din söta bild?</a>'; $ret .= '<div style="display: none" id="photoblog_edit_do">'; $ret .= '<h3>Ändringar <small><a href="/fotoblogg/ordna">(Du kanske vill sortera dina bilder?)</a></small></h3>'; $ret .= '<input type="hidden" value="' . $current_photo['id'] . '" name="edit_id" />'; $ret .= '<p id="photoblog_edit_description"><textarea rows="5" cols="50" name="edit_description">' . $current_photo['description'] . '</textarea></p>'; $ret .= '<div id="photoblog_edit_date"><h4>Datum</h4>'; $ret .= '<p><input type="text" name="edit_date" value="' . $current_photo['date'] . '" /></p></div>'; $ret .= '<p id="photoblog_edit_save"><input type="submit" value="Spara dina ändringar" name="edit_submit" /> <input type="submit" name="edit_delete" value="Ta bort bilden" /></p>'; $ret .= '</div>'; $ret .= '</form>'; $ret .= '</div>'; } $ret .= '</div>'; $ret .= '<script type="text/javascript">'; $ret .= 'hp.photoblog.current_user = {'; $ret .= 'id: ' . $user_id; $ret .= ', date: ' . $date; $ret .= ', album_view: ' . (int) ($options['album_view'] || $options['is_album']); $ret .= '};'; $ret .= 'hp.photoblog.view.current_id = ' . ($current_photo['id'] ? $current_photo['id'] : '0') . ';'; $ret .= '</script>'; if ($current_photo) { $comments = photoblog_comments_fetch(array('photo_id' => $current_photo['id'])); $comment_options = array('my_blog' => $_SESSION['login']['id'] == $photoblog_user['id']); $ret .= photoblog_comments_form($photo_options); $ret .= photoblog_comments_list($comments, $comment_options); } else { $ret .= '<p>Här var det jättetomt! Vänd tillbaka!</p>'; } return $ret; }