function testOutput() { $this->assertEqual($this->dd->line("bob", "slob"), '<a href="bob">slob</a>'); $thing = array('xhtml' => 'Randy', 'default' => 'Slacker'); $this->assertEqual($this->dd->line("bob", $thing), '<a href="bob">Randy</a>'); $this->assertTrue($this->dd->activate_style('text')); print $this->dd->type; $this->assertEqual($this->dd->type, 'text'); $this->assertEqual($this->dd->line("bob", $thing), '-- bob : Slacker'); $this->assertEqual($this->dd->line("bob", array("default" => "something")), '-- bob : something'); $df = new folksoDisplayFactory(); $dd2 = $df->FancyResourceList(); $this->assertIsA($dd2, folksoDataDisplay); $dd2->activate_style('xml'); $this->assertEqual($dd2->type, 'xml'); $ltext = $dd2->line('abcXXXdef', 'WWW', 'Bob is a slob', 'plooof'); $this->assertPattern('/<numid>abcXXXdef/', $ltext); $this->assertPattern('/<url>WWW<\\/url>/', $ltext); }
function fancyResource(folksoQuery $q, folksoDBconnect $dbc, folksoSession $fks) { $r = new folksoResponse(); try { $i = new folksoDBinteract($dbc); /* * This is a bit of a hack. We are using a UNION to put the tag name * in the first row of the result set, to avoid two separate * queries. If columns are to be added to the main query, equivalent * dummy columns should be added to the first part of the UNION. */ $querytagtitle = "SELECT tagdisplay AS title, \n\t" . "id AS id, \n\t" . "'dummy' AS href, \n\t" . "'dummy' AS display, \n\t" . "'dummy' AS tags \n" . "FROM tag \n\t"; if (is_numeric($q->tag)) { $querytagtitle .= ' WHERE id = ' . $q->tag . ' '; } else { $querytagtitle .= " WHERE tagnorm = normalize_tag('" . $i->dbescape($q->tag) . "') "; } $querytagtitle .= ' LIMIT 1 '; // just to be sure $querystart = ' SELECT r.title AS title, r.id AS id, r.uri_raw AS href, CASE WHEN title IS NULL THEN uri_normal ELSE title END AS display, (SELECT GROUP_CONCAT(DISTINCT concat(t2.tagdisplay, \'::\', t2.tagnorm) SEPARATOR \' - \') FROM tag t2 JOIN tagevent te2 ON t2.id = te2.tag_id JOIN resource r2 ON r2.id = te2.resource_id WHERE r2.id = r.id ) AS tags FROM resource r JOIN tagevent te ON r.id = te.resource_id JOIN tag t ON te.tag_id = t.id'; // $queryend = " LIMIT 100"; $querywhere = ''; if (is_numeric($q->tag)) { $querywhere = 'WHERE t.id = ' . $q->tag . ' '; } else { $querywhere = "WHERE t.tagnorm = normalize_tag('" . $i->dbescape($q->tag) . "') "; } $total_query = $querytagtitle . " UNION \n" . $querystart . ' ' . $querywhere . ' ' . $queryend; $i->query($total_query); } catch (dbException $e) { return $r->handleDBexception($e); } switch ($i->result_status) { case 'NOROWS': $r->setOk(200, 'No resources associated with tag'); return $r; break; case 'OK': $r->setOk(200, 'Found'); break; default: $r->setError(500, 'Inexplicable error', 'This does not make sense'); return $r; } // so we are 'OK' $df = new folksoDisplayFactory(); $dd = $df->FancyResourceList(); $dd->activate_style('xml'); //pop the first line of the results containing the tagtitle $row1 = $i->result->fetch_object(); $r->t($dd->startform()); $r->t($dd->title($row1->title)); while ($row = $i->result->fetch_object()) { $r->t($dd->line($row->id, htmlspecialchars($row->href, ENT_COMPAT, 'UTF-8'), html_entity_decode(strip_tags($row->display), ENT_NOQUOTES, 'UTF-8'), htmlspecialchars($row->tags, ENT_COMPAT, 'UTF-8'))); // inner quotes supplied by sql } $r->t($dd->endform()); return $r; }