示例#1
0
 function testLogreturn()
 {
     wpro()->debug->logblock('dummy');
     $r = wpro()->debug->logreturn('test');
     $this->assertTrue(wpro()->debug->is_in_cache("return: 'test'"));
     wpro()->debug->clean_debug_cache();
 }
示例#2
0
 function testSetAndGetOption()
 {
     $option = 'wpro_testSetAndGetOption';
     $value = 'test value';
     wpro()->options->register($option);
     wpro()->options->set($option, $value);
     $this->assertEquals($value, wpro()->options->get($option));
     wpro()->options->deregister($option);
 }
示例#3
0
 function testAllAdminMethodsExist()
 {
     $this->assertTrue(method_exists(wpro()->admin, 'admin_form'));
     $this->assertTrue(method_exists(wpro()->admin, 'admin_init'));
     $this->assertTrue(method_exists(wpro()->admin, 'admin_menu'));
     $this->assertTrue(method_exists(wpro()->admin, 'admin_post'));
     $this->assertTrue(method_exists(wpro()->admin, 'is_trusted'));
     $this->assertTrue(method_exists(wpro()->admin, 'network_admin_menu'));
 }
示例#4
0
 function register($backend_class_name)
 {
     $log = wpro()->debug->logblock('WPRO_Backends::register()');
     if ($this->has_backend($backend_class_name::NAME)) {
         return $log->logreturn(false);
     }
     $this->backends[$backend_class_name::NAME] = new $backend_class_name();
     return $log->logreturn(true);
 }
示例#5
0
 function testTheIsBackendActivatedFunction()
 {
     wpro()->backends->deactivate_backend();
     $this->assertFalse(wpro()->backends->is_backend_activated());
     $backendName = 'Custom Filesystem Path';
     wpro()->backends->activate_backend($backendName);
     $this->assertTrue(wpro()->backends->is_backend_activated());
     wpro()->backends->deactivate_backend();
     $this->assertFalse(wpro()->backends->is_backend_activated());
 }
示例#6
0
 function testCleanUpTempDirectories()
 {
     $tmpfname = tempnam('/tmp', 'FOO');
     unlink($tmpfname);
     mkdir($tmpfname);
     $this->assertTrue(is_dir($tmpfname));
     wpro()->tmpdir->cleanUpDirs[] = $tmpfname;
     wpro()->tmpdir->cleanUp();
     $this->assertFalse(is_dir($tmpfname));
 }
示例#7
0
文件: url.php 项目: kamatama41/wpro
 function upload_dir($data)
 {
     $log = wpro()->debug->logblock('WPRO_Url::upload_dir()');
     $backend = wpro()->backends->active_backend;
     if (is_null($backend)) {
         return $log->logreturn($data);
     }
     $baseurl = trim(apply_filters('wpro_backend_retrieval_baseurl', $data['baseurl']), '/');
     return $log->logreturn(array('path' => wpro()->tmpdir->reqTmpDir() . $data['subdir'], 'url' => $baseurl . $data['subdir'], 'subdir' => $data['subdir'], 'basedir' => wpro()->tmpdir->reqTmpDir(), 'baseurl' => $baseurl, 'error' => false));
 }
示例#8
0
 function cleanUp()
 {
     $log = wpro()->debug->logblock('WPRO_TmpDir::cleanUp()');
     foreach ($this->cleanUpDirs as $tmpDir) {
         $log->log('Clean up dir: ' . $tmpDir);
         if (is_dir($tmpDir)) {
             $this->rmdirRecursive($tmpDir);
         }
     }
     return $log->logreturn(true);
 }
示例#9
0
 function testUploadDirFilterShouldReturnProperDataIfThereIsABackend()
 {
     wpro()->backends->activate_backend('Amazon S3');
     // Only subdir and baseurl needed:
     $result = wpro()->url->upload_dir(array('subdir' => '/1973/09', 'baseurl' => 'http://example.org/wp-content/uploads'));
     $this->assertStringStartsWith($result['basedir'], $result['path']);
     $this->assertStringStartsWith($result['baseurl'], $result['url']);
     $this->assertStringEndsWith($result['subdir'], $result['path']);
     $this->assertStringEndsWith($result['subdir'], $result['url']);
     wpro()->backends->deactivate_backend();
 }
示例#10
0
文件: http.php 项目: kamatama41/wpro
 function url_exists($url)
 {
     $log = wpro()->debug->logblock('WPRO_Http::url_exists($url = "' . $url . '")');
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_NOBODY, 1);
     curl_setopt($ch, CURLOPT_URL, $url);
     $result = trim(curl_exec_follow($ch));
     $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if ($httpCode != 200) {
         return $log->logreturn(false);
     }
     return $log->logreturn(true);
 }
示例#11
0
文件: wpcli.php 项目: kamatama41/wpro
 /**
  * List options.
  * 
  * ## OPTIONS
  * 
  *     --keys - Only list the option keys, not the values.
  *
  * ## EXAMPLES
  * 
  *     wp wpro list_options
  *     wp wpro list_options --keys
  *
  * @synopsis
  */
 function list_options($args, $assoc_args)
 {
     $options = wpro()->options->get_all_options();
     if (isset($assoc_args['keys'])) {
         foreach ($options as $key => $val) {
             echo $key . "\n";
         }
     } else {
         foreach ($options as $key => $val) {
             echo $key . '=' . $val . "\n";
         }
     }
 }
示例#12
0
文件: edit.php 项目: kamatama41/wpro
 function save_image_editor_file($dummy, $filename, $image, $mime_type, $post_id)
 {
     // This function is called when an image has been edited.
     // The $image variable is the ImageMagick data object of the new image.
     $log = wpro()->debug->logblock('WPRO_Uploads::save_image_editor_file($dummy = "' . $dummy . '", $filename = "' . $filename . '", $image, $mime_type = "' . $mime_type . '", $post_id = ' . $post_id . ')');
     if (!wpro()->backends->is_backend_activated()) {
         $log->log('Backend not activated.');
         return $log->logreturn(null);
     }
     // Just test so we are really using a temporary directory as work dir.
     $reqTmpDir = wpro()->tmpdir->reqTmpDir();
     if (substr($filename, 0, strlen($reqTmpDir)) != $reqTmpDir) {
         return $log->logreturn(false);
     }
     $image->save($filename, $mime_type);
     apply_filters('wpro_backend_store_file', array('file' => $filename, 'url' => wpro()->url->attachmentUrl($filename), 'type' => $mime_type));
     return $log->logreturn(true);
 }
示例#13
0
 function testUploadHandleFunction()
 {
     // Create a 1x1 pixel transparent PNG:
     $tmpfname = tempnam('/tmp', 'WPROTEST');
     wpro()->tmpdir->cleanUpDirs[] = $tmpfname;
     $fh = fopen($tmpfname, 'w');
     $transparentpng = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=';
     fwrite($fh, base64_decode($transparentpng));
     fclose($fh);
     $tmpdir = tempnam('/tmp', 'WPROTESTFSPATH');
     unlink($tmpdir);
     mkdir($tmpdir);
     //wpro()->tmpdir->cleanUpDirs[] = $tmpdir;
     wpro()->backends->activate_backend('Custom Filesystem Path');
     wpro()->options->set('wpro-fs-baseurl', 'http://example.org/');
     wpro()->options->set('wpro-fs-path', $tmpdir);
     do_action('wpro_backend_store_file', array('file' => $tmpfname, 'url' => 'http://www.example.org/wp-content/uploads/2014/05/test.png', 'type' => 'image/png'));
     wpro()->backends->deactivate_backend();
     $this->assertEquals(base64_encode(file_get_contents($tmpdir . '/2014/05/test.png')), $transparentpng);
 }
示例#14
0
 function gravityforms_after_submission($entry, $form)
 {
     $log = wpro()->debug->logblock('WPRO_Gravityforms::gravityforms_after_submission()');
     $upload_dir = wp_upload_dir();
     foreach ($form['fields'] as $field) {
         if ($field['type'] == 'fileupload') {
             $id = (int) $field['id'];
             $file_to_upload = $entry[$id];
             if ($file_to_upload) {
                 $url = $entry[$id];
                 $file_to_upload = str_replace($upload_dir['baseurl'], $upload_dir['basedir'], $file_to_upload);
                 $mime = wp_check_filetype($file_to_upload);
                 $response = $this->backend->upload($file_to_upload, $url, $mime['type']);
                 if (!$response) {
                     return $log->logreturn(false);
                 }
             }
         }
     }
     return $log->logreturn(true);
 }
示例#15
0
文件: debug.php 项目: kamatama41/wpro
 function wp_handle_upload_error(&$file, $message)
 {
     $log = wpro()->debug->logblock('wp_handle_upload_error()');
     $log->log('$file = ' . var_export($file, true));
     $log->log('$message = ' . var_export($message, true));
     if (file_exists($file['tmp_name'])) {
         $log->log('Temporary file still exists.');
         $log->log('File size: ' . filesize($file['tmp_name']));
     } else {
         $log->log('Temporary file does not exist (anymore).');
     }
     $upload_dir = wp_upload_dir();
     if (!is_dir($upload_dir['basedir'])) {
         if (file_exists($upload_dir['basedir'])) {
             $log->log('Upload basedir is NOT a directory: ' . $upload_dir['basedir']);
         } else {
             $log->log('Upload basedir DOES NOT exist: ' . $upload_dir['basedir']);
         }
     } else {
         $log->log('Upload basedir exists: ' . $upload_dir['basedir']);
     }
     return $log->logreturn(array('error' => $message));
 }
示例#16
0
文件: admin.php 项目: kamatama41/wpro
 function network_admin_menu()
 {
     $log = wpro()->debug->logblock('WPRO_Admin::network_admin_menu()');
     add_submenu_page('settings.php', 'WPRO Plugin Settings', 'WPRO Settings', 'manage_options', 'wpro', array($this, 'admin_form'));
     return $log->logreturn(true);
 }
示例#17
0
 function testUrlExists()
 {
     $this->assertTrue(wpro()->http->url_exists('http://www.sunet.se/'));
     $this->assertFalse(wpro()->http->url_exists('http://www.google.com/fuckingshit'));
     // Yakees would never dare to have such an url. It would be http://www.google.com/beeeeepbeep in their world.
 }
示例#18
0
文件: wpro.php 项目: kamatama41/wpro
    public static function instance()
    {
        if (!isset(self::$instance)) {
            self::$instance = new WPRO_Core();
            self::$instance->construct_singleton();
            // Instead of __construct
        }
        return self::$instance;
    }
    /**
     * Prevent cloning
     */
    function __clone()
    {
    }
    /**
     * Prevent unserializing
     */
    function __wakeup()
    {
    }
}
/**
 * Allow direct access to WPRO classes
 */
function wpro()
{
    return WPRO_Core::instance();
}
wpro();
示例#19
0
 function upload_bits($data)
 {
     $log = wpro()->debug->logblock('WPRO_Uploads::upload_bits()');
     $log->log('$data["name"] = "' . $data['name'] . '";');
     $log->log('$data["time"] = "' . $data['time'] . '";');
     $log->log('Data size: ' . strlen($data['bits']));
     if (!wpro()->backends->is_backend_activated()) {
         $log->log('There is no backend.');
         $log->logblockend();
         return $data;
     }
     $ending = '';
     if (preg_match('/\\.([^\\.\\/]+)$/', $data['name'], $regs)) {
         $ending = '.' . $regs[1];
     }
     $tmpfile = wpro()->tmpdir->reqTmpDir() . '/wpro' . time() . rand(0, 999999) . $ending;
     while (file_exists($tmpfile)) {
         $tmpfile = wpro()->tmpdir->reqTmpDir() . '/wpro' . time() . rand(0, 999999) . $ending;
     }
     $fh = fopen($tmpfile, 'wb');
     fwrite($fh, $data['bits']);
     fclose($fh);
     $upload = wp_upload_dir();
     return $log->logreturn(array('file' => $tmpfile, 'url' => rtrim($upload['url'], '/') . '/' . $data['name'], 'error' => false));
 }
示例#20
0
 function url($value)
 {
     $log = wpro()->debug->logblock('WPRO_Backend_Filesystem::url()');
     // Remove trailing slashes.
     $url = rtrim(wpro()->options->get('wpro-fs-baseurl'), '/');
     return $log->logreturn($url);
 }
示例#21
0
 function url($value)
 {
     $log = wpro()->debug->logblock('WPRO_Backend_S3::url()');
     $protocol = 'http';
     if (wpro()->options->get('wpro-aws-ssl')) {
         $protocol = 'https';
     }
     if (wpro()->options->get_option('wpro-aws-virthost')) {
         $url = $protocol . '://' . wpro()->options->get('wpro-aws-bucket') . '/';
     } else {
         $url = $protocol . '://' . wpro()->options->get('wpro-aws-bucket') . '.' . wpro()->options->get('wpro-aws-endpoint') . '/';
     }
     if (strlen($folder = trim(wpro()->options->get_option('wpro-folder'), '/'))) {
         $url .= $folder;
     }
     return $log->logreturn($url);
 }
示例#22
0
 function set($option, $value)
 {
     $log = wpro()->debug->logblock('WPRO_Options::set($option = "' . $option . '", $value = "' . $value . '")');
     if (!$this->is_an_option($option)) {
         return false;
     }
     return $log->logreturn(update_site_option($option, $value));
 }
示例#23
0
文件: cdn.php 项目: kamatama41/wpro
 function __construct()
 {
     $log = wpro()->debug->logblock('WPRO_CDN::__construct()');
     $cdns = array();
     return $log->logreturn(true);
 }
示例#24
0
 function testSaveImageEditorFileShouldReturnNullWhenNoBackend()
 {
     $this->assertNull(wpro()->edit->save_image_editor_file('', 'filename', 'image', 'some/mime', 1));
 }