tag:blogger.com,1999:blog-74512590170920723032024-03-14T06:03:16.197-07:00Web, Apps and Latest Technologyjothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.comBlogger57125tag:blogger.com,1999:blog-7451259017092072303.post-70392456179088943922015-06-29T05:29:00.001-07:002015-06-29T05:29:21.938-07:00Yii 2 - Unable to find 'console\controllers\RbacController, RBAC yii rbac/initI have installed the very latest version of Yii 2.0.4, and while using the Advanced Template with RBAC i got the below issue while running the command <span style="color: blue;">yii rbac/init</span><br />
<br />
<br />
<br />
<span style="color: red;">Exception 'yii\base\UnknownClassException' with message </span><br />
<span style="color: red;">'Unable to find 'console\controllers\RbacController' </span><br />
<span style="color: red;">in file: /var/www/yii/console/controllers/RbacController.php. Namespace missing?'</span><br />
<br />
<br />
To overcome this simply edit the "namespace console\commands;" as "namespace console\controllers;" in RbacController.php<br />
<br />
RbacController - will be inside the console/controllers folder.<br />
<br />
Once we set all correctly run yii rbac/init then we will get the values automatically in our migrated tables auth_item and auth_item_child<br />
<br />
<br />
<br />
<br />jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-24016632191112837072015-03-04T04:46:00.000-08:002015-03-04T04:46:33.447-08:00Wordpress Year Pagination.<div dir="ltr" style="text-align: left;" trbidi="on">
We have used Page No pagination in WordPress like<br />
<br />
[15] [14] [13] ... [1]<br />
<br />
Likewise we can create the Year pagination for our archive post. OK use the below code to simply past in your archive list area under the pagination part.<br />
<br />
<br />
<?php<br />
$current_year= date('Y'); // this will the current year<br />
$archive_year = get_the_time('Y'); // this will get the year of the archive list<br />
$starting_year= "2006"; // this will be our starting year<br />
?><br />
<br />
<ul class="SOME CLASS"><br />
<?php if($archive_year < $current_year ) { ?><span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<li><a href="<?php echo get_year_link( $archive_year+1 ); ?>"><i class="SOME CLASS"></i></a></li><br />
<?php } ?><br />
<?php if($archive_year == $current_year ) { ?><span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<li><a href="<?php echo get_year_link( $archive_year ); ?>"><i class="SOME CLASS"></i></a></li><br />
<?php } ?><br />
<li class="SOME CLASS FOR DIVIDER"></li><br />
<?php<br />
<br />
for($i=date('Y'); $i>2005; $i--) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$diff= $i-$archive_year;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if($diff>2&&$diff<4)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>echo '<li><a href='.get_year_link( $current_year ).'>'.$current_year.'</a></li>';<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>echo '<li><a class="SOME CLASS">…</a></li>';<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if($diff>-3&&$diff<3)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if ($i == $archive_year) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>echo '<li class="active"><a href='.get_year_link( $i ).'>'.$archive_year.'</a></li>';<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>else {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>echo '<li><a href='.get_year_link( $i ).'>'.$i.'</a></li>';<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if($diff>-4&&$diff<-2)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>echo '<li><a class="SOME CLASS">…</a></li>';<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>echo '<li><a href='.get_year_link( $starting_year ).'>'.$starting_year.'</a></li>';<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} <span class="Apple-tab-span" style="white-space: pre;"> </span><br />
}<br />
?><br />
<li class="SOME CLASS FOR DIVIDER"></li><br />
<?php if($archive_year <= $current_year && $archive_year > '2006') { ?><span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<li><a href="<?php echo get_year_link( $archive_year-1 ); ?>"><i class="SOME CLASS"></i></a></li><br />
<?php } ?><br />
<?php if($archive_year == $current_year && $archive_year == '2006') { ?><span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<li><a href="<?php echo get_year_link( $archive_year); ?>"><i class="SOME CLASS"></i></a></li><br />
<?php } ?><br />
<?php if($archive_year != $current_year && $archive_year == '2006') { ?><span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<li><a href="<?php echo get_year_link( $archive_year); ?>"><i class="SOME CLASS"></i></a></li><br />
<?php } ?><br />
</ul><br />
<div>
<br /></div>
<div>
<br /></div>
<div>
So the above will output like below</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUUboGeGdwU32xpxuV4Hjw2JxuIceY66-JVolnCdViolYpxcMUxP6TJAwSAlfU2KHQRp1kyNaGxE_QYTRRme-B1EVmYlk0seSuRnk3w4w_1SuFZvj2yV7ogtBWyd2HJcp0fEtuwB9vaeA/s1600/Year-pagination.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUUboGeGdwU32xpxuV4Hjw2JxuIceY66-JVolnCdViolYpxcMUxP6TJAwSAlfU2KHQRp1kyNaGxE_QYTRRme-B1EVmYlk0seSuRnk3w4w_1SuFZvj2yV7ogtBWyd2HJcp0fEtuwB9vaeA/s1600/Year-pagination.png" /></a></div>
<div>
<br /></div>
</div>
zffihttp://www.blogger.com/profile/07510258168724229724noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-21953823201485212482015-02-05T23:30:00.001-08:002015-03-04T04:31:53.033-08:00Simple Mobile number subscription plugin Wordpress, Wordpress Mobile number subscription plugin<div dir="ltr" style="text-align: left;" trbidi="on">
Simple Mobile number subscription plugin<br />
<br />
== Description ==<br />
<br />
This plugin will be handy for your users to add their numbers in your site, and you can use this plugin for your whatsapp subscription list<br />
<br />
A few notes about the sections above:<br />
<br />
* Shortcode for widget<br />
* Admin can able to add, edit, delete the mobile number<br />
* "Tested up to" is the highest version that you've *successfully used to test the plugin*. Note that it might work on<br />
higher versions... this is just the highest one you've verified.<br />
<br />
== Installation ==<br />
<br />
1. Upload `whatsapp-subscription` to the `/wp-content/plugins/` directory<br />
2. Activate the plugin through the 'Plugins' menu in WordPress<br />
<br />
<br />
<br />
This is the shortcode that we need to use<span style="color: red;"> [ADD-SUBSCRIPTION-WHATSAPP]</span><br />
<br />
<br />
<br />
<span style="background-color: yellow;">Use this Wordpress Simple plugin: </span>https://wordpress.org/plugins/whatsapp-subscription/<br />
<br />
<br />
<br />
<br /></div>
zffihttp://www.blogger.com/profile/07510258168724229724noreply@blogger.com4tag:blogger.com,1999:blog-7451259017092072303.post-60729550720971237522015-02-03T23:06:00.002-08:002015-02-03T23:06:30.827-08:00Avoid Custom Codes in WordPress Core files<div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="color: #3d85c6;"><br /></span></b>
<b><span style="color: #3d85c6;"><br /></span></b>
<b><span style="color: #3d85c6;">WordPress</span></b> is the best blogger CMS open source, as well as hack-able one. So we need to keep updating everything regularly.<br />
<br />
Themes<br />
Plugins<br />
WordPress version<br />
<br />
<br />
<br />
WordPress version update comes with Manual update as well as One click update from the dashboard. But if you made any custom codes inside wp-admin/ or wp-includes folders, then it will be replaced and we will lose our files, functions etc.<br />
<br />
<blockquote class="tr_bq">
<span style="color: #3d85c6;">So Always don't edit any core files of WordPress</span></blockquote>
<br />
<br />
as well as don't update any raw files inside wp-content/themes or wp-cotent/plugins, if you edit any WordPress themes then it will be big head ache as well as we need to be stay in the old version if we need our site in the same format, if you did any edits in the theme files and updating the version then we will entirely loose the site design, functions etc.<br />
<br />
<blockquote class="tr_bq">
<span style="color: #3d85c6;">So always create a Child theme and put your edited files there</span></blockquote>
<br />
<br />
If we are following this formats, then by a single click we can update our versions, and our site will be get secured.<br />
<br />
<br />
<br /></div>
zffihttp://www.blogger.com/profile/07510258168724229724noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-91147318772613425392015-02-01T22:49:00.001-08:002015-02-03T23:11:05.266-08:00Whatsapp for sharing your Posts, Whatsapp PHP API for Wordpress, Whatsapp for Wordpress<div dir="ltr" style="text-align: left;" trbidi="on">
We can see many sharing services like Addthis, Sharethis have already integrated the Whatsapp sharing services in their stream.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6QZ2afFZDRd6dhshFepyJ718Emhn7iz2JkIjZlzy7MPXBDNhEDvdL02l-8C9MrRHQHJ-fny37bDSh-CHV2aH4ByxLQKpWlMDWgjSUkKjGz1EB27rQfP4Q_YKpRZsEHJQ9moW3xZH6bzI/s1600/addthis.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6QZ2afFZDRd6dhshFepyJ718Emhn7iz2JkIjZlzy7MPXBDNhEDvdL02l-8C9MrRHQHJ-fny37bDSh-CHV2aH4ByxLQKpWlMDWgjSUkKjGz1EB27rQfP4Q_YKpRZsEHJQ9moW3xZH6bzI/s1600/addthis.jpg" height="233" width="320" /></a></div>
<br />
But it wont work in the Desktop version, as Whatsapp will work in latest Iphone and Chrome version. May be in the future days they will set the API for web sharing, but for now there is no such options in Whatsapp as well as in other Social Sharing Sites.<br />
<br />
Ok, but we can do the sharing. Please refer this https://github.com/venomous0x/WhatsAPI, they are having the API to send the Whatsapp message from a mobile to other mobile.<br />
<br />
Ok, here is the steps to set your API:<br />
<br />
<br />
<ul style="text-align: left;">
<li>First we need to register our Mobile number with WART (https://github.com/shirioko/WhatsAPI/wiki/WhatsApp-Registration-Flow), check this site.</li>
</ul>
<br />
<br />
<ul style="text-align: left;">
<li>Once you register you will get a SMS code confirmation</li>
</ul>
<br />
<br />
<ul style="text-align: left;">
<li>We need to set the Code confirmation again in the same registration form and once set we will get the below </li>
</ul>
<br />
<br />
<blockquote class="tr_bq">
<ul style="text-align: left;">
<li>Username</li>
<li>Password</li>
<li>Identity </li>
</ul>
</blockquote>
and this is what we need for the API<br />
<br />
<br />
<br />
Please set the credentials inside the exampleFunctional.php file, and set the [$target] target mobile number to which you want to send your blog titles/ URLs.<br />
<br />
The target numbers will get the Whatsapp Message from our WART registered Mobile number.<br />
<br />
<br class="Apple-interchange-newline" />
This Github URL is providing all the variables set for Whatsapp API from venomous0x<br />
https://github.com/shirioko/WhatsAPI/wiki/WhatsApi-events<br />
<br />
<div style="text-align: left;">
--------------------------------------------------------------------------------------------------------------------</div>
<br />
We can use this API and integrate with our Blogger or Wordpress sites, we can set some AUTO system and send the messages to the Subscribed mobile numbers once we post a new articles in our site.<br />
<br />
<br />
YES WHATSAPP IS WORKING.<br />
<br />
<br />
<div>
--------------------------------------------------------------------------------------------------------------------</div>
<div>
<br /></div>
<div>
Why Whatsapp is not working in my ADDTHIS share code?</div>
<div>
<br /></div>
<div>
That is because it will be get worked inside the mobile device only with latest OS and CHROME versions. Also while referred to different forums, it is detailed that it will get worked in the latest Iphone devices.</div>
<div>
<br /></div>
<div>
If we run the Addthis - Whatsapp share inside the desktop version we will get the below link and it wont get worked</div>
<div>
<br /></div>
<div>
http://whatsapp//send?text=***************************************</div>
<br />
<br />
<br />
<br />
Happy coding...<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>
zffihttp://www.blogger.com/profile/07510258168724229724noreply@blogger.com2tag:blogger.com,1999:blog-7451259017092072303.post-67171655282129805602014-12-09T23:30:00.002-08:002014-12-09T23:30:19.012-08:00Play with CSS - CSS BOX SHADOWCSS comes with a good box pattern called "Box Shadow" of your tag. For more details on Box shadow tutorials refer here http://css-tricks.com/snippets/css/css-box-shadow/<br />
<br />
<br />
We can set the floating of our tags (DIV, P etc) by setting the Box shadow style.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig8ukw7vkYnvah9jX56bGyCggZD4s_2hRasW9CZc_VGhfP2fG6VaO0gQF51dTlPFxEVL4UGpbaKm-RhodDgbDVLuIslBD45rb6uFv_jSilpAn2Ab3FfazEaWAOJkXxxZ-ohAPrsKJUOWIb/s1600/floatings.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig8ukw7vkYnvah9jX56bGyCggZD4s_2hRasW9CZc_VGhfP2fG6VaO0gQF51dTlPFxEVL4UGpbaKm-RhodDgbDVLuIslBD45rb6uFv_jSilpAn2Ab3FfazEaWAOJkXxxZ-ohAPrsKJUOWIb/s1600/floatings.png" height="139" width="320" /></a></div>
<br />
The box-shadow property sets one or more drop-shadows to the tags.<br />
<br />
Sometime you need this http://www.w3schools.com/cssref/playit.asp?filename=playcss_box-shadow&preval=50px%2050px%205px%20black<br />
<br />
Through this box shadow pattern i did some CSS image styling, please refer my below screenshot<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOaVJXsL4z1XYbQZCyoG2czidySPVVQx4qpToiopJKKeirpXQNan4pnVYAXDsq2fSVVNECLk0nDyfhZoGlj9HjaAYP7ZRy9axlOo950dZmTUj2ZQR61JtDrALDSbDuH79qdTawzKaNytvw/s1600/cool.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOaVJXsL4z1XYbQZCyoG2czidySPVVQx4qpToiopJKKeirpXQNan4pnVYAXDsq2fSVVNECLk0nDyfhZoGlj9HjaAYP7ZRy9axlOo950dZmTUj2ZQR61JtDrALDSbDuH79qdTawzKaNytvw/s1600/cool.png" /></a></div>
<br />
<blockquote class="tr_bq">
.myclass{<br /><b>box-shadow</b>: 1em 0 0 0 red,<br />0 1em 0 0 red,<br />-1em 0 0 0 red,<br />0 -1em 0 0 red,<br />-1em -2em 0 0 red,<br />1em -2em 0 0 red,<br />-1em 2em 0 0 red,<br />1em 2em 0 0 red,<br />2em 1em 0 0 red,<br />2em -1em 0 0 red,<br />-2em 1em 0 0 red,<br />-2em -1em 0 0 red,<br />3em 0 0 0 red,<br />-3em 0 0 0 red,<br />0 3em 0 0 red,<br />0 -3em 0 0 red;<br />background: black;<br />width: 1em;<br />height: 1em;<br />overflow: hidden;<br />margin: 50px 0 70px 65px;<br />}</blockquote>
<br />
At some point we can avoid using the image and we can reduce the load time of the site. I didt diked any online tutorials, but this is what i got while working practically<br />
<br />
<br />
<span style="color: red;"><b>1em</b></span> 0 0 0 red (Creates a box to the right of your tag (for me it is a div tag)<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmx-yk9K1bkpPJOiqvmXLpcqlHq7FoNEp23aElt6hFsNf0A__jVNxjIaR8V0h8rPDYXLt6Zb1fUkPoIzkQuo2xGbJMbWEkI6Qxf1T7mh2PrdzUPZStckmiV_ehXFQrmVxVtGQhuoqyB5Lx/s1600/play.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmx-yk9K1bkpPJOiqvmXLpcqlHq7FoNEp23aElt6hFsNf0A__jVNxjIaR8V0h8rPDYXLt6Zb1fUkPoIzkQuo2xGbJMbWEkI6Qxf1T7mh2PrdzUPZStckmiV_ehXFQrmVxVtGQhuoqyB5Lx/s1600/play.png" /></a></div>
<br />
<br />
so what if <span style="color: red;"><b>2em</b></span> 0 0 0 red (Creates a box to the right of your tag with space like below (for me it is a div tag)<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj63svwBu8C7UL-AsYE-phKETUGdILEAfh-tGVA-ma7YTUiYnsxsAd3EGgvv4-5rtS5fz-ZgHNuuw4JfRTFkM2QX7E24nx9wqHOW4ZuqEWiLg0kMrmLlKSpP6exeaYoo6tTyIhL_WG4PQtM/s1600/play2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj63svwBu8C7UL-AsYE-phKETUGdILEAfh-tGVA-ma7YTUiYnsxsAd3EGgvv4-5rtS5fz-ZgHNuuw4JfRTFkM2QX7E24nx9wqHOW4ZuqEWiLg0kMrmLlKSpP6exeaYoo6tTyIhL_WG4PQtM/s1600/play2.png" /></a></div>
<br />
<br />jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-46452778300317660532014-11-07T01:46:00.003-08:002014-11-07T01:46:39.102-08:00Why my wordpress site is slow and how to avoid it<span style="font-family: Trebuchet MS, sans-serif;">I have been working in a WordPress project for a while and it is having too many data and comments from users. May be some 4000 posts and 30000 comments, day by day the site became shaky and it took lot of time to get loaded.</span><div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">But i used the clean WordPress formats and codes, so i don't need to bother about any custom code issues. </span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<blockquote class="tr_bq">
<span style="color: #0b5394; font-family: Trebuchet MS, sans-serif;"><i>Note: PLEASE DO NOT CUSTOM CODE anything in the WordPress default file or write any unwanted SQL queries. Unwanted files and SQL queries will took time for the site to get loaded.</i></span></blockquote>
<br />
<span style="font-family: Trebuchet MS, sans-serif;">But there is something that makes the site to get loaded very slow. Actually i am just loading 10 posts in the home page and every other pages of the site is loading only 10 posts per page.</span><br />
<br />
<span style="font-family: Trebuchet MS, sans-serif;">Mine is a WINDOWS / MYSQL server and it is easy for me to check any TEMP and CACHE values. While looked into my windows temp folder it loading with many 100+ PHP-CGI.exe files created for every minute, so i used a good cache plugin to cache the files and reduced the EXE file generation.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<blockquote class="tr_bq">
<span style="color: #3d85c6; font-family: Trebuchet MS, sans-serif;"><i>Note by default the Cache files will be get deleted on some time period (2 HRS, 4 HRS) and mine is 2 hrs.</i></span></blockquote>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">But this does not actually reduced my page load problem and some time i got MYSQL server is overloaded something, and again i checked my TEMP folder and it showed it is stored some SESSION values for 1KB, the reason is i am using plugins (SI Captcha, Ninja Forms and YII poll) </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Inside these plugins there are code lines to generate Session values and we know all the session values will be get stored in our server, for every second the TEMP session files are getting generating. For a second i got some 5 files got generated, so i deleted these plugins and i got the site came in normal. So the problem is too many session files and php exe files.</span><br />
<br />
<blockquote class="tr_bq">
<span style="color: #3d85c6; font-family: Trebuchet MS, sans-serif;"><i>Note: While creating any WordPress project DON'T CREATE TOO MANY SESSION values, as all will get stored in your server. And while using any plugin please check whether this is creating any session values.</i></span></blockquote>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">My Wordpress site is very big so i did all, if you are not having that much traffic then no problem.</span><br />
<br />
<blockquote class="tr_bq">
</blockquote>
<br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com2tag:blogger.com,1999:blog-7451259017092072303.post-40248131110912771852014-04-19T00:36:00.001-07:002014-04-19T00:36:09.722-07:00Multiple polygons on google map with hover show, hide<span style="font-family: Trebuchet MS, sans-serif;">Here you can find the multiple ploygons on the google map and we can show and hide the ploygons as per the title mouse over, i didt find much time to shorten this jquery code. Meantime i am not ok with the line </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><code></code></span><br />
<span style="font-family: Trebuchet MS, sans-serif;">idx=jQuery(this).attr('id');</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for(var i=0,l=countries.length;i<l font="" i=""></l></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(idx==i){countries[i].setMap(map);}</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>else{countries[i].setMap(null);}</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Trebuchet MS, sans-serif;"> </span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;">I cant able to directly assign my idx value like this countries[idx].setMap(map);, if i put like then it is showing as countriex[idx] is not a function, if anyone know the solution please let me know</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Trebuchet MS, sans-serif;"> </span></span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Trebuchet MS, sans-serif;"> </span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><code></code></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="color: orange; font-family: Trebuchet MS, sans-serif; font-size: large;">Put your google map script URL</span><br />
<span style="color: orange; font-family: Trebuchet MS, sans-serif; font-size: large;">Put your Jquery ajax URL</span><br />
<span style="color: orange; font-family: Trebuchet MS, sans-serif; font-size: large;">Set your div tags with ID values</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<span style="font-family: Trebuchet MS, sans-serif;">function initialize() {</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var myLatLng = new google.maps.LatLng(24.886436490787712, -70.2685546875); </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var mapOptions = { zoom: 2, center: myLatLng, mapTypeId: google.maps.MapTypeId.TERRAIN }; </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var countries = new Array();</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>countries[0] = new google.maps.Polygon({</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>paths: [</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(59.677361, -2.469846), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(59.299717, -6.314917), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(57.877247, -9.314917), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(54.428078, -11.638861), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(51.784554, -11.702241), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(50.185848, -10.054354), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(49.405380, -7.012100), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(49.090675, -3.272664), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(48.775970, -1.709283), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(49.757851, -2.089565), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(50.714554, 1.037195), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(51.482437, 2.304801), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(53.433609, 3.276632), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(55.863132, 3.445646)],</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>strokeColor: "#FF0000",</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>strokeOpacity: 0.8,</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>strokeWeight: 2,</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>fillColor: "#FF0000",</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>fillOpacity: 0.35</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>});</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Trebuchet MS, sans-serif;"> </span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>countries[1] = new google.maps.Polygon({ </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>paths: [ </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(25.774252, -80.190262), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(18.466465, -66.118292), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(32.321384, -64.757370), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(25.774252, -80.190262)],</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>strokeColor: "#FF0000", </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>strokeOpacity: 0.8, </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>strokeWeight: 2, </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>fillColor: "#FF0000", </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>fillOpacity: 0.3</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>});</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Trebuchet MS, sans-serif;"> </span></span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Trebuchet MS, sans-serif;"> </span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>countries[2] = new google.maps.Polygon({ </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>paths: [ </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(12.774252, -80.190262), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(33.466465, -66.118292), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(44.321384, -64.757370), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(33.774252, -80.190262)],</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>strokeColor: "#FF0000", </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>strokeOpacity: 0.8, </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>strokeWeight: 2, </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>fillColor: "#FF0000", </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>fillOpacity: 0.3</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>});</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Trebuchet MS, sans-serif;"> </span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>countries[3] = new google.maps.Polygon({ </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>paths: [ </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(33.774252, -44.190262), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(55.466465, -54.118292), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(75.321384, -64.757370), </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new google.maps.LatLng(53.774252, -80.190262)],</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>strokeColor: "#FF0000", </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>strokeOpacity: 0.8, </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>strokeWeight: 2, </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>fillColor: "#FF0000", </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>fillOpacity: 0.3</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>});</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jQuery('#submenu_links li a').mousemove(function(){</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>idx=jQuery(this).attr('id');</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for(var i=0,l=countries.length;i<l font="" i=""></l></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(idx==i){countries[i].setMap(map);}</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>else{countries[i].setMap(null);}</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>});</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Trebuchet MS, sans-serif;"> </span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jQuery('#submenu_links li a').mouseout(function(){</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var id=jQuery(this).attr('id');</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for(var i=0,l=countries.length;i<l font="" i=""></l></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>countries[i].setMap(null);</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>});</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"> <span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"> }</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">google.maps.event.addDomListener(window, 'load', initialize);</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"></span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><div>
<span style="font-family: Trebuchet MS, sans-serif;"></span></div>
jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-28035099503751946372014-03-06T02:44:00.003-08:002014-03-06T02:44:58.217-08:00How to show the Active/ Inactive dropdown status in YII C detail View<span style="font-family: Verdana, sans-serif;">Its simple to set the active, inactive in the C detail View dropdown list, just assign the status value as like the below format</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<span style="font-family: Verdana, sans-serif;"> array( </span><br />
<span style="font-family: Verdana, sans-serif;"> 'label'=>'Status',</span><br />
<span style="font-family: Verdana, sans-serif;"> 'type'=>'raw',</span><br />
<span style="font-family: Verdana, sans-serif;"> 'value'=>($model->status == 1) ? "Active" : "Inactive",</span><br />
<span style="font-family: Verdana, sans-serif;"> ),</span>jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-25871070282299942922014-03-06T02:05:00.003-08:002014-03-06T02:05:13.927-08:00CActiveDataProvider Yii - Is simple and neat<br />
<br />
<span style="font-family: Verdana, sans-serif;"><b>CActiveDataProvider</b> Yii - Is simple and neat, where we can enter our condition, pagination etc</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">I actually started coding with custom select query in YII, but while referred to "<b>CActiveDataProvider</b>" with conditions and pagination there is no need for to call the sql query second time with condition or pagination</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Here i will explain what i had previously and how the YII default CActiveDataProvider is working</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">My custom code in my controller function:</span><br />
<span style="font-family: Verdana, sans-serif;">===========================================</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">public function actionList()</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">{</span><br />
<span style="font-family: Verdana, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$criteria = new CDbCriteria();</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$criteria->addCondition('user_id='.Yii::app()->user->id.'');</span><br />
<span style="font-family: Verdana, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$count = Blog::model()->count($criteria);</span><br />
<span style="font-family: Verdana, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$pages = new CPagination($count);</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Verdana, sans-serif;"> </span></span><br />
<span style="font-family: Verdana, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span> </span><br />
<span style="font-family: Verdana, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$pages->pageSize = 5;</span><br />
<span style="font-family: Verdana, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$pages->applyLimit($criteria);</span><br />
<span style="font-family: Verdana, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$models = Blog::model()->findAll($criteria);</span><br />
<span style="font-family: Verdana, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$this->render('list', array('models' => $models, 'pages' => $pages));</span><br />
<span style="font-family: Verdana, sans-serif;">}</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">While following the above code, i need to call this $model inside a foreach and need to show the values. </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">YII default CActiveDataProvider in my controller function:</span><br />
<span style="font-family: Verdana, sans-serif;">===========================================</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">public function actionList()</span><br />
<span style="font-family: Verdana, sans-serif;">{</span><br />
<span style="font-family: Verdana, sans-serif;">$criteria=new CDbCriteria;</span><br />
<span style="font-family: Verdana, sans-serif;">$criteria->order='id DESC';<span class="Apple-tab-span" style="white-space: pre;"> </span> </span><br />
<span style="font-family: Verdana, sans-serif;">$dataProvider=new CActiveDataProvider('Blog',array('criteria'=>$criteria,'pagination' => array('pageSize'=>Yii::app()->params['PaginationPerPage']),));</span><br />
<span style="font-family: Verdana, sans-serif;">$this->render('list',array('<b>dataProvider</b>'=>$dataProvider,));</span><br />
<span style="font-family: Verdana, sans-serif;">}</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">This is what Yii gave in default, its simple. And while following this code we can simply use the default view format from YII like below </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"></span><br />
<span style="font-family: Verdana, sans-serif;">$this->widget('zii.widgets.CListView', array('dataProvider'=>$dataProvider,'itemView'=>'_view',)); </span><br />
<span style="font-family: Verdana, sans-serif;">?></span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<br />
jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-30326541250865626172014-02-11T03:36:00.002-08:002014-02-11T03:36:55.201-08:00How to set the country, state relationship in Yii <br />
<br />
<br />
My Country table:<br />
================<br />
id<br />
name<br />
<br />
<br />
My state table:<br />
===============<br />
id<br />
country_id<br />
name<br />
<br />
<br />
<br />
Here i need to refer the country from state using the country_id relationship<br />
<br />
So first i need to generate a Relationship in my State Model like below<br />
<br />
<br />
public function relations()<br />
{<br />
<br />
return array(<br />
'country'=>array(self::BELONGS_TO, 'Country', 'country_id'),<br />
);<br />
<br />
}<br />
<br />
Country here is the country model<br />
country_id is the reference key in state table to refer the country table<br />
<br />
<br />
Ok so in CGrid view use the below format<br />
<br />
'country.name',<br />
<br />
<br />
===========================================================================<br />
<br />
And if we need filtering for countries in state admin?<br />
<br />
Just use the compare setup like below<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public function search()<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// @todo Please modify the following code to remove attributes that should not be searched.<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$criteria=new CDbCriteria;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$criteria->compare('id',$this->id);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$criteria->compare('name',$this->name);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$criteria->with = array('country');<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$criteria->compare('country.id',$this->country_id, true);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return new CActiveDataProvider($this, array(<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>'criteria'=>$criteria,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<br />
And in your Cgridview area have it like below<br />
<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>array(<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>'name'=>'country_id',<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>'header'=>'Country',<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>'value'=>'$data->country->name',<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>'filter'=>CHtml::listData(Country::model()->findall(),'id','name' ),<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>),<br />
jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-42452247512500273102014-02-05T01:59:00.002-08:002014-02-05T02:49:32.568-08:00How to set the active and inactive status for 1,0 values in YII CGridView<span style="font-family: Verdana, sans-serif;">In Yii normal CGridView will have the below structure</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"></span><br />
<span style="font-family: Verdana, sans-serif;">'columns'=>array(</span><br />
<span style="font-family: Verdana, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>'id',</span><br />
<span style="font-family: Verdana, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>'title',</span><br />
<span style="font-family: Verdana, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>'sstatus',</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">So to set the 0 as Inactive and 1 as Active </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">we need to edit the 'status' as</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">array(</span><br />
<span style="font-family: Verdana, sans-serif;">'header'=>'status', //for to set the title for the table column, we can remove this if we need to show the default value</span><br />
<span style="font-family: Verdana, sans-serif;">'name'=>'sstatus' // where sstatus is my database column name</span><br />
<span style="font-family: Verdana, sans-serif;">'value'=>'($data->sstatus==1)? "Active" : "Inactive"'</span><br />
<span style="font-family: Verdana, sans-serif;">),</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Once set we can see 0 as inactive and 1 as active. </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">But how about filtering? </span><br />
<span style="font-family: Verdana, sans-serif;">The filtering in Yii will work when we input 1 and not as active, so just replace this filter area with dropdown list in the same area where we updated our above code, just add filter array like below</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<span style="font-family: Verdana, sans-serif;">array(</span><br />
<span style="font-family: Verdana, sans-serif;">'header'=>'status', //for to set the title for the table column, we can remove this if we need to show the default value</span><br />
<span style="font-family: Verdana, sans-serif;">'name'=>'sstatus' // where sstatus is my database column name</span><br />
<span style="font-family: Verdana, sans-serif;">'value'=>'($data->sstatus==1)? "Active" : "Inactive"',</span><br />
<span style="font-family: Verdana, sans-serif;"></span><br />
<span style="font-family: Verdana, sans-serif;">'filter'=>CHtml::dropDownList('Slider[sstatus]', 'sstatus', </span><br />
<span style="font-family: Verdana, sans-serif;"> array(</span><br />
<span style="font-family: Verdana, sans-serif;"> ''=>'All',</span><br />
<span style="font-family: Verdana, sans-serif;"> '1'=>'Active',</span><br />
<span style="font-family: Verdana, sans-serif;"> '0'=>'Inactive',</span><br />
<span style="font-family: Verdana, sans-serif;"> )</span><br />
<span style="font-family: Verdana, sans-serif;"> ),</span><br />
<span style="font-family: Verdana, sans-serif;"> ),</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">),</span><br />
<br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">in the above Slider is my model name and sstatus is my database table column... thats it.......</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">But i faced some problems like auto select and select all is not working, so we can set the filter directly like the below code</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"></span><br />
<span style="font-family: Verdana, sans-serif;"> array(</span><br />
<span style="font-family: Verdana, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 'name' => 'sstatus',</span><br />
<span style="font-family: Verdana, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 'filter' => array(0 => 'In Active', 1 => 'Active'),</span><br />
<span style="font-family: Verdana, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>'value' => '($data->sstatus == 1) ? "Active" : "Inactive"',</span><br />
<span style="font-family: Verdana, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span> ),</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-156958668497993402013-08-20T21:59:00.000-07:002013-08-20T21:59:06.091-07:00PHP Translator, replacement for google translator api?.<br />
<span style="font-family: Verdana, sans-serif;">I struggled to get the language translator for my php project and found Google API is not WORKING FOR ME, I dont know it works for others. While surfed i got google closed its Free Translator API, and microsoft is providing its API with limited character free subscription.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">The code providing by them comes in SOAP, HTTP and Javascript and yes it supported my PHP. Even they are providing exact PHP class files that helped me a lot. You can register your Keys with them, use this link for to Sign up for the Microsoft Translator API "https://datamarket.azure.com/dataset/1899a118-d202-492c-aa16-ba21c33c06cb". They have listed all the subscription plans ranges from free to $6000/ month.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">I think this link will also helpful http://www.microsofttranslator.com/dev/. After creating your Keys register with Datamarket and your translator will work good. I have used HTTP >> Translate Method "http://msdn.microsoft.com/en-us/library/ff512421.aspx" and there you can see the PHP class files, and it is very handy......</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Happy coding</span><br />
jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-72164155724997030422013-08-19T01:21:00.000-07:002013-08-19T01:21:44.471-07:00How to get the meta title, description and keywords using PHP<br />
<br />
<span style="font-family: Verdana, sans-serif;">function getUrlData($url)</span><br />
<span style="font-family: Verdana, sans-serif;">{</span><br />
<span style="font-family: Verdana, sans-serif;"> $result = false;</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><br />
<span style="font-family: Verdana, sans-serif;"> $contents = getUrlContents($url);</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"> if (isset($contents) && is_string($contents))</span><br />
<span style="font-family: Verdana, sans-serif;"> {</span><br />
<span style="font-family: Verdana, sans-serif;"> $title = null;</span><br />
<span style="font-family: Verdana, sans-serif;"> $metaTags = null;</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><br />
<span style="font-family: Verdana, sans-serif;"> preg_match('/<***title***>([^***>]*)<***\/title***>/si', $contents, $match );</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"> if (isset($match) && is_array($match) && count($match) > 0)</span><br />
<span style="font-family: Verdana, sans-serif;"> {</span><br />
<span style="font-family: Verdana, sans-serif;"> $title = strip_tags($match[1]);</span><br />
<span style="font-family: Verdana, sans-serif;"> }</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><br />
<span style="font-family: Verdana, sans-serif;"> preg_match_all('/<***[\s]*meta[\s]*name="?' . '([^***>"]*)"?[\s]*' . 'content="?([^***>"]*)"?[\s]*[\/]?[\s]****>/si', $contents, $match);</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><br />
<span style="font-family: Verdana, sans-serif;"> if (isset($match) && is_array($match) && count($match) == 3)</span><br />
<span style="font-family: Verdana, sans-serif;"> {</span><br />
<span style="font-family: Verdana, sans-serif;"> $originals = $match[0];</span><br />
<span style="font-family: Verdana, sans-serif;"> $names = $match[1];</span><br />
<span style="font-family: Verdana, sans-serif;"> $values = $match[2];</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><br />
<span style="font-family: Verdana, sans-serif;"> if (count($originals) == count($names) && count($names) == count($values))</span><br />
<span style="font-family: Verdana, sans-serif;"> {</span><br />
<span style="font-family: Verdana, sans-serif;"> $metaTags = array();</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><br />
<span style="font-family: Verdana, sans-serif;"> for ($i=0, $limiti=count($names); $i <*** $limiti; $i++)</span><br />
<span style="font-family: Verdana, sans-serif;"> {</span><br />
<span style="font-family: Verdana, sans-serif;"> $metaTags[$names[$i]] = array (</span><br />
<span style="font-family: Verdana, sans-serif;"> 'html' => htmlentities($originals[$i]),</span><br />
<span style="font-family: Verdana, sans-serif;"> 'value' => $values[$i]</span><br />
<span style="font-family: Verdana, sans-serif;"> );</span><br />
<span style="font-family: Verdana, sans-serif;"> }</span><br />
<span style="font-family: Verdana, sans-serif;"> }</span><br />
<span style="font-family: Verdana, sans-serif;"> }</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><br />
<span style="font-family: Verdana, sans-serif;"> $result = array (</span><br />
<span style="font-family: Verdana, sans-serif;"> 'title' => $title,</span><br />
<span style="font-family: Verdana, sans-serif;"> 'metaTags' => $metaTags</span><br />
<span style="font-family: Verdana, sans-serif;"> );</span><br />
<span style="font-family: Verdana, sans-serif;"> }</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><br />
<span style="font-family: Verdana, sans-serif;"> return $result;</span><br />
<span style="font-family: Verdana, sans-serif;">}</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">function getUrlContents($url, $maximumRedirections = null, $currentRedirection = 0)</span><br />
<span style="font-family: Verdana, sans-serif;">{</span><br />
<span style="font-family: Verdana, sans-serif;"> $result = false;</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><br />
<span style="font-family: Verdana, sans-serif;"> $contents = @file_get_contents($url);</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><br />
<span style="font-family: Verdana, sans-serif;"> // Check if we need to go somewhere else</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><br />
<span style="font-family: Verdana, sans-serif;"> if (isset($contents) && is_string($contents))</span><br />
<span style="font-family: Verdana, sans-serif;"> {</span><br />
<span style="font-family: Verdana, sans-serif;"> preg_match_all('/<***[\s]*meta[\s]*http-equiv="?REFRESH"?' . '[\s]*content="?[0-9]*;[\s]*URL[\s]*=[\s]*([^***>"]*)"?' . '[\s]*[\/]?[\s]****>/si', $contents, $match);</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><br />
<span style="font-family: Verdana, sans-serif;"> if (isset($match) && is_array($match) && count($match) == 2 && count($match[1]) == 1)</span><br />
<span style="font-family: Verdana, sans-serif;"> {</span><br />
<span style="font-family: Verdana, sans-serif;"> if (!isset($maximumRedirections) || $currentRedirection <*** $maximumRedirections)</span><br />
<span style="font-family: Verdana, sans-serif;"> {</span><br />
<span style="font-family: Verdana, sans-serif;"> return getUrlContents($match[1][0], $maximumRedirections, ++$currentRedirection);</span><br />
<span style="font-family: Verdana, sans-serif;"> }</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><br />
<span style="font-family: Verdana, sans-serif;"> $result = false;</span><br />
<span style="font-family: Verdana, sans-serif;"> }</span><br />
<span style="font-family: Verdana, sans-serif;"> else</span><br />
<span style="font-family: Verdana, sans-serif;"> {</span><br />
<span style="font-family: Verdana, sans-serif;"> $result = $contents;</span><br />
<span style="font-family: Verdana, sans-serif;"> }</span><br />
<span style="font-family: Verdana, sans-serif;"> }</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><br />
<span style="font-family: Verdana, sans-serif;"> return $contents;</span><br />
<span style="font-family: Verdana, sans-serif;">}</span><br />
<span style="font-family: Verdana, sans-serif;">?></span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><***?php</span><br />
<span style="font-family: Verdana, sans-serif;">$result = getUrlData('http://elwatannews.com/');</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">echo '<***pre***>'; print_r($result); echo '<***/pre***>';</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Note: Remove </span><span style="font-family: Verdana, sans-serif;">***s</span><br />
<br />
jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-6872429978169705102013-08-16T21:39:00.001-07:002013-08-16T21:39:16.025-07:00How to Resize or Scale your image using CSS There are many best ways to scale the images for your site. We can use the php resize codes or Jquery resize scripts and others, and one of the best way is to <span style="color: #cc0000;">scale the images through CSS</span>. For a demo please check the below code<br />
<br />
<span style="color: #666666;"><code></code></span><br />
<br />
<span style="color: #666666;"><*****style type="text/css"></span><br />
<span style="color: #666666;">.center-cropped {</span><br />
<span style="color: #666666;"> width: 310px;</span><br />
<span style="color: #666666;"> height: 168px;</span><br />
<span style="color: #666666;"> background-position: 50% 11%;</span><br />
<span style="color: #666666;"> background-size: cover;</span><br />
<span style="color: #666666;"> }</span><br />
<span style="color: #666666;"></span><br />
<span style="color: #666666;"><*****div class="center-cropped" style="background-image: url('http://elbadil.com/sites/default/files/styles/428xauto_node_image_2/public/13/08/32/0_73.jpg?itok%3Dk9uRSMGi');"></span><br />
<span style="color: #666666;"><******/div></span><br />
<span style="color: #666666;"></span><br />
<br />
<b><span style="color: orange;">Note: remove ******</span></b><br />
<br />
<br />
In the above code background-size acts as the center point, I just need a whole cover section, but we can use contain or auto or anything as per your needs.<br />
<br />
Check the background-position too. I made as 50: 11 Percentage ratio. You can set the height and width and by this there wont be any stretch in the image. But the whole concept will make the load time bit high when compared to resizing :)<br />
<br />
<br />
<br />
<br />
jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-21523998472531162772013-08-16T04:23:00.002-07:002013-08-16T04:23:35.228-07:00Code to make other site image to get stored in your wordpress database as well as making other site images to your wordpress post featured image<br />
<span style="font-family: Verdana, sans-serif;">$upload_dir = wp_upload_dir();</span><br />
<span style="font-family: Verdana, sans-serif;">$image_data = file_get_contents("Image URL for other site");</span><br />
<span style="font-family: Verdana, sans-serif;">$filename = basename($image_url);</span><br />
<span style="font-family: Verdana, sans-serif;">if(wp_mkdir_p($upload_dir['path']))</span><br />
<span style="font-family: Verdana, sans-serif;">$file = $upload_dir['path'] . '/' . $filename;</span><br />
<span style="font-family: Verdana, sans-serif;">else</span><br />
<span style="font-family: Verdana, sans-serif;">$file = $upload_dir['basedir'] . '/' . $filename;</span><br />
<span style="font-family: Verdana, sans-serif;">file_put_contents($file, $image_data);</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">$wp_filetype = wp_check_filetype($filename, null );</span><br />
<span style="font-family: Verdana, sans-serif;">$attachment = array(</span><br />
<span style="font-family: Verdana, sans-serif;">'post_mime_type' => $wp_filetype['type'],</span><br />
<span style="font-family: Verdana, sans-serif;">'post_title' => sanitize_file_name($filename),</span><br />
<span style="font-family: Verdana, sans-serif;">'post_content' => '',</span><br />
<span style="font-family: Verdana, sans-serif;">'post_status' => 'inherit'</span><br />
<span style="font-family: Verdana, sans-serif;">);</span><br />
<span style="font-family: Verdana, sans-serif;">$attach_id = wp_insert_attachment( $attachment, $file, $post_id );</span><br />
<span style="font-family: Verdana, sans-serif;">require_once(ABSPATH . 'wp-admin/includes/image.php');</span><br />
<span style="font-family: Verdana, sans-serif;">$attach_data = wp_generate_attachment_metadata( $attach_id, $file );</span><br />
<span style="font-family: Verdana, sans-serif;">wp_update_attachment_metadata( $attach_id, $attach_data );</span><br />
<span style="font-family: Verdana, sans-serif;">set_post_thumbnail( $post_id , $attach_id );</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">wp_update_attachment_metadata will make the image to get stored in your database</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">set_post_thumbnail will make the image to get featured for the post</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">$post_id - will be ID of your post, for example if you just want to make your post id 5 to get featured image then just replace the variable $post_id with 5</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<br />
<br />
<br />
jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-5672440317413158322013-08-16T04:22:00.001-07:002013-08-16T04:23:42.717-07:00substr in php is not removing characters?<br />
I had a similar problem before and rectified using mb_substr, for demo please check the below code<br />
<br />
$then_truncate_the_value=mb_substr($remove_html_first , 0, 123);<br />
<div>
<br /></div>
jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-42408203748147283192013-08-16T04:04:00.002-07:002013-08-16T04:22:22.771-07:00How to scrap the titles of a Wordpress site using CURL php?<br />
<span style="font-family: Verdana, sans-serif;">$curl1 = curl_init();</span><br />
<span style="font-family: Verdana, sans-serif;">curl_setopt($curl1, CURLOPT_URL, 'Your URL');</span><br />
<span style="font-family: Verdana, sans-serif;">curl_setopt($curl1, CURLOPT_HEADER, false); </span><br />
<span style="font-family: Verdana, sans-serif;">curl_setopt($curl1, CURLOPT_RETURNTRANSFER, true); </span><br />
<span style="font-family: Verdana, sans-serif;">curl_setopt($curl1, CURLOPT_FOLLOWLOCATION,true);</span><br />
<span style="font-family: Verdana, sans-serif;">curl_setopt($curl1, CURLOPT_ENCODING,"");</span><br />
<span style="font-family: Verdana, sans-serif;">curl_setopt($curl1, CURLOPT_USERAGENT, "spider");</span><br />
<span style="font-family: Verdana, sans-serif;">curl_setopt($curl1, CURLOPT_AUTOREFERER,true);</span><br />
<span style="font-family: Verdana, sans-serif;">$result1 = curl_exec($curl1); curl_close($curl1); </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">## get the title</span><br />
<span style="font-family: Verdana, sans-serif;">preg_match_all('your h1 tag with calss', $result1, $matches1, PREG_OFFSET_CAPTURE);</span><br />
<span style="font-family: Verdana, sans-serif;">preg_match('/your anchor tag/', $matches1[0][0][0], $set1);</span><br />
<span style="font-family: Verdana, sans-serif;">$my_title=$set1[2];</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">1) Initialize the CURL</span><br />
<span style="font-family: Verdana, sans-serif;">2) Enter the URL</span><br />
<span style="font-family: Verdana, sans-serif;">3) Check whether the wordpress site comes with the h1 tag and with the same class i declared here, else use the correct one</span><br />
<span style="font-family: Verdana, sans-serif;">4) I dont want the link tag so i removed the <--a---> tag, and finally we will have the result</--a---></span><br />
jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-58482868965730471472013-08-16T03:35:00.002-07:002013-08-16T03:35:36.995-07:00How to get images for a URL through php?We can use many concepts for this eithe we can use DOM or CURL or anything. Lets see a simple example on how to use DOM concept<br />
<br />
<br />
<code></code><br />
<br />
<br />
$doc = new DOMDocument();<br />
$doc->loadHTML('Your URL');<br />
$imageTags = $doc->getElementsByTagName('img');<br />
<br />
foreach($imageTags as $tag) {<br />
$img_src= $tag->getAttribute('src');<br />
}<br />
<div>
<br /></div>
<br />
<br />
<br />
<br />
By this we can get all the image tag in the particular URL, you can write separate scripts for Image types too.jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-53262890285122659012013-07-12T02:32:00.001-07:002013-08-16T03:40:03.620-07:00Search lists from Youtube, Dailymotion, Google and Metacafe using PHP<b><span style="color: red; font-size: large;">Youtube</span></b>: For youtube you need to down the files from google-api-php-client and please use this below demo file<br />
<br />
<br />
$htmlBody = <<<end p=""></end><br />
<form method="GET">
</form>
<br />
<div>
</div>
<br />
Search Term: <input id="q" name="q" placeholder="Enter Search Term" type="search" /><br />
<br />
<br />
<div>
</div>
<br />
Max Results: <input id="maxResults" max="50" min="1" name="maxResults" step="1" type="number" value="25" /><br />
<br />
<input type="submit" value="Search" /><br />
<br />
END;<br />
<br />
if ($_GET['q'] && $_GET['maxResults']) {<br />
// Call set_include_path() as needed to point to your client library.<br />
require_once 'src/Google_Client.php';<br />
require_once 'src/contrib/Google_YouTubeService.php';<br />
<br />
/* Set $DEVELOPER_KEY to the "API key" value from the "Access" tab of the<br />
Google APIs Console <http: access="" apis="" code.google.com="" console=""></http:><br />
Please ensure that you have enabled the YouTube Data API for your project. */<br />
$DEVELOPER_KEY = 'put your api key here';<br />
<br />
$client = new Google_Client();<br />
$client->setDeveloperKey($DEVELOPER_KEY);<br />
<br />
$youtube = new Google_YoutubeService($client);<br />
<br />
try {<br />
$searchResponse = $youtube->search->listSearch('id,snippet', array(<br />
'q' => $_GET['q'],<br />
'maxResults' => $_GET['maxResults'],<br />
));<br />
<br />
$videos = '';<br />
$channels = '';<br />
$playlists = '';<br />
<br />
<br />
//print_r($searchResponse['items']);<br />
<br />
<br />
<br />
for($x=0;$x<count items="" p="" searchresponse="" x=""><br />
echo $searchResponse['items'][$x]['id'] ['videoId'] ;<br /><br />
<br />
}<br />
<br />
/*<br />
foreach ($searchResponse['items'] as $searchResult) {<br />
switch ($searchResult['id']['kind']) {<br />
case 'youtube#video':<br />
$videos .= sprintf('
</count><br />
<li>%s (%s)</li>
', $searchResult['snippet']['title'],<br />
$searchResult['id']['videoId']);<br />
break;<br />
case 'youtube#channel':<br />
$channels .= sprintf('
<li>%s (%s)</li>
', $searchResult['snippet']['title'],<br />
$searchResult['id']['channelId']);<br />
break;<br />
case 'youtube#playlist':<br />
$playlists .= sprintf('
<li>%s (%s)</li>
', $searchResult['snippet']['title'],<br />
$searchResult['id']['playlistId']);<br />
break;<br />
}<br />
}<br />
<br />
$htmlBody .= <<<end p=""> <h3>
Videos</h3>
<ul>$videos</ul>
<br />
<br />
<h3>
Channels</h3>
<br />
<ul>$channels</ul>
<br />
<h3>
Playlists</h3>
<br />
<ul>$playlists</ul>
<br />
END;*/<br />
} catch (Google_ServiceException $e) {<br />
$htmlBody .= sprintf('A service error occurred: <code>%s</code><br />
',<br />
htmlspecialchars($e->getMessage()));<br />
} catch (Google_Exception $e) {<br />
$htmlBody .= sprintf('An client error occurred: <code>%s</code><br />
',<br />
htmlspecialchars($e->getMessage()));<br />
}<br />
}<br />
?><br />
<br />
<br />
<html></html><br />
<head></head><br />
<title>YouTube Search</title><br />
</end><br />
<body></body><br />
<br />
<br />
<br />
<br />
<br />
=================================================================<br />
<br />
<h2>
<span style="color: red;">Google Image Search:</span></h2>
<div>
<br /></div>
<div>
<br />
$url = "<a href="https://ajax.googleapis.com/ajax/services/search/images" target="_blank">https://ajax.googleapis.com/<wbr></wbr>ajax/services/search/images</a>?" .<br />
"v=1.0&q=barack%20obama&<wbr></wbr>userip=INSERT-USER-IP";<br />
<br />
// sendRequest<br />
// note how referer is set manually<br />
$ch = curl_init();<br />
curl_setopt($ch, CURLOPT_URL, $url);<br />
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br />
curl_setopt($ch, CURLOPT_REFERER, "<a href="http://localhost/jothirajan/demos/google.php" target="_blank">http://localhost/#######/google.php</a>");<br />
$body = curl_exec($ch);<br />
curl_close($ch);<br />
<br />
// now, process the JSON string<br />
$json = json_decode($body);<br />
<br />
/*$results = array();<br />
foreach ($json['responseData']['<wbr></wbr>results'] as $result) {<br />
$results[] = array(<br />
'url' => $result['url'],<br />
'title' => $result['title'],<br />
'content'=>$result['content']<br />
);<br />
}<br />
*/<br />
echo '<br />
<pre>';
var_dump($json->responseData-><wbr></wbr>results);
echo '</pre>
';<br />
<br />
<br />
for($x=0;$x<count json-=""><wbr></wbr>responseData->results);$x++){<br /><br />echo "<b>Result ".($x+1)."</b>";<br />
echo "<br />Image: ";<br />echo $json->responseData->results[$<wbr></wbr>x]->url;<br />echo "<br /><img br="" height="".$json->responseData-<wbr>>results[$x]->tbHeight."" src="".$json->responseData-><wbr>results[$x]->url."" width="".$json->responseData-><wbr>results[$x]->tbWidth."" />
<br /><br />echo $json->responseData->results[$<wbr></wbr>x]->url;<br />echo "<br />URL: ";<br />echo $json->responseData->results[$<wbr></wbr>x]->url;<br />echo "<br />VisibleURL: ";<br />echo $json->responseData->results[$<wbr></wbr>x]->visibleUrl;<br />
echo "<br />Title: ";<br />echo $json->responseData->results[$<wbr></wbr>x]->title;<br />echo "<br />Content: ";<br />echo $json->responseData->results[$<wbr></wbr>x]->content;<br />echo "<br /><br />";<br />
<br />}<br /><br />// now have some fun with the results...<br /><br />/*echo '</count><br />
<pre>';
var_dump($json);
echo '</pre>
';<br />*/<br /><br /><br />//$decodedJSON = json_encode($json);<br /><br />// Put everyting to the screen with var_dump;<br />
//var_dump($decodedJSON);<br /><br />// With print_r ( useful for arrays );<br />//print_r($decodedJSON);<br /><br />/*foreach ( $json->responseData->results as $results1 )<br />{<br /> echo $results1;<br />}*/<br /><br />//print_r($json->responseData-<wbr></wbr>>results);<br />
<br />/*$properties = get_object_vars($json);<br />print_r($properties);*/<br /><br />//print_r($json);<br /><br />?></div>
<br />
<br />
==================================================================<br />
<br />
<h2>
<span style="color: red;">Metacafe:</span></h2>
<br />
<br />
if(isset($_POST['search']))<br />
{<br />
$video=$_POST['video'];<br />
//echo $video;<br />
$curl = curl_init();<br />
curl_setopt($curl, CURLOPT_URL, '<a href="http://www.metacafe.com/topics/%27.$video" target="_blank">http://www.metacafe.com/<wbr></wbr>topics/'.$video</a>);<br />
curl_setopt($curl, CURLOPT_HEADER, 0); <br />
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); <br />
curl_setopt($curl, CURLOPT_FOLLOWLOCATION,true);<br />
$result = curl_exec($curl); curl_close($curl); <br />
//echo $result; <br />
<br />
//$value=preg_match_all('/<<wbr></wbr>section class=\"CCol">(.*?)<\/section><wbr></wbr>/s',$result,PREG_PATTERN_<wbr></wbr>ORDER);<br />
preg_match('/<br />
<section class="\" ol="">(.*?)<\/section><wbr></wbr>/s', $result, $matches, PREG_OFFSET_CAPTURE);<br />
print_r($matches);<br />}<br />?><br />http://www.w3.org/TR/xhtml1/<wbr></wbr>DTD/xhtml1-transitional.dtd</section><br />
"><br />
<html http:="" target="_blank" www.w3.org="" xhtml="" xmlns="<a href=">http://www.w3.org/1999/<wbr></wbr>xhtml</html>"><br />
<head><br /><br />
<title>Search Video - Metcafe</title></head><br />
<body><br /><form action="" id="search" method="post" name="search">
<br /><table><br />
<tr><br />
<td><br /> Search videos<br /> </td><br /> <td><br /> <input id="video" name="video" nbsp="" type="text" /><br /> </td><br /> <td><br /> <input id="search" name="search" nbsp="" type="submit" value="search" /><br />
</td><br /> </tr>
<br />
<tr><br /> <td><br /> <div id="results">
<br /> <br /> </div>
<br /> </td><br /> </tr>
</table>
</form>
</body><br />
<br />
<br />
==================================================================<br />
<div>
<br /></div>
<h2>
<span style="color: red;">Daily Motion:</span></h2>
<div>
<br />
$url="<a href="https://api.dailymotion.com/videos?search=" target="_blank">https://api.dailymotion.<wbr></wbr>com/videos?search=</a><span style="color: magenta;">facebook</span>&<wbr></wbr>fields=id,title,channel,<wbr></wbr>thumbnail_medium_url";<br />
<div class="im">
// sendRequest<br />
// note how referer is set manually<br />
$ch = curl_init();<br />
curl_setopt($ch, CURLOPT_URL, $url);<br />
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);</div>
curl_setopt($ch, CURLOPT_REFERER, "<a href="http://localhost/jothirajan/demos/dailymotion-sdk-php-master/test.php" target="_blank">http://localhost/jothirajan/<wbr></wbr>demos/dailymotion-sdk-php-<wbr></wbr>master/test.php</a>");<br />
<div class="im">
<br />
$body = curl_exec($ch);<br />
curl_close($ch);<br />
<br />
// now, process the JSON string<br />
$json = json_decode($body);<br />
<br /></div>
<div class="im">
/*echo '<br />
<pre>';
var_dump($json);
echo '</pre>
';<br />
<br />
*/</div>
for($x=0;$x<count json-="">list)<wbr></wbr>;$x++){</count><br />
<div class="im">
<br />
<br />
echo "<b>Result ".($x+1)."</b>";</div>
echo "<br />id: ";<br />echo $json->list[$x]->id;<br />echo "<br />Img: ";<br />
echo "<br /><img br="" src="".$json->list[$x]-><wbr>thumbnail_medium_url."" />";<br /><br />echo "<br />channel: ";<br />echo $json->list[$x]->channel;<br />echo "<br />title: ";<br />
echo $json->list[$x]->title;<br /><br />echo "<br /><br />";<br /><br />}<br /><br />?></div>
<br />
<br />
<br />
<br />
<div>
<br /></div>
jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-39151487141420381342013-05-02T04:06:00.001-07:002013-05-02T04:17:01.737-07:00Increment date using while loop in php<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> $start_date = "2013-01-01";<br />
$end_date = "2013-01-20";<br />
$next_date = $start_date;<br />
<br />
while(strtotime($next_date) <= strtotime($end_date))<br />
{<br />
echo "$next_date<br />
";<br />
$next_date = date ("Y-m-d", strtotime("+5 day", strtotime($next_date)));<br />
}<br />
<br />
<br />
<div>
Ok in for loop?<br />
<br />
<br />
$start_date = "2013-01-01";<br />
$end_date = "2013-01-25";<br />
$next_date = $start_date;<br />
<br />
for($i=0;$i<=(strtotime($next_date) <= strtotime($end_date));$i++)<br />
{<br />
echo "$next_date<br />";<br />
$next_date = date ("Y-m-d", strtotime("+2 day", strtotime($next_date)));<br />
}<br />
<br />
<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
</div>
jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-69248774415741239792013-05-02T04:05:00.002-07:002013-05-02T04:05:45.685-07:00SUM TWO TIMES IN PHP, SUM TWO TIME VALUES IN PHPecho sum_the_time('01:45:22', '17:27:03'); <br />
<br />
function sum_the_time($time1, $time2) {<br />
$times = array($time1, $time2);<br />
$seconds = 0;<br />
foreach ($times as $time)<br />
{<br />
list($hour,$minute,$second) = explode(':', $time);<br />
$seconds += $hour*3600;<br />
$seconds += $minute*60;<br />
$seconds += $second;<br />
}<br />
$hours = floor($seconds/3600);<br />
$seconds -= $hours*3600;<br />
$minutes = floor($seconds/60);<br />
$seconds -= $minutes*60;<br />
// return "{$hours}:{$minutes}:{$seconds}";<br />
return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);<br />
<br />
<br />jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com6tag:blogger.com,1999:blog-7451259017092072303.post-54723091271381836102013-03-14T22:01:00.001-07:002013-03-14T22:01:30.782-07:00Phonegap photoswipe with download option script<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>(function(window, PhotoSwipe){<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>document.addEventListener('DOMContentLoaded', function(){<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>var<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>options = {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>getImageCaption: function(el){<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>var captionText, captionEl, captionTextSRC;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// Get the caption from the alt tag<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (el.nodeName === "IMG"){<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>captionText = el.getAttribute('alt');<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>captionTextSRC = el.getAttribute("src");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>var i, j, childEl;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>for (i=0, j=el.childNodes.length; i<j i="" p=""><span class="Apple-tab-span" style="white-space: pre;"> </span>childEl = el.childNodes[i];<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (el.childNodes[i].nodeName === 'IMG'){<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>captionText = childEl.getAttribute('alt');<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>captionTextSRC = childEl.getAttribute("src");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// Return a DOM element with custom styling<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>captionEl = document.createElement('div');<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>captionEl.style.cssText = 'background: red; font-weight: bold; padding: 5px;';<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>captionEl.appendChild(document.createTextNode("Download"));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//console.log('JJJJJJJJJJJJ'+ captionTextSRC);<br />
//captionEl.onclick = testing;<br />
//var fileTransfer = new FileTransfer();<br />
captionEl.onclick = (function() {<br />
//navigator.notification.alert("Loasdasdsaddsdsdsdgin Successfull");<br />
var fileTransfer = new FileTransfer();<br />
fileTransfer.download(<br />
captionTextSRC,<br />
"file://sdcard/"+captionText,<br />
function(entry) {<br />
navigator.notification.alert("download complete: " + entry.fullPath);<br />
},<br />
function(error) {<br />
navigator.notification.alert("download error source " + error.source);<br />
navigator.notification.alert("download error target " + error.target);<br />
navigator.notification.alert("upload error code" + error.code);<br />
});<br />
<br />
});<br />
<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//captionEl.appendChild(document.createTextNode(captionText));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return captionEl;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// Alternatively you can just pass back a string. However, any HTML<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// markup will be escaped<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>},<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>instance = PhotoSwipe.attach( window.document.querySelectorAll('#Gallery a'), options );<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}, false);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}(window, window.Code.PhotoSwipe));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>function testing()<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>navigator.notification.alert("Login Successfull");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
</j>jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-70239861585496166612013-03-13T22:01:00.001-07:002013-03-13T22:01:35.083-07:00SVN: Authorisation FailedUse the below command: rm ~/.gnome2/keyri<wbr></wbr>ngs/login.keyri<wbr></wbr>ng<br />
<span class="kn" title="neelima@blaze.ws"></span>jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0tag:blogger.com,1999:blog-7451259017092072303.post-17594401250974255302012-07-02T02:15:00.001-07:002012-07-02T02:15:27.447-07:00How to get the Spanish Character from URL in php?How to get the Spanish Character from URL in php?<br />
<br />
Use utf8_decode("string");jothi.rhttp://www.blogger.com/profile/10483963554272208237noreply@blogger.com0