Example #1
0
function csv_format_feed($videos, $feed_config)
{
    global $config, $languages;
    header("Content-Type: text/plain; charset=utf-8");
    $csv_separator = $feed_config['csv_separator'];
    if ($csv_separator == '') {
        $csv_separator = '|';
    }
    $csv_columns = $feed_config['csv_columns'];
    if (!is_array($csv_columns)) {
        $csv_columns = array();
        $csv_columns[] = 'id';
        $csv_columns[] = 'title';
        $csv_columns[] = 'dir';
        $csv_columns[] = 'description';
        $csv_columns[] = 'post_date';
        $csv_columns[] = 'content_source';
        $csv_columns[] = 'content_source_url';
        $csv_columns[] = 'link';
        $csv_columns[] = 'categories';
        $csv_columns[] = 'tags';
        $csv_columns[] = 'duration';
        if ($feed_config['video_content_type_id'] == 2) {
            $csv_columns[] = 'url';
            $csv_columns[] = 'embed';
        } elseif ($feed_config['video_content_type_id'] == 3) {
            $csv_columns[] = 'embed';
        } elseif ($feed_config['video_content_type_id'] == 4) {
            $csv_columns[] = 'url';
            $csv_columns[] = 'embed';
        }
        $csv_columns[] = 'main_screenshot';
    }
    $result = '';
    foreach ($videos as $video) {
        $dir_path = get_dir_by_id($video['video_id']);
        $row = '';
        foreach ($csv_columns as $field) {
            if ($row != '') {
                $row .= $csv_separator;
            }
            switch ($field) {
                case 'id':
                    $row .= $video['video_id'];
                    break;
                case 'title':
                    $row .= $video['title'];
                    break;
                case 'dir':
                    $row .= $video['dir'];
                    break;
                case 'description':
                    $row .= $video['description'];
                    break;
                case 'rating':
                    $row .= round($video['rating'] * 10) / 10;
                    break;
                case 'popularity':
                    $row .= $video['popularity'];
                    break;
                case 'post_date':
                    $row .= $video['post_date'];
                    break;
                case 'user':
                    $row .= $video['user_title'];
                    break;
                case 'content_source':
                    $row .= $video['cs_title'];
                    break;
                case 'content_source_url':
                    $row .= $video['cs_url'];
                    break;
                case 'dvd':
                    $row .= $video['dvd_title'];
                    break;
                case 'link':
                    $row .= $video['website_link'];
                    break;
                case 'categories':
                    $row .= implode(',', $video['categories']);
                    break;
                case 'tags':
                    $row .= implode(',', $video['tags']);
                    break;
                case 'models':
                    $row .= implode(',', $video['models']);
                    break;
                case 'release_year':
                    if ($video['release_year'] > 0) {
                        $row .= $video['release_year'];
                    }
                    break;
                case 'duration':
                    if (is_array($video['hotlink_format'])) {
                        $row .= $video['hotlink_format']['duration'];
                    } else {
                        $row .= $video['duration'];
                    }
                    break;
                case 'width':
                    if (is_array($video['hotlink_format'])) {
                        $row .= $video['hotlink_format']['dimensions'][0];
                    } else {
                        $dimensions = explode("x", $video['file_dimensions']);
                        $row .= $dimensions[0];
                    }
                    break;
                case 'height':
                    if (is_array($video['hotlink_format'])) {
                        $row .= $video['hotlink_format']['dimensions'][1];
                    } else {
                        $dimensions = explode("x", $video['file_dimensions']);
                        $row .= $dimensions[1];
                    }
                    break;
                case 'filesize':
                    if (is_array($video['hotlink_format'])) {
                        $row .= $video['hotlink_format']['file_size'];
                    }
                    break;
                case 'url':
                    if (is_array($video['hotlink_format'])) {
                        if ($feed_config['video_content_type_id'] == 4) {
                            $video_url = "{$config['project_url']}/get_file/{$video['server_group_id']}" . '/' . $video['hotlink_format']['file_path'];
                            if ($config['omit_slash_video_files'] != 'true') {
                                $video_url .= "/";
                            }
                            $time = date("YmdHis");
                            $ahv = md5($video_url . $time . $config['ahv']);
                            $row .= "{$video_url}?time={$time}&ahv={$ahv}";
                        } else {
                            $row .= "{$config['project_url']}/get_file/{$video['server_group_id']}" . '/' . $video['hotlink_format']['file_path'];
                            if ($config['omit_slash_video_files'] != 'true') {
                                $row .= "/";
                            }
                        }
                    } elseif ($video['file_url'] != '') {
                        $row .= $video['file_url'];
                    }
                    break;
                case 'embed':
                    $row .= $video['embed'];
                    break;
                case 'screenshots_prefix':
                    if ($feed_config['screenshot_sources'] == 1) {
                        //$row.="$config[project_url]/get_file/0/";
                        $row .= "http://direct.upornia.com/get_file/0/";
                    } else {
                        $row .= $config['content_url_videos_screenshots'] . '/' . $video['screen_url'] . '/';
                    }
                    break;
                case 'main_screenshot':
                    $hash = md5($config['cv'] . "{$dir_path}/{$video['video_id']}/screenshots/{$video['screen_main']}.jpg");
                    if (in_array('screenshots_prefix', $csv_columns)) {
                        if ($feed_config['screenshot_sources'] == 1) {
                            $row .= "{$hash}/{$dir_path}/{$video['video_id']}/screenshots/{$video['screen_main']}.jpg";
                            if ($config['omit_slash_screenshot_sources'] != 'true') {
                                $row .= "/";
                            }
                        } else {
                            $row .= "{$video['screen_main']}.jpg";
                        }
                    } else {
                        if ($feed_config['screenshot_sources'] == 1) {
                            //$row.="$config[project_url]/get_file/0/$hash/$dir_path/$video[video_id]/screenshots/$video[screen_main].jpg";
                            $row .= "http://direct.upornia.com/get_file/0/{$hash}/{$dir_path}/{$video['video_id']}/screenshots/{$video['screen_main']}.jpg";
                            if ($config['omit_slash_screenshot_sources'] != 'true') {
                                $row .= "/";
                            }
                        } else {
                            $row .= "{$config['content_url_videos_screenshots']}/{$video['screen_url']}/{$video['screen_main']}.jpg";
                        }
                    }
                    break;
                case 'main_screenshot_number':
                    $row .= $video['screen_main'];
                    break;
                case 'screenshots':
                    for ($i = 1; $i <= $video['screen_amount']; $i++) {
                        $hash = md5($config['cv'] . "{$dir_path}/{$video['video_id']}/screenshots/{$i}.jpg");
                        if (in_array('screenshots_prefix', $csv_columns)) {
                            if ($feed_config['screenshot_sources'] == 1) {
                                $row .= "{$hash}/{$dir_path}/{$video['video_id']}/screenshots/{$i}.jpg";
                                if ($config['omit_slash_screenshot_sources'] != 'true') {
                                    $row .= "/";
                                }
                            } else {
                                $row .= "{$i}.jpg";
                            }
                        } else {
                            if ($feed_config['screenshot_sources'] == 1) {
                                //$row.="$config[project_url]/get_file/0/$hash/$dir_path/$video[video_id]/screenshots/$i.jpg";
                                $row .= "http://direct.upornia.com/get_file/0/{$hash}/{$dir_path}/{$video['video_id']}/screenshots/{$i}.jpg";
                                if ($config['omit_slash_screenshot_sources'] != 'true') {
                                    $row .= "/";
                                }
                            } else {
                                $row .= "{$config['content_url_videos_screenshots']}/{$video['screen_url']}/{$i}.jpg";
                            }
                        }
                        if ($i < $video['screen_amount']) {
                            $row .= ',';
                        }
                    }
                    break;
                case 'custom1':
                    $row .= $video['custom1'];
                    break;
                case 'custom2':
                    $row .= $video['custom2'];
                    break;
                case 'custom3':
                    $row .= $video['custom3'];
                    break;
            }
            foreach ($languages as $language) {
                if ($field == "title_{$language['code']}") {
                    $row .= $video["title_{$language['code']}"];
                }
                if ($field == "description_{$language['code']}") {
                    $row .= $video["description_{$language['code']}"];
                }
                if ($field == "dir_{$language['code']}") {
                    $row .= $video["dir_{$language['code']}"];
                }
            }
            if (strpos($field, 'static:') === 0) {
                $row .= str_replace('static:', '', $field);
            }
        }
        $result .= "{$row}\n";
    }
    return $result;
}
Example #2
0
        flock($fp, LOCK_EX);
        fwrite($fp, serialize($data));
        fclose($fp);
    }
} else {
    $data = mr2array(sql_pr($query));
}
$website_ui_data = @unserialize(file_get_contents("{$config['project_path']}/admin/data/system/website_ui_params.dat"));
$pattern = $website_ui_data['WEBSITE_LINK_PATTERN'];
$affiliate_str = '';
if ($feed['affiliate_param_name'] != '' && $_REQUEST[$feed['affiliate_param_name']] != '') {
    $affiliate_str = "?{$feed['affiliate_param_name']}=" . $_REQUEST[$feed['affiliate_param_name']];
}
foreach ($data as $k => $video) {
    $video_id = $video['video_id'];
    $dir_path = get_dir_by_id($video_id);
    $video_formats = get_video_formats($video_id, $video['file_formats']);
    $data[$k]['video_id'] = "phc_{$video_id}";
    $data[$k]['screen_url'] = "{$dir_path}/{$video_id}/{$screenshot_format}";
    if ($feed_options['enable_localization'] == 1 && $locale != '') {
        if ($video["title_{$locale}"] != '') {
            $data[$k]['title'] = $video["title_{$locale}"];
            $video['title'] = $video["title_{$locale}"];
        }
        if ($video["dir_{$locale}"] != '') {
            $data[$k]['dir'] = $video["dir_{$locale}"];
            $video['dir'] = $video["dir_{$locale}"];
        }
        if ($video["description_{$locale}"] != '') {
            $data[$k]['description'] = $video["description_{$locale}"];
            $video['description'] = $video["description_{$locale}"];
Example #3
0
function kvs_format_feed($videos, $feed_config)
{
    global $config, $languages;
    header("Content-Type: text/xml; charset=utf-8");
    $result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    if ($feed_config['screenshot_sources'] == 1) {
        $result .= "<videos base_video_url=\"{$config['project_url']}/get_file/\" base_screen_url=\"{$config['screen_project_url']}/get_file/0/\">\n";
    } else {
        $result .= "<videos base_video_url=\"{$config['project_url']}/get_file/\" base_screen_url=\"{$config['content_url_videos_screenshots']}/\">\n";
    }
    foreach ($videos as $video) {
        $dir_path = get_dir_by_id($video['video_id']);
        $item_result = '';
        $item_result .= "\t<video>\n";
        $item_result .= "\t\t" . kvs_format_feed_tag('id', $video['video_id']) . "\n";
        $item_result .= "\t\t" . kvs_format_feed_tag('title', $video['title']) . "\n";
        if ($feed_config['enable_localization'] == 1) {
            foreach ($languages as $language) {
                if ($video["title_{$language['code']}"] != '') {
                    $item_result .= "\t\t" . kvs_format_feed_tag("title_{$language['code']}", $video["title_{$language['code']}"]) . "\n";
                }
            }
        }
        $item_result .= "\t\t" . kvs_format_feed_tag('dir', $video['dir']) . "\n";
        if ($feed_config['enable_localization'] == 1) {
            foreach ($languages as $language) {
                if ($video["dir_{$language['code']}"] != '') {
                    $item_result .= "\t\t" . kvs_format_feed_tag("dir_{$language['code']}", $video["dir_{$language['code']}"]) . "\n";
                }
            }
        }
        if ($video['description'] != '') {
            $item_result .= "\t\t" . kvs_format_feed_tag('description', $video['description']) . "\n";
            if ($feed_config['enable_localization'] == 1) {
                foreach ($languages as $language) {
                    if ($video["description_{$language['code']}"] != '') {
                        $item_result .= "\t\t" . kvs_format_feed_tag("description_{$language['code']}", $video["description_{$language['code']}"]) . "\n";
                    }
                }
            }
        }
        $item_result .= "\t\t" . kvs_format_feed_tag('rating', round($video['rating'])) . "\n";
        $item_result .= "\t\t" . kvs_format_feed_tag('popularity', $video['popularity']) . "\n";
        $item_result .= "\t\t" . kvs_format_feed_tag('post_date', $video['post_date']) . "\n";
        if ($feed_config['video_content_type_id'] == 1 || $feed_config['video_content_type_id'] == 3) {
            $item_result .= "\t\t" . kvs_format_feed_tag('duration', $video['duration']) . "\n";
        }
        if ($video['cs_title'] != '') {
            $item_result .= "\t\t" . kvs_format_feed_tag('content_source', $video['cs_title']) . "\n";
        }
        if ($video['cs_url'] != '') {
            $item_result .= "\t\t" . kvs_format_feed_tag('content_source_url', $video['cs_url']) . "\n";
        }
        if ($video['user_title'] != '') {
            $item_result .= "\t\t" . kvs_format_feed_tag('user', $video['user_title']) . "\n";
        }
        if ($video['dvd_title'] != '') {
            $item_result .= "\t\t" . kvs_format_feed_tag('dvd', $video['dvd_title']) . "\n";
        }
        if ($video['website_link'] != '') {
            $item_result .= "\t\t" . kvs_format_feed_tag('link', $video['website_link']) . "\n";
        }
        if (is_array($video['tags']) && count($video['tags']) > 0) {
            $item_result .= "\t\t" . kvs_format_feed_tag('tags', implode(',', $video['tags'])) . "\n";
        }
        if (is_array($video['categories']) && count($video['categories']) > 0) {
            $item_result .= "\t\t" . kvs_format_feed_tag('categories', implode(',', $video['categories'])) . "\n";
        }
        if (is_array($video['models']) && count($video['models']) > 0) {
            $item_result .= "\t\t" . kvs_format_feed_tag('models', implode(',', $video['models'])) . "\n";
        }
        if ($video['embed'] != '') {
            $item_result .= "\t\t" . kvs_format_feed_tag('embed', $video['embed']) . "\n";
        }
        if (is_array($video['hotlink_format'])) {
            $item_result .= "\t\t<files>\n";
            $item_result .= "\t\t\t<file>\n";
            $item_result .= "\t\t\t\t" . kvs_format_feed_tag('duration', $video['hotlink_format']['duration']) . "\n";
            $item_result .= "\t\t\t\t" . kvs_format_feed_tag('width', $video['hotlink_format']['dimensions'][0]) . "\n";
            $item_result .= "\t\t\t\t" . kvs_format_feed_tag('height', $video['hotlink_format']['dimensions'][1]) . "\n";
            $item_result .= "\t\t\t\t" . kvs_format_feed_tag('filesize', $video['hotlink_format']['file_size']) . "\n";
            if ($feed_config['video_content_type_id'] == 4) {
                $video_url = "{$config['project_url']}/get_file/" . $video['server_group_id'] . '/' . $video['hotlink_format']['file_path'] . '/';
                $time = date("YmdHis");
                $ahv = md5($video_url . $time . $config['ahv']);
                $item_result .= "\t\t\t\t" . kvs_format_feed_tag('url', $video['server_group_id'] . '/' . $video['hotlink_format']['file_path'] . "/?time={$time}&ahv={$ahv}") . "\n";
            } else {
                $item_result .= "\t\t\t\t" . kvs_format_feed_tag('url', $video['server_group_id'] . '/' . $video['hotlink_format']['file_path'] . '/') . "\n";
            }
            $item_result .= "\t\t\t</file>\n";
            $item_result .= "\t\t</files>\n";
        } elseif ($video['file_url'] != '') {
            $dimensions = explode("x", $video['file_dimensions']);
            $item_result .= "\t\t<files>\n";
            $item_result .= "\t\t\t<file>\n";
            $item_result .= "\t\t\t\t" . kvs_format_feed_tag('duration', $video['duration']) . "\n";
            $item_result .= "\t\t\t\t" . kvs_format_feed_tag('width', $dimensions[0]) . "\n";
            $item_result .= "\t\t\t\t" . kvs_format_feed_tag('height', $dimensions[1]) . "\n";
            $item_result .= "\t\t\t\t" . kvs_format_feed_tag('filesize', $video['file_size']) . "\n";
            $item_result .= "\t\t\t\t" . kvs_format_feed_tag('url', $video['file_url']) . "\n";
            $item_result .= "\t\t\t</file>\n";
            $item_result .= "\t\t</files>\n";
        }
        $item_result .= "\t\t<screens main=\"{$video['screen_main']}\">\n";
        for ($i = 1; $i <= $video['screen_amount']; $i++) {
            if ($feed_config['screenshot_sources'] == 1) {
                $hash = md5($config['cv'] . "{$dir_path}/{$video['video_id']}/screenshots/{$i}.jpg");
                $item_result .= "\t\t\t" . kvs_format_feed_tag('screen', "{$hash}/{$dir_path}/{$video['video_id']}/screenshots/{$i}.jpg/") . "\n";
            } else {
                $item_result .= "\t\t\t" . kvs_format_feed_tag('screen', "{$video['screen_url']}/{$i}.jpg") . "\n";
            }
        }
        $item_result .= "\t\t</screens>\n";
        $item_result .= "\t</video>\n";
        if ($feed_config['video_content_type_id'] == 1 && $video['website_link'] == '') {
            continue;
        } elseif ($feed_config['video_content_type_id'] == 2 && !is_array($video['hotlink_format']) && $video['file_url'] == '') {
            continue;
        } elseif ($feed_config['video_content_type_id'] == 3 && $video['embed'] == '') {
            continue;
        }
        $result .= $item_result;
    }
    $result .= "</videos>\n";
    return $result;
}