function fortune() { header('Content-Type: text/html; charset=utf-8'); $fortunes = Fortune::all(); array_walk($fortunes, "fortune_to_array"); $fortunes[] = array("id" => 0, "message" => "Additional fortune added at request time."); usort($fortunes, "compare_fortunes"); return render("fortune.php", null, array("fortunes" => $fortunes)); }
/** * Parses and format one fortune contents to HTML * * @param Fortune $fortune * * @return string */ function fortunize(Fortune $fortune) { $r = ""; foreach (explode("\n", $fortune->getContent()) as $i => $line) { if (!trim($line)) { continue; } $className = 0 === $i % 2 ? 'odd' : 'even'; if (preg_match('/^<(\\w+)>\\s?(.*)$/i', trim($line), $m)) { $nick = $m[1]; $quote = htmlspecialchars($m[2], ENT_QUOTES, sfConfig::get('sf_charset')); $r .= sprintf("<dt class=\"%s\"><%s></dt><dd><q>%s</q></dd>\n", $className, $nick, $quote); } else { $r .= sprintf("<dt> </dt><dd>%s</dd>\n", trim($line)); } } return sprintf('<dl>%s</dl>', $r); }
/** * Get the content as a string. * * @access public * * @return string The page content. * Lines are separated by new-lines. */ function getPackedContent() { $data =& $this->_data; if (empty($data['%content'])) { include_once 'lib/InlineParser.php'; // A feature similar to taglines at http://www.wlug.org.nz/ // Lib from http://www.aasted.org/quote/ if (defined('FORTUNE_DIR') and is_dir(FORTUNE_DIR) and in_array($GLOBALS['request']->getArg('action'), array('create', 'edit'))) { include_once "lib/fortune.php"; $fortune = new Fortune(); $quote = str_replace("\n<br>", "\n", $fortune->quoteFromDir(FORTUNE_DIR)); return sprintf("<verbatim>\n%s</verbatim>\n\n" . _("Describe %s here."), $quote, "[" . WikiEscape($this->_pagename) . "]"); } // Replace empty content with default value. return sprintf(_("Describe %s here."), "[" . WikiEscape($this->_pagename) . "]"); } // There is (non-default) content. assert($this->_version > 0); if (!is_string($data['%content'])) { // Content was not provided to us at init time. // (This is allowed because for some backends, fetching // the content may be expensive, and often is not wanted // by the user.) // // In any case, now we need to get it. $data['%content'] = $this->_get_content(); assert(is_string($data['%content'])); } return $data['%content']; }
public function fortune(&$irc, &$data, &$core) { $sayfortune = Fortune::factory()->languages(array('es'))->jars(array('asimov.fortunes', 'deprimente.fortunes', 'informatica.fortunes', 'leydemurphy.fortunes', 'camioneros.fortunes'))->display_long(true)->display_offensive(true)->get_fortunes(true)->text; $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $sayfortune); }
$worlds[] = $world; } return response()->json($worlds); }); $app->get("updates", function (Request $request) { $query_count = $request->input("queries"); if ($query_count < 1) { $query_count = 1; } if ($query_count > 500) { $query_count = 500; } $worlds = array(); for ($i = 0; $i < $query_count; $i++) { $id = mt_rand(1, 10000); $world = World::find($id); $world->randomNumber = mt_rand(1, 10000); $world->save(); $worlds[] = $world; } return response()->json($worlds); }); $app->get("fortune", function () use($app) { $fortunes = Fortune::all()->toArray(); $new_fortune = array("id" => 0, "message" => "Additional fortune added at request time."); $fortunes[] = $new_fortune; $fortunes = array_sort($fortunes, function ($value) { return $value["message"]; }); return view("fortune", ["fortunes" => $fortunes]); });