Friday, 22 August 2014

Parse JSON String by SQL script

The first question: Why do you need to parse JSON by SQL script? You can do it easily by C# or VB, or any PL.
But I sure that if you search this keyword and reach this post, you already have your own reason.
In my case, I got a task from Chris (my manager) in Microsoft, he want to migrate database, one of those step is parse about 100 k Json string and Insert into new table.
I have tried with C#, it worked, but I don't know how long, because I recognize that it is not a smart way and stop them ( program is running and thinking about C# solution). I try with SQL script.

Thanks 
And then try with script
Select * From
parseJSON
(
       '[{"Text":"YES","Value":"YES","Default":true},
       {"Text":"NO","Value":"NO","Default":false}]'

)

Great because we can get all field we need, but that is not the format we want. We should have table with three field TEXT, VALUE and Defaule.

That's why we need do more a little


  • Use this script to query table from JSON string
Select
       max(case when name='Text' then convert(Varchar(50),StringValue) else '' end) as [Text],
       max(case when name='Value' then convert(Varchar(50),StringValue) else '' end) as [Value],
       max(case when name='Default' then convert(bit,StringValue) else 0 end) as [Default]
From parseJSON
(
       '[{"Text":"YES","Value":"YES","Default":true},
       {"Text":"NO","Value":"NO","Default":false}]'
)
where ValueType = 'string' OR ValueType = 'boolean'
group by parent_ID


And this is result


All things I need are some where here, I hope you too.
If you have some problem with this Function, feel free to comment here.
Thanks

Reference: 
  1. https://www.simple-talk.com/sql/t-sql-programming/consuming-json-strings-in-sql-server/
  2. http://msdn.microsoft.com/en-us/library/ms187928.aspx
  3. http://www.w3schools.com/sql/func_convert.asp

Wednesday, 14 August 2013

How to style default Joomla! Pagination with CSS

Most of the sites we design have plenty of fancy elements, but we always end up with a simple or unstyled page navigation list. The PSD always looks unique, but the web version falls short of the designers’ expectations. This is because there are no CSS selectors on the arrows, start, prev, next, end or numbers.
I probably looked at the custom pagination.php 100 times, before realizing how simple it was to add a CSS class to each element.
Ok, time for the good stuff. Here are the simple steps required to add CSS classes to your Joomla! page navigation (pagination) elements:
  1. Create a file named pagination.php in the “html” folder of your template directory. The file structure should be “/templates/yourtemplatename/html/pagination.php”.
  2. Copy the content of this file (pagination.txt) to your newly created pagination.php file.
  3. Open pagination.php and replace this:
    function pagination_item_active(&$item) {
    return "<li><a href=\"".$item->link."\" title=\"".$item->text."\">".$item->text."</a></li>";
    }
    function pagination_item_inactive(&$item) {
    return "<li><span>".$item->text."</span></li>";
    }
    with this:
    function pagination_item_active(&$item) {
    
    //Custom variable created to use as the element class
    $item_class = strtolower($item->text);
    if(is_numeric ($item_class)) {
    $item_class .= " number";
    }
    return "<li class=\"".$item_class."\"><a href=\"".$item->link."\" title=\"".$item->text."\">".$item->text."</a></li>";
    }
    
    function pagination_item_inactive(&$item) {
    
    //Custom variable created to use as the element class
    $item_class = strtolower($item->text);
    if(is_numeric ($item_class)) {
    $item_class .= " number";
    }
    return "<li class=\"".$item_class."\"><span>".$item->text."</span></li>";
    }
Now the li elements of each pagination item should have a class that matches the text of the element. In addition, the numbers should have a second class of “number.”
Your HTML should look like this:
<ul class="pagination">
    <li class="start"><span>Start</span></li>
    <li class="prev"><span>Prev</span></li>
    <li class="1 number"><span>1</span></li>
    <li class="2 number"><a title="2" href="/category/Page-2">2</a></li>
    <li class="3 number"><a title="3" href="/category/Page-3">3</a></li>
    <li class="next"><a title="Next" href="/category/Page-2">Next</a></li>
    <li class="end"><a title="End" href="/category/Page-3">End</a></li>
</ul>

Tuesday, 23 July 2013

Create Facebook comment and Like button for each page ( each Link, each Product)

Create Like Button
- Go to https://developers.facebook.com/docs/reference/plugins/like/
- Clear URL to Like and choice some options by yourself.
- Press Get Code and paste those code on your source code.

Create Comment Facebook
- Go to https://developers.facebook.com/docs/reference/plugins/comments/
- Clear URL to comment on and choice some options by yourself
- Press Get Code and paste those code on your source code with some changes.
- Include code
data-href="http://yourweb.com<?=$_SERVER['REQUEST_URI']?>"
 into this code:
<div class="fb-comments" data-width="470" data-num-posts="10"></div>
This is the final code to put comment box to. Example your website is http://bantudong.com
<div class="fb-comments" data-href="http://bantudong.com<?=$_SERVER['REQUEST_URI']?>" data-width="470" data-num-posts="10"></div>

Sunday, 21 July 2013

Correct Facebook share thumbnail and description - Joomla 2.5 & Virtuemart 2.0

This is a great way to add Open Graph meta tags to the flypage of Virtuemart, to specify the image used by Facebook like, share, send, etc buttons 
I have made some little improvements to your code though, so that it will not be necessary to hard code the domain name of your site and also i added the og::site_name meta tag.
Also I wanted the generated html code to be valid (http://validator.w3.org/) so i had to use addCustomTag() instead of setMetaData() to generate "meta property" instead of "meta name" .

Code: 
$og_type = 'article';
$og_url = JURI::current();
$og_image =  JRoute::_(JURI::base().$this->product->images[0]->file_url);
$og_desc = $this->product->product_s_desc;
$og_title = $this->product->product_name;

$app =& JFactory::getApplication();
$og_sitename = $app->getCfg('sitename');

$doc = JFactory::getDocument();
$doc->addCustomTag('<meta property="og:type" content="article"/>');
$doc->addCustomTag('<meta property="og:url" content="'.$og_url.'"/>');
$doc->addCustomTag('<meta property="og:site_name" content="'.$og_sitename.'"/>');
$doc->addCustomTag('<meta property="og:image" content="'.$og_image.'"/>');
$doc->addCustomTag('<meta property="og:description" content="'.$og_desc.'"/>');
$doc->addCustomTag('<meta property="og:title" content="'.$og_title.'"/>');


This piece of code has to be inserted at the first lines of file "components/com_virtuemart/views/productdetails/tmpl/default.php" just after the line:

Code: 
defined('_JEXEC') or die('Restricted access');
It would be even better if you copy this file at your template directory (folder: templates/my_Joomla_template/html/com_virtuemart/productdetails/) so that it will not be modified by any Virtuemart upgrades.


Check this Change by link:
https://developers.facebook.com/tools/debug

Product sort order on browse/category view - ascending to descending

Problem:
When i show virtuemart home page the product will show in ASC order , (the oldest first) how can i change this with the newest first ?
In the configuration i use date_created_on , if i press this option (in selectbox) is correct but i would that was by default

Solution:
change file: /administrator/components/com_virtuemart/models/product.php
Find the following code:
Code: [Select]
/* invert order value set*/
if ($order =='ASC') {
$orderlink ='&order=DESC';
$orderTxt = JText::_('COM_VIRTUEMART_SEARCH_ORDER_DESC');
} else {
$orderTxt = JText::_('COM_VIRTUEMART_SEARCH_ORDER_ASC');
$orderlink ='';
}

and just switch the order. Be AWARE that this will change all your default sort by to descend.

ALSO, Do you have SEF on or off?

if SEF on, then go to /components/com_virtuemart/router.php.
Inside the file, move the following:
Code: [Select]
if ( isset($query['order']) ) {
if ($query['order'] =='DESC') $segments[] = $helper->lang('orderDesc') ;
unset($query['order']);
}
to after 
Code: [Select]
if ( isset($query['orderby']) ) {
$segments[] = $helper->lang('by').','.$helper->lang( $query['orderby']) ;
unset($query['orderby']);
}

Wednesday, 17 July 2013

Use Module Title as link in Joomla 1.6 , 1.7 , 2.5

1 – Open your module .xml file  example - modules/mod_articles_news/mod_articles_news.xml
2 –  Add the following line between the first set of <fieldset name=”basic”></fieldset> tags
<field name="title_link" type="text" default="" label="Title link" description="" />
Save your XML file.
3 – Now go to templates/system/html/modules.php open it & find the xhtml function or find this line “ xhtml (divs and font headder tags) ” here you can find this function
function modChrome_xhtml($module, &$params, &$attribs)
{
 if (!empty ($module->content)) : ?>
  <div class="moduletable<?php echo htmlspecialchars($params->get('moduleclass_sfx')); ?>">
  <?php if ($module->showtitle != 0) : ?>
   <h3><?php echo $module->title; ?></h3>
  <?php endif; ?>
   <?php echo $module->content; ?>
  </div>
 <?php endif;
}

& replace with
function modChrome_xhtml($module, &$params, &$attribs)
{
 if (!empty ($module->content)) : ?>
  <div class="moduletable<?php echo htmlspecialchars($params->get('moduleclass_sfx')); ?>">
  <?php if ($module->showtitle != 0) : ?>
   <?php $title_link = $params->get('title_link'); ?>
   <h3><?php if($title_link) { ?> <a href="<?php echo $params->get('title_link');  ?>"> <?php } ?><?php echo $module->title; ?><?php if($title_link) { ?></a><?php } ?></h3>
  <?php endif; ?>
   <?php echo $module->content; ?>
  </div>
 <?php endif;
}

4 – now you have link area in your module basic parameter add your link  :)
Conclusion - Its very simple hack  or trick in joomla i hope in joomla! 3.0 joomla add this feature by default :) if you get any kind of issue or can’t get right result kindly leave your comment or contact with me thanks

Tuesday, 16 July 2013

Use sh404SEF to create friendly web link

One of the most way to SEO an webpage is create an friendly web link. With Joomla, we can choice sh404SEF component as a best solution.
This is step by step how to use it.



  1. Download load sh404SEF 4.1.0.1559  here. This version is used for Joomla 2.5 and 3.0
  2. Install this component into your Joomla website


  3. Enter sh404SEF Control Panel by this way: menu Component->sh404sef->Control Panel

  4. At Quick Start tab, choice all are Yes, and Rewriting mode is with .htaccess (mod_rewrite), then Press Start button
  5. Now press Configuration Button at top right and choice tab General->Main. At Character replacements list add more these characters:
    , á|a, à|a, ả|a, ã|a, ạ|a, â|a, ấ|a, ầ|a, ẩ|a, ẫ|a, ậ|a, ă|a, ắ|a, ằ|a, ẳ|a, ẵ|a, ặ|a, đ|d, é|e, è|e, ẻ|e, ẽ|e, ẹ|e, ê|e, ế|e, ề|e, ể|e, ễ|e, ệ|e, í|i, ì|i, ỉ|i, ĩ|i, ị|i, ó|o, ò|o, ỏ|o, õ|o, ọ|o, ô|o, ố|o, ồ|o, ổ|o, ỗ|o, ộ|o, ơ|o, ớ|o, ờ|o, ở|o, ỡ|o, ợ|o, ú|u, ù|u, ủ|u, ũ|u, ụ|u, ư|u, ứ|u, ừ|u, ử|u, ữ|u, ự|u, ý|y, ỳ|y, ỷ|y, ỹ|y, ỵ|y, Á|A, À|A, Ả|A, Ã|A, Ạ|A, Â|A, Ấ|A, Ầ|A, Ẩ|A, Ẫ|A, Ậ|A, Ă|A, Ắ|A, Ằ|A, Ẳ|A, Ẵ|A, Ặ|A, Đ|D, É|E, È|E, Ẻ|E, Ẽ|E, Ẹ|E, Ê|E, Ế|E, Ề|E, Ể|E, Ễ|E, Ệ|E, Í|I, Ì|I, Ỉ|I, Ĩ|I, Ị|I, Ó|O, Ò|O, Ỏ|O, Õ|O, Ọ|O, Ô|O, Ố|O, Ồ|O, Ổ|O, Ỗ|O, Ộ|O, Ơ|O, Ớ|O, Ờ|O, Ở|O, Ỡ|O, Ợ|O, Ú|U, Ù|U, Ủ|U, Ũ|U, Ụ|U, Ư|U, Ứ|U, Ừ|U, Ử|U, Ữ|U, Ự|U, Ý|Y, Ỳ|Y, Ỷ|Y, Ỹ|Y, Ỵ|Y
  6. It has many options, but you can use default.
  7. Go to you File Manager on your hosting, Edit file htaccess.txt - Find code:
        ########## Begin - Joomla! core SEF Section
    #
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/index.php
    RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
    RewriteRule (.*) index.php
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
    #
    ########## End - Joomla! core SEF Section
    
    
    And replace by this code:
    
    
    ########## Begin - Joomla! core SEF Section
    #
    #RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteCond %{REQUEST_URI} !^/index.php
    #RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
    #RewriteRule (.*) index.php
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
    #
    ########## End - Joomla! core SEF Section
    #
    ########## Begin - 3rd Party SEF Section
    ############# Use this section if you are using a 3rd party (Non Joomla! core) SEF extension - e.g. OpenSEF, 404_SEF, 404SEFx, SEF Advance, etc
    #
    RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR] ##optional - see notes##
    RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.]*)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php
    #
    ########## End - 3rd Party SEF Section
    
    
    
    
  8. Change name of htaccess.txt to .htaccess
  9. Turn off all SEO Setting in Global Configuration of Joomla.
Done. Now you can check you web link again.