January 27, 2009

Media Button in WYSIWYG Module

Filed under: Drupal, PHP — admin @ 11:17 am

We’re implementing the new WYSIWYG Module in Drupal 6, and really digging it.  We are using it with our WYSIWYG Editor of choice: TinyMCE (3.2.1.1).

We noticed, however, as we were setting up the module in Drupal, that our beloved media button was gone. Here’s how we got it back in there:

First, you need to install and setup the module & tinyMCE as detailed in the readme file.  Next, open ‘…modules\wysiwyg\editors\tinymce.inc’

All you have to do is add a few lines of code (around line 472):

‘layer’ => array(
‘path’ => $editor['library path'] .’/plugins/layer’,
‘buttons’ => array(’insertlayer’ => t(’Insert layer’), ‘moveforward’ => t(’Move forward’), ‘movebackward’ => t(’Move backward’), ‘absolute’ => t(’Absolute’)),
‘url’ => ‘http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/layer’,
‘internal’ => TRUE,
‘load’ => TRUE,
),

/*Begin Inserted Lines*/

‘media’ => array(
‘path’ => $editor['library path'] .’/plugins/meda’,
‘buttons’ => array(’media’ => t(’Insert Media’)),
‘url’ => ‘http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/media’,
‘internal’ => TRUE,
‘load’ => TRUE,
),

/*End Inserted Lines*/

‘paste’ => array(
‘path’ => $editor['library path'] .’/plugins/paste’,
‘buttons’ => array(’pastetext’ => t(’Paste text’), ‘pasteword’ => t(’Paste from Word’), ’selectall’ => t(’Select all’)),
‘url’ => ‘http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/paste’,
‘internal’ => TRUE,
‘load’ => TRUE,
),

Now the media button will be available to be selected as an option from your TinyMCE administrator page within drupal.

January 7, 2008

Control Drupal Forum Access by Role

Filed under: Drupal, PHP — Soleer @ 9:56 pm

We are developing an online community with forums which need to be private (only accessed by the members of the community).  Unfortunately, the forum.module for drupal allows anyone with ‘access content’ privileges to access the forums.  Obviously, we want visitors to be able to view the pages and almost all other content, but we want the forums to be private. 

There is a module called Forum Access, which enables great control over forum access, but if used to disable access for visitors and other roles, these users will still see a Forum menu item, and if they click on it they will see a “No Forums Defined” message.  This will undoubtedly give some people the wrong picture.

With 2 simple edits to the forum.module file, we enabled the exact functionality we were looking for: Control Forum Display using Access Roles, and Hide the Forums for those not authorized.

On line 41 of the forum.module file:
‘access’ => user_access(’access forums’), //changed from ‘access content’ to ‘access forums’ <- Our own defined permission

On line 131 of the forum.module file:
return array(’create forum topics’, ‘edit own forum topics’, ‘administer forums’, ‘access forums’); //added ‘access forums’ permission

Now all we have to do is go to: Administer >> User management >> Access control, and select the checkbox next to ‘access forums’ (under forum module) for each of the roles that we want to give forum access to.

December 27, 2007

Get the ID generated from the previous INSERT opereration

Filed under: MySQL, PHP — Soleer @ 4:43 pm

With the PHP function mysql_insert_id( ), you can obtain the previous index generated from an insert operation.

The need for this capability came about when we were generating a MySQL database for invoice storage.  Our database contains an INVOICE table for customer billing information, and an INV_ITEM table for individual items that are included in each order.

 The INVOICE table uses inv_id as an AUTO INCREMENT primary key, and the INV_ITEM uses inv_id as an index value, so the invoice items may be associated with the correct invoice.  All of this worked great, but we needed to send an email with order information, and an order number corresponding to the inv_id so we could access the order easily from the database if need be. 

The answer was to use the mysql_insert_id( ) function immeadiately after the insert statement, which returns the generated ID, which was inv_id in our case.  We then stored the returned ID to a string, and used it where necessary in the rest of our code.

$sql = “INSERT INTO invoices (”.$key_string.”) VALUES (”.$value_string.”)”;
$result = mysql_query($sql) ;
$invoice_id = mysql_insert_id();
if (!$result) {
      die(’Invalid query: ‘ . mysql_error());
}

The result of the previous code was that our values were inserted into the database as required, with the inv_id generated, and then stored into the $invoice_id variable for further use in the code.

December 17, 2007

PHP 4.3: Remove a specific key from an array

Filed under: PHP — Soleer @ 10:43 pm

PHP 5+ provides the built-in function array_diff_key() which can be used to delete a certain key from an array.  Although I’m not proud of it, some of our customers’ sites are still running versions prior to PHP 5.  This is how we delete a specific key from an array in PHP 4+ (4.3).

 Let’s say that I have an array which contains the following:

$my_array = array(”key1″=> “apple”, “key2″ => “orange”, “key3″ => “banana”);

If I wanted to remove the key “key1″, and it’s associated value from the array, there is an array function array_diff_assoc() in PHP 4.3+ which compares 2 arrays, and deletes any key/value combinations from the first array which are present in the second, and returns the resulting array.  The problem is, that the key & value must be the same in both arrays.  This is the statement we used to delete the desired key:

$my_new_array = array_diff_assoc($my_array,array(”key1″=> $my_array["key1"]));

Because we are reading the value of the key, from the desired array, we can be assured that the key/value combinations will match in both arrays, and the result will be a returned array, matching the original $my_array, but with “key1″ => “apple” removed!

 You could also create a function to accomplish this:

function array_remove_key($target_array, $key){

          return array_diff_assoc($target_array,array($key => $target_array[$key]));

}

December 10, 2007

Drupal: Custom Latest Posts

Filed under: Drupal, PHP — Soleer @ 10:29 pm

We’re currently developing a Drupal community website for an up-and-coming society.

On the community front page we wanted to display a list of the most recent forum posts. This can easily be accomplished using the Drupal API, and the forum_block() function, with the parameters ‘view’, and the 0 for most active posts, and 1 for newest post (i.e. forum_block(‘view’,0).

The problem in our situation was that we wanted to be able to customize the output beyond the standard API capabilities. In this case, it is a small customization, but this small customization involved digging deep into the Drupal PHP code. We wanted to display who posted the forum topic.

Here’s what we did:

<?php

/*Display Most Active Forum Posts*/

//sets variable to display 3 most active posts
variable_set(’forum_block_num_0′, ‘3′);

//SQL databse call, copied from forum_block(), added: n.uid which is the database value storing the user id of the poster
$sql = db_rewrite_sql(”SELECT n.nid, n.title, n.uid, l.comment_count, l.last_comment_timestamp FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND n.type = ‘forum’ ORDER BY l.last_comment_timestamp DESC”);

//Get database results, and limit to number of posts defined by forum_block_num
$result = db_query_range($sql, 0, variable_get(’forum_block_num_0′, ‘5′));

//if the result isn’t empty, display the forum topics
if (db_num_rows($result)) {

     //for every row in the database, display the desired output
     while ($node = db_fetch_object($result)) {

           //create a user object, with the uid from the posting
           $user->uid = $node->uid;

           //take the partial user object, load a full user object, and get the username
           $user_name = user_load($user)->name;

           //create a link to the forum node, add ‘posted by’ with poster’s username
           $items[] = l($node->title, ‘node/’. $node->nid, $node->comment_count ? array(’title’ => format_plural($node->comment_count, ‘1 comment’, ‘@count comments’)) : ”).’ posted by: ‘.$user_name;
     }

//format the resulting list and return as content
     $content = theme(’node_list’, $items, $title);
}
echo $content; //return the formatted list of recent topics
?>

Newer Posts »

Who we are

Explore our history and character.

If you've ever been on a blind-date, odds are great that you know how disastrous "jumping before looking" can be. Feel free to do some online stalking here before you contact Soleer.

What We Do

"Girls only want boyfriends who have great skills." -Napoleon Dynamite

While we aren't looking to be your boyfriend and might not have "nunchuku skills," we do offer a number of other services and solutions to assist your organization.

What We’ve Done

As we say in Texas, "This ain't our first rodeo." Take a look at a sampling of some of our masterpieces, from logo design and brochure creation to webpage design and online community development.