Image Sitemap with Zend_Navigation - image

I generate a Sitemap using Zend_Navigation and i wanted to add images to this sitemap, now i got no Idea how to get this done, i use following (working) code to generate the sitemap
foreach($sitemapItems as $item)
{
$newSite = new Zend_Navigation_Page_Uri();
$newSite->uri = 'http://' . $_SERVER['HTTP_HOST'] . $item->getSpeakingUrl();
$newSite->lastmod = $item->getUpdatedAt();
$newSite->changefreq = 'weekly';
$this->_navigation->addPage($newSite);
}
$this->view->navigation($this->_navigation);
$this->view->navigation()->sitemap()->setFormatOutput(true);
The Output is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://test.dev/pictures/site-28.html</loc>
<lastmod>2010-03-11T17:47:30+01:00</lastmod>
<changefreq>weekly</changefreq>
</url>
....
I need the following Output inside the Url part
<image:image>
<image:loc>http://example.com/image.jpg</image:loc>
</image:image>
i tried to just set
$newSite->image = URI
but it didnt work also i tried to add custom attribute via
$newSite->__set('image', array('loc' => URI));
Does anyone know if what i want is even possible ? i cant find anything in the docs or web...
Thanks for your time,
Dominik

Oki so first what you need to do is extend Zend_Navigation_Page_Uri and add you're image var to it smth like below :
class Mylib_NavPageUriImage extends Zend_Navigation_Page_Uri
{
protected $_image = null;
public function setImage($image)
{
if (null !== $image && !is_string($image)) {
require_once 'Zend/Navigation/Exception.php';
throw new Zend_Navigation_Exception(
'Invalid argument: $image must be a string or null');
}
$this->_image = $image;
return $this;
}
public function getImage()
{
return $this->_image;
}
public function toArray()
{
return array_merge(
parent::toArray(),
array(
'image' => $this->getImage()
));
}
}
Add this class to library/Mylib/NavPageUriImage.php.
To make it usable you need to register the namespace ( i like to register my namespaces at bootstrap but it can be done from app.ini too ) so in you're bootstrap class add the following :
function _initNamespace()
{
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Mylib_');
}
Then in you're controller you can now use :
$newSite = new Mylib_NavPageUriImage();
$newSite->uri = 'http://' . $_SERVER['HTTP_HOST'] . $item->getSpeakingUrl();
$newSite->lastmod = $item->getUpdatedAt();
$newSite->changefreq = 'weekly';
$newSite->image = 'some image';
THE FOLLOWING IS NOT RECOMENDED , YOU NEED TO EXTEND YOU'RE OWN NAVIGATION HELPER AND USE THAT ( i just don't have the time to play with it now ) ALLSO ADD YOU'RE OWN imageValidator
And then in library/zend/view/helper/navigation/sitemap.php add the following lines ( under the add priority element if statement , mine ends at 443 so i added this at 444 ) :
// add 'image' element if a valid image is set in page
if (isset($page->image)) {
$image = $page->image;
$imgDom = $dom->createElementNS(self::SITEMAP_NS, 'image:image');
$imgDom->appendChild($dom->createElementNS(self::SITEMAP_NS, 'image:loc', $image));
$urlNode->appendChild($imgDom);
}

Related

October CMS extend System/Models/File

I trying to keep original file name when using System/Models/File, I got following code to extend this model:
namespace System\Models;
class NewFile extends File { public function fromPost($uploadedFile) { if ($uploadedFile === null) { return; }
$this->file_name = $uploadedFile->getClientOriginalName();
$this->file_size = $uploadedFile->getClientSize();
$this->content_type = $uploadedFile->getMimeType();
$this->disk_name = $this->getDiskName();
/*
* getRealPath() can be empty for some environments (IIS)
*/
$realPath = empty(trim($uploadedFile->getRealPath()))
? $uploadedFile->getPath() . DIRECTORY_SEPARATOR . $uploadedFile->getFileName()
: $uploadedFile->getRealPath();
//$this->putFile($realPath, $this->disk_name);
$this->putFile($realPath, $this->file_name);
return $this;
It works with file itself, it keeps original name but problem is link to attached file is still being generated. Broke my mind but cant get this work. Can anyone elaborate how to fix it?
Oh I see it seems its try to use disk_name to generate URL
so you did well for saving an image
//$this->putFile($realPath, $this->disk_name);
$this->putFile($realPath, $this->file_name);
but you just need to replace one line .. just undo your changes and make this one change
$this->file_name = $uploadedFile->getClientOriginalName();
$this->file_size = $uploadedFile->getClientSize();
$this->content_type = $uploadedFile->getMimeType();
// $this->disk_name = $this->getDiskName();
$this->disk_name = $this->file_name;
// use same file_name for disk ^ HERE
Link logic ( for referance only ) vendor\october\rain\src\Database\Attach\File.php and modules\system\models\File.php
/**
* Returns the public address to access the file.
*/
public function getPath()
{
return $this->getPublicPath() . $this->getPartitionDirectory() . $this->disk_name;
}
/**
* Define the public address for the storage path.
*/
public function getPublicPath()
{
$uploadsPath = Config::get('cms.storage.uploads.path', '/storage/app/uploads');
if ($this->isPublic()) {
$uploadsPath .= '/public';
}
else {
$uploadsPath .= '/protected';
}
return Url::asset($uploadsPath) . '/';
}
Just make disk_name also same as file_name so when file saved on disk it will use original name and when the link is generated it also use disk_name which is original file_name
now your link and file name are synced and will be same always.
if any doubt please comment.

How to create a slug from title and subtitle in Laravel 5

I want to create a slug. it should be a concatenation of title and subtitle.The following is my code and it's not working, i don't know where i went wrong?
public function setTitleAttribute($value)
{
$this->attributes['main_title'] = ucfirst($value);
$this->attributes['sub_title'] = $value;
if (! $this->exists) {
$this->attributes['slug'] = str_slug($this->attributes['main_title'].$this->attributes['sub_title']);
}
}
I need slug as a combination of main_title+sub_title
public function to_slug ($string) {
$table = array(
'Š'=>'S', 'ı'=>'i', 'ğ'=>'g', 'ü'=>'u', 'ş'=>'s', 'ö'=>'o', 'ç'=>'c', 'Ğ'=>'G', 'Ü'=>'U', 'Ş'=>'S',
'İ'=>'I', 'Ö'=>'O', 'Ç'=>'C',
'š'=>'s', 'Đ'=>'Dj', 'đ'=>'dj', 'Ž'=>'Z', 'ž'=>'z', 'Č'=>'C', 'č'=>'c', 'Ć'=>'C', 'ć'=>'c',
'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O',
'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss',
'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e',
'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o',
'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b',
'ÿ'=>'y', 'Ŕ'=>'R', 'ŕ'=>'r',
);
return preg_replace('/[^A-Za-z0-9-]+/', '-', strtr($string, $table) );
}
I'm using this code and its working for me.
It is also good for utf-8.
You can use a laravel package:
https://github.com/cviebrock/eloquent-sluggable
Or I use JavaScript when I sent the form:
https://github.com/madflow/jquery-slugify
I have replicated the exact condition like yours passing static data and its working perfectly in my machine.. try below solution.. do some dd and see whats the combination of the main_title and sub_title is resulting. Also check by removing that if condition once.
$this->attributes['main_title'] = ucfirst($value) . " ";
$this->attributes['sub_title'] = $value;
$slugToUse = $this->attributes['main_title'] . $this->attributes['sub_title'];
if (! $this->exists) {
$this->attributes['slug'] = str_slug($slugToUse);
}
}

Dynamic filter with liipImagineBundle

I'm using liipImagineBundle and am trying to apply a filter directly into a controller.
In the doc I found two sections in which explains how to use liipImagineBundle from the controller. This one https://github.com/liip/LiipImagineBundle#using-the-controller-as-a-service
public function indexAction()
{
// RedirectResponse object
$imagemanagerResponse = $this->container
->get('liip_imagine.controller')
->filterAction(
$this->getRequest(),
'uploads/foo.jpg', // original image you want to apply a filter to
'my_thumb' // filter defined in config.yml
);
// string to put directly in the "src" of the tag <img>
$srcPath = $imagemanagerResponse->headers->get('location');
// ..
}
And https://github.com/liip/LiipImagineBundle/blob/master/Resources/doc/filters.md#dynamic-filters
public function filterAction(Request $request, $path, $filter)
{
$targetPath = $this->cacheManager->resolve($request, $path, $filter);
if ($targetPath instanceof Response) {
return $targetPath;
}
$image = $this->dataManager->find($filter, $path);
$filterConfig = $this->filterManager->getFilterConfiguration();
$config = $filterConfig->get($filter);
$config['filters']['thumbnail']['size'] = array(300, 100);
$filterConfig->set($filter, $config);
$response = $this->filterManager->get($request, $filter, $image, $path);
if ($targetPath) {
$response = $this->cacheManager->store($response, $targetPath, $filter);
}
return $response;
}
I tested as indicated in "Using the controller as a service" and it works, the problem I have is that I don't know how to access the filter settings to modify it.
liip_imagine:
driver: gd
web_root: %kernel.root_dir%/../web
data_root: %kernel.root_dir%/../web
cache_mkdir_mode: 0777
cache_prefix: /media/cache
cache: web_path
cache_clearer: true
data_loader: filesystem
controller_action: liip_imagine.controller:filterAction
formats: []
filter_sets:
my_thumb:
filters:
crop: { start: [0, 0], size: [200, 150] }
my_paste:
quality: 90
filters:
paste: { start: [30, 60], image: ../web/uploads/images/firma.jpg }
The second, really, I don't understand when he says "With a custom data loader...".
In the example he is only modifying the method filteraction() from the ImagineController class (Liip\ImagineBundle\Controller). I wonder how I can modify that method dynamically? For example from my controller indexAction().
Also i have read this post https://stackoverflow.com/questions/16166719/loading-your-custom-filters-with-liipimaginebundle where #NSCoder says that "You can use the built in filter and modify their configuration." but i don't understand it.
I've been looking for several days but I haven't found an example from which to start.
Looking for some more I found another LiipImagineBundle topic (Use LiipImagineBundle to Resize Image after Upload?) that has helped me to do what I wanted..
here I leave the code I use to dynamically apply a filter
public function indexAction()
{
$container = $this->container;
# The controller service
$imagemanagerResponse = $container->get('liip_imagine.controller');
# The filter configuration service
$filterConfiguration = $container->get('liip_imagine.filter.configuration');
# Get the filter settings
$configuracion = $filterConfiguration->get('my_thumb');
# Update filter settings
$configuracion['filters']['crop']['size'] = array(50, 150);
$configuracion['filters']['crop']['start'] = array(10, 10);
$filterConfiguration->set('my_thumb', $configuracion);
# Apply the filter
$imagemanagerResponse->filterAction($this->getRequest(),'uploads/images/logo.jpg','my_thumb');
# Move the img from temp
$fileTemporal = new File('media/cache/my_thumb/uploads/images/logo.jpg');
$fileTemporal->move('uploads/images/', 'mini-logo.jpg');
####################################
}

Adding step to Magento onepage checkout process

I am try to create an additional step in the Magento onepage checkout process.
I am following the tutorial located at http://www.excellencemagentoblog.com/magento-onestep-checkout-add-step but specifically adding a step at the end before the review.
My folder / file structure is as follows. (Ignore widget.xml)
I have uploaded the code in it's current state to this gist:
https://gist.github.com/Relequestual/5263498
I have the theme set to 'new'.
I am var_dumping the $this->getSteps() which shows that the 'testcheck' returns null.
In config.xml, if I change under gobal, blocks, checkout, rewrite, onepage to the same class with '_TestCheck' on the end, the checkout doesn't display at all, but 'Test Check' appears in the progress section on the right. When I revert this change, it then shows as not being null in the var dump like so...
But, I still don't see the step actually added to the page.
I've not done any magento before, so feel a bit in over my head. I expect there is some problem with the xml configuration files, but I've been working on this for 2 days now, and am somewhat lost as to what else I can try.
I know this question may sound similar to others, which it is, however I can't find a question where the OP has the same symptoms as what I am seeing.
By default magento gives some checkout steps. But Sometime you need to add extra information from the customer for future reference. A common requested customization is to add the Custom Form in default checkout process.
This is not good practice to touch core files. You can do this via overriding Modules.
In this example Comapnyname is Ipragmatech and Module name is Checkoutstep.
Step1: Add Custom step in the checkout process
Open the Ipragmatech > Checkoutstep > Block > Onepage> Checkoutstep.php file and write the following code
class Ipragmatech_Checkoutstep_Block_Onepage_Checkoutstep extends Mage_Checkout_Block_Onepage_Abstract
{
protected function _construct()
{
$this->getCheckout()->setStepData('checkoutstep', array(
'label' => Mage::helper('checkout')->__('Invitation to participation'),
'is_show' => true
));
parent::_construct();
}
}
Step2: Add steps which and where you want in the checkout process
Open the Ipragmatech > Checkoutstep > Block > Onepage> Checkoutstep.php file and write the following code
class Ipragmatech_Checkoutstep_Block_Onepage extends Mage_Checkout_Block_Onepage
{
public function getSteps()
{
$steps = array();
if (!$this->isCustomerLoggedIn()) {
$steps['login'] = $this->getCheckout()->getStepData('login');
}
$stepCodes = array('billing', 'shipping', 'shipping_method', 'payment', 'checkoutstep', 'review');
foreach ($stepCodes as $step) {
$steps[$step] = $this->getCheckout()->getStepData($step);
}
return $steps;
}
}
Step3: Grab the submitted value of custom form and set the values of Custom form
Open the ipragmatech > Checkoutstep > controllers > OnepageController.php and write the following fucntion
public function saveCheckoutstepAction()
{
$this->_expireAjax();
if ($this->getRequest()->isPost()) {
//Grab the submited value
$_entrant_name = $this->getRequest()->getPost('entrant_name',"");
$_entrant_phone = $this->getRequest()->getPost('entrant_phone',"");
$_entrant_email = $this->getRequest()->getPost('entrant_email',"");
$_permanent_address = $this->getRequest() ->getPost('permanent_address',"");
$_address = $this->getRequest()->getPost('local_address',"");
Mage::getSingleton('core/session') ->setIpragmatechCheckoutstep(serialize(array(
'entrant_name' =>$_entrant_name,
'entrant_phone' =>$_entrant_phone,
'entrant_email' =>$_entrant_email,
'permanent_address' =>$_permanent_address,
'address' =>$_address
)));
$result = array();
$redirectUrl = $this->getOnePage()->getQuote()->getPayment() ->getCheckoutRedirectUrl();
if (!$redirectUrl) {
$this->loadLayout('checkout_onepage_review');
$result['goto_section'] = 'review';
$result['update_section'] = array(
'name' => 'review',
'html' => $this->_getReviewHtml()
);
}
if ($redirectUrl) {
$result['redirect'] = $redirectUrl;
}
$this->getResponse()->setBody(Zend_Json::encode($result));
}
}
Step4: Save Custom Form information
When checkout_onepage_controller_success_action
event hook is called. Open the Ipragmatech > Checkoutstep > Model >Observer.php and write the following
class Ipragmatech_Checkoutstep_Model_Observer {
const ORDER_ATTRIBUTE_FHC_ID = 'checkoutstep';
public function hookToOrderSaveEvent() {
if (Mage::helper('checkoutstep')->isEnabled()) {
$order = new Mage_Sales_Model_Order ();
$incrementId = Mage::getSingleton ( 'checkout/session' )->getLastRealOrderId ();
$order->loadByIncrementId ( $incrementId );
// Fetch the data
$_checkoutstep_data = null;
$_checkoutstep_data = Mage::getSingleton ( 'core/session' )->getIpragmatechCheckoutstep ();
$model = Mage::getModel ( 'checkoutstep/customerdata' )->setData ( unserialize ( $_checkoutstep_data ) );
$model->setData ( "order_id",$order["entity_id"] );
try {
$insertId = $model->save ()->getId ();
Mage::log ( "Data successfully inserted. Insert ID: " . $insertId, null, 'mylog.log');
} catch ( Exception $e ) {
Mage::log ( "EXCEPTION " . $e->getMessage (), null, 'mylog.log' );
}
}
}
}
Magento – Add Custom Form in Checkout Extension is a complete solution to add extra step in Checkout process for your ecommerce website. It allow admin to export data from custom table in CSV format.
Visit the link to get this free extension http://www.magentocommerce.com/magento-connect/custom-form-in-checkout.html

Magento Adding Step to Onepage Checkout

I'm attempting to add a very basic (literally just a div with some text and a continue button) step to the onepage checkout but have come up short, in that they don't work (i suspect it's because they were created prior to 1.7.0.2), when following the examples here (Fontis), here (inchoo) and here (Magento Forums).
I've also tried to combined bits from different examples and forum posts but i've gotten no where in the week i've been attempting to do this.
I have been recommended the book 'Php Architect's Guide to E-Commerce Programming with Magento' which i've purchased and will begin reading but i was wondering if someone could kindly point me in the right direction in adding a new step to 1.7.0.2's onepage checkout?
Much appreciated for any help!
I have done this successfully in 1.7.0.2 following this guide:
http://www.excellencemagentoblog.com/magento-onestep-checkout-add-step
In summary, you need to extend/override Mage_Checkout_Block_Onepage::getSteps() to add your new step in the sequence.
Create your new step's block/template (loaded using an Ajax request when the previous step is completed) Your block class will need to extend: Mage_Checkout_Block_Onepage_Abstract
You also need to extend the onepagecheckout javascript as this does much of the heavy lifting. The Prototype library has a nice way of doing this.
Finally you will need to extend the controller class (Mage_Checkout_OnepageController) to override the responses of any existing steps, return the content of your new step (loaded using ajax), and handle the save action of any data (form fields etc) entered in your new step.
By default magento gives some checkout steps. But Sometime you need to add extra information from the customer for future reference. A common requested customization is to add the Custom Form in default checkout process.
This is not good practice to touch core files. You can do this via overriding Modules.
In this example Comapnyname is Ipragmatech and Module name is Checkoutstep.
Step1: Add Custom step in the checkout process
Open the Ipragmatech > Checkoutstep > Block > Onepage> Checkoutstep.php file and write the following code
class Ipragmatech_Checkoutstep_Block_Onepage_Checkoutstep extends Mage_Checkout_Block_Onepage_Abstract
{
protected function _construct()
{
$this->getCheckout()->setStepData('checkoutstep', array(
'label' => Mage::helper('checkout')->__('Invitation to participation'),
'is_show' => true
));
parent::_construct();
}
}
Step2: Add steps which and where you want in the checkout process
Open the Ipragmatech > Checkoutstep > Block > Onepage> Checkoutstep.php file and write the following code
class Ipragmatech_Checkoutstep_Block_Onepage extends Mage_Checkout_Block_Onepage
{
public function getSteps()
{
$steps = array();
if (!$this->isCustomerLoggedIn()) {
$steps['login'] = $this->getCheckout()->getStepData('login');
}
$stepCodes = array('billing', 'shipping', 'shipping_method', 'payment', 'checkoutstep', 'review');
foreach ($stepCodes as $step) {
$steps[$step] = $this->getCheckout()->getStepData($step);
}
return $steps;
}
}
Step3: Grab the submitted value of custom form and set the values of Custom form
Open the ipragmatech > Checkoutstep > controllers > OnepageController.php and write the following fucntion
public function saveCheckoutstepAction()
{
$this->_expireAjax();
if ($this->getRequest()->isPost()) {
//Grab the submited value
$_entrant_name = $this->getRequest()->getPost('entrant_name',"");
$_entrant_phone = $this->getRequest()->getPost('entrant_phone',"");
$_entrant_email = $this->getRequest()->getPost('entrant_email',"");
$_permanent_address = $this->getRequest() ->getPost('permanent_address',"");
$_address = $this->getRequest()->getPost('local_address',"");
Mage::getSingleton('core/session') ->setIpragmatechCheckoutstep(serialize(array(
'entrant_name' =>$_entrant_name,
'entrant_phone' =>$_entrant_phone,
'entrant_email' =>$_entrant_email,
'permanent_address' =>$_permanent_address,
'address' =>$_address
)));
$result = array();
$redirectUrl = $this->getOnePage()->getQuote()->getPayment() ->getCheckoutRedirectUrl();
if (!$redirectUrl) {
$this->loadLayout('checkout_onepage_review');
$result['goto_section'] = 'review';
$result['update_section'] = array(
'name' => 'review',
'html' => $this->_getReviewHtml()
);
}
if ($redirectUrl) {
$result['redirect'] = $redirectUrl;
}
$this->getResponse()->setBody(Zend_Json::encode($result));
}
}
Step4: Save Custom Form information
When checkout_onepage_controller_success_action
event hook is called. Open the Ipragmatech > Checkoutstep > Model >Observer.php and write the following
class Ipragmatech_Checkoutstep_Model_Observer {
const ORDER_ATTRIBUTE_FHC_ID = 'checkoutstep';
public function hookToOrderSaveEvent() {
if (Mage::helper('checkoutstep')->isEnabled()) {
$order = new Mage_Sales_Model_Order ();
$incrementId = Mage::getSingleton ( 'checkout/session' )->getLastRealOrderId ();
$order->loadByIncrementId ( $incrementId );
// Fetch the data
$_checkoutstep_data = null;
$_checkoutstep_data = Mage::getSingleton ( 'core/session' )->getIpragmatechCheckoutstep ();
$model = Mage::getModel ( 'checkoutstep/customerdata' )->setData ( unserialize ( $_checkoutstep_data ) );
$model->setData ( "order_id",$order["entity_id"] );
try {
$insertId = $model->save ()->getId ();
Mage::log ( "Data successfully inserted. Insert ID: " . $insertId, null, 'mylog.log');
} catch ( Exception $e ) {
Mage::log ( "EXCEPTION " . $e->getMessage (), null, 'mylog.log' );
}
}
}
}
Magento – Add Custom Form in Checkout Extension is a complete solution to add extra step in Checkout process for your ecommerce website. It allow admin to export data from custom table in CSV format.
Visit the link to get this free extension http://www.magentocommerce.com/magento-connect/custom-form-in-checkout.html

Resources