I was running a module through coder and there were numerous white spaces at the end of the lines. Doing these one at a time would have been awful and was starting to be. I use Komodo Edit for my editor and searching for a function I found this is built in. Go to “Edit->Preferences->Editor->Save Options” then choose “Clean trailing whitespace and EOL markers”. Now every time you save it will clean up those extra whitespaces for you. Nice.
Remove Spaces at end of lines easily with Komodo Edit
Posted July 16, 2008 by Adam MooreCategories: Drupal, PHP
Only Show Certain Themes
Posted May 30, 2008 by Adam MooreCategories: Drupal, PHP, Templates, javascript
Tags: PHP
I was looking for a way to only show certain themes on admin/build/themes page. I ended up adding some jquery to handle this. I created this script in a js file called theme_list.js.
var themes =new Array();
//Enter themes here into the array.
themes[0] = 'theme_1';
themes[1] = 'theme_2';
themes[2] = 'theme_3';
if(Drupal.jsEnabled) {
$(document).ready(
function(){
//Hide all the themes.
$('form#system-themes-form table.sticky-table tbody tr').toggle();
//Only show the themes we want to appear.
for (var i in themes){
$("input[@value='" + themes [i] + "']").parent().parent().parent().parent().toggle();
}
}
);
}
Then go into your template.php file and add this.
<?php
$theme_path = drupal_get_path('theme', 'your_admin_theme');
drupal_add_js($theme_path .'/js/theme_list.js', 'theme');
?>
A little hacky but should work.
Preview Your Theme Styles
Posted May 13, 2008 by Adam MooreCategories: Drupal, PHP, Templates
I was working on creating a preview window in the theme settings page for a theme I was implementing. See Garlands preview for an idea of what I’m talking about. It was a simple idea that the user would choose the style they wanted of that theme and it would update an image on that page that would show the preview of that style.
Here is how I accomplished it. Getting the paths to the theme I am configuring was hard to find. I am using a hacky solution that probably could be done better. Please tell me if you know how to do it better.
First, here is the layout of my theme folder.
theme-
|- css
| |- color
| | |- black.css
| | |- blue.css
| |
| |- style.css
|
|- images
| |- black
| | |- header.png
| | |- screenshot.png
| |
| |- blue
| | |- header.png
| | |- screenshot.png
|
|- js
|- page.tpl.php
|- template.php
|- theme.info
|- theme-settings.php
|- screenshot.png
The screenshot.png that is in the image folder will be the one that will show on the preview window. Create a theme-settings.php file and put this code in it.
<?php
function phptemplate_settings($saved_settings) {
//Set the default style
$defaults = array(
'my_theme_style' => 'gray',
);
$settings = array_merge($defaults, $saved_settings);
//Here is the hacky code. It get's all the theme's info.
$themes = list_themes();
//Then grabs the information for just our theme.
$theme_object = $themes['my_theme'];
//We specifically grab the .info file, remove the my_theme.info from the end and
//then we add base_path to the beginning to give us the theme path.
$theme_path = base_path() . rtrim($theme_object->filename,'my_theme.info');
//Create a form item that just prints out our javascript code. This code updates
//the image when the select box is changed.
$form['my_theme_js'] = array(
'#value' =>'<script type="text/javascript">
function updatePreview(style){ document.getElementById("my_theme_preview").src="'. $theme_path .'images/" + style + "/screenshot.png";}</script>',
);
//Create our select box with an onChange attribute that runs our js code.
$form['my_theme_style'] = array(
'#type' => 'select',
'#title' => t('Style'),
'#default_value' => $settings['my_theme_style'],
'#options' => array(
'black' => t('Black'),
'blue' => t('Blue'),
),
'#attributes' => array('onChange' => 'updatePreview(this.value)'),
);
//This creates a form item for our preview. It prints out the img tag along with our
//current theme image.
$form['my_theme_preview'] = array(
'#type' => 'item',
'#title' => t('Preview'),
'#value' => '<img style="border:1px solid #999;" src="'. $theme_path .'images/'. $settings['my_theme_style'] .'/screenshot.png" alt="" />',
);
return $form;
}
Now that we have that created we are ready to test the preview function. As long as you have built your theme with the layout that I have you should be able to change styles and the preview should update.
Multisite installation steps Drupal
Posted December 14, 2007 by Adam MooreCategories: Drupal, Multisite, PHP
- Create a database for your template site.
- Copy the drupal files to your chosen location.
- Install drupal according to the main instructions.
- Export the tables and data of your new installation.
- Open up the exported sql file and make sure there isn’t a create database operation.
This is how you will set up each additional site.
- In the database create a new db for your new site. Keep in mind the user that can access that db.
- Import your template sql file you exported earlier.
- In the sites folder copy the default folder and paste it in the same folder renaming it to yoursite.com So if your site is happycow.com you would name the folder happycow.com
- In that folder open up settings.php and fill in the database access information. For example if my username was admin, my password was monkey, and my db was happycow I would put: mysql://admin:monkey@localhost/happycow This is assuming that the database is on the same server as the drupal installation.
- Go to your new website, in this case happycow.com, and login using the same admin username and password you made in the template site.
- Go to Administer->Site configuration->File System and change the File System Path to a location that is specific for that website.
Drupal Facebook CiviCRM
Posted October 23, 2007 by Adam MooreCategories: Drupal, Modules, Work
Wow these things can get complicated. My requirements are Drupal +casAuth or ldap Auth +normal account creation +facebook +CiviCRM Anybody see any possible user management issues with this? I know I do. Not quite sure what to do about managing users in this scenario.
Drupal CCK and Views Tutorial
Posted October 18, 2007 by Adam MooreCategories: Drupal, Modules
I found this tutorial extremely helpful in learning about CCK and views. Give it a shot if you are having problems with understanding what everyone is so excited about cck and views.
http://learn.awakenedvoice.com/2007/07/30/drupal-cck-and-views-tutorial/
Drupal Modules Needed For Current Project
Posted October 15, 2007 by Adam MooreCategories: Drupal, Modules, Work
My Ideal Software Development App
Posted October 5, 2007 by Adam MooreCategories: PHP, Work
I have been looking for the perfect community development app.
Here are my requirements.
- Create Multiple projects.
- Blog w/ standard api so i can use ScribeFire to post to the blog.
- Subversion browsing and repository creation.
- Ticket Management
- Task Management
- File Management
- Wiki
- Open Source
- PHP for easy installation and portability.
If you happen to find an app that fits the bill please inform me.
How Composer-NVU-KompoZer is a story of open source success.
Posted October 1, 2007 by Adam MooreCategories: PHP, Web Design
I learned today that NVU has been picked up bug fixed and rebadged as KompoZer. I’m sure, with how this product has been having a tough time getting off the ground, that people would be hard pressed to call this a success. But I think it is and here is why.
Open Source Builds Momentum
People have followed these products through their iterations. They have learned to love how this works and how easy it is for them to edit a web page. Imagine this is a closed source product. The project would have died with Composer and I think more people came on board with the product when it hit NVU. As Kompozer picks it up and starts working on it there will be more people wanting to use it.
Projects Don’t Die, They Just Multiply
(Any guesses on the movie reference?) Because Composer was open sourced it has allowed these products to continue to be open sourced. That means developers that still want to hack on this can. They can user their talents to make it better. They can learn from past mistakes and move the product beyond the scope the other projects meant it for. This happens all the time. I don’t know how many times I’ve been looking for how to do things and the best place I found the code is in a dead open source project. So some of their code gets assimilated into mine. Resistance is futile.
It Shows Us Where Some Pitfalls Occur
Now this isn’t really a success, but one place that I feel Open Source has a hard time figuring out is Trademarks. Really a more consistent naming would have made it an even more successful move. That said how do we pass along the naming when a project becomes dead, or we think it has. You can’t just assume you can have the name because you took the code, the project might not be dead even though you think it is. I think as an open source citizen you need to be aware that when your project becomes dead someone might want to pick it up. If they do and you like what they are doing make the effort to offer them the rights to the trademark. What the heck are you going to use it for? They might not want it, but it’s at least made available.
All in all I wish the best for this project and I hope that they will continue to make a great product.
links for 2007-09-29
Posted September 29, 2007 by Adam MooreCategories: Del.icio.us
-
List of projects at drupal
