language->id, null, 0, 'id_product', 'DESC'); $link = Context::getContext()->link; foreach ($products as &$product) { $category = new Category((int)$product['id_category_default'], Context::getContext()->language->id); $product['product_link'] = str_replace(' ', '%20', $link->getProductLink($product['id_product'])); $product['category_name'] = $category->name; $product['description_short'] = strip_tags($product['description_short']); $date = date('D, d M Y H:i:s', strtotime($product['date_add'])); $product['publish_date'] = $date . ' GMT'; } createRSS($name, $products, array('id_product' => 'guid', 'product_link' => 'link', 'name' => 'title', 'description_short' => 'description', 'category_name' => 'category', 'publish_date' => 'pubDate')); } function createCmsRSS($name) { $collection_post = new Collection('CmsPsPost', Context::getContext()->language->id); $collection_post->where('active', '=', 1); $collection_post->orderBy('date_add', 'DESC'); $posts = $collection_post->getResults(); $posts = CmsPsPost::injectsData($posts); $link = Context::getContext()->link; $dataPosts = array(); foreach ($posts as $post) { $category = new CmsPsCategory((int)$post->id_category, Context::getContext()->language->id); $dataPost = array(); $dataPost['title'] = $post->title; $dataPost['post_link'] = str_replace(' ', '%20', $link->getPostCmsLink($post->id_post)); $dataPost['category_name'] = $category->title; $dataPost['intro'] = strip_tags(str_replace("\n", '', $post->intro)); $dataPost['id'] = $post->id_post; $date = date('D, d M Y H:i:s', strtotime($post->date_add)); $dataPost['publish_date'] = $date . ' GMT'; $dataPosts[] = $dataPost; } createRSS($name, $dataPosts, array('id' => 'guid', 'title' => 'title', 'post_link' => 'link', 'category_name' => 'category', 'intro' => 'description', 'publish_date' => 'pubDate')); } function createRSS($name, $datas, $keys) { $xml = ''; $xml .= ''; $xml .= ''; $xml .= ''.$name.''; $xml .= ''._PS_BASE_URL_.'/rss/'.$name.'.xml'; $xml .= ''.$name.' RSS'; foreach ($datas as $data) { $xml .= ''; foreach ($keys as $key => $label) { if (!empty($data[$key])) { if ($label == 'guid') { $xml .= '<'.$label.' isPermaLink="false">'; } else { $xml .= '<'.$label.'>'; } $xml .= ''; $xml .= ''; } } $xml .= ''; } $xml .= ''; $xml .= ''; file_put_contents(__DIR__ . '/rss/' . $name . '.xml', $xml); }