Index: image_title.info =================================================================== --- image_title.info (revision 307) +++ image_title.info (working copy) @@ -1,10 +1,5 @@ -; $Id: image_title.info,v 1.1 2008/08/24 03:52:45 dksdev01 Exp $ name = Image Title description = Allows to upload nice image to replace text version of node title package = Other -version = VERSION -; Information added by drupal.org packaging script on 2008-09-30 -version = "5.x-1.x-dev" -project = "image_title" -datestamp = "1222733187" +core = 6.x Index: image_title.install =================================================================== --- image_title.install (revision 307) +++ image_title.install (working copy) @@ -4,27 +4,46 @@ /** * Implementation of hook_install(). */ -function image_title_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {image_title} ( - nid int unsigned NOT NULL default '0', - image varchar(225) default NULL, - status int(1) NOT NULL, - KEY imgtype (nid, image) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + function image_title_install(){ + // create tables + drupal_install_schema('image_title'); + } - break; - case 'pgsql': - // need support - break; - } -} +/** + * Implementation of hook_schema(). + */ + function image_title_schema(){ + $schema['image_title'] = array( + 'description' => t('Table for holding title images attached to nodes'), + 'fields' => array( + 'nid' => array( + 'description' => t('The primary identifier for a node'), + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'image' => array( + 'description' => t('The image attached to the title of the node'), + 'type' => 'varchar', + 'length' => 225, + 'default' => '', + ), + 'status' => array( + 'description' => t('status of the image title, on or off'), + 'type' => 'int', + 'not null' => TRUE, + ), + ), + 'primary key' => array('nid', 'image'), + ); + return $schema; + } + /** * Implementation of hook_uninstall(). */ function image_title_uninstall() { - db_query('DROP TABLE {image_title}'); + // remove tables + drupal_uninstall_schema('image_title'); } \ No newline at end of file Index: image_title.module =================================================================== --- image_title.module (revision 307) +++ image_title.module (working copy) @@ -1,68 +1,55 @@ 'radios', - '#title' => t('Default image title'), - '#default_value' => variable_get('image_title_'. $form['#node_type']->type, 0), - '#options' => array(t('Disabled'), t('Enabled')), - '#description' => t('Enable this to have image title for this content type.'), - ); - } - elseif (isset($form['type'])) { - $type = $form['type']['#value']; - } - elseif (isset($form['orig_type'])) { - $type = $form['orig_type']['#value']; - } - else { - return; - } +function image_title_form_alter( &$form, $form_state, $form_id) { + //check user is permitted to create image titles + if (user_access('create image titles')) { - // check node type and match settings - if($form_id == $type .'_node_form' && user_access('add image title') && (variable_get('image_title_'. $type, 0) == 1) ){ - - $form['image_title'] = array( '#type' => 'fieldset', - '#title' => t('Title Image'), - '#weight' => 1, - '#collapsible' => TRUE, - '#collapsed' => TRUE, - ); - $form['image_title']['image_title_upload'] = array( - '#type' => 'file', - '#title' => t('Attach title image'), - '#size' => 40, - ); + // We're only modifying node forms, if the type field isn't set we don't need + // to bother; otherwise, store it for later retrieval. + if (isset($form['type'])) { + $type = $form['type']['#value']; + } + elseif (isset($form['orig_type'])) { + $type = $form['orig_type']['#value']; + } + else { + return; + } + // check node type and match settings + if($form_id == $type .'_node_form' ){ + $form['image_title'] = array( + '#type' => 'fieldset', '#title' => t('Title Image'), '#weight' => 1); + $form['image_title']['image_title_upload'] = array( + '#type' => 'file', + '#title' => t('Attach title image'), + '#size' => 40, + ); - $node = $form['#node']; + $node = $form['#node']; $picture = theme("image_title", $node); $form['image_title']['current_timage'] = array('#value' => $picture); - $form['image_title']['current_timage_v'] = array('#type' => 'checkbox', - '#default_value' => $node->image_title_status, - '#title' => t('Show this image in place of title'), - '#description' => t('Check this box to override title with image uploaded.'), - ); // used as status + $form['image_title']['current_timage_v'] = array( + '#type' => 'checkbox', + '#default_value'=>$node->image_title_status, + '#title' => t('Show this image in place of title'), + '#description' => t('Check this box to override title with image uploaded.') + ); // used as status - $form['#attributes']['enctype'] = 'multipart/form-data'; - + $form['#attributes']['enctype'] = 'multipart/form-data'; + } } - } /** * theming image field for title for node form .. @@ -83,33 +70,46 @@ } /** + * Implementation of hook_theme() + */ +function image_title_theme(){ + return array( + 'image_title' => array( + 'arguments' => array('node' => NULL), + ), + ); +} + +/** * nodeapi to save image for title */ function image_title_nodeapi(&$node, $op, $teaser, $page) { global $form_values; - if( !user_access('add image title') || (variable_get('image_title_'. $node->type, 0) == 0) ) { - return; // do nothing ... - } switch ($op) { case 'validate': $form_values['image_title'] = $node->image_title; - if ($file = file_check_upload('image_title_upload')) { + $validators = array( + 'file_validate_is_image' => array(), + ); + if(!empty($_FILES['files']['name']['image_title_upload'])){ if (!form_get_errors()) { - $path = file_directory_path(); - if ($file1 = file_save_upload('image_title_upload', $path.'/img-title-'. $node->nid .''. $file->filename, 1)) { - $form_values['image_title'] = $file1->filepath; + $path = file_directory_path(); + $fullpath = $path.'/img-title'; + + if ($file = file_save_upload('image_title_upload', $validators = array(), $fullpath, 1)) { + file_set_status($file, FILE_STATUS_PERMANENT); + $form_values['image_title'] = $file->filepath; } else { form_set_error('image_title', t("Failed to upload the image title; the %directory directory doesn't exist or is not writable.", array('%directory' => $path.'/img-title-'. $node->nid))); - } - } - } + } + } + } + break; - break; - case 'load': $image_title = db_fetch_array(db_query('SELECT image, status FROM {image_title} WHERE nid = %d', $node->nid)); @@ -119,19 +119,19 @@ break; case 'insert': - db_query('INSERT INTO {image_title} (nid, image) VALUES (%d, "%s")', $node->nid, $form_values['image_title']); + + db_query('INSERT INTO {image_title} (nid, image,status) VALUES (%d, "%s", %d)', $node->nid, $form_values['image_title'], $node->current_timage_v); break; case 'update': - - if($form_values['current_timage_v']) { - $status = $form_values['current_timage_v']; + if($node->current_timage_v) { + $status = $node->current_timage_v; }else { $status = 0; // fine } // insert update/database here ... - if( $form_values['image_title'] != '' ) { + if(!empty($_FILES['files']['name']['image_title_upload'])){ db_query('DELETE FROM {image_title} WHERE nid = %d', $node->nid); db_query('INSERT INTO {image_title} (nid, image, status) VALUES (%d, "%s", %d)', $node->nid, $form_values['image_title'], $status); }else { @@ -143,35 +143,18 @@ case 'delete': db_query('DELETE FROM {image_title} WHERE nid = %d', $node->nid); break; - - case 'view': // not confident here -- avail for detail page only ... - if( $node->image_title_status == 1 ) { - - if(arg(0) == 'node' && arg(1) != '' && is_numeric(arg(1)) ) { - // add this image to title.. ?? on teaser too ? yes - drupal_set_title(theme('image', $node->image_title, $node->title, $node->title, '', FALSE)); - }else { - // you may use this var in .tpl for customizing - // $node->title = theme('image', $node->image_title, $node->title, $node->title, '', FALSE); - // above can't be done as there is some text restriction... - $node->title = ''; // is it good ?? - $node->content['image_title'] = array( - '#value' => l(theme('image', $node->image_title, $node->title, $node->title, '', FALSE), 'node/'.$node->nid,array(),'','',false,true), - '#weight' => -1, - ); - } - } - break; } } -// view is still need to be updated .. add to ur template -/* add this to ur theme page.tpl.php where title is printed - image_title_status && $node->image_title != '' ) { - echo theme('image', $node->image_title); - }else { - ?> -
- - */ \ No newline at end of file +/** + * function extending the available page variables + */ +function image_title_preprocess_page(&$variables) { + + $thisnode = node_load($variables['node']->nid); + if($thisnode->image_title_status == 1){ + $image = theme('image', $thisnode->image_title, $thisnode->title, $thisnode->title, '', FALSE); + $title = '' . $thisnode->title . '' . $image ; + $variables['title'] = $title; + } +} \ No newline at end of file