$v) { if ($i>0) $r.=", "; $r.=$f; $i++; } $r.=") VALUES ("; $i=0; foreach ($query as $f => $v) { if ($i>0) $r.=", "; if (is_string($v)) $r.="'".mysql_real_escape_string($v)."'"; else $r.=intval($v); $i++; } $r.=")"; // echo $r; exit; return $r; } function le_generate_sql_update_block (&$query) { $r=" "; $i=0; foreach ($query as $f => $v) { if ($f=='fi_id') continue; if ($i>0) $r.=", "; if (is_string($v)) $r.=$f."='".mysql_real_escape_string($v)."'"; else $r.=$f."=".intval($v); $i++; } $r.=" "; return $r; } function update_latter() { global $update_latter; if (!isset($update_latter)) return; foreach ($update_latter as $f => $v) { $sql='UPDATE '.SITE_DB_ARTICLE_TABLE.' SET '.le_generate_sql_update_block($v).' WHERE '.SITE_DB_ARTICLE_ID.'='.$f; if (!mysql_query ($sql)) {echo $sql." ".mysql_error(); exit;} //echo $sql." ".mysql_error(); exit; } //print_r($update_latter); exit; } function check_if_email_exists($email) { global $found_user_id; $found_user_id=0; $email = mysql_real_escape_string($email); $sql="SELECT ".SITE_DB_USERS_ID." FROM ".SITE_DB_USERS_TABLE." WHERE ".SITE_DB_USERS_EMAIL."='".$email."'"; $sql_email_check = mysql_query($sql); $email_check = mysql_num_rows($sql_email_check); if ($email_check==0) return FALSE; else { if ($row = mysql_fetch_array($sql_email_check, MYSQL_ASSOC)) $found_user_id=$row[SITE_DB_USERS_ID]; return TRUE; } } function check_if_username_exists($username) { global $found_user_id; $found_user_id=0; $username = mysql_real_escape_string($username); $sql_username_check = mysql_query("SELECT ".SITE_DB_USERS_ID." FROM ".SITE_DB_USERS_TABLE." WHERE ".SITE_DB_USERS_USERNAME."='".$username."'"); $username_check = mysql_num_rows($sql_username_check); if ($username_check==0) return FALSE; else { if ($row = mysql_fetch_array($sql_username_check, MYSQL_ASSOC)) $found_user_id=$row[SITE_DB_USERS_ID]; return TRUE; } } function le_user_reset_userdata() { $GLOBALS[SITE_VAR_USERDATA]=le_get_reseted_userdata(); return $GLOBALS[SITE_VAR_USERDATA]; } function le_get_reseted_userdata() { return array( SITE_DB_USERS_ID => 0, SITE_VAR_USERDATA_LOGGED_IN => FALSE, SITE_VAR_USERDATA_LOGGED_OFF => TRUE, SITE_VAR_USERDATA_LOGIN_STATUS => 0, SITE_VAR_USERDATA_ADMIN_STATUS => 0, SITE_DB_USERS_ACTIVE => 0 ); } function le_check_user_login ($username, $password, $encrypted=0) { $username = mysql_real_escape_string($username); if ($encrypted==0 && SITE_USERS_PASSWORDS_ENCRYPTED==TRUE) $password = md5($password); else $password = mysql_real_escape_string($password); $sql = mysql_query("SELECT * FROM ".SITE_DB_USERS_TABLE." WHERE ".SITE_DB_USERS_USERNAME."='".$username."' AND ".SITE_DB_USERS_PASSWORD."='".$password."'".SITE_USERS_ACTIVE_WHERE_QUERY); $login_check = mysql_num_rows($sql); if ($login_check > 0) { $GLOBALS[SITE_VAR_USERDATA]=mysql_fetch_array($sql, MYSQL_ASSOC); $GLOBALS[SITE_VAR_USERDATA][SITE_VAR_USERDATA_LOGGED_IN]=TRUE; $GLOBALS[SITE_VAR_USERDATA][SITE_VAR_USERDATA_LOGGED_OFF]=FALSE; $GLOBALS[SITE_VAR_USERDATA][SITE_VAR_USERDATA_LOGIN_STATUS]=1; $GLOBALS[SITE_VAR_USERDATA][SITE_DB_USERS_ACTIVE]=1; if (!isset($GLOBALS[SITE_VAR_USERDATA][SITE_VAR_USERDATA_ADMIN_STATUS])) $GLOBALS[SITE_VAR_USERDATA][SITE_VAR_USERDATA_ADMIN_STATUS]=0; if (SITE_VAR_USERDATA_ADMIN_STATUS_LITERAL_CHECK) { if ($GLOBALS[SITE_VAR_USERDATA][SITE_VAR_USERDATA_ADMIN_STATUS]=="1") $GLOBALS[SITE_VAR_USERDATA][SITE_VAR_USERDATA_ADMIN_STATUS]=1; else $GLOBALS[SITE_VAR_USERDATA][SITE_VAR_USERDATA_ADMIN_STATUS]=0; } return TRUE; } else { le_user_reset_userdata(); return FALSE; } } function le_login_as ($user_id) { $sql = mysql_query("SELECT * FROM ".SITE_DB_USERS_TABLE." WHERE ".SITE_DB_USERS_ID."=".$user_id.SITE_USERS_ACTIVE_WHERE_QUERY); $login_check = mysql_num_rows($sql); if ($login_check > 0) { $GLOBALS[SITE_VAR_USERDATA]=mysql_fetch_array($sql, MYSQL_ASSOC); $GLOBALS[SITE_VAR_USERDATA][SITE_VAR_USERDATA_LOGGED_IN]=TRUE; $GLOBALS[SITE_VAR_USERDATA][SITE_VAR_USERDATA_LOGGED_OFF]=FALSE; $GLOBALS[SITE_VAR_USERDATA][SITE_VAR_USERDATA_LOGIN_STATUS]=1; $GLOBALS[SITE_VAR_USERDATA][SITE_DB_USERS_ACTIVE]=1; if (!isset($GLOBALS[SITE_VAR_USERDATA][SITE_VAR_USERDATA_ADMIN_STATUS])) $GLOBALS[SITE_VAR_USERDATA][SITE_VAR_USERDATA_ADMIN_STATUS]=0; if (SITE_VAR_USERDATA_ADMIN_STATUS_LITERAL_CHECK) { if ($GLOBALS[SITE_VAR_USERDATA][SITE_VAR_USERDATA_ADMIN_STATUS]=="1") $GLOBALS[SITE_VAR_USERDATA][SITE_VAR_USERDATA_ADMIN_STATUS]=1; else $GLOBALS[SITE_VAR_USERDATA][SITE_VAR_USERDATA_ADMIN_STATUS]=0; } return TRUE; } else { le_user_reset_userdata(); return FALSE; } } function le_get_userdata ($id) { $sql = mysql_query("SELECT * FROM ".SITE_DB_USERS_TABLE." WHERE ".SITE_DB_USERS_ID."=".intval($id)); $login_check = mysql_num_rows($sql); if ($login_check > 0) { $user=mysql_fetch_array($sql, MYSQL_ASSOC); if (!isset($user[SITE_VAR_USERDATA_ADMIN_STATUS])) $user[SITE_VAR_USERDATA_ADMIN_STATUS]=0; if (SITE_VAR_USERDATA_ADMIN_STATUS_LITERAL_CHECK) { if ($user[SITE_VAR_USERDATA_ADMIN_STATUS]=="1") $user[SITE_VAR_USERDATA_ADMIN_STATUS]=1; else $user[SITE_VAR_USERDATA_ADMIN_STATUS]=0; } if (defined('SITE_DB_USERS_ACTIVE')) { if (!isset($user[SITE_DB_USERS_ACTIVE])) $user[SITE_DB_USERS_ACTIVE]=0; if (SITE_VAR_USERDATA_ACTIVE_STATUS_LITERAL_CHECK) { if ($user[SITE_DB_USERS_ACTIVE]=="1") $user[SITE_DB_USERS_ACTIVE]=1; else $user[SITE_DB_USERS_ACTIVE]=0; } } else $user[SITE_DB_USERS_ACTIVE]=1; return $user; } else { return le_get_reseted_userdata(); } } function base64_url_decode($input) { return base64_decode(strtr($input, '-_', '+/')); } function parse_signed_request($signed_request, $secret) { list($encoded_sig, $payload) = explode('.', $signed_request, 2); // decode the data $sig = base64_url_decode($encoded_sig); $data = json_decode(base64_url_decode($payload), true); if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') { error_log('Unknown algorithm. Expected HMAC-SHA256'); return null; } // check sig $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true); if ($sig !== $expected_sig) { error_log('Bad Signed JSON signature!'); return null; } return $data; } function get_facebook_cookie($app_id, $app_secret) { if (!isset($_COOKIE['fbsr_' . $app_id])) return FALSE; $signed_request = parse_signed_request($_COOKIE['fbsr_' . $app_id], $app_secret); // $signed_request should now have most of the old elements $signed_request[uid] = $signed_request[user_id]; // for compatibility if (!is_null($signed_request)) return $signed_request['code']; else return FALSE; } function check_facebook_cookie() { if (isset($_COOKIE['fbsr_' . FACEBOOK_APP_ID])) return TRUE; return FALSE; } function get_access_token($app_id, $app_secret, $cookie) { $access_token_response = @file_get_contents("https://graph.facebook.com/oauth/access_token?client_id=".$app_id."&redirect_uri=&client_secret=".$app_secret."&code=".$cookie); if ($access_token_response) { parse_str($access_token_response); $signed_request['access_token'] = $access_token; $signed_request['expires'] = time() + $expires; return $signed_request['access_token']; } else return FALSE; } function get_facebook_user($access_token) { [email protected]_get_contents('https://graph.facebook.com/me?access_token=' . $access_token); if ($file) { $user = json_decode($file); } else return FALSE; if (isset($user->id)) return $user; else return FALSE; } function facebook_main_function() { global $facebook_logged_in, $facebook_user; $facebook_logged_in=0; $cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_APP_SECRET); if ($cookie) { $access_token=get_access_token(FACEBOOK_APP_ID, FACEBOOK_APP_SECRET, $cookie); if ($access_token) { $facebook_user=get_facebook_user($access_token); if ($facebook_user) $facebook_logged_in=1; else setcookie('fbsr_' . FACEBOOK_APP_ID, '', time()-4000, "/"); } else setcookie('fbsr_' . FACEBOOK_APP_ID, '', time()-4000, "/"); } } function what_to_do_with_facebook_login() { global $found_user_id, $facebook_logged_in, $facebook_user, $registered_user_id; if (!isset($facebook_logged_in)) return FALSE; if ($facebook_logged_in==0) return FALSE; if (!isset($facebook_user->email)) return FALSE; $email=$facebook_user->email; if (strlen($email)<2) return FALSE; if (check_if_email_exists($email)) { return just_login_with_user($found_user_id); } if (!isset($facebook_user->name)) return FALSE; $username=$facebook_user->name; if (strlen($username)<2) return FALSE; $i=1; $busername=$username; while (check_if_username_exists($username)) { $i++; $username=$busername." ".$i; } if (isset($facebook_user->id)) { $avatar='http://graph.facebook.com/'.$facebook_user->id.'/picture'; } return register_user_and_login($username, rand(1000, 1000000), $email, $avatar); } function le_full_url_encode ($url) { $p=strrpos($url, "/"); $d1=substr($url, 0, $p+1); $d2=substr($url, $p+1); return $d1.rawurlencode($d2); } function le_get_mysql_cache ($name, $type, $var, $timeout, $func, $param=NULL) { global $dont_update_mysql_cache; $dont_update_mysql_cache=0; $bvalue=""; if ($type==1) $var=intval($var); if ($type==2) $var=mysql_real_escape_string($var); if ($type==1) $where="cache_variable=".$var; if ($type==2) $where="cache_variable='".$var."'"; $sql = "SELECT cache_value, cache_time FROM phpbb_cache_".$name." WHERE ".$where; if ( !($result = mysql_query($sql)) ) { echo $sql."
".mysql_error(); exit; } if ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row['cache_time']') return $i; if ($in==0 && $c=='<') return $i-1; if ($c=='"' || $c=="'") { if ($enter=='') { $enter=$c; $in=1; } else { if ($enter==$c && substr($buf, $i-1, 1)!="\\") { $in=0; } } } } return FALSE; } function get_xml_tag_name(&$buf, $start=0, $skip_check=0, $lowercase=0) { if ($skip_check==0) { if (!isset($buf)) return ''; if ($buf==FALSE) return ''; if ($buf=='') return ''; $len=strlen($buf); if ($start>=$len) return ''; } $skip_slash=0; if (substr($buf, $start+1, 1)=='/') $skip_slash=1; $mp=0; $p1=strpos($buf, ' ', $start); if ($p1!==FALSE) { if ($mp==0) $mp=$p1; else { if ($p1<$mp) $mp=$p1; } } if ($skip_slash==0) { $p1=strpos($buf, '/', $start); if ($p1!==FALSE) { if ($mp==0) $mp=$p1; else { if ($p1<$mp) $mp=$p1; } } } $p1=strpos($buf, '>', $start); if ($p1!==FALSE) { if ($mp==0) $mp=$p1; else { if ($p1<$mp) $mp=$p1; } } if ($mp==0) return ''; if ($lowercase==0) return substr ($buf, $start+1, $mp-($start+1)); else return strtolower(substr ($buf, $start+1, $mp-($start+1))); } function find_xml_block (&$buf, $tag, $start=0, $skip_check=0, $only_first_tag=0, $end=0) { if ($skip_check==0) { if (!isset($buf)) return FALSE; if ($buf==FALSE) return FALSE; if ($buf=='') return FALSE; $len=strlen($buf); if ($start>=$len) return FALSE; } if ($end==0) { if (isset($len)) $end=$len; else $end=strlen($buf); } $p1=strpos($buf, '<'.$tag, $start); if ($p1===FALSE) { $p1=strpos($buf, '<'.strtoupper($tag), $start); if ($p1===FALSE) return FALSE; } if ($p1>=$end) return FALSE; return find_raw_xml_block ($buf, $p1, 1, $only_first_tag, 1, $tag); } function find_raw_xml_block (&$buf, $start=0, $skip_check=0, $only_first_tag=0, $right_here=0, $what_tag_is_here='', $end=0) { if ($skip_check==0) { if (!isset($buf)) return FALSE; if ($buf==FALSE) return FALSE; if ($buf=='') return FALSE; $len=strlen($buf); if ($start>=$len) return FALSE; } if ($end==0) { if (isset($len)) $end=$len; else $end=strlen($buf); } $data=array(); $level=0; if ($right_here==0) { $p1=strpos($buf, '<', $start); if ($p1===FALSE) return FALSE; } else $p1=$start; if ($p1>=$end) return FALSE; $start=$p1+1; //$p2=strpos($buf, '>', $start); $p2=find_end_of_tag ($buf, $start); if ($p2===FALSE) return FALSE; $data['start']=$p1; $data['start_end']=$p2; $data['have_block']=0; // // eccho "'".substr($buf, $p2-1, 1)."'\n"; exit; if (substr($buf, $p2-1, 1)=='/') $data['slashed']=1; else $data['slashed']=0; /* if (substr($buf, $p1+1, 1)=='?') $data['xml_header']=1; else $data['xml_header']=0; if (substr($buf, $p1+1, 1)=='!') $data['html_header']=1; else $data['html_header']=0; */ if ($only_first_tag==1) { //$data['end']=$data['start_end']; return $data; } $start=$p2+1; $level++; if ($what_tag_is_here=='') $tag=get_xml_tag_name($buf, $p1); else $tag=$what_tag_is_here; // // eccho 'tag:"'.$tag.'"'; exit; while (1) { $p1=strpos($buf, '0) { if ($p==0) $p=$p1; if ($p2>0) if ($p2<$p1) $p=$p2; } if ($p2>0) { if ($p==0) $p=$p2; if ($p1>0) if ($p1<$p2) $p=$p1; } if ($p==0) { //if ($data['end']==0) $data['end']=$data['start_end']; return $data; } if (substr($buf, $p, 2)==" $cdata) { $arr[$i]=get_xml_block ($buf, $cdata); } return $arr; } function find_first_xml_block (&$buf, $start=0, $skip_check=0, $limit=0) { if ($skip_check==0) { if (!isset($buf)) return FALSE; if ($buf==FALSE) return FALSE; if ($buf=='') return FALSE; $len=strlen($buf); if ($start>=$len) return FALSE; } $p1=strpos($buf, '<', $start); if ($p1===FALSE) return FALSE; if ($limit) { if ($p1>=$limit) return FALSE; } return $p1; } function get_xml_tag_attributes ($buf, $start=0) { $attribute_start=0; $attribute_end=0; $value_start=0; $value_end=0; $attribute=''; $value=''; $in=0; $can=0; $len=strlen($buf); $enter=''; $cekam_var=0; $arr=array(); for ($i=$start; $i<$len; $i++) { $c=substr($buf, $i, 1); if ($c==' ') $can=1; if ($can==0 && $c=='>') return $arr; if ($can==1) { if ($in==0) { $empty_attr=0; if ($cekam_var==1 && ($c!='=' && $c!=" ")) { if ($c=='>' || $c=='<') { return $arr; } $empty_attr=1; $cekam_var=0; } if ($empty_attr==1 || ($attribute=='' && $attribute_start==0 && $value_end==0 && $value_start==0 && $attribute_end==0 && $c!=' ' && $c!='>' && $c!='=' && $c!="/")) { $attribute_start=$i; continue; } if ($attribute_start>0 && $value_end==0 && $value_start==0 && $attribute_end==0 && ($c==' ' || $c=='>' || $c=='=')) { $attribute_end=$i; $attribute=substr($buf, $attribute_start, $attribute_end-$attribute_start); $arr[$attribute]=''; // // eccho "attribute='".$attribute."'\n"; $attribute_start=0; $attribute_end=0; $cekam_var=1; if ($c=='=') $cekam_var=2; if ($c=='>') return $arr; continue; } if ($cekam_var==1 && $c=='=') { $cekam_var=2; continue; } if ($cekam_var==2 && $c!='"' && $c!="'" && $c!=" " && $c!="/") { $cekam_var=3; $value_start=$i; // eccho "golo_value_start=".$value_start."\n"; continue; } if ($cekam_var==3 && ($c==' ' || $c=='/' || $c=='>')) { $value_end=$i; // eccho "golo_value_end=".$value_end."\n"; $value=substr($buf, $value_start, $value_end-$value_start); // eccho "golo_value='".$value."'\n"; $arr[$attribute]=$value; $attribute=''; $cekam_var=0; $value_start=0; $value_end=0; if ($c=='>') { // eccho "kraj\n"; return $arr; } continue; } if ($c=='>' || $c=='<') { return $arr; } } if ($c=='"' || $c=="'") { // // eccho $i."=".$c."\n"; if ($enter=='') { $enter=$c; $in=1; $value_start=$i; // // eccho "value_start=".$value_start."\n"; continue; } else { if ($enter==$c && substr($buf, $i-1, 1)!="\\") { $enter=''; $in=0; $value_end=$i; $value=substr($buf, $value_start+1, $value_end-$value_start-1); // // eccho "value='".$value."'\n"; $arr[$attribute]=$value; $attribute=''; $value=''; $cekam_var=0; $value_start=0; $value_end=0; continue; } } } } } // // eccho "kraj2\n"; return $arr; } function get_xml_block_content (&$buf, $data, $skip_check=0) { if ($skip_check==0) { if (!isset($buf)) return ''; if ($buf==FALSE) return ''; if ($buf=='') return ''; if (!isset($data['start_end'])) return ''; if (!isset($data['end_start'])) return ''; } return substr($buf, $data['start_end']+1, ($data['end_start']-$data['start_end'])-1); } function parse_xml (&$buf, &$arr, &$pointers=0, $have_pointers=0, $html=0, $start=0, $end=0, $skip_check=0, $func=NULL, $func_filter='', &$arr_root=NULL, $level=0) { /* if (isset($pointers)) echo "SETOVAN\n"; if (!isset($pointers)) echo "NIJE SETOVAN\n"; if ($pointers) echo "()\n"; if (!$pointers) echo "!\n"; if ($pointers===TRUE) echo "TRUE\n"; if ($pointers===FALSE) echo "FALSE\n"; if ($pointers===NULL) echo "NULL\n"; */ if (!isset($pointers)) { if ($have_pointers) $pointers=array(); } // if (isset($pointers)) if (is_array($pointers)) echo "array - level=".$level."\n"; echo "--------\n"; return; $arr=array(); $ret=FALSE; $i=0; if ($skip_check==0) { if (!isset($buf)) return FALSE; if ($buf==FALSE) return FALSE; if ($buf=='') return FALSE; } if ($arr_root==NULL) $arr_root=&$arr; if ($html) if (!isset($arr_root['last'])) $arr_root['last']=0; if (!isset($arr_root['count'])) $arr_root['count']=0; if ($end==0) $end=strlen($buf); if ($func_filter!='') $func_filter=strtolower($func_filter); while(1) { $ret2=0; $data=find_raw_xml_block ($buf, $start, 0, 0, 0, '', $end); if ($data===FALSE) $ret2=1; if ($ret2==0) if (!isset($data['start_end'])) $ret2=1; if ($ret2==1) { /* if ($i>0 && ($html)) { $data2=find_raw_xml_block ($buf, $start, 0, 0, 0, ''); if ($data2!==FALSE) { if (!isset($arr[$i-1]['after'])) { $x=substr($buf, $start, $data2['start']-$start); if (trim($x)!='') $arr[$i-1]['after']=$x; } else { $x=substr($buf, $start, $data2['start']-$start); if (trim($x)!='') $arr[$i-1]['after2']=$x; } } else { if (!isset($arr[$i-1]['after'])) { $x=substr($buf, $start); if (trim($x)!='') $arr[$i-1]['after']=$x; } else { $x=substr($buf, $start); if (trim($x)!='') $arr[$i-1]['after2']=$x; } } }*/ if ($level==0 && $i>0 && ($html)) { $data2=find_raw_xml_block ($buf, $start, 0, 0, 0, ''); if ($data2===FALSE) { $x=substr($buf, $start); if (trim($x)!='') $arr[$i-1]['after']=$x; } } if ($level==0) { if ($html) if (isset($arr_root['last'])) unset($arr_root['last']); if (isset($arr_root['count'])) unset($arr_root['count']); } return $ret; } $ret=TRUE; if (isset($data['end'])) $start=$data['end']+1; else $start=$data['start_end']+1; if (isset($data['end'])) $start2=$data['end']+1; else $start2=$data['start_end']+1; // if ($data['xml_header']==1) continue; $tagc=get_xml_block ($buf, $data, 1, 0); // eccho "tag='".$tagc."'\n"; $arr[$i]['tag']=get_xml_tag_name($buf, $data['start'], 1); $arr[$i]['tag_lowercase']=strtolower($arr[$i]['tag']); // echo 'count='.$arr_root['count']."\n"; echo 'level='.$level."\n"; echo 'i='.$i."\n"; echo 'tag='.$arr[$i]['tag']."\n\n"; $arr[$i]['id']=$arr_root['count']; $arr[$i]['level']=$level; $arr[$i]['slashed']=$data['slashed']; if ($have_pointers) if (is_array($pointers)) $pointers[$arr_root['count']]=&$arr[$i]; $arr_root['count']++; $attr=get_xml_tag_attributes ($buf, $data['start']); if (count($attr)>0) $arr[$i]['attributes']=$attr; //echo $arr[$i]['tag_lowercase']."\n"; if ($html) { if ($arr_root['last']<$data['start']) { $x=substr($buf, $arr_root['last'], $data['start']-$arr_root['last']); if (trim($x)!='') $arr[$i]['before']=$x; $arr_root['last']=$data['start']; } } if (isset($data['end_start'])) { $arr[$i]['block']=1; $arr[$i]['content']=get_xml_block_content ($buf, $data, 1); // eccho "content='".$content."'\n"; /* $ima=find_first_xml_block ($buf, $data['start_end']+1, 1); if ($ima!==FALSE) { $ok=0; if ($ima==$data['end_start']) { $ima=find_first_xml_block ($buf, $data['end']+1, 1); if ($ima!==FALSE) $ok=1; } if ($ok==1) { $arr[$i]['after']=substr($buf, $data['end']+1, $ima-($data['end']+1)); $arr_root['last']=$data['end']+1; } else { if ($ima>$data['start_end']+1) { $arr[$i]['after']=substr($buf, $data['start_end']+1, $ima-($data['start_end']+1)); $arr_root['last']=$ima; } // } // $arr[$i]['sub']=array(); } */ $ima=find_first_xml_block ($buf, $data['start_end']+1, 1, $data['end_start']); if ($html) { if ($ima>$data['start_end']+1) { $x=substr($buf, $data['start_end']+1, $ima-($data['start_end']+1)); if (trim($x)!='') $arr[$i]['after_in']=$x; $arr_root['last']=$ima; } } if ($ima!==FALSE) parse_xml($buf, $arr[$i]['sub'], $pointers, $have_pointers, $html, $data['start_end']+1, $data['end_start'], 1, $func, $func_filter, $arr_root, $level+1); if ($html) $arr_root['last']=$data['end']+1; if ($html) { $ima=find_first_xml_block ($buf, $data['end']+1, 1); if ($ima!==FALSE) { $x=substr($buf, $data['end']+1, $ima-($data['end']+1)); if (trim($x)!='') $arr[$i]['after']=$x; $arr_root['last']=$ima+1; } } } else { $arr[$i]['block']=0; if ($html) $arr_root['last']=$data['start_end']+1; if ($html) { $ima=find_first_xml_block ($buf, $data['start_end']+1, 1); if ($ima!==FALSE) { if ($ima>$data['start_end']+1) { $x=substr($buf, $data['start_end']+1, $ima-($data['start_end']+1)); if (trim($x)!='') $arr[$i]['after']=$x; $arr_root['last']=$ima; } } //$arr_root['last']=$data['start_end']+1; } } if ($func!=NULL) { $ok=0; if ($func_filter=='') $ok=1; else { if ($arr[$i]['tag_lowercase']==$func_filter) $ok=1; } if ($ok==1) call_user_func($func, $arr[$i]); } $i++; } return $ret; } function foreach_xml_tag (&$parsed_xml, $tag, $func, $param=FALSE, $lowercase=0) { // foreach ($parsed_xml as $i => $data) // { $count=count($parsed_xml); for ($i=0; $i<$count; $i++) { $p = &$parsed_xml[$i]; if ($lowercase==1) { if ($parsed_xml[$i]['tag_lowercase']==$tag) call_user_func($func, $p, $param); } else { if ($parsed_xml[$i]['tag']==$tag) call_user_func($func, $p, $param); } if (isset($parsed_xml[$i]['sub'])) foreach_xml_tag ($parsed_xml[$i]['sub'], $tag, $func, $param, $lowercase); } } function foreach_xml_items (&$parsed_xml, $tag, $func) { foreach_xml_tag ($parsed_xml, $tag, 'foreach_xml_items_cb', $func); } function foreach_xml_items_cb (&$data, $param=FALSE) { $arr=array(); $i=0; if (isset($data['sub'])) { foreach ($data['sub'] as $i => $data2) { // if ($data2['tag_lowercase']=='sifra_alfa3') $kurs['valuta']=$data2['content']; $arr[$data2['tag']]=$data2['content']; } call_user_func($param, $arr); } } class my_xml { var $buffer; var $data; var $parsed; var $have_pointers; var $pointers; var $html; var $func; var $func_filter; function __construct(&$buf='', $have_pointers=1, $html=1, $func=NULL, $func_filter='') { $this->buffer=$buf; $this->data=array(); $this->parsed=FALSE; $this->pointers=array(); $this->have_pointers=$have_pointers; $this->html=$html; $this->func=$func; $this->func_filter=$func_filter; if ($buf=='') return; $this->parse(); } function __destruct() { unset($this->buffer); unset($this->data); unset($this->pointers); } function set_buffer(&$buf) { $this->buffer=$buf; } function clear() { $this->buffer=''; $this->parsed=FALSE; $this->data=array(); $this->pointers=array(); } function parse(&$buf='') { if ($buf!='') $this->buffer=$buf; $this->data=array(); $this->parsed=FALSE; $this->pointers=array(); $ret = parse_xml ($this->buffer, $this->data, $this->pointers, $this->have_pointers, $this->html=1, 0, 0, 0, $this->func, $this->func_filter); if ($ret) { $this->parsed=TRUE; } return $ret; } } ?>