/** * For initializing members of the class. * * @param array $args misc. arguments * * @return boolean true */ function prepare($args) { parent::prepare($args); if (!$this->isPost()) { throw new ClientException(_('POST only'), 405); } $this->checkSessionToken(); $this->url = $this->trimmed('url'); if (empty($this->url)) { throw new ClientException(_('URL is required.'), 400); } if (!Validate::uri($this->url, array('allowed_schemes' => array('http', 'https')))) { throw new ClientException(_('Invalid URL.'), 400); } $f = File::staticGet('url', $this->url); if (empty($url)) { $f = File::processNew($this->url); } // How about now? if (!empty($f)) { $this->oembed = File_oembed::staticGet('file_id', $f->id); if (!empty($this->oembed)) { $this->title = $this->oembed->title; } $this->thumbnail = File_thumbnail::staticGet('file_id', $f->id); } return true; }
/** * Show core. * * Shows local navigation, content block and aside. * * @return nothing */ function showCore() { $file_thumbnail = File_thumbnail::staticGet('file_id', $this->attachment->id); if (empty($file_thumbnail->url)) { return; } $this->element('img', array('src' => $file_thumbnail->url, 'alt' => 'Thumbnail')); }
/** * Get the attachment's thumbnail record, if any. * * @return File_thumbnail */ function getThumbnail() { return File_thumbnail::staticGet('file_id', $this->id); }
function common_linkify($url) { // It comes in special'd, so we unspecial it before passing to the stringifying // functions $url = htmlspecialchars_decode($url); if (strpos($url, '@') !== false && strpos($url, ':') === false) { //url is an email address without the mailto: protocol $canon = "mailto:{$url}"; $longurl = "mailto:{$url}"; } else { $canon = File_redirection::_canonUrl($url); $longurl_data = File_redirection::where($canon); if (is_array($longurl_data)) { $longurl = $longurl_data['url']; } elseif (is_string($longurl_data)) { $longurl = $longurl_data; } else { throw new ServerException("Can't linkify url '{$url}'"); } } $attrs = array('href' => $canon, 'title' => $longurl, 'rel' => 'external'); $is_attachment = false; $attachment_id = null; $has_thumb = false; // Check to see whether this is a known "attachment" URL. $f = File::staticGet('url', $longurl); if (empty($f)) { // XXX: this writes to the database. :< $f = File::processNew($longurl); } if (!empty($f)) { if ($f->getEnclosure()) { $is_attachment = true; $attachment_id = $f->id; $thumb = File_thumbnail::staticGet('file_id', $f->id); if (!empty($thumb)) { $has_thumb = true; } } } // Add clippy if ($is_attachment) { $attrs['class'] = 'attachment'; if ($has_thumb) { $attrs['class'] = 'attachment thumbnail'; } $attrs['id'] = "attachment-{$attachment_id}"; } return XMLStringer::estring('a', $attrs, $url); }
function common_linkify($url) { // It comes in special'd, so we unspecial it before passing to the stringifying // functions $url = htmlspecialchars_decode($url); if (strpos($url, '@') !== false && strpos($url, ':') === false && Validate::email($url)) { //url is an email address without the mailto: protocol $canon = "mailto:{$url}"; $longurl = "mailto:{$url}"; } else { $canon = File_redirection::_canonUrl($url); $longurl_data = File_redirection::where($canon, common_config('attachments', 'process_links')); if (is_array($longurl_data)) { $longurl = $longurl_data['url']; } elseif (is_string($longurl_data)) { $longurl = $longurl_data; } else { // Unable to reach the server to verify contents, etc // Just pass the link on through for now. common_log(LOG_ERR, "Can't linkify url '{$url}'"); $longurl = $url; } } $attrs = array('href' => $canon, 'title' => $longurl); $is_attachment = false; $attachment_id = null; $has_thumb = false; // Check to see whether this is a known "attachment" URL. $f = File::staticGet('url', $longurl); if (empty($f)) { if (common_config('attachments', 'process_links')) { // XXX: this writes to the database. :< $f = File::processNew($longurl); } } if (!empty($f)) { if ($f->getEnclosure()) { $is_attachment = true; $attachment_id = $f->id; $thumb = File_thumbnail::staticGet('file_id', $f->id); if (!empty($thumb)) { $has_thumb = true; } } } // Add clippy if ($is_attachment) { $attrs['class'] = 'attachment'; if ($has_thumb) { $attrs['class'] = 'attachment thumbnail'; } $attrs['id'] = "attachment-{$attachment_id}"; } // Whether to nofollow $nf = common_config('nofollow', 'external'); if ($nf == 'never') { $attrs['rel'] = 'external'; } else { $attrs['rel'] = 'nofollow external'; } return XMLStringer::estring('a', $attrs, $url); }
function showRepresentation() { $thumbnail = File_thumbnail::staticGet('file_id', $this->attachment->id); if (!empty($thumbnail)) { $this->out->element('img', array('alt' => '', 'src' => $thumbnail->url, 'width' => $thumbnail->width, 'height' => $thumbnail->height)); } }
/** * Pull a thumbnail image reference for the given file, and if necessary * resize it to match currently thumbnail size settings. * * @return File_Thumbnail or false/null */ function getThumbInfo() { $thumbnail = File_thumbnail::staticGet('file_id', $this->attachment->id); if ($thumbnail) { $maxWidth = common_config('attachments', 'thumb_width'); $maxHeight = common_config('attachments', 'thumb_height'); if ($thumbnail->width > $maxWidth) { $thumb = clone $thumbnail; $thumb->width = $maxWidth; $thumb->height = intval($thumbnail->height * $maxWidth / $thumbnail->width); return $thumb; } } return $thumbnail; }
/** * Save embedding info for a new file. * * @param object $data Services_oEmbed_Object_* * @param int $file_id */ function saveNew($data, $file_id) { $file_oembed = new File_oembed(); $file_oembed->file_id = $file_id; $file_oembed->version = $data->version; $file_oembed->type = $data->type; if (!empty($data->provider_name)) { $file_oembed->provider = $data->provider_name; } if (!empty($data->provider)) { $file_oembed->provider = $data->provider; } if (!empty($data->provide_url)) { $file_oembed->provider_url = $data->provider_url; } if (!empty($data->width)) { $file_oembed->width = intval($data->width); } if (!empty($data->height)) { $file_oembed->height = intval($data->height); } if (!empty($data->html)) { $file_oembed->html = $data->html; } if (!empty($data->title)) { $file_oembed->title = $data->title; } if (!empty($data->author_name)) { $file_oembed->author_name = $data->author_name; } if (!empty($data->author_url)) { $file_oembed->author_url = $data->author_url; } if (!empty($data->url)) { $file_oembed->url = $data->url; $given_url = File_redirection::_canonUrl($file_oembed->url); if (!empty($given_url)) { $file = File::staticGet('url', $given_url); if (empty($file)) { $file_redir = File_redirection::staticGet('url', $given_url); if (empty($file_redir)) { $redir_data = File_redirection::where($given_url); $file_oembed->mimetype = $redir_data['type']; } else { $file_id = $file_redir->file_id; } } else { $file_oembed->mimetype = $file->mimetype; } } } $file_oembed->insert(); if (!empty($data->thumbnail_url) || $data->type == 'photo') { $ft = File_thumbnail::staticGet('file_id', $file_id); if (!empty($ft)) { common_log(LOG_WARNING, "Strangely, a File_thumbnail object exists for new file {$file_id}", __FILE__); } else { File_thumbnail::saveNew($data, $file_id); } } }
/** * Output the HTML for a bookmark in a list * * @param NoticeListItem $nli The list item being shown. * * @return boolean hook value */ function onStartShowNoticeItem($nli) { $nb = Bookmark::getByNotice($nli->notice); if (!empty($nb)) { $out = $nli->out; $notice = $nli->notice; $profile = $nli->profile; $atts = $notice->attachments(); if (count($atts) < 1) { // Something wrong; let default code deal with it. return true; } $att = $atts[0]; // XXX: only show the bookmark URL for non-single-page stuff if ($out instanceof ShowbookmarkAction) { } else { $out->elementStart('h3'); $out->element('a', array('href' => $att->url, 'class' => 'bookmark-title entry-title'), $nb->title); $out->elementEnd('h3'); $countUrl = common_local_url('noticebyurl', array('id' => $att->id)); $out->element('a', array('class' => 'bookmark-notice-count', 'href' => $countUrl), $att->noticeCount()); } // Replies look like "for:" tags $replies = $nli->notice->getReplies(); $tags = $nli->notice->getTags(); if (!empty($replies) || !empty($tags)) { $out->elementStart('ul', array('class' => 'bookmark-tags')); foreach ($replies as $reply) { $other = Profile::staticGet('id', $reply); $out->elementStart('li'); $out->element('a', array('rel' => 'tag', 'href' => $other->profileurl, 'title' => $other->getBestName()), sprintf('for:%s', $other->nickname)); $out->elementEnd('li'); $out->text(' '); } foreach ($tags as $tag) { $out->elementStart('li'); $out->element('a', array('rel' => 'tag', 'href' => Notice_tag::url($tag)), $tag); $out->elementEnd('li'); $out->text(' '); } $out->elementEnd('ul'); } if (!empty($nb->description)) { $out->element('p', array('class' => 'bookmark-description'), $nb->description); } if (common_config('attachments', 'show_thumbs')) { $haveThumbs = false; foreach ($atts as $check) { $thumbnail = File_thumbnail::staticGet('file_id', $check->id); if (!empty($thumbnail)) { $haveThumbs = true; break; } } if ($haveThumbs) { $al = new InlineAttachmentList($notice, $out); $al->show(); } } $out->elementStart('div', array('class' => 'bookmark-info entry-content')); $avatar = $profile->getAvatar(AVATAR_MINI_SIZE); $out->element('img', array('src' => $avatar ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_MINI_SIZE), 'class' => 'avatar photo bookmark-avatar', 'width' => AVATAR_MINI_SIZE, 'height' => AVATAR_MINI_SIZE, 'alt' => $profile->getBestName())); $out->raw(' '); $out->element('a', array('href' => $profile->profileurl, 'title' => $profile->getBestName()), $profile->nickname); $nli->showNoticeLink(); $nli->showNoticeSource(); $nli->showNoticeLocation(); $nli->showContext(); $nli->showRepeat(); $out->elementEnd('div'); $nli->showNoticeOptions(); return false; } return true; }