Ejemplo n.º 1
0
 * Определение констант
 */
if (!defined('GS_PLUGIN_PATH')) {
    define('GS_PLUGIN_PATH', dirname(__FILE__));
}
GdeSlonImport::check_access();
$path = GS_PLUGIN_PATH . '/downloads';
set_error_handler(create_function('$severity, $message, $file, $line', 'throw new ErrorException($message, $severity, $severity, $file, $line);'));
try {
    file_put_contents($path . '/test.txt', 'Hello File');
    @unlink($path . '/test.txt');
} catch (ErrorException $e) {
    die("Не хватает прав на запись в каталог {$path} . Выставьте нужные права и попробуйте еще раз.");
}
restore_error_handler();
if (!GdeSlonImport::checkCurl() && !GdeSlonImport::checkFileGetContentsCurl()) {
    die("Не найдено расширение php cUrl, а получение удаленного файла запрещено в настройках php.ini");
}
@unlink($path . '/archive.zip');
$f = fopen($path . '/archive.zip', 'w');
fwrite($f, GdeSlonImport::getFileFromUrl());
fclose($f);
if (GdeSlonImport::checkMimeType($path . '/archive.zip')) {
    die("По указанному пути не найден ZIP-файл. Проверьте правильность введённой ссылки");
}
/* Удаление старых xml-файлов */
$dh = opendir($path);
while ($file = readdir($dh)) {
    if (strpos($file, '.xml') !== false) {
        @unlink($path . '/' . $file);
        break;
Ejemplo n.º 2
0
	<?php 
if (GdeSlonImport::checkCurl() || GdeSlonImport::checkFileGetContentsCurl()) {
    ?>
	<div style="border: 1px solid #aaa; padding: 7px;">
		Необходимо в крон добавить запуск модуля импорта:<br /><br />
		<b>GET <?php 
    echo admin_url('admin-ajax.php');
    ?>
?action=parse_url&code=<?php 
    echo GS_Config::init()->get('ps_access_code');
    ?>
</b><br />
		<br />
		Либо запустите импорт товаров вручную:<br />
		<p>Для выкачивания файла будет использован <strong><?php 
    echo GdeSlonImport::checkCurl() ? 'cUrl' : 'file_get_contents';
    ?>
</strong></p>
		<form method="post" action="<?php 
    echo admin_url('admin-ajax.php');
    ?>
?action=parse_url" target="_blank">
			<input type="hidden" name="code" value="<?php 
    echo GS_Config::init()->get('ps_access_code');
    ?>
" />
			<input type="submit" class="button-primary archive" value="Запустить импорт" />
		</form>
		<br />
		<p>Дождитесь, чтобы импорт товаров закончился, иначе Ваша выгрузка будет неполной.</p>
		<form method="post" action="<?php 
Ejemplo n.º 3
0
/**
 * Подгрузка изображения
 * @param $url
 * @param $postId
 * @todo добавить обходной вариант на тот случай, если загрузка не удалась — просто запоминать урл на картинку
 * @todo Вынести наконец всё в красивый класс и закончить рефакторинг — запланировано на 7.06.2012
 */
function download_image($url, $postId)
{
    if (!GS_Config::init()->get('ps_download_images')) {
        $currentValue = get_post_meta($postId, 'image', TRUE);
        update_post_meta($postId, 'image', $url, $currentValue);
        return;
    }
    if (!GdeSlonImport::checkCurl()) {
        $opts = array('http' => array('method' => "GET", 'header' => "Accept-language: en\r\n"));
        $context = stream_context_create($opts);
        $fileContents = file_get_contents($url, false, $context);
    } else {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $fileContents = curl_redirect_exec($ch);
        curl_close($ch);
    }
    if (!$fileContents) {
        echo 'При попытке загрузить файл ' . $url . ' возникла ошибка: ' . "Содержимое файла не получено. Файл был присоединён старым способом\n\r";
        $currentValue = get_post_meta($postId, 'image', TRUE);
        update_post_meta($postId, 'image', $url, $currentValue);
        return;
    }
    $localFilepath = dirname(__FILE__) . '/downloads/' . basename($url);
    $f = fopen($localFilepath, 'w');
    fwrite($f, $fileContents);
    fclose($f);
    /**
     * Удаление не пользовательских аттачментов
     */
    foreach (get_children(array('post_parent' => $postId, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => -1)) as $attachment) {
        if (get_post_meta($attachment->ID, 'is_image_from_gdeslon', TRUE)) {
            wp_delete_attachment($attachment->ID, TRUE);
        }
    }
    $state = insert_attachment($localFilepath, $postId, true);
    if (is_wp_error($state)) {
        echo 'При попытке загрузить файл ' . $url . ' возникла ошибка: ' . $state->get_error_message() . ". Файл был присоединён старым способом\n\r";
        $currentValue = get_post_meta($postId, 'image', TRUE);
        update_post_meta($postId, 'image', $url, $currentValue);
    } else {
        add_post_meta($state, 'is_image_from_gdeslon', TRUE);
    }
    if (is_file($localFilepath)) {
        unlink($localFilepath);
    }
}