This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
Sequenzia/app/helpers/AvatarHelper.php

41 lines
1.6 KiB
PHP
Raw Normal View History

2013-10-27 01:06:58 +02:00
<?php
class AvatarHelper extends Rails\ActionView\Helper
{
2014-09-07 23:38:08 +02:00
protected $avatar_posts_registry = [];
2013-10-27 01:06:58 +02:00
# id is an identifier for the object referencing this avatar; it's passed down
# to the javascripts to implement blacklisting "click again to open".
public function avatar(User $user, $id, array $html_options = array())
{
static $shown_avatars = array();
static $posts_to_send = array();
#if not @shown_avatars[user] then
$shown_avatars[$user->id] = true;
$posts_to_send[] = $user->avatar_post;
2014-09-07 23:38:08 +02:00
$this->avatar_posts_registry[] = $user->avatar_post;
2013-10-27 01:06:58 +02:00
$img = $this->imageTag($user->avatar_url() . "?" . strtotime($user->avatar_timestamp),
array_merge(array('class' => "avatar", 'width' => $user->avatar_width, 'height' => $user->avatar_height), $html_options));
return $this->linkTo($img,
array("post#show", 'id' => $user->avatar_post->id),
array('class' => "ca" . $user->avatar_post->id,
2014-09-07 23:38:08 +02:00
'onclick' => "return Post.check_avatar_blacklist(".$user->avatar_post->id.", ".$id.")"));
2013-10-27 01:06:58 +02:00
#end
}
public function avatar_init(Post $post = null)
{
2014-09-07 23:38:08 +02:00
if (!$this->avatar_posts_registry) {
return '';
}
2013-10-27 01:06:58 +02:00
2014-09-07 23:38:08 +02:00
$ret = '';
foreach ($this->avatar_posts_registry as $post) {
$ret .= 'Post.register('.$post->toJson().");\n";
2013-10-27 01:06:58 +02:00
}
2014-09-07 23:38:08 +02:00
$ret .= "Post.init_blacklisted();\n";
return $ret;
2013-10-27 01:06:58 +02:00
}
2014-09-07 23:38:08 +02:00
}