protected function executeProcessing(PinholePhoto $photo) { $photo->process($this->getFilePath($photo)); if ($photo->auto_publish) { $photo->publish(); } else { $photo->status = PinholePhoto::STATUS_PENDING; } }
protected function buildComments() { $global_status = $this->app->config->pinhole->global_comment_status; if ($global_status === null) { $status = $this->photo->comment_status; } elseif ($global_status == true) { // comments are globally turned on $status = $this->app->config->pinhole->default_comment_status; } else { // comments are globally turned off $status = SiteCommentStatus::CLOSED; } if ($status !== SiteCommentStatus::CLOSED) { $comments = $this->photo->getVisibleComments(); if (count($comments) > 0) { $this->ui->getWidget('comments_frame')->visible = true; ob_start(); $div_tag = new SwatHtmlTag('div'); $div_tag->id = 'comments'; $div_tag->class = 'photo-comments'; $div_tag->open(); $view = SiteViewFactory::get($this->app, 'photo-comment'); foreach ($comments as $comment) { $view->display($comment); } $div_tag->close(); $this->ui->getWidget('comments')->content = ob_get_clean(); } ob_start(); $this->comment_ui->display(); $this->ui->getWidget('comments_ui')->content = ob_get_clean(); } }
protected function buildSiteLinks() { $replicator = $this->ui->getWidget('site_link_field'); foreach ($this->getDimensions() as $dimension) { if ($dimension->shortname == 'original') { $image = $this->photo->getTitle(true); $link = $this->photo->getUri('original'); } else { $image = $this->photo->getImgTag($dimension->shortname); $image->src = $this->app->getFrontendBaseHref() . $image->src; $link = 'photo/' . $this->photo->id; } $code = sprintf('<a href="%s%s">%s</a>', $this->app->getFrontendBaseHref(), $link, $image); $replicator->getWidget('site_link_code', $dimension->id)->value = $code; } }
protected function processInternal() { $form = $this->ui->getWidget('form'); $form->process(); if ($form->isProcessed() && $form->isAuthenticated()) { ini_set('memory_limit', -1); set_time_limit(300); $class_name = SwatDBClassMap::get('PinholePhotoUploadSet'); $upload_set = new $class_name(); $upload_set->setDatabase($this->app->db); $upload_set->createdate = new SwatDate(); $upload_set->createdate->toUTC(); $upload_set->save(); $files = PinholePhoto::saveUploadedFile('file'); $image_set = $this->getImageSet(); foreach ($files as $temp_filename => $original_filename) { $photo = $this->getTempPhoto($upload_set, $image_set, $temp_filename, $original_filename); $photo->save(); } $this->saveConfigSettings(); $this->app->relocate($this->getComponentName() . '/LastUpload'); } }
/** * Creates a new file in this directory * * @param string $name the name of the file to create. * @param resource $data optional. The initial data payload. If null, * an empty file is created. */ public function createFile($original_filename, $data = null) { $ext = strtolower(end(explode('.', $original_filename))); $filename = uniqid('file') . '.' . $ext; $file_path = sprintf('%s/%s', sys_get_temp_dir(), $filename); file_put_contents($file_path, $data); $files = PinholePhoto::parseFile($file_path, $original_filename); $image_set = $this->getImageSet(); $now = new SwatDate(); $now->toUTC(); foreach ($files as $temp_filename => $original_filename) { $class_name = SwatDBClassMap::get('PinholePhoto'); $photo = new $class_name(); $photo->setDatabase($this->app->db); $photo->image_set = $image_set->id; //$photo->upload_set = $upload_set; $photo->original_filename = $original_filename; $photo->temp_filename = $temp_filename; $photo->status = PinholePhoto::STATUS_UNPROCESSED; $photo->dav_upload = true; $photo->upload_date = $now; $config = $this->app->config->pinhole; $photo->auto_publish = !$config->dav_set_pending; $photo->private = $config->dav_set_private_photos; $photo->photo_time_zone = $config->dav_photo_time_zone; $photo->camera_time_zone = $config->dav_photo_time_zone; $photo->auto_rotate = $config->dav_auto_rotate; $photo->set_content_by_meta_data = $config->dav_set_content_by_meta_data; $photo->set_tags_by_meta_data = $config->dav_set_tags_by_meta_data; $photo->save(); $photo->setFileBase('../photos'); $processor = new PinholePhotoProcessor($this->app); $processor->processPhoto($photo); $photo->save(); } }
/** * Gets the content type of this file * * This should be a mime-type value. If null, * <kbd>application/octet-steam</kbd> is used. * * @return string the content type of this file. */ public function getContentType() { return $this->photo->getMimeType('original'); }
/** * Applies this tag to a photo * * @param PinholePhoto $photo the photo this tag is to be applied to. */ public function applyToPhoto(PinholePhoto $photo) { $photo->for_sale = $this->getValue(); $photo->save(); }
protected function displayNext(PinholePhoto $photo = null) { if ($photo === null) { $span_tag = new SwatHtmlTag('span'); $span_tag->class = 'next'; $span_tag->setContent(Pinhole::_('Next')); $span_tag->display(); } else { $a_tag = new SwatHtmlTag('a'); $href = $this->appendTagPath(sprintf('%sphoto/%s', $this->base, $photo->id)); $a_tag->href = $href; $a_tag->title = $photo->title; $a_tag->class = 'next'; $a_tag->setContent(Pinhole::_('Next')); $a_tag->display(); $this->html_head_entry_set->addEntry(new SwatLinkHtmlHeadEntry($href, 'prefetch', null, null, Pinhole::PACKAGE_ID)); $this->html_head_entry_set->addEntry(new SwatLinkHtmlHeadEntry($photo->getUri('large'), 'prefetch', null, null, Pinhole::PACKAGE_ID)); $this->html_head_entry_set->addEntry(new SwatLinkHtmlHeadEntry($href, 'next', null, $photo->title, Pinhole::PACKAGE_ID)); } }
protected function buildNavBar() { parent::buildNavBar(); $this->layout->navbar->createEntry($this->photo->getTitle(), 'Photo/Edit?id=' . $this->photo->id); }
/** * Applies this tag to a photo * * Any unsaved changes to the tag and photo are saved before this tag is * applied to the photo. * * @param PinholePhoto $photo the photo this tag is to be applied to. */ public function applyToPhoto(PinholePhoto $photo) { $transaction = new SwatDBTransaction($this->db); try { // save photo and tag $photo->save(); $this->save(); // save binding $sql = sprintf('insert into PhotoPhotoTagBinding (photo, tag) values (%s, %s)', $this->db->quote($photo->id, 'integer'), $this->db->quote($this->id, 'integer')); SwatDB::exec($this->db, $sql); $transaction->commit(); } catch (Exception $e) { $transaction->rollback(); throw $e; } $this->photos->add($photo); }
protected function getTileClasses(PinholePhoto $photo) { $classes = array(); if (!$photo->isPublished()) { $classes[] = 'insensitive'; } if ($photo->private) { $classes[] = 'private'; } return implode(' ', $classes); }
/** * Processes actions on photos * * @param SwatTableView $view the view to process. * @param SwatActions $actions the list of actions. */ public function process($view, $actions, $ui) { switch ($actions->selected->id) { case 'delete': $this->page->app->replacePage('Photo/Delete'); $this->page->app->getPage()->setItems($view->getSelection(), $view->isExtendedCheckAllSelected()); break; case 'time': $this->page->app->replacePage('Photo/Time'); $this->page->app->getPage()->setItems($view->getSelection(), $view->isExtendedCheckAllSelected()); break; case 'private': if ($ui->getWidget('passphrase')->value !== null) { $this->page->app->config->pinhole->passphrase = md5($ui->getWidget('passphrase')->value); $this->page->app->config->save(array('pinhole.passphrase')); } if ($this->page->app->config->pinhole->passphrase !== null) { $photos = $this->getPhotos($view); $num = count($photos); foreach ($photos as $photo) { $photo->private = true; $photo->save(); } if (isset($this->page->app->memcache)) { $this->page->app->memcache->flushNs('photos'); } $message = new SwatMessage(sprintf(Pinhole::ngettext('One photo has been set as private.', '%s photos have been set as private.', $num), SwatString::numberFormat($num))); $this->page->app->messages->add($message); } break; case 'public': $photos = $this->getPhotos($view); $num = count($photos); foreach ($photos as $photo) { $photo->private = true; $photo->save(); } if (isset($this->page->app->memcache)) { $this->page->app->memcache->flushNs('photos'); } $message = new SwatMessage(sprintf(Pinhole::ngettext('One photo has been set as public.', '%s photos have been set as public.', $num), SwatString::numberFormat($num))); $this->page->app->messages->add($message); break; case 'for_sale': case 'not_for_sale': $photos = $this->getPhotos($view); $num = count($photos); foreach ($photos as $photo) { $photo->for_sale = $actions->selected->id == 'for_sale'; $photo->save(); } if (isset($this->page->app->memcache)) { $this->page->app->memcache->flushNs('photos'); } if ($actions->selected->id == 'for_sale') { $message = new SwatMessage(sprintf(Pinhole::ngettext('One photo has been set as for-sale.', '%s photos have been set as for-sale.', $num), SwatString::numberFormat($num))); } else { $message = new SwatMessage(sprintf(Pinhole::ngettext('One photo has been set as not for-sale.', '%s photos have been set as not for-sale.', $num), SwatString::numberFormat($num))); } $this->page->app->messages->add($message); break; case 'publish': case 'status_action': $photos = $this->getPhotos($view); $num = count($photos); if ($ui->hasWidget('status_flydown')) { $status = $ui->getWidget('status_flydown')->value; } else { $status = PinholePhoto::STATUS_PUBLISHED; } foreach ($photos as $photo) { $photo->setStatus($status); $photo->save(); } if (isset($this->page->app->memcache)) { $this->page->app->memcache->flushNs('photos'); } $message = new SwatMessage(sprintf(Pinhole::ngettext('One photo has been updated to “%2$s”.', '%1$s photos have been updated to “%2$s”.', $num), SwatString::numberFormat($num), PinholePhoto::getStatusTitle($status))); $this->page->app->messages->add($message); break; case 'tags_action': $tag_array = $ui->getWidget('tags')->getSelectedTagArray(); if (count($tag_array) > 0) { $photos = $this->getPhotos($view); $num = count($photos); foreach ($photos as $photo) { $photo->addTagsByName($tag_array); } if (isset($this->page->app->memcache)) { $this->page->app->memcache->flushNs('photos'); } if (count($tag_array) > 1) { $message = new SwatMessage(sprintf(Pinhole::ngettext('%s tags have been added to one photo.', '%s tags have been added to %s photos.', $num), SwatString::numberFormat(count($tag_array)), SwatString::numberFormat($num))); } else { $message = new SwatMessage(sprintf(Pinhole::ngettext('A tag has been added to one photo.', 'A tag has been added to %s photos.', $num), SwatString::numberFormat($num))); } $this->page->app->messages->add($message); } // reset tag list $ui->getWidget('tags')->setSelectedTagArray(array()); break; } }
protected function getPhotoContent(PinholePhoto $photo, PinholeImageDimension $dimension) { ob_start(); $div_tag = new SwatHtmlTag('div'); $div_tag->open(); $img = $photo->getImgTag($dimension->shortname); $img->src = $this->app->getBaseHref() . $img->src; $img->display(); if ($photo->description !== null) { $div_tag = new SwatHtmlTag('div'); $div_tag->setContent($photo->description, 'text/xml'); $div_tag->display(); } $div_tag->close(); return ob_get_clean(); }
private function displaySinglePhoto(PinholePhoto $photo, $tag_list) { $a_tag = new SwatHtmlTag('a'); $a_tag->href = sprintf('%sphoto/%s', $this->app->config->pinhole->path, $photo->id); if ($tag_list !== null) { $a_tag->href .= '?' . $tag_list; } $a_tag->open(); echo $photo->getImgTag('small')->__toString(); if ($photo->getTitle() != '') { $h2_tag = new SwatHtmlTag('div'); $h2_tag->setContent($photo->getTitle()); $h2_tag->display(); } $a_tag->close(); }
protected function getTileClasses(PinholePhoto $photo) { $classes = array(); if ($photo->private && $photo->isPublished()) { $classes[] = 'published-private'; } elseif ($photo->private) { $classes[] = 'private'; } elseif ($photo->isPublished()) { $classes[] = 'published'; } return implode(' ', $classes); }