steffen: server/kolab-horde-fbview/kolab-horde-fbview/fbview/util barcode.php, NONE, 1.1 css2horde.php, NONE, 1.1 google_example.php, NONE, 1.1 po_stats.php, NONE, 1.1 regex_test.php, NONE, 1.1
cvs at intevation.de
cvs at intevation.de
Mon Oct 31 12:43:43 CET 2005
Author: steffen
Update of /kolabrepository/server/kolab-horde-fbview/kolab-horde-fbview/fbview/util
In directory doto:/tmp/cvs-serv18388/kolab-horde-fbview/kolab-horde-fbview/fbview/util
Added Files:
barcode.php css2horde.php google_example.php po_stats.php
regex_test.php
Log Message:
Fbview in separate package
--- NEW FILE: barcode.php ---
<?php
/**
* $Horde: horde/util/barcode.php,v 1.10 2004/05/07 20:51:36 chuck Exp $
*
* Copyright 2002-2004 Chuck Hagenbuch <chuck at horde.org>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*/
@define('HORDE_BASE', dirname(__FILE__) . '/..');
require_once HORDE_BASE . '/lib/core.php';
require_once 'Horde/Image.php';
// Get text, uppercase, add start/stop characters.
$text = Util::getFormData('barcode', 'test');
$text = String::upper($text, true);
$text = "*$text*";
$textlen = strlen($text);
$height = Util::getFormData('h', 40);
$thinwidth = Util::getFormData('w', 2);
$thickwidth = $thinwidth * 3;
$width = $textlen * (7 * $thinwidth + 3 * $thickwidth) - $thinwidth;
$codingmap = array('0' => '000110100', '1' => '100100001',
'2' => '001100001', '3' => '101100000', '4' => '000110001',
'5' => '100110000', '6' => '001110000', '7' => '000100101',
'8' => '100100100', '9' => '001100100', 'A' => '100001001',
'B' => '001001001', 'C' => '101001000', 'D' => '000011001',
'E' => '100011000', 'F' => '001011000', 'G' => '000001101',
'H' => '100001100', 'I' => '001001100', 'J' => '000011100',
'K' => '100000011', 'L' => '001000011', 'M' => '101000010',
'N' => '000010011', 'O' => '100010010', 'P' => '001010010',
'Q' => '000000111', 'R' => '100000110', 'S' => '001000110',
'T' => '000010110', 'U' => '110000001', 'V' => '011000001',
'W' => '111000000', 'X' => '010010001', 'Y' => '110010000',
'Z' => '011010000', ' ' => '011000100', '$' => '010101000',
'%' => '000101010', '*' => '010010100', '+' => '010001010',
'-' => '010000101', '.' => '110000100', '/' => '010100010');
$image = &Horde_Image::factory(Util::getFormData('type', 'png'),
array('temp' => Horde::getTempDir(),
'width' => $width,
'height' => $height,
'background' => 'white'));
$xpos = 0;
for ($idx = 0; $idx < $textlen; $idx++) {
$char = substr($text, $idx, 1);
// Make unknown chars a '-'.
if (!isset($codingmap[$char])) {
$char = '-';
}
for ($bar = 0; $bar <= 8; $bar++) {
$elementwidth = $codingmap[$char]{$bar} ? $thickwidth : $thinwidth;
if (($bar + 1) % 2) {
$image->rectangle($xpos, 0, $elementwidth - 1, $height, 'black', 'black');
}
$xpos += $elementwidth;
}
$xpos += $thinwidth;
}
header('Pragma: public');
$image->display();
--- NEW FILE: css2horde.php ---
<!-- $Horde: horde/util/css2horde.php,v 1.6 2003/09/24 21:22:06 chuck Exp $ -->
<form method="post">
<textarea name="css" rows="8" cols="80"><?php if (!empty($_POST['css'])) echo $_POST['css'] ?></textarea>
<br />
<input type="submit" />
</form>
<?php
if (isset($_POST['css'])) {
$css = get_magic_quotes_gpc() ? stripslashes($_POST['css']) : $_POST['css'];
$items = explode('}', $css);
$styles = array();
foreach ($items as $item) {
$item = trim(str_replace('}', '', $item));
if (!empty($item)) {
$styleitem = explode('{', $item);
$styleitems = explode(';', $styleitem[1]);
foreach ($styleitems as $stylebit) {
$stylebit = trim($stylebit);
if (!empty($stylebit)) {
$attribute = explode(':', $stylebit);
$styles[trim($styleitem[0])][trim($attribute[0])] = trim($attribute[1]);
}
}
}
}
foreach ($styles as $class => $props) {
foreach ($props as $prop => $value) {
echo '$css[\'' . escape($class) . '\'][\'' . escape($prop) . '\'] = \'' . escape($value) . '\';' . "\n<br />";
}
echo '<br />';
}
}
/**
* Make sure single quotes get escaped.
*
* @param string $text The string to escape.
*
* @return Escaped $text.
*/
function escape($text)
{
return str_replace("'", "\'", $text);
}
--- NEW FILE: google_example.php ---
<?php
/**
* $Horde: horde/util/google_example.php,v 1.1 2003/09/28 03:23:52 chuck Exp $
*/
$google_key = '';
define('HORDE_BASE', dirname(__FILE__));
require_once HORDE_BASE . '/lib/base.php';
require_once HORDE_BASE . '/lib/Search.php';
if (empty($google_key)) {
exit('You must provide a Google API key.');
}
$google = &Horde_Search::singleton('google', array('key' => $key));
$result = $google->search(array('query' => Util::getFormData('q', 'horde')));
if ($result !== $false) {
echo '<pre>';
var_dump($result);
echo '</pre>';
} else {
echo 'Query failed.';
}
--- NEW FILE: po_stats.php ---
<?php
/**
* $Horde: horde/util/po_stats.php,v 1.2 2004/01/01 16:17:55 jan Exp $
*
* Copyright 2002-2004 Chuck Hagenbuch <chuck at horde.org>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*/
define('HORDE_BASE', dirname(__FILE__) . '/..');
require_once HORDE_BASE . '/lib/base.php';
$i = 0;
$handle = opendir('../po');
while ($file = readdir($handle)) {
if (preg_match('/(.*)\.po$/', $file, $matches)) {
$locale = $matches[1];
if (!isset($nls['languages'][$locale]) ||
$locale == 'en_GB') {
continue;
}
$i++;
$lines = file("../po/$file");
$fuzzy = 0;
$untranslated = -1;
$translated = 0;
$obsolete = 0;
foreach ($lines as $line) {
if (strpos($line,'msgstr') === 0) {
if (stristr($line, 'msgstr ""')) {
$untranslated++;
} else {
$translated++;
}
} elseif (strpos($line,'#, fuzzy') === 0) {
$fuzzy++;
} elseif (strpos($line,'#~ ') === 0) {
$obsolete++;
}
}
$all = $translated + $fuzzy + $untranslated;
$percent_done = round($translated / $all * 100, 2);
$rpd = round($percent_done, 0);
$report[$locale] = array($percent_done, $translated, $fuzzy, $untranslated);
if ($rpd < 50) {
$color = dechex(255 - $rpd * 2) . '0000';
} else {
$color = '00' . dechex(55 + $rpd * 2) . '00';
}
if (strlen($color) < 6) {
$color = '0' . $color;
}
$report[$locale] = array($color, $percent_done, $translated, $fuzzy, $untranslated, $obsolete);
}
}
closedir($handle);
function my_usort_function($a, $b)
{
if ($a[1] > $b[1]) { return -1; }
if ($a[1] < $b[1]) { return 1; }
return 0;
}
uasort ($report, 'my_usort_function');
?>
<html>
<body>
<head>
<link rel="stylesheet" type="text/css" href="g1-report.css">
</head>
<h2>Localization Status Report for Horde</h2>
<table align="center" border="0" cellspacing="0" cellpadding="0">
<tr>
<th> </th>
<th>Language</th>
<th>Locale</th>
<th>Status</th>
<th valign="bottom" style="width: 30px;">T<br/>r<br/>a<br/>n<br/>s<br/>l<br/>a<br/>t<br/>e<br/>d</th>
<th valign="bottom" style="width: 30px;">F<br/>u<br/>z<br/>z<br/>y</th>
<th valign="bottom" style="width: 30px;">U<br/>n<br/>t<br/>r<br/>a<br/>n<br/>s<br/>l<br/>a<br/>t<br/>e<br/>d</th>
<th valign="bottom" style="width: 30px;">O<br/>b<br/>s<br/>o<br/>l<br/>e<br/>t<br/>e</th>
</tr>
<?php
$i = 0;
$j = 0;
$line = 0;
$last_key = null;
foreach ($report as $key => $value) {
$i++;
if ($i % 2 == 0) {
$color = "#ffffff";
$nr = 1;
} else {
$color = "#CECECE";
$nr = 2;
}
echo "\n<tr>";
if (!is_null($last_key) && $report[$key][1] != $report[$last_key][1]) {
$line++;
echo "\n\t<td style=\"background-color:$color\">$line)</td>";
} else {
echo "\n\t<td style=\"background-color:$color\"> </td>";
}
echo "\n\t<td style=\"background-color:$color\">" . $nls['languages'][$key] . "</td>";
echo "\n\t<td style=\"background-color:$color\">" . $key . "</td>";
echo "\n\t<td style=\"background-color:#" . $value[0] . "\">" . $value[1] . "% done</td>";
echo "\n\t<td class=\"translated$nr\">" . $value[2] . "</td>";
echo "\n\t<td class=\"fuzzy$nr\">" . $value [3] . "</td>";
echo "\n\t<td class=\"untranslated$nr\">" . $value[4] . "</td>";
echo "\n\t<td class=\"obsolete$nr\">" . $value[5] . "</td>";
echo "\t</tr>";
$last_key = $key;
}
?>
</table>
</body>
</html>
--- NEW FILE: regex_test.php ---
<?php
/**
* Simple script to help with regex construction/debugging. Put it somewhere
* on your webserver and point your browser to it.
*
* Based on: http://myfluffydog.com/programming/php/scripts/regexp.php
*/
require 'Horde/Util.php';
$regexp = Util::getFormData('regexp');
$subject = Util::getFormData('subject');
$submit = Util::getFormData('submit');
set_time_limit (2);
function unhtmlentities($string)
{
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}
if ($submit == "Test") { // doing a reg expression search -- get variables
$unescapedRegexp = unhtmlentities($regexp); // for search
$escapedRegexp = htmlentities($regexp); // for showing on page and in textarea
$text = $subject;
$text = stripslashes($text);
$text = unhtmlentities($text); // for search
$escapedText = htmlentities($text);// for textarea
// Do preg_replace on source, substituting matched_text with [b]matched_text[/b]
$highlightedText = preg_replace($unescapedRegexp, '[b]\\0[/b]', $text);
// convert htmlentities
$highlightedText = htmlentities($highlightedText);
// replace [b] with <b> and [/b] with </b>
$highlightedText = str_replace('[b]', '<span class="highlight">', $highlightedText);
$highlightedText = str_replace('[/b]', '</span>', $highlightedText);
}
?>
<html>
<head>
<title>Test regular expressions</title>
<style type="text/css">
<!--
h1 {
font-size: large;
}
.fixed {
font-size: 10px;
font-family: monospace,fixed;
color: #000099;
background-color: #cccccc;
}
.notes {
font-size: small;
color: #000099;
background-color: #cccccc;
}
.highlight {
color: #000066;
background-color: #ffff00;
}
.empty {
background-color: #ff9933
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<h1>Test <a href="http://www.php.net/manual/en/ref.pcre.php">PHP Regular Expression Functions (Perl-Compatible)</a></h1>
<div class="fixed">preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER)</div>
<form name="form1" method="post" action="<?php echo $PHP_SELF?>">
<p><strong>Enter your regular expression ($pattern):</strong><br />
<textarea name="regexp" cols="80" rows="6" id="regexp"><?php if($submit){echo $escapedRegexp;}?></textarea>
<br />
<strong>Enter text to search against in the textarea below ($subject):</strong><br />
<textarea name="subject" cols="80" rows="3"><?php if($subject){echo $escapedText;}?></textarea>
<br />
<input type="submit" name="submit" value="Test">
<input type="reset" name="Reset" value="Reset">
<a href='<?php echo $PHP_SELF?>'>Home</a><br />
</p>
</form>
<hr>
<?php
if ($submit){ // only shows up on results page
if (preg_match_all($unescapedRegexp, $text, $results, PREG_SET_ORDER)) { // found match
echo "The regexp <strong> $escapedRegexp </strong> matched!\n<p>";
echo "<h1>Here's what was matched searching the text you entered:</h1>\n";
$y = 0;
echo '<div class="fixed">';
foreach ($results as $loop_result) {
$x = 0;
foreach ($loop_result as $loop_result2){
if ($x != 0) {
/* Indent subpatterns. */
echo "<blockquote>";
}
printf('$matches[%s][%s]: ', $y, $x);// show variable name
if (!$loop_result2){
echo '<span class="empty">Empty</span>';
} else {
echo '<span class="highlight">' . htmlentities($loop_result2) . '</span>';
}
if ($x != 0) {
echo "</blockquote>";
} else {
echo "<p />";
}
$x++;
}
$y++;
}
echo '</div>';
} else { // no match
echo "regexp <strong> $escapedRegexp </strong> doesn't return any results\n<p>";
}
?>
<h1>Searched text with matches <span class='highlight'>highlighted</span></h1>
<?php // Show searched text with matches highlighted
echo '<pre>';
echo $highlightedText;
echo '</pre><hr>';
}
?>
<div class="notes">
<h1>Example regular expressions:</h1>
<p><strong>{<!--(?:.|\s)*?-->}</strong> -- Shows comments in html </p>
<ul>
<li><strong>{</strong> open delimiter</li>
<li><strong><!--</strong> search for opening comment tag</li>
<li><strong>(?:.|\s)*</strong> any number of characters or white space</li>
<li><strong>?</strong> non-greedy</li>
<li><strong>--></strong> search for closing comment tag</li>
<li><strong>}</strong> close delimiter</li>
</ul>
<p><strong>{<style type(?:.|\s)*?</style>}</strong> -- Shows styles</p>
<p>Notes:</p>
<ul>
<li>The results page shows the individual matches and subpattern matches, and the original text with the matches highlighted.</li>
<li>Might not be able to search for html entities like "&" because of the converting for display and textareas (the search pattern (regexp) and non-url subjects are processed by unhtmlentities)</li>
</ul></div>
</body>
</html>
More information about the commits
mailing list