Esempio n. 1
0
 public function insert_prevent_direct_access($post_id, $is_prevented)
 {
     $repository = new Repository();
     $file_info = array('time' => current_time('mysql'), 'post_id' => $post_id, 'is_prevented' => $is_prevented, 'url' => Pda_Helper::generate_unique_string());
     $result = $repository->create_advance_file($file_info);
     if ($result < 1 || $result === false) {
         $file_result = array('error' => "Cannot create file advance's info");
     } else {
         $file_result = $repository->get_advance_file_by_post_id($file_info['post_id']);
         $generated_file_code = $file_result->url;
         $file_result->url = site_url() . '/private/' . $file_result->url;
     }
     return $file_result;
 }
Esempio 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>';
    }
}