5 require_once 'plc_functions.php';
7 // all known peers hashed on peer_id
11 function Peers ($api) {
13 // fake entry fot the local myplc
14 $local_fake_peer = array ('peername' => PLC_NAME,
15 'shortname' => PLC_SHORTNAME,
17 $hash['local']=$local_fake_peer;
19 $peer_columns=array('peer_id','shortname','peername');
21 $peers = $api->GetPeers($peer_filter,$peer_columns);
22 if ($peers) foreach ($peers as $peer) {
23 $hash[$peer['peer_id']]=$peer;
28 public static function is_local ($peer) {
29 return $peer['peer_id'] == 'local';
32 function peer ($peer_id) {
33 // use the fake local entry
36 return $this->hash[$peer_id];
39 public function peername ($peer_id) {
40 $peer = $this->peer ($peer_id);
41 return $peer['peername'];
44 public function shortname ($peer_id) {
45 $peer = $this->peer ($peer_id);
46 return $peer['shortname'];
49 public function label ($peer_id) {
50 $peer = $this->peer ($peer_id);
51 $result = $peer['peername'] . " (" . $peer['shortname'] . ")";
52 if (Peers::is_local ($peer))
53 $result = "[local] " . $result;
57 public function link ($peer_id,$text) {
59 return href("/",$text);
60 $peer = $this->peer ($peer_id);
61 return l_peer_t($peer['peer_id'],$text);
64 public function peer_link ($peer_id) {
66 return href("/",$this->label($peer_id));
67 $peer = $this->peer ($peer_id);
68 return l_peer_t($peer['peer_id'],$this->label($peer_id));
71 function classname ($peer_id) {
74 $peer = $this->peer ($peer_id);
75 $shortname=$peer['shortname'];
76 return "plc-$shortname";
79 function block_start ($peer_id) {
80 // to set the background to grey on foreign objects
81 // return true if the peer is local
86 $classname=strtolower($this->classname($peer_id));
87 // set two classes, one generic to all foreign, and one based on the peer's shortname for finer grain tuning
88 printf ("<div class=\"plc-foreign %s\">",$classname);
93 function block_end ($peer_id) {
102 function PeerScope ($api, $peerscope) {
103 switch ($peerscope) {
105 $this->filter=array();
106 $this->label="all peers";
109 $this->filter=array("peer_id"=>NULL);
110 $this->label=PLC_SHORTNAME;
113 $this->filter=array("~peer_id"=>NULL);
114 $this->label="foreign peers";
117 if (my_is_int ($peerscope)) {
118 $peer_id=intval($peerscope);
119 $peers=$api->GetPeers(array("peer_id"=>$peer_id));
121 $peers=$api->GetPeers(array("shortname"=>$peerscope));
125 $peer_id=$peer['peer_id'];
126 $this->filter=array("peer_id"=>$peer_id);
127 $this->label='peer "' . $peer['shortname'] . '"';
129 $this->filter=array();
130 $this->label="[no such peerscope " . $peerscope . "]";
136 public function filter() {
137 return $this->filter;
139 public function label() {