Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

CB auto action php code

  • ThePiston
  • ThePiston
  • OFFLINE
  • Posts: 334
  • Thanks: 26
  • Karma: 1
11 years 6 months ago #225826 by ThePiston
CB auto action php code was created by ThePiston
Is this valid code to put into php (eval)?
Code:
$query = " SELECT id ,cb_pofficename ,cb_paddress1 ,cb_paddress2 ,cb_pcity ,cb_pstate ,cb_pzip ,cb_lat1st ,cb_long1st ,cb_sofficename ,cb_saddress1 ,cb_saddress2 ,cb_scity ,cb_sstate ,cb_szip ,cb_lat2nd ,cb_long2nd ,cb_tofficename ,cb_taddress1 ,cb_taddress2 ,cb_tcity ,cb_tstate ,cb_tzip ,cb_lat3rd ,cb_long3rd FROM `jos_comprofiler` a WHERE cb_findinsearch = 'Yes' AND id = [user_id] "; $rs = mysql_query ( $query ); $arr = array (); $count = 0; while ( $obj = mysql_fetch_object ( $rs ) ) { $arr[]=$obj; } foreach($arr as $a){ if(strlen($a->cb_paddress1)>3){ sleep(.3); $newlatLong=getLatLong($a->cb_paddress1 . ', ' . (strlen ( $a->cb_paddress2 ) ? $a->cb_paddress2.', ' : '') . $a->cb_pcity .', ' . $a->cb_pstate. ',+' . $a->cb_pzip.' USA'); $latitude1 =$newlatLong['lat']; $longitude1 = $newlatLong['long']; if($latitude1&&$longitude1 ){ $count++; $query =" UPDATE jos_comprofiler SET cb_lat1st ='$latitude1' ,cb_long1st ='$longitude1' WHERE id='".$a->id."' "; $rs = mysql_query ( $query ); echo '<i>ADDRESS UPDATED '.$count.' :</i>&nbsp;&nbsp; <small>'.str_replace ( " ", "+", $a->cb_paddress1) . ',+' . (strlen ( $a->cb_paddress2) ? str_replace ( " ", "+,", $a->cb_paddress2 ) : '') . ',+' . str_replace ( " ", "+", $a->cb_pcity ) . ',+' . $a->cb_pstate. ',+' . $a->cb_pzip. ',+USA</small> &nbsp;&nbsp;&nbsp; <b>'.$latitude1.':'.$longitude1 .'</b><br/>'; } } if(strlen($a->cb_saddress1)>3){ sleep(.3); $newlatLong=getLatLong($a->cb_saddress1 . ', ' . (strlen ( $a->cb_saddress2 ) ? $a->cb_saddress2.', ' : '') . $a->cb_scity .', ' . $a->cb_sstate. ',+' . $a->cb_szip.' USA'); $latitude2 =$newlatLong['lat']; $longitude2 = $newlatLong['long']; if($latitude2&&$longitude2 ){ $count++; $query =" UPDATE jos_comprofiler SET cb_lat2nd ='$latitude2' ,cb_long2nd ='$longitude2' WHERE id='".$a->id."' "; $rs = mysql_query ( $query ); echo '<i>ADDRESS UPDATED '.$count.' :</i>&nbsp;&nbsp; <small>'.str_replace ( " ", "+", $a->cb_saddress1 ) . ',+' . (strlen ( $a->cb_saddress2 ) ? str_replace ( " ", "+,", $a->cb_saddress2 ) : '') . ',+' . str_replace ( " ", "+", $a->cb_scity ) . ',+' . $a->cb_sstate. ',+' . $a->cb_szip. ',+USA</small> &nbsp;&nbsp;&nbsp; <b>'.$latitude2.':'.$longitude2 .'</b><br/>'; } } if(strlen($a->cb_taddress1)>3){ sleep(.3); $newlatLong=getLatLong($a->cb_taddress1 . ', ' . (strlen ( $a->cb_taddress2 ) ? $a->cb_taddress2.', ' : '') . $a->cb_tcity .', ' . $a->cb_tstate. ',+' . $a->cb_tzip.' USA'); $latitude3 =$newlatLong['lat']; $longitude3 = $newlatLong['long']; if($latitude3&&$longitude3 ){ $count++; $query =" UPDATE jos_comprofiler SET cb_lat3rd ='$latitude3' ,cb_long3rd ='$longitude3' WHERE id='".$a->id."' "; $rs = mysql_query ( $query ); echo '<i>ADDRESS UPDATED '.$count.':</i> &nbsp;&nbsp;<small>'.str_replace ( " ", "+", $a->cb_taddress1 ) . ',+' . (strlen ( $a->cb_taddress2 ) ? str_replace ( " ", "+,", $a->cb_taddress2 ) : '') . ',+' . str_replace ( " ", "+", $a->cb_tcity ) . ',+' . $a->cb_tstate. ',+' . $a->cb_tzip. ',+USA </small> &nbsp;&nbsp;&nbsp; <b>'.$latitude3.':'.$longitude3 .'</b><br/>'; } } } function getLatLong($address){ if (!is_string($address))die("All Addresses must be passed as a string"); $_url = sprintf('http://maps.google.com/maps?output=js&q=%s',rawurlencode($address)); $_result = false; if($_result = file_get_contents($_url)) { if(strpos($_result,'errortips') > 1 || strpos($_result,'Did you mean:') !== false) return false; preg_match('!center:\s*{lat:\s*(-?\d+\.\d+),lng:\s*(-?\d+\.\d+)}!U', $_result, $_match); $_coords['lat'] = $_match[1]; $_coords['long'] = $_match[2]; } return $_coords; }

CB 2.3, CBsubs 4.3, PHP 7.1, J! 3.9.X

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48460
  • Thanks: 8280
  • Karma: 1443
11 years 6 months ago #225831 by krileon
Replied by krileon on topic CB auto action php code
I don't know, probably; try it. It does as minimal cleaning as possible, but some lines of code could trigger cleaning of some sort. Save it to a code action then review the re-display of the code and see if it was altered.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum