public function execute() { $photo_id = waRequest::get('photo_id', null, waRequest::TYPE_INT); $size = waRequest::get('size', null, waRequest::TYPE_STRING); $album = null; $photo_model = new photosPhotoModel(); $photo = $photo_model->getById($photo_id); if (!$photo) { throw new waException(_w("Unknown photo")); } $photo['frontend_link'] = photosFrontendPhoto::getLink($photo, $album); $sizes = $this->getConfig()->getSizes(); $contexts = array(); foreach ($sizes as $sz) { $contexts[$sz]['html'] = photosPhoto::getEmbedImgHtml($photo, $sz); $contexts[$sz]['url'] = photosPhoto::getPhotoUrl($photo, $sz, true); } if (!$size || !isset($contexts[$size])) { $size = $sizes[0]; } $domains = photosPhoto::getDomains(null, $photo); if (count($domains) <= 1) { $domains = array(); } $this->view->assign('photo', $photo); $this->view->assign('sizes', $sizes); $this->view->assign('size', $size); $this->view->assign('contexts', $contexts); $this->view->assign('original_domain', wa()->getRootUrl(true)); $this->view->assign('domains', $domains); }
/** * Get image with special predefined attributes needed for RIA UI in frontend * * @param array $photo * @param string $size * @param array $attributes user-attribure, e.g. class or style * @return string */ public function getImgHtml($photo, $size, $attributes = array(), $style = true) { $attributes['data-size'] = $size; $attributes['data-photo-id'] = $photo['id']; $attributes['class'] = !empty($attributes['class']) ? $attributes['class'] : ''; $attributes['class'] .= ' photo_img'; // !Important: obligatory class. Need in frontend JS return photosPhoto::getEmbedImgHtml($photo, $size, $attributes, $style, false, $this->cdn); }
public static function getEmbedPhotoListContext($hash, $size, $limit = null, $context = null) { $link = photosCollection::getFrontendLink($hash); $collection = new photosCollection($hash); $thumb_key = 'thumb_' . $size; $photos = $collection->getPhotos('*, ' . $thumb_key, 0, $limit == null ? 500 : $limit); $photo_ids = array_keys($photos); $photo_model = new photosPhotoModel(); $public_photo_ids = $photo_model->filterByField($photo_ids, 'status', 1); $all_public = count($photo_ids) == count($public_photo_ids); // change default collection sort if hash looks like id/1,2,3,4 if (strstr($hash, 'id/') !== false) { $photo_ids = explode(',', preg_replace('/\\/*id\\//', '', $hash)); $old_photos = $photos; $photos = array(); foreach ($photo_ids as $photo_id) { $photo_id = intval($photo_id); // need in case of private photo (cause of hash suffix) if (isset($old_photos[$photo_id])) { $photos[$photo_id] = $old_photos[$photo_id]; } } } $urls = ''; $html = ''; $html_with_descriptions = ''; foreach ($photos as $photo) { $urls .= $photo[$thumb_key]['url'] . PHP_EOL; $img_html = photosPhoto::getEmbedImgHtml($photo, $size); $html_with_descriptions .= '<p>' . ($photo['description'] ? $photo['description'] . '<br>' : '') . $img_html . '</p>' . PHP_EOL; $html .= $img_html . '<br>' . PHP_EOL; } $params_string = '"' . $hash . '", "' . $size . '"'; $smarty_code = '{if $wa->photos}' . PHP_EOL; $smarty_code .= ' {$photos = $wa->photos->photos(' . $params_string . ')}' . PHP_EOL; $smarty_code .= ' {foreach $photos as $photo}' . PHP_EOL; $smarty_code .= ' <p>{if $photo.description}{$photo.description}<br>{/if}' . PHP_EOL; $smarty_code .= ' <img src=\'{$photo.' . $thumb_key . '.url}\' alt=\'{$photo.name}.{$photo.ext}\'>' . PHP_EOL; $smarty_code .= ' </p>' . PHP_EOL; $smarty_code .= ' {/foreach}' . PHP_EOL; $smarty_code .= '{/if}' . PHP_EOL; return array('urls' => $urls, 'html' => $html, 'html_with_descriptions' => $html_with_descriptions, 'link' => $link, 'smarty_code' => $smarty_code, 'count' => count($photos), 'all_public' => $all_public, 'domains' => self::getDomains($hash)); }
public function explainLogs($logs) { $logs = parent::explainLogs($logs); $photo_ids = array(); foreach ($logs as $l_id => $l) { if (in_array($l['action'], array('photos_upload')) && $l['params']) { $photo_ids = array_merge($photo_ids, explode(',', $l['params'])); } } if ($photo_ids) { $photo_model = new photosPhotoModel(); $photos = $photo_model->getById($photo_ids); } foreach ($logs as $l_id => $l) { if (in_array($l['action'], array('photos_upload'))) { $ids = explode(',', $l['params']); $html = ''; foreach ($ids as $id) { if (!empty($photos[$id])) { $p = $photos[$id]; $url = wa()->getConfig()->getBackendUrl(true) . $l['app_id'] . '/#/photo/' . $id . '/'; $_is_2x_enabled = $this->getOption('enable_2x'); $_image_size = '96x96'; if ($_is_2x_enabled) { $_image_size = '96x96@2x'; } $img = photosPhoto::getEmbedImgHtml($p, $_image_size); $html .= '<div class="photo-item"><a href="' . $url . '">' . $img . '</a></div>'; } } if ($html) { $logs[$l_id]['params_html'] = '<div class="activity-photo-wrapper"><div class="activity-photo-list">' . $html . '</div></div>'; } } } return $logs; }