function ninja_forms_external_url()
{
    if (isset($_GET['nf-upload'])) {
        $args = array('id' => $_GET['nf-upload']);
        $upload = ninja_forms_get_uploads($args);
        $external = NF_Upload_External::instance($upload['data']['upload_location']);
        if ($external) {
            $path = isset($upload['data']['external_path']) ? $upload['data']['external_path'] : '';
            $file_url = $external->file_url($upload['data']['file_name'], $path);
        }
        wp_redirect($file_url);
        die;
    }
}
Esempio n. 2
0
File: ajax.php Progetto: webtlp/gdid
function ninja_forms_delete_upload($upload_id = '')
{
    global $wpdb;
    if (isset($_REQUEST['upload_id']) and $upload_id == '') {
        $upload_id = $_REQUEST['upload_id'];
    }
    $args = array('id' => $upload_id);
    $upload_row = ninja_forms_get_uploads($args);
    $upload_data = $upload_row['data'];
    if (is_array($upload_data) and isset($upload_data['file_path'])) {
        $file = $upload_data['file_path'] . $upload_data['file_name'];
        if (file_exists($file)) {
            unlink($file);
        }
    }
    $wpdb->query($wpdb->prepare("DELETE FROM " . NINJA_FORMS_UPLOADS_TABLE_NAME . " WHERE id = %d", $upload_id));
    if (isset($_REQUEST['upload_id'])) {
        die;
    }
}
Esempio n. 3
0
function ninja_forms_tab_browse_uploads()
{
    global $wpdb;
    $plugin_settings = get_option("ninja_forms_settings");
    //Check for filters
    $args = array();
    if (isset($_POST['form_id']) and $_POST['form_id'] == 'all') {
        unset($_SESSION['ninja_forms_form_id']);
    } else {
        if (isset($_POST['form_id']) and $_POST['form_id'] != 'all') {
            $args['form_id'] = $_POST['form_id'];
            $_SESSION['ninja_forms_form_id'] = $_POST['form_id'];
        } else {
            if (isset($_SESSION['ninja_forms_form_id']) and $_SESSION['ninja_forms_form_id'] != 'all') {
                $args['form_id'] = $_SESSION['ninja_forms_form_id'];
            }
        }
    }
    if (isset($_POST['begin_date']) and !empty($_POST['begin_date'])) {
        $args['begin_date'] = $_POST['begin_date'];
    } else {
        if (isset($_SESSION['ninja_forms_begin_date']) and !empty($_SESSION['ninja_forms_begin_date'])) {
            $args['begin_date'] = $_SESSION['ninja_forms_begin_date'];
        }
    }
    if (isset($_POST['end_date']) and !empty($_POST['end_date'])) {
        $args['end_date'] = $_POST['end_date'];
    } else {
        if (isset($_SESSION['ninja_forms_end_date']) and !empty($_SESSION['ninja_forms_end_date'])) {
            $args['end_date'] = $_SESSION['ninja_forms_end_date'];
        }
    }
    if (isset($_POST['upload_types']) and !empty($_POST['upload_types'])) {
        $args['upload_types'] = $_POST['upload_types'];
    } else {
        if (isset($_SESSION['ninja_forms_upload_types']) and !empty($_SESSION['ninja_forms_upload_types'])) {
            $args['upload_types'] = $_SESSION['ninja_forms_upload_types'];
        }
    }
    if (isset($_POST['upload_name']) and !empty($_POST['upload_name'])) {
        $args['upload_name'] = $_POST['upload_name'];
    } else {
        if (isset($_SESSION['ninja_forms_upload_name']) and !empty($_SESSION['ninja_forms_upload_name'])) {
            $args['upload_name'] = $_SESSION['ninja_forms_upload_name'];
        }
    }
    if (isset($_POST['upload_user']) and !empty($_POST['upload_user'])) {
        $args['upload_user'] = $_POST['upload_user'];
    } else {
        if (isset($_SESSION['ninja_forms_upload_user']) and !empty($_SESSION['ninja_forms_upload_user'])) {
            $args['upload_user'] = $_SESSION['ninja_forms_upload_user'];
        }
    }
    if (isset($_POST['order_by']) and !empty($_POST['order_by'])) {
        $args['order_by'] = $_POST['order_by'];
    } else {
        if (isset($_SESSION['ninja_forms_upload_order_by']) and !empty($_SESSION['ninja_forms_upload_order_by'])) {
            $args['order_by'] = $_SESSION['ninja_forms_upload_order_by'];
        } else {
            $args['order_by'] = 'date_updated';
        }
    }
    $all_files = ninja_forms_get_uploads($args);
    $upload_count = count($all_files);
    if (isset($_POST['limit'])) {
        $saved_limit = $_POST['limit'];
        $limit = $_POST['limit'];
    } else {
        $saved_limit = 20;
        $limit = 20;
    }
    if ($upload_count < $limit) {
        $limit = $upload_count;
    }
    if (isset($_REQUEST['paged']) and !empty($_REQUEST['paged'])) {
        $current_page = $_REQUEST['paged'];
    } else {
        $current_page = 1;
    }
    if ($upload_count > $limit) {
        $page_count = ceil($upload_count / $limit);
    } else {
        $page_count = 1;
    }
    if ($current_page > 1) {
        $start = ($current_page - 1) * $limit;
        if ($upload_count < $limit) {
            $end = $upload_count;
        } else {
            $end = $current_page * $limit;
        }
        if ($end > $upload_count) {
            $end = $upload_count;
        }
    } else {
        $start = 0;
        $end = $limit;
    }
    ?>
		<div id="" class="tablenav top">
			<div class="alignleft actions">
				<select id="" class="" name="bulk_action">
					<option value=""><?php 
    _e('Bulk Actions', 'ninja-forms');
    ?>
</option>
					<option value="delete"><?php 
    _e('Delete', 'ninja-forms');
    ?>
</option>
				</select>
				<input type="submit" name="submit" value="Apply" class="button-secondary">
			</div>
			<div class="alignleft actions">
				<select id="" name="limit">
					<option value="20" <?php 
    selected($saved_limit, 20);
    ?>
>20</option>
					<option value="50" <?php 
    selected($saved_limit, 50);
    ?>
>50</option>
					<option value="100" <?php 
    selected($saved_limit, 100);
    ?>
>100</option>
				</select>
				<?php 
    _e('Uploads Per Page', 'ninja-forms');
    ?>
				<input type="submit" name="submit" value="Go" class="button-secondary">
			</div>
			<div id="" class="alignright navtable-pages">
				<?php 
    if ($upload_count != 0 and $current_page <= $page_count) {
        ?>
				<span class="displaying-num"><?php 
        if ($start == 0) {
            echo 1;
        } else {
            echo $start;
        }
        ?>
 - <?php 
        echo $end;
        ?>
 of <?php 
        echo $upload_count;
        ?>
 <?php 
        if ($upload_count == 1) {
            _e('Upload', 'ninja-forms');
        } else {
            _e('Uploads', 'ninja-forms');
        }
        ?>
</span>
				<?php 
    }
    if ($page_count > 1) {
        $first_page = add_query_arg(array('paged' => 1));
        $last_page = add_query_arg(array('paged' => $page_count));
        if ($current_page > 1) {
            $prev_page = $current_page - 1;
            $prev_page = add_query_arg(array('paged' => $prev_page));
        } else {
            $prev_page = $first_page;
        }
        if ($current_page != $page_count) {
            $next_page = $current_page + 1;
            $next_page = add_query_arg(array('paged' => $next_page));
        } else {
            $next_page = $last_page;
        }
        ?>
				<span class="pagination-links">
					<a class="first-page disabled" title="Go to the first page" href="<?php 
        echo $first_page;
        ?>
">«</a>
					<a class="prev-page disabled" title="Go to the previous page" href="<?php 
        echo $prev_page;
        ?>
">‹</a>
					<span class="paging-input"><input class="current-page" title="Current page" type="text" name="paged" value="<?php 
        echo $current_page;
        ?>
" size="2"> of <span class="total-pages"><?php 
        echo $page_count;
        ?>
</span></span>
					<a class="next-page" title="Go to the next page" href="<?php 
        echo $next_page;
        ?>
">›</a>
					<a class="last-page" title="Go to the last page" href="<?php 
        echo $last_page;
        ?>
">»</a>
				</span>
				<?php 
    }
    ?>
			</div>
		</div>
		<br />
		<table border="1px" class="wp-list-table widefat fixed posts">
			<thead>
				<tr>
					<th class="check-column"><input type="checkbox" id="ninja_forms_select_all" class="ninja-forms-uploads-bulk-action"></th>
					<th><?php 
    _e('File Name', 'ninja-forms');
    ?>
</th>
					<th><?php 
    _e('Original User Filename', 'ninja-forms');
    ?>
</th>
					<th><?php 
    _e('Date', 'ninja-forms');
    ?>
</th>
					<th><?php 
    _e('Form Name', 'ninja-forms');
    ?>
</th>
					<th><?php 
    _e('User Name', 'ninja-forms');
    ?>
</th>
				</tr>
			</thead>
			<tbody id="ninja_forms_uploads_tbody">
		<?php 
    if (is_array($all_files) and !empty($all_files) and $current_page <= $page_count) {
        for ($i = $start; $i < $end; $i++) {
            $field_id = $all_files[$i]['field_id'];
            $upload_id = $all_files[$i]['id'];
            $date_updated = strtotime($all_files[$i]['date_updated']);
            $date_updated = date('m/d/Y', $date_updated);
            $data = $all_files[$i]['data'];
            $form_row = ninja_forms_get_form_by_field_id($field_id);
            $form_data = $form_row['data'];
            $form_title = $form_data['form_title'];
            if (isset($data['user_file_name'])) {
                $user_file_name = stripslashes($data['user_file_name']);
            } else {
                $user_file_name = '';
            }
            if (isset($all_files[$i]['user_id']) and !empty($all_files[$i]['user_id'])) {
                $user_data = get_userdata($all_files[$i]['user_id']);
                $user_nicename = $user_data->user_nicename;
            } else {
                $user_nicename = '';
            }
            if (isset($data['file_url'])) {
                $file_url = $data['file_url'];
            } else {
                $file_url = '';
            }
            if (isset($data['file_name'])) {
                $file_name = $data['file_name'];
            } else {
                $file_name = '';
            }
            ?>
				<tr id="ninja_forms_upload_<?php 
            echo $upload_id;
            ?>
_tr">
					<th scope="row" class="check-column">
						<input type="checkbox" id="" name="ninja_forms_uploads[]" value="<?php 
            echo $upload_id;
            ?>
" class="ninja-forms-uploads-bulk-action">
					</th>
					<td>
						<a href="<?php 
            echo $file_url;
            ?>
" target="_blank"><?php 
            echo $file_name;
            ?>
</a>
						<div class="row-actions">
							<span class="view"><a class="view" title="View this file" href="<?php 
            echo $file_url;
            ?>
" target="_blank" id="">View</a> | </span>
							<span class="trash"><a class="trash ninja-forms-delete-upload" title="Delete this file" href="#" id="delete_upload_<?php 
            echo $upload_id;
            ?>
">Delete</a></span>
						</div>
					</td>
					<td>
						<?php 
            echo $user_file_name;
            ?>
					</td>
					<td>
						<?php 
            echo $date_updated;
            ?>
					</td>
					<td>
						<?php 
            echo $form_title;
            ?>
					</td>
					<td>
						<?php 
            echo $user_nicename;
            ?>
					</td>
				</tr>
			<?php 
        }
    } else {
        ?>
		<tr id="ninja_forms_files_empty" style="">
			<td colspan="5">
				<?php 
        _e("No files found", "ninja-forms");
        ?>
			</td>
		</tr>
		<?php 
    }
    ?>

			</tbody>
			<tfoot>
				<tr>
					<th class="check-column"><input type="checkbox" id="ninja_forms_select_all" class="ninja-forms-uploads-bulk-action"></th>
					<th><?php 
    _e('File Name', 'ninja-forms');
    ?>
</th>
					<th><?php 
    _e('Original User Filename', 'ninja-forms');
    ?>
</th>
					<th><?php 
    _e('Date', 'ninja-forms');
    ?>
</th>
					<th><?php 
    _e('Form Name', 'ninja-forms');
    ?>
</th>
					<th><?php 
    _e('User Name', 'ninja-forms');
    ?>
</th>
				</tr>
			</tfoot>
		</table>

	<?php 
}