示例#1
0
                $params = array();
                if (!empty($_REQUEST['location'])) {
                    $params['location'] = $_REQUEST['location'];
                }
                if (fn_data_feeds_export($datafeed_id, $params)) {
                    $location = empty($_REQUEST['location']) ? db_get_field("SELECT export_location FROM ?:data_feeds WHERE datafeed_id = ?i", $datafeed_id) : $_REQUEST['location'];
                    if ($location == 'L') {
                        $meta_url = urlencode(fn_url('data_feeds.download?datafeed_id=' . $datafeed_id, 'A', 'rel'));
                        $_suffix = '&meta_redirect_url=' . $meta_url;
                        $url = (empty($_SERVER['HTTP_REFERER']) ? fn_url("data_feeds.manage") : fn_query_remove($_SERVER['HTTP_REFERER'], 'meta_redirect_url')) . $_suffix;
                        Tygh::$app['ajax']->assign('force_redirection', $url);
                    }
                }
            }
        }
    }
    exit;
} elseif ($mode == 'cron_export') {
    $cron_password = Registry::get('addons.data_feeds.cron_password');
    if ((!isset($_REQUEST['cron_password']) || $cron_password != $_REQUEST['cron_password']) && !empty($cron_password)) {
        die(__('access_denied'));
    }
    $params = array('status' => 'A', 'cron' => 'Y');
    $datafeeds = fn_data_feeds_get_data($params);
    if (!empty($datafeeds)) {
        foreach ($datafeeds as $datafeed) {
            fn_data_feeds_export($datafeed['datafeed_id']);
        }
    }
    exit;
}
示例#2
0
    }
    Registry::get('view')->assign('datafeed_langs', $datafeed_langs);
    $pattern = fn_get_schema('exim', 'products');
    Registry::get('view')->assign('pattern', $pattern);
    if (empty($datafeed_data['datafeed_id'])) {
        return array(CONTROLLER_STATUS_NO_PAGE);
    }
    Registry::get('view')->assign('export_fields', $pattern['export_fields']);
    Registry::get('view')->assign('feature_fields', fn_data_feeds_get_features_fields());
    // [Page sections]
    Registry::set('navigation.tabs', array('detailed' => array('title' => __('general'), 'js' => true), 'exported_items' => array('title' => __('exported_items'), 'js' => true), 'fields' => array('title' => __('map_fields'), 'js' => true)));
    // [/Page sections]
} elseif ($mode == 'download') {
    $params['datafeed_id'] = $_REQUEST['datafeed_id'];
    $params['single'] = true;
    $datafeed_data = fn_data_feeds_get_data($params, DESCR_SL);
    $filename = fn_get_files_dir_path() . $datafeed_data['file_name'];
    if (file_exists($filename)) {
        fn_get_file($filename);
    }
    exit;
}
function fn_data_feeds_update_feed($feed_data, $feed_id = 0, $lang_code = CART_LANGUAGE)
{
    if (!empty($feed_data['fields'])) {
        $_fields = array();
        foreach ($feed_data['fields'] as $key => $field) {
            if (empty($field['export_field_name'])) {
                unset($feed_data['fields'][$key]);
            } else {
                $_fields[intval($field['position'])][] = $field;
示例#3
0
function fn_data_feeds_export($datafeed_id, $options = array(), $pattern = '')
{
    static $pattern;
    if (empty($pattern)) {
        $pattern = fn_get_pattern_definition('products');
    }
    $params['datafeed_id'] = $datafeed_id;
    $params['single'] = true;
    $params['available_fields'] = 'Y';
    $params = array_merge($params, $options);
    $datafeed_data = fn_data_feeds_get_data($params, DESCR_SL);
    if (empty($pattern) || empty($params['datafeed_id'])) {
        fn_set_notification('E', __('error'), __('error_exim_no_data_exported'));
        return false;
    }
    if ($datafeed_data['exclude_disabled_products'] == 'Y') {
        $params['status'] = 'A';
    }
    if (empty($datafeed_data['products']) && empty($datafeed_data['categories'])) {
        $params['cid'] = 0;
        $params['subcats'] = 'Y';
        $params['skip_view'] = 'Y';
        $params['extend'] = array('categories');
        list($products, $search) = fn_get_products($params);
        $pids = array_map(create_function('$product', '$pid = $product["product_id"]; return $pid;'), $products);
    } else {
        $pids = array();
        if (!empty($datafeed_data['products'])) {
            $pids = explode(',', $datafeed_data['products']);
        }
        if (!empty($datafeed_data['categories'])) {
            $params['cid'] = explode(',', $datafeed_data['categories']);
            $params['subcats'] = 'Y';
            $params['skip_view'] = 'Y';
            $params['extend'] = array('categories');
            list($products, $search) = fn_get_products($params);
            $_pids = array_map(create_function('$product', '$pid = $product["product_id"]; return $pid;'), $products);
            $pids = array_merge($pids, $_pids);
            unset($_pids);
        }
        $pids = array_unique($pids);
    }
    if (empty($pids)) {
        fn_set_notification('E', __('error'), __('error_exim_no_data_exported'));
        return false;
    }
    $pattern['condition']['conditions']['product_id'] = $pids;
    $fields = array();
    if (!empty($datafeed_data['fields'])) {
        foreach ($datafeed_data['fields'] as $field) {
            $fields[$field['field']] = $field['export_field_name'];
        }
    }
    $features = db_get_array('SELECT feature_id, description FROM ?:product_features_descriptions WHERE lang_code = ?s', DESCR_SL);
    $features_fields = array();
    if (!empty($features)) {
        foreach ($features as $feature) {
            $features_fields[$feature['description']] = array('process_get' => array('fn_data_feeds_get_product_features', '#key', '#field', '#lang_code'), 'linked' => false);
        }
    }
    $pattern['export_fields'] = array_merge($pattern['export_fields'], $features_fields);
    $options = $datafeed_data['export_options'];
    $options['delimiter'] = $datafeed_data['csv_delimiter'];
    $options['filename'] = $datafeed_data['file_name'];
    $options['fields_names'] = true;
    $options['force_header'] = true;
    $pattern['enclosure'] = !empty($datafeed_data['enclosure']) ? $datafeed_data['enclosure'] : '';
    if (!empty($fields)) {
        if (fn_export($pattern, $fields, $options) == true) {
            $errors = false;
            $export_location = empty($params['location']) ? $datafeed_data['export_location'] : $params['location'];
            if ($export_location == 'S') {
                if (file_exists(fn_get_files_dir_path() . $datafeed_data['file_name']) && is_dir($datafeed_data['save_dir'])) {
                    fn_rename(fn_get_files_dir_path() . $datafeed_data['file_name'], $datafeed_data['save_dir'] . '/' . $datafeed_data['file_name']);
                } else {
                    $errors = true;
                    fn_set_notification('E', __('error'), __('check_server_export_settings'));
                }
            } elseif ($export_location == 'F') {
                if (empty($datafeed_data['ftp_url'])) {
                    $errors = true;
                    fn_set_notification('E', __('error'), __('ftp_connection_problem'));
                } else {
                    preg_match("/[^\\/^\\^:]+/", $datafeed_data['ftp_url'], $matches);
                    $host = $matches[0];
                    preg_match("/.*:([0-9]+)/", $datafeed_data['ftp_url'], $matches);
                    $port = empty($matches[1]) ? 21 : $matches[1];
                    preg_match("/[^\\/]+(.*)/", $datafeed_data['ftp_url'], $matches);
                    $url = empty($matches[1]) ? '' : $matches[1];
                    $conn_id = @ftp_connect($host, $port);
                    $result = @ftp_login($conn_id, $datafeed_data['ftp_user'], $datafeed_data['ftp_pass']);
                    if (!empty($url)) {
                        @ftp_chdir($conn_id, $url);
                    }
                    $filename = fn_get_files_dir_path() . $datafeed_data['file_name'];
                    if ($result) {
                        if (@ftp_put($conn_id, $datafeed_data['file_name'], $filename, FTP_ASCII)) {
                            unlink($filename);
                        } else {
                            $errors = true;
                            fn_set_notification('E', __('error'), __('ftp_connection_problem'));
                        }
                    } else {
                        $errors = true;
                        fn_set_notification('E', __('error'), __('ftp_connection_problem'));
                    }
                    @ftp_close($conn_id);
                }
            }
            if (!$errors) {
                fn_set_notification('N', __('notice'), __('text_exim_data_exported'));
                return true;
            } else {
                unlink(fn_get_files_dir_path() . $datafeed_data['file_name']);
                return false;
            }
        } else {
            fn_set_notification('E', __('error'), __('error_exim_no_data_exported'));
            return false;
        }
    } else {
        fn_set_notification('E', __('error'), __('error_exim_fields_not_selected'));
        return false;
    }
}