tag:blogger.com,1999:blog-26386081129251253862024-03-13T22:30:22.761-07:00Drupal Dr.Turn the coffee into code.ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.comBlogger53125tag:blogger.com,1999:blog-2638608112925125386.post-19136160280835890932014-08-14T13:51:00.002-07:002014-08-14T13:51:39.839-07:00Construct URL after submit.<div dir="ltr" style="text-align: left;" trbidi="on">
When you create a custom form using some custom module, and you want to construct the url after user submit the form... use<br />
<br />
<pre class="brush : php"> $form['method'] = 'get';
</pre>
<br />
in the form generation code.</div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-61698147682541658942014-03-27T00:44:00.000-07:002014-03-27T00:44:19.401-07:00 Convert Putty ppk key to SSH key <div dir="ltr" style="text-align: left;" trbidi="on">
You cant use a putty ppk to ssh to a remote server from you linux machine. In that case you may need to first convert ppk to ssh file.<br />
<br />
For that first you need to install putty on your machine.<br />
<br />
<pre class="brush : php">$ sudo apt-get install putty
</pre>
<br />
Then goto the directory and run the following command to convert ppk to ssh file.<br />
<br />
<pre class="brush : php">$ puttygen key.ppk -O private-openssh -o key.ssh
</pre>
<br />
Here, I assume, kep.ppk is you ppk file and key.ssh will be newly created ssh file.<br />
After this you can ssh to your remote machine/server using following command.<br />
<br />
<pre class="brush : php">$ ssh user@myserver.com -i key.ssh
</pre>
</div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-85320032259146955742014-03-12T02:22:00.000-07:002014-03-12T02:22:06.102-07:00Not Found - phpmyadmin<div dir="ltr" style="text-align: left;" trbidi="on">
I installed phpmyadmin with apache on Linux but I was seeing this at localhost/phpmyadmin<br />
<br />
<pre class="brush : html">
Not Found
The requested URL /phpmyadmin/ was not found on this server.
Apache/2.2.17 (Ubuntu) Server at localhost Port 80
</pre>
<br />
<br />
To fix this I had to make changes to apache.conf<br />
<br />
<pre class="brush : php">
sudo vim /etc/apache2/apache2.conf
</pre>
<br />
and added the following line at the end...<br />
<br />
<pre class="brush : php">
Include /etc/phpmyadmin/apache.conf
</pre>
<br />
then restart the apache..<br />
<br />
<pre class="brush : php">
sudo service apache2 restart
</pre>
<br />
</div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-57137287699987230932014-03-12T00:06:00.000-07:002014-03-12T00:24:19.906-07:00Installing NetBeans - Linux<div dir="ltr" style="text-align: left;" trbidi="on">
Before installing NetBeans you need to install JDK software. <br />
You can install the JDK software and NetBeans IDE in directories of your choice. Note: This installer does not displace the system version of the Java platform that is supplied by the operating system.<br />
<br />
You can run the following command to install JDK.<br />
<br />
<pre class="brush : php">sudo apt-get install openjdk-7-jdk
</pre>
<br />
Go to the <a href="https://netbeans.org/downloads/index.html" target="_blank">NetBeans download page</a> and download the PHP package. Save the file on the desktop.<br />
<br />
Now open terminal and run the following command.<br />
<br />
<pre class="brush : php">sudo sh netbeans-7.4-php-linux.sh
</pre>
<br />
After unpacking, you will find with the first step of the installation wizard.<br />
Go through the installation wizard.<br />
After that you will find net beans at Dash home or Applications.<br />
<br />
Now if you need to configure Netbeans for Drupal, see <a href="https://drupal.org/node/1019816" target="_blank">this</a>.</div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-8461797264137652452014-02-28T06:23:00.001-08:002014-02-28T06:24:17.828-08:00Compare FIELD value befaore saving the form - Form API<div dir="ltr" style="text-align: left;" trbidi="on">
If you want to compare a field value with it self it was changed or not, you can do it using $node->original in <a href="https://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_node_presave/7" target="_blank">hook_node_presave</a><br />
<pre class = 'brush : php'>
function custom_node_presave($node) {
if ($node->field_name == 1 && $node->original->field_name == 0) {
//Do the magic here...
}
}
</pre>
<br />
Here I am comparing if checkbox was newly checked or was already checked. :)
<br /></div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-37116967503036558322014-02-28T06:16:00.001-08:002014-02-28T06:17:33.471-08:00Set value for CheckBox field - Form API<div dir="ltr" style="text-align: left;" trbidi="on">
By default checkbox works with 1, 0 values to be checked, unchecked respectivly.<br />
<br />
<pre class= 'brush: php'>
$form['custom_checkbox'] = array(
'#type' => 'checkbox',
'#title' => 'Title',
'#default_value' => variable_get('custom_var'),
);
</pre><br />
<br />
you can use #return_value to set a desired value for the checkbox field is it is selected.<br />
<br />
<pre class= 'brush: php'>
$form['custom_checkbox'] = array(
'#type' => 'checkbox',
'#title' => 'Title',
'#return_value' => $key,
'#default_value' => variable_get('custom_var'),
);
</pre></div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-22467222069251165272014-02-27T04:44:00.003-08:002014-02-27T04:45:38.173-08:00Ajax Status Message - Drupal<div dir="ltr" style="text-align: left;" trbidi="on">
I was trying to show status message against an ajax call. Was using rules_link to promote nodes clicking on a link. And wanted to show message if it was done.<br />
<br />
Here is how I did it....<br />
<pre class="brush: php">
$commands = array();
$commands[] = ajax_command_prepend('div#ajax-status-messages-wrapper', drupal_set_message(variable_get('limit_po_notification'), 'error'));
return array('#type' => 'ajax', '#commands' => $commands);
</pre>
<br />
<br /></div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-35480066026110195262014-02-21T08:50:00.000-08:002014-02-21T09:10:22.865-08:00Syntax Highlighting with Blogger Engine<div dir="ltr" style="text-align: left;" trbidi="on">
I was trying to style the code snippets highlighted as code as developer in my blog. Did it using some custom css but no positive impression. Recently googling, found an article abt that <a href="http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.html" target="_blank">here</a>.<br />
<br />
This can be done using <a href="http://alexgorbatchev.com/wiki/SyntaxHighlighter" target="_blank">syntaxhiglighter</a>.<br />
<br />
Drop this code right before your </head> tag... <br />
<br />
<pre class="brush: php"><link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css"></link>
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" rel="stylesheet" type="text/css"></link>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js" type="text/javascript"></script>
<script language="javascript">
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf';
SyntaxHighlighter.all();
</script>
</pre>
<br />
<br />
and save.<br />
And here is the way how you can use it.<br />
<br />
1. Using <script> tag with CDATA<br />
<br />
<pre class="brush: php"><script class=""brush:" csharp="" quot="" type=""syntaxhighlighter"">
<![CDATA[
// Commenting this function
function custom_one($var) {
if($one == $two) {
$three = array(
'one',
'two'
);
}
}
]]>
</script>
</pre>
This will output....<br />
<br />
<pre class="brush: php">
// Commenting this function
function custom_one($var) {
if($one == $two) {
$three = array(
'one',
'two'
);
}
}
</pre>
<br />
<br />
2. Using the <pre> tag.<br />
<br />
<pre class="brush: php">
<pre class="brush: php">
// Commenting this function
function custom_one($var) {
if($one == $two) {
$three = array(
'one',
'two'
);
}
}
</pre>
</pre>
This will output.... <br />
<pre class="brush: php">
// Commenting this function
function custom_one($var) {
if($one == $two) {
$three = array(
'one',
'two'
);
}
}
</pre>
<br />
<br /></div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com2tag:blogger.com,1999:blog-2638608112925125386.post-9498794771103733022014-02-21T07:13:00.003-08:002014-02-21T07:14:56.126-08:00Webform in Blocks - Drupal 7<div dir="ltr" style="text-align: left;" trbidi="on">
In Drupal 6, we have been using <a href="https://drupal.org/project/formblock" target="_blank">FormBlock</a> to show the form in the block.<br />
But in D7 its pretty simple to do so.<br />
<br />
After creating a webform, goto form setting at 'node/103/webform/configure'<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-l7RwvG6im2Y/UwdopFqN7HI/AAAAAAAAAm0/TLQ9Aj4iIT8/s1600/001-webform.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-l7RwvG6im2Y/UwdopFqN7HI/AAAAAAAAAm0/TLQ9Aj4iIT8/s1600/001-webform.png" height="100" width="400" /></a></div>
Move down to Advaced Setting and check the "Available as block" option.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-dFldnCAhkJg/UwdqJRh5EqI/AAAAAAAAAnE/RPCTnp7E8Nw/s1600/002-webforma.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-dFldnCAhkJg/UwdqJRh5EqI/AAAAAAAAAnE/RPCTnp7E8Nw/s1600/002-webforma.png" height="211" width="400" /></a></div>
<br /></div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-16034302647618361352013-12-28T00:08:00.001-08:002013-12-28T00:09:49.578-08:00How To Install and Utilize VirtualMin on a VPS<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="https://www.digitalocean.com/community/articles/how-to-install-and-utilize-virtualmin-on-a-vps">https://www.digitalocean.com/community/articles/how-to-install-and-utilize-virtualmin-on-a-vps</a></div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-22272877373534342852013-08-01T01:44:00.001-07:002014-02-21T07:31:46.167-08:00Drupal 7 - First Time Login Redirection<div dir="ltr" style="text-align: left;" trbidi="on">
I was trying tocome up with a solution for first time login redirection and after that redirection to user profile edit page every time a user logged in.<br />
<br />
For that I created a role, "First Time Login". Then created a rule using <a href="https://drupal.org/project/rules" target="_blank">rules</a> module. It will assign role "First Time Login" to a newly created user.<br />
<br />
Then in the following code, in module "custom_login_redirections" using <a href="https://api.drupal.org/api/drupal/modules!user!user.api.php/function/hook_user_login/7" target="_blank">hook_user_login</a> redirected user to the "Welcome Page" of it has role "First Time Login".<br />
<br />
<br />
<br />
<pre class="brush: csharp">// Comment
function custom_login_redirections_user_login(&$edit, $account) {
if (!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset') {
if(isset($account->roles[30])){
if(in_array($account->roles[30], $account->roles)) {
$options = array(
'absolute' => TRUE,
'query' => array('destination' => '#overlay=node/17973')
);
$redirect = url('user/register', $options);
$_GET['destination'] = $redirect;//drupal_encode_path('#overlay=node/17973');
custom_remove_role_from_user($account->uid, $account->roles[30]);
}
}
else {
$_GET['destination'] = 'user/'.$account->uid.'/edit';
}
}
}
</pre>
<br />
Then using "custom_remove_role_from_user" function, removed that role "First Time Login" from the user. So next time it should redirect to user edit page.<br />
<br />
<pre class="brush: csharp">// Comment
function custom_remove_role_from_user($user, $role_name) {
// For convenience, we'll allow user ids as well as full user objects.
if (is_numeric($user)) {
$user = user_load($user);
}
// Only remove the role if the user already has it.
$key = array_search($role_name, $user->roles);
if ($key == TRUE) {
// Get the rid from the roles table.
$roles = user_roles(TRUE);
$rid = array_search($role_name, $roles);
if ($rid != FALSE) {
// Make a copy of the roles array, without the deleted one.
$new_roles = array();
foreach($user->roles as $id => $name) {
if ($id != $rid) {
$new_roles[$id] = $name;
}
}
user_save($user, array('roles' => $new_roles));
}
}
}
</pre>
<br />
<br /></div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-39439636936330020402013-07-18T06:06:00.002-07:002014-02-21T07:32:35.259-08:00Drupal - Hiding field group and its Children<div dir="ltr" style="text-align: left;" trbidi="on">
It came to me when I was trying to hide field_group on account page. Searching on I found the following solution using hook_form_alter<br />
<pre class="brush: csharp">// Comment
/**
* Implements hook_form_FORM_ID_alter().
*/
function MODULE_form_node_form_alter(&$form, &$form_state) {
global $user;
// The 'internal' field groups should only be accessible for
regional administrators.
if (!in_array('regional administrator', $user->roles)) {
foreach (array('group_action_internal', 'group_company_internal',
'group_topic_internal') as $fieldgroup) {
if (isset($form['#fieldgroups'][$fieldgroup])
&& isset($form['#group_children'])) {
// Hide the field group itself.
$form['#fieldgroups'][$fieldgroup]->format_type = 'hidden';
// Hide the elements inside the field group.
foreach ($form['#group_children'] as $field => $group) {
if ($group == $fieldgroup) {
$form[$field]['#access'] = FALSE;
}
}
}
}
}
}
</pre>
Source <a href="https://drupal.org/node/1324860">https://drupal.org/node/1324860</a><br />
<br />
<br /></div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-72193646224966795092013-07-03T06:08:00.001-07:002014-02-21T07:36:28.236-08:00Some Useful Drush Commands<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Downloading modules: </b><br />
<br />
<pre class="brush: php">
$ drush dl module_name
</pre>
<br />
It will automaticly download extracted module to modules folder in your project.
Enabling modules:<br />
<br />
<pre class="brush: php">
$ drush en module_name
</pre>
<br />
<b>Disabling modules:</b><br />
<br />
<pre class="brush: php">
$ drush pm-disable module_name
</pre>
<br />
<b>Unistalling modules:</b><br />
<br />
<pre class="brush: php">
$ drush pm-uninstall module_name
</pre>
<br />
<b>Clear Cache: </b><br />
You can use the following command to clear all cache of your site.<br />
<br />
<pre class="brush: php">
$ drush cc all
</pre>
<br />
<b>List modules:</b><br />
<br />
<pre class="brush: php">
$ drush pm-list --type=module
</pre>
<br />
And if you want to list only non core modules, you can use<br />
<br />
<pre class="brush: php">
$ drush pm-list --type=module --no-core --pipe
</pre>
<br />
<b>SQL dump:</b><br />
<br />
<pre class="brush: php">
$ drush sql-dump > filename.sql
</pre>
<br />
It will automatically take the dump of the database of the project in which you are.
status (st)
Check the Status:
Provides a birds-eye view of the current Drupal installation, if any.<br />
<br />
<pre class="brush: php">
$ drush status
</pre>
<br />
<b>Check the Recent Watchdog: </b><br />
To list the recent watch dog status, us the following.<br />
<br />
<pre class="brush: php">
$ drush ws
</pre>
<br />
ws referes to Watchdog show.<br />
<br />
<b>Database connection detail:</b><br />
Provides a birds-eye view of the current Drupal installation.<br />
<br />
<pre class="brush: php">
$ drush sql-conf
</pre>
<br />
It will print the connection detail.
Execute update.php:
To execute the update.php process you can run the following command in drush.<br />
<br />
<pre class="brush: php">
$ drush updb
</pre>
<br /></div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-32436450575687391492013-07-03T00:11:00.001-07:002014-02-21T07:40:47.031-08:00Installing Drupal - On Lamp<div dir="ltr" style="text-align: left;" trbidi="on">
<style type="text/css">
<!--
@page { margin: 0.79in }
PRE { direction: ltr; color: #00000a; widows: 0; orphans: 0 }
PRE.western { so-language: en-US }
PRE.cjk { so-language: zh-CN }
PRE.ctl { so-language: hi-IN }
P { margin-bottom: 0.08in; direction: ltr; color: #00000a; widows: 0; orphans: 0 }
P.western { font-family: "Liberation Serif", serif; font-size: 12pt; so-language: en-US }
P.cjk { font-family: "DejaVu Sans"; font-size: 12pt; so-language: zh-CN }
P.ctl { font-family: "Lohit Hindi"; font-size: 12pt; so-language: hi-IN }
A:link { so-language: en-US }
</style>
<br />
Here we will see how to install Drupal on a LAMP environment.
We can do it using two ways, one is downloading it manulay and other is
install it using DRUSH.(We will see how to install drush in next
sections.)<br />
<br />
<b>Downloading and Extracting Drupal </b><br />
<br />
You can download latest Drupal by going to https://drupal.org/project/drupal are by using any utility.
Here we will be using wget in shell.<br />
<br />
<pre class="brush: php">wget http://ftp.drupal.org/files/projects/drupal-x.x.tar.gz
</pre>
<br />
You can replace x.x with the version you want to download. For example..<br />
<br />
<pre class="brush: php">wget http://ftp.drupal.org/files/projects/drupal-7.22.tar.gz
</pre>
Now time to exteact the file you just downloaded.<br />
<br />
<pre class="brush: php">tar -zxvf drupal-7.22.tar.gz
</pre>
<br />
After extracting you can move files in drupal-7.22.tar.gz directory one
level "up" into the web server's document root or your public HTML
directory.<br />
<br />
<pre class="brush: php">mv drupal-7.22/* /var/www/local.mysite.com/docroot
</pre>
<br />
NOTE: In your web server's configuration file the base URL for your Drupal installation will be set.<br />
<br />
<b>Creating Database and User </b><br />
<br />
You need to create an empty database and database user before running the installation script.
You can do it using command line or using PHPMyAdmin user interface.
You can use the following commands to create database and a user.<br />
<br />
<pre class="brush: php">mysql -u root -proot
</pre>
<br />
After logging in create database<br />
<br />
<pre class="brush: php">create database database_name;
</pre>
<br />
Then create a user for this database..<br />
<br />
<pre class="brush: php">CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
</pre>
<br />
By now, newuser has no permissions to do anything with the databases.
So to grant him permissions for a database we just created.<br />
<br />
<pre class="brush: php">GRANT ALL ON database_name.* TO 'newuser'@'localhost';
</pre>
<br />
And there you go.
</div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-14659048076311792422013-05-28T00:13:00.002-07:002014-02-21T09:52:59.268-08:00Set menu item active using custom code.<div dir="ltr" style="text-align: left;" trbidi="on">
If you want to set a menu item of the main menu as active (class="active"). Here is how you can do this..<br />
<pre class="brush: php">
function mymodule_init() {
$link=menu_link_load(2570);
$link["options"]["attributes"]["class"]="active";
menu_link_save($link);
}
</pre>
2570 is mlid of that perticuler menu item. You can check it by editing that perticuler menu item "admin/build/menu/item/2570/edit"
Now, I just want to set it active on some specific pages... like "mypage01", "mypage02" etc
<pre class="brush: php">
function mymodule_init() {
if((arg(0) == 'mypage01') || (arg(0) == 'mypage02')) {
$link=menu_link_load(2570);
$link["options"]["attributes"]["class"]="active";
menu_link_save($link);
$menu_active = 1;
}
else {
if($menu_active == 1) {
$link=menu_link_load(2570);
$link["options"]["attributes"]["class"]="";
menu_link_save($link);
$menu_active = 0;
}
}
}
</pre>
There you go...
</div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-10197534932749332412013-05-03T01:59:00.000-07:002014-02-21T09:53:24.030-08:00Downgrading PHP 5.4 to 5.3 on Ubuntu<div dir="ltr" style="text-align: left;" trbidi="on">
Download the shell script from <a href="http://www.ubuntugeek.com/images/php5_4_downgrade_5.3.sh" target="_blank">here</a> <br />
Once you have php5_4_downgrade_5.3.sh file you need to change the permissions using the following command<br />
<br />
<pre class="brush: php">
su root
</pre>
<pre class="brush: php">
chmod u+x ./php5_4_downgrade_5.3.sh
</pre>
Now you can run the script using the following command
<pre class="brush: php">
sudo sh php5_4_downgrade_5.3.sh
</pre>
Follow the on instructions
</div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-86033506825159984362013-04-04T02:44:00.002-07:002013-04-04T02:44:33.616-07:00Illegal offset type in isset or empty pathauto.inc:180<div dir="ltr" style="text-align: left;" trbidi="on">
In my scenario, I was using "simplexml_load_file" and getting values in variable.<br />
<pre>if ($child2->getName() == 'job_title') {
print $node_title = $child2;
}
</pre>
<br />
passing $node_title to node->title using node object and was saving it.<br />
It was working well in browser, when i was running script. But created a drush command for it 'drush impvac', which was resulting in<br />
<br />
<pre>docroot$ drush impvac
Illegal offset type in isset or empty pathauto.inc:180 [warning]
Illegal offset type pathauto.inc:223 [warning]
</pre>
<br />
It was because node->title was not getting a plain string from xml, so just added 'check_plain' to dp my stuff.<br />
<br />
<pre>if ($node_title != '') {
$node->title = check_plain($node_title);
}</pre>
And all was set.</div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-58840451756833938062013-03-19T04:20:00.003-07:002013-03-19T04:21:29.325-07:00How to get most recent date from an array of dates?<div dir="ltr" style="text-align: left;" trbidi="on">
<pre> $all_dates = array(
"15-03-2015-14:50",
"16-03-2013-14:50",
"15-08-2017-14:52",
"15-03-2014-14:50",
"20-03-2016-14:50",
);
//
foreach($all_dates as $date_one){
$date_one_to_string = strtotime($date_one);
$all_date_strings[$date_one] = $date_one_to_string;
}
arsort($all_date_strings);
$latest_date_strings = current($all_date_strings);
$key = array_search($latest_date_strings, $all_dates);
print 'Latest Date Is :'.$latest_date_strings;
</pre>
</div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-75240806994670120822013-03-13T00:00:00.002-07:002013-03-13T00:00:58.855-07:00Install urdu fonts in Linux (Ubuntu)<div dir="ltr" style="text-align: left;" trbidi="on">
<b>1- NafeesWeb.ttf </b>(For urdupoint.com etc)<br />
Go to <a href="http://www.crulp.org/software/localization/Fonts/nafeesWebNaskh.html" target="_blank">http://www.crulp.org/software/localization/Fonts/nafeesWebNaskh.html</a><br />
Download the file with title ‘<b>Font with MS VOLT project source</b>‘. Unzip it.<br />
<b>2-</b> <b>asunaskh.ttf</b> (For bbcurdu.com etc)<br />
Download from <a href="http://www.quran.or.kr/urdu/font/asunaskh.ttf" target="_blank">http://www.quran.or.kr/urdu/font/asunaskh.ttf</a><br />
<br />
<b>1-</b> Go to your home directory like /home/[name]. You can use nautilus for this. Click on <b>Places -> Computer</b> and then navigate to your <b>home directory</b>.<br />
<b>2-</b> Now click on ‘<b>View</b>‘ in the menu and click ‘<b>Show hidden files</b>‘. Or you can use <b>Ctrl+h</b>.<br />
<b>3-</b> Search for folder <b>.fonts</b>. Just
create it if it is not there, right click and create a directory with name without quotes ‘<b>.fonts</b>‘.<br />
<b>4-</b> Now copy the fonts from the downloaded directory and paste it in <b>.fonts</b> directory.<br />
<b>5-</b> Open <b>terminal </b>and type <br />
<pre>sudo fc-cache -vf</pre>
Enter your password if asked<br />
<b>6-</b> Thats it, <b>restart the browsers</b> and check the websites.<br />
<br /></div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com1tag:blogger.com,1999:blog-2638608112925125386.post-25448191012599084912013-03-10T12:19:00.000-07:002013-03-10T12:22:36.173-07:00Installing Gnome 3 on Ubuntu 12.04<div dir="ltr" style="text-align: left;" trbidi="on">
Installing Gnome 3 on Ubuntu 12.04 is very easy. Just copy-paste the following lines for the latest release from the Gnome team into a terminal.<br />
<br />
<pre>sudo add-apt-repository ppa:gnome3-team/gnome3
sudo apt-get update
sudo apt-get install gnome-shell</pre>
<br />
Now reboot your computer and when you see
your login screen you have the following additional options (click on
the little Ubuntu icon next to your login name).<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-bCXquXUIff0/UTzdKPayNDI/AAAAAAAAAP4/R-8zp7gjUJo/s1600/gnome-select-menu.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-bCXquXUIff0/UTzdKPayNDI/AAAAAAAAAP4/R-8zp7gjUJo/s1600/gnome-select-menu.png" /></a></div>
<br /></div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-32034388008294418302012-11-14T23:10:00.000-08:002014-02-21T09:54:33.780-08:00Installing Drupal 7 using Drush <div dir="ltr" style="text-align: left;" trbidi="on">
Drush is raealy handy to do the Drupal stuff ver quick and easy. If you haven't already installed Drush check http://drupal.org/project/drush.<br />
<br />
Installing Drupal 7 with DRUSH is awsome, with just two simple commands, setting up MYSQL user and DB, note down the passwoprd, then run the following comman.<br />
<br />
Make sure to replace the user and passwords names for your local setup:<br />
<br />
<pre class="brush: php">
drush dl drupal-7.x<br />
drush site-install standard --account-name=admin --account-pass=admin --db-url=mysql://MySQLUser:Password@localhost/MySQLDatabase
</pre>
<br />
...and you're done.<br />
<br />
*Note: The Drupal username and password seemed to always end up as admin/admin. So, just using those and then changing them after you login to your new site.</div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com1tag:blogger.com,1999:blog-2638608112925125386.post-24353556338639558222012-11-01T01:42:00.000-07:002012-11-01T01:44:01.956-07:00Override Default Blog View<div dir="ltr" style="text-align: left;" trbidi="on">
Drupal by default creates a blog view for evry use at sitename.com/blogs/user-name. To override this view with your custom one, create a page view of content type Blog Entry, with path as "blogs/%". Add "Content: Author" in Relationship. As you can see in below screen shot.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/--LS0bmcLxzk/UJI0obUTNjI/AAAAAAAAAMk/zRY8d25Wuyc/s1600/Screenshot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="257" src="http://2.bp.blogspot.com/--LS0bmcLxzk/UJI0obUTNjI/AAAAAAAAAMk/zRY8d25Wuyc/s400/Screenshot.png" width="400" /></a></div>
<br />
Now you need to filter it by the author of content. In contextual filter use "(Author) user: Uid" with selection of "Specify Validation Criteria", Choose user as "Validator". See attached screen shot for this.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-pULj7qyDKlw/UJI1dzyb7PI/AAAAAAAAAMs/tEGvGUokps0/s1600/Screenshot-4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="256" src="http://2.bp.blogspot.com/-pULj7qyDKlw/UJI1dzyb7PI/AAAAAAAAAMs/tEGvGUokps0/s400/Screenshot-4.png" width="400" /></a></div>
<br />
And there you go.<br />
Now what ever url you set in path auto, it will get that automatically.<br />
<br /></div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com1tag:blogger.com,1999:blog-2638608112925125386.post-22647591361107665662012-06-20T00:11:00.000-07:002014-02-21T09:55:05.403-08:00Resetting Drupal Passwords in Drupal 7 with Drush<div dir="ltr" style="text-align: left;" trbidi="on">
Sometimes, whether in testing or other situations, you need to reset a password (often the admin password) for a Drupal site.<br />
The shortest answer is that two wonderful options are built into drush!<br />
<br />
<div>
<pre class="brush: php">
# Get an admin login link
drush uli
# Set the password for any user
drush upwd admin --password="newpassword"
</pre>
</div>
</div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0tag:blogger.com,1999:blog-2638608112925125386.post-72418917783036679112012-06-19T23:23:00.002-07:002014-02-21T10:05:39.300-08:00How to Reset Root Password in Drupal 7 with phpMyAdmin<div dir="ltr" style="text-align: left;" trbidi="on">
Copy the hash..<br />
<b>$S$C6x2r.aW5Nkg7st6/u.IKWjTerHXscjPtu4spwhCVZlP89UKcbb/</b><br />
(that’s the hash for <b>newPassword</b>).<br />
<br />
<br />
Navigate to your phpMyAdmin (likely in your control panel online somewhere).<br />
Then browse the User table for the Root user, look like his.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-l_HqnEc2ciw/T-FuGMwy_OI/AAAAAAAAALY/Vca9x-FO55o/s1600/001.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-l_HqnEc2ciw/T-FuGMwy_OI/AAAAAAAAALY/Vca9x-FO55o/s400/001.jpg" height="300" width="400" /></a></div>
<br />
<br />
<br />
Take the copied hashed text and paste it into the pass field of the Root user and hit “Go”.<br />
<br />
See this If you want to reset Drupal pasword using <a href="http://drupaldr.blogspot.com/2012/06/resetting-drupal-passwords-in-drupal-7.html" target="_blank">Drush</a>. </div>
ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com5tag:blogger.com,1999:blog-2638608112925125386.post-31531579469923107072012-05-08T01:50:00.002-07:002013-03-13T00:25:13.324-07:00Drupal - List User's Author<div dir="ltr" style="text-align: left;" trbidi="on">
Drupal by default donot provide user's author detail in views or any where in data base. Once I went through this kind of requirnment to list users with detail, who created those users.<br />
<br />
A simple way in D7 is to add text field in "user_register_form". That field will be hidden and will get current user's detail in it. We will do this using a module with hook_form_alter.<br />
<br />
Say you added a text field in user registration form with name "field_authortxt"<br />
Add the following code in .module file
<br />
<div>
<pre>function custom_user_author_form_alter(&$form, &$form_state, $form_id) {
if(( $form_id == "user_register_form") || ( $form_id == "user_profile_form")){
$lang = $form['field_authortxt']['#language'];
global $user;
$form['field_authortxt'][$lang][0]['value']['#default_value'] = $user->name;
$form['#after_build'][] = '_tansnippet_after_build';
}
}
</pre>
</div>
Now we need to hide the field... we will be using after build handler for this..<br />
<div id="codee">
<pre>function _dothis_after_build($form, &$form_state) {
// Use this one if the field is placed on top of the form.
if(!empty($form['field_authortxt'])){
_dothis_fix_disabled($form['field_authortxt']);
}
return $form;
}
</pre>
</div>
This will be calling "_dothis_fix_disabled"<br />
<div >
<code>
function _dothis_fix_disabled(&$elements) {
foreach (element_children($elements) as $key) {
if (isset($elements[$key]) && $elements[$key]) {
// Recurse through all children elements.
_dothis_fix_disabled($elements[$key]);
}
}
//Adding readonly attributes to $elements
if (!isset($elements['#attributes'])) {
$elements['#attributes'] = array();
}
$elements['#attributes']['Hidden'] = 'Hidden';
}
</code>
</div>
Then in the views, you can list the users with "field_authortxt" as users author.
<br />
<br />
<br /></div>ibrainhttp://www.blogger.com/profile/15850399390124428304noreply@blogger.com0