summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tabbed_block.module159
1 files changed, 82 insertions, 77 deletions
diff --git a/tabbed_block.module b/tabbed_block.module
index ac74525..8b0f1fb 100644
--- a/tabbed_block.module
+++ b/tabbed_block.module
@@ -1,5 +1,9 @@
<?php
+// $Id$
+
/**
+ * @file
+ *
* author:joe tsui
* email:joetsuihk@gmail.com
* homepage/blog: http://www.joetsuihk.com
@@ -50,42 +54,43 @@
* $block['subject']: subject of the block
* $block['content']: content of the block
*/
-function tabbed_block_block( $op="list" , $module_delta=0 ){
+function tabbed_block_block( $op="list" , $module_delta=0 ) {
static $core_sent;
$path = drupal_get_path('module', 'tabbed_block');
- if ( !$core_sent ){
+ if ( !$core_sent ) {
//include js files
//tabs
//ajax for this block
- drupal_add_js( $path."/tabbed_block.js" );
+ drupal_add_js( $path ."/tabbed_block.js" );
}
- if ( $op == "list" ){
+ if ( $op == "list" ) {
$list = variable_get( 'tabbed_block_list', NULL );
- if ( $list ){
- foreach ( $list as $block_key => $block_name ){
+ if ( $list ) {
+ foreach ( $list as $block_key => $block_name ) {
//TODO: change the display name
- $blocks[$block_key]['info'] = t("Tabbed Block").$block_key;
+ $blocks[$block_key]['info'] = t("Tabbed Block") . $block_key;
}
return $blocks;
}
- }else if( $op == "view" ){
+ }
+ else if ( $op == "view" ) {
//css for this block module
drupal_add_css($path .'/tabbed_block.css');
- drupal_add_js("var base_path = ".drupal_to_js(base_path()) , "inline" );
+ drupal_add_js("var base_path = ". drupal_to_js(base_path()) , "inline" );
//get current settings
- $settings = variable_get( 'tabbed_block_settings'.$module_delta , NULL);
+ $settings = variable_get( 'tabbed_block_settings'. $module_delta , NULL);
//if there is settings:
- if ( $settings ){
+ if ( $settings ) {
//currently do not use subject for this block, may override in config of block inside drupal
//TODO: enable name suuply in tabbed_block_list(v1.0+)
$block['subject'] = "";
@@ -94,12 +99,12 @@ function tabbed_block_block( $op="list" , $module_delta=0 ){
$i = 0;
$tab_subject = "<ul>";
$tab_content = "";
- foreach ( $settings as $conf ){
+ foreach ( $settings as $conf ) {
list( $name , $delta, $delta2) = explode( "-" , $conf );
- if ( !empty($delta2) ){
- $delta = $delta."-".$delta2;
+ if ( !empty($delta2) ) {
+ $delta = $delta ."-". $delta2;
}
//use this function to get the block content,
@@ -109,37 +114,37 @@ function tabbed_block_block( $op="list" , $module_delta=0 ){
//tab headers
//catch potential empty block, redirect user to overide title
- if ( $temp->subject ){
- $tab_subject .= "<li><a href='#' id='fragment".$module_delta."-".$i."'>".$temp->subject."</a></li>";
+ if ( $temp->subject ) {
+ $tab_subject .= "<li><a href='#' id='fragment". $module_delta."-". $i."'>". $temp->subject."</a></li>";
//tabe content
- if ( $temp->content ){
- $tab_content .= "<div id='content-fragment".$module_delta."-".$i."'>".$temp->content."</div>";
+ if ( $temp->content ) {
+ $tab_content .= "<div id='content-fragment". $module_delta."-". $i."'>". $temp->content."</div>";
}else{
- $tab_content .= "<div id='content-fragment".$module_delta."-".$i."'>Nothing here.</div>";
+ $tab_content .= "<div id='content-fragment". $module_delta."-". $i."'>Nothing here.</div>";
}
}else{
- $tab_subject .= "<li><a href='#' id='fragment".$module_delta."-".$i."'>Error! click here!</a></li>";
- $tab_content .= "<div id='content-fragment".$module_delta."-".$i."'>".l("Please config the tab title here." , "admin/build/block/configure/".$name."/".$delta)."</div>";
+ $tab_subject .= "<li><a href='#' id='fragment". $module_delta."-". $i."'>Error! click here!</a></li>";
+ $tab_content .= "<div id='content-fragment". $module_delta."-". $i."'>".l("Please config the tab title here." , "admin/build/block/configure/". $name."/". $delta) ."</div>";
}
$i++;
}
$tab_subject .= "</ul>";
- }elseif( !variable_get( 'tabbed_block_list' , NULL) ){
+ }elseif ( !variable_get( 'tabbed_block_list' , NULL) ) {
$block['subject'] = "Tabbed Block Block";
$tab_subject = '';
- $tab_content = 'No tabbed Block exists. <a href="'.base_path().'admin/settings/tabbed_block/add">Add</a>';
+ $tab_content = 'No tabbed Block exists. <a href="'.base_path() .'admin/settings/tabbed_block/add">Add</a>';
}else{
//if settings exists
$block['subject'] = "Tabbed Block Block";
$tab_subject = '';
- $tab_content = l("Configure this block" , base_path().'admin/settings/tabbed_block/edit/'.$delta);
+ $tab_content = l("Configure this block" , base_path() .'admin/settings/tabbed_block/edit/'. $delta);
}
//tab wrapper needed for tab
$block['content'] = "<div class='tabbed-block'>";
- $block['content'] .= $tab_subject.$tab_content;
+ $block['content'] .= $tab_subject. $tab_content;
$block['content'] .= "</div>";
return $block;
@@ -163,25 +168,25 @@ function tabbed_block_js() {
* from menu: admin/settings/tabbed_block/list
*
*/
-function tabbed_block_list(){
+function tabbed_block_list() {
$output = '';
$header = array( 'Name' , 'Operation' );
$list = variable_get( 'tabbed_block_list' , NULL );
- if ( $list ){
- foreach ( $list as $block_key => $block_name ){
+ if ( $list ) {
+ foreach ( $list as $block_key => $block_name ) {
$rows[] = array(
- 'tabbed_block'.$block_key ,
- l("edit","admin/settings/tabbed_block/edit/".$block_key)." ".l("delete","admin/settings/tabbed_block/delete/".$block_key) );
+ 'tabbed_block'. $block_key ,
+ l("edit","admin/settings/tabbed_block/edit/". $block_key) ." ".l("delete","admin/settings/tabbed_block/delete/". $block_key) );
}
- $output .= '<p>You may add new block in the above '.l('Add tab','admin/settings/tabbed_block/add').'.</p>';
+ $output .= '<p>You may add new block in the above '.l('Add tab','admin/settings/tabbed_block/add') .'.</p>';
- $output .= '<p>Remember to place the tabbed block to target regions in '.l('block setting page','admin/build/block').'.</p>';
+ $output .= '<p>Remember to place the tabbed block to target regions in '.l('block setting page','admin/build/block') .'.</p>';
$output .= theme('table', $header, $rows);
}else{
- $output = 'No Tabbed block configured<br />Press '.l('here','admin/settings/tabbed_block/add').' to add a new tabbed block.';
+ $output = 'No Tabbed block configured<br />Press '.l('here','admin/settings/tabbed_block/add') .' to add a new tabbed block.';
}
return $output;
@@ -192,7 +197,7 @@ function tabbed_block_list(){
* register both ajax request path and settings menu path
*
*/
-function tabbed_block_menu(){
+function tabbed_block_menu() {
$items = array();
//register PHP handler for ajax request
@@ -237,7 +242,7 @@ function tabbed_block_menu(){
);
$items['admin/settings/tabbed_block/delete/%'] = array(
- 'title' => t('Are you sure you want to delete Tabbed block ').$delta."?",
+ 'title' => t('Are you sure you want to delete Tabbed block ') . $delta."?",
'access arguments' => array('administer blocks'),
'page callback' => 'drupal_get_form',
'page arguments' => array('tabbed_block_delete',4),
@@ -279,12 +284,12 @@ function tabbed_block_output_content_block($conf) {
$block->module = $conf['module'];
$block->delta = $conf['delta'];
- $temp = db_fetch_array(db_query("SELECT title FROM {blocks} WHERE theme = '".$theme."' AND module = '".$conf['module']."' AND delta ='".$conf['delta']."'" ) );
- if ( $temp['title'] ){
+ $temp = db_fetch_array(db_query("SELECT title FROM {blocks} WHERE theme = '". $theme."' AND module = '". $conf['module']."' AND delta ='". $conf['delta']."'" ) );
+ if ( $temp['title'] ) {
$block->subject = $temp['title'];
}
- if ( !$block->subject ){
+ if ( !$block->subject ) {
$temp = block_box_get( $conf['delta'] );
$block->subject = $temp['title'];
}
@@ -303,7 +308,7 @@ function tabbed_block_output_content_block($conf) {
} else {
$page_match = TRUE;
}
- if($page_match) {
+ if ($page_match) {
$output = $block;
}
return $output;
@@ -313,9 +318,9 @@ function tabbed_block_output_content_block($conf) {
* function for add tabbed block
*
*/
-function tabbed_block_add( ){
+function tabbed_block_add( ) {
$list = variable_get( 'tabbed_block_list' , NULL );
- if ( $list ){
+ if ( $list ) {
ksort( $list );
$max_key = $list[count($list)];
$list[] = $max_key+1 ;
@@ -338,13 +343,13 @@ function tabbed_block_delete( $form_state ) {
$form['id'] = array('#type' => 'hidden', '#value' => arg(4));
$form['warning'] = array(
- '#value' => t('Please remove this block from sidebars before delete it')."<br />",
+ '#value' => t('Please remove this block from sidebars before delete it') ."<br />",
'#prefix' => '<p class="tabbed_block_error">',
'#subfix' => '</p>',
);
$form['help'] = array(
- '#value' => t('This action cannot be undone.')."<br />",
+ '#value' => t('This action cannot be undone.') ."<br />",
'#prefix' => '<p>',
'#subfix' => '</p>',
);
@@ -355,7 +360,7 @@ function tabbed_block_delete( $form_state ) {
);
$form['cancel'] = array(
- '#value' => "<a href='../'>".t('Cancel')."</a>",
+ '#value' => "<a href='../'>".t('Cancel') ."</a>",
);
return $form;
@@ -365,7 +370,7 @@ function tabbed_block_delete_submit( $form, &$form_state ) {
$list = variable_get( 'tabbed_block_list' , NULL );
unset($list[arg(4)]);
variable_set( 'tabbed_block_list' , $list );
- variable_del( 'tabbed_block_settings'.$form_state['values']['id'] );
+ variable_del( 'tabbed_block_settings'. $form_state['values']['id'] );
$form_state['redirect'] = 'admin/settings/tabbed_block';
drupal_set_message(t('The block had been deleted.'));
@@ -383,7 +388,7 @@ function tabbed_block_delete_submit( $form, &$form_state ) {
*
* @return $form
*/
-function tabbed_block_admin_settings( $form_states ){
+function tabbed_block_admin_settings( $form_states ) {
//get args passed in, to find the delta of this editing block
$module_delta = arg(4);
@@ -458,7 +463,7 @@ function tabbed_block_admin_settings( $form_states ){
return $form;
}
-function tabbed_block_form_alter(&$form, &$form_state, $form_id){
+function tabbed_block_form_alter(&$form, &$form_state, $form_id) {
/*
print("<pre>");
@@ -467,22 +472,22 @@ function tabbed_block_form_alter(&$form, &$form_state, $form_id){
exit();
*/
- if( $form_id == 'tabbed_block_admin_settings' ){
+ if ( $form_id == 'tabbed_block_admin_settings' ) {
//if this is from a submit
- if ( $form_state['post']['exists'] ){
+ if ( $form_state['post']['exists'] ) {
- for( $i=0 ; $i < count($form_state['post']['exists']) ; $i++ ){
+ for( $i=0 ; $i < count($form_state['post']['exists']) ; $i++ ) {
$block_list[] = $form_state['post']['exists'][$i]['hidden'];
- if ( $form_state['post']['exists'][$i]['up'] ){
+ if ( $form_state['post']['exists'][$i]['up'] ) {
$op = 'up';
$key = $i;
- }elseif($form_state['post']['exists'][$i]['down']){
+ }elseif ($form_state['post']['exists'][$i]['down']) {
$op = 'down';
$key = $i;
- }elseif($form_state['post']['exists'][$i]['delete']){
+ }elseif ($form_state['post']['exists'][$i]['delete']) {
$op = 'delete';
$key = $i;
}
@@ -490,32 +495,32 @@ function tabbed_block_form_alter(&$form, &$form_state, $form_id){
}else{
//get current setting from DB
$module_delta = arg(4);
- if ( $temp = variable_get('tabbed_block_settings'.$module_delta, NULL) ){
+ if ( $temp = variable_get('tabbed_block_settings'. $module_delta, NULL) ) {
$block_list = $temp;
}
}
//process add block buttom
- if ( $form_state['post']['op'] == t('Add block') ){
+ if ( $form_state['post']['op'] == t('Add block') ) {
//insert the selected block into settings
$block_list[] = $form_state['post']['block'];
drupal_set_message("Added successfully. <br/>Note that <b>this configuration will not be saved until you press the save buttom</b>");
- }elseif( $form_state['post']['op'] == t('Delete all block') ){
+ }elseif ( $form_state['post']['op'] == t('Delete all block') ) {
$block_list = array();
drupal_set_message("All Blocks deleted successfully. <br/>Note that <b>this configuration will not be saved until you press the save buttom</b>");
- }elseif($op == 'delete') {
+ }elseif ($op == 'delete') {
array_splice( $block_list , $key , 1 );
drupal_set_message("Deleted successfully. <br/>Note that <b>this configuration will not be saved until you press the save buttom</b>");
- }elseif ( $op == "up" ){
+ }elseif ( $op == "up" ) {
//find the block need to move
$move_block = array_slice( $block_list , $key , 1 );
@@ -528,7 +533,7 @@ function tabbed_block_form_alter(&$form, &$form_state, $form_id){
drupal_set_message("Move up successfully. <br/>Note that <b>this configuration will not be saved until you press the save buttom</b>");
- }elseif ( $op == "down" ){
+ }elseif ( $op == "down" ) {
//find the block need to move
$move_block = array_slice( $block_list , $key , 1 );
@@ -545,12 +550,12 @@ function tabbed_block_form_alter(&$form, &$form_state, $form_id){
//generate an exists block list, with their names, position, and operation buttoms
- if ( $block_list ){
+ if ( $block_list ) {
//init count of blocks
$max_i = count( $block_list )-1;
//generate form for each $block_list
- for ( $i = 0 ; $i < count($block_list) ; $i++ ){
+ for ( $i = 0 ; $i < count($block_list) ; $i++ ) {
$block = $block_list[$i];
list( $name , $delta ) = explode( "-" , $block , 2 );
@@ -562,18 +567,18 @@ function tabbed_block_form_alter(&$form, &$form_state, $form_id){
//delete buttom
$form['exists'][$i]['delete'] = array(
'#type' => 'image_button',
- '#src' => drupal_get_path('module','tabbed_block').'/user-trash.png',
- '#value' => 'delete#'.$i, // original value of button text
+ '#src' => drupal_get_path('module','tabbed_block') .'/user-trash.png',
+ '#value' => 'delete#'. $i, // original value of button text
'#executes_submit_callback' => FALSE,
'#prefix' => '<div>',
);
//move up buttom
- if ( $i != 0 ){
+ if ( $i != 0 ) {
$form['exists'][$i]['up'] = array(
'#type' => 'image_button',
- '#src' => drupal_get_path('module','tabbed_block').'/go-up.png',
- '#value' => 'up#'.$i, // original value of button text
+ '#src' => drupal_get_path('module','tabbed_block') .'/go-up.png',
+ '#value' => 'up#'. $i, // original value of button text
'#executes_submit_callback' => FALSE,
);
}else{
@@ -582,11 +587,11 @@ function tabbed_block_form_alter(&$form, &$form_state, $form_id){
);
}
//move down buttom
- if ( $i != $max_i ){
+ if ( $i != $max_i ) {
$form['exists'][$i]['down'] = array(
'#type' => 'image_button',
- '#src' => drupal_get_path('module','tabbed_block').'/go-down.png',
- '#value' => 'down#'.$i, // original value of button text
+ '#src' => drupal_get_path('module','tabbed_block') .'/go-down.png',
+ '#value' => 'down#'. $i, // original value of button text
'#executes_submit_callback' => FALSE,
);
}else{
@@ -633,7 +638,7 @@ function tabbed_block_form_alter(&$form, &$form_state, $form_id){
* it is used to prevent double process of thr form, if op is not save
*
*/
-function tabbed_block_admin_settings_validate( $form, &$form_state ){
+function tabbed_block_admin_settings_validate( $form, &$form_state ) {
/*
print("<pre>");
@@ -650,7 +655,7 @@ function tabbed_block_admin_settings_validate( $form, &$form_state ){
*
* it is only called by tabbed_block_admin_setting(), as a normal function call.
*/
-function tabbed_block_admin_settings_submit( $form, &$form_state ){
+function tabbed_block_admin_settings_submit( $form, &$form_state ) {
//process submit
$variable = 'tabbed_block_settings'.arg(4);
@@ -665,11 +670,11 @@ function tabbed_block_admin_settings_submit( $form, &$form_state ){
*/
//init exists blocks from POST instead of database settings
- if ( $form_state['values']['exists'] ){
- for( $i=0 ; $i < count($form_state['values']['exists']) ; $i++ ){
+ if ( $form_state['values']['exists'] ) {
+ for( $i=0 ; $i < count($form_state['values']['exists']) ; $i++ ) {
$block_list[] = $form_state['values']['exists'][$i]['hidden'];
}
- if ($form_state['values']['op'] == t('Save') ){
+ if ($form_state['values']['op'] == t('Save') ) {
variable_set( $variable , $block_list );
drupal_set_message( "Blocks saved sucessfully." );
}
@@ -691,14 +696,14 @@ function tabbed_block_admin_settings_submit( $form, &$form_state ){
*
* @return $array: the sortted array
*/
-function array_move( $in_array , $insert , $new_key ){
+function array_move( $in_array , $insert , $new_key ) {
$new_array = array();
reset( $in_array );
//as there is one more element have to insert, so $i<= count
- for ( $i = 0 ; $i <= count( $in_array ) ; $i++ ){
- if ( $i == $new_key ){
+ for ( $i = 0 ; $i <= count( $in_array ) ; $i++ ) {
+ if ( $i == $new_key ) {
$new_array[] = $insert;
}else{
$new_array[] = current( $in_array );