diff --git a/protected/src/composer.json b/protected/src/composer.json index d92b1d8..76315bd 100644 --- a/protected/src/composer.json +++ b/protected/src/composer.json @@ -2,6 +2,7 @@ "require": { "twig/twig": "^3.0", "liquid/liquid": "^1.4", - "ezyang/htmlpurifier": "^4.18" + "ezyang/htmlpurifier": "^4.18", + "twilio/sdk": "^8.7" } } diff --git a/protected/src/configs/off_remove_request_vars.php b/protected/src/configs/off_remove_request_vars.php new file mode 100644 index 0000000..1fb3513 --- /dev/null +++ b/protected/src/configs/off_remove_request_vars.php @@ -0,0 +1,13 @@ + + * @copyright (c) 2025, Robert Strutts + * @license MIT + */ + +unset($_REQUEST); // Request is dangerious as order of Vars is not Known +unset($_GET); // Super Globals are not Filtered, so unset them +unset($_POST); \ No newline at end of file diff --git a/protected/src/configs/off_twilio.php b/protected/src/configs/off_twilio.php new file mode 100644 index 0000000..3d02547 --- /dev/null +++ b/protected/src/configs/off_twilio.php @@ -0,0 +1,18 @@ + + * @copyright (c) 2025, Robert Strutts + * @license MIT + */ + +use CodeHydrater\bootstrap\configure as Config; + +// Your Twilio credentials +Config::set('twilio', [ + 'sid' => '', + 'token' => '', +]); + diff --git a/protected/src/controllers/app/home_ctrl.php b/protected/src/controllers/app/home_ctrl.php index ce3b142..672385a 100644 --- a/protected/src/controllers/app/home_ctrl.php +++ b/protected/src/controllers/app/home_ctrl.php @@ -19,10 +19,13 @@ class home_ctrl { private $footer; public function __construct() { // FROM on_footer_banner.php in the configs folder... - $this->footer = \Project\get_footer(); + if (function_exists("\Project\get_footer")) { + $this->footer = \Project\get_footer(); + } else { + $this->footer = ""; + } } - public function index() { $html = new \CodeHydrater\html_document(); $html->set_footer($this->footer); @@ -76,5 +79,4 @@ class home_ctrl { echo "PAGE = ". $page; } - public function error_demo() { \CodeHydrater\bootstrap\broken_error(); } } diff --git a/protected/src/controllers/app/twilio_ctrl.php b/protected/src/controllers/app/twilio_ctrl.php new file mode 100644 index 0000000..46f7f73 --- /dev/null +++ b/protected/src/controllers/app/twilio_ctrl.php @@ -0,0 +1,76 @@ + + * @copyright (c) 2025, Robert Strutts + * @license MIT + */ + +namespace Project\controllers\app; + +/** + * Description of twilio_ctrl + * + * Twilio Setup, REQUIRES off_twilio.php to be turned on... + * Then define the sid and token + * + * @link https://github.com/twilio/twilio-php + * @link https://www.twilio.com/docs/messaging/quickstart + * + * + */ +class twilio_ctrl { + + private function get_caller() { + /** Get Callers Phone Number, if plus-sign (+) not found add it */ + $caller_number = (isset($_REQUEST['From'])) ? $_REQUEST['From'] : false; + if ($caller_number !== false) { + $plus = substr($caller_number, 0, 1); + $caller_number = ($plus !== '+') ? "+" . $caller_number : $caller_number; + } + return $caller_number; + } + + public function index() { + header("content-type: text/xml"); + $response = \CodeHydrater\twilio_setup::init_voice(); + $the_caller_number = $this->get_caller(); + // If the user entered digits, process their request + if (array_key_exists('Digits', $_POST)) { + switch ($_POST['Digits']) { + case 1: + $response->say('You selected sales. Good for you!'); + break; + case 2: + $response->say('You need support. We will help!'); + break; + default: + $response->say('Sorry, I don\'t understand that choice.'); + } + } else { + // If no input was sent, use the verb to collect user input + $gather = $response->gather(array('numDigits' => 1)); + // use the verb to request input from the user + $gather->say('For sales, press 1. For support, press 2.'); + + // If the user doesn't enter input, loop + $response->redirect('/app/twilio/index'); + } + echo $response; + } + + public function send_sms(): string { + $twilio = \CodeHydrater\twilio_setup::init_sms(); + // Example: Send an SMS Text message to Cell Phone + $message = $twilio->messages->create( + '+15558675309', // To number GOES HERE + [ + 'from' => '+15017122661', // YOUR Twilio number HERE + 'body' => 'Hello from Twilio!' + ] + ); + echo $message->body; + } +} diff --git a/protected/src/services/on_twilio_setup.php b/protected/src/services/on_twilio_setup.php new file mode 100644 index 0000000..0fc35f9 --- /dev/null +++ b/protected/src/services/on_twilio_setup.php @@ -0,0 +1,40 @@ + + * @copyright (c) 2025, Robert Strutts + * @license MIT + */ +namespace CodeHydrater; + +use CodeHydrater\bootstrap\registry as Reg; +use CodeHydrater\bootstrap\configure as Config; + +final class twilio_setup { + const VENDOR = CodeHydrater_PROJECT . 'vendor/twilio/sdk/src/Twilio/'; + + public static function init_sms() { + if (! Reg::get('loader')->is_loaded('Twilio')) { + Reg::get('loader')->add_namespace('Twilio', self::VENDOR); + } + $sid = Config::get('twilio', 'sid') ?? false; + if ($sid === false) { + throw new \Exception("Twilio SID not defined"); + } + $token = Config::get('twilio', 'token') ?? false; + if ($token === false) { + throw new \Exception("Twilio TOKEN not defined"); + } + return new \Twilio\Rest\Client($sid, $token); + } + + public static function init_voice() { + if (! Reg::get('loader')->is_loaded('Twilio')) { + Reg::get('loader')->add_namespace('Twilio', self::VENDOR); + return new \Twilio\TwiML\VoiceResponse(); + } + } + +} \ No newline at end of file diff --git a/protected/src/views/default/app/home_index.php b/protected/src/views/default/app/home_index.php index 206ed1c..bf818e6 100644 --- a/protected/src/views/default/app/home_index.php +++ b/protected/src/views/default/app/home_index.php @@ -8,6 +8,9 @@ $method_name_demo = "name_demo"; $route_liquid = "app/home"; $method_liquid = "liquid"; +$route_rss = "app/rss"; +$method_rss = "feed.xml"; + ?>
@@ -20,4 +23,8 @@ $method_liquid = "liquid"; View Liquid Demo +|| + +View RSS XML feed Demo +
\ No newline at end of file