Samat Says (Posts about Drupal)https://blog.samat.org/tag/drupal.atom2018-06-29T09:25:27ZSamat K JainNikolaChanging Drupal 7's built-in jQuery UI themehttps://blog.samat.org/2011/08/22/Changing-Drupal-7s-built-in-jQuery-UI-theme/2011-08-22T00:00:00Z2011-08-22T00:00:00ZSamat K Jain<div><p><a href="http://jqueryui.com/">jQuery UI</a>, a Javascript widget framework built upon jQuery, comes built-in Drupal 7 core. One of jQuery UI's nicer features is that you can switch <a href="http://jqueryui.com/themeroller/">themes</a> by changing out a CSS file.</p>
<p>There are some nice jQuery UI themes out there (unfortunately, not enough!), like Tait Brown's <a href="http://taitems.tumblr.com/post/482577430/introducing-aristo-a-jquery-ui-theme">port of Aristo to jQuery UI</a> (see <a href="http://taitems.github.com/Aristo-jQuery-UI-Theme/">demo</a>).</p>
<p>But since jQuery UI is in Drupal core, which internally keeps track of CSS files, how do you switch the jQuery UI theme in use?</p>
<p>The Seven theme, including with Drupal core, provides <a href="http://drupalcode.org/project/drupal.git/blob/HEAD:/themes/seven/template.php#l103">inspiration</a> on the "one true Drupal way" of doing this, by providing <code>hook_css_alter()</code>. Place into your theme's template.php:</p>
<pre><code>function MYTHEME_css_alter(&$css) {
if (isset($css['misc/ui/jquery.ui.theme.css'])) {
$css['misc/ui/jquery.ui.theme.css']['data'] = drupal_get_path('theme', 'MYTHEME') . '/jquery.ui.theme.css';
}
}
</code></pre>
<p>Replace "MYTHEME" with the name of your theme, and adjust the path to your jQuery UI theme's CSS file accordingly (the above assumes you place jquery.ui.theme.css in the root folder of your theme).</p>
<p>With this magic in hand, I now have the Aristo jQuery UI theme running on this blog. Looks quite a bit better!</p>
<p>This post was inspired by an <a href="http://drupal.stackexchange.com/questions/2458/jquery-ui-theming/9771#9771">answer I posted on StackExchange</a>.</p></div>BrowserID session API support for Drupalhttps://blog.samat.org/2011/08/15/BrowserID-session-API-support-for-Drupal/2011-08-15T00:00:00Z2011-08-15T00:00:00ZSamat K Jain<div><p>Late last week, Mozilla's Identity team made available a <a href="http://identity.mozilla.com/post/8841090082/sign-into-websites-directly-from-your-browser-toolbar">Firefox extension for BrowserID</a>, a new browser-oriented single-sign on mechanism. Click a button in your address bar and automagically login into a website.</p>
<p>Along with it they made available a <a href="http://www.shanetomlinson.com/2011/mozilla-session-api-tutorial/">browser session API</a>—that is, the browser can now keep track and show whether you're logged in, logged out, etc, also displayed in your address bar.</p>
<p>Drupal had a <a href="http://drupal.org/project/browserid">BrowserID module</a> less than 24 hours after BrowserID's initial announcement (thanks <a href="http://www.isaacsukin.com/">Isaac Sukin</a>!). Likewise, in the weekend after the session API announcement I helped out and <a href="http://drupal.org/node/1249746">wrote a patch</a> adding support for the new API.</p>
<p>If you're familiar with Drupal development, install the Drupal module, <s>apply the patch,</s> <a href="https://addons.mozilla.org/en-US/firefox/addon/browser-sign-in/">install the Firefox add-on</a>, and get browser-integrated, one-click login to your Drupal-powered website.</p>
<p>The patched module is running live on this site right now, so please play with it (<a href="http://myfavoritebeer.org/">myfavoritebeer.org</a> does get boring).</p>
<p>At the moment, Drupal's BrowserID module <strong>does not create an account on my blog</strong>, so you must do that first, separately. <a href="https://blog.samat.org/user/register">Create an account here</a>, or if you've an OpenID, <a href="https://blog.samat.org/user/login">logon with your OpenID directly</a> to also create an account (funny how complicated this has gotten already). Make sure to set and use the same e-mail address as the one you use for your BrowserID. After creating an account, logout, and then log back in using your BrowserID. If you've problems/find a bug, please leave comments on the Drupal bug or this blog post—thanks!</p>
<p>[UPDATE: 16 Aug 2010]: Drupal's BrowserID module now includes my patch; you don't need to download and apply the patch separately.</p></div>Taking Drupal sites offline via mysql and the command linehttps://blog.samat.org/2008/10/31/taking-drupal-site-offline-mysql-and-command-line/2008-10-31T00:00:00Z2008-10-31T00:00:00ZSamat K Jain<div><p>Drupal-powered websites can be put into an "offline mode." This is much better than most alternatives (such as taking the web server offline), especially for search engines, as the message and HTTP status codes given to users and robots alike will tell them to patiently come back later.</p>
<p>I've found that putting the site into offline mode makes database backups go much faster on heavily trafficked sites (which is obvious). However, for a particular site I was working with, this needed to be done in an automated manner, and on a dedicated database server that did not have access to the Drupal installation.</p>
<p>Most people take their Drupal sites offline through Drupal's web-based administration interface. They can also be put offline through the <a href="http://drupal.org/project/drush">Drupal Shell</a>. Neither were suitable for me: the former cannot be automated easily, and the latter requires access to the Drupal installation. Fortunately, Drupal sites can easily be taken offline by setting things in the database, which can easily be done via bash scripts and the command-line MySQL client.</p>
<p>Given your database user is <i>my_db_user</i>, password <i>my_password</i>, and database <i>my_drupal_db</i>, the backup script would look something similar to:</p>
<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15</pre></div></td><td class="code"><pre class="code literal-block"><span></span><span class="ch">#!/bin/bash</span>
<span class="c1"># Take site offline</span>
mysql --user my_db_user --password<span class="o">=</span>my_password my_drupal_db <span class="s"><< EOF</span>
<span class="s">UPDATE variable SET value='s:1:"1";' WHERE name = 'site_offline';</span>
<span class="s">DELETE FROM cache WHERE CID = 'variables';</span>
<span class="s">EOF</span>
<span class="c1"># Do stuff here while the site is offline (e.g. backup)</span>
<span class="c1"># Bring site online</span>
mysql --user my_db_user --password<span class="o">=</span>my_password my_drupal_db <span class="s"><< EOF</span>
<span class="s">UPDATE variable SET value='s:1:"0";' WHERE name = 'site_offline';</span>
<span class="s">DELETE FROM cache WHERE CID = 'variables';</span>
<span class="s">EOF</span>
</pre>
</td></tr></table>
<p><strong>Update:</strong> The original version of this article had some problems on some setups with the variables table being cached. I added another SQL statement to make sure this cache is flushed so the site actually reflects its configuration.</p>
<p><strong>Update:</strong> This method really doesn't work that well, and the more I think about it, there isn't a way to get around writing something that interacts with Drupal. I'm working on a script that will be more fool-proof.</p></div>