posts;
}
$postdata=$wpdb->get_row("SELECT * FROM $tableposts WHERE ID = '$post_ID'");
$c = $postdata->post_content;
$c = mysql_real_escape_string(_greekify($c));
$wpdb->query("UPDATE $tableposts SET post_content = '$c' WHERE ID = '$post_ID'");
return $post_ID;
}
add_action('publish_post','_greekifyPost',9);
add_action('edit_post','_greekifyPost');
function _greekify($a)
{
while (preg_match("//", $a, $m) > 0 )
{
$res = (_process($m[1]));
$a = _greekify( preg_replace("//","$res",$a,1));
}
return $a;
}
//add_filter('the_content', '_greekify');
function _process($a)
{
_defaults();
$result = "";
foreach (split("::", $a) as $line)
{
if (preg_match("/^\s*(\d?\s?\w*) ([0-9]+):([0-9]+):([0-9]+)-([0-9]+)\s*$/", $line, $m)>0)
{
$result .= _greek($m[1],$m[2],$m[3],$m[4],$m[5]);
}
if (preg_match("/^\s*(\d?\s?\w*) ([0-9]+):([0-9]+):([0-9]+)\s*$/", $line, $m)>0)
{
$result .= _greek($m[1],$m[2],$m[3],$m[4],$m[4]);
}
if (preg_match("/^\s*(\d?\s?\w*) ([0-9]+):([0-9]+-[0-9]+)\s*$/", $line, $m)>0)
{
$result .= _greeks($m[1],$m[2],$m[3]);
}
if (preg_match("/^\s*(\d?\s?\w*) ([0-9]+):([0-9]+)\s*$/", $line, $m)>0)
{
$result .= _greek($m[1],$m[2],$m[3]);
}
if (preg_match("/^\s*(\w*)=(.*)$/", $line, $m)>0)
{
_set($m[1], $m[2]);
}
}
return $result;
}
function _defaults()
{
global $_outhover,$_outurl,$_outlinked,$_outpre,$_outpost, $_ttformat;
$_outhover = "%lemma : %def
%pos
%case %number %gender
%person %mood %degree";
$_outurl = "http://www.zhubert.com/word?word=%form&root=%lemma&number=%gkey";
$_outlinked = "%form";
$_outpre = "";
$_outpost = " ";
$_ttformat = "";
}
function _set($key, $a)
{
global $_outhover,$_outurl,$_outlinked,$_outpre,$_outpost, $_ttformat;
if ($key == "hover") { $_outhover = $a; return; }
if ($key == "url") { $_outurl = $a; return; }
if ($key == "linked") { $_outlinked = $a; return; }
if ($key == "pre") { $_outpre = $a; return; }
if ($key == "post") { $_outpost = $a; return; }
$_ttformat = "$_ttformat;this.$key='$a'";
}
function _makereplacements2($word, $rep)
{
$a = array();
foreach ($rep as $key) {
$k = substr($key,1);
$b = $word[$k];
if ($b == "") { $b = $word['parsing'][$k]; }
$a[] = strtr($b, "-", " ");
}
return $a;
}
function _greeks($book, $chapter, $verses) {
$boom = explode("-", $verses);
$result = "";
for ($n=$boom[0]; $n<=$boom[1]; $n++)
{
$result .= _greek($book, $chapter, $n);
}
return $result;
}
function _greek($book, $chapter, $verse, $gkmin=0, $gkmax=999999999) {
global $_outhover,$_outurl,$_outlinked,$_outpre,$_outpost, $_ttformat;
$_rep = array ( "%gkey", "%form", "%lemma", "%pos", "%def", "%person", "%tense", "%voice", "%mood", "%case", "%number", "%gender", "%degree" );
$b = urlencode($book);
$url = "http://www.zhubert.com/xml/verse.php?book=$b&chapter=$chapter&verse=$verse";
$data = implode('',file($url));
$res = makeXMLTree2($data);
$words = $res["verse"]["words"];
$result = "";
foreach ($words["word"] as $word) {
$rep = _makereplacements2($word, $_rep);
if ($rep[0]>=$gkmin and $rep[0]<=$gkmax)
{
$o1 = str_replace($_rep, $rep, $_outhover);
$o2 = str_replace($_rep, $rep, $_outurl);
$o3 = str_replace($_rep, $rep, $_outlinked);
$o4 = str_replace($_rep, $rep, $_outpre);
$o5 = str_replace($_rep, $rep, $_outpost);
$o6 = str_replace($_rep, $rep, $_ttformat);
$result .= <<$o3$o5
END;
}
}
return $result;
}
// put elements, that need to be put in a list
// here
$XML_LIST_ELEMENTS = array( "word" );
function makeXMLTree2($data)
{
// create parser
$parser = xml_parser_create('UTF-8');
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($parser,$data,$values,$tags);
xml_parser_free($parser);
// we store our path here
$hash_stack = array();
// this is our target
$ret = array();
foreach ($values as $key => $val) {
switch ($val['type']) {
case 'open':
array_push($hash_stack, $val['tag']);
if (isset($val['attributes']))
$ret = composeArray2($ret, $hash_stack, $val['attributes']);
else
$ret = composeArray2($ret, $hash_stack);
break;
case 'close':
array_pop($hash_stack);
break;
case 'complete':
array_push($hash_stack, $val['tag']);
$ret = composeArray2($ret, $hash_stack, $val['value']);
array_pop($hash_stack);
// handle attributes
if (isset($val['attributes']))
{
while(list($a_k,$a_v) = each($val['attributes']))
{
$hash_stack[] = $val['tag']."_attribute_".$a_k;
$ret = composeArray2($ret, $hash_stack, $a_v);
array_pop($hash_stack);
}
}
break;
}
}
return $ret;
}
function &composeArray2($array, $elements, $value=array())
{
global $XML_LIST_ELEMENTS;
// get current element
$element = array_shift($elements);
// does the current element refer to a list
if (in_array($element,$XML_LIST_ELEMENTS))
{
// more elements?
if(sizeof($elements) > 0)
{
$array[$element][sizeof($array[$element])-1] = &composeArray2($array[$element][sizeof($array[$element])-1], $elements, $value);
}
else // if (is_array($value))
{
$array[$element][sizeof($array[$element])] = $value;
}
}
else
{
// more elements?
if(sizeof($elements) > 0)
{
$array[$element] = &composeArray2($array[$element], $elements, $value);
}
else
{
$array[$element] = $value;
}
}
return $array;
}
?>