Copy Source | Copy HTML /** <br/> * Implementation of hook_menu(). <br/> */ function ivt_header_menu() { $items [ 'admin/settings/ivt_header_settings' ] = array ( 'title' => t( 'IVT Header Settings' ), 'page callback' => 'drupal_get_form' , 'page arguments' => array ( '_ivt_header_settings_form' ), 'access arguments' => array ( 'access administration pages' ), 'type' => MENU_NORMAL_ITEM, ); return $items ; }
Copy Source | Copy HTML /** <br/> * Implementation of hook_menu(). <br/> */ function ivt_header_menu() { $items [ 'admin/settings/ivt_header_settings' ] = array ( 'title' => t( 'IVT Header Settings' ), 'page callback' => 'drupal_get_form' , 'page arguments' => array ( '_ivt_header_settings_form' ), 'access arguments' => array ( 'access administration pages' ), 'type' => MENU_NORMAL_ITEM, ); return $items ; }
Copy Source | Copy HTML /** <br/> * Implementation of hook_menu(). <br/> */ function ivt_header_menu() { $items [ 'admin/settings/ivt_header_settings' ] = array ( 'title' => t( 'IVT Header Settings' ), 'page callback' => 'drupal_get_form' , 'page arguments' => array ( '_ivt_header_settings_form' ), 'access arguments' => array ( 'access administration pages' ), 'type' => MENU_NORMAL_ITEM, ); return $items ; }
Copy Source | Copy HTML /** <br/> * Implementation of hook_menu(). <br/> */ function ivt_header_menu() { $items [ 'admin/settings/ivt_header_settings' ] = array ( 'title' => t( 'IVT Header Settings' ), 'page callback' => 'drupal_get_form' , 'page arguments' => array ( '_ivt_header_settings_form' ), 'access arguments' => array ( 'access administration pages' ), 'type' => MENU_NORMAL_ITEM, ); return $items ; }
Copy Source | Copy HTML /** <br/> * Implementation of hook_menu(). <br/> */ function ivt_header_menu() { $items [ 'admin/settings/ivt_header_settings' ] = array ( 'title' => t( 'IVT Header Settings' ), 'page callback' => 'drupal_get_form' , 'page arguments' => array ( '_ivt_header_settings_form' ), 'access arguments' => array ( 'access administration pages' ), 'type' => MENU_NORMAL_ITEM, ); return $items ; }
Copy Source | Copy HTML /** <br/> * Implementation of hook_menu(). <br/> */ function ivt_header_menu() { $items [ 'admin/settings/ivt_header_settings' ] = array ( 'title' => t( 'IVT Header Settings' ), 'page callback' => 'drupal_get_form' , 'page arguments' => array ( '_ivt_header_settings_form' ), 'access arguments' => array ( 'access administration pages' ), 'type' => MENU_NORMAL_ITEM, ); return $items ; }
Copy Source | Copy HTML /** <br/> * Implementation of hook_menu(). <br/> */ function ivt_header_menu() { $items [ 'admin/settings/ivt_header_settings' ] = array ( 'title' => t( 'IVT Header Settings' ), 'page callback' => 'drupal_get_form' , 'page arguments' => array ( '_ivt_header_settings_form' ), 'access arguments' => array ( 'access administration pages' ), 'type' => MENU_NORMAL_ITEM, ); return $items ; }
Copy Source | Copy HTML /** <br/> * Implementation of hook_menu(). <br/> */ function ivt_header_menu() { $items [ 'admin/settings/ivt_header_settings' ] = array ( 'title' => t( 'IVT Header Settings' ), 'page callback' => 'drupal_get_form' , 'page arguments' => array ( '_ivt_header_settings_form' ), 'access arguments' => array ( 'access administration pages' ), 'type' => MENU_NORMAL_ITEM, ); return $items ; }
Copy Source | Copy HTML /** <br/> * Implementation of hook_menu(). <br/> */ function ivt_header_menu() { $items [ 'admin/settings/ivt_header_settings' ] = array ( 'title' => t( 'IVT Header Settings' ), 'page callback' => 'drupal_get_form' , 'page arguments' => array ( '_ivt_header_settings_form' ), 'access arguments' => array ( 'access administration pages' ), 'type' => MENU_NORMAL_ITEM, ); return $items ; }
Copy Source | Copy HTML /** <br/> * Implementation of hook_menu(). <br/> */ function ivt_header_menu() { $items [ 'admin/settings/ivt_header_settings' ] = array ( 'title' => t( 'IVT Header Settings' ), 'page callback' => 'drupal_get_form' , 'page arguments' => array ( '_ivt_header_settings_form' ), 'access arguments' => array ( 'access administration pages' ), 'type' => MENU_NORMAL_ITEM, ); return $items ; }
Copy Source | Copy HTML /** <br/> * Implementation of hook_menu(). <br/> */ function ivt_header_menu() { $items [ 'admin/settings/ivt_header_settings' ] = array ( 'title' => t( 'IVT Header Settings' ), 'page callback' => 'drupal_get_form' , 'page arguments' => array ( '_ivt_header_settings_form' ), 'access arguments' => array ( 'access administration pages' ), 'type' => MENU_NORMAL_ITEM, ); return $items ; }
Copy Source | Copy HTML /** <br/> * Implementation of hook_menu(). <br/> */ function ivt_header_menu() { $items [ 'admin/settings/ivt_header_settings' ] = array ( 'title' => t( 'IVT Header Settings' ), 'page callback' => 'drupal_get_form' , 'page arguments' => array ( '_ivt_header_settings_form' ), 'access arguments' => array ( 'access administration pages' ), 'type' => MENU_NORMAL_ITEM, ); return $items ; }
Copy Source | Copy HTML
- function _ivt_header_settings_form () {
- $ form [ '#attributes' ] [ 'enctype' ] = 'multipart / form-data' ;
- $ form [ 'header_images_del' ] = array (
- '#type' => 'checkboxes' ,
- '#title' => t ( 'Delete images' ),
- '#options' => variable_get ( 'ivt_header_images' , array ()),
- );
- $ form [ 'header_images_upload' ] = array (
- '#type' => 'file' ,
- '#title' => t ( 'Attach new image' ),
- );
- $ form [ 'submit' ] = array (
- '#type' => 'submit' ,
- '#value' => t ( 'Go!' )
- );
- return $ form ;
- }
Copy Source | Copy HTML
- function _ivt_header_settings_form_validate ( $ form , & $ form_state ) {
- if ( isset ( $ form [ 'header_images_upload' ])) {
- // validation for file extension
- $ validators = array ( 'file_validate_extensions' => array ( 'png' ));
- // folder where the file will be loaded
- $ dir = file_directory_path (). '/ headers' ;
- // check if the directory exists. if it is not there, it will be created
- if (file_check_directory ( $ dir , 1 )) {
- // load the file
- $ file = file_save_upload ( 'header_images_upload' , $ validators , $ dir );
- // add new file field to $ form_state
- if ( $ file ) $ form_state [ 'values' ] [ 'header_image_file' ] = $ file ;
- }
- }
- }
Copy Source | Copy HTML
- function _ivt_header_settings_form_submit ( $ form , & $ form_state ) {
- $ image_file = $ form_state [ 'values' ] [ 'header_image_file' ];
- $ images_del = $ form_state [ 'values' ] [ 'header_images_del' ];
- $ images_del = array_filter ( $ images_del );
- // get the list of already uploaded files
- $ header_images = variable_get ( 'ivt_header_images' , array ());
- // if during submission a file was selected for download
- if ( $ image_file ) {
- // add it to our list
- $ header_images [ $ image_file -> fid] = l ( $ image_file -> filename, $ image_file -> filepath);
- drupal_set_message (t ( 'Image% has has been uploaded!' , array ( '% filename' => $ image_file -> filename)));
- }
- // if files were deleted during submission
- if ( $ images_del ) {
- // run through all files
- foreach ( $ images_del as $ fid ) {
- // load the file from the database
- $ sql_file = db_fetch_object (db_query ( "SELECT filepath, filename FROM files WHERE fid = '% s'" , $ fid ));
- // delete the file from the database
- db_query ( 'DELETE FROM {files} WHERE fid =% d' , $ fid );
- // delete the file
- file_delete ( $ sql_file -> filepath);
- // delete the file from our list
- unset ( $ header_images [ $ fid ]);
- drupal_set_message (t ( 'Image% has has been removed!' , array ( '% filename' => $ sql_file -> filename)));
- }
- }
- // save our list
- variable_set ( 'ivt_header_images' , $ header_images );
- }
Copy Source | Copy HTML
- function ivt_header_get_image ( $ fid = null ) {
- global $ base_url ;
- // if there is no argument, then take arbitrarily
- if (! $ fid ) {
- // load the list
- $ header_images = variable_get ( 'ivt_header_images' , array ());
- // take a random
- $ fid = array_rand ( $ header_images );
- }
- // get the path to the image
- $ sql_file = db_fetch_object (db_query ( "SELECT filepath FROM files WHERE fid = '% s'" , $ fid ));
- $ filepath = $ sql_file -> filepath;
- $ image_html = "<img src = '" . $ base_url . '/' . $ filepath . "'/>" ;
- // return the image
- return $ header_images ? $ image_html : '' ;
- }
Source: https://habr.com/ru/post/97596/
All Articles