Jump to content

herghost

Members
  • Posts

    699
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

herghost's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. Got it! <?php /* Plugin Name: POstHotel Plugin URI: http://www.hotelwifiscore.com Description: Creates post from supplied data Version: 1 Author: davegrix Author URI: http://www.hotelwifiscore.com */ require_once('wp-load.php'); class wm_mypost { var $post_title; var $post_category; } function post_a_newhotel($title, $post_cat) { if (class_exists('wm_mypost')) { $myclass = new wm_mypost(); } else { class wm_mypost { var $post_title; var $post_category; } } echo $title; // initialize post object $wm_mypost = new wm_mypost(); // fill object $wm_mypost->post_title = $title; $wm_mypost->post_category = $post_cat; $wm_mypost->post_status = 'publish'; $result = utf8_encode_deep($wm_mypost); array_walk_recursive($wm_mypost, function (&$value) { $value = htmlspecialchars(html_entity_decode($value, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8'); } ); print_r($result); wp_insert_post($wm_mypost); } function utf8_encode_deep(&$input) { if (is_string($input)) { $input = utf8_encode($input); } else if (is_array($input)) { foreach ($input as &$value) { utf8_encode_deep($value); } unset($value); } else if (is_object($input)) { $vars = array_keys(get_object_vars($input)); foreach ($vars as $var) { utf8_encode_deep($input->$var); } } }
  2. Hi, The page is just called from the browser directly, it then gets the details from one table (echo's here correctly) gets passed to the function to insert new post (echo s here correctly as well!) Then gets sent to the database in the WordPress insert_post function, this is where I am sure something dodgy is happening :-) The tables all have the same encoding
  3. It's just the question mark in replace of the ô which is the issue, there are no HTML declarations as its a php script. Utf8_bin and general should cover these characters as they are fine in one table, its just when it's moved, they are both utf8.
  4. Hi all I am having problems with french characters when using a custom function to upload posts from a database into wordpress Firstly here is my code: //This gets the values that is sent to the class to create post <?php require_once('wp-content/plugins/PostAdder/index.php'); try { $host = 'localhost'; //$dbname = 'wordpress'; $dbname = 'HotelWifi'; $user = 'root'; $pass = ''; $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8') ); } catch(PDOException $e) { echo $e->getMessage(); } $STH = $DBH->query('select * from activepropertylist'); $STH->setFetchMode(PDO::FETCH_ASSOC); while($row = $STH->fetch()) { $hotelname = ucwords(utf8_decode($row['Name'])); $city = $row['City']; $STH1 = $DBH->query('select * from wp_terms WHERE name = "' . $city . '"'); $STH1->setFetchMode(PDO::FETCH_ASSOC); while($row1 = $STH1->fetch()) { $cat = $row1['term_id']; } $tcat = array($cat); post_a_newhotel($hotelname, $tcat) ; } ?> // this is the function that fills the class and calls the wp_insert_post function <?php /* Plugin Name: POstHotel Plugin URI: http://www.hotelwifiscore.com Description: Creates post from supplied data Version: 1 Author: davegrix Author URI: http://www.hotelwifiscore.com */ require_once('wp-load.php'); class wm_mypost { var $post_title; var $post_category; } function post_a_newhotel($title, $post_cat) { if (class_exists('wm_mypost')) { $myclass = new wm_mypost(); } else { class wm_mypost { var $post_title; var $post_category; } } // initialize post object $wm_mypost = new wm_mypost(); // fill object $wm_mypost->post_title = utf8_decode($title); $wm_mypost->post_category = $post_cat; $wm_mypost->post_status = 'publish'; array_walk_recursive($wm_mypost, function (&$value) { $value = htmlspecialchars(html_entity_decode($value, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8'); } ); wp_insert_post($wm_mypost); } ?> The string I am having problems with is 'Best Western Premier Hôtel L'Aristocrate' The result stored using the above is: Best Western Premier H?tel L'Aristocrate database is set to utf8_general_ci Can anyone shine any light on what to do?
  5. Apologies, some of it appears to have been stripped, please see below: <?PHP ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); //use latest minorRev 14 $url ='http://api.ean.com/ean-services/rs/hotel/v3/list?minorRev=14'; $url .= 'removed'; $url .= '&cid=55505'; $url .= '&locale=en_US&city=Dallas&stateProvinceCode=TX&countryCode=US&numberOfResults=3'; $url .= '&searchRadius=50'; //using the cache returns results much faster $url .= '&supplierCacheTolerance=MED_ENHANCED'; //dates and occupancy //$url .='&arrivalDate=19/02/2014&departureDate=09/05/2012&room1=2'; $header[] = "Accept: application/json"; $header[] = "Accept-Encoding: gzip"; $ch = curl_init(); curl_setopt( $ch, CURLOPT_HTTPHEADER, $header ); curl_setopt($ch,CURLOPT_ENCODING , "gzip"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt( $ch, CURLOPT_URL, $url ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); $response = json_decode(curl_exec($ch)); $var = '@activePropertyCount'; //foreach($response as $data) // { // $mycount = $data->HotelList->$var; // // } $mycount = 1; foreach($response as $data) { try { $host = 'localhost'; $dbname = 'HotelWifi'; $user = 'root'; $pass = 'removed'; # MySQL with PDO_MYSQL $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); } catch(PDOException $e) { echo $e->getMessage(); } //print_r($data->HotelList->HotelSummary[$mycount-1]->hotelId); //print_r($data->HotelList->HotelSummary[$mycount-1]); $STH = $DBH->prepare("INSERT INTO HotelData (HotelID, HotelName, HotelCity, HotelCountry, LowRate, Long, Lat) values (:id,:name,:city,:country,:low,:long,:lat)"); $HotelID = $data->HotelList->HotelSummary[$mycount-1]->hotelId; $HotelName = $data->HotelList->HotelSummary[$mycount-1]->name; $HotelCity = $data->HotelList->HotelSummary[$mycount-1]->city; $HotelCountry = $data->HotelList->HotelSummary[$mycount-1]->countryCode; $LowRate = $data->HotelList->HotelSummary[$mycount-1]->lowRate; $Long = $data->HotelList->HotelSummary[$mycount-1]->longitude; $Lat = $data->HotelList->HotelSummary[$mycount-1]->latitude; $STH->bindParam(":id", $HotelID); $STH->bindParam(":name", $HotelName); $STH->bindParam(":city", $HotelCity); $STH->bindParam(":country", $HotelCountry); $STH->bindParam(":low", $LowRate); $STH->bindParam(":long", $Long); $STH->bindParam(":lat", $Lat); echo $HotelID . " " . $HotelName . " " . $HotelCity . " " . $HotelCountry . " " . $LowRate . " " . $Long . " " . $Lat; try { $STH->execute(); print_r($STH); } catch(PDOException $e) { echo $e->getMessage(); } } ?> </body> </html>
  6. Hi Guys Any ideas why nothing is being stored in my database? I have echoed out all the variables and they appear fine, likewise I am not getting any PDO errors from the try/catch, just nothing is being stored! <?PHP //for ($x=0; $x <=9; $x++) //{ // print_r($url); // print_r(" "); // print_r(""); // print_r ($response); // print_r(""); //} $var = '@activePropertyCount'; foreach($response as $data) { $mycount = $data->HotelList->$var; } // while( $mycount > -1) // { $mycount = 1; foreach($response as $data) { try { $host = 'localhost'; $dbname = 'HotelWifi'; $user = 'removed'; $pass = 'removed'; # MySQL with PDO_MYSQL $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); } catch(PDOException $e) { echo $e->getMessage(); } //print_r($data->HotelList->HotelSummary[$mycount-1]->hotelId); //print_r($data->HotelList->HotelSummary[$mycount-1]); $STH = $DBH->prepare("INSERT INTO HotelData (HotelID, HotelName, HotelCity, HotelCountry, LowRate, Long, Lat) values (:id,:name,:city,:country,:low,:long,:lat)"); $HotelID = $data->HotelList->HotelSummary[$mycount-1]->hotelId; $HotelName = $data->HotelList->HotelSummary[$mycount-1]->name; $HotelCity = $data->HotelList->HotelSummary[$mycount-1]->city; $HotelCountry = $data->HotelList->HotelSummary[$mycount-1]->countryCode; $LowRate = $data->HotelList->HotelSummary[$mycount-1]->lowRate; $Long = $data->HotelList->HotelSummary[$mycount-1]->longitude; $Lat = $data->HotelList->HotelSummary[$mycount-1]->latitude; $STH->bindParam(":id", $HotelID); $STH->bindParam(":name", $HotelName); $STH->bindParam(":city", $HotelCity); $STH->bindParam(":country", $HotelCountry); $STH->bindParam(":low", $LowRate); $STH->bindParam(":long", $Long); $STH->bindParam(":lat", $Lat); echo $HotelID . " " . $HotelName . " " . $HotelCity . " " . $HotelCountry . " " . $LowRate . " " . $Long . " " . $Lat; try { $STH->execute(); print_r($STH); } catch(PDOException $e) { echo $e->getMessage(); } } // // // // // // print_r($data->HotelList); // // // $i = $i + 1; ?>
  7. HI guys I am having some issues getting the results I want from a query. Basically I have two tables. To keep things short and sweet ill use made up values table a contains the field ID,Week table b contains ID and type Type can be either a 1 or a 0 and and the ID will match table A. Table b can contain more than one entry for the same ID on table A with different types. What I am trying to do is return all the ID's in table B that only contain a type of 0, for a specific week in table a. So if table B contains: ID Type 1 1 1 0 2 0 2 0 3 1 3 1 I would only need to return ID 2 I have tried something like this select a.id, b.id from b inner join a on b.id = a.id where a.week = '22' and b.type = 0 This issue is that it will return ID 1 and 2 as ID 1 contains a 0? I hope this is clear enough! Thanks for any pointers or help
  8. Hi everyone I am having some problems with a query and I am wondering if it is even possible with sql! Basically I have two tables, a and b, which contain columns 1,2 & 3 What I am trying to do is copy values 2 and 3 from table 2 into table 1 columns 2 and 3 and set my own variable for column 1. Is this possible or is select/insert only possible if you are copying an exact match from one table to another?
  9. Hi Guys I am trying to implement the rpxnow / janrain social login into my site. I am having issues in returning the providername when the user logs in with facebook. Basically the results from janrain are returned as an array. to get the providerid from Google I use this: foreach ($auth_info as $key) { } $provider = $key['providerName']; which correctly returns "Google", however when the user try's to login with facebook the result is "f" where the array output is "Facebook". Using the demo file for outputting the array, the structure looks like this for google: auth_info: array(2) { ["stat"]=> string(2) "ok" ["profile"]=> array(10) { ["url"]=> string(45) "https://plus.google.com/*deleted*" ["preferredUsername"]=> string(10) "*deleted*" ["email"]=> string(20) "*deleted*" ["name"]=> array(3) { ["givenName"]=> string(4) "Dave" ["familyName"]=> string(4) "*deleted*" ["formatted"]=> string(9) "*deleted*" } ["photo"]=> string(169) "http://www.google.com/ig/c/photos/public/*deleted*" ["displayName"]=> string(9) "*deleted*" ["identifier"]=> string(53) "https://www.google.com/profiles/*deleted*" ["verifiedEmail"]=> string(20) "*deleted*" ["providerName"]=> string(6) "Google" ["googleUserId"]=> string(21) "*deleted*" } } and like this for facebook auth_info: array(3) { ["stat"]=> string(2) "ok" ["profile"]=> array(12) { ["providerName"]=> string( "Facebook" ["identifier"]=> string(48) "http://www.facebook.com/profile.php?id=*deleted*" ["preferredUsername"]=> string( "*deleted*" ["displayName"]=> string(9) "*deleted*" ["email"]=> string(20) "*deleted*" ["name"]=> array(3) { ["formatted"]=> string(9) "*deleted*" ["givenName"]=> string(4) "Dave" ["familyName"]=> string(4) "*deleted*" } ["url"]=> string(33) "http://www.facebook.com/*deleted*" ["photo"]=> string(55) "https://graph.facebook.com/*deleted*/picture?type=large" ["utcOffset"]=> string(5) "01:00" ["address"]=> array(2) { ["formatted"]=> string(16) "*deleted*" ["type"]=> string(15) "currentLocation" } ["gender"]=> string(4) "male" ["verifiedEmail"]=> string(20) "*deleted*" } ["limited_data"]=> string(5) "false" } I also tried to use $provider = ['profile']['providerName'] however this returns an error : PHP Fatal error: Cannot use string offset as an array How can I correctly return "Facebook" Thanks
  10. Hi Jesirose Many thanks for your response, firebug is fantastic! fixed script - I was forgetting to update my html content for the span div <script type="text/javascript"> $(document).ready(function() { $("#username").change(function() { var username = $("#username").val(); var msgbox = $("#status"); if(username.length < 6) { $("#status").html('<img src="img/cancel.png" /> Username must be at least 6 characters'); $('#username').css('background-image', 'url("../forms/img/cancel.png")'); document.getElementById("registerNew").disabled=true; } if(username.length > 5) { $("#status").html('<img src="img/loading.gif" /> ...Checking Username'); $('#username').css('background-image', 'url("../forms/img/asterisk_orange.png")'); document.getElementById("registerNew").disabled=true; jQuery.ajax({ type: "POST", url: "http://localhost/logtrav/forms/usernamechecker.php", data: 'username='+ username, cache: false, success: function(response) { if(response == 0) { $('#username').css('background-image', 'url("../forms/img/tick.png")'); document.getElementById("registerNew").disabled=false; $("#status").html(''); } else{ $('#username').css('background-image', 'url("../forms/img/cancel.png")'); $("#status").html('Username already in use'); } } }); } }); }); </script>
  11. Hi Guys This is my first attempt at an ajax script, so please be gentle! Basically my script is meant to check a db to see if the username exists, however it just hangs on the loading.gif <script type="text/javascript"> $(document).ready(function() { $("#username").change(function() { var username = $("#username").val(); var msgbox = $("#status"); if(username.length < 6) { $("#status").html('<img src="img/cancel.png" /> Username must be at least 6 characters'); $('#username').css('background-image', 'url("../forms/img/cancel.png")'); document.getElementById("registerNew").disabled=true; } if(username.length > 5) { $("#status").html('<img src="img/loading.gif" /> ...Checking Username'); $('#username').css('background-image', 'url("../forms/img/asterisk_orange.png")'); document.getElementById("registerNew").disabled=true; jQuery.ajax({ type: "POST", url: "usernamechecker.php", data: 'username='+ username, cache: false, success: function(response) { if(response = 0) { $('#username').css('background-image', 'url("../forms/img/tick.png")'); document.getElementById("registerNew").disabled=false; } else{ $('#username').css('background-image', 'url("../forms/img/cancel.png") Username already in use'); } } }); } }); }); </script> usernamechecker.php <?php include('../class/class.dbconnect.inc.php'); $username = trim(strtolower($_POST['username'])); $username = mysql_real_escape_string($username); $db = new dbconnect(); $db->connect(); $db->select('tbl_users','username','username="'.$username.'"'); $amount = count($db->getResult()); echo $amount; ?> If I set a variable username in the checker manually and call the page I get the correct response from the database. My table (tbl_users) id, email, username, password 1, test@test.com, testuser, sha1pass Can anyone point me in the direction of what I am doing wrong?
  12. Wow, thats 3 hours wasted ;-) Many Thanks
  13. Hi Guys Firstly apologies if this is in the wrong section, my required output is php! Basically I have the following jQuery which once a submit button is clicked my form opens in a fancybox window. What I am trying to achieve is basically just got the POST values of two input boxes, name & email <script type="text/javascript"> $(document).ready(function(){ $('#register').submit(function() { var url = $(this).attr("action") + "?" + $(this).serialize(); $.fancybox({ href: url, centerOnScroll: true, width: 450, 'type': 'iframe' }); return false; }); }); I have had a read through the .serialize docs but dont really understand how to get the results out into php variables.
  14. Hi Guys Thanks for all your responses, the data is coming from an API into the minecraft extension bukkit, my actual results from query display as: "result": "success", "source": "getDirectory", "success": ["plugins/Essentials.jar", "plugins/Essentials/", "plugins/Essentials/config.yml", "plugins/Essentials/items.csv", "plugins/Essentials/upgrades-done.yml", "plugins/Essentials/warps/", "plugins/Essentials/worth.yml", "plugins/JSONAPI.jar", "plugins/JSONAPI/", "plugins/JSONAPI/config.yml", "plugins/JSONAPI/config_rtk.yml", "plugins/JSONAPI/methods.json", "plugins/JSONAPI/methods/", "plugins/JSONAPI/methods/permissions.json", "plugins/JSONAPI/methods/readme.txt", "plugins/JSONAPI/methods/remotetoolkit.json", "plugins/JSONAPI/methods/system.json", "plugins/JSONAPI/methods/world.json", "plugins/MinecraftRKitPlugin.jar", "plugins/PluginMetrics/", "plugins/PluginMetrics/config.yml"] } So all I am trying to do is extract the results that end in .jar and ignore the rest so I can have a list of installed plugins.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.