protected function buildInternal() { parent::buildInternal(); if (count($this->ui->getWidget('index_view')->model) == 0 && count($this->unprocessed_photos) == 0) { $this->app->relocate($this->getComponentName() . '/Pending'); } $this->ui->getWidget('index_frame')->title = Pinhole::_('Last Upload'); if (count($this->unprocessed_photos) > 0) { $this->ui->getWidget('processing_message_content')->content = sprintf(Pinhole::ngettext('You have one photo waiting to be processed', 'You have %s photos waiting to be processed', count($this->unprocessed_photos)), count($this->unprocessed_photos)); } $tile_view = $this->ui->getWidget('index_view'); $tile_view->check_all_visible_count += count($this->unprocessed_photos); $tile_view->check_all_extended_count = count($this->unprocessed_photos) + $this->getAllPendingPhotosCount(); if ($tile_view->check_all_extended_count > $tile_view->check_all_visible_count) { $tile_view->show_check_all = true; $frame = $this->ui->getWidget('index_frame'); $frame->title_content_type = 'text/xml'; $frame->subtitle = sprintf('<a href="Photo/Pending">%s</a>', sprintf(Pinhole::_('View all %s pending photos'), $tile_view->check_all_extended_count)); } if (count($this->unprocessed_photos) > 0) { $tile_view->show_check_all = true; $this->ui->getWidget('index_actions')->visible = true; $this->ui->getWidget('processing_form')->visible = true; } }
protected function processActions(SwatTableView $view, SwatActions $actions) { $num = count($view->getSelection()); $message = null; switch ($actions->selected->id) { case 'delete': $this->app->replacePage('MetaData/Delete'); $this->app->getPage()->setItems($view->checked_items); break; case 'show_details': SwatDB::updateColumn($this->app->db, 'PinholeMetaData', 'boolean:visible', true, 'id', $view->getSelection()); $message = new SwatMessage(sprintf(Pinhole::ngettext('One detail has been enabled.', '%s details have been enabled.', $num), SwatString::numberFormat($num))); break; case 'dont_show_details': SwatDB::updateColumn($this->app->db, 'PinholeMetaData', 'boolean:visible', false, 'id', $view->getSelection()); $message = new SwatMessage(sprintf(Pinhole::ngettext('One detail has been disabled.', '%s details have been disabled.', $num), SwatString::numberFormat($num))); break; case 'show_machine': SwatDB::updateColumn($this->app->db, 'PinholeMetaData', 'boolean:machine_tag', true, 'id', $view->getSelection()); $message = new SwatMessage(sprintf(Pinhole::ngettext('One machine tag has been enabled.', '%s machine tags have been enabled.', $num), SwatString::numberFormat($num))); break; case 'dont_show_machine': SwatDB::updateColumn($this->app->db, 'PinholeMetaData', 'boolean:machine_tag', false, 'id', $view->getSelection()); $message = new SwatMessage(sprintf(Pinhole::ngettext('One machine tag has been disabled.', '%s machine tags have been disabled.', $num), SwatString::numberFormat($num))); break; } if ($message !== null) { $this->app->messages->add($message); } }
protected function processDBData() { parent::processDBData(); $instance_id = $this->app->getInstanceId(); $sql = 'delete from PinholePhotographer where id in (%s) and instance %s %s'; $item_list = $this->getItemList('integer'); $sql = sprintf($sql, $item_list, SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer')); $num = SwatDB::exec($this->app->db, $sql); $message = new SwatMessage(sprintf(Pinhole::ngettext('One photographer has been deleted.', '%s photographers have been deleted.', $num), SwatString::numberFormat($num))); $this->app->messages->add($message); }
public function display() { if (!$this->visible) { return; } if ($this->tag_list === null) { return; } if ($this->sub_tag_list === null || count($this->sub_tag_list) == 0) { return; } parent::display(); $div_tag = new SwatHtmlTag('div'); $div_tag->class = 'pinhole-sub-tag-list-view'; $div_tag->id = $this->id; $div_tag->open(); if (count($this->tag_list) > 0) { $titles = array(); foreach ($this->tag_list as $tag) { $titles[] = $tag->getTitle(); } $header_tag = new SwatHtmlTag('h2'); $header_tag->setContent(sprintf(Pinhole::_('View photos tagged “%s” and:'), implode('”, “', $titles))); $header_tag->display(); } elseif ($this->title !== null) { $header_tag = new SwatHtmlTag('h2'); $header_tag->setContent($this->title); $header_tag->display(); } $ul_tag = new SwatHtmlTag('ul'); $ul_tag->id = $this->id . '_list'; $ul_tag->open(); $li_tag = new SwatHtmlTag('li'); foreach ($this->sub_tag_list as $tag) { $add_list = clone $this->tag_list; $add_list->add($tag); $li_tag->open(); $add_anchor_tag = new SwatHtmlTag('a'); $add_anchor_tag->class = 'pinhole-tag-list-view-tag'; $add_anchor_tag->rel = 'tag'; $add_anchor_tag->href = $this->base . '?' . $add_list->__toString(); $add_anchor_tag->setContent($tag->getTitle()); if ($tag->photo_count !== null) { $add_anchor_tag->title = sprintf('%s %s', SwatString::minimizeEntities(SwatString::numberFormat($tag->photo_count)), SwatString::minimizeEntities(Pinhole::ngettext('Photo', 'Photos', $tag->photo_count))); } $add_anchor_tag->display(); $li_tag->close(); unset($add_list); } $ul_tag->close(); $div_tag->close(); }
/** * Processes photographer actions * * @param SwatTableView $view the table-view to get selected photographers * from. * @param SwatActions $actions the actions list widget. */ protected function processActions(SwatTableView $view, SwatActions $actions) { switch ($actions->selected->id) { case 'delete': $this->app->replacePage('Photographer/Delete'); $this->app->getPage()->setItems($view->checked_items); break; case 'status_action': $num = count($view->checked_items); $status = $this->ui->getWidget('status_flydown')->value; SwatDB::updateColumn($this->app->db, 'PinholePhotographer', 'integer:status', $status, 'id', $view->checked_items); $message = new SwatMessage(sprintf(Pinhole::ngettext('The status of one photographer has been changed.', 'The status of %s photographers has been changed.', $num), SwatString::numberFormat($num))); $this->app->messages->add($message); break; } }
protected function processDBData() { parent::processDBData(); $sql = 'delete from PinholeTag where instance %s %s'; $item_list = $this->getItemList('integer'); $instance_id = $this->app->getInstanceId(); $sql = sprintf($sql, SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer')); if (!$this->extended_selected) { $sql .= sprintf(' and id in (%s)', $item_list); } $num = SwatDB::exec($this->app->db, $sql); if (isset($this->app->memcache)) { $this->app->memcache->flushNs('photos'); } $message = new SwatMessage(sprintf(Pinhole::ngettext('One tag has been deleted.', '%s tags have been deleted.', $num), SwatString::numberFormat($num))); $this->app->messages->add($message); }
protected function processDBData() { parent::processDBData(); $item_list = $this->getItemList('integer'); $instance_id = $this->app->getInstanceId(); $this->addToSearchQueue($item_list); $sql = sprintf('delete from PinholeComment where id in (select PinholeComment.id from PinholeComment inner join PinholePhoto on PinholePhoto.id = PinholeComment.photo inner join ImageSet on PinholePhoto.image_set = ImageSet.id where instance %s %s and PinholeComment.id in (%s))', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $item_list); $num = SwatDB::exec($this->app->db, $sql); if (isset($this->app->memcache)) { $this->app->memcache->flushNS('photos'); } $message = new SwatMessage(sprintf(Pinhole::ngettext('One comment has been deleted.', '%s comments have been deleted.', $num), SwatString::numberFormat($num))); $this->app->messages->add($message); }
protected function displayTag(PinholeTag $tag) { $add_list = clone $this->tag_list; $add_list->add($tag); $add_anchor_tag = new SwatHtmlTag('a'); $add_anchor_tag->rel = 'tag'; $add_anchor_tag->href = $this->app->config->pinhole->path . 'tag?' . $add_list->__toString(); $add_anchor_tag->setContent($tag->getTitle()); if ($tag->photo_count !== null) { $add_anchor_tag->title = sprintf('%s %s', SwatString::minimizeEntities(SwatString::numberFormat($tag->photo_count)), SwatString::minimizeEntities(Pinhole::ngettext('Photo', 'Photos', $tag->photo_count))); } $add_anchor_tag->display(); }
protected function buildInternal() { parent::buildInternal(); if ($this->extended_selected) { // note the only page with an extended-selection that accesses this // is the pending photos page - so the message can be more // specific. $message = $this->ui->getWidget('confirmation_message'); $message->content_type = 'text/xml'; $message->content = Pinhole::_('<strong>Are you sure ' . 'you want to delete all pending photos?</strong>'); } else { $container = $this->ui->getWidget('confirmation_container'); $delete_view = $this->ui->getWidget('delete_view'); $store = new SwatTableStore(); foreach ($this->getPhotos() as $photo) { $ds = new SwatDetailsStore(); $ds->photo = $photo; $store->add($ds); } $delete_view->model = $store; $message = $this->ui->getWidget('confirmation_message'); $message->content_type = 'text/xml'; $message->content = sprintf(Pinhole::_('<strong>Are you sure ' . 'you want to delete the following %s?</strong>'), Pinhole::ngettext('photo', 'photos', count($store))); } }
/** * 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; } }
/** * Gets a formatted value * * @return string The formatted value. */ private static function formatExposureTime($value) { $values = explode('/', $value); if (count($values) == 2 && $values[1] > 0) { $seconds = (double) $values[0] / (double) $values[1]; } else { $seconds = (double) $value; } $locale = SwatI18NLocale::get(); $output = sprintf(Pinhole::ngettext('%s second', '%s seconds', $seconds == 1 ? 1 : 0), $locale->formatNumber(round($seconds, 6))); $fraction = self::formatAsFraction($value); if ($fraction !== null) { $output = $fraction . ' (' . $output . ')'; } return $output; }
protected function buildPendingCount() { if ($this->getUpcomingPhotoCount() > 0) { $this->ui->getWidget('proceed_button')->visible = true; if ($this->pending) { $this->ui->getWidget('status_info')->content = sprintf(Pinhole::ngettext('%d pending photo left.', '%d pending photos left.', $this->getUpcomingPhotoCount()), $this->getUpcomingPhotoCount()); } } }
/** * Displays date.date tags for all the photos in the site instance of * this date tag browser's tag list * * The <i>$start_date</i> and <i>$end_date</i> are used to tell which * day, month and year are currently selected. * * @param SwatDate $start_date the start date of the photos in this date * tag browser's tag list. * @param SwatDate $end_date the end date of the photos in this date * tag browser's tag list. */ protected function displayDays(SwatDate $start_date, SwatDate $end_date) { $date = new SwatDate(); /* * Setting the month and year to the $start_date month and year makes * sense because the day list is only displayed if the start year and * month are the same as the end year and month. */ $date->setMonth($start_date->getMonth()); $date->setYear($start_date->getYear()); // get selected day if it exists if ($start_date->getDay() == $end_date->getDay()) { $selected_day = $start_date->getDay(); } else { $selected_day = null; } // create base tag list that new date.month tags will be added to $tag_list = $this->tag_list->filter(array('PinholeDateTag')); $tag_list->add(sprintf('date.year=%s', $date->formatLikeIntl('yyyy'))); $tag_list->add(sprintf('date.month=%s', $date->formatLikeIntl('MM'))); $photos = $tag_list->getPhotoCountByDate('day'); // Filter again since the day list uses date.date tags instead of // combined date.year, date.month and date.day tags. $tag_list = $this->tag_list->filter(array('PinholeDateTag')); // display date.date tags for each day $div_tag = new SwatHtmlTag('div'); $div_tag->class = 'days clearfix'; $div_tag->open(); $days_in_month = $date->getDaysInMonth(); for ($i = 1; $i <= $days_in_month; $i++) { $date->setDay($i); $key = $date->formatLikeIntl('yyyy-MM-dd'); $tag_string = sprintf('date.date=%s', $date->formatLikeIntl('yyyy-MM-dd')); $tag_list->add($tag_string); if ($selected_day === $i) { $span_tag = new SwatHtmlTag('span'); $span_tag->setContent($date->formatLikeIntl('dd')); $span_tag->class = 'selected'; $span_tag->display(); } elseif (array_key_exists($key, $photos)) { $a_tag = new SwatHtmlTag('a'); $a_tag->href = $this->base . '?' . $tag_list->__toString(); $a_tag->title = sprintf(Pinhole::ngettext('1 photo', '%s photos', $photos[$key]), SwatString::numberFormat($photos[$key])); $a_tag->setContent($date->formatLikeIntl('dd')); $a_tag->display(); } else { $span_tag = new SwatHtmlTag('span'); $span_tag->setContent($date->formatLikeIntl('dd')); $span_tag->display(); } $tag_list->remove($tag_string); } $div_tag->close(); }
/** * Processes photographer actions * * @param SwatTableView $view the table-view to get selected tags * from. * @param SwatActions $actions the actions list widget. */ protected function processActions(SwatTableView $view, SwatActions $actions) { switch ($actions->selected->id) { case 'delete': $this->app->replacePage($this->getComponentName() . '/Delete'); $this->app->getPage()->setItems($view->checked_items, $view->getColumn('checkbox')->isExtendedCheckAllSelected()); break; case 'archive': $num = count($view->checked_items); $sql = sprintf('update PinholeTag set archived = true where PinholeTag.instance = %s and PinholeTag.id in(%s)', $this->app->db->quote($this->app->getInstanceId(), 'integer'), SwatDB::implodeSelection($this->app->db, $view->getSelection())); SwatDB::exec($this->app->db, $sql); $message = new SwatMessage(sprintf(Pinhole::ngettext('One tag has been archived.', '%s tags have been archived.', $num), SwatString::numberFormat($num))); $this->app->messages->add($message); break; case 'unarchive': $num = count($view->checked_items); $sql = sprintf('update PinholeTag set archived = false where PinholeTag.instance = %s and PinholeTag.id in(%s)', $this->app->db->quote($this->app->getInstanceId(), 'integer'), SwatDB::implodeSelection($this->app->db, $view->getSelection())); SwatDB::exec($this->app->db, $sql); $message = new SwatMessage(sprintf(Pinhole::ngettext('One tag has been set as not archived.', '%s tags have been set as not archived.', $num), SwatString::numberFormat($num))); $this->app->messages->add($message); break; case 'event': $num = count($view->checked_items); $sql = sprintf('update PinholeTag set event = true where PinholeTag.instance = %s and PinholeTag.id in(%s)', $this->app->db->quote($this->app->getInstanceId(), 'integer'), SwatDB::implodeSelection($this->app->db, $view->getSelection())); SwatDB::exec($this->app->db, $sql); $message = new SwatMessage(sprintf(Pinhole::ngettext('One tag has been set as an event.', '%s tags have been set as events.', $num), SwatString::numberFormat($num))); $this->app->messages->add($message); break; case 'unevent': $num = count($view->checked_items); $sql = sprintf('update PinholeTag set event = false where PinholeTag.instance = %s and PinholeTag.id in(%s)', $this->app->db->quote($this->app->getInstanceId(), 'integer'), SwatDB::implodeSelection($this->app->db, $view->getSelection())); SwatDB::exec($this->app->db, $sql); $message = new SwatMessage(sprintf(Pinhole::ngettext('One tag has been set as not an event.', '%s tags have been set as not events.', $num), SwatString::numberFormat($num))); $this->app->messages->add($message); break; } }
protected function displayCount() { // show a count of photos in the tag list $photo_count = $this->tag_list->getPhotoCount(); $span_tag = new SwatHtmlTag('span'); $span_tag->class = 'photo-count'; $span_tag->setContent(sprintf(Pinhole::ngettext('(%s Photo)', '(%s Photos)', $photo_count), SwatString::numberFormat($photo_count))); $span_tag->display(); }
protected function buildInternal() { parent::buildInternal(); if ($this->extended_selected) { // note the only page with an extended-selection that accesses this // is the pending photos page - so the message can be more // specific. $message = $this->ui->getWidget('confirmation_message'); $message->content_type = 'text/xml'; $message->content = Pinhole::_('<strong>Update the date/time/' . 'time-zone of all pending photos.</strong>'); } else { $this->ui->getWidget('confirmation_frame')->classes[] = 'two-column'; $container = $this->ui->getWidget('confirmation_container'); $photo_view = $this->ui->getWidget('photo_view'); $store = new SwatTableStore(); foreach ($this->getPhotos() as $photo) { $ds = new SwatDetailsStore(); $ds->photo = $photo; $store->add($ds); } $photo_view->model = $store; $message = $this->ui->getWidget('confirmation_message'); $message->content_type = 'text/xml'; $message->content = sprintf(Pinhole::_('<strong>Update the ' . 'date/time/time-zone of the following %s:</strong>'), Pinhole::ngettext('photo', 'photos', count($store))); } }
public static function displayCalendarBody(SiteWebApplication $app, SwatDate $date) { if (isset($app->memcache)) { $cache_key = sprintf('PinholeCalendarGadget.%s.%s.%s', 'displayCalendarBody', $date->getISO8601(), $app->session->isLoggedIn() ? 'private' : 'public'); $body = $app->memcache->getNs('photos', $cache_key); if ($body !== false) { echo $body; return; } } ob_start(); $day_count = self::getPhotoCountPerDay($app, $date); echo '<table>'; $wd = new SwatDate(); $wd->setDate(1995, 1, 1); echo '<tr class="days-of-week">'; for ($i = 1; $i <= 7; $i++) { echo '<td>' . $wd->formatLikeIntl('EEE') . '</td>'; $wd->setDay($i + 1); } echo '</tr>'; $locale = SwatI18NLocale::get(); $start = -1 * $date->getDayOfWeek() + 1; $current_date = clone $date; for ($i = 0; $i <= 41; $i++) { $day = $i + $start; if ($i == 0) { echo '<tr>'; } elseif ($i % 7 == 0) { echo '</tr><tr>'; } if ($day > 0 && $day <= $date->getDaysInMonth()) { $current_date->setDay($day); if (array_key_exists($day, $day_count)) { printf('<td class="has-photos">' . '<a href="%stag?date.date=%s" ' . 'title="%s %s">%s</a></td>', $app->config->pinhole->path, $current_date->formatLikeIntl('yyyy-MM-dd'), $locale->formatNumber($day_count[$day]), Pinhole::ngettext('Photo', 'Photos', $day_count[$day]), $day); } else { echo '<td>' . $day . '</td>'; } } else { echo '<td> </td>'; } } echo '</tr></table>'; $body = ob_get_clean(); if (isset($app->memcache)) { $app->memcache->setNs('photos', $cache_key, $body); } echo $body; }