"Friends", // "groups" => "Groups", ); public $friends_per_page = 20; public $showing_states = array( 'all' => "Showing first blue, then grey highlighted friends from below", 'only' => "Showing ONLY blue highlighted friends from below", ); function __construct($user, $badge_tag) { $this->user = $user; $this->badge_tag = $badge_tag; try { $this->state = $user->get_blog_badge_config($this->badge_tag); } catch (PAException $e) { if ($e->code != ROW_DOES_NOT_EXIST) throw $e; $this->state = array("friends"=>array()); } $this->url = BASE_URL_REL."/badge_create.php"; } private function save_state() { try { $this->user->save_blog_badge_config($this->badge_tag, $this->state); } catch (PAException $e) { echo "
error occurred saving badge!
$e->code | ".$e->getMessage()."
"; exit; } } function op($op, $section, $params) { switch ($op) { case 'enable': if (!isset($this->sections[$section])) return "invalid section for enable"; if (!isset($this->state[$section])) $this->state[$section] = array(); $this->state[$section]['enabled'] = TRUE; $this->save_state(); return $this->render_section_inner($section); case 'disable': if (!isset($this->sections[$section])) return "invalid section for disable"; if (isset($this->state[$section])) $this->state[$section]['enabled'] = FALSE; $this->save_state(); return $this->render_section_inner($section); default: return $this->{"op_$section"}($op, $params); } } function op_friends($op, $params) { switch ($op) { case 'include': case 'exclude': @list($subid) = $params; //FIXME: verify that the subid is actually a friend $incl =& $this->state['friends']['included']; if (!isset($incl)) {$incl = array(); $this->save_state();} if ($op == 'include') $incl[(int)$subid] = 1; else if (isset($incl)) unset($incl[(int)$subid]); $this->save_state(); return $this->render_friend_image((int)$subid); case 'show': @list($show_state) = $params; if (!@$this->showing_states[$show_state]) return "invalid show_state"; $this->state['friends']['show'] = $show_state; $this->save_state(); return $this->render_section_inner("friends"); case 'display': return $this->render_section_inner("friends"); default: return "invalid friends op"; } } // render the entire editing interface function render() { $ret = ""; foreach ($this->sections as $key => $title) { $ret .= $this->render_section($key, $title, "this:render_$key"); } return $ret; } // render an entire section (e.g. friends, groups, ...) function render_section($key, $title, $body) { $inner = $this->render_section_inner($key, $title, $body); return <<This section is disabled. Click 'enable' above to show it in your blog badge.
"; return <<$img
$name
ENS; } function render_friends() { $page = (int)@$_REQUEST['page']; $friend_state =& $this->state['friends']; if (!isset($friend_state['included'])) { $friend_state['included'] = array(); $this->save_state(); } // paging controls $total_friends = Relation::count_relations($this->user->user_id); $total_pages = (int)ceil((float)$total_friends / $this->friends_per_page); if ($page < 1) $page = 1; if ($page > $total_pages) $page = $total_pages; $paging = "Show page: "; for ($i = 1; $i < $total_pages+1; ++$i) { if ($i == $page) { $paging .= "$i "; } else { $paging .= "url/op/friends/display?page=$i');\">$i "; } } $first_friend = ($page-1)*$this->friends_per_page + 1; $last_friend = min($first_friend + $this->friends_per_page - 1, $total_friends); $paging .= "(showing $first_friend-$last_friend of $total_friends friends)"; // 'showing XXX' link $keys = array_keys($this->showing_states); if (!@$friend_state['show']) { $friend_state['show'] = $keys[0]; $this->save_state(); } // default $next_showing_state = $keys[(array_search($friend_state['show'], $keys) + 1) % count($keys)]; // next one $showing = "url/op/friends/show/$next_showing_state?page=$page')\">".$this->showing_states[$friend_state['show']]." (click to change)"; // facewall display $facewall = ""; foreach (Relation::get_all_relations($this->user->user_id, 0, FALSE, $this->friends_per_page, $page) as $rel) { $facewall .= '$paging
ENS; } function render_groups() { return <<Paste this HTML into your blog to display this information:
default badge: "; var_dump($default_badge); echo "
"; } catch (PAException $e) { echo "no default badge available.
"; } $left_sidebar = ob_get_contents(); ob_end_clean(); // --- $page = new PageRenderer(NULL, PAGE_BADGE_CREATE, "Design your blog badge"); $page->onload = "update_badge();"; $page->add_header_css("$current_theme_path/badge_create.css"); $page->add_module("left", "top", " "); // is there a better way to push stuff into the middle of the page? //$page->add_module("left", "top", $left_sidebar); // debugging $page->add_module("middle", "top", $page_html); $page->add_module("right", "top", $preview_html); echo $page->render(); ?>