public function imageAction() { $request = $this->getRequest(); $response = $this->getResponse(); $id = (int) $request->getQuery('id'); $w = (int) $request->getQuery('w'); $h = (int) $request->getQuery('h'); $hash = $request->getQuery('hash'); $realHash = DatabaseObject_BlogPostImage::GetImageHash($id, $w, $h); $this->_helper->viewRenderer->setNoRender(); $image = new DatabaseObject_BlogPostImage($this->db); if ($hash != $realHash || !$image->load($id)) { $response->setHttpResponseCode(404); return; } try { $fullpath = $image->createThumbnail($w, $h); } catch (Exception $ex) { $fullpath = $image->getFullPath(); } $info = getImageSize($fullpath); $response->setHeader('content-type', $info['mime']); $response->setHeader('content-length', filesize($fullpath)); echo file_get_contents($fullpath); }
public function imagesAction() { $request = $this->getRequest(); $post_id = (int) $request->getPost('id'); $post = new DatabaseObject_BlogPost($this->db); $json = array(); if (!$post->loadForUser($this->identity->user_id, $post_id)) { $this->_redirect($this->getUrl()); } if ($request->getPost('upload')) { $fp = new FormProcessor_BlogPostImage($post); if ($fp->process($request)) { $this->messenger->addMessage('Image uploaded'); } else { foreach ($fp->getErrors() as $error) { $this->messenger->addMessage($error); } } } else { if ($request->getPost('reorder')) { $order = $request->getPost('post_images'); $post->setImageOrder($order); } else { if ($request->getPost('delete')) { $image_id = (int) $request->getPost('image'); $image = new DatabaseObject_BlogPostImage($this->db); if ($image->loadForPost($post->getId(), $image_id)) { $image->delete(); if ($request->isXmlHttpRequest()) { $json = array('deleted' => true, 'image_id' => $image_id); } else { $this->messenger->addMessage('Image deleted'); } } } } } if ($request->isXmlHttpRequest()) { $this->sendJson($json); } else { $url = $this->getUrl('preview') . '?id=' . $post->getId(); $this->_redirect($url); } }
public static function GetPosts($db, $options = array()) { $defaults = array('offset' => 0, 'limit' => 0, 'order' => 'p.ts_created'); foreach ($defaults as $k => $v) { $options[$k] = array_key_exists($k, $options) ? $options[$k] : $v; } $select = self::_GetBaseQuery($db, $options); $select->from(null, 'p.*'); if ($options['limit'] > 0) { $select->limit($options['limit'], $options['offset']); } $select->order($options['order']); $data = $db->fetchAll($select); $posts = self::BuildMultiple($db, __CLASS__, $data); $post_ids = array_keys($posts); if (count($post_ids) == 0) { return array(); } $profiles = Profile::BuildMultiple($db, 'Profile_BlogPost', array('post_id' => $post_ids)); foreach ($posts as $post_id => $post) { if (array_key_exists($post_id, $profiles) && $profiles[$post_id] instanceof Profile_BlogPost) { $posts[$post_id]->profile = $profiles[$post_id]; } else { $posts[$post_id]->profile->setPostId($post_id); } } $options = array('post_id' => $post_ids); $images = DatabaseObject_BlogPostImage::GetImages($db, $options); foreach ($images as $image) { $posts[$image->post_id]->images[$image->getId()] = $image; } $locations = DatabaseObject_BlogPostLocation::GetLocations($db, $options); foreach ($locations as $l) { $posts[$l->post_id]->locations[$l->getId()] = $l; } return $posts; }