Pages

Thursday, December 19, 2013

Code for Create or Update Resource in Modx Revo

Code for create new resource in Modx Revo :

                    $class = 'modResource';
                    $resource= $modx->newObject($class);
                    $resource->set('context_key', 'web');
                    $resource->set('content_type', 1);
                    $resource->set('pagetitle', PAGE_TITLE); //  here you enter your new resource pagetitle
                    $resource->set('parent', PARENT_ID); // here you enter parent id in which you want to see you new resource
                    $resource->set('isfolder', false);
                    $resource->set('published', true);
                    $resource->set('template', TEMPLATE_ID); // set template id
                    $resource->set('pub_date', strftime('%Y-%m-%d %H:%M:%S',strtotime(PUBLISH_DATE))); // set publish date
                    $resource->set('searchable', $this->modx->getOption('search_default'));
                    $resource->set('cacheable', $this->modx->getOption('cache_default'));
                   
                    $resource->_fields['content']= $res_content; // set resource content in $res_content
                    $resource->save();

now it will create new reource in your modx. Now,

   
Code for create new resource in Modx Revo :

            $newResourceUpdate = $modx->getObject('modResource',RESOURCE_ID); // set resource id
            $newResourceUpdate->set('template',TEMPLATE_ID);
            $newResourceUpdate->set('parent',PARENT_ID);
            $newResourceUpdate->set('pub_date', strftime('%Y-%m-%d %H:%M:%S',strtotime(PUBLISH_DATE)));
            $newResourceUpdate->save();

After this it will update your resource values.

Comment it and ?Share it if it helps you.

Code for Duplicate resource in modx revo

 Here is the code for Duplicate resource in modx revolution :

            $oldResource = $modx->getObject('modResource',RESOURCE_ID); // set resource id from which you want to Duplicate resource
             if (empty($oldResource)) return $modx->error->failure($modx->lexicon('resource_err_nfs',array('id' => $props['resourceID'])));
           
            if (!$oldResource->checkPolicy('copy')) {
                return $modx->error->failure($modx->lexicon('permission_denied'));
            }
           
            /* get parent */
            $parent = $cat;
           
            $newResource = $oldResource->duplicate(array(
                'newName' => NEW_TITLE,  // New Title which you want to see in new resource
            ));
            if (!($newResource instanceof modResource)) {
                return $newResource;
            }
           
            $modx->invokeEvent('OnResourceDuplicate',array(
                'newResource' => &$newResource,
                'oldResource' => &$oldResource,
            ));

Comment it and Share it if it helps you.

Get Migx TV values from resource in Modx Revo

Here is the code :

                    $docid = RESOURCE_ID; // id of current resource
                    $tvname = 'MultiColumn'; // Name of your TV
                    $tv = $modx->getObject('modTemplateVar', array('name' => $tvname));
                    $outputvalue = $tv->renderOutput($docid);
                    $items = $modx->fromJSON($outputvalue);
                    $idx = 0; // initialize idx
                    $output = array();
                    foreach ($items as $key => $item) {
                        $idx++; // increase idx
                        $output[] = print_r($item,1);
                    }
                    $outputSeparator = "\n";
                    $o = implode($outputSeparator, $output); // implode output

Here you will get all the value from Migx from any resource in arrays.

Comment it and Share it if it helps you.

Monday, October 21, 2013

Return to top in page using jquery

$("html, body").animate({ scrollTop: 0 }, 200);
 
use this jquery code in onclick event. it's working like a charm. This 
is the simplest code for return to top in page. It is also working if 
you are using AJAX and calling from AJAX part.
 
If it's help you, comment it and share it.
 
 
 

Tuesday, October 15, 2013

migx inside migx in Modx Revo

Here i am showing code for migx within another migx in Modx Revolution

BackEnd :
first you have to written below code in "Form tabs" when you create migx TV in which you want to show another migx,

{"field":"institutions","caption":"Institutions","inputTV":"another_migx_name","renderer":"this.renderChunk"},

this will create another migx inside your original migx and store values in it.

FrontEnd :
now in frontend in main migx write simple migx code for fetch values from main migx.
[[!getImageList?
           &tvname='migxTVname`
           &tpl=`mainChunkName`
]]

in another migx for fetching values you can write like this code,
[[!getImageList?
        &value=`[[+institutions]]`
        &tpl=`Chunk_name`
]]

now it's done, and it will show your inside migx values.

If this helps you comment it and share it.

Friday, October 4, 2013

jQuery not working after AJAX call


When programmer bounded the functionality of the click event even before the new content is injected to the DOM. So that functionality will not be available to the newly added (injected) dynamic content. To handle this , you need to use jQuery on

So Change your code from
$(function(){
   $(".class_name").click(function(){    
     // your code    
   });
});
to
$(function(){
    $(document).on("click",".class_name",function(){
       //your code
    });
});
jQuery on will work for current and future elements. on is avaialbe from jQuery 1.7+ onwards. If you are using a previous version of jQuery, use live

So Change code in previous version
$(".class_name").live("click",function(){

Wednesday, March 6, 2013

Get resource id from resource name in modx revolution


$resource = $modx->getObject('modResource',Resource_Id);
$longTitle = $resource->get('pagetitle');

Here, from above code you can get pagetitle from resource id(Resource_Id).



Get resource id from resource name

$resource = $modx->getObject('modResource','Resource_Name');
$longTitle = $resource->get('id');

in this code you can get resource id from resource pagetitle('Resource_Name').

Get template id from template name modx revolution

$templateObj = $modx->resource->getOne('Template',array('templatename'=>'Template_Name'));
$templateid = $templateObj->get('id');

Here, in this code "Template_Name" is template name from which user want to get template id.

Wednesday, December 12, 2012

TV image preview modx Revo

There is a bug in modx revo that in manager i can't see image preview in TV.

Solutions is :

So, following the method mentioned in the bug report, I simply changed Line 219 in core/model/phpthumb/phpthumb.class.php:

From :
$this->config_document_root = (@$_SERVER['DOCUMENT_ROOT'] ? $_SERVER['DOCUMENT_ROOT'] : $this->config_document_root);

To :
$this->config_document_root = (@$_SERVER['DOCUMENT_ROOT'] ? '/home/username/public_html' : $this->config_document_root);

and it's worked for me.

Thursday, May 10, 2012

Display product list Randomly and limited numbers in Magento HomePage

Create new file product_list.phtml and copy content from list.phtml to product_list.phtml, log in to your magento admin go to cms -> pages -> home page
paste step1 to contact area. click save.

step 1.

{{block type="catalog/product_list_random"  category_id="4" template="catalog/product/product_list.phtml"}}

now open product_list.phtml use the code below to display 4 products at once

step 2.
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
    if ($_productCollection->count()):
    $_productCollection = $_productCollection->getItems();

    $i = 0;
             foreach ($_productCollection as $_product):
        if ($i < 4):
                             // Product Data With CSS
        endif;
    $i++;
     endforeach;
    endif;

?>
 Now you can show your index page product list randomly with 3 limited number products.

Comment it and share it.

Wednesday, May 9, 2012

Replace default email logo in welcome email Magento

You can create a new theme and place it there. This isn't as difficult as it sounds because of the way themes fall back onto defaults in Magento. If Magento can't find something in your theme, it will fall back onto the base theme by looking in the default folder.

For example, in a store that you maintain, you uploaded your own version of the e-mail logo image in
/skin/frontend/{package}/{my-theme-name}/images/logo_email.gif
and in the Administration panel, you went to System > Configuration > Design > Themes and set Default to {your-theme-name}.

Why does this work?
In the e-mail templates, Magento specifies the src of the logo image as {{skin url="images/logo_email.gif" _area='frontend'}}. This is Magento template gibberish for "find the images/logo_email.gif in the frontend area of the current theme." So Magento looks in for /frontend/{package}/{your-theme-name}/images/logo_email.gif, finds it, and uses that path when dishing out the HTML.

If you delete your image, it doesn't break! Instead, although Magento would still first search in your theme directory as described above, it would discover that it doesn't exist and fall back onto the one in /frontend/{package}/default/images/logo_email.gif.

Good luck, and hope this helps!

Tuesday, May 8, 2012

Magento Backend user edit in account information checkboxes values show and update code

You have to customize in couple of file for showing checked value and update those checkboxes in magento backend Account Information page.

for showing checked value
app/code/core/Mage/Adminhtml/controllers/CustomerController.php

and for update checkboxes value
app/code/core/Mage/Adminhtml/Block/Widget/form.php


          else if ($inputType == 'checkbox') {
                    $customer11 = Mage::registry('current_customer');
                    if($customer11->getData($attribute->getAttributeCode()) == '1' || $customer11->getData($attribute->getAttributeCode()) != '')
                        $element->setChecked('1');
                    else if($customer11->getData($attribute->getAttributeCode()) == '0' || $customer11->getData($attribute->getAttributeCode()) == '')
                        $element->setChecked('0');
                }

set this codition in function _setFieldset in form.php file for showing your checkbox is checked or not in backend Account infomation page in magento.


            $emailprefs = array(
                'ATTRIBUTECODE1','ATTRIBUTECODE2','ATTRIBUTECODE3',...,
            );
            // Prepare customer saving data
            if (isset($data['account'])) {
                foreach($emailprefs as $pref){
                    $data['account'][$pref] = isset($data['account'][$pref]) ? 1 : 0;
                }
               
                if (isset($data['account']['email'])) {
                    $data['account']['email'] = trim($data['account']['email']);
                }
                $customer->addData($data['account']);
            }

Put this code in function saveAction() in CustomerController.php page for updating your checkboxes values in backend Account infomation page in magento. Replace 'ATTRIBUTECODE' with your checkboxes attribute codes.

Magento update checkboxes in frontend edit registration page code


app\code\core\Mage\Customer\controllers\AccountController.php
 
             /**
             * we would like to preserver the existing group id
             */
            if ($this->_getSession()->getCustomerGroupId()) {
                $customer->setGroupId($this->_getSession()->getCustomerGroupId());
            }

            /**
             * Custom coding for Promoted Update & Rented Update by Leo
             */
            if ($this->getRequest()->getParam('ATTRIBUTE_CODE')) {
                $customer->setATTRIBUTE_CODE(1);
            } else {
                $customer->setATTRIBUTE_CODE(0);
            }
            /**
             * End
             */

From this customizing user can update checkboxes values from edit registration page frontside in Magento if user has checkbox fields in registration of his magento site. Replace 'ATTRIBUTE_CODE' with your checkbox attribute code.

Thursday, May 3, 2012

Find number of total checkboxes in form or page Javascript

var formobj = document.getElementById('FORM_ID');
var counter = 0;
for (var j = 0; j < formobj.elements.length; j++)
{
    if (formobj.elements[j].type == "checkbox")
    {
        if (formobj.elements[j].checked)
        {
            counter++;
        }
    } 
}

alert('Total Checked = ' + counter);
 
This javascript is using to find number of total checkboxes in form or page and also 
user can find from all checkboxes how many is checked. In this 'FORM_ID' is the id 
of <form>.

Saturday, February 25, 2012

How to check if GD Library is installed?

Try this:

php Code: 
<?php 
if (extension_loaded('gd') && function_exists('gd_info')) {
     echo "It looks like GD is installed";  
}
?>


You could also spit some info about your GD version by doing this:

php Code: 
<?php
  echo "<pre>"; var_dump(gd_info()); echo "</pre>";
 ?>
 
You will definitely get the ans of your GD Library is installed or not.

Inserting and Updating Records Using JDatabase in Joomla

When you are doing simple single table inserts and updates you can use the JDatabase methods to do so. The advantages of using the JDatabase methods is it saves your time from hand coding sql and will escape and correctly quote your inputs for you.

The following will insert a new record into a table:

<?php 
$db = JFactory::getDBO();
//Create data object
$row = new JObject();
$row->title = 'The Title';
$row->author = 'Bob Smith';
//Insert new record into #__book table.
$ret = $db->insertObject('#__book', $row);
//Get the new record id
$new_id = (int)$db->insertid();
?>
 
This will update an existing record:
<?php
$db = JFactory::getDBO();
//Create data object
$row = new JObject();
//Record to update
$row->rec_id = 200;
$row->title = 'The Title';
$row->author = 'Bob Smith';
//Update the record. Third parameter is table id field that will be used to update.
$ret = $db->updateObject('#__book', $row,'rec_id');
?>
 
You can also use JTable to insert and update records, but requires more initial setup since you have to create a new JTable class for each table you want to modify. Using JTable is preferred if table has many fields to update from a form submit. JTable will automatically bind the form fields to corresponding table fields using the bind() method.

Here is more info on using JTable.

Tuesday, January 10, 2012

Convert Joomla 1.5 AJAX into Joomla 1.7



Joomla 1.5 AJAX Syntax

var a = new Ajax( url, {
 method: 'get',onComplete: function(){
 alert("AJAX is Working in Joomla 1.5")},
 update: element
}).request();


Joomla 1.6/1.7 AJAX Syntax

var a = new Request.HTML({
 url: url,
 method: 'get',onComplete: function(){
 alert("AJAX is Working in Joomla 1.7")},
 update: element
}).send();


Joomla 1.5 above AJAX syntax is not working in Joomla 1.7 because in Joomla 1.7 AJAX is not defined in mootools. so this perticular Joomla 1.6/1.7 AJAX syntax is properly working in Joomla 1.7 and in Joomla 1.6 also.

Convert BBCode to HTML in PHP

function bb2html($message)
        {                               
            $preg = array(
                '/(?<!\\\\)\[COLOR(?::\w+)?=(.*?)\](.*?)\[\/COLOR(?::\w+)?\]/si'   => "<span style=\"color:\\1\">\\2</span>",
                '/(?<!\\\\)\[SIZE(?::\w+)?=(.*?)\](.*?)\[\/SIZE(?::\w+)?\]/si'     => "<span style=\"font-size:\\1\">\\2</span>",
                '/(?<!\\\\)\[FONT(?::\w+)?=(.*?)\](.*?)\[\/FONT(?::\w+)?\]/si'     => "<span style=\"font-family:\\1\">\\2</span>",
                '/(?<!\\\\)\[ALIGN(?::\w+)?=(.*?)\](.*?)\[\/ALIGN(?::\w+)?\]/si'   => "<div style=\"text-align:\\1\">\\2</div>",
                '/(?<!\\\\)\[B(?::\w+)?\](.*?)\[\/B(?::\w+)?\]/si'                 => "<span style=\"font-weight:bold\">\\1</span>",
                '/(?<!\\\\)\[I(?::\w+)?\](.*?)\[\/I(?::\w+)?\]/si'                 => "<span style=\"font-style:italic\">\\1</span>",
                '/(?<!\\\\)\[U(?::\w+)?\](.*?)\[\/U(?::\w+)?\]/si'                 => "<span style=\"text-decoration:underline\">\\1</span>",
                '/(?<!\\\\)\[CENTER(?::\w+)?\](.*?)\[\/CENTER(?::\w+)?\]/si'       => "<div style=\"text-align:center\">\\1</div>",
                               
                // [email]
                '/(?<!\\\\)\[EMAIL(?::\w+)?\](.*?)\[\/EMAIL(?::\w+)?\]/si'         => "<a href=\"mailto:\\1\" class=\"bb-email\">\\1</a>",
                '/(?<!\\\\)\[EMAIL(?::\w+)?=(.*?)\](.*?)\[\/EMAIL(?::\w+)?\]/si'   => "<a href=\"mailto:\\1\" class=\"bb-email\">\\2</a>",
                // [url]
                '/(?<!\\\\)\[URL(?::\w+)?\]www\.(.*?)\[\/URL(?::\w+)?\]/si'        => "<a href=\"http://www.\\1\" target=\"_blank\" class=\"bb-url\">\\1</a>",
                '/(?<!\\\\)\[URL(?::\w+)?\](.*?)\[\/URL(?::\w+)?\]/si'             => "<a href=\"\\1\" target=\"_blank\" class=\"bb-url\">\\1</a>",
                '/(?<!\\\\)\[URL(?::\w+)?=(.*?)?\](.*?)\[\/URL(?::\w+)?\]/si'      => "<a href=\"\\1\" target=\"_blank\" class=\"bb-url\">\\2</a>",
                // [img]
                '/(?<!\\\\)\[IMG(?::\w+)?\](.*?)\[\/IMG(?::\w+)?\]/si'             => "<img src=\"\\1\" alt=\"\\1\" class=\"bb-image\" />",
                '/(?<!\\\\)\[IMG(?::\w+)?=(.*?)x(.*?)\](.*?)\[\/IMG(?::\w+)?\]/si' => "<img width=\"\\1\" height=\"\\2\" src=\"\\3\" alt=\"\\3\" class=\"bb-image\" />",
                                       
                // [list]
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[\*(?::\w+)?\](.*?)(?=(?:\s*<br\s*\/?>\s*)?\[\*|(?:\s*<br\s*\/?>\s*)?\[\/?LIST)/si' => "\n<li class=\"bb-listitem\">\\1</li>",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[\/LIST(:(?!u|o)\w+)?\](?:<br\s*\/?>)?/si'    => "\n</ul>",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[\/LIST:u(:\w+)?\](?:<br\s*\/?>)?/si'         => "\n</ul>",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[\/LIST:o(:\w+)?\](?:<br\s*\/?>)?/si'         => "\n</ol>",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[LIST(:(?!u|o)\w+)?\]\s*(?:<br\s*\/?>)?/si'   => "\n<ul class=\"bb-list-unordered\">",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[LIST:u(:\w+)?\]\s*(?:<br\s*\/?>)?/si'        => "\n<ul class=\"bb-list-unordered\">",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[LIST:o(:\w+)?\]\s*(?:<br\s*\/?>)?/si'        => "\n<ol class=\"bb-list-ordered\">",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[LIST(?::o)?(:\w+)?=1\]\s*(?:<br\s*\/?>)?/si' => "\n<ol class=\"bb-list-ordered,bb-list-ordered-d\">",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[LIST(?::o)?(:\w+)?=i\]\s*(?:<br\s*\/?>)?/s'  => "\n<ol class=\"bb-list-ordered,bb-list-ordered-lr\">",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[LIST(?::o)?(:\w+)?=I\]\s*(?:<br\s*\/?>)?/s'  => "\n<ol class=\"bb-list-ordered,bb-list-ordered-ur\">",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[LIST(?::o)?(:\w+)?=a\]\s*(?:<br\s*\/?>)?/s'  => "\n<ol class=\"bb-list-ordered,bb-list-ordered-la\">",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[LIST(?::o)?(:\w+)?=A\]\s*(?:<br\s*\/?>)?/s'  => "\n<ol class=\"bb-list-ordered,bb-list-ordered-ua\">",
                                       
                //line breaks
                '/\n/'                                                               => "<br>",
                // escaped tags like \[b], \[color], \[url], ...
                '/\\\\(\[\/?\w+(?::\w+)*\])/'                                      => "\\1"
                               
            );
                               
            $message = preg_replace(array_keys($preg), array_values($preg), $message);
            return $message;
        }


// Call Function bb2html and echo

$htmltext = bb2html($message);
echo $htmltext;