Exemplo n.º 1
0
 public function setImage($image_path)
 {
     $this->Image = new AkImage($image_path);
     $this->Image->transform('resize', array('size' => '24x24'));
     $this->_tmp_file = AK_TMP_DIR . DS . '__AkImageColorScheme_' . Ak::randomString(32) . '.jpg';
     $this->Image->save($this->_tmp_file);
 }
Exemplo n.º 2
0
 public function Test_of_encrypt_decrypt()
 {
     $original = "Este es el texto que quiero encriptar";
     $this->assertEqual(Ak::decrypt(Ak::encrypt($original)), $original);
     $key = Ak::randomString(20);
     $file = file_get_contents(__FILE__);
     $ecripted = Ak::encrypt($file, $key);
     $this->assertEqual(Ak::decrypt($ecripted, $key), $file);
 }
Exemplo n.º 3
0
 /**
  * Trace helper function for development purposes
  *
  * @access public
  * @static
  * @param    string    $text    Helper text
  * @param    string    $line    Helper line
  * @param    string    $file    Helper file
  * @return echoes result to screen
  */
 static function trace($text = null, $line = null, $file = null, $method = null, $escape_html_entities = true)
 {
     static $counter = 0;
     if (AK_PRODUCTION_MODE) {
         return;
     }
     $html_entities_function = $escape_html_entities ? 'htmlentities' : 'trim';
     list($default_file, $default_line, $default_method) = self::getLastFileAndLineAndMethod();
     $default_method = is_bool($text) || empty($text) ? 'var_dump' : $default_method;
     $line = is_null($line) ? $default_line : $line;
     $file = is_null($file) ? $default_file : $file;
     $method = is_null($method) ? $default_method : $method;
     if (AK_CLI) {
         $text = self::dump($text, 'print_r');
     } elseif (!empty($text) && !is_scalar($text)) {
         $rand = Ak::randomString();
         $formatted = '';
         $methods = array('print_r', 'var_dump', 'var_export');
         foreach ($methods as $method) {
             $pre_style = 'display:none;';
             if (defined('AK_TRACE_DUMP_METHOD')) {
                 if (AK_TRACE_DUMP_METHOD == $method) {
                     $pre_style = '';
                 }
             } elseif ($method == 'print_r') {
                 $pre_style = '';
             }
             $element_id = $method . '_' . $rand;
             $formatted .= "<div style='margin:10px;'><a href='javascript:void(0);' onclick='e_{$element_id} = document.getElementById(\"{$element_id}\"); e_{$element_id}.style.display = (e_{$element_id}.style.display == \"none\"?\"block\":\"none\");' title='Set the constant AK_TRACE_DUMP_METHOD to your favourite default method'>{$method}</a><br />" . '<pre style="' . $pre_style . '" id="' . $element_id . '">' . $html_entities_function(self::dump($text, $method)) . '</pre></div>';
         }
         $text = $formatted;
     } elseif (is_bool($text) || empty($text)) {
         $text = '<pre style="margin:10px;">' . $html_entities_function(self::dump($text, $default_method)) . '</pre>';
     } elseif (is_scalar($text)) {
         $text = '<pre style="margin:10px;">' . $html_entities_function($text) . '</pre>';
     }
     if (!isset($text)) {
         $counter++;
         $text = '';
     } else {
         $text = AK_CLI ? '---> ' . $text : $text;
     }
     $include_file_and_line = strlen(trim($file . $line)) > 0;
     if ($include_file_and_line) {
         echo AK_CLI ? "----------------\n{$file} ({$line}):\n {$text}\n----------------\n" : "<div style='background-color:#fff;margin:10px;color:#000;font-family:sans-serif;border:3px solid #fc0;font-size:12px;'><div style='background-color:#ffc;padding:10px;color:#000;font-family:sans-serif;'>{$file} <span style='font-weight:bold'>{$line}</span></div>" . $text . "</div>\n";
     } else {
         echo AK_CLI ? "----------------\n {$text}\n----------------\n" : "<div style='background-color:#fff;margin:10px;color:#000;font-family:sans-serif;border:1px solid #ccc;font-size:12px;'>" . $text . "</div>\n";
     }
 }
Exemplo n.º 4
0
 function init()
 {
     $this->ext = empty($this->ext) ? 'doc' : strtolower(trim($this->ext, '.'));
     $this->tmp_name = Ak::randomString();
     if (empty($this->source_file)) {
         $this->source_file = AK_CACHE_DIR . DS . $this->tmp_name . '.' . $this->ext;
         Ak::file_put_contents($this->source_file, $this->source);
         $this->delete_source_file = true;
         $this->keep_destination_file = empty($this->keep_destination_file) ? empty($this->destination_file) ? false : true : $this->keep_destination_file;
     } else {
         $this->delete_source_file = false;
         $this->keep_destination_file = true;
     }
     $this->convert_to = 'txt';
     $this->destination_file_name = empty($this->destination_file_name) ? $this->tmp_name . '.' . $this->convert_to : $this->destination_file_name . (strstr($this->destination_file_name, '.') ? '' : '.' . $this->convert_to);
     $this->destination_file = empty($this->destination_file) ? AK_CACHE_DIR . DS . $this->destination_file_name : $this->destination_file;
 }
Exemplo n.º 5
0
 public function init()
 {
     $this->ext = empty($this->ext) ? 'xls' : strtolower(trim($this->ext, '.'));
     $this->tmp_name = Ak::randomString();
     if (empty($this->source_file)) {
         $this->source_file = AK_TMP_DIR . DS . $this->tmp_name . '.' . $this->ext;
         Ak::file_put_contents($this->source_file, $this->source);
         $this->delete_source_file = true;
         $this->keep_destination_file = empty($this->keep_destination_file) ? empty($this->destination_file) ? false : true : $this->keep_destination_file;
     } else {
         $this->delete_source_file = false;
         $this->keep_destination_file = true;
     }
     $this->convert_to = !empty($this->convert_to) && empty($this->_file_type_codes[$this->convert_to]) ? 'csv' : (empty($this->convert_to) ? 'csv' : $this->convert_to);
     $this->destination_file_name = empty($this->destination_file_name) ? $this->tmp_name . '.' . $this->convert_to : $this->destination_file_name . (strstr($this->destination_file_name, '.') ? '' : '.' . $this->convert_to);
     $this->destination_file = empty($this->destination_file) ? AK_TMP_DIR . DS . $this->destination_file_name : $this->destination_file;
 }
Exemplo n.º 6
0
 function init()
 {
     if (empty($this->handler)) {
         require_once AK_VENDOR_DIR . DS . 'Excel' . DS . 'reader.php';
         $this->handler = new Spreadsheet_Excel_Reader();
         $this->handler->setRowColOffset(empty($this->first_column) ? 0 : $this->first_column);
     }
     $this->tmp_name = Ak::randomString();
     if (empty($this->source_file)) {
         $this->source_file = AK_CACHE_DIR . DS . $this->tmp_name . '.xls';
         Ak::file_put_contents($this->source_file, $this->source);
         $this->delete_source_file = true;
         $this->keep_destination_file = empty($this->keep_destination_file) ? empty($this->destination_file) ? false : true : $this->keep_destination_file;
     } else {
         $this->delete_source_file = false;
         $this->keep_destination_file = true;
     }
 }
Exemplo n.º 7
0
 public function _setAssociatedMemberId(&$Member)
 {
     if (empty($Member->__hasAndBelongsToManyMemberId)) {
         $Member->__hasAndBelongsToManyMemberId = Ak::randomString();
     }
     $object_id = $Member->getId();
     if (!empty($object_id)) {
         $this->associated_ids[$object_id] = $Member->__hasAndBelongsToManyMemberId;
     }
 }
Exemplo n.º 8
0
 public function _setAssociatedMemberId(&$Member)
 {
     if (empty($Member->__hasManyMemberId)) {
         $Member->__hasManyMemberId = Ak::randomString();
     }
     $object_id = method_exists($Member, 'getId') ? $Member->getId() : null;
     if (!empty($object_id)) {
         $this->associated_ids[$object_id] = $Member->__hasManyMemberId;
     }
 }
Exemplo n.º 9
0
Arquivo: Ak.php Projeto: joeymetal/v1
 function uncompress($compressed_data, $format = 'gzip')
 {
     $key = Ak::randomString(15);
     $compressed_file = AK_TMP_DIR . DS . 's' . $key;
     $uncompressed_file = AK_TMP_DIR . DS . 'd' . $key;
     if (Ak::file_put_contents($compressed_file, $compressed_data, array('base_path' => AK_TMP_DIR))) {
         $compressed = gzopen($compressed_file, "r");
         $uncompressed = fopen($uncompressed_file, "w");
         while (!gzeof($compressed)) {
             $string = gzread($compressed, 4096);
             fwrite($uncompressed, $string, strlen($string));
         }
         gzclose($compressed);
         fclose($uncompressed);
     } else {
         trigger_error(Ak::t('Could not write to temporary directory for generating uncompressing file using Ak::uncompress(). Please provide write access to %dirname', array('%dirname' => AK_TMP_DIR)), E_USER_ERROR);
     }
     $result = Ak::file_get_contents($uncompressed_file, array('base_path' => AK_TMP_DIR));
     return $result;
 }
Exemplo n.º 10
0
 public static function form_authenticity_token()
 {
     if (!isset($_SESSION['_csrf_token'])) {
         $_SESSION['_csrf_token'] = sha1(Ak::uuid() . Ak::randomString());
     }
     return $_SESSION['_csrf_token'];
 }
Exemplo n.º 11
0
 public function test_should_create_base_path_ticket_148()
 {
     $tmp_dir = AkConfig::getDir('tmp') . DS . Ak::randomString();
     $base_path = AkConfig::getDir('tmp') . 'new_dir_' . time();
     AkFileSystem::make_dir($base_path, array('base_path' => $base_path));
     $this->assertTrue(is_dir($base_path), 'Could base_path directory ' . $base_path);
     clearstatcache();
 }
Exemplo n.º 12
0
 /**
  * Creates a file for streaming from a file.
  * This way you might free memory usage is file is too large
  */
 function sendDataAsStream($data, $options)
 {
     $temp_file_name = tempnam(AK_TMP_DIR, Ak::randomString());
     $fp = fopen($temp_file_name, 'w');
     fwrite($fp, $data);
     fclose($fp);
     $this->sendFile($temp_file_name, $options);
 }
Exemplo n.º 13
0
 function test_framework_config_locale_update()
 {
     $langs=Ak::langs();
     $translation_key=Ak::randomString(8);
     $this->assertEqual(Ak::t($translation_key),$translation_key);
     AkLocaleManager::updateLocaleFiles();
     list($locales,$core_dictionary) = AkLocaleManager::getCoreDictionary(AK_FRAMEWORK_LANGUAGE);
     $this->assertTrue(isset($core_dictionary[$translation_key]));
     
     foreach($langs as $lang) {
         list($locales,$core_dictionary) = AkLocaleManager::getCoreDictionary($lang);
         $this->assertTrue(isset($core_dictionary[$translation_key]));
     }
 }
Exemplo n.º 14
0
 function test_should_delete_nested_directories_when_include_hidden_files()
 {
     $dir_name = AK_TMP_DIR . Ak::randomString();
     Ak::make_dir($dir_name);
     Ak::make_dir($dir_name . DS . '.hidden');
     $this->assertTrue(is_dir($dir_name), 'Could not create test directory ' . $dir_name);
     $this->assertTrue(Ak::directory_delete($dir_name));
     clearstatcache();
     $this->assertFalse(is_dir($dir_name));
 }
Exemplo n.º 15
0
 public function getBoundaryString()
 {
     return md5(Ak::randomString(10) . time());
 }
Exemplo n.º 16
0
 public function test_should_delete_nested_directories_when_include_hidden_files()
 {
     $tmp_dir = AK_TMP_DIR . DS . Ak::randomString();
     $hidden_tmp_dir = $tmp_dir . DS . '.hidden';
     Ak::make_dir($tmp_dir, array('base_path' => AK_TMP_DIR));
     Ak::make_dir($tmp_dir . DS . '.hidden', array('base_path' => AK_TMP_DIR));
     $this->assertTrue(is_dir($hidden_tmp_dir), 'Could not create test directory ' . $hidden_tmp_dir);
     $this->assertTrue(Ak::directory_delete($tmp_dir, array('base_path' => AK_TMP_DIR)));
     clearstatcache();
     $this->assertFalse(is_dir($tmp_dir));
 }
Exemplo n.º 17
0
 /**
  * Creates a file for streaming from a file.
  * This way you might free memory usage is file is too large
  */
 public function sendDataAsStream($data, $options)
 {
     $temp_file_name = tempnam(AkConfig::getDir('tmp'), Ak::randomString());
     $fp = fopen($temp_file_name, 'w');
     fwrite($fp, $data);
     fclose($fp);
     $this->sendFile($temp_file_name, $options);
 }
Exemplo n.º 18
0
 public function partialMock($class_name, $methods, $returns = array())
 {
     $name = 'Mock' . time() . Ak::randomString() . $class_name;
     Mock::generatePartial($class_name, $name, Ak::toArray($methods));
     $Mock = new $name($this);
     foreach ($returns as $method => $value) {
         if ($value instanceof Exception) {
             $Mock->throwOn($method, $value);
         } else {
             $Mock->returnsByValue($method, $value);
         }
     }
     return $Mock;
 }
Exemplo n.º 19
0
 function sha1($phrase, $use_original_login = false)
 {
     $login = $use_original_login ? $this->getPreviousValueForAttribute('login') : $this->get('login');
     empty($this->password_salt) ? $this->set('password_salt', Ak::randomString(16)) : null;
     return sha1($this->get('password_salt') . $phrase . $login);
 }
Exemplo n.º 20
0
    function getDefaultOptions()
    {
        return array(
        'production_database_type'=> $this->getDatabaseType('production'),
        'production_database_host'=> $this->getDatabaseHost('production'),
        'production_database_name'=> $this->getDatabaseName('production'),
        'production_database_user'=> $this->getDatabaseUser('production'),
        'production_database_password'=> '',

        'development_database_type'=> $this->getDatabaseType('development'),
        'development_database_host'=> $this->getDatabaseHost('development'),
        'development_database_name'=> $this->getDatabaseName('development'),
        'development_database_user'=> $this->getDatabaseUser('development'),
        'development_database_password'=> '',

        'testing_database_type'=> $this->getDatabaseType('testing'),
        'testing_database_host'=> $this->getDatabaseHost('testing'),
        'testing_database_name'=> $this->getDatabaseName('testing'),
        'testing_database_user'=> $this->getDatabaseUser('testing'),
        'testing_database_password'=> '',

        'admin_database_user' => $this->getDatabaseAdminUser(),
        'admin_database_password' => $this->getDatabaseAdminPassword(),

        'url_suffix'=> trim(AK_SITE_URL_SUFFIX, '/'),
        'locales'=> join(',',$this->suggestLocales()),
        'ftp_user' => $this->getFtpUser(),
        'ftp_host' => $this->getFtpHost(),
        'ftp_path' => $this->getFtpPath(),

        'random' => Ak::randomString(),
        );
    }