Example #1
0
function translation_statistics_category_lang($lang) {
  $list=array();

  $sql_str="select category.* from category_current left join category on category_current.version=category.version";
  $res=sql_query($sql_str);
  while($elem=pg_fetch_assoc($res)) {
    $tags=new tags(parse_hstore($elem['tags']));
    $cat_lang=coalesce($tags->get("lang"), "en");

    if(($s=$tags->get("name:$lang"))||(($s=$tags->get("name"))&&$lang==$cat_lang))
      $list["category:{$elem['category_id']}:name"]=$s;
    if(($s=$tags->get("description:$lang"))||(($s=$tags->get("description"))&&$lang==$cat_lang))
    $list["category:{$elem['category_id']}:description"]=$s;

    $sql_str="select * from category_rule where version='{$elem['version']}'";
    $res_r=sql_query($sql_str);
    while($elem_r=pg_fetch_assoc($res_r)) {
      $tags_r=new tags(parse_hstore($elem_r['tags']));

      if(($s=$tags_r->get("name:$lang"))||(($s=$tags_r->get("name"))&&$lang==$cat_lang))
	$list["category:{$elem['category_id']}:{$elem_r['rule_id']}:name"]=$s;
    }
  }

  return $list;
}
Example #2
0
function category_history_recent_changes($list) {
  $res=sql_query("select * from category where version_tags ? 'date' order by version_tags->'date' desc limit 50");
  while($elem=pg_fetch_assoc($res)) {
    $elem['version_tags']=parse_hstore($elem['version_tags']);
    $t=new tags(parse_hstore($elem['tags']));

    $entry=$elem['version_tags'];
    $entry['name']=sprintf("%s \"%s\"", lang("category", 1), $t->get_lang("name"));
    $entry['msg']=coalesce($elem['version_tags']['msg'], "no message");
    $entry['plugin']="category";
    $entry['href']="javascript:category_show(\"osm:{$elem['category_id']}\", { version: \"{$elem['version']}\"})";

    $list[]=$entry;
  }
}
Example #3
0
function whats_here_find($param) {
  global $load_xml;
//  global $query;

  $dist_mul=(19-$param[zoom])*(19-$param[zoom]);
  $dist=3*$dist_mul;

  $poly="PolyFromText('POLYGON((".
    ($param[lon]-$dist)." ".($param[lat]-$dist).",".
    ($param[lon]-$dist)." ".($param[lat]+$dist).",".
    ($param[lon]+$dist)." ".($param[lat]+$dist).",".
    ($param[lon]+$dist)." ".($param[lat]-$dist).",".
    ($param[lon]-$dist)." ".($param[lat]-$dist)."))', 900913)";
  $distance="Distance(osm_way, GeometryFromText('POINT($param[lon] $param[lat])', 900913))";

  $qry="select *, astext(ST_Centroid(osm_way)) as \"#geo:center\" from (".
    "select *, $distance-\"#dist_modi\"*$dist_mul as \"#distance\" from (".
    "select osm_id, osm_tags, osm_way, 1 as \"#area\", 4 as \"#dist_modi\" from osm_point where osm_way&&$poly".
    " union all ".
    "select osm_id, osm_tags, osm_way, ST_Length(osm_way) as \"#area\", 1.5 as \"#dist_modi\" from osm_line where osm_way&&$poly".
    " union all ".
    "select osm_id, osm_tags, osm_way, ST_Area(osm_way) as \"#area\", 1 as \"#dist_modi\" from osm_polygon where osm_way&&$poly".
    " union all ".
    "select osm_id, osm_tags, osm_way, ST_Area(osm_way) as \"#area\", 1 as \"#dist_modi\" from osm_rel where osm_way&&$poly".
    ") x1 offset 0) x2 where \"#distance\"<$dist order by \"#distance\" asc, \"#area\" asc";

  $res=sql_query($qry);
  while($elem=pg_fetch_assoc($res)) {
    $osm_tags=parse_hstore($elem['osm_tags']);
    foreach($elem as $k=>$v) {
      if(substr($k, 0, 1)=="#")
        $osm_tags[$k]=$v;
    }

    $ret[]=array("id"=>$elem['osm_id'], "tags"=>new tags($osm_tags));
  }

  return $ret;
}
Example #4
0
  function read_file_category($f) {
    $ret=array();
    if(!preg_match("/^(.*):(.*)$/", $f, $m))
      return null;

    $category=$m[1];
    $version=$m[2];

    $res=sql_query("select * from category where version='$version'", $db_central);
    $elem=pg_fetch_assoc($res);
    $tags=parse_hstore($elem['tags']);
    $orig_lang=$tags['lang'];
    if(!$orig_lang)
      $orig_lang="en";
    $suffix="";
    if($orig_lang!=$this->lang)
      $suffix=":{$this->lang}";

    $ret["$category:name"]=array(
      'value'=>$tags["name{$suffix}"],
      'help'=>"Category name",
    );
    $ret["$category:description"]=array(
      'value'=>$tags["description{$suffix}"],
      'help'=>"Category description",
    );

    $res_rule=sql_query("select * from category_rule where category_id='$category' and version='$version'", $db_central);
    while($elem_rule=pg_fetch_assoc($res_rule)) {
      $tags=parse_hstore($elem_rule['tags']);
      $rule_id=$elem_rule['rule_id'];

      $ret["$category:$rule_id:name"]=array(
	'value'=>$tags["name{$suffix}"],
	'help'=>"Match: {$tags['match']}",
      );
      $ret["$category:$rule_id:description"]=array(
	'value'=>$tags["description{$suffix}"],
      );
    }

    return array(
      'list'=>$ret,
      'help'=>"Please use the form =array([Gender,] \"Singular\", \"Plural\") where appropriate (see top of page for explanation)",
      'orig_lang'=>$orig_lang,
      'order'=>array_keys($ret),
    );
  }
function template_lang_category($category, $version) {
  global $db_central;
  global $ui_lang;
  @include "../lang/{$ui_lang}_deprecated.php";

  print "==== Category: $category ====\n";
  print "Version: $version\n";
  print "<syntaxhighlight lang=\"php\">\n";
  print "// Please use the form =array([Gender,] \"Singular\", \"Plural\") where appropriate (see top of page for explanation)\n";

  $res=sql_query("select * from category where category_id='$category' and version='$version'", $db_central);
  $elem=pg_fetch_assoc($res);
  $tags=parse_hstore($elem['tags']);
  $lang=$tags['lang'];
  if(!$lang)
    $lang="en";

  // check if deprecated $lang_str exists
  if(!$tags["name:$ui_lang"]) {
    if($x=$lang_str["cat:".strtr($category, array("_"=>"/"))]) {
      if(is_array($x))
	$x=$x[0];
      $tags["name:$ui_lang"]=$x;
    }
    if($x=$lang_str["list_".strtr($category, array("_"=>"_"))]) {
      if(is_array($x))
	$x=$x[0];
      $tags["name:$ui_lang"]=$x;
    }
//    elseif($x=$lang_str["station_type_".strtr($tags["match"], array("="=>"_"))]) {
//      $tags["name:$ui_lang"]=$x;
//    }
  }
  // end deprecated stuff

  print_category_entry("$category:name", $tags, $lang, "Original Name ($lang): {$tags['name']}", "name");

  if($tags['description']) {
    print_category_entry("$category:description", $tags, $lang, "Default description: \"{$tags['description']}\"", "description");
  }

  $res_rule=sql_query("select * from category_rule where category_id='$category' and version='$version'", $db_central);
  while($elem_rule=pg_fetch_assoc($res_rule)) {
    $tags=parse_hstore($elem_rule['tags']);

    // check if deprecated $lang_str exists
    if(!$tags["name:$ui_lang"]) {
      if($x=$lang_str["list_".strtr($tags["match"], array("="=>"_"))]) {
	if(is_array($x))
	  $x=$x[0];
	$tags["name:$ui_lang"]=$x;
      }
      elseif($x=$lang_str["station_type_".strtr($tags["match"], array("="=>"_"))]) {
	if(is_array($x))
	  $x=$x[0];
	$tags["name:$ui_lang"]=$x;
      }
    }
    // end deprecated stuff

    print_category_entry("$category:{$elem_rule['rule_id']}:name", $tags, $lang, "Match: {$tags['match']}", "name");

    if($tags['description']) {
      print_category_entry("$category:{$elem_rule['rule_id']}:description", $tags, $lang, "Default description: \"{$tags['description']}\"", "description");
    }
  }

  print "</syntaxhighlight>\n";
  print "\n";
}
      if($l==$lang)
	$tags_cat["$tag"]=$value;
      else
	$tags_cat["$tag:$l"]=$value;
    }
  }

  if(sizeof(array_diff_assoc($tags_cat, $tags_old)))
    $change=true;
 
  $sql_str.="insert into category values ( '$category_id', ".array_to_hstore($tags_cat).", '$new_version', Array[ '$version' ], ''::hstore );\n";
  $sql_str.="update category_current set version='$new_version' where category_id='$category_id';\n";

  $res_rule=sql_query("select * from category_rule where category_id='$category_id' and version='$version'");
  while($elem_rule=pg_fetch_assoc($res_rule)) {
    $tags_rule=parse_hstore($elem_rule['tags']);

    $tags_old=$tags_rule;

    foreach($lang_cat_list["$category_id:{$elem_rule['rule_id']}"] as $tag=>$dummy) {
      foreach($dummy as $l=>$value) {
        if(is_array($value)) {
	  $value=implode(";", $value);
	}

	if($l==$lang)
	  $tags_rule["$tag"]=$value;
	else
	  $tags_rule["$tag:$l"]=$value;
      }
    }
Example #7
0
function category_history_all($id, $param, $version) {
  $pg_id=postgre_escape($id);
  $list=array();

  if(!$version) {
    $res=sql_query("select * from category_current where category_id=$pg_id", $db_central);
    $elem=pg_fetch_assoc($res);
    $version=$elem['version'];
  }

  if($id)
    $res=sql_query("select * from category where category_id=$pg_id", $db_central);
  else {
    $pg_version=postgre_escape($version);
    $res=sql_query("select * from category where category_id=(select category_id from category first where first.version=$pg_version)", $db_central);
  }

  while($elem=pg_fetch_assoc($res)) {
    $elem['category_id']=$elem['category_id'];
    $elem['parent_versions']=parse_array($elem['parent_versions']);
    $elem['version_tags']=parse_hstore($elem['version_tags']);
    $list[$elem['version']]=$elem;
  }

  return array($list, $version);
}
Example #8
0
  function __construct($param=0, $force_auth=0) {
    global $db_central;

    $this->authenticated=false;

    // anonymous user
    if(!$param) {
      $this->load_anonymous();
      return;
    }

    // forced authentication (e.g. we found a valid auth_id)
    if($force_auth) {
      $this->username=$param['username'];
      $this->pg_username=postgre_escape($this->username);
      $this->auth_id=$param['auth_id'];
      $this->authenticated=true;
    }
    else {
      // Other methods for auth, e.g. OpenID
      $other_auth=null;
      call_hooks("user_is_valid", &$other_auth, $param);
      if($other_auth) {
	$this->username=$other_auth['username'];
	$this->pg_username=postgre_escape($other_auth['username']);
	$this->authenticated=true;
      }
      // also other auth methods did not work
      else {
	$this->username=$param['username'];
	$this->pg_username=postgre_escape($param['username']);
      }
    }

    // get user from database
    $res=sql_query("select * from user_list where username={$this->pg_username}", $db_central);
    // user does not exist -> anonymous
    if(!($elem=pg_fetch_assoc($res))) {
      $this->load_anonymous();
      return;
    }

    // not authenticated yet, check password
    if(!$this->authenticated) {
      if($elem['md5_password']!=$param['md5_password']) {
	unset($this->username);
	unset($this->pg_username);
	$this->load_anonymous();
	return;
      }
    }

    $this->authenticated=true;
    $this->tags=new tags(parse_hstore($elem['osm_tags']));
    $this->create_auth();
  }
Example #9
0
  function print_match($res) {
    global $data_lang;
    $lang=$data_lang;
    $id=array();

    global $make_valid;
    $id=$res['osm_id'];

    $rule_tags=new tags(parse_hstore($res['rule_tags']));

    $tags=parse_hstore($res['osm_tags']);

    $ret="<match ";
    $ob=load_object($res, $tags);
    $info=explode("||", $res['res']);

    $ret.="id=\"{$id}\" ";
    $ret.="rule_id=\"{$res['rule_id']}\">\n";

    foreach($tags as $k=>$v) {
      $k=strtr($k, array("&"=>"&amp;", ">"=>"&gt;", "<"=>"&lt;", "\""=>"&quot;"));
      $v=strtr($v, array("&"=>"&amp;", ">"=>"&gt;", "<"=>"&lt;", "\""=>"&quot;"));
      $ret.="  <tag k=\"$k\" v=\"$v\" />\n";
    }

    $ret.="  <tag k=\"#geo:center\" v=\"{$res['center']}\"/>\n";
    $ret.="  <tag k=\"#importance\" v=\"{$res['importance']}\"/>\n";

    $ret.="</match>\n";

    return $ret;
  }