how can i generate a sitemap for processwire 3 for huebert-webentwicklung.de/sitemap.xml it doesen't work with the Plugin MarkupSitemapXML. Any idea how to get it work?
Thanks.
Create a new page template (sitemap.xml) then set the page output to be XML the the PW backend. Create a page and link it (set it to hidden).
function renderSitemapPage(Page $page) {
return
"\n<url>" .
"\n\t<loc>" . $page->httpUrl . "</loc>" .
"\n\t<lastmod>" . date("Y-m-d", $page->modified) . "</lastmod>" .
"\n</url>";
}
function renderSitemapChildren(Page $page) {
$out = '';
$newParents = new PageArray();
$children = $page->children;
foreach($children as $child) {
$out .= renderSitemapPage($child);
if($child->numChildren) $newParents->add($child);
else wire('pages')->uncache($child);
}
foreach($newParents as $newParent) {
$out .= renderSitemapChildren($newParent);
wire('pages')->uncache($newParent);
}
return $out;
}
function renderSitemapXML(array $paths = array()) {
$out = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
array_unshift($paths, '/'); // prepend homepage
foreach($paths as $path) {
$page = wire('pages')->get($path);
if(!$page->id) continue;
$out .= renderSitemapPage($page);
if($page->numChildren) $out .= renderSitemapChildren($page);
}
$out .= "\n</urlset>";
return $out;
}
header("Content-Type: text/xml");
echo renderSitemapXML();
Related
I have this code below which generates a query string for my url.
Question I would like to know is there away that it could automatically replace the first & with a ? question mark no matter what the first $_GET is.
$url = '';
if ($this->input->get('directory')) {
$pos = strrpos($this->input->get('directory'), '/');
if ($pos) {
$url .= '&directory=' . urlencode(substr($this->input->get('directory'), 0, $pos));
}
}
if ($this->input->get('target')) {
$url .= '&target=' . $this->input->get('target');
}
if ($this->input->get('thumb')) {
$url .= '&thumb=' . $this->input->get('thumb');
}
$data['parent'] = base_url('image_manager' . $url);
Found solution
$find = '&';
$replace = '?';
$result = preg_replace("/$find/", $replace, $url, 1);
echo $result;
I want to disable the anchor tag of two subcategories. I used a free extension for topmenu. The code for subcategory menu is:
public function drawMenuItem($children, $level = 1)
{
$html = '<div class="itemMenu level' . $level . '">';
$keyCurrent = $this->getCurrentCategory()->getId();
foreach ($children as $child) {
if (is_object($child) && $child->getIsActive()) {
// --- class for active category ---
$active = '';
if ($this->isCategoryActive($child)) {
$active = ' actParent';
if ($child->getId() == $keyCurrent) $active = ' act';
}
// --- format category name ---
$name = $this->escapeHtml($child->getName());
if (Mage::getStoreConfig('custom_menu/general/non_breaking_space')) $name = str_replace(' ', ' ', $name);
$html.= '<a class="itemMenuName level' . $level . $active . '" href="' . $this->getCategoryUrl($child) . '"><span>' . $name . '</span></a>';
$activeChildren = $this->_getActiveChildren($child, $level);
if (count($activeChildren) > 0) {
$html.= '<div class="itemSubMenu level' . $level . '">';
$html.= $this->drawMenuItem($activeChildren, $level + 1);
$html.= '</div>';
}
}
}
$html.= '</div>';
return $html;
}
I tried to disable the two subcategories. But it didn't work. How can I give proper condition to disable particular two subcategories link?
I have a function which builds category tree:
public static function buildSelectTree($tree, $step = 0) {
$result = '';
foreach ($tree as $element) {
$result .= "<option>";
$result .= str_repeat('--', $step) . ' ' . $element->name;
$result .= '</option>';
if ($element->children) {
$result .= self::buildSelectTree($element->children, $step + 1);
}
}
return $result;
}
Is it okay to put it in a model? Or I should put it somewhere else? I don't like the idea to work with html inside a model
I want to add footer row to the table generated by CI table class. There are classes available which extend the table class and add this functionality. I would prefer to use native feature if available without extending the table class.
Is it possible in CI table class?
I ended up putting a div under the table with similar formatting to offer an illusion of footer row. Hopefully in future the table class will include the tfoot feature.
I am aware of extended classes which will add this feature to CI table class.
This is a old question but I just ran into the same issue, here's the modified Table library that allows for table footers
https://github.com/rhspeer/TableWithTableFooter
I did extend the table class, I also set the template to work with jquery ui by default, and unlike the example above, I don't recreate the base methods that don't need updating.
In application/libraries add a file named MY_table.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Table extends CI_Table{
var $footer = array();
function __construct()
{
parent::__construct();
$this->template = array(
'table_open' => '<table class="ui-corner-top ui-widget" >',
'thead_open' => '<thead class="ui-widget-header">',
'thead_close' => '</thead>',
'heading_row_start' => '<tr>',
'heading_row_end' => '</tr>',
'heading_cell_start' => '<th>',
'heading_cell_end' => '</th>',
'tbody_open' => '<tbody class="ui-widget-content">',
'tbody_close' => '</tbody>',
'row_start' => '<tr class="table_row_odd">',
'row_end' => '</tr>',
'cell_start' => '<td>',
'cell_end' => '</td>',
'row_alt_start' => '<tr class="table_row_even">',
'row_alt_end' => '</tr>',
'cell_alt_start' => '<td>',
'cell_alt_end' => '</td>',
'tfoot_open' => '<tfoot class="ui-widget-header ui-priority-secondary">',
'footer_row_start' => '<tr>',
'footer_row_end' => '</tr>',
'footer_cell_start' => '<th>',
'footer_cell_end' => '</th>',
'tfoot_close' => '</tfoot>',
'table_close' => '</table>'
);
$this->empty_cells = ' ';
}
function set_template($template)
{
// extends the normal method so that only the required elements have to be entered. the remainder stay as defaults.
if ( ! is_array($template))
{
return FALSE;
}
else
{
foreach($template as $param => $value)
{
$this->template[$param] = $value;
}
}
}
function set_footer()
{
$args = func_get_args();
$this->footer = $this->_prep_args($args);
}
function clear()
{
$this->footer = array();
parent::clear();
}
// extend the generate table method. just adds the bit in to handle tfoot.
function generate($table_data = NULL)
{
// The table data can optionally be passed to this function
// either as a database result object or an array
if ( ! is_null($table_data))
{
if (is_object($table_data))
{
$this->_set_from_object($table_data);
}
elseif (is_array($table_data))
{
$set_heading = (count($this->heading) == 0 AND $this->auto_heading == FALSE) ? FALSE : TRUE;
$this->_set_from_array($table_data, $set_heading);
}
}
// Is there anything to display? No? Smite them!
if (count($this->heading) == 0 AND count($this->rows) == 0)
{
return 'Undefined table data';
}
// Compile and validate the template date
$this->_compile_template();
// set a custom cell manipulation function to a locally scoped variable so its callable
$function = $this->function;
// Build the table!
$out = $this->template['table_open'];
$out .= $this->newline;
// Add any caption here
if ($this->caption)
{
$out .= $this->newline;
$out .= '<caption>' . $this->caption . '</caption>';
$out .= $this->newline;
}
// Is there a table heading to display?
if (count($this->heading) > 0)
{
$out .= $this->template['thead_open'];
$out .= $this->newline;
$out .= $this->template['heading_row_start'];
$out .= $this->newline;
foreach ($this->heading as $heading)
{
$temp = $this->template['heading_cell_start'];
foreach ($heading as $key => $val)
{
if ($key != 'data')
{
$temp = str_replace('<th', "<th $key='$val'", $temp);
}
}
$out .= $temp;
$out .= isset($heading['data']) ? $heading['data'] : '';
$out .= $this->template['heading_cell_end'];
}
$out .= $this->template['heading_row_end'];
$out .= $this->newline;
$out .= $this->template['thead_close'];
$out .= $this->newline;
}
if (count($this->footer) > 0)
{
$out .= $this->template['tfoot_open'];
$out .= $this->newline;
$out .= $this->template['footer_row_start'];
$out .= $this->newline;
foreach ($this->footer as $footer)
{
$temp = $this->template['footer_cell_start'];
foreach ($footer as $key => $val)
{
if ($key != 'data')
{
$temp = str_replace('<th', "<th $key='$val'", $temp);
}
}
$out .= $temp;
$out .= isset($footer['data']) ? $footer['data'] : '';
$out .= $this->template['footer_cell_end'];
}
$out .= $this->template['footer_row_end'];
$out .= $this->newline;
$out .= $this->template['tfoot_close'];
$out .= $this->newline;
}
// Build the table rows
if (count($this->rows) > 0)
{
$out .= $this->template['tbody_open'];
$out .= $this->newline;
$i = 1;
foreach ($this->rows as $row)
{
if ( ! is_array($row))
{
break;
}
// We use modulus to alternate the row colors
$name = (fmod($i++, 2)) ? '' : 'alt_';
$out .= $this->template['row_'.$name.'start'];
$out .= $this->newline;
foreach ($row as $cell)
{
$temp = $this->template['cell_'.$name.'start'];
foreach ($cell as $key => $val)
{
if ($key != 'data')
{
$temp = str_replace('<td', "<td $key='$val'", $temp);
}
}
$cell = isset($cell['data']) ? $cell['data'] : '';
$out .= $temp;
if ($cell === "" OR $cell === NULL)
{
$out .= $this->empty_cells;
}
else
{
if ($function !== FALSE && is_callable($function))
{
$out .= call_user_func($function, $cell);
}
else
{
$out .= $cell;
}
}
$out .= $this->template['cell_'.$name.'end'];
}
$out .= $this->template['row_'.$name.'end'];
$out .= $this->newline;
}
$out .= $this->template['tbody_close'];
$out .= $this->newline;
}
$out .= $this->template['table_close'];
// Clear table class properties before generating the table
$this->clear();
return $out;
}
}
I think this what are you search for
https://github.com/EllisLab/CodeIgniter/wiki/Table
Not necessary extends table library, you would to use set_template function, passing array template.
My question: how do you use Magmi for bulk image import into Magento?
I've installed it, also got the 'Image attributes processor' plugin. Now what? The documentation on sourceforge is thin and I can't seem to find much on google either. A 'how to' would be appreciated, or hey, even a link to a tutorial.
Thank you. Cheers!
For a conversion to Magento I started out using Magmi as well for importing product data and images. After half a day I stopped with the images side cause I could not get it to work properly.
Did some investigating and Googling and came accross a script to import the images. Don't know from where anymore, but props to the creator of the base!
Seeing your question and remembering my struggle I wanted to share it with you. Hope it helps you out as well ;)
The script uses a table in the Magento-db which holds the image paths and sku's. It pulls the images from the path imports them directly into the Magento db.
Be carefull and testdrive on a test environment before firing it on a live site. Test it thoroughly to make sure it does not mess up your magento database. You also might want to check the image_attribute_id's to be correct as these are different per Magento version I noticed.
Hope it helps:)
############################################################################
#
# Change these variables to suit your store!
#
$_mediaBase = realpath('../media/catalog/product').'/';
$_imagesSrc = realpath('../media/import/_osc_media').'/';
// Image attribute_id's: image=79, small_image=80, thumbnail=81, gallery=82
$imgAttrIds = array(79,80,81,88);
$imageGalId = array(82);
require_once '../app/Mage.php';
#
############################################################################
#
# Debug (true/false)
#
$debug = false;
#
############################################################################
umask(0);
error_reporting(E_ALL);
ini_set('display_errors', '1');
Mage::setIsDeveloperMode(true);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
$connW = Mage::getSingleton('core/resource')->getConnection('core_write');
//$images = scandir($_imagesSrc);
/*
* Relocate the images into Magento friendly format
*/
$imgArr = array();
$imgSkuArr[] = array();
$imgSrcArr[] = array();
$sql = "SELECT sku, image_path
FROM aa_image_paths";
$images = $conn->fetchAll($sql);
/**
* $images =
* [8] => Array(
* [sku] => ST-P006
* [image_path] => 47/ST-P006/Carying bag Heli P005A.jpg
* )
*/
#debug
if($debug == true){
echo '<p>Images: <pre>';
print_r($images);
echo '</pre>';
}//end: debug
//iterator
$y = $z = 0;
foreach($images as $image)
{
$pathChunks = explode('/', $image['image_path']);
$imgFile = end($pathChunks);
$firstDir = strtolower($_mediaBase . substr($imgFile,0,1));
$secondDir = strtolower($firstDir.'/' . substr($imgFile,1,1));
$imageEntityDir = strtolower('/' . substr($imgFile,0,1) . '/' . substr($imgFile,1,1) . '/' . $imgFile);
#debug
if($debug == true){
echo '<p>imgFile: ' . $imgFile . '<br />imageEntityDir: ' . $imageEntityDir . '</p>';
}//end: debug
/**
* Get the product_entity details
*/
$sql = "SELECT *
FROM catalog_product_entity
WHERE sku = '" . $image['sku'] . "'";
$_products = $conn->fetchAll($sql);
#debug
if($debug == true){
echo '<p>SQL: ' . $sql . '<br />';
echo '_products:<br />';
echo '<pre>';
print_r($_products);
echo '</pre></p>';
echo (isset($_products)) ? '<h6>products isset() = true</h6>' : '<h6>products isset() = false</h6>';
echo (!empty($_products))? '<h6>products empty() = false</h6>' : '<h6>products empty() = true</h6>';
}//end:debug
if(!empty($_products))
{
if(file_exists($_imagesSrc . $image['image_path'])){
$path = strtolower($secondDir . '/' . $imgFile);
if(!file_exists($path)) {
echo "Making $secondDir and copying to $path";
/**
* If NOT debug than do copy and mkdir stuff!
*/
if($debug == false)
{
if (!file_exists($secondDir)){
mkdir($secondDir, 0777, true);
}
copy($_imagesSrc . $image['image_path'], $path);
}//end: debug FALSE
}//end:if(!file_exists($path)) {
#debug
if($debug == true){
echo '<p>_imagesSrc + image_path: ' . $_imagesSrc . $image['image_path'] . '<br />';
echo 'image[image_path]' . $image['image_path'] . '<br />';
echo 'path: ' . $path . '<br />';
echo 'image[sku]: ' . $image['sku'] . '<br />';
echo 'imgEntDir: ' . $imageEntityDir . '<br />';
echo '</p>';
}//end: debug
/**
* Create the array for the product with the data.
* #var $product
*/
$productData = array();
$productData['sku'] = $image['sku'];
$productData['entity_id'] = $_products[0]['entity_id'];
$productData['imgSrc'] = $imageEntityDir;
#debug
if($debug == true){
echo 'productData: ' . $productData . '<br />';
echo 'productData[sku]: ' . $productData['sku'] . '<br />';
echo 'productData[entity_id]: ' . $productData['entity_id'] . '<br />';
echo 'productData[imgSrc]: ' . $productData['imgSrc'] . '<br />';
echo 'productData: <pre>';
var_dump($productData);
echo '</pre></p>';
}//end:debug
/**
* Check the existing images
*/
// General Base, small and thumb images
$sql = "SELECT *
FROM catalog_product_entity_varchar
WHERE entity_id = '" . $productData['entity_id'] . "'
AND attribute_id IN (".implode(",",$imgAttrIds).")";
$_imageAssoc = $conn->fetchAll($sql);
$existingImgs = array();
foreach($_imageAssoc as $img)
{
$existingImgs[$img['entity_id']][$img['attribute_id']] = $img;
}
// Gallery Images
$sql = "SELECT *
FROM catalog_product_entity_media_gallery
WHERE entity_id = '" . $productData['entity_id'] . "'";
$_galleryImgs = $conn->fetchAll($sql);
$existingGall = array();
foreach($_galleryImgs as $img)
{
$existingGall[$img['entity_id']][$img['attribute_id']] = $img;
#debug
if($debug == true){
echo '<p>img print_r: <br /><pre>';
print_r($img);
echo '</pre></p>';
}//end:debug
}
#debug
if($debug == true){
# print existingImg
echo '<p>existingImgs print_r: <br /><pre>';
print_r($existingImgs);
echo '</pre></p>';
# print existingGal
echo '<p>existingImgs print_r: <br /><pre>';
print_r($existingImgs);
echo '</pre></p>';
}//end:debug
/**
* Then associate to the product itself.
*/
//$insertData = array();
//$skusToInsert = array();
foreach($_products as $productArrId=>$product) {
$missingImgs = $imgAttrIds;
//$imageName = strtolower('/'.$product['sku'][0].'/'.$product['sku'][1].'/'.$product['sku'].'.jpg');
$imageName = $productData['imgSrc'];
#debug
if($debug == true){
echo '<p>Imagename print_r: <br /><pre>';
print_r($imageName);
echo '</pre></p>';
}//end:debug
// Check if it has an image associated already ...
if ( array_key_exists( $productData['entity_id'], $existingImgs) ) {
// Check which images exists and remove those already set
foreach ($imgAttrIds as $id=>$val) {
if ( array_key_exists( $val , $existingImgs[$productData['entity_id']] ) ) {
//if ( $existingImgs[$productData['entity_id']][$val]['value'] == "no_selection" ) {
$sql = "DELETE FROM catalog_product_entity_varchar WHERE value_id = '".$existingImgs[$productData['entity_id']][$val]['value_id']."'";
#debug
if($debug == true)
{
echo 'SQL base images: <pre>' . $sql . '</pre>';
}
else
{
//Execute the Query
$connW->query($sql);
}
//} else {
unset($missingImgs[$id]);
//}
}//end:f ( array_key_exists( $val
}//end: foreach ($imgAttrIds as $id=>$val) {
}//end;if ( array_key_exists( $productData['entity_id'], $existingImgs) ) {
// Check if it has Gallery images associated already ...
if ( array_key_exists( $productData['entity_id'], $existingGall) ) {
// Check which images exists and remove those already set
foreach ($imageGalId as $id=>$val) {
if ( array_key_exists( $val , $existingGall[$productData['entity_id']] ) ) {
//if ( $existingImgs[$productData['entity_id']][$val]['value'] == "no_selection" ) {
$sql = "DELETE FROM catalog_product_entity_media_gallery_value WHERE value_id = '".$existingGall[$productData['entity_id']][$val]['value_id']."'";
#debug
if($debug == true)
{
echo 'SQL gallery Value: <pre>' . $sql . '</pre>';
}
else
{
//Execute the Query
$connW->query($sql);
}
$sql = "DELETE FROM catalog_product_entity_media_gallery WHERE value_id = '".$existingGall[$productData['entity_id']][$val]['value_id']."'";
#debug
if($debug == true)
{
echo 'SQL gallery: <pre>' . $sql . '</pre>';
}
else
{
//Execute the Query
$connW->query($sql);
}
//} else {
unset($missingImgs[$id]);
//}
}//end:f ( array_key_exists( $val
}//end: foreach ($imgAttrIds as $id=>$val) {
}//end;if ( array_key_exists( $productData['entity_id'], $existingImgs) ) {
foreach ($imgAttrIds as $id=>$val) {
//Update the Media gallery items in DB
$sql = "INSERT INTO catalog_product_entity_varchar (entity_type_id, attribute_id, store_id, entity_id, value) VALUES " .
"(4, " . $val . ", 0, " . $productData['entity_id'] . ", '" . $imageName . "')";
#debug
if($debug == true)
{
echo 'SQL Insert1: <pre>' . $sql . '</pre>';
}
else
{
//Execute the Query
$connW->query($sql);
}
$y++;
}//end:foreach ($imgAttrIds as $id=>$val) {
foreach ($imageGalId as $id=>$val) {
//Update the
$sql = "INSERT INTO catalog_product_entity_media_gallery (attribute_id, entity_id, value) VALUES " .
"(".$val.", ".$productData['entity_id'].", '".$imageName."')";
//implode(",",$skusToInsert) . ";";
#debug
if($debug == true)
{
echo 'SQL Insert1: <pre>' . $sql . '</pre>';
}
else
{
//Execute the Query
$connW->query($sql);
}
//Update the Gallery value
/*
$sql = "INSERT INTO catalog_product_entity_media_gallery_value (value_id, store_id, position, disabled) VALUES " .
"((SELECT value_id FROM catalog_product_entity_media_gallery
WHERE attribute_id = '".$imageGalId."'
AND entity_id = '".$productData['entity_id']."'
AND value = '".$imageName."'),0, 1, 0)";
*/
$sql = "INSERT INTO catalog_product_entity_media_gallery_value (value_id, store_id, position, disabled) " .
"SELECT value_id, 0 store_id, 1 position, 0 disabled
FROM catalog_product_entity_media_gallery
WHERE attribute_id = '".$val."'
AND entity_id = '".$productData['entity_id']."'
AND value = '".$imageName."'";
#debug
if($debug == true)
{
echo 'SQL Insert1: <pre>' . $sql . '</pre>';
}
else
{
//Execute the Query
$connW->query($sql);
}
$z++;
}//end:foreach ($imgAttrIds as $id=>$val) {
}//end:foreach($_products as $productArrId=>$product) {
}//end: if(file_exists($_imagesSrc . $image['image_path']))
}//end: if(!empty($_products))
#debug
if($debug == true){
echo '<hr>';
}//end:debug
}//end:foreach($images as $image)
echo "<h5>Updated ". $y ." images for products. </h5>";
echo "<h5>Updated ". $z ." images in MediaGallery</h5>";
I had the same issue. Its pretty brittle. I realized it had created a new ./magento folder, and dumped the images in there. I merged that into my real magento folder & ran a reindex to fix it.
I then saw the 'path to Magento' setting was ../../magento/, changed this to ../../../magento/.
My setup is like this:
./magento/...files..
./magmi/...files...
It had dumped the images in a folder in ./magmi/magento/media/ because I was missing a ../ when telling magmi the path to my Magento folder. That didn't work because now it says it couldn't find the source images in ./media/import. The only viable solution was to manually merge the magento folders in to each other after each import. What a mess.
FYI In my spreadsheet I put in the image column /image.jpg just like that with the preceding slash.