예제 #1
0
function wikipedia_streetnames_info($info_ret, $object) {
  global $data_lang;
  $text="";

  if(!$object->tags->get("highway"))
    return;

  $res=sql_query("select * from osm_polygon where osm_way && geomfromtext('{$object->data['way']}', 900913) and CollectionIntersects(osm_way, geomfromtext('{$object->data['way']}', 900913)) and osm_tags @> 'boundary=>administrative' order by parse_number(osm_tags->'admin_level') desc");
  while($elem=pg_fetch_assoc($res)) {
    $boundary=load_object($elem['osm_id']);

    $data=cache_search($boundary->id, "wikipedia:street_names:$data_lang");
    if($data) {
      $data=unserialize($data);
    }
    else {
      $data=wikipedia_get_lang_page($boundary, "wikipedia:street_names");
      $article=wikipedia_get_article($boundary, $data['page'], $data['lang']);
      $data['article']=$article;

      cache_insert($boundary->id, "wikipedia:street_names:$data_lang", 
        serialize($data), "1 hour");
    }

    if($data['article']) {
      $text.=wikipedia_streetnames_parse($data['article'], $object);
      if($text) {
	$text.="<br>".lang("source").": <a class='external' href='".wikipedia_url($boundary, $data['page'], $data['lang'])."'>Wikipedia</a>\n";
	$info_ret[]=array("head"=>"wikipedia_streetnames", "content"=>$text, "doc"=>"plugin:wikipedia_streetnames/feature");
	return;
      }
    }
  }
}
예제 #2
0
 function pre_routes(&$uri = array(), &$old_uri = "")
 {
     //echo $uri . ' - ' . $old_uri;
     if ($uri != "/" && strpos($uri, "userlogin") === false) {
         if (!isset($_SESSION['usr_id'])) {
             $CTR =& load_object('Config');
             Output::App()->redirect($CTR->get('base_url'));
         }
     }
 }
예제 #3
0
function ajax_info($param, $xml) {
  $ob=load_object($param);

  if(!$ob)
    return 0;

  $chapters=array();
  call_hooks("info", &$chapters, $ob);

  return $chapters;
}
/**
 *	controller that shows a textarea for editing either a page's or the global 
 *	user-defined css file
 */
function controller_user_css_stylesheet($args)
{
    if ($args[0][1] == 'stylesheet') {
        // changing page stylesheet
        $page = $args[0][0];
        page_canonical($page);
        if (!page_exists($page)) {
            hotglue_error(404);
        }
    } else {
        // changing global stylesheet
        $page = false;
    }
    default_html(true);
    html_add_js_var('$.glue.page', $page);
    html_add_css(base_url() . 'modules/user_css/user_css.css');
    if (USE_MIN_FILES) {
        html_add_js(base_url() . 'modules/user_css/user_css.min.js');
    } else {
        html_add_js(base_url() . 'modules/user_css/user_css.js');
    }
    $bdy =& body();
    elem_attr($bdy, 'id', 'user_css');
    if ($page === false) {
        body_append('<h1>Global stylesheet</h1>' . nl());
        // try to load css
        $css = @file_get_contents(CONTENT_DIR . '/usercss');
        if ($css === false) {
            $css = '';
        }
    } else {
        body_append('<h1>' . htmlspecialchars($page, ENT_NOQUOTES, 'UTF-8') . ' stylesheet</h1>' . nl());
        load_modules('glue');
        $obj = load_object(array('name' => $page . '.usercss'));
        if ($obj['#error']) {
            $css = '';
        } else {
            $css = $obj['#data']['content'];
        }
    }
    // encoding to html must come before the replacement below
    $css = htmlspecialchars($css, ENT_NOQUOTES, 'UTF-8');
    // replace newline characters by an entity to prevent render_object()
    // from adding some indentation
    $css = str_replace("\r\n", '&#10;', $css);
    $css = str_replace("\n", '&#10;', $css);
    // why not replace tabs as well why we are at it
    $css = str_replace("\t", '&#09;', $css);
    body_append('<textarea id="user_css_text" placeholder="enter css code here">' . $css . '</textarea>' . nl());
    body_append('<br>' . nl());
    body_append('<input id="user_css_save" type="button" value="save">' . nl());
    echo html_finalize();
}
예제 #5
0
function load_page($file_name, $vars = [])
{
    if (!isset($_SESSION)) {
        session_start();
        session_write_close();
    }
    $pages = ['header', 'nav', $file_name, 'footer'];
    $vars['config'] = load_object('blog');
    $vars['user'] = $_SESSION;
    foreach ($pages as $page) {
        $file_path = sprintf(PAGE_PATH, $page);
        require $file_path;
    }
}
예제 #6
0
function osm_member_info(&$chapters, $ob) {
  $members=$ob->members();

  if($members) {
    $content=array();
    foreach($members as $member_id=>$role) {
      $member=load_object($member_id);
      if($member) {
	$member->tags->set("#role", $role);
	$content[$member_id]=$member->export_array();
      }
    }

    $chapters[]=array(
      "id"=>"osm_member-members",
      "head"=>lang("osm_member-members"),
      "weight"=>5,
      "data"=>$content,
    );
  }

  $member_of=$ob->member_of();

  if(sizeof($member_of)) {
    $content=array();
    foreach($member_of as $of_id=>$role) {
      $of=load_object($of_id);
      if($of) {
	$of->tags->set("#role", $role);
	$content[$of_id]=$of->export_array();
      }
    }

    $chapters[]=array(
      "id"=>"osm_member-member_of",
      "head"=>lang("osm_member-member_of"),
      "weight"=>5,
      "data"=>$content,
    );
  }
}
예제 #7
0
function ajax_load_object($param, $xml) {
  $ob=load_object($param['ob']);

  $result=dom_create_append($xml, "result", $xml);
  $node=$ob->export_dom($xml);

  if($node)
    $result->appendChild($node);
}
예제 #8
0
function page_upload($args)
{
    // only handle the file if the frontend wants us to
    if (empty($args['preferred_module']) || $args['preferred_module'] != 'page') {
        return false;
    }
    // check if supported file
    if (!in_array($args['mime'], array('image/jpeg', 'image/png', 'image/gif')) || $args['mime'] == '' && !in_array(filext($args['file']), array('jpg', 'jpeg', 'png', 'gif'))) {
        return false;
    }
    // check if there is already a background-image and delete it
    $obj = load_object(array('name' => $args['page'] . '.page'));
    if (!$obj['#error']) {
        $obj = $obj['#data'];
        if (!empty($obj['page-background-file'])) {
            delete_upload(array('pagename' => array_shift(expl('.', $args['page'])), 'file' => $obj['page-background-file'], 'max_cnt' => 1));
        }
    }
    // set as background-image in page object
    $obj = array();
    $obj['name'] = $args['page'] . '.page';
    $obj['page-background-file'] = $args['file'];
    $obj['page-background-mime'] = $args['mime'];
    // update page object
    load_modules('glue');
    $ret = update_object($obj);
    if ($ret['#error']) {
        log_msg('page_upload: error updating page object: ' . quot($ret['#data']));
        return false;
    } else {
        // we don't actually render the object here, but signal the
        // frontend that everything went okay
        return true;
    }
}
예제 #9
0
 private static function _build_menu($domain_name = '')
 {
     $C =& load_object('Controller');
     //new Controller();
     //$C->get_instance();
     if (isset($_SESSION['usr_id'])) {
         $domain_list = '';
         $dt = array("username" => $_SESSION['usr_fullname'], 'domain_alias' => $domain_name, 'switch_domain' => $domain_list, 'url_change_pass' => $C->config['base_url'] . 'changepass/', 'url_logout' => $C->config['base_url'] . 'logout/');
         #$ret = $this->render("box/_box_menu_logged", $dt, true);
         $ret = $C->view("box/_top_menu/mn_setting", $dt, true);
     } else {
         $ret = $C->view("box/_box_menu_login", array('domain_alias' => $domain_name), true);
     }
     return $ret;
 }
예제 #10
0
function objects_to_xml($list, $xml, $osm, $all=0, $bounds=0) {
  $loaded=array();
  $to_load_list=array();

  call_hooks("modify_geometry", $list);
  if($list) foreach($list as $id) {
    $r=load_object($id);

    if($r) {
      $loaded[]=$r->id;
      $c=$r->get_xml($osm, $xml, 1, $bounds);
//      if($c)
//	$osm->appendChild($c);

//      if($all) {
//	$to_load_list=array_merge($to_load_list, $r->member_list());
//      }
    }
  }

//  $loaded=array();
//  do {
//    $has_loaded=0;

//    foreach($to_load_list as $obj) {
//      if(!in_array($obj, $loaded)) {
//	$r=load_element($obj);
//	$loaded[]=$r->long_id;
//
//	if($r) {
//	  $c=$r->get_xml($xml);
//	  if($c)
//	    $osm->appendChild($c);
//
//	  if($all) {
//	    $size_to_load_list=sizeof(array_unique($to_load_list));
//	    $to_load_list=array_unique(array_merge($to_load_list, $r->member_list()));
//	    if(sizeof($to_load_list)>$size_to_load_list)
//	      $has_loaded=1;
//	  }
//	}
//      }
//    }
//  } while($has_loaded);
/*
  $list=explode(",", $param[ways]);
  if($list) foreach($list as $id) {
    $r=new way($id);
    $c=$r->get_xml($xml);
    if($c)
      $osm->appendChild($c);
  }

  $list=explode(",", $param[nodes]);
  if($list) foreach($list as $id) {
    $r=new node($id);
    $c=$r->get_xml($xml);
    if($c)
      $osm->appendChild($c);
  }
  */
}
예제 #11
0
/**
 *	serve a resource associated with an object
 *
 *	the function might not return (e.g. when a module calls serve_file()).
 *	@param string $s object (e.g. page.rev.obj)
 *	@param bool $dl download file
 *	@return bool
 */
function serve_resource($s, $dl)
{
    load_modules('glue');
    // resolve symlinks
    $ret = object_get_symlink(array('name' => $s));
    if ($ret['#error'] == false && $ret['#data'] !== false) {
        log_msg('debug', 'controller: resolved resource ' . quot($s) . ' into ' . quot($ret['#data']));
        $s = $ret['#data'];
    }
    $obj = load_object(array('name' => $s));
    if ($obj['#error']) {
        return false;
    } else {
        $obj = $obj['#data'];
    }
    $ret = invoke_hook_while('serve_resource', false, array('obj' => $obj, 'dl' => $dl));
    // this is probably not needed as the module will most likely call
    // serve_file() on success, which does not return
    foreach ($ret as $key => $val) {
        if ($val !== false) {
            return true;
        }
    }
    return false;
}
예제 #12
0
<?php

namespace YABA;

require_once 'includes/includes.inc.php';
if (!file_exists('config/')) {
    header('Location: setup/index.php?page=1');
}
$config = load_object('blog');
$page = 1;
if (array_key_exists('page', $_GET)) {
    $page = $_GET['page'];
}
$pages = [];
load_page('main', ['page' => $page, 'parser' => new \Parsedown(), 'pages' => $pages]);
예제 #13
0
 function send_to_server($filesource = array())
 {
     $C =& load_object('Controller');
     $return = false;
     if (is_array($filesource)) {
         $ftp_server = '';
         $ftp_started = false;
         foreach ($filesource as $key => $f) {
             if (file_exists($f) && preg_match('/\\/media\\//', $f)) {
                 $temp = explode('/', str_replace($C->config['klimg_dir'], '', $f));
                 $folder = $temp[0];
                 if (!$ftp_started) {
                     if ($conn = ftp_connect($C->config['default']['ftp_host'])) {
                         if (ftp_login($conn, $C->config['default']['ftp_username'], $C->config['default']['ftp_password'])) {
                             $ftp_started = true;
                         } else {
                             ftp_close($conn);
                             $return = false;
                         }
                     } else {
                         ftp_close($conn);
                         $return = false;
                     }
                 }
                 $target = $C->config['default']['ftp_rootfolder'];
                 $source = $C->config['klimg_dir'];
                 for ($i = 0; $i <= count($temp) - 1; $i++) {
                     $target .= '/' . $temp[$i];
                     $source .= '/' . $temp[$i];
                     $target = str_replace('//', '/', $target);
                     $source = str_replace('//', '/', $source);
                     if (is_dir($source)) {
                         $this->create_dir($target . "/", $conn);
                     } elseif (is_file($source)) {
                         //optimize JPEG files - reyno (20120308)
                         if (preg_match('/\\.jpg/i', $source)) {
                             exec('/usr/local/bin/jpegoptim --strip-all ' . $source);
                         }
                         //optimize PNG files - reyno (20120312)
                         if (preg_match('/\\.png/i', $source)) {
                             exec('/usr/local/bin/optipng -o7 ' . $source);
                         }
                         if (!ftp_put($conn, $target, $source, FTP_BINARY)) {
                             // file_put_contents($this->log_location, date('Y-m-d H:i:s').' | '. $source."\n", FILE_APPEND);
                             $return = false;
                             var_dump("failed");
                         } else {
                             unset($this->filesource[$key]);
                             $success[] = str_replace('/sooperboy.com', 'http://cdn.klimg.com/sooperboy.com', $target) . "?" . date("Ymdhis");
                             #var_dump($target);
                         }
                     }
                 }
             }
         }
         if ($ftp_started) {
             ftp_close($conn);
         }
         $return = true;
     }
     return $return;
 }
예제 #14
0
function route_info($ret, $object) {
  global $route_types;
  global $network_names;

  if($object->tags->get("type")!="route")
    return;

  $tags=$object->tags;

  switch($tags->get("route")) {
    case "bicycle":
    case "hiking":
    case "foot":
    case "mtb":
      show_overlay("ch");
      break;
    case "road":
      show_overlay("car");
      break;
    case "train":
    case "subway":
    case "railway":
    case "rail":
    case "tram":
    case "bus":
    case "minibus":
    case "ferry":
    case "trolley":
    case "trolleybus":
      show_overlay("pt");
      break;
  }

  $ret[]=array("general_info", $tags->compile_text("#tag_route_type#: %route%<br />\n"));
  //$ret.="Network Type: ".$this->data[network]."<br />\n";
  // TODO - field network in db muss nicht gleich tag sein

  $ret[]=array("general_info", $tags->compile_text("#tag_links#: <a href='%website%'>#field_website#</a><br />\n"));
  $ret[]=array("general_info", $tags->compile_text("#tag_state#: %state%<br />\n"));
  $ret[]=array("general_info", $tags->compile_text("#tag_symbol#: %symbol%<br />\n"));
  $ret[]=array("general_info", $tags->compile_text("#tag_description#: %description%<br />\n"));

  $text="";
  $res_i=sql_query("select * from planet_osm_rels join relation_members on planet_osm_rels.id=relation_members.relation_id and relation_members.member_type='R' where '{$object->data["id"]}'=relation_members.member_id and type='network'");
  if(pg_num_rows($res_i))
    $text.="This route is part of the networks:\n";
  while($elem_i=pg_fetch_assoc($res_i)) {
    $obj=load_object("rel_$elem_i[id]");
    $text.=list_entry($obj->id, $obj->long_name());
  }

  $text="";
  $stop_list=array();
  foreach($object->place()->members as $mem) {
    $id=$mem[0]->id;
    $role=$mem[1];

    if(eregi("^stop.*$", $role, $m)) {
      $stop_index[$id]=sizeof($stop_list);
      $stop_list[$id]=array("dir"=>0, "id"=>$id, "role"=>"both");
      $stop_id_list[]=$mem[0]->only_id;
      $load_list[]=$id;
    }
    elseif(eregi("^forward[:_]stop.*$", $role, $m)) {
      $stop_index[$id]=sizeof($stop_list);
      $stop_list[$id]=array("dir"=>1, "id"=>$id, "role"=>"forward");
      $stop_id_list[]=$mem[0]->only_id;
      $load_list[]=$id;
    }
    elseif(eregi("^backward[:_]stop.*$", $role, $m)) {
      $stop_index[$id]=sizeof($stop_list);
      $stop_list[$id]=array("dir"=>-1, "id"=>$id, "role"=>"backward");
      $stop_id_list[]=$mem[0]->only_id;
      $load_list[]=$id;
    }
  }

  load_objects($load_list);

  if(sizeof($stop_id_list)) {
    $res=sql_query("select 'way_'||l.osm_id as way_id, 'node_'||p.osm_id as stop_id, wn.sequence_id as pos from planet_osm_point p join way_nodes wn on wn.node_id=p.osm_id join planet_osm_line l on wn.way_id=l.osm_id join relation_members rm on rm.member_type='W' and rm.member_id=l.osm_id where rm.relation_id='{$object->only_id}' and p.osm_id in (".implode(",", $stop_id_list).")");
    while($elem=pg_fetch_assoc($res)) {
      $stop_list[$elem[stop_id]][ways][]=array("way_id"=>$elem[way_id], "pos"=>$elem[pos]);
      $way_stop_list[$elem[way_id]][$elem[stop_id]]=$elem;
      unset($stop_id_list[array_search(substr($elem[stop_id], 5), $stop_id_list)]);
    }
  }

  if(sizeof($stop_id_list)) {
    $res=sql_query("select 'way_'||l.osm_id as way_id, 'node_'||p.osm_id as stop_id, (select wn.sequence_id from way_nodes wn join planet_osm_nodes nodes on wn.node_id=nodes.id where wn.way_id=l.osm_id order by Distance(p.way, geometryfromtext('POINT('||nodes.lon||' '||nodes.lat||')', 900913)) asc limit 1) as pos, Distance(p.way, l.way) as d from planet_osm_point p join planet_osm_line l on geometryfromtext('POLYGON(('||".
      "XMIN(p.way)-50||' '||YMIN(p.way)-50||','||".
      "XMAX(p.way)+50||' '||YMIN(p.way)-50||','||".
      "XMAX(p.way)+50||' '||YMAX(p.way)+50||','||".
      "XMIN(p.way)-50||' '||YMAX(p.way)+50||','||".
      "XMIN(p.way)-50||' '||YMIN(p.way)-50||'))', 900913)&&l.way and Distance(p.way, l.way)<20 join relation_members rm on l.osm_id=rm.member_id and rm.member_type='W' where rm.relation_id='{$object->only_id}' and p.osm_id in (".implode(",", $stop_id_list).")");
    while($elem=pg_fetch_assoc($res)) {
      $stop_list[$elem[stop_id]][ways][]=array("way_id"=>$elem[way_id], "pos"=>$elem[pos]);
      $way_stop_list[$elem[way_id]][$elem[stop_id]]=$elem;
    }
  }

  $res=sql_query("select 'way_'||member_id as way_id, 'node_'||(select node_id from way_nodes where way_id=member_id and way_nodes.sequence_id=0) as first, 'node_'||(select node_id from way_nodes where way_id=member_id order by way_nodes.sequence_id desc limit 1) as last from relation_members rm where relation_id='{$object->only_id}' and member_type='W'");
  $nodes=array();
  $ways=array();
  while($elem=pg_fetch_assoc($res)) {
    $ways[$elem[way_id]]=$elem;
    $nodes[$elem[first]][]=$elem[way_id];
    $nodes[$elem[last]][]=$elem[way_id];
  }
  
  foreach($nodes as $node_id=>$way_ids) {
    $nodes[$node_id]=array_unique($way_ids);
  }

  $data=array(
    "stop_list"=>$stop_list,
    "stop_index"=>$stop_index,
    "way_stop_list"=>$way_stop_list,
    "ways"=>$ways,
    "nodes"=>$nodes);

  function possible_way($stop0, $cur_stop_id, &$data, $rek=array(), &$tried=array()) {
    $ret=array();
    if(!$stop0[ways])
      return array();
    
    //print_r($stop0[ways]);
    $ways=array();
    foreach($stop0[ways] as $w) {
      $r="$w[way_id]_$stop0[dir]_$stop0[id]";
      if(!in_array($r, $rek)) {
	$ways[]=$w;
	$rek[]=$r;
      }

      if($tried[$r]) {
	//print "Already tried $r\n";
	return;
      }
      $tried[$r]=1;
    }

    if(!sizeof($ways))
      return array();

//    if(in_array("$stop0[dir]$stop0[id]", $rek))
//      return array();
//    $rek[]="$stop0[dir]$stop0[id]";
//    print "rek ".sizeof($rek).": ".implode(",", $rek)."\n";
//    print "stop0 ";print_r($stop0);

    foreach($stop0[ways] as $way0) {
      $pos0=$way0[pos];
      $poss=array();
//      print "way_stop_list "; print_r($data[way_stop_list][$way0[way_id]]);
      if($data[way_stop_list][$way0[way_id]])
      foreach($data[way_stop_list][$way0[way_id]] as $poss_stop) {
//	print "poss_stop "; print_r($poss_stop);
	if($poss_stop[stop_id]!=$cur_stop_id) {
	  $stopo=$data[stop_list][$poss_stop[stop_id]];
//	print "stop0 "; print_r($stop0);
//	print "stopo "; print_r($stopo);
	  if(($stop0["dir"]==1)&&($poss_stop["pos"]>$pos0)&&($stopo["dir"]!=-1))
	    $poss[$poss_stop["pos"]]=$poss_stop;
	  if(($stop0["dir"]==-1)&&($poss_stop["pos"]<$pos0)&&($stopo["dir"]!=1))
	    $poss[$poss_stop["pos"]]=$poss_stop;
	}
      }
      //print "dir".$stop0[dir]; print "poss ";print_r($poss);
      $k=array_keys($poss);
      if($stop0["dir"]==1)
	sort($k);
      else
	rsort($k);
//	print "dir".$stop0[dir]; print_r($k);

      if(sizeof($poss)) {
	$ret[]=array("stop_id"=>$poss[$k[0]][stop_id], "dir"=>$stop0["dir"], "way"=>$way0[way_id], "rek"=>$rek);
      }
      else {
	$end=$data[ways][$way0[way_id]];
	if($stop0["dir"]==1)
	  $end=$end[last];
	else
	  $end=$end[first];
//	  print "END";
//	  print_r($end);
//	  print_r($way0);
//print_r($data[nodes][$end]);
	foreach($data[nodes][$end] as $w) {
	  if(($w==$way0[way_id])&&(sizeof($data[nodes][$end])>1)) {
	  }
	  elseif($data[ways][$w][first]==$end) {
	    $s=array(
	      "dir"=>1,
	      "id"=>$end,
	      "pos"=>0,
	      "ways"=>array(array("way_id"=>$w, "pos"=>0)));
	    if($d=possible_way($s, $cur_stop_id, $data, $rek, $tried))
	      $ret=array_merge($ret, $d);
	  }
	  else {
	    $s=array(
	      "dir"=>-1,
	      "id"=>$end,
	      "pos"=>9999,
	      "ways"=>array(array("way_id"=>$w, "pos"=>9999)));
	    if($d=possible_way($s, $cur_stop_id, $data, $rek, $tried))
	      $ret=array_merge($ret, $d);
	  }
	}
      }
    }
    /*
      foreach($stop1[ways] as $way1) {
	foreach($data[way_stop_list][$way0] as $poss_stop) {
	  if($poss_stop[id]==$stop0[id]) {
	  }
	  
	  print "poss";
	  print_r($poss_stop);
	}
	if($way0==$way1) {
	  $pos0=$data[way_stop_list][$way0][$stop0[id]][pos];
	  $pos1=$data[way_stop_list][$way1][$stop1[id]][pos];
	  if(($stop0["dir"]==1)&&($stop1["dir"]!=-1))
	    return 1;
	  if(($stop0["dir"]==-1)&&($stop1["dir"]!=1))
	    return -1;
	} 
      }
    }*/

    return $ret;
  }

  $end_node=array(null, null);
  //print_r($data);

  foreach($stop_list as $i=>$stop) {
    //print "$i\n";
    if($stop[ways]) foreach($stop[ways] as $way) {
      $s=$stop;
      $s[ways]=array($way);

      if($stop["dir"]>-1) {
	$s["dir"]=1;
	$poss=possible_way($s, $stop[id], $data);
	$stop_list[$i][possible][$way[way_id]][1]=$poss;
	foreach($poss as $p) {
	  $stop_list[$p[stop_id]][come][$p[way]][$p[dir]][]=array("stop_id"=>$stop[id], "dir"=>$stop["dir"], "way"=>$way[way_id]);
	}
      }
      if($stop["dir"]<1) {
	$s["dir"]=-1;
	$poss=possible_way($s, $stop[id], $data);
	$stop_list[$i][possible][$way[way_id]][-1]=$poss;
	foreach($poss as $p) {
	  $stop_list[$p[stop_id]][come][$p[way]][$p[dir]][]=array("stop_id"=>$stop[id], "dir"=>$stop["dir"], "way"=>$way[way_id]);
	}
      }
    }
    //print_r($stop_list[$i]);
  }

  function posscome_merge($posscome) {
    $ret=array();
    if(!$posscome)
      return array();
    foreach($posscome as $way) {
     foreach($way as $dir) {
       foreach($dir as $poss) {
	 $ret[]=$poss;
       }
     }
    }

    return $ret;
  }

  $turn=1;
  $last=array("possible"=>null, "come"=>null);
  foreach($stop_list as $i=>$stop) {
    $stop_ob=load_object($stop[id]);
    //print $stop[id]." ".$stop_ob->tags->get("name")."\n";

    $success_p=0;
    if($last["possible"]) {
      $come_match=array();
      foreach($last["possible"] as $p) {
	if($p[stop_id]==$stop[id]) {
	  $success_p=1;
	  foreach($stop["come"] as $come_way_id=>$come_way) {
	    foreach($come_way as $come_dir=>$come_list) {
	      foreach($come_list as $come) {
		if($come[stop_id]==$last["possible_id"]) {
		  $come_match[]=array("way_id"=>$come_way_id, "dir"=>$come_dir);
		}
	      }
	    }
	  }
	}
      }

      if($success_p) {
	$stop_list[$last["possible_id"]]["next0"]=$stop[id];
	$stop_list[$stop[id]]["prev0"]=$last["possible_id"];
	$last["possible_id"]=$stop[id];
	//print "$success_p $dir_1 $way_1 $dir1 $way1\n";
	$stop_list[$stop[id]][come_match]=$come_match;
//	print "come_match ";print_r($come_match);

	$last["possible"]=array();
	foreach($come_match as $match) {
	  if($stop["possible"][$match["way_id"]]&&
	     $stop["possible"][$match["way_id"]][$match["dir"]])
	    $last["possible"]=array_merge($last["possible"],
	      $stop["possible"][$match["way_id"]][$match["dir"]]);
	}
      }
    }
    else {
      $last["possible"]=posscome_merge($stop[possible]);
      $last["possible_id"]=$stop[id];
    }

    $success_n=0;
    if($last["come"]) {
      $poss_match=array();
      foreach($last["come"] as $p) {
	if($p[stop_id]==$stop[id]) {
	  $success_n=1;
	  foreach($stop["possible"] as $poss_way_id=>$poss_way) {
	    foreach($poss_way as $poss_dir=>$poss_list) {
	      foreach($poss_list as $poss) {
		if($poss[stop_id]==$last["come_id"]) {
		  $poss_match[]=array("way_id"=>$poss_way_id, "dir"=>$poss_dir);
		}
	      }
	    }
	  }
	}
      }

      if($success_n) {
	$stop_list[$last["come_id"]]["next1"]=$stop[id];
	$stop_list[$stop[id]]["prev1"]=$last["come_id"];
	$last["come_id"]=$stop[id];
	$stop_list[$stop[id]][poss_match]=$poss_match;
	//print "poss_match"; print_r($poss_match);

      //print "stop ";print_r($stop);
	$last["come"]=array();
	foreach($poss_match as $match) {
	  if($stop["come"][$match["way_id"]]&&
	     $stop["come"][$match["way_id"]][$match["dir"]])
	    $last["come"]=array_merge($last["come"],
	      $stop["come"][$match["way_id"]][$match["dir"]]);
	}
      }
    }
    else {
      $last["come"]=posscome_merge($stop[come]);
      $last["come_id"]=$stop[id];
    }

    if((!$success_p)&&(!$success_n)) {
      $last["possible"]=posscome_merge($stop[possible]);
      $last["possible_id"]=$stop[id];
      $last["come"]=posscome_merge($stop[come]);
      $last["come_id"]=$stop[id];
    }
//    if(sizeof($result)&&
//       ($result[sizeof($result)-1][name]==$stop_ob->tags->get("name"))) {
//    }
//    else {
//      $res=array(
//        "name"=>$stop_ob->tags->get("name"),
//        "stop"=>$stop);
      //print "last "; print_r($last);
    $stop_list[$i][last]=$last;
  }

//  print_r($result);

//	print "success {$s[id]}->$stop[id]: $dir\n";
//	$stop_list[$s[id]]["dir_$s[dir]"]=array("dir"=>$dir, "id"=>$stop[id]);
//	unset($no_next[$sp]);
//      }
//  }
  //print_r($stop_list);
//  print_r($way_stop_list);
//  print_r($ways);

  if(sizeof($stop_list)) {
    $text.="<table cellpadding=0 cellspacing=0>\n";

    $waiting=array(0, 0);
    $stop_list_keys=array_keys($stop_list);
    for($i=0; $i<sizeof($stop_list_keys); $i++) {
      $stop=$stop_list[$stop_list_keys[$i]];

      $stop_ob=load_object($stop[id]);
      if($stop[role]=="both") {
	$waiting=array(0, 0);
	if($stop[prev0]&&$stop[next0]) {
	  $img_left="stop_left_both";
	  $waiting[0]=1;
	}
        elseif($stop[prev0]) {
	  $img_left="stop_left_prev";
	}
	elseif($stop[next0]) {
	  $img_left="stop_left_next";
	  $waiting[0]=1;
	}
	else {
	  $img_left="stop_left_none";
	}
	if($stop[prev1]&&$stop[next1]) {
	  $img_right="stop_right_both";
	  $waiting[1]=1;
	}
        elseif($stop[prev1]) {
	  $img_right="stop_right_prev";
	}
	elseif($stop[next1]) {
	  $img_right="stop_right_next";
	  $waiting[1]=1;
	}
	else {
	  $img_right="stop_right_none";
	}

        $highlight="onMouseOver='set_highlight([\"$stop_ob->id\"])' onMouseOut='unset_highlight()'";
	$text.="<tr><td $highlight><img src='img/$img_left.png'></td><td $highlight><img src='img/$img_right.png'></td><td>{$stop_ob->tags->get("name")}</td></tr>\n";
      }
      else {
	// right or left?
	if($stop[prev0]||$stop[next0])
	  $side=0;
	else
	  $side=1;

	$waiting[$side]=0;
	if($stop["prev$side"]&&$stop["next$side"]) {
	  $img="stop_single_both";
	  $waiting[$side]=1;
	}
        elseif($stop["prev$side"])
	  $img="stop_single_prev";
	elseif($stop["next$side"]) {
	  $img="stop_single_next";
	  $waiting[$side]=1;
	}
	else {
	  $img="stop_single_none";
	}

        $otherside=(int)!$side;
	$other_highlight="";
	if((!$waiting[$otherside])&&($stop["next$otherside"])) {
	  $img_other="stop_to".($side?"right":"left")."_next";
	  $img.="_from".($side?"left":"right");
	  $waiting[$otherside]=1;
	}
	elseif(($waiting[$otherside])&&($stop["prev$otherside"])&&(!$stop["next$otherside"])) {
	  $img_other="stop_to".($side?"right":"left")."_prev";
	  $img.="_from".($side?"left":"right");
	  $waiting[$otherside]=0;
	}
	elseif($waiting[$otherside]) {
	  $next_stop=$stop_list[$stop_list_keys[$i+1]];
	  $next_stop_ob=load_object($next_stop[id]);
	  if(($next_stop_ob->tags->get("name")==$stop_ob->tags->get("name"))&&
	     ($next_stop["prev$otherside"]||($next_stop["next$otherside"]))) {
	    $i++;
	    $waiting[$otherside]=0;
	    if($next_stop["prev$otherside"]&&$next_stop["next$otherside"]) {
	      $img_other="stop_single_both";
	      $waiting[$otherside]=1;
	    }
	    elseif($next_stop["prev$otherside"])
	      $img_other="stop_single_prev";
	    elseif($next_stop["next$otherside"]) {
	      $img_other="stop_single_next";
	      $waiting[$otherside]=1;
	    }
	    $other_highlight="onMouseOver='set_highlight([\"$next_stop_ob->id\"])' onMouseOut='unset_highlight()'";
	  }
	  else {
	    $img_other="stop_none_both";
	  }
	}
	else {
	  $img_other="stop_none_none";
	}

        $text.="<tr>";
        $highlight="onMouseOver='set_highlight([\"$stop_ob->id\"])' onMouseOut='unset_highlight()'";
	if($side)
	  $text.="<td><img $other_highlight src='img/$img_other.png'></td><td $highlight><img src='img/$img.png'></td>";
	else
	  $text.="<td $highlight><img src='img/$img.png'></td><td><img $other_highlight src='img/$img_other.png'></td>";
	
	$text.="<td>{$stop_ob->tags->get("name")}</td></tr>\n";
      }
    }

    $text.="</table>\n";

//    $text.="<pre>".print_r($stop_list, 1)."</pre>";
    $ret[]=array("stops", $text);
  }

  return $ret;

  if(sizeof($stop_list)) {
    $stop_list_sort=array_keys($stop_list);
    natsort($stop_list_sort);

    $text.="<table>\n";
    $text.="<thead><tr><td>↓</td><td>↑</td><td></td></tr></thead>\n<tbody>";
    foreach($stop_list_sort as $num) {
      $stops=$stop_list[$num];
      $station=array(0, 0);

// TODO: find_station_rel optimieren ... Durch eine Abfrage ersetzen?
      $station=$stops;
      $stops_obj=array(load_object($stops[0]), load_object($stops[1]));
      if($stops[0]) {
	if(method_exists($stops_obj[0], "find_station"))
	  $station[0]=$stops_obj[0]->find_station();
	else 
	  $station[0]=$stops_obj[0];
      }
      if($stops[1]) {
	if(method_exists($stops_obj[1], "find_station"))
	  $station[1]=$stops_obj[1]->find_station();
	else 
	  $station[1]=$stops_obj[1];
      }
//        if($stops[0]==$stops[1]) {
//	  $station=$stops;
////	  if($r=find_station($stops)) {
////	    $station[0]="rel_{$r[0]->id}";
////	    $station[1]="rel_{$r[0]->id}";
////	  }
//	}
//	else {
//	  if($stops[0]) {
//	    $station[0]="node_{$stops[0]->id}";
//	    if($r=find_station_rel($stops[0]->id))
//	      $station[0]="rel_{$r[0]->id}";
//	  }
//	  if($stops[1]) {
//	    $station[1]="node_{$stops[1]->id}";
//	    if($r=find_station_rel($stops[1]->id))
//	      $station[1]="rel_{$r[0]->id}";
//	  }
//	}

      if((!$stops[0])&&(!$stops[1])) {
      }
      elseif(!$stops[0]) {
	$text.="  <tr>\n";
	$text.="    <td class='bullet'>|</td>\n";
	$text.="    <td class='bullet' onMouseOver='set_highlight([\"{$stops[1]}\"])' onMouseOut='unset_highlight()'>O</td>\n";
	$text.="    <td class='details'><a href='#{$station[1]->id}' onMouseOver='set_highlight([\"$stops[1]\"])' onMouseOut='unset_highlight()'>".$stops_obj[1]->long_name()."</a></td>\n";
	$text.="  </tr>\n";
      }
      elseif(!$stops[1]) {
	$text.="  <tr>\n";
	$text.="    <td class='bullet' onMouseOver='set_highlight([\"{$stops[0]}\"])' onMouseOut='unset_highlight()'>O</td>\n";
	$text.="    <td class='bullet'>|</td>\n";
	$text.="    <td class='details'><a href='#{$station[0]->id}' onMouseOver='set_highlight([\"{$stops[0]}\"])' onMouseOut='unset_highlight()'>".$stops_obj[0]->long_name()."</a></td>\n";
	$text.="  </tr>\n";
      }
      elseif($stops[0]==$stops[1]) {
	$text.="  <tr>\n";
	$text.="    <td class='bullet' onMouseOver='set_highlight([\"{$stops[0]}\"])' onMouseOut='unset_highlight()'>O</td>\n";
	$text.="    <td class='bullet' onMouseOver='set_highlight([\"{$stops[1]}\"])' onMouseOut='unset_highlight()'>O</td>\n";
	$text.="    <td class='details'><a href='#{$station[0]->id}' onMouseOver='set_highlight([\"{$stops[0]}\"])' onMouseOut='unset_highlight()'>".$stops_obj[0]->long_name()."</a></td>\n";
	$text.="  </tr>\n";
      }
      elseif($stops_obj[0]->long_name()==$stops_obj[1]->long_name()) {
	$text.="  <tr>\n";
	$text.="    <td class='bullet' onMouseOver='set_highlight([\"{$stops[0]}\"])' onMouseOut='unset_highlight()'>O</td>\n";
	$text.="    <td class='bullet' onMouseOver='set_highlight([\"{$stops[1]}\"])' onMouseOut='unset_highlight()'>O</td>\n";
	$text.="    <td class='details'><a href='#{$station[0]->id}' onMouseOver='set_highlight([\"{$stops[0]}\", \"{$stops[1]}\"])' onMouseOut='unset_highlight()'>".$stops_obj[1]->long_name()."</a></td>\n";
	$text.="  </tr>\n";
      }
      else {
	$text.="  <tr>\n";
	$text.="    <td class='bullet' onMouseOver='set_highlight([\"{$stops[0]}\"])' onMouseOut='unset_highlight()'>O</td>\n";
	$text.="    <td class='bullet'>|</td>\n";
	$text.="    <td class='details'><a href='#{$station[0]->id}' onMouseOver='set_highlight([\"{$stops[0]}\"])' onMouseOut='unset_highlight()'>".$stops_obj[0]->long_name()."</a></td>\n";
	$text.="  </tr>\n";
	$text.="  <tr>\n";
	$text.="    <td class='bullet'>|</td>\n";
	$text.="    <td class='bullet' onMouseOver='set_highlight([\"{$stops[1]}\"])' onMouseOut='unset_highlight()'>O</td>\n";
	$text.="    <td class='details'><a href='#{$station[1]->id}' onMouseOver='set_highlight([\"{$stops[1]}\"])' onMouseOut='unset_highlight()'>".$stops_obj[1]->long_name()."</a></td>\n";
	$text.="  </tr>\n";
      }
    }

    $text.="</tbody></table>\n";
    $ret[]=array("stops", $text);
  }

  return $ret;
}
예제 #15
0
function newbb_load_object()
{
    return load_object();
}
예제 #16
0
파일: json.php 프로젝트: cyberorca/dfp-api
 function _build_result()
 {
     $server_cluster = $this->config['server_cluster'];
     if (post("read_json")) {
         if (post("url_read")) {
             $json_path = post("url_read");
             foreach ($server_cluster as $serv) {
                 //echo $json_path.'<br>'.$this->config['www_url'].'<br>';
                 $json_path = str_replace(trim($this->config['www_url']), "", trim($json_path));
                 //echo $serv . 'read-json/' . $json_path;
                 $json = file_get_contents($serv . 'read-json/' . $json_path);
                 $tmp = json_decode($json, true);
                 return '<pre>' . print_r($tmp, true) . '</pre>';
             }
         } elseif (post("id_read")) {
             $id_news = post("id_read");
             $var = $this->news_model->get_news_by_id($id_news);
             $cat = $this->get_cat_parent_jsview($id_news, $var[0]['news_category']);
             foreach ($server_cluster as $serv) {
                 $json = file_get_contents($serv . 'read-json/' . $cat['url'] . '/' . $var[0]['news_url'] . '.html');
                 $tmp = json_decode($json, true);
                 return '<pre>' . print_r($tmp, true) . '</pre>';
             }
         }
     } else {
         if (post("read_cache")) {
             $CC =& load_object('Cache');
             $CC->memcache_active = true;
             $CC->filecache_active = true;
             setCache("key-key-key", "data cache key", 1800);
             if (post("url_read")) {
                 $json_path = post("url_read");
                 //$cache = checkCache($url,true);
             } elseif (post("id_read")) {
                 $id_news = post("id_read");
                 $var = $this->news_model->get_news_by_id($id_news);
                 $cat = $this->get_cat_parent_jsview($id_news, $var[0]['news_category']);
                 $url = $this->config['www_url'] . $cat['url'] . '/' . $var[0]['news_url'] . '.html';
                 //$cache = checkCache($url,true);
             }
             $cache = checkCache("key-key-key", true, 1800);
             var_dump($cache);
             $CC->memcache_active = false;
             $CC->filecache_active = false;
             return $cache;
         } else {
             if (post("update_json")) {
                 if (post("url_gen")) {
                     $json_path = post("url_gen");
                     foreach ($server_cluster as $serv) {
                         //echo $json_path.'<br>'.$this->config['www_url'].'<br>';
                         $json_path = str_replace(trim($this->config['www_url']), "", trim($json_path));
                         $json = file_get_contents($serv . 'update-json/' . $json_path);
                         if ($json) {
                             return 'Json Update';
                         }
                     }
                 } elseif (post("id_gen")) {
                     $id_news = post("id_gen");
                     $var = $this->news_model->get_news_by_id($id_news);
                     $cat = $this->get_cat_parent_jsview($id_news, $var[0]['news_category']);
                     foreach ($server_cluster as $serv) {
                         $json = file_get_contents($serv . 'update-json/' . $cat['url'] . '/' . $var[0]['news_url'] . '.html');
                         if ($json) {
                             return 'Json Update';
                         }
                     }
                 } else {
                     $ret = '';
                     $cat = post('categori');
                     $arrCat = array();
                     if ($cat != '0') {
                         $arrCat[] = $cat;
                         $tmp_name = $this->arr_Categori['id_to_url'][$cat];
                         $cat_sub = $this->get_sub_cat($tmp_name);
                         if (is_array($cat_sub) && count($cat_sub) > 0) {
                             $arrCat = array_merge($arrCat, $cat_sub);
                         }
                     }
                     $dateFrom = trim(post('startPeriod'));
                     $dateTo = trim(post('endPeriod'));
                     $type_news = post('type_news');
                     $type_news = $type_news != '' ? $type_news : 'all';
                     $row = $this->news_model->get_news_by_category($arrCat, $type_news, $dateFrom, $dateTo);
                     if (is_array($row) && count($row) > 0) {
                         foreach ($row as $rs) {
                             $cat = $this->get_cat_parent_jsview($rs['news_id'], $rs['news_category']);
                             foreach ($server_cluster as $serv) {
                                 $json = file_get_contents($serv . 'update-json/' . $cat['url'] . '/' . $rs['news_url'] . '.html');
                                 $ret .= $this->config['www_url'] . $cat['url'] . '/' . $rs['news_url'] . '.html<br>';
                             }
                         }
                     }
                     return $ret;
                 }
             }
         }
     }
 }
예제 #17
0
function cemetery_info($ret, $object) {
  $is_ceme=0;
  $is_grave=0;
  $text="";

  if($x=$object->tags->get("cemetery")) {
    show_overlay("culture");
    if($x=="grave")
      $is_grave=1;
  }
  if($object->tags->get("amenity")=="grave_yard") {
    show_overlay("culture");
    $is_ceme=1;
  }
  if($object->tags->get("landuse")=="cemetery") {
    show_overlay("culture");
    $is_ceme=1;
  }

  if(($object->element=="way")&&($is_ceme)) {
    $qry="(select 'node' as element, gra.osm_id as id, gra.name from planet_osm_polygon ceme join planet_osm_point gra on gra.way&&ceme.way and Within(gra.way, ceme.way) and (gra.cemetery='grave' or gra.historic='grave') where ceme.osm_id='$object->only_id' union select 'way' as element, gra.osm_id as id, gra.name from planet_osm_polygon ceme join planet_osm_polygon gra on gra.way&&ceme.way and Within(gra.way, ceme.way) and (gra.cemetery='grave' or gra.historic='grave') where ceme.osm_id='$object->only_id') order by name";
    $res=sql_query($qry);

    $list=array();
    while($elem=pg_fetch_assoc($res)) {
      $list[]=$elem;
    }

    load_objects($list);

    foreach($list as $l) {
      $l=load_object($l);
      $text.=list_entry($l->id, $l->long_name());
    }

    if($text)
      $ret[]=array("graves", $text);
  }

  if($is_grave) {
    switch($object->element) {
      case "node":
        $qry="select 'way' as element, ceme.osm_id as id, ceme.name from planet_osm_point gra join planet_osm_polygon ceme on gra.way&&ceme.way and Within(gra.way, ceme.way) and (ceme.landuse='cemetery' or ceme.amenity='grave_yard') where gra.osm_id='$object->only_id'";
	break;
      case "way":
        $qry="select 'way' as element, ceme.osm_id as id, ceme.name from planet_osm_polygon gra join planet_osm_polygon ceme on gra.way&&ceme.way and Within(gra.way, ceme.way) and (ceme.landuse='cemetery' or ceme.amenity='grave_yard') where gra.osm_id='$object->only_id'";
    }
    $res=sql_query($qry);

    while($elem=pg_fetch_assoc($res)) {
      $list[]=$elem;
    }

    load_objects($list);

    foreach($list as $l) {
      $l=load_object($l);
      $text.=lang("grave_is_on")." <a href='#$l->id'>{$l->long_name()}</a><br/>";
    }

    if($text)
      $ret[]=array("general_info", $text);
  }

  if($object->tags->get("landuse"))
    map_zoom(16);
}
예제 #18
0
 function __construct($data) {
   parent::__construct($data);
   if(is_string($this->data[member_ids])) {
     $this->data[member_ids]=parse_array($this->data[member_ids]);
     $this->data[member_roles]=parse_array($this->data[member_roles]);
     load_objects($this->data[member_ids]);
     foreach($this->data[member_ids] as $i=>$mem) {
       $obj=load_object($mem);
       $this->members[]=array($obj, $this->data[member_roles][$i]);
     }
   }
 }
예제 #19
0
/**
 *	list all objects referencing a certain file in the shared directory
 *
 *	@param array $args arguments
 *		key 'pagename' is the pagename (i.e. page)
 *		key 'file' filename of file in the shared directory
 *		key 'stop_after' n references
 *	@return array response
 *		array of objects (i.e. page.rev.obj)
 */
function upload_references($args)
{
    $revs = revisions($args);
    if ($revs['#error']) {
        return $revs;
    } else {
        $revs = $revs['#data'];
    }
    if (empty($args['file'])) {
        return response('Required argument "file" missing or empty', 400);
    }
    // this is an optimization for delete_upload()
    if (@is_numeric($args['stop_after'])) {
        $stop_after = intval($args['stop_after']);
    } else {
        $stop_after = 0;
    }
    $ret = array();
    // for each revision
    foreach ($revs as $rev) {
        // load all objects
        $files = @scandir(CONTENT_DIR . '/' . $args['pagename'] . '/' . $rev);
        foreach ($files as $f) {
            if ($f == '.' || $f == '..') {
                continue;
            }
            $obj = load_object(array('name' => $args['pagename'] . '.' . $rev . '.' . $f));
            if ($obj['#error']) {
                continue;
            } else {
                $obj = $obj['#data'];
            }
            // and handle the object to our modules
            log_msg('debug', 'upload_references: checking ' . quot($obj['name']));
            $revs = invoke_hook_while('has_reference', false, array('file' => $args['file'], 'obj' => $obj));
            if (count($revs)) {
                $ret[] = $args['pagename'] . '.' . $rev . '.' . $f;
                if (count($ret) == $stop_after) {
                    // return prematurely
                    return response($ret);
                }
            }
        }
    }
    return response($ret);
}
예제 #20
0
/**
 *	controller that shows a textarea for editing either a page's or the global 
 *	user-defined code files
 */
function controller_user_code_stylesheet($args)
{
    if ($args[0][1] == 'code') {
        // changing page code
        $page = $args[0][0];
        page_canonical($page);
        if (!page_exists($page)) {
            hotglue_error(404);
        }
    } else {
        // changing global code
        $page = false;
    }
    default_html(true);
    html_add_js_var('$.glue.page', $page);
    html_add_css(base_url() . 'modules/user_code/user_code.css');
    if (USE_MIN_FILES) {
        html_add_js(base_url() . 'modules/user_code/user_code.min.js');
    } else {
        html_add_js(base_url() . 'modules/user_code/user_code.js');
    }
    $bdy =& body();
    // create array with names of code elements
    $code = array('head' => '', 'body' => '');
    elem_attr($bdy, 'id', 'user_code');
    if ($page === false) {
        body_append('<h1>Global code</h1>' . nl());
        // try to load code
        foreach ($code as $x => $v) {
            $code[$x] = @file_get_contents(CONTENT_DIR . '/user' . $x);
            if ($code[$x] === false) {
                $code[$x] = '';
            }
        }
    } else {
        body_append('<h1>"' . htmlspecialchars(substr($page, 0, strpos($page, '.')), ENT_NOQUOTES, 'UTF-8') . '" page code</h1>' . nl());
        load_modules('glue');
        foreach ($code as $x => $v) {
            $obj = load_object(array('name' => $page . '.user' . $x));
            if ($obj['#error']) {
                $code[$x] = '';
            } else {
                $code[$x] = $obj['#data']['content'];
            }
        }
    }
    foreach ($code as $k => $v) {
        // encoding to html must come before the replacement below
        $v = htmlspecialchars($v, ENT_NOQUOTES, 'UTF-8');
        // replace newline characters by an entity to prevent render_object()
        // from adding some indentation
        $v = str_replace("\r\n", '&#10;', $v);
        $v = str_replace("\n", '&#10;', $v);
        // why not replace tabs as well why we are at it
        $v = str_replace("\t", '&#09;', $v);
        $code[$k] = $v;
    }
    body_append('<div id=\'text\'>add your custom code to &lt;head&gt; and &lt;body&gt; sections of this ' . ($page ? 'page.' : 'site.') . nl());
    body_append('<br>' . nl());
    body_append('be cautious - errors in the code below may render the whole ' . ($page ? 'page' : 'site') . ' unusable.</div>' . nl());
    body_append('<br>' . nl());
    body_append('<div id=\'fake_tags\'>&lt;head&gt;</div>' . nl());
    body_append('<textarea id="user_head_text" placeholder="enter code here">' . $code['head'] . '</textarea>' . nl());
    body_append('<br>' . nl());
    body_append('<div id=\'fake_tags\'>&lt;/head&gt;<br>' . nl());
    body_append('&lt;body&gt;</div>' . nl());
    body_append('<textarea id="user_body_text" placeholder="enter code here">' . $code['body'] . '</textarea>' . nl());
    body_append('<div id=\'fake_tags\'>&lt;/body&gt;</div><br>' . nl());
    body_append('<input id="user_code_save" type="button" value="save">' . nl());
    echo html_finalize();
}
예제 #21
0
/**
 *	resize an image object
 *
 *	this function drops the reference to any currently resized version, 
 *	saves the resized image together with the original image in the page's 
 *	shared folder and updates the object file to use the resized version.
 *	@param array $args arguments
 *		key 'name' name of the objects
 *		key 'width' width in px
 *		key 'height' height in px
 *	@return array response
 *		true if the client is advised to reload the image, false if not
 */
function image_resize($args)
{
    // check for gd
    if (!_gd_available()) {
        return response('Host does not have gd', 500);
    }
    // set requested width & height
    if (($width = @intval($args['width'])) == 0) {
        return response('Required argument "width" is zero or does not exist', 400);
    }
    if (($height = @intval($args['height'])) == 0) {
        return response('Required argument "height" is zero or does not exist', 400);
    }
    load_modules('glue');
    // resolve symlinks
    $ret = object_get_symlink($args);
    if ($ret['#error']) {
        return $ret;
    } elseif ($ret['#data'] !== false) {
        log_msg('debug', 'image_resize: resolved object ' . quot($args['name']) . ' into ' . quot($ret['#data']));
        $args['name'] = $ret['#data'];
    }
    // load object
    $obj = load_object($args);
    if ($obj['#error']) {
        return $obj;
    } else {
        $obj = $obj['#data'];
    }
    if (@intval($obj['image-file-width']) == 0 || @intval($obj['image-file-height']) == 0) {
        return response('Original dimensions are not available', 500);
    }
    // set pagename
    $pn = array_shift(expl('.', $obj['name']));
    // resizing might not be necessary at all
    if (!empty($obj['image-resized-file']) && @intval($obj['image-resized-width']) == $width && @intval($obj['image-resized-height'] == $height)) {
        log_msg('debug', 'image_resize: width and height match the current resized file, no resize necessary');
        return response(false);
    }
    // else remove any currently resized file
    if (!empty($obj['image-resized-file'])) {
        log_msg('info', 'image_resize: dropping reference to previous resized file ' . quot($obj['image-resized-file']));
        delete_upload(array('pagename' => $pn, 'file' => $obj['image-resized-file'], 'max_cnt' => 1));
        unset($obj['image-resized-file']);
        unset($obj['image-resized-width']);
        unset($obj['image-resized-height']);
        // update object file as well
        $ret = object_remove_attr(array('name' => $obj['name'], 'attr' => array('image-resized-file', 'image-resized-width', 'image-resized-height')));
        if ($ret['#error']) {
            return $ret;
        }
        $was_resized = true;
    } else {
        $was_resized = false;
    }
    // check if width or height are larger than the original
    if (@intval($obj['image-file-width']) <= $width || @intval($obj['image-file-height']) <= $height) {
        log_msg('debug', 'image_resize: dimensions requested are larger or equal than the original file is, no resize necessary');
        // the client need not reload the the image if we were using the
        // original before
        if (!$was_resized) {
            return response(false);
        } else {
            return response(true);
        }
    }
    // check if we really have a source image
    if (empty($obj['image-file-mime']) && empty($obj['image-file'])) {
        return response(false);
    }
    // TODO (later): make this a generic function
    // load source file
    $ext = filext($obj['image-file']);
    $fn = CONTENT_DIR . '/' . $pn . '/shared/' . $obj['image-file'];
    if ($obj['image-file-mime'] == 'image/jpeg' || in_array($ext, array('jpg', 'jpeg'))) {
        $orig = @imagecreatefromjpeg($fn);
        $dest_ext = 'jpg';
    } elseif ($obj['image-file-mime'] == 'image/png' || $ext == 'png') {
        $orig = @imagecreatefrompng($fn);
        $dest_ext = 'png';
    } elseif (is_ani($fn)) {
        // animated images shall not be resized
        log_msg('debug', 'image_resize: animated image, not resizing');
        return response(true);
    } elseif ($obj['image-file-mime'] == 'image/gif' || $ext == 'gif') {
        $orig = @imagecreatefromgif($fn);
        // save gifs as png
        // TODO (later): check for animated gif (see php.net/manual/en/function.imagecreatefromgif.php)
        $dest_ext = 'png';
    } else {
        return response('Unsupported source file format ' . quot($obj['image-file']), 500);
    }
    if ($orig === false) {
        return response('Error loading source file ' . quot($obj['image-file']), 500);
    }
    // get source file dimensions
    $orig_size = @getimagesize($fn);
    // create resized image
    if (($resized = @imagecreatetruecolor($width, $height)) === false) {
        @imagedestroy($orig);
        return response('Error creating the resized image', 500);
    }
    // preserve any alpha channel
    @imagealphablending($resized, false);
    @imagesavealpha($resized, true);
    // try to resize
    if (!@imagecopyresampled($resized, $orig, 0, 0, 0, 0, $width, $height, $orig_size[0], $orig_size[1])) {
        @imagedestroy($resized);
        @imagedestroy($orig);
        return response('Error resizing the source image', 500);
    }
    // setup destination filename
    $a = expl('.', $obj['image-file']);
    if (1 < count($a)) {
        // throw the previous extension away
        $fn = CONTENT_DIR . '/' . $pn . '/shared/' . implode('.', array_slice($a, 0, -1)) . '-' . $width . 'x' . $height . '.' . $dest_ext;
    } else {
        $fn = CONTENT_DIR . '/' . $pn . '/shared/' . $a[0] . '-' . $width . 'x' . $height . '.' . $dest_ext;
    }
    $m = umask(0111);
    if ($dest_ext == 'jpg') {
        $ret = @imagejpeg($resized, $fn, IMAGE_JPEG_QUAL);
    } else {
        if ($dest_ext == 'png') {
            // preserve any alpha channel
            @imagealphablending($resized, false);
            @imagesavealpha($resized, true);
            $ret = @imagepng($resized, $fn, IMAGE_PNG_QUAL);
        }
    }
    umask($m);
    // destroy images again
    @imagedestroy($resized);
    @imagedestroy($orig);
    if (!$ret) {
        return response('Error saving the resized image', 500);
    } else {
        log_msg('info', 'image_resize: created a resized image of ' . quot($obj['name']) . ' -> ' . quot(basename($fn)));
    }
    // the code above can take a while, so read in the object anew via
    // update_object()
    $update = array();
    $update['name'] = $obj['name'];
    $update['image-resized-file'] = basename($fn);
    $update['image-resized-width'] = $width;
    $update['image-resized-height'] = $height;
    // we change width and height here as well since we are racing with the
    // save_object from the frontend after resize
    $update['object-width'] = $width . 'px';
    $update['object-height'] = $height . 'px';
    return update_object($update);
}
예제 #22
0
function forum_load_object()
{
	return load_object();
}
예제 #23
0
 function send_to_server($filesource = array())
 {
     // aws, disable send to server
     return true;
     //include("/data/kapanlagi/development/applications/admin_men/config/ftp.php");
     //include("/data/kapanlagi/development/applications/admin_men/config/url_dir.php");
     $C =& load_object('Controller');
     $return = false;
     if (is_array($filesource)) {
         $ftp_server = '';
         $ftp_started = false;
         foreach ($filesource as $key => $f) {
             if (file_exists($f) && preg_match('/\\/media\\//', $f)) {
                 //$C->config['klimg_dir'].'<br />';
                 $temp = explode('/', str_replace($C->config['klimg_dir'], '', $f));
                 $folder = $temp[0];
                 if (!$ftp_started) {
                     if ($conn = ftp_connect($C->config['default']['ftp_host'])) {
                         if (ftp_login($conn, $C->config['default']['ftp_username'], $C->config['default']['ftp_password'])) {
                             $ftp_started = true;
                         } else {
                             ftp_close($conn);
                             $return = false;
                         }
                     } else {
                         ftp_close($conn);
                         $return = false;
                     }
                 }
                 //echo $C->config['sitename'];
                 $target = $C->config['default']['ftp_rootfolder'];
                 #$target = '/kapanlagi.com';
                 #$source = MEDIA_DIR.$folder;
                 $source = $C->config['klimg_dir'];
                 #echo $source.'<br />';
                 for ($i = 0; $i <= count($temp) - 1; $i++) {
                     $target .= '/' . $temp[$i];
                     $source .= '/' . $temp[$i];
                     //echo '$target : '.$target.'<br />';
                     //echo '$source : '.$source.'<br />';
                     if (is_dir($source)) {
                         //echo $source.'=='.$target.'<br />';
                         @ftp_mkdir($conn, $target);
                     } elseif (is_file($source)) {
                         //optimize JPEG files - reyno (20120308)
                         if (preg_match('/\\.jpg/i', $source)) {
                             exec('/usr/local/bin/jpegoptim --strip-all ' . $source);
                         }
                         //optimize PNG files - reyno (20120312)
                         if (preg_match('/\\.png/i', $source)) {
                             exec('/usr/local/bin/optipng -o7 ' . $source);
                         }
                         if (!@ftp_put($conn, $target, $source, FTP_BINARY)) {
                             // file_put_contents($this->log_location, date('Y-m-d H:i:s').' | '. $source."\n", FILE_APPEND);
                             $return = false;
                             //var_dump("failed");
                         } else {
                             unset($this->filesource[$key]);
                             $success[] = str_replace('/sooperboy.com', 'http://cdn.klimg.com/sooperboy.com', $target) . "?" . date("Ymdhis");
                             //var_dump("success");
                         }
                     }
                 }
             }
         }
         if ($ftp_started) {
             ftp_close($conn);
         }
         $return = true;
     }
     //var_dump($return);die;
     return $return;
 }
예제 #24
0
/**
 * Tag management for XOOPS
 *
 * @copyright	The XOOPS project http://www.xoops.org/
 * @license		http://www.fsf.org/copyleft/gpl.html GNU public license
 * @author		Taiwen Jiang (phppp or D.J.) <*****@*****.**>
 * @since		1.00
 * @version		$Id$
 * @package		module::tag
 */
if (!defined("XOOPS_ROOT_PATH")) {
    exit;
}
defined("FRAMEWORKS_ART_FUNCTIONS_INI") || (include_once XOOPS_ROOT_PATH . '/Frameworks/art/functions.ini.php');
load_object();
/**
 * TagLink 
 * 
 * @author D.J. (phppp)
 * @copyright copyright &copy; Xoops Project
 * @package module::tag
 *
 * {@link ArtObject} 
 *
 */
class TagLink extends ArtObject
{
    /**
     * Constructor
     */
예제 #25
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;
  }