Exemplo n.º 1
0
 /**
  * Encode data into a single string
  *
  * @param    string  $data
  * @return   string
  */
 public function encode($plain_text, $key = null)
 {
     $cipher = $this->getCipher();
     if ($cipher == false) {
         return false;
     }
     if ($key == null) {
         $sdk = GiveItSdk::getInstance();
         $key = $sdk->data_key;
     }
     if ($key == null) {
         $this->addError('missing key for encryption');
         return false;
     }
     $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher, MCRYPT_MODE_CBC), MCRYPT_RAND);
     $td = mcrypt_module_open($cipher, '', MCRYPT_MODE_CBC, '');
     mcrypt_generic_init($td, $key, $iv);
     $text = $this->pkcs5Pad($plain_text, mcrypt_enc_get_block_size($td));
     // manually pad the data since mcrypt doesn't do this properly
     $encrypted = mcrypt_generic($td, $text);
     $crypt = base64_encode($iv . $encrypted);
     $crypt = urlencode($crypt);
     if ($this->debug) {
         echo "\n---- cipher ---\n" . $this->cipher;
         echo "\n---- text  ----\n" . $text;
         echo "\n---- crypt ----\n" . $crypt;
         echo "\n---------------\n";
     }
     return $crypt;
 }
Exemplo n.º 2
0
 public function __construct()
 {
     $this->sdk = GiveItSdk::getInstance();
     $this->cookie_cache = fopen('php://memory', 'w+');
     $this->setupCurl();
 }
Exemplo n.º 3
0
 /**
  * Generate Button HTML
  *
  * This function generates the necessary HTML to render the button.
  *
  */
 public function getButtonHTML($button_type = 'blue_rect_sm')
 {
     if (!$this->validate()) {
         $this->addError('product data is invalid');
         return $this->getErrorsHTML();
     }
     $parent = GiveItSdk::getInstance();
     $crypt = GiveItSdkCrypt::getInstance();
     if ($parent == false) {
         $this->addError('SDK must be instantiated to render buttons');
         return false;
     }
     $encrypted = $crypt->encode(Tools::jsonEncode($this->data), $parent->data_key);
     if ($encrypted == false) {
         if (!$this->render_errors) {
             return false;
         }
         $this->addError($crypt->errors());
         return $this->getErrorsHTML();
     }
     // $encrypted  = urlencode($encrypted);
     $html = "<span class='giveit-button' data-giveit-buttontype='{$button_type}' data-giveit-data='{$encrypted}'></span>";
     return $html;
 }
Exemplo n.º 4
0
 /**
  * Register the singleton
  *
  * @return boolean
  */
 protected function registerInstance()
 {
     self::$instance = $this;
     return true;
 }
Exemplo n.º 5
0
 public function __construct()
 {
     $this->parent = GiveItSdk::getInstance();
     $this->crypt = GiveItSdkCrypt::getInstance();
 }