Exemple #1
0
 /**
  * Set Custom Route Method
  *
  * @param  string $custom_method the custom method
  * @return object $instance      Current Class
  */
 public static function method($custom_method)
 {
     $instance = self::singleton();
     $last_route = empty($instance->x_last_route['route']) || !isset($instance->x_last_route['name']) ? null : $instance->x_last_route;
     if (!$last_route || !isset($instance->x_routes[$last_route['name']][$last_route['route']]['function']) || !is_callable($instance->x_routes[$last_route['name']][$last_route['route']]['function'])) {
         if (isset($last_route)) {
             unset($instance->x_routes[$last_route['name']][$last_route['route']]);
         }
         return $instance;
     }
     if (is_string($custom_method)) {
         $method = strtoupper(trim($custom_method));
         if (strpos($custom_method, '|') !== false) {
             $custom_method = explode('|', $method);
             $custom_method = array_map('trim', $custom_method);
         }
     }
     if (is_array($custom_method)) {
         $custom_method = Internal::strtoUpper($custom_method);
         if (in_array('ALL', $custom_method)) {
             $method = 'ALL';
         } else {
             $method = '';
             foreach ($custom_method as $value) {
                 if (is_string($value)) {
                     if ($value != 'ALL' || !defined("\\" . __NAMESPACE__ . "\\Http\\Request::{$value}")) {
                         continue;
                     }
                     $value = trim(strtoupper($value));
                     $method .= "{$value}|";
                     if ($value == 'ALL') {
                         $method = 'ALL';
                         break;
                     }
                 }
             }
             $method = trim($method, "|");
         }
     }
     /**
      * Set & CHeck Method
      */
     if (!$method || is_string($custom_method) && strpos($method, '|') === false && ($method == 'ALL' || !defined("\\" . __NAMESPACE__ . "\\Http\\Request::{$method}"))) {
         $method = 'ALL';
     }
     $key = $last_route['name'];
     $route = $last_route['route'];
     // reset
     $x_method = null;
     /**
      * Check Method parsing array
      */
     if (!empty($instance->x_routes[$key][$route]) && $method != 'ALL') {
         $x_method = strtoupper($instance->x_routes[$key][$route]['method']);
         $ex = $x_method == 'ALL' ? array() : explode('|', $x_method);
         $method = array_unique(array_merge($ex, explode('|', $method)));
         $method = implode('|', $method);
     }
     $instance->x_routes[$key][$route]['method'] = trim($method, '|');
     if (!isset($instance->x_routes[$key][$route]['param']) || !is_array($instance->x_routes[$key][$route]['param'])) {
         $instance->x_routes[$key][$route]['param'] = array();
     }
     unset($x_method, $method);
     // $instance->x_last_route = null;
     return $instance;
 }
Exemple #2
0
 /**
  * Alternative decryption using Pure PHP Libraries
  * @http://px.sklar.com/code.html/id=1287
  * Fix and added More Secure Method
  *
  * @param  string $str  string to be decode
  * @param  string $pass the hash key
  * @return mixed        decryption value output
  */
 public static function altDecrypt($enc, $pass = '')
 {
     // if has $enc or invalid no value or not as string stop here
     if (!is_string($enc) || strlen(trim($enc)) < 4 || (strlen($enc) > 10 ? strpos($enc, 'aCb') !== 10 : strpos($enc, 'aCb') !== 2)) {
         // check if mcrypt loaded and crypt using mcrypt
         if (is_string($enc) && strlen(trim($enc)) > 3 && extension_loaded('mcrypt') && (strlen($enc) > 10 ? strpos($enc, 'mCb') === 10 : strpos($enc, 'mCb') === 2)) {
             return static::decrypt($enc, $pass);
         }
         return null;
     }
     /**
      * Replace Injection 3 characters sign
      */
     $enc = strlen($enc) > 10 ? substr_replace($enc, '', 10, 3) : substr_replace($enc, '', 2, 3);
     // this is base64 safe encoded?
     if (preg_match('/[^a-z0-9\\+\\/\\=\\-\\_]/i', $enc)) {
         return null;
     }
     /**
      * ------------------------------------
      * Safe Sanitized
      * ------------------------------------
      */
     $pass = !$pass ? Config::get('security_salt', '') : $pass;
     (is_null($pass) || $pass === false) && ($pass = '');
     // safe is use array orobject as hash
     $pass = StringHelper::maybeSerialize($pass);
     if (!$pass) {
         $pass = Sha1::hash($pass);
     }
     /**
      * Doing decode of input encryption
      */
     $enc = Internal::safeBase64Decode($enc);
     /**
      * ------------------------------------
      * Doing convert encrypted string
      * ------------------------------------
      */
     $enc_arr = str_split($enc);
     $pass_arr = str_split($pass);
     $add = 0;
     $div = strlen($enc) / strlen($pass);
     $newpass = '';
     while ($add <= $div) {
         $newpass .= $pass;
         $add++;
     }
     $pass_arr = str_split($newpass);
     $ascii = '';
     foreach ($enc_arr as $key => $asc) {
         $pass_int = ord($pass_arr[$key]);
         $enc_int = ord($asc);
         $str_int = $enc_int - $pass_int;
         $ascii .= chr($str_int - strlen($enc));
     }
     /* --------------------------------
      * reversing
      * ------------------------------ */
     // unpack
     $unpack = unpack('a*', trim($ascii));
     /**
      * if empty return here
      */
     if (!$unpack) {
         return null;
     }
     // implode the unpacking array
     $unpack = implode('', (array) $unpack);
     /**
      * Doing decode of input encryption from unpacked
      */
     $unpack = Internal::safeBase64Decode($unpack);
     /**
      * Reverse Rotate
      */
     $retval = Internal::rotate($unpack, 13);
     /**
      * For some case packing returning invisible characters
      * remove it
      */
     $retval = StringHelper::removeInvisibleCharacters($retval, false);
     // check if string less than 40 && match end of hash
     if (strlen($retval) < 40 || substr($retval, -40) !== Sha1::hash(Sha256::hash($pass))) {
         return;
     }
     // remove last 40 characters
     $retval = substr($retval, 0, strlen($retval) - 40);
     // check if result is not string it will be need to be unserialize
     $retval = StringHelper::maybeUnserialize($retval);
     /**
      * Check if value is array
      */
     if (is_array($retval) && array_key_exists('acb', $retval)) {
         return $retval['acb'];
     }
     // freed the memory
     unset($retval);
     return null;
 }
Exemple #3
0
 public function setActiveTemplateDirectory($directory)
 {
     if (Internal::isDir($directory)) {
         $active = $this->getActiveTemplate();
         $this->x_list_templates[$active]['Directory'] = Path::cleanSlashed($directory);
         return true;
     }
     return false;
 }
Exemple #4
0
 /**
  * Get Media Type (type/subtype within Content Type header)
  *
  * @return string|null
  */
 public static function getMediaType()
 {
     $contentType = static::getContentType();
     if ($contentType) {
         $contentTypeParts = preg_split('/\\s*[;,]\\s*/', $contentType);
         return Internal::strToLower($contentTypeParts[0]);
     }
     return null;
 }