Пример #1
0
 function runCommand($command)
 {
     $commands = $this->getOptionsFromCommand($command);
     $generator_name = isset($commands['generator']) ? $commands['generator'] : array_shift($commands);
     if (empty($generator_name)) {
         echo "\n   " . Ak::t("You must supply a valid generator as the first command.\n\n   Available generator are:");
         echo "\n\n   " . join("\n   ", $this->_getAvailableGenerators()) . "\n\n";
         AK_CONSOLE_MODE ? null : exit;
         return;
     }
     if (count(array_diff($commands, array('help', '-help', 'usage', '-usage', 'h', '-h', 'USAGE', '-USAGE'))) != count($commands) || count($commands) == 0) {
         $usage = method_exists($this, 'banner') ? $this->banner() : @Ak::file_get_contents(AK_SCRIPT_DIR . DS . 'generators' . DS . $generator_name . DS . 'USAGE');
         echo empty($usage) ? "\n" . Ak::t('Could not locate usage file for this generator') : "\n" . $usage . "\n";
         return;
     }
     if (file_exists(AK_SCRIPT_DIR . DS . 'generators' . DS . $generator_name . DS . $generator_name . '_generator.php')) {
         include_once AK_SCRIPT_DIR . DS . 'generators' . DS . $generator_name . DS . $generator_name . '_generator.php';
         $generator_class_name = AkInflector::camelize($generator_name . '_generator');
         $generator = new $generator_class_name();
         $generator->type = $generator_name;
         $generator->_identifyUnnamedCommands($commands);
         $generator->_assignVars($commands);
         $generator->cast();
         $generator->_generate();
     } else {
         echo "\n" . Ak::t('Could not find %generator_name generator', array('%generator_name' => $generator_name)) . "\n";
     }
 }
Пример #2
0
    function up_1()
    {
        $new_code = '
    private function __call ($method, $args)
    {
        if(substr($method,0,4) == \'find\'){
            $finder = substr(AkInflector::underscore($method), 5);
            list($type, $columns) = explode(\'by_\', $finder);
            $callback = strstr($type,\'create\') ?  \'findOrCreateBy\' : (strstr($type,\'first\') || !strstr($type,\'all\') ? \'findFirstBy\' : \'findAllBy\');
            $columns = strstr($columns, \'_and_\') ? explode(\'_and_\', $columns) : array($columns);
            array_unshift($args, join(\' AND \', $columns));
            return Ak::call_user_func_array(array(&$this,$callback), $args);
        }

        $backtrace = debug_backtrace();
        trigger_error(\'Call to undefined method \'.__CLASS__.\'::\'.$method.\'() in <b>\'.$backtrace[1][\'file\'].\'</b> on line <b>\'.$backtrace[1][\'line\'].\'</b> reported \', E_USER_ERROR);
    }

';
        $original_class = Ak::file_get_contents(AK_APP_DIR.DS.'shared_model.php');
        if(strstr($original_class, '__call')){
            trigger_error('You seem to have a __call method on your shared model. This plugin can\'t be installed as it will conflict with your existing code.', E_USER_ERROR);
        }

        $modified_class = preg_replace('/ActiveRecord[ \n\t]*extends[ \n\t]*AkActiveRecord[ \n\t]*[ \n\t]*{/i', "ActiveRecord extends AkActiveRecord \n{\n\n$new_code", $original_class);

        Ak::file_put_contents(AK_APP_DIR.DS.'shared_model.php', $modified_class);
    }
Пример #3
0
 public function convert()
 {
     $word = new COM('word.application') or die('Unable to instantiate Word');
     $word->Visible = false;
     $word->Documents->Open($this->source_file);
     $word->Documents[1]->SaveAs($this->destination_file, $this->_file_type_codes[$this->convert_to]);
     $word->Quit();
     $word = null;
     $result = Ak::file_get_contents($this->destination_file);
     $this->delete_source_file ? Ak::file_delete($this->source_file) : null;
     $this->keep_destination_file ? null : Ak::file_delete($this->destination_file);
     return $result;
 }
Пример #4
0
 public function convert()
 {
     $excel = new COM('excel.application') or die('Unable to instantiate Excel');
     $excel->Visible = false;
     $excel->WorkBooks->Open($this->source_file);
     $excel->WorkBooks[1]->SaveAs($this->destination_file, $this->_file_type_codes[$this->convert_to]);
     $excel->Quit();
     unset($excel);
     $result = Ak::file_get_contents($this->destination_file);
     $this->delete_source_file ? @Ak::file_delete($this->source_file) : null;
     $this->keep_destination_file ? null : Ak::file_delete($this->destination_file);
     return $result;
 }
Пример #5
0
 function generate()
 {
     if (empty($this->clone_setup_done)) {
         $this->_setupCloner();
     }
     foreach ($this->files_to_clone as $origin => $destination) {
         if (file_exists($origin)) {
             $origin_code = Ak::file_get_contents($origin);
             $destination_code = str_replace(array_keys($this->clone_replacements), array_values($this->clone_replacements), $origin_code);
             $this->save($destination, $destination_code);
         }
     }
 }
Пример #6
0
 function raiseError($code = null)
 {
     $code = empty($code) ? @$this->_options['code'] : $code;
     if (AK_DEBUG) {
         // We can't halt execution while testing and the error message is too large for trigger_error
         if (AK_ENVIRONMENT == 'testing') {
             trigger_error(join("\n", $this->getErrors()), E_USER_WARNING);
         } else {
             echo '<h1>' . Ak::t('Template %template_file security error', array('%template_file' => @$this->_options['file_path'])) . ':</h1>' . "<ul><li>" . join("</li>\n<li>", $this->getErrors()) . "</li></ul><hr />\n" . '<h2>' . Ak::t('Showing template source from %file:', array('%file' => $this->_options['file_path'])) . '</h2>' . (isset($this->_options['file_path']) ? '<pre>' . htmlentities(Ak::file_get_contents($this->_options['file_path'])) . '</pre><hr />' : '') . '<h2>' . Ak::t('Showing compiled template source:') . '</h2>' . highlight_string($code, true);
             die;
         }
     } else {
         trigger_error(Ak::t('Template compilation error'), E_USER_ERROR);
     }
 }
Пример #7
0
 function Test_file_get_contents()
 {
     $file_name = AK_CACHE_DIR . DS . 'test_file_1.txt';
     $content = 'This is the NEW content for file 1';
     $this->assertFalse(!Ak::file_get_contents($file_name) === $content);
     $file_name = AK_CACHE_DIR . DS . 'test_file_2.txt';
     $content = "\n\rThis is the content of file 2\n";
     $this->assertFalse(!Ak::file_get_contents($file_name) === $content);
     $file_name = 'cache' . DS . 'test_file_3.txt';
     $content = "\rThis is the content of file 3\r\n";
     $this->assertFalse(!Ak::file_get_contents($file_name) === $content);
     $file_name = 'cache/test_file_4.txt';
     $content = "\rThis is the content of file 4\r\n";
     $this->assertFalse(!Ak::file_get_contents($file_name) === $content);
 }
Пример #8
0
 function install()
 {
     $source = dirname(__FILE__) . DS . 'phpunit_test.php';
     $target = AK_BASE_DIR . DS . 'script' . DS . 'phpunit_testsuite.php';
     if (copy($source, $target)) {
         echo "Copied script to your ./script folder.\n\r";
         $source_file_mode = fileperms($source);
         $target_file_mode = fileperms($target);
         if ($source_file_mode != $target_file_mode) {
             chmod($destination_file, $source_file_mode);
         }
     }
     echo "Be sure to read the README.\n\r";
     echo "We're now on version: " . Ak::file_get_contents(dirname(dirname(__FILE__)) . DS . 'VERSION');
 }
Пример #9
0
    function raiseError($code = null)
    {
        $code = empty($code) ? @$this->_options['code'] : $code;
        if(AK_DEBUG){
            echo
            '<h1>'.Ak::t('Template %template_file security error', array('%template_file'=>@$this->_options['file_path'])).':</h1>'.
            "<ul><li>".join("</li>\n<li>",$this->getErrors())."</li></ul><hr />\n".
            '<h2>'.Ak::t('Showing template source from %file:',array('%file'=>$this->_options['file_path'])).'</h2>'.
            (isset($this->_options['file_path']) ? '<pre>'.htmlentities(Ak::file_get_contents($this->_options['file_path'])).'</pre><hr />':'').
            '<h2>'.Ak::t('Showing compiled template source:').'</h2>'.highlight_string($code,true);

            die();
        }else{
            trigger_error(Ak::t('Template compilation error'),E_USER_ERROR);
        }
    }
Пример #10
0
 function convert()
 {
     $xdoc2txt_bin = AK_VENDOR_DIR . DS . 'hyperestraier' . DS . 'xdoc2txt.exe';
     if (AK_OS != 'WINDOWS') {
         trigger_error(Ak::t('Xdoc2Text is a windows only application. Please use wvWare instead'), E_USER_WARNING);
         return false;
     }
     if (!file_exists($xdoc2txt_bin)) {
         trigger_error(Ak::t('Could not find xdoc2txt.exe on %path. Please download it from http://www31.ocn.ne.jp/~h_ishida/xdoc2txt.html', array('%path' => $xdoc2txt_bin)), E_USER_WARNING);
         return false;
     }
     exec('@"' . $xdoc2txt_bin . '" -f "' . $this->source_file . '" "' . $this->destination_file . '"');
     $result = Ak::file_get_contents($this->destination_file);
     $this->delete_source_file ? @Ak::file_delete($this->source_file) : null;
     $this->keep_destination_file ? null : Ak::file_delete($this->destination_file);
     return $result;
 }
Пример #11
0
 function _loadDbDesignerDbSchema()
 {
     if($path = $this->_getDbDesignerFilePath()){
         $this->db_designer_schema = Ak::convert('DBDesigner','AkelosDatabaseDesign', Ak::file_get_contents($path));
         return !empty($this->db_designer_schema);
     }
     return false;
 }
Пример #12
0
 function relativizeStylesheetPaths()
 {
     $asset_path = $this->_getAssetBasePath();
     if($this->hasUrlSuffix() || !empty($asset_path)){
         $url_suffix = trim($this->getUrlSuffix(),'/');
         if(!empty($asset_path)){
             $url_suffix = trim($url_suffix.'/'.$asset_path,'/');
         }
         foreach ($this->stylesheets as $stylesheet) {
             $filename = AK_PUBLIC_DIR.DS.'stylesheets'.DS.$stylesheet.'.css';
             $relativized_css = preg_replace("/url\((\'|\")?\/images/","url($1/$url_suffix/images", @Ak::file_get_contents($filename));
             empty($relativized_css) ? null : @Ak::file_put_contents($filename, $relativized_css);
         }
     }
 }
Пример #13
0
 function testFtpSettings()
 {
     if (!$this->canUseFtpFileHandling()) {
         return false;
     }
     $ftp_path = 'ftp://' . $this->getFtpUser() . ':' . $this->getFtpPassword() . '@' . $this->getFtpHost() . $this->getFtpPath();
     @define('AK_UPLOAD_FILES_USING_FTP', true);
     @define('AK_READ_FILES_USING_FTP', false);
     @define('AK_DELETE_FILES_USING_FTP', true);
     @define('AK_FTP_PATH', $ftp_path);
     @define('AK_FTP_AUTO_DISCONNECT', true);
     if (@Ak::file_put_contents(AK_CONFIG_DIR . DS . 'test_file.txt', 'hello from ftp')) {
         $text = @Ak::file_get_contents(AK_CONFIG_DIR . DS . 'test_file.txt');
         @Ak::file_delete(AK_CONFIG_DIR . DS . 'test_file.txt');
     }
     $this->ftp_enabled = isset($text) && $text == 'hello from ftp';
     return $this->ftp_enabled;
 }
Пример #14
0
 function Test_of_binary_data_on_database()
 {
     $long_string = Ak::file_get_contents(AK_LIB_DIR . DS . 'AkActiveRecord.php');
     $_tmp_file = fopen(AK_LIB_DIR . DS . 'AkActiveRecord.php', "rb");
     $binary_data = fread($_tmp_file, fileSize(AK_LIB_DIR . DS . 'AkActiveRecord.php'));
     $i = 1;
     $details = array('varchar_field' => "{$i} string ", 'longtext_field' => $long_string, 'text_field' => "{$i} text", 'logblob_field' => $binary_data, 'date_field' => "2005/05/{$i}", 'datetime_field' => "2005/05/{$i}", 'tinyint_field' => $i, 'integer_field' => $i, 'smallint_field' => $i, 'bigint_field' => $i, 'double_field' => "{$i}.{$i}", 'numeric_field' => $i, 'bytea_field' => $binary_data, 'timestamp_field' => "2005/05/{$i} {$i}:{$i}:{$i}", 'boolean_field' => !($i % 2), 'int2_field' => "{$i}", 'int4_field' => $i, 'int8_field' => $i, 'foat_field' => "{$i}.{$i}", 'varchar4000_field' => "{$i} text", 'clob_field' => "{$i} text", 'nvarchar2000_field' => "{$i} text", 'blob_field' => $binary_data, 'nvarchar_field' => "{$i}", 'decimal1_field' => "{$i}", 'decimal3_field' => $i, 'decimal5_field' => $i, 'decimal10_field' => "{$i}", 'decimal20_field' => $i, 'decimal_field' => $i);
     $AkTestField = new AkTestField($details);
     $this->assertEqual($long_string, $binary_data);
     $this->assertTrue($AkTestField->save());
     $AkTestField = new AkTestField($AkTestField->getId());
     $this->assertEqual($AkTestField->longtext_field, $long_string);
     $this->assertEqual($AkTestField->bytea_field, $binary_data);
     $this->assertEqual($AkTestField->blob_field, $binary_data);
     $this->assertEqual($AkTestField->logblob_field, $binary_data);
     //Now we add some more records for next tests
     foreach (range(2, 10) as $i) {
         $details = array('varchar_field' => "{$i} string", 'text_field' => "{$i} text", 'date_field' => "2005/05/{$i}", 'datetime_field' => "2005/05/{$i}", 'tinyint_field' => $i, 'integer_field' => $i, 'smallint_field' => $i, 'bigint_field' => $i, 'double_field' => "{$i}.{$i}", 'numeric_field' => $i, 'timestamp_field' => "2005/05/{$i} {$i}:{$i}:{$i}", 'boolean_field' => !($i % 2), 'int2_field' => "{$i}", 'int4_field' => $i, 'int8_field' => $i, 'foat_field' => "{$i}.{$i}", 'varchar4000_field' => "{$i} text", 'clob_field' => "{$i} text", 'nvarchar2000_field' => "{$i} text", 'nvarchar_field' => "{$i}", 'decimal1_field' => "{$i}", 'decimal3_field' => $i, 'decimal5_field' => $i, 'decimal10_field' => "{$i}", 'decimal20_field' => $i, 'decimal_field' => $i);
         $AkTestField = new AkTestField($details);
         $this->assertTrue($AkTestField->save());
     }
 }
Пример #15
0
    /**
     * Gets a list of available plugins.
     * 
     * Goes through each trusted plugin server and retrieves the name of the 
     * folders (plugins) on the repository path.
     * 
     * @param  boolean $force_update If it is not set to true, it will only check remote sources once per hour
     * @return array   Returns an array containing "plugin_name" => "repository URL"
     * @access public 
     */
    function getPlugins($force_update = false)
    {
        if($force_update || !is_file($this->_getRepositoriesCahePath()) || filemtime($this->_getRepositoriesCahePath()) > 3600){
            if(!$this->_updateRemotePluginsList()){
                return array();
            }
        }

        return array_map('trim', Ak::convert('yaml', 'array', Ak::file_get_contents($this->_getRepositoriesCahePath())));
    }
Пример #16
0
    function extractImagesIntoInlineParts(&$Mail, $options = array())
    {
        $html =& $Mail->body;
        require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'helpers'.DS.'text_helper.php');
        $images = TextHelper::get_image_urls_from_html($html);
        $html_images = array();
        if(!empty($images)){
            require_once(AK_LIB_DIR.DS.'AkImage.php');
            require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'helpers'.DS.'asset_tag_helper.php');

            $images = array_diff(array_unique($images), array(''));

            foreach ($images as $image){
                $original_image_name = $image;
                $image = $this->_getImagePath($image);
                if(!empty($image)){
                    $extenssion = substr($image, strrpos('.'.$image,'.'));
                    $image_name = Ak::uuid().'.'.$extenssion;
                    $html_images[$original_image_name] = 'cid:'.$image_name;

                    $Mail->setAttachment('image/'.$extenssion, array(
                    'body' => Ak::file_get_contents($image),
                    'filename' => $image_name,
                    'content_disposition' => 'inline',
                    'content_id' => '<'.$image_name.'>',
                    ));
                }
            }
            $modified_html = str_replace(array_keys($html_images),array_values($html_images), $html);
            if($modified_html != $html){
                $html = $modified_html;
                $Mail->_moveBodyToInlinePart();
            }
        }
    }
Пример #17
0
 /**
  * Sends the file by streaming it 4096 bytes at a time. This way the
  * whole file doesn't need to be read into memory at once.  This makes
  * it feasible to send even large files.
  * 
  * Be careful to sanitize the path parameter if it coming from a web
  * page.  sendFile($params['path']) allows a malicious user to
  * download any file on your server.
  * 
  * Options:
  * * <tt>filename</tt> - suggests a filename for the browser to use.
  *   Defaults to realpath($path).
  * * <tt>type</tt> - specifies an HTTP content type.
  *   Defaults to 'application/octet-stream'.
  * * <tt>disposition</tt> - specifies whether the file will be shown inline or downloaded.  
  *   Valid values are 'inline' and 'attachment' (default).
  * * <tt>stream</tt> - whether to send the file to the user agent as it is read (true)
  *   or to read the entire file before sending (false). Defaults to true.
  * * <tt>buffer_size</tt> - specifies size (in bytes) of the buffer used to stream the file.
  *   Defaults to 4096.
  * 
  * The default Content-Type and Content-Disposition headers are
  * set to download arbitrary binary files in as many browsers as
  * possible.  IE versions 4, 5, 5.5, and 6 are all known to have
  * a variety of quirks (especially when downloading over SSL).
  * 
  * Simple download:
  *   sendFile('/path/to.zip');
  * 
  * Show a JPEG in browser:
  *   sendFile('/path/to.jpeg', array('type' => 'image/jpeg', 'disposition' => 'inline'));
  * 
  * Read about the other Content-* HTTP headers if you'd like to
  * provide the user with more information (such as Content-Description).
  * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11
  * 
  * Also be aware that the document may be cached by proxies and browsers.
  * The Pragma and Cache-Control headers declare how the file may be cached
  * by intermediaries.  They default to require clients to validate with
  * the server before releasing cached responses.  See
  * http://www.mnot.net/cache_docs/ for an overview of web caching and
  * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
  * for the Cache-Control header spec.
  */
 function sendFile($path, $options = array())
 {
     $path = realpath($path);
     if (!file_exists($path)) {
         trigger_error(Ak::t('Cannot read file %path', array('%path' => $path)), E_USER_NOTICE);
         return false;
     }
     $options['length'] = empty($options['length']) ? filesize($path) : $options['length'];
     $options['filename'] = empty($options['filename']) ? basename($path) : $options['filename'];
     $options['type'] = empty($options['type']) ? Ak::mime_content_type($path) : $options['type'];
     $this->performed_render = false;
     $this->_sendFileHeaders($options);
     if (!empty($options['stream'])) {
         require_once AK_LIB_DIR . DS . 'AkStream.php';
         $this->render(array('text' => new AkStream($path, $options['buffer_size'])));
     } else {
         $this->render(array('text' => Ak::file_get_contents($path)));
     }
 }
Пример #18
0
 public function Test_file_get_contents()
 {
     $file_name = AK_TMP_DIR . DS . 'test_file_1.txt';
     $content = 'This is the NEW content for file 1';
     $this->assertTrue(Ak::file_get_contents($file_name) === $content);
     $file_name = AK_TMP_DIR . DS . 'test_file_2.txt';
     $content = "\n\rThis is the content of file 2\n";
     $this->assertTrue(Ak::file_get_contents($file_name) === $content);
     $file_name = 'cache' . DS . 'test_file_3.txt';
     $content = "\rThis is the content of file 3\r\n";
     $this->assertTrue(Ak::file_get_contents($file_name) === $content);
     $file_name = 'cache\\test_file_4.txt';
     $content = "\rThis is the content of file 4\r\n";
     $this->assertTrue(Ak::file_get_contents($file_name) === $content);
 }
Пример #19
0
 public function test_should_read_files_using_scoped_file_get_contents_function()
 {
     $this->assertEqual(Ak::file_get_contents(AK_LIB_DIR . DS . 'AkActiveRecord.php'), file_get_contents(AK_LIB_DIR . DS . 'AkActiveRecord.php'));
 }
Пример #20
0
    function relativizeStylesheetPaths()
    {
        $url_suffix = AkInstaller::promptUserVar(
        'The admin plugin comes with some fancy CSS background images.

Your aplication might be accesible at /myapp, 
and your images folder might be at /myapp/public

Insert the relative path where your images folder is
so you don\'t need to manually edit the CSS files', array('default'=>'/'));
        
        $url_suffix =  trim(preg_replace('/\/?images\/admin\/?$/','',$url_suffix),'/');
        
        if(!empty($url_suffix)){
            $stylesheets = array('admin/admin','admin/menu');
            foreach ($stylesheets as $stylesheet) {
                $filename = AK_PUBLIC_DIR.DS.'stylesheets'.DS.$stylesheet.'.css';
                $relativized_css = preg_replace("/url\((\'|\")?\/images/","url($1/$url_suffix/images", @Ak::file_get_contents($filename));
                !empty($relativized_css) && @Ak::file_put_contents($filename, $relativized_css);
            }
        }
    }
Пример #21
0
 /**
  * @todo Refactor this method
  */
 function updateLocaleFiles()
 {
     $new_core_entries = array();
     $new_controller_entries = array();
     $new_controller_files = array();
     $used_entries = AkLocaleManager::getUsedLanguageEntries();
     require AK_CONFIG_DIR . DS . 'locales' . DS . AK_FRAMEWORK_LANGUAGE . '.php';
     $core_dictionary = $dictionary;
     $controllers_dictionaries = array();
     foreach ($used_entries as $k => $v) {
         // This is a controller file
         if (is_array($v)) {
             if (!isset($controllers_dictionaries[$k])) {
                 $controller = $k;
                 $module_lang_file = AK_APP_DIR . DS . 'locales' . DS . $controller . DS . AK_FRAMEWORK_LANGUAGE . '.php';
                 if (is_file($module_lang_file)) {
                     require $module_lang_file;
                     $controllers_dictionaries[$controller] = array_merge((array) $dictionary, (array) $v);
                     $existing_controllers_dictionaries[$controller] = (array) $dictionary;
                 } else {
                     $controllers_dictionaries[$controller] = (array) $v;
                     $new_controller_files[$controller] = $module_lang_file;
                 }
             }
         } else {
             if (!isset($core_dictionary[$k])) {
                 $new_core_entries[$k] = $k;
             }
         }
     }
     $dictionary_file = '';
     foreach ($new_controller_files as $controller => $file_name) {
         $dictionary_file = "<?php\n\n// File created on: " . date("Y-m-d G:i:s", Ak::time()) . "\n\n\$dictionary = array();\n\n";
         foreach ($controllers_dictionaries[$controller] as $k => $entry) {
             $entry = str_replace("'", "\\'", $entry);
             $dictionary_file .= "\n\$dictionary['{$entry}'] = '{$entry}';";
         }
         unset($controllers_dictionaries[$controller]);
         $dictionary_file .= "\n\n\n?>";
         Ak::file_put_contents($file_name, $dictionary_file);
     }
     // Module files
     foreach ((array) $controllers_dictionaries as $controller => $controller_entries) {
         $dictionary_file = '';
         foreach ($controller_entries as $entry) {
             if ($entry == '' || isset($existing_controllers_dictionaries[$controller][$entry])) {
                 continue;
             }
             $entry = str_replace("'", "\\'", $entry);
             $dictionary_file .= "\n\$dictionary['{$entry}'] = '{$entry}';";
         }
         if ($dictionary_file != '') {
             $original_file = Ak::file_get_contents(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . AK_FRAMEWORK_LANGUAGE . '.php');
             $original_file = rtrim($original_file, "?> \n\r");
             $new_entries = "\n\n// " . date("Y-m-d G:i:s", Ak::time()) . "\n\n" . $dictionary_file . "\n\n\n?>\n";
             $dictionary_file = $original_file . $new_entries;
             Ak::file_put_contents(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . AK_FRAMEWORK_LANGUAGE . '.php', $dictionary_file);
             foreach (Ak::langs() as $lang) {
                 if ($lang != AK_FRAMEWORK_LANGUAGE) {
                     $lang_file = @Ak::file_get_contents(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . $lang . '.php');
                     if (empty($lang_file)) {
                         $dictionary_file = $original_file;
                     } else {
                         $lang_file = rtrim($lang_file, "?> \n\r");
                         $dictionary_file = $lang_file;
                     }
                     Ak::file_put_contents(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . $lang . '.php', $dictionary_file . $new_entries);
                 }
             }
         }
     }
     // Core locale files
     $dictionary_file = '';
     foreach ($new_core_entries as $core_entry) {
         if ($core_entry == '') {
             continue;
         }
         $core_entry = str_replace("'", "\\'", $core_entry);
         $dictionary_file .= "\n\$dictionary['{$core_entry}'] = '{$core_entry}';";
     }
     if ($dictionary_file != '') {
         $original_file = Ak::file_get_contents(AK_CONFIG_DIR . DS . 'locales' . DS . AK_FRAMEWORK_LANGUAGE . '.php');
         $original_file = rtrim($original_file, "?> \n\r");
         $new_entries = "\n\n// " . date("Y-m-d G:i:s", Ak::time()) . "\n\n" . $dictionary_file . "\n\n\n?>\n";
         $dictionary_file = $original_file . $new_entries;
         Ak::file_put_contents(AK_CONFIG_DIR . DS . 'locales' . DS . AK_FRAMEWORK_LANGUAGE . '.php', $dictionary_file);
         foreach (Ak::langs() as $lang) {
             if ($lang != AK_FRAMEWORK_LANGUAGE) {
                 $lang_file = Ak::file_get_contents(AK_CONFIG_DIR . DS . 'locales' . DS . $lang . '.php');
                 if (empty($lang_file)) {
                     $dictionary_file = str_replace("\$locale['description'] = 'English';", "\$locale['description'] = '{$lang}';", $original_file);
                 } else {
                     $lang_file = rtrim($lang_file, "?> \n\r");
                     $dictionary_file = $lang_file;
                 }
                 Ak::file_put_contents(AK_CONFIG_DIR . DS . 'locales' . DS . $lang . '.php', $dictionary_file . $new_entries);
             }
         }
     }
 }
Пример #22
0
 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;
 }
Пример #23
0
 function _removeMethodFromClass($path, $name, $pluginName)
 {
     return Ak::file_put_contents($path, preg_replace("|(\n[^\n]*?/\\*\\* AUTOMATED START: {$pluginName}::{$name} \\*/.*?/\\*\\* AUTOMATED END: {$pluginName}::{$name} \\*/\n)|s", "", Ak::file_get_contents($path)));
 }
Пример #24
0
 public function _config($key = null, $value = null, $environment = AK_ENVIRONMENT, $unset = false)
 {
     if (AkDbSchemaCache::shouldRefresh()) {
         return false;
     }
     static $config;
     if (!isset($config[$environment])) {
         $file_name = AkDbSchemaCache::getCacheFileName($environment);
         $config[$environment] = file_exists($file_name) ? unserialize(Ak::file_get_contents($file_name)) : array();
         if (AK_LOG_EVENTS) {
             $Logger =& Ak::getLogger();
             $Logger->message('Loading cached database settings');
         }
     }
     if (!is_null($key)) {
         if (!is_null($value)) {
             $config[$environment][$key] = $value;
         } elseif ($unset) {
             unset($config[$environment][$key]);
         }
         return isset($config[$environment][$key]) ? $config[$environment][$key] : false;
     }
     return $config[$environment];
 }
Пример #25
0
<?php

error_reporting(E_ALL);
defined('AK_ENVIRONMENT') ? null : define('AK_ENVIRONMENT', 'testing');
defined('AK_TEST_DIR') ? null : define('AK_TEST_DIR', str_replace(DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php', '', __FILE__));
defined('AK_APP_DIR') ? null : define('AK_APP_DIR', AK_TEST_DIR . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'app');
defined('AK_PUBLIC_DIR') ? null : define('AK_PUBLIC_DIR', AK_TEST_DIR . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'public');
defined('AK_TEST_HELPERS_DIR') ? null : define('AK_TEST_HELPERS_DIR', AK_TEST_DIR . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'helpers');
define('AK_SITE_URL_SUFFIX', str_replace(array(join(DIRECTORY_SEPARATOR, array_diff((array) @explode(DIRECTORY_SEPARATOR, AK_TEST_DIR), (array) @explode('/', @$_SERVER['REQUEST_URI']))), DIRECTORY_SEPARATOR), array('', '/'), AK_TEST_DIR));
defined('AK_ENABLE_AKELOS_ARGS') ? null : define('AK_ENABLE_AKELOS_ARGS', true);
//define('AK_SKIP_DB_CONNECTION',isset($db) && $db === false);
defined('AK_URL_REWRITE_ENABLED') ? null : define('AK_URL_REWRITE_ENABLED', true);
include_once substr(AK_TEST_DIR, 0, -5) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
defined('AK_APP_LOCALES') ? null : define('AK_APP_LOCALES', 'en,es');
defined('AK_PUBLIC_LOCALES') ? null : define('AK_PUBLIC_LOCALES', AK_APP_LOCALES);
defined('AK_ACTIVE_RECORD_INTERNATIONALIZE_MODELS_BY_DEFAULT') ? null : define('AK_ACTIVE_RECORD_INTERNATIONALIZE_MODELS_BY_DEFAULT', true);
defined('AK_ACTIVE_RECORD_ENABLE_AUTOMATIC_SETTERS_AND_GETTERS') ? null : define('AK_ACTIVE_RECORD_ENABLE_AUTOMATIC_SETTERS_AND_GETTERS', true);
defined('AK_TESTING_URL') ? null : define('AK_TESTING_URL', rtrim(AK_URL, '/') . '/test/fixtures/public');
defined('AK_TESTING_REWRITE_BASE') ? null : define('AK_TESTING_REWRITE_BASE', false);
defined('AK_LIB_TESTS_DIRECTORY') ? null : define('AK_LIB_TESTS_DIRECTORY', AK_TEST_DIR . DS . 'unit' . DS . 'lib');
if (AK_TESTING_REWRITE_BASE) {
    Ak::file_put_contents(AK_BASE_DIR . '/test/fixtures/public/.htaccess', str_replace('# RewriteBase /test/fixtures/public', 'RewriteBase ' . AK_TESTING_REWRITE_BASE, Ak::file_get_contents(AK_BASE_DIR . '/test/fixtures/public/.htaccess')));
}
if (defined('AK_TEST_DATABASE_ON')) {
    $default_profile = array_key_exists($argv[count($argv) - 1], $database_settings) ? array_pop($argv) : AK_ENVIRONMENT;
    define('AK_DEFAULT_DATABASE_PROFILE', $default_profile);
    include_once AK_LIB_DIR . DS . 'Ak.php';
    Ak::db();
    unset($default_profile);
}
require_once AK_LIB_DIR . DS . 'AkUnitTest.php';
Пример #26
0
 function _canIncludeMergedFile($class_name_to_extend, $checksum)
 {
     $merge_path = AK_TMP_DIR . DS . '.lib';
     if (AK_CLASS_EXTENDER_ENABLE_CACHE && file_exists($merge_path . DS . 'Extensible' . $class_name_to_extend . '.php') && Ak::file_get_contents($merge_path . DS . 'checksums' . DS . 'Extensible' . $class_name_to_extend) == $checksum) {
         return true;
     }
     return false;
 }
Пример #27
0
 function Test_of_compress_decompress()
 {
     $original = Ak::file_get_contents(__FILE__);
     $compressed = Ak::compress($original);
     Ak::file_put_contents(AK_TMP_DIR . DS . 'gzip_test.gz', $compressed, array('base_path' => AK_TMP_DIR));
     $this->assertTrue(strlen($compressed) < strlen($original));
     $compressed_file = Ak::file_get_contents(AK_TMP_DIR . DS . 'gzip_test.gz', array('base_path' => AK_TMP_DIR));
     $this->assertEqual($compressed_file, $compressed);
     $uncompressed_from_file = Ak::uncompress($compressed_file);
     $uncompressed_from_string = Ak::uncompress($compressed);
     $this->assertEqual($uncompressed_from_file, $uncompressed_from_string);
 }
Пример #28
0
 /**
  * This method reads a template file.
  */
 function _readTemplateFile($template_path)
 {
     return Ak::file_get_contents($template_path);
 }
Пример #29
0
 public function getPersistedCookie()
 {
     if(file_exists($this->_cookie_path)){
         return Ak::file_get_contents($this->_cookie_path);
     }
     return false;
 }
Пример #30
0
    /**
    * This method tries to determine if url rewrite is enabled on this server.
    * It has only been tested on apache.
    * It is strongly recomended that you manually define the constant 
    * AK_URL_REWRITE_ENABLED on your config file to the avoid overload
    * this function causes and to prevent from missfunctioning
    */
    function _loadUrlRewriteSettings()
    {
        static $result;
        if(isset($result)){
            return $result;
        }

        if(defined('AK_URL_REWRITE_ENABLED')){
            $result = AK_URL_REWRITE_ENABLED;
            return AK_URL_REWRITE_ENABLED;
        }
        if(AK_DESKTOP){
            if(!defined('AK_URL_REWRITE_ENABLED')){
                define('AK_URL_REWRITE_ENABLED',false);
                $result = AK_URL_REWRITE_ENABLED;
                return false;
            }
        }
        if(defined('AK_ENABLE_URL_REWRITE') && AK_ENABLE_URL_REWRITE == false){
            if(!defined('AK_URL_REWRITE_ENABLED')){
                define('AK_URL_REWRITE_ENABLED',false);
            }
            $result = AK_URL_REWRITE_ENABLED;
            return false;
        }

        $url_rewrite_status = false;

        //echo '<pre>'.print_r(get_defined_functions(), true).'</pre>';

        if( isset($_SERVER['REDIRECT_STATUS'])
        && $_SERVER['REDIRECT_STATUS'] == 200
        && isset($_SERVER['REDIRECT_QUERY_STRING'])
        && strstr($_SERVER['REDIRECT_QUERY_STRING'],'ak=')){

            if(strstr($_SERVER['REDIRECT_QUERY_STRING'],'&')){
                $tmp_arr = explode('&',$_SERVER['REDIRECT_QUERY_STRING']);
                $ak_request = $tmp_arr[0];
            }else{
                $ak_request = $_SERVER['REDIRECT_QUERY_STRING'];
            }
            $ak_request = trim(str_replace('ak=','',$ak_request),'/');

            if(strstr($_SERVER['REDIRECT_URL'],$ak_request)){
                $url_rewrite_status = true;
            }else {
                $url_rewrite_status = false;
            }
        }

        // We check if available by investigating the .htaccess file if no query has been set yet
        elseif(function_exists('apache_get_modules')){

            $available_modules = apache_get_modules();

            if(in_array('mod_rewrite',(array)$available_modules)){

                // Local session name is changed intentionally from .htaccess
                // So we can see if the file has been loaded.
                // if so, we restore the session.name to its original
                // value
                if(ini_get('session.name') == 'AK_SESSID'){
                    $session_name = defined('AK_SESSION_NAME') ? AK_SESSION_NAME : get_cfg_var('session.name');
                    ini_set('session.name',$session_name);
                    $url_rewrite_status = true;

                    // In some cases where session.name cant be set up by htaccess file,
                    // we can check for modrewrite status on this file
                }elseif (file_exists(AK_BASE_DIR.DS.'.htaccess')){
                    $htaccess_file = Ak::file_get_contents(AK_BASE_DIR.DS.'.htaccess');
                    if(stristr($htaccess_file,'RewriteEngine on')){
                        $url_rewrite_status = true;
                    }
                }
            }

            // If none of the above works we try to fetch a file that should be remaped
        }elseif (isset($_SERVER['REDIRECT_URL']) && $_SERVER['REDIRECT_URL'] == '/' && isset($_SERVER['REDIRECT_STATUS']) && $_SERVER['REDIRECT_STATUS'] == 200){
            $url_rewrite_test_url = AK_URL.'mod_rewrite_test';
            if(!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])){
                $url_rewrite_test_url = AK_PROTOCOL.$_SERVER['PHP_AUTH_USER'].':'.$_SERVER['PHP_AUTH_PW'].'@'.AK_HOST.'/mod_rewrite_test';
            }

            $url_rewrite_status = strstr(@file_get_contents($url_rewrite_test_url), 'AK_URL_REWRITE_ENABLED');
            $AK_URL_REWRITE_ENABLED = "define(\\'AK_URL_REWRITE_ENABLED\\', ".($url_rewrite_status ? 'true' : 'false').");\n";

            register_shutdown_function(create_function('',"Ak::file_put_contents(AK_CONFIG_DIR.DS.'config.php',
            str_replace('<?php\n','<?php\n\n$AK_URL_REWRITE_ENABLED',Ak::file_get_contents(AK_CONFIG_DIR.DS.'config.php')));"));
        }



        if(!defined('AK_URL_REWRITE_ENABLED')){
            define('AK_URL_REWRITE_ENABLED', $url_rewrite_status);
        }
        $result = AK_URL_REWRITE_ENABLED;
        return AK_URL_REWRITE_ENABLED;
    }