Exemplo n.º 1
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 
Exemplo n.º 2
0
<?php

header('Content-type: text/html; charset=utf-8');
define('PARSING_IS_RUNNING', TRUE);
ignore_user_abort(true);
set_time_limit(36000);
define('DOING_CRON', true);
/**
 * Определение констант
 */
if (!defined('GS_PLUGIN_PATH')) {
    define('GS_PLUGIN_PATH', dirname(__FILE__));
}
GdeSlonImport::check_access();
$path = GS_PLUGIN_PATH . '/downloads';
try {
    file_put_contents($path . '/test.txt', 'Hello File');
    @unlink($path . '/test.txt');
} catch (ErrorException $e) {
    die("Не хватает прав на запись в каталог {$path} . Выставьте нужные права и попробуйте еще раз.");
}
restore_error_handler();
/* Распаковка архива */
WP_Filesystem();
if ($status = unzip_file($path . '/archive.zip', $path) !== TRUE) {
    die('Ошибка при распаковке архива. Данные об ошибке
	PclZip — Code: ' . $status->get_error_code() . '; Message: ' . $status->get_error_message($status->get_error_code()));
}
$xmlfile = '';
$dh = opendir($path);
while ($file = readdir($dh)) {
Exemplo n.º 3
0
        preg_match('|\\<picture\\>(.+)\\</picture\\>|', $product, $matches);
        $image = @$matches[1];
        preg_match('|\\<name\\>(.+)\\</name\\>|', $product, $matches);
        $title = @$matches[1];
        $title = str_replace('<![CDATA[', '', $title);
        $title = str_replace(']]>', '', $title);
        if (!$title && preg_match('|\\<model\\>(.+)\\</model\\>|', $product, $matches)) {
            $title = @$matches[1];
            $title = str_replace('<![CDATA[', '', $title);
            $title = str_replace(']]>', '', $title);
        }
        $ps = mb_strpos($product, '<description>', 0, 'utf-8');
        $pe = mb_strpos($product, '</description>', 0, 'utf-8');
        $descr = mb_substr($product, $ps + mb_strlen('<description>', 'utf-8'), $pe - $ps - mb_strlen('<description>', 'utf-8'), 'utf-8');
        $descr = str_replace('<![CDATA[', '', $descr);
        $descr = str_replace(']]>', '', $descr);
        preg_match('|\\<categoryId\\>(.+)\\</categoryId\\>|', $product, $matches);
        $categoryId = @$matches[1];
        //обновление поста
        importPost(array('id' => $id, 'title' => $title, 'description' => nl2br($descr), 'url' => $url, 'price' => $price, 'currency' => $currency, 'image' => $image, 'category_id' => $categoryId), GdeSlonImport::parseParams($product));
        unset($content);
    } else {
        break;
    }
}
fclose($f);
@unlink($path . '/' . $xmlfile);
flushCache($cats);
wp_mail(get_option('admin_email'), 'Обновление товаров', 'Обновление товаров завершено!');
echo "Done!\n";
exit;
Exemplo n.º 4
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);
    }
}