Beispiel #1
0
/**
 * Updating Likes
 */
function videogall_update_likes()
{
    $id = trim($_POST['id']);
    $clientip = $_SERVER['REMOTE_ADDR'];
    $current_video = videogall_get_results("videogall_videos", "id", $id);
    $likes = "";
    foreach ($current_video as $current_entry) {
        $likes = $current_entry['likes'];
        break;
    }
    $current_likes = explode(",", $likes);
    $new_likes = $current_likes;
    if (!in_array($clientip, $current_likes)) {
        array_push($new_likes, $clientip);
    }
    $like_str = trim(implode(",", $new_likes), ",");
    $count = 0;
    foreach ($new_likes as $like_entry) {
        if (trim($like_entry) != "") {
            $count++;
        }
    }
    $update_str = "likes='" . $like_str . "'";
    $result = videogall_update("videogall_videos", $id, $update_str);
    echo $count;
    die;
}
/**
 * Add/Update video/categories
 */
function videogall_video_action()
{
    global $videogall_url;
    if (isset($_POST['delete-id']) and trim($_POST['delete-id']) != "") {
        $delete_id = videogall_sanitize($_POST['delete-id']);
        if ($delete_id != 0 and $delete_id != "") {
            $result = videogall_bulk_delete("videogall_videos", $delete_id);
            if (!$result) {
                add_settings_error('videogall_options', 'error', __('Videos cannot be deleted', 'videogall'), 'error');
            } else {
                add_settings_error('videogall_options', 'success', __('Videos deleted', 'videogall'), 'updated');
            }
        } else {
            add_settings_error('videogall_options', 'error', __('No videos selected. Select/Unselect videos to delete by clicking on them', 'videogall'), 'error');
        }
    }
    if (isset($_POST['edit-video-submit'])) {
        $id = videogall_sanitize($_POST['edit-id']);
        if ($id != 0 and $id != "") {
            $url = videogall_process_url(esc_attr(videogall_sanitize($_POST['edit-video-url-' . $id])));
            if ($url != "") {
                $thumbnail = esc_attr(videogall_sanitize($_POST['edit-video-thumb-' . $id]));
                if ($thumbnail == "") {
                    $thumbnail = videogall_get_thumbnail($url);
                }
                if ($thumbnail == "") {
                    $thumbnail = $videogall_url . 'images/default.png';
                }
                if (preg_match('/blip\\.tv/i', $url) > 0) {
                    $url = videogall_blip_url($url);
                }
                $category = esc_attr(videogall_sanitize($_POST['edit-video-category-' . $id]));
                $caption = esc_attr(videogall_sanitize($_POST['edit-video-caption-' . $id]));
                $description = videogall_sanitize($_POST['edit-video-description-' . $id]);
                $update_str = "url='" . $url . "', thumbnail='" . $thumbnail . "', category='" . $category . "', caption='" . $caption . "', description='" . $description . "'";
                $result = videogall_update("videogall_videos", $id, $update_str);
                if (!$result) {
                    add_settings_error('videogall_options', 'error', __('Video not updated', 'videogall'), 'error');
                } else {
                    add_settings_error('videogall_options', 'success', __('Video Updated', 'videogall'), 'updated');
                }
            } else {
                add_settings_error('videogall_options', 'error', __('Name & URL are required', 'videogall'), 'error');
            }
        }
    }
    if (isset($_POST['add-video-submit'])) {
        $url = videogall_process_url(esc_attr(videogall_sanitize($_POST['add-video-url'])));
        if ($url != "") {
            $thumbnail = esc_attr(videogall_sanitize($_POST['add-video-thumb']));
            if ($thumbnail == "") {
                $thumbnail = videogall_get_thumbnail($url);
            }
            if ($thumbnail == "") {
                $thumbnail = $videogall_url . 'images/default.png';
            }
            if (preg_match('/blip\\.tv/i', $url) > 0) {
                $url = videogall_blip_url($url);
            }
            $category = esc_attr(videogall_sanitize($_POST['add-video-category']));
            $caption = esc_attr(videogall_sanitize($_POST['add-video-caption']));
            $description = videogall_sanitize($_POST['add-video-description']);
            $video = array("url" => $url, "thumbnail" => $thumbnail, "category" => $category, "caption" => $caption, "description" => $description);
            $result = videogall_insert("videogall_videos", $video);
            if (!$result) {
                add_settings_error('videogall_options', 'error', __('Video cannot be added', 'videogall'), 'error');
            } else {
                add_settings_error('videogall_options', 'success', __('New Video Added', 'videogall'), 'updated');
            }
        } else {
            add_settings_error('videogall_options', 'error', __('URL is required', 'videogall'), 'error');
        }
    }
    if (isset($_POST['update-category-submit'])) {
        $existing_category = videogall_sanitize($_POST['update-video-category']);
        $new_category = videogall_sanitize($_POST['update-category-name']);
        if ($existing_category != "0") {
            if ($new_category != "") {
                $update_str = "name = '" . $new_category . "'";
                $result = videogall_update("videogall_categories", $existing_category, $update_str);
                if (!$result) {
                    add_settings_error('videogall_options', 'error', __('Category cannot be updated', 'videogall'), 'error');
                } else {
                    add_settings_error('videogall_options', 'success', __('Category Updated', 'videogall'), 'updated');
                }
            }
        } else {
            add_settings_error('videogall_options', 'error', __('Select category from dropdown to update', 'videogall'), 'error');
        }
    }
    if (isset($_POST['delete-category-submit'])) {
        $existing_category = videogall_sanitize($_POST['update-video-category']);
        if ($existing_category != "0") {
            $result = videogall_delete("videogall_categories", $existing_category);
            if (!$result) {
                add_settings_error('videogall_options', 'error', __('Category cannot be deleted', 'videogall'), 'error');
            } elseif ($result > 0) {
                $update_str = "category = 0";
                $result = videogall_update_video_by_category($existing_category, $update_str);
                add_settings_error('videogall_options', 'success', __('Category deleted', 'videogall'), 'updated');
            }
        }
    }
    if (isset($_POST['add-category-submit'])) {
        $name = videogall_sanitize($_POST['add-category-name']);
        if ($name != "") {
            $category = array("name" => $name);
            $result = videogall_insert("videogall_categories", $category);
            if (!$result) {
                add_settings_error('videogall_options', 'error', __('Category cannot be added', 'videogall'), 'error');
            } else {
                add_settings_error('videogall_options', 'success', __('New Category Added', 'videogall'), 'updated');
            }
        } else {
            add_settings_error('videogall_options', 'error', __('Category name is required', 'videogall'), 'error');
        }
    }
}