function saveNew($data, $file_id) { $tn = new File_thumbnail(); $tn->file_id = $file_id; $tn->url = $data->thumbnail_url; $tn->width = intval($data->thumbnail_width); $tn->height = intval($data->thumbnail_height); $tn->insert(); }
/** * 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; }
/** * 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 (!common_valid_http_url($this->url)) { throw new ClientException(_('Invalid URL.'), 400); } try { // processNew will first try to fetch a locally stored File entry $f = File::processNew($this->url); } catch (ServerException $e) { $f = null; } // How about now? if ($f instanceof File) { // FIXME: Use some File metadata Event instead $this->oembed = File_oembed::getKV('file_id', $f->id); if ($this->oembed instanceof File_oembed) { $this->title = $this->oembed->title; } $this->thumbnail = File_thumbnail::getKV('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')); }
/** * Save a thumbnail record for the referenced file record. * * @param int $file_id * @param string $url * @param int $width * @param int $height */ static function saveThumbnail($file_id, $url, $width, $height) { $tn = new File_thumbnail(); $tn->file_id = $file_id; $tn->url = $url; $tn->width = intval($width); $tn->height = intval($height); $tn->insert(); }
public function showPage() { // Returns a File_thumbnail object or throws exception if not available try { $thumbnail = $this->attachment->getThumbnail($this->thumb_w, $this->thumb_h, $this->thumb_c); } catch (UseFileAsThumbnailException $e) { common_redirect($e->file->getUrl()); } common_redirect(File_thumbnail::url($thumbnail->filename)); }
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 (!isset($file_oembed->provider) && !empty($data['provide'])) { $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']; } $file_oembed->insert(); if (!empty($data['thumbnail_url'])) { File_thumbnail::saveNew($data, $file_id); } }
/** * Add stuff to notices in API responses * * @param Action $action action being executed * * @return boolean hook return */ function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped) { // groups $notice_groups = $notice->getGroups(); $group_addressees = false; foreach ($notice_groups as $g) { $group_addressees[] = array('nickname' => $g->nickname, 'url' => $g->mainpage); } $twitter_status['statusnet_in_groups'] = $group_addressees; // for older verions of gnu social: include the repeat-id, which we need when unrepeating later if (array_key_exists('repeated', $twitter_status) && $twitter_status['repeated'] === true) { $repeated = Notice::pkeyGet(array('profile_id' => $scoped->id, 'repeat_of' => $notice->id, 'verb' => 'http://activitystrea.ms/schema/1.0/share')); $twitter_status['repeated_id'] = $repeated->id; } // more metadata about attachments // get all attachments first, and put all the extra meta data in an array $attachments = $notice->attachments(); $attachment_url_to_id = array(); if (!empty($attachments)) { foreach ($attachments as $attachment) { if (is_object($attachment)) { try { $enclosure_o = $attachment->getEnclosure(); // Oembed if (array_key_exists('Oembed', StatusNet::getActivePlugins())) { $oembed = File_oembed::getKV('file_id', $attachment->id); if ($oembed instanceof File_oembed) { $oembed_html = str_replace('<!--//-->', '', $oembed->html); // trash left of wordpress' javascript after htmLawed removed the tags if ($oembed->provider == 'Twitter' && strstr($oembed_html, '>— ' . $oembed->author_name)) { $oembed_html = substr($oembed_html, 0, strpos($oembed_html, '>— ' . $oembed->author_name) + 1); // remove user data from twitter oembed html (we have it in ) $twitter_username = substr($oembed->html, strpos($oembed->html, '>— ' . $oembed->author_name) + strlen('>— ' . $oembed->author_name)); $twitter_username = substr($twitter_username, strpos($twitter_username, '(@') + 1); $twitter_username = substr($twitter_username, 0, strpos($twitter_username, ')')); $oembed->title = $twitter_username; } $oembed_html = str_replace('…', '...', $oembed_html); // ellipsis is sometimes stored as html in db, for some reason $oembed_html = mb_substr(trim(strip_tags(html_entity_decode($oembed_html, ENT_QUOTES))), 0, 250); // sometimes we have html charachters that we want to decode and then strip $oembed_title = trim(strip_tags(html_entity_decode($oembed->title, ENT_QUOTES))); $oembed_provider = trim(strip_tags(html_entity_decode($oembed->provider, ENT_QUOTES))); $oembed_author_name = trim(strip_tags(html_entity_decode($oembed->author_name, ENT_QUOTES))); $attachment_url_to_id[$enclosure_o->url]['oembed'] = array('type' => $oembed->type, 'provider' => $oembed_provider, 'provider_url' => $oembed->provider_url, 'oembedHTML' => $oembed_html, 'title' => $oembed_title, 'author_name' => $oembed_author_name, 'author_url' => $oembed->author_url); } else { $attachment_url_to_id[$enclosure_o->url]['oembed'] = false; } } // add id to all attachments $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id; // add an attachment version to all attachments // this means we can force all cached attachments to update, if we change this $attachment_url_to_id[$enclosure_o->url]['version'] = '1.2'; // add data about thumbnails $thumb = $attachment->getThumbnail(); $large_thumb = $attachment->getThumbnail(1000, 3000, false); if (method_exists('File_thumbnail', 'url')) { $thumb_url = File_thumbnail::url($thumb->filename); $large_thumb_url = File_thumbnail::url($large_thumb->filename); } else { $thumb_url = $thumb->getUrl(); $large_thumb_url = $large_thumb->getUrl(); } $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $large_thumb_url; $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width; $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height; // animated gif? if ($attachment->mimetype == 'image/gif') { $image = ImageFile::fromFileObject($attachment); if ($image->animated == 1) { $attachment_url_to_id[$enclosure_o->url]['animated'] = true; } else { $attachment_url_to_id[$enclosure_o->url]['animated'] = false; } } // this applies to older versions of gnu social, i think } catch (Exception $e) { $thumb = File_thumbnail::getKV('file_id', $attachment->id); if ($thumb instanceof File_thumbnail) { $thumb_url = $thumb->getUrl(); $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id; $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width; $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height; // animated gif? if ($attachment->mimetype == 'image/gif') { $image = ImageFile::fromFileObject($attachment); if ($image->animated == 1) { $attachment_url_to_id[$enclosure_o->url]['animated'] = true; } else { $attachment_url_to_id[$enclosure_o->url]['animated'] = false; } } } } } } } // add the extra meta data to $twitter_status if (!empty($twitter_status['attachments'])) { foreach ($twitter_status['attachments'] as &$attachment) { if (!empty($attachment_url_to_id[$attachment['url']])) { $attachment = array_merge($attachment, $attachment_url_to_id[$attachment['url']]); } } } // quoted notices if (!empty($twitter_status['attachments'])) { foreach ($twitter_status['attachments'] as &$attachment) { $quoted_notice = false; // if this attachment has an url this might be a notice url if (isset($attachment['url'])) { $noticeurl = common_path('notice/', StatusNet::isHTTPS()); $instanceurl = common_path('', StatusNet::isHTTPS()); // remove protocol for the comparison below $noticeurl_wo_protocol = preg_replace('(^https?://)', '', $noticeurl); $instanceurl_wo_protocol = preg_replace('(^https?://)', '', $instanceurl); $attachment_url_wo_protocol = preg_replace('(^https?://)', '', $attachment['url']); // local notice urls if (strpos($attachment_url_wo_protocol, $noticeurl_wo_protocol) === 0) { $possible_notice_id = str_replace($noticeurl_wo_protocol, '', $attachment_url_wo_protocol); if (ctype_digit($possible_notice_id)) { $quoted_notice = Notice::getKV('id', $possible_notice_id); } } elseif (strpos($attachment_url_wo_protocol, $instanceurl_wo_protocol) !== 0 && stristr($attachment_url_wo_protocol, '/notice/')) { $quoted_notice = Notice::getKV('url', $attachment['url']); // try with http<->https if no match. applies to quitter.se notices mostly if (!$quoted_notice instanceof Notice) { if (strpos($attachment['url'], 'https://') === 0) { $quoted_notice = Notice::getKV('url', str_replace('https://', 'http://', $attachment['url'])); } else { $quoted_notice = Notice::getKV('url', str_replace('http://', 'https://', $attachment['url'])); } } } // include the quoted notice in the attachment if ($quoted_notice instanceof Notice) { $quoted_notice_author = Profile::getKV('id', $quoted_notice->profile_id); if ($quoted_notice_author instanceof Profile) { $attachment['quoted_notice']['id'] = $quoted_notice->id; $attachment['quoted_notice']['content'] = $quoted_notice->content; $attachment['quoted_notice']['nickname'] = $quoted_notice_author->nickname; $attachment['quoted_notice']['fullname'] = $quoted_notice_author->fullname; $attachment['quoted_notice']['is_local'] = $quoted_notice_author->isLocal(); $quoted_notice_attachments = $quoted_notice->attachments(); foreach ($quoted_notice_attachments as $q_attach) { if (is_object($q_attach)) { try { $qthumb = $q_attach->getThumbnail(); if (method_exists('File_thumbnail', 'url')) { $thumb_url = File_thumbnail::url($qthumb->filename); } else { $thumb_url = $qthumb->getUrl(); } $attachment['quoted_notice']['attachments'][] = array('thumb_url' => $thumb_url, 'attachment_id' => $q_attach->id); } catch (Exception $e) { common_debug('Qvitter: could not get thumbnail for attachment id=' . $q_attach->id . ' in quoted notice id=' . $quoted_notice->id); } } } } } } } } try { $twitter_status['external_url'] = $notice->getUrl(true); } catch (InvalidUrlException $e) { common_debug('Qvitter: No URL available for external notice: id=' . $notice->id); } // reply-to profile url try { $reply = $notice->getParent(); $twitter_status['in_reply_to_profileurl'] = $reply->getProfile()->getUrl(); } catch (ServerException $e) { $twitter_status['in_reply_to_profileurl'] = null; } // fave number $faves = Fave::byNotice($notice); $favenum = count($faves); $twitter_status['fave_num'] = $favenum; // repeat number $repeats = $notice->repeatStream(); $repeatnum = 0; while ($repeats->fetch()) { if ($repeats->verb == ActivityVerb::SHARE) { // i.e. not deleted repeats $repeatnum++; } } $twitter_status['repeat_num'] = $repeatnum; // is this a post? (previously is_activity) if (method_exists('ActivityUtils', 'compareVerbs')) { $twitter_status['is_post_verb'] = ActivityUtils::compareVerbs($notice->verb, array(ActivityVerb::POST)); } else { $twitter_status['is_post_verb'] = $notice->verb == ActivityVerb::POST ? true : false; } // some more metadata about notice if ($notice->is_local == '1') { $twitter_status['is_local'] = true; } else { $twitter_status['is_local'] = false; if ($twitter_status['is_post_verb'] === true) { try { $twitter_status['external_url'] = $notice->getUrl(true); } catch (InvalidUrlException $e) { common_debug('Qvitter: No URL available for external notice: id=' . $notice->id); } } } if (ActivityUtils::compareTypes($notice->verb, array('qvitter-delete-notice', 'delete'))) { $twitter_status['qvitter_delete_notice'] = true; } return true; }
/** * Save embedding info for a new file. * * @param object $data Services_oEmbed_Object_* * @param int $file_id */ public static function saveNew($data, $file_id) { $file_oembed = new File_oembed(); $file_oembed->file_id = $file_id; if (!isset($data->version)) { common_debug('DEBUGGING oEmbed: data->version undefined in variable $data: ' . var_export($data, true)); } $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->provider_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::getKV('url', $given_url); if ($file instanceof File) { $file_oembed->mimetype = $file->mimetype; } else { $redir = File_redirection::where($given_url); if (empty($redir->file_id)) { $f = $redir->getFile(); $file_oembed->mimetype = $f->mimetype; } else { $file_id = $redir->file_id; } } } } $result = $file_oembed->insert(); if ($result === false) { throw new ServerException('Failed to insert File_oembed data into database!'); } if (!empty($data->thumbnail_url) || $data->type == 'photo') { $ft = File_thumbnail::getKV('file_id', $file_id); if ($ft instanceof File_thumbnail) { common_log(LOG_WARNING, "Strangely, a File_thumbnail object exists for new file {$file_id}", __FILE__); } else { File_thumbnail::saveNew($data, $file_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); }
public function delete($useWhere = false) { // Delete the file, if it exists locally if (!empty($this->filename) && file_exists(self::path($this->filename))) { $deleted = @unlink(self::path($this->filename)); if (!$deleted) { common_log(LOG_ERR, sprintf('Could not unlink existing file: "%s"', self::path($this->filename))); } } // Clear out related things in the database and filesystem, such as thumbnails if (Event::handle('FileDeleteRelated', array($this))) { $thumbs = new File_thumbnail(); $thumbs->file_id = $this->id; if ($thumbs->find()) { while ($thumbs->fetch()) { $thumbs->delete(); } } $f2p = new File_to_post(); $f2p->file_id = $this->id; if ($f2p->find()) { while ($f2p->fetch()) { $f2p->delete(); } } } // And finally remove the entry from the database return parent::delete($useWhere); }
public function delete($useWhere = false) { if (!empty($this->filename) && file_exists(File_thumbnail::path($this->filename))) { $deleted = @unlink(self::path($this->filename)); if (!$deleted) { common_log(LOG_ERR, sprintf('Could not unlink existing file: "%s"', self::path($this->filename))); } } return parent::delete($useWhere); }
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); }
/** * 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; }
protected function storeRemoteFileThumbnail(File_thumbnail $thumbnail) { if (!empty($thumbnail->filename) && file_exists($thumbnail->getPath())) { throw new AlreadyFulfilledException(sprintf('A thumbnail seems to already exist for remote file with id==%u', $thumbnail->file_id)); } $url = $thumbnail->getUrl(); $this->checkWhitelist($url); // First we download the file to memory and test whether it's actually an image file // FIXME: To support remote video/whatever files, this needs reworking. common_debug(sprintf('Downloading remote thumbnail for file id==%u with thumbnail URL: %s', $thumbnail->file_id, $url)); $imgData = HTTPClient::quickGet($url); $info = @getimagesizefromstring($imgData); if ($info === false) { throw new UnsupportedMediaException(_('Remote file format was not identified as an image.'), $url); } elseif (!$info[0] || !$info[1]) { throw new UnsupportedMediaException(_('Image file had impossible geometry (0 width or height)')); } // We'll trust sha256 not to have collision issues any time soon :) $filename = hash('sha256', $imgData) . '.' . common_supported_mime_to_ext($info['mime']); $fullpath = File_thumbnail::path($filename); // Write the file to disk. Throw Exception on failure if (!file_exists($fullpath) && file_put_contents($fullpath, $imgData) === false) { throw new ServerException(_('Could not write downloaded file to disk.')); } // Get rid of the file from memory unset($imgData); // Updated our database for the file record $orig = clone $thumbnail; $thumbnail->filename = $filename; $thumbnail->width = $info[0]; // array indexes documented on php.net: $thumbnail->height = $info[1]; // https://php.net/manual/en/function.getimagesize.php // Throws exception on failure. $thumbnail->updateWithKeys($orig, 'file_id'); }
public function getFileThumbnail($width, $height, $crop) { if (!$this->fileRecord instanceof File) { throw new ServerException('No File object attached to this ImageFile object.'); } if ($width === null) { $width = common_config('thumbnail', 'width'); $height = common_config('thumbnail', 'height'); $crop = common_config('thumbnail', 'crop'); } if ($height === null) { $height = $width; $crop = true; } // Get proper aspect ratio width and height before lookup // We have to do it through an ImageFile object because of orientation etc. // Only other solution would've been to rotate + rewrite uploaded files // which we don't want to do because we like original, untouched data! list($width, $height, $x, $y, $w, $h) = $this->scaleToFit($width, $height, $crop); $thumb = File_thumbnail::pkeyGet(array('file_id' => $this->fileRecord->id, 'width' => $width, 'height' => $height)); if ($thumb instanceof File_thumbnail) { return $thumb; } $filename = $this->fileRecord->filehash ?: $this->filename; // Remote files don't have $this->filehash $extension = File::guessMimeExtension($this->mimetype); $outname = "thumb-{$this->fileRecord->id}-{$width}x{$height}-{$filename}." . $extension; $outpath = File_thumbnail::path($outname); // The boundary box for our resizing $box = array('width' => $width, 'height' => $height, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h); // Doublecheck that parameters are sane and integers. if ($box['width'] < 1 || $box['width'] > common_config('thumbnail', 'maxsize') || $box['height'] < 1 || $box['height'] > common_config('thumbnail', 'maxsize') || $box['w'] < 1 || $box['x'] >= $this->width || $box['h'] < 1 || $box['y'] >= $this->height) { // Fail on bad width parameter. If this occurs, it's due to algorithm in ImageFile->scaleToFit common_debug("Boundary box parameters for resize of {$this->filepath} : " . var_export($box, true)); throw new ServerException('Bad thumbnail size parameters.'); } common_debug(sprintf('Generating a thumbnail of File id==%u of size %ux%u', $this->fileRecord->id, $width, $height)); // Perform resize and store into file $this->resizeTo($outpath, $box); // Avoid deleting the original if ($this->getPath() != File_thumbnail::path($this->filename)) { $this->unlink(); } return File_thumbnail::saveThumbnail($this->fileRecord->id, File_thumbnail::url($outname), $width, $height, $outname); }
/** * 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); } } }
function deleteMissingLocalFileThumbnails() { printfnq("Removing all local File_thumbnail entries without existing files..."); $thumbs = new File_thumbnail(); $thumbs->whereAdd('filename IS NOT NULL'); // only fill in names where they're missing // Checking if there were any File_thumbnail entries without filename if ($thumbs->find()) { while ($thumbs->fetch()) { try { $thumbs->getPath(); } catch (FileNotFoundException $e) { $thumbs->delete(); } } } printfnq("DONE.\n"); }
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)); } }
/** * 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 && 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 (isset($longurl_data->redir_url)) { $longurl = $longurl_data->redir_url; } else { // e.g. local files $longurl = $longurl_data->url; } } $attrs = array('href' => $longurl, 'title' => $longurl); $is_attachment = false; $attachment_id = null; $has_thumb = false; // Check to see whether this is a known "attachment" URL. try { $f = File::getByUrl($longurl); } catch (NoResultException $e) { if (common_config('attachments', 'process_links')) { // XXX: this writes to the database. :< try { $f = File::processNew($longurl); } catch (ServerException $e) { $f = null; } } } if ($f instanceof File) { try { $enclosure = $f->getEnclosure(); $is_attachment = true; $attachment_id = $f->id; $thumb = File_thumbnail::getKV('file_id', $f->id); $has_thumb = $thumb instanceof File_thumbnail; } catch (ServerException $e) { // There was not enough metadata available } } // 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); }
/** * 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; }
/** * Add stuff to notices in API responses * * @param Action $action action being executed * * @return boolean hook return */ function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped) { // groups $notice_groups = $notice->getGroups(); $group_addressees = false; foreach ($notice_groups as $g) { $group_addressees[] = array('nickname' => $g->nickname, 'url' => $g->mainpage); } $twitter_status['statusnet_in_groups'] = $group_addressees; // for older verions of gnu social: include the repeat-id, which we need when unrepeating later if (array_key_exists('repeated', $twitter_status) && $twitter_status['repeated'] === true) { $repeated = Notice::pkeyGet(array('profile_id' => $scoped->id, 'repeat_of' => $notice->id, 'verb' => 'http://activitystrea.ms/schema/1.0/share')); $twitter_status['repeated_id'] = $repeated->id; } // more metadata about attachments // get all attachments first, and put all the extra meta data in an array $attachments = $notice->attachments(); $attachment_url_to_id = array(); if (!empty($attachments)) { foreach ($attachments as $attachment) { if (is_object($attachment)) { try { $enclosure_o = $attachment->getEnclosure(); // add id to all attachments $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id; // add data about thumbnails $thumb = $attachment->getThumbnail(); $large_thumb = $attachment->getThumbnail(1000, 3000, false); if (method_exists('File_thumbnail', 'url')) { $thumb_url = File_thumbnail::url($thumb->filename); $large_thumb_url = File_thumbnail::url($large_thumb->filename); } else { $thumb_url = $thumb->getUrl(); $large_thumb_url = $large_thumb->getUrl(); } $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $large_thumb_url; $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width; $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height; // animated gif? if ($attachment->mimetype == 'image/gif') { $image = ImageFile::fromFileObject($attachment); if ($image->animated == 1) { $attachment_url_to_id[$enclosure_o->url]['animated'] = true; } else { $attachment_url_to_id[$enclosure_o->url]['animated'] = false; } } // this applies to older versions of gnu social, i think } catch (ServerException $e) { $thumb = File_thumbnail::getKV('file_id', $attachment->id); if ($thumb instanceof File_thumbnail) { $thumb_url = $thumb->getUrl(); $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id; $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width; $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height; // animated gif? if ($attachment->mimetype == 'image/gif') { $image = ImageFile::fromFileObject($attachment); if ($image->animated == 1) { $attachment_url_to_id[$enclosure_o->url]['animated'] = true; } else { $attachment_url_to_id[$enclosure_o->url]['animated'] = false; } } } } } } } // add the extra meta data to $twitter_status if (!empty($twitter_status['attachments'])) { foreach ($twitter_status['attachments'] as &$attachment) { if (!empty($attachment_url_to_id[$attachment['url']])) { $attachment = array_merge($attachment, $attachment_url_to_id[$attachment['url']]); } } } // quoted notices if (!empty($twitter_status['attachments'])) { foreach ($twitter_status['attachments'] as &$attachment) { $quoted_notice = false; // if this attachment has an url this might be a notice url if (isset($attachment['url'])) { $noticeurl = common_path('notice/', StatusNet::isHTTPS()); $instanceurl = common_path('', StatusNet::isHTTPS()); // remove protocol for the comparison below $noticeurl_wo_protocol = preg_replace('(^https?://)', '', $noticeurl); $instanceurl_wo_protocol = preg_replace('(^https?://)', '', $instanceurl); $attachment_url_wo_protocol = preg_replace('(^https?://)', '', $attachment['url']); // local notice urls if (strpos($attachment_url_wo_protocol, $noticeurl_wo_protocol) === 0) { $possible_notice_id = str_replace($noticeurl_wo_protocol, '', $attachment_url_wo_protocol); if (ctype_digit($possible_notice_id)) { $quoted_notice = Notice::getKV('id', $possible_notice_id); } } elseif (strpos($attachment_url_wo_protocol, $instanceurl_wo_protocol) !== 0 && stristr($attachment_url_wo_protocol, '/notice/')) { $quoted_notice = Notice::getKV('url', $attachment['url']); // try with http<->https if no match. applies to quitter.se notices mostly if (!$quoted_notice instanceof Notice) { if (strpos($attachment['url'], 'https://') === 0) { $quoted_notice = Notice::getKV('url', str_replace('https://', 'http://', $attachment['url'])); } else { $quoted_notice = Notice::getKV('url', str_replace('http://', 'https://', $attachment['url'])); } } } // include the quoted notice in the attachment if ($quoted_notice instanceof Notice) { $quoted_notice_author = Profile::getKV('id', $quoted_notice->profile_id); if ($quoted_notice_author instanceof Profile) { $attachment['quoted_notice']['id'] = $quoted_notice->id; $attachment['quoted_notice']['content'] = $quoted_notice->content; $attachment['quoted_notice']['nickname'] = $quoted_notice_author->nickname; $attachment['quoted_notice']['fullname'] = $quoted_notice_author->fullname; $quoted_notice_attachments = $quoted_notice->attachments(); foreach ($quoted_notice_attachments as $q_attach) { if (is_object($q_attach)) { try { $qthumb = $q_attach->getThumbnail(); if (method_exists('File_thumbnail', 'url')) { $thumb_url = File_thumbnail::url($qthumb->filename); } else { $thumb_url = $qthumb->getUrl(); } $attachment['quoted_notice']['attachments'][] = array('thumb_url' => $thumb_url, 'attachment_id' => $q_attach->id); } catch (Exception $e) { common_debug('Qvitter: could not get thumbnail for attachment id=' . $q_attach->id . ' in quoted notice id=' . $quoted_notice->id); } } } } } } } } try { $twitter_status['external_url'] = $notice->getUrl(true); } catch (InvalidUrlException $e) { common_debug('Qvitter: No URL available for external notice: id=' . $notice->id); } // reply-to profile url try { $reply = $notice->getParent(); $twitter_status['in_reply_to_profileurl'] = $reply->getProfile()->getUrl(); } catch (ServerException $e) { $twitter_status['in_reply_to_profileurl'] = null; } // fave number $faves = Fave::byNotice($notice); $favenum = count($faves); $twitter_status['fave_num'] = $favenum; // repeat number $repeats = $notice->repeatStream(); $repeatnum = 0; while ($repeats->fetch()) { if ($repeats->verb == ActivityVerb::SHARE) { // i.e. not deleted repeats $repeatnum++; } } $twitter_status['repeat_num'] = $repeatnum; // is this a post? (previously is_activity) if (method_exists('ActivityUtils', 'compareVerbs')) { $twitter_status['is_post_verb'] = ActivityUtils::compareVerbs($notice->verb, array(ActivityVerb::POST)); } else { $twitter_status['is_post_verb'] = $notice->verb == ActivityVerb::POST ? true : false; } // some more metadata about notice if ($notice->is_local == '1') { $twitter_status['is_local'] = true; } else { $twitter_status['is_local'] = false; if ($twitter_status['is_post_verb'] === true) { try { $twitter_status['external_url'] = $notice->getUrl(true); } catch (InvalidUrlException $e) { common_debug('Qvitter: No URL available for external notice: id=' . $notice->id); } } } if (ActivityUtils::compareTypes($notice->verb, array('qvitter-delete-notice', 'delete'))) { $twitter_status['qvitter_delete_notice'] = true; } return true; }
/** * Generate and store a thumbnail image for the uploaded file, if applicable. * * @return File_thumbnail or null */ function storeThumbnail() { if (substr($this->mimetype, 0, strlen('image/')) != 'image/') { // @fixme video thumbs would be nice! return null; } try { $image = new ImageFile($this->fileRecord->id, File::path($this->filename)); } catch (Exception $e) { // Unsupported image type. return null; } $outname = File::filename($this->user->getProfile(), 'thumb-' . $this->filename, $this->mimetype); $outpath = File::path($outname); $maxWidth = common_config('attachments', 'thumb_width'); $maxHeight = common_config('attachments', 'thumb_height'); list($width, $height) = $this->scaleToFit($image->width, $image->height, $maxWidth, $maxHeight); $image->resizeTo($outpath, $width, $height); File_thumbnail::saveThumbnail($this->fileRecord->id, File::url($outname), $width, $height); }
/** * Add stuff to notices in API responses * * @param Action $action action being executed * * @return boolean hook return */ function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped) { // groups $notice_groups = $notice->getGroups(); $group_addressees = false; foreach ($notice_groups as $g) { $group_addressees[] = array('nickname' => $g->nickname, 'url' => $g->mainpage); } $twitter_status['statusnet_in_groups'] = $group_addressees; // for older verions of gnu social: include the repeat-id, which we need when unrepeating later if (array_key_exists('repeated', $twitter_status) && $twitter_status['repeated'] === true) { $repeated = Notice::pkeyGet(array('profile_id' => $scoped->id, 'repeat_of' => $notice->id, 'verb' => 'http://activitystrea.ms/schema/1.0/share')); $twitter_status['repeated_id'] = $repeated->id; } // more metadata about attachments // get all attachments first, and put all the extra meta data in an array $attachments = $notice->attachments(); $attachment_url_to_id = array(); if (!empty($attachments)) { foreach ($attachments as $attachment) { if (is_object($attachment)) { try { $enclosure_o = $attachment->getEnclosure(); // add id to all attachments $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id; // add data about thumbnails $thumb = $attachment->getThumbnail(); $large_thumb = $attachment->getThumbnail(1000, 3000, false); if (method_exists('File_thumbnail', 'url')) { $thumb_url = File_thumbnail::url($thumb->filename); $large_thumb_url = File_thumbnail::url($large_thumb->filename); } else { $thumb_url = $thumb->getUrl(); $large_thumb_url = $large_thumb->getUrl(); } $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $large_thumb_url; $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width; $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height; // animated gif? if ($attachment->mimetype == 'image/gif') { $image = ImageFile::fromFileObject($attachment); if ($image->animated == 1) { $attachment_url_to_id[$enclosure_o->url]['animated'] = true; } else { $attachment_url_to_id[$enclosure_o->url]['animated'] = false; } } // this applies to older versions of gnu social, i think } catch (ServerException $e) { $thumb = File_thumbnail::getKV('file_id', $attachment->id); if ($thumb instanceof File_thumbnail) { $thumb_url = $thumb->getUrl(); $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id; $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width; $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height; // animated gif? if ($attachment->mimetype == 'image/gif') { $image = ImageFile::fromFileObject($attachment); if ($image->animated == 1) { $attachment_url_to_id[$enclosure_o->url]['animated'] = true; } else { $attachment_url_to_id[$enclosure_o->url]['animated'] = false; } } } } } } } // add the extra meta data to $twitter_status if (!empty($twitter_status['attachments'])) { foreach ($twitter_status['attachments'] as &$attachment) { if (!empty($attachment_url_to_id[$attachment['url']])) { $attachment = array_merge($attachment, $attachment_url_to_id[$attachment['url']]); } } } // reply-to profile url try { $reply = $notice->getParent(); $twitter_status['in_reply_to_profileurl'] = $reply->getProfile()->getUrl(); } catch (ServerException $e) { $twitter_status['in_reply_to_profileurl'] = null; } // fave number $faves = Fave::byNotice($notice); $favenum = count($faves); $twitter_status['fave_num'] = $favenum; // repeat number $repeats = $notice->repeatStream(); $repeatnum = 0; while ($repeats->fetch()) { if ($repeats->verb == ActivityVerb::SHARE) { // i.e. not deleted repeats $repeatnum++; } } $twitter_status['repeat_num'] = $repeatnum; // some more metadata about notice if ($notice->is_local == '1') { $twitter_status['is_local'] = true; } else { $twitter_status['is_local'] = false; if ($notice->object_type != 'activity') { try { $twitter_status['external_url'] = $notice->getUrl(true); } catch (InvalidUrlException $e) { common_debug('Qvitter: No URL available for external notice: id=' . $notice->id); } } } if ($notice->source == 'activity' || $notice->object_type == 'activity' || $notice->object_type == 'http://activitystrea.ms/schema/1.0/activity' || $notice->verb == 'delete') { $twitter_status['is_activity'] = true; } else { $twitter_status['is_activity'] = false; } if (ActivityUtils::compareTypes($notice->verb, array('qvitter-delete-notice', 'delete'))) { $twitter_status['qvitter_delete_notice'] = true; } return true; }
/** * Handle the request * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); $noticeurl = common_path('notice/', StatusNet::isHTTPS()); $instanceurl = common_path('', StatusNet::isHTTPS()); // remove protocol for the comparison below $noticeurl_wo_protocol = preg_replace('(^https?://)', '', $noticeurl); $instanceurl_wo_protocol = preg_replace('(^https?://)', '', $instanceurl); $url_wo_protocol = preg_replace('(^https?://)', '', $this->url); // find local notice if (strpos($url_wo_protocol, $noticeurl_wo_protocol) === 0) { $possible_notice_id = str_replace($noticeurl_wo_protocol, '', $url_wo_protocol); if (ctype_digit($possible_notice_id)) { $notice = Notice::getKV('id', $possible_notice_id); } else { $this->clientError("Notice not found.", 404); } } if (!$notice instanceof Notice) { // TRANS: Client error displayed in oEmbed action when notice not found. // TRANS: %s is a notice. $this->clientError(sprintf(_("Notice %s not found."), $this->id), 404); } $profile = $notice->getProfile(); if (!$profile instanceof Profile) { // TRANS: Server error displayed in oEmbed action when notice has not profile. $this->serverError(_('Notice has no profile.'), 500); } $authorname = $profile->getFancyName(); $oembed = array(); $oembed['version'] = '1.0'; $oembed['provider_name'] = common_config('site', 'name'); $oembed['provider_url'] = common_root_url(); $oembed['type'] = 'link'; // TRANS: oEmbed title. %1$s is the author name, %2$s is the creation date. $oembed['title'] = ApiAction::dateTwitter($notice->created) . ' (Qvitter)'; $oembed['author_name'] = $authorname; $oembed['author_url'] = $profile->profileurl; $oembed['url'] = $notice->getUrl(); $oembed['html'] = $notice->getRendered(); // maybe add thumbnail $attachments = $notice->attachments(); if (!empty($attachments)) { foreach ($attachments as $attachment) { if (is_object($attachment)) { try { $thumb = $attachment->getThumbnail(); } catch (ServerException $e) { // } if (!empty($thumb) && method_exists('File_thumbnail', 'url')) { try { $thumb_url = File_thumbnail::url($thumb->filename); $oembed['thumbnail_url'] = $thumb_url; break; // only first one } catch (ClientException $e) { // } } } } } if ($this->format == 'json') { $this->initDocument('json'); print json_encode($oembed); $this->endDocument('json'); } elseif ($this->format == 'xml') { $this->initDocument('xml'); $this->elementStart('oembed'); foreach (array('version', 'type', 'provider_name', 'provider_url', 'title', 'author_name', 'author_url', 'url', 'html') as $key) { if (isset($oembed[$key]) && $oembed[$key] != '') { $this->element($key, null, $oembed[$key]); } } $this->elementEnd('oembed'); $this->endDocument('xml'); } else { $this->serverError(sprintf(_('Format %s not supported.'), $this->format), 501); } }
/** * Add stuff to notices in API responses * * @param Action $action action being executed * * @return boolean hook return */ function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped) { // groups $notice_groups = $notice->getGroups(); $group_addressees = false; foreach ($notice_groups as $g) { $group_addressees = array('nickname' => $g->nickname, 'url' => $g->mainpage); } $twitter_status['statusnet_in_groups'] = $group_addressees; // include the repeat-id, which we need when unrepeating later if (array_key_exists('repeated', $twitter_status) && $twitter_status['repeated'] === true) { $repeated = Notice::pkeyGet(array('profile_id' => $scoped->id, 'repeat_of' => $notice->id)); $twitter_status['repeated_id'] = $repeated->id; } // thumb urls // find all thumbs $attachments = $notice->attachments(); $attachment_url_to_id = array(); if (!empty($attachments)) { foreach ($attachments as $attachment) { if (is_object($attachment)) { try { $enclosure_o = $attachment->getEnclosure(); $thumb = $attachment->getThumbnail(); $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id; $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb->getUrl(); $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width; $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height; // animated gif? if ($attachment->mimetype == 'image/gif') { $image = ImageFile::fromFileObject($attachment); if ($image->animated == 1) { $attachment_url_to_id[$enclosure_o->url]['animated'] = true; } else { $attachment_url_to_id[$enclosure_o->url]['animated'] = false; } } } catch (ServerException $e) { $thumb = File_thumbnail::getKV('file_id', $attachment->id); if ($thumb instanceof File_thumbnail) { $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id; $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb->getUrl(); $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width; $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height; // animated gif? if ($attachment->mimetype == 'image/gif') { $image = ImageFile::fromFileObject($attachment); if ($image->animated == 1) { $attachment_url_to_id[$enclosure_o->url]['animated'] = true; } else { $attachment_url_to_id[$enclosure_o->url]['animated'] = false; } } } } } } } // add thumbs to $twitter_status if (!empty($twitter_status['attachments'])) { foreach ($twitter_status['attachments'] as &$attachment) { if (!empty($attachment_url_to_id[$attachment['url']])) { $attachment['id'] = $attachment_url_to_id[$attachment['url']]['id']; $attachment['width'] = $attachment_url_to_id[$attachment['url']]['width']; $attachment['height'] = $attachment_url_to_id[$attachment['url']]['height']; $attachment['thumb_url'] = $attachment_url_to_id[$attachment['url']]['thumb_url']; if (isset($attachment_url_to_id[$attachment['url']]['animated'])) { $attachment['animated'] = $attachment_url_to_id[$attachment['url']]['animated']; } } } } // reply-to profile url try { $reply = $notice->getParent(); $twitter_status['in_reply_to_profileurl'] = $reply->getProfile()->getUrl(); } catch (ServerException $e) { $twitter_status['in_reply_to_profileurl'] = null; } // fave number $faves = Fave::byNotice($notice); $favenum = count($faves); $twitter_status['fave_num'] = $favenum; // repeat number $repeats = $notice->repeatStream(); $repeatnum = 0; while ($repeats->fetch()) { $repeatnum++; } $twitter_status['repeat_num'] = $repeatnum; // some more metadata about notice if ($notice->is_local == '1') { $twitter_status['is_local'] = true; } else { $twitter_status['is_local'] = false; if ($notice->object_type != 'activity') { $twitter_status['external_url'] = $notice->getUrl(true); } } if ($notice->object_type == 'activity' || $notice->object_type == 'http://activitystrea.ms/schema/1.0/activity') { $twitter_status['is_activity'] = true; } else { $twitter_status['is_activity'] = false; } if ($notice->verb == 'qvitter-delete-notice') { $twitter_status['qvitter_delete_notice'] = true; } return true; }
Will print '.' for deleted local files and 'x' where File entry was missing. If the script seems to stop, it is processing correct File_thumbnail entries. END_OF_HELP; require_once INSTALLDIR . '/scripts/commandline.inc'; if (!have_option('y', 'yes')) { print "About to delete locally generated thumbnails to allow regeneration. Are you sure? [y/N] "; $response = fgets(STDIN); if (strtolower(trim($response)) != 'y') { print "Aborting.\n"; exit(0); } } print "Deleting"; $thumbs = new File_thumbnail(); $thumbs->find(); while ($thumbs->fetch()) { try { $file = $thumbs->getFile(); if ($file->isLocal()) { // only delete properly linked thumbnails if they're local $thumbs->delete(); print '.'; } } catch (NoResultException $e) { // No File object for thumbnail, let's delete the thumbnail entry $thumbs->delete(); print 'x'; } }