Ejemplo n.º 1
0
 public function htaccess_contents($rules)
 {
     // eg. index.php?pre_dir_acc_61co625547=$1 [R=301,L]
     $configs = Pda_Helper::get_plugin_configs();
     $endpoint = $configs['endpoint'];
     $downloadFileRedirect = str_replace(trailingslashit(site_url()), '', 'index.php') . "?{$endpoint}=\$1 [R=301,L]" . PHP_EOL;
     $newRule = "RewriteRule private/([a-zA-Z0-9]+)\$ " . $downloadFileRedirect;
     $newRule .= "RewriteCond %{REQUEST_FILENAME} -s" . PHP_EOL;
     $directAccessPath = str_replace(trailingslashit(site_url()), '', 'index.php') . "?{$endpoint}=\$1&is_direct_access=true&file_type=\$2 [QSA,L]" . PHP_EOL;
     // eg. RewriteRule wp-content/uploads(/[a-zA-Z_\-\s0-9\.]+)+\.([a-zA-Z0-9]+)$ index.php?pre_dir_acc_61co625547=$1&is_direct_access=true&file_type=$2 [QSA,L]
     $newRule .= "RewriteRule " . str_replace(trailingslashit(site_url()), '', wp_upload_dir()['baseurl']) . "(/[a-zA-Z_\\-\\s0-9\\.]+)+\\.([a-zA-Z0-9]+)\$ " . $directAccessPath;
     return $newRule . $rules . "Options -Indexes" . PHP_EOL;
 }
Ejemplo n.º 2
0
function show_file_from_private_link()
{
    $configs = Pda_Helper::get_plugin_configs();
    $endpoint = $configs['endpoint'];
    if (isset($_GET[$endpoint])) {
        $private_url = $_GET[$endpoint];
        $repository = new Repository();
        $advance_file = $repository->get_advance_file_by_url($private_url);
        if (isset($advance_file) && $advance_file->is_prevented === "1") {
            $post_id = $advance_file->post_id;
            $post = $repository->get_post_by_id($post_id);
            if (isset($post)) {
                download_file($post);
            } else {
                echo '<h2>Sorry! Invalid post!</h2>';
            }
        } else {
            echo '<h2>Sorry! Invalid url!</h2>';
        }
    } else {
        echo '<h2>Sorry! Invalid url!</h2>';
    }
}