require_once('.../wp/wp-load.php'); function get_random_js_array($images){ $js_keys=array(); foreach($images as $category => $image){ foreach ($image as $key => $value){ $js_keys[]=$key; } } $tmp_arr=range(0,count($js_keys)-1); srand((float)microtime()*1000000); shuffle($tmp_arr); array_splice($tmp_arr,7,count($js_keys)); $js_keys_to_show=array(); foreach ($tmp_arr as $index){ $js_keys_to_show[]=$js_keys[$index]; } $result=''; $temp=''; $i=0; foreach ($js_keys_to_show as $js_key){ if ($i==0) $temp.='"'.$js_key.'"'; else $temp.=', "'.$js_key.'"'; $i++; } $result.='photospercat[\'random\']=['.$temp.'];'; return($result); } function get_images_per_category_js_array($images){ $cats=array_keys($images); $bot_urls_per_cat=array(); foreach ($cats as $cat){ $bot_urls_per_cat[$cat]=array_keys($images[$cat]); } $result='photospercat=new Array();'; foreach ($bot_urls_per_cat as $cat => $urls){ $temp=''; $i=0; foreach ($urls as $url){ if ($i==0) $temp.='"'.$url.'"'; else $temp.=', "'.$url.'"'; $i++; } $result.='photospercat[\''.$cat.'\']=['.$temp.'];'; } return ($result); } function output_images_js_array($images){ $image_fields=array_keys($images[key($images)][key($images[key($images)])]); $var_definitions=''; foreach ($image_fields as $index => $field_name){ $var_definitions.='var '.$field_name.'='.$index.';'; } echo $var_definitions; echo 'images_array = {'; $fields_to_exclude=array('post_content'); $number_fields=array('photo_long_dec','photo_lat_dec'); $not_first_photo=false; foreach ($images as $category => $photo_values){ foreach ($photo_values as $js_key => $values) { if ($not_first_photo){ echo ','; }else{ $not_first_photo=true; } echo $js_key.':['; $not_first_photo_value=false; foreach ($values as $field_name => $field_value) { if (!(in_array($field_name,$number_fields))){ $delimiter='"'; }else{ $delimiter=''; } if (!(in_array($field_name,$fields_to_exclude))){ if ($not_first_photo_value){ echo ','; }else{ $not_first_photo_value=true; } echo $delimiter; _e($field_value); echo $delimiter; }else{ echo ','; echo '"x"'; } } echo ']'; } } echo '};'; } function get_select_text(){ $selecttextes=htmlentities('Llévame a...'); $selecttextca=htmlentities('Porta\'m a...'); $selecttexten=htmlentities('Take me to...'); $selecttext=''.$selecttextes.''.$selecttexten.''.$selecttextca.''; return($selecttext); } function get_images_array(){ global $wpdb; $my_sql="SELECT ID, js_key, post_content, post_title, post_name, guid, photo_url, photo_date, photo_long_dec, photo_lat_dec, photo_category, photo_filename, photo_pre_th_url, photo_bot_th_url, photo_big_th_url FROM $wpdb->posts WHERE post_category= 27"; $results = $wpdb->get_results($my_sql, ARRAY_A); $images=array(); foreach ($results as $row) { $cat=$row['photo_category']; $jskey=$row['js_key']; $images[$cat][$jskey]=$row; } return($images); } function get_add_marker_code($row,$base_url){ $pre_th=$base_url.$row['photo_category'].'/th/pre_'.$row['photo_filename']; $name=$row['photo_category'].'_'.$row['photo_filename']; $name=str_replace(' ','_',$name); $name=str_replace('.','_',$name); $result='var pointSW = new GLatLng('.$row['photo_lat_dec'].'-latBox ,'.$row['photo_long_dec'].'-longBox );'; $result.='var pointNE = new GLatLng('.$row['photo_lat_dec'].'+latBox ,'.$row['photo_long_dec'].'+longBox );'; $result.='addPhotoToMap(map, pointNE,pointSW, \''.$pre_th.'\');'; $result.='addBorderToPhoto(map,pointNE,pointSW, \''.$pre_th.'\',\''.$name.'\');'; return($result); } function get_bot_anchor($row,$base_url){ $name=$row['photo_category'].'_'.$row['photo_filename']; $name=str_replace(' ','_',$name); $name=str_replace('.','_',$name); $result=""; $bot_th=$base_url.$row['photo_category'].'/th/bot_'.$row['photo_filename']; $result.=""; $result.=""; return($result); } function get_sql($file_values,$base_url){ $base_prefix='photos/img/'; $base_img_url=$base_url.$base_prefix; $post_author=1; $post_date=date('Y-m-d H:i:s'); $post_date_gmt=date('Y-m-d H:i:s',time () - 3600); $post_title=''.$file_values['complete_filename'].''.$file_values['complete_filename'].''.$file_values['complete_filename'].''; $post_category=27; $post_excerpt=''; $post_status='publish'; $comment_status='open'; $ping_status='closed'; $post_password=''; $post_name=str_replace('.','',str_replace(' ','-',strtolower($file_values['complete_filename']))); $to_ping=''; $pinged=''; $post_modified=''; $post_modified_gmt=''; $post_content_filtered=''; $post_parent=0; $guid=$base_url.$post_name; $menu_order=0; $post_type='page'; $post_mime_type=''; $comment_count=0; $robotsmeta='NULL'; $photo_url=$base_img_url.$file_values['category'].'/'.htmlentities($file_values['complete_filename']); $photo_date=$file_values['year'].'-'.$file_values['month'].'-'.$file_values['day'].' '.$file_values['hour'].':'.$file_values['minute'].':'.$file_values['second']; $photo_long_dec=$file_values['long_dec']; $photo_lat_dec=$file_values['lat_dec']; $photo_category=$file_values['category']; $photo_filename=$file_values['complete_filename']; $photo_pre_th_url=$base_url.$base_prefix.$file_values['category'].'/th/pre_'.$file_values['complete_filename']; $photo_bot_th_url=$base_url.$base_prefix.$file_values['category'].'/th/bot_'.$file_values['complete_filename']; $photo_big_th_url=$base_url.$base_prefix.$file_values['category'].'/th/big_'.$file_values['complete_filename']; $tmpfilename=str_replace('.','_',$file_values['complete_filename']); $tmpfilename=str_replace(' ','_',$tmpfilename); $js_key=$file_values['category'].'_'.$tmpfilename; //$post_content=''.$file_values['complete_filename'].' CAT catala'; //$post_content.=''.$file_values['complete_filename'].' esp esp'; //$post_content.=''.$file_values['complete_filename'].' eng eng'; $post_content=''; $sql='INSERT INTO `wp_posts` (`post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_category`,'; $sql.='`post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`,'; $sql.='`post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`,'; $sql.='`post_mime_type`, `comment_count`, `robotsmeta`,`photo_url`,`photo_date`,`photo_long_dec`,`photo_lat_dec`,`photo_category`,`photo_filename`,`js_key`,`photo_pre_th_url`,`photo_bot_th_url`,`photo_big_th_url`) '; $sql.='VALUES('.$post_author.',\''.$post_date.'\',\''.$post_date_gmt.'\',\''.$post_content.'\',\''.$post_title.'\','.$post_category.',\''.$post_excerpt.'\',\''.$post_status.'\','; $sql.='\''.$comment_status.'\',\''.$ping_status.'\',\''.$post_password.'\',\''.$post_name.'\',\''.$to_ping.'\',\''.$pinged.'\',\''.$post_modified.'\',\''.$post_modified_gmt.'\','; $sql.='\''.$post_content_filtered.'\','.$post_parent.',\''.$guid.'\','.$menu_order.',\''.$post_type.'\',\''.$post_mime_type.'\','.$comment_count.','.$robotsmeta.',\''.$photo_url.'\','; $sql.='\''.$photo_date.'\','.$photo_long_dec.','.$photo_lat_dec.',\''.$photo_category.'\',\''.$photo_filename.'\',\''.$js_key.'\',\''.$photo_pre_th_url.'\',\''.$photo_bot_th_url.'\',\''.$photo_big_th_url.'\');'; return $sql; } function get_dirs_array($base_dir_path){ $dirs_array=array(); if ($dir_handle = opendir($base_dir_path)){ while (($file=readdir($dir_handle))!==false){ if (($file!='.')&&($file!='..')){ if(filetype($base_dir_path.$file)=='dir'){ $dirs_array[]=$base_dir_path.$file; } } } closedir($dir_handle); } return($dirs_array); } function get_files_assoc_array($dirs_array){ $dirs_assoc_array=array(); while(NULL!==($dir=array_pop($dirs_array))){ if ($dir_handle = opendir($dir)){ $category=substr($dir,strrpos($dir,'/')+1); $files=array(); while (($file=readdir($dir_handle))!==false){ if (($file!='.')&&($file!='..')){ $file_path=$dir.'/'.$file; if(filetype($file_path)=='file'){ if (strtolower(substr($file_path,-3))=='jpg'){ $files[substr($file_path,strrpos($file_path,'/')+1)]=get_file_data($file_path); } } } } $dirs_assoc_array[$category]=$files; } closedir($dir_handle); } return($dirs_assoc_array); } function get_file_data($path){ $file_data=array(); $file_data['path']=$path; $file_data['complete_filename']=substr($path,strrpos($path,'/')+1); $file_data['ext']=substr($path,-3); $file_data['filename']=substr($file_data['complete_filename'],0,-4); $file_data['directory']=substr($path,0,strrpos($path,'/')+1); $tmp=substr($path,0,strrpos($path,'/')); $file_data['category']=substr($tmp,strrpos($tmp,'/')+1); $file_data=set_exif_data($path,$file_data); return ($file_data); } function set_exif_data($path,$data_array){ $raw_exif=exif_read_data($path, 0, true); $data_array['hour']=substr(($raw_exif['EXIF']['DateTimeOriginal']),11,2); $data_array['minute']=substr(($raw_exif['EXIF']['DateTimeOriginal']),14,2); $data_array['second']=substr(($raw_exif['EXIF']['DateTimeOriginal']),17,2); $data_array['year']=substr(($raw_exif['EXIF']['DateTimeOriginal']),0,4); $data_array['month']=substr(($raw_exif['EXIF']['DateTimeOriginal']),5,2); $data_array['day']=substr(($raw_exif['EXIF']['DateTimeOriginal']),8,2); $data_array=set_gps_data($raw_exif,$data_array); return($data_array); } function set_gps_data($raw_exif,$data_array) { $deg = convert_fraction_to_decimal($raw_exif['GPS']['GPSLatitude'][0]); $min = convert_fraction_to_decimal($raw_exif['GPS']['GPSLatitude'][1]); $sec = convert_fraction_to_decimal($raw_exif['GPS']['GPSLatitude'][2]); $data_array['lat_ref'] = $raw_exif['GPS']['GPSLatitudeRef']; $data_array['lat_deg']=$deg; $data_array['lat_min']=$min; $data_array['lat_sec']=$sec; $data_array['lat_dec'] = exif_convert_deg_min_sec_to_DD($deg, $min, $sec); if ($data_array['lat_ref'] == 'S') {$data_array['lat_dec'] *= -1;}; $deg = convert_fraction_to_decimal($raw_exif['GPS']['GPSLongitude'][0]); $min = convert_fraction_to_decimal($raw_exif['GPS']['GPSLongitude'][1]); $sec = convert_fraction_to_decimal($raw_exif['GPS']['GPSLongitude'][2]); $data_array['long_ref'] = $raw_exif['GPS']['GPSLongitudeRef']; $data_array['long_deg']=$deg; $data_array['long_min']=$min; $data_array['long_sec']=$sec; $data_array['long_dec'] = exif_convert_deg_min_sec_to_DD($deg, $min, $sec); if ($data_array['long_ref'] == 'W') {$data_array['long_dec'] *= -1;}; return($data_array); } function output_link_to_google_maps($exif_data) { echo "View location in Google Maps"; } function convert_fraction_to_decimal($fraction) { if ( !isset ( $fraction ) ) return 0; $dividerPosition = strpos ( $fraction, '/' ); if ( $dividerPosition === false ) return $fraction; return substr ( $fraction, 0, $dividerPosition ) / substr ( $fraction, $dividerPosition + 1 ); } function exif_convert_deg_min_sec_to_DD($deg, $min, $sec) { $dec_min = ($min*60.0 + $sec)/60.0; $result = ($deg*60.0 + $dec_min)/60.0; return $deg + $min/60 + $sec/3600; }