/[drupal]/contributions/modules/word2web/word2web.module
ViewVC logotype

Diff of /contributions/modules/word2web/word2web.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.6, Thu Jul 24 15:33:12 2008 UTC revision 1.6.2.1, Wed Jan 14 14:30:08 2009 UTC
# Line 2  Line 2 
2    
3  /*  /*
4   * Author   : Tom MacWright, Young Hahn   * Author   : Tom MacWright, Young Hahn
5   * Revision : $Id$   * Revision : $Id: word2web.module,v 1.6 2008/07/24 15:33:12 tmcw Exp $
6   */   */
7    
8  /**  /**
# Line 15  Line 15 
15  /**  /**
16   * Implementation off hook_menu()   * Implementation off hook_menu()
17   */   */
18  function word2web_menu($may_cache) {  function word2web_menu() {
19    $items = array();    $items = array();
20    if ($may_cache) {  /* TODO
21      $items[] = array(     Non menu code that was placed in hook_menu under the '!$may_cache' block
22        'path' => 'admin/settings/word2web',     so that it could be run during initialization, should now be moved to hook_init.
23        'title' => t('Word2Web Settings'),     Previously we called hook_init twice, once early in the bootstrap process, second
24        'description' => t('Configure word2web nodetypes and settings.'),     just after the bootstrap has finished. The first instance is now called boot
25        'callback' => 'drupal_get_form',     instead of init.
26        'callback arguments' => array('word2web_settings_form'),  
27        'access' => user_access('administer site configuration'),     In Drupal 6, there are now two hooks that can be used by modules to execute code
28      );     at the beginning of a page request. hook_boot() replaces hook_boot() in Drupal 5
29    }     and runs on each page request, even for cached pages. hook_boot() now only runs
30       for non-cached pages and thus can be used for code that was previously placed in
31       hook_menu() with $may_cache = FALSE:
32    
33       Dynamic menu items under a '!$may_cache' block can often be simplified
34       to remove references to arg(n) and use of '%<function-name>' to check
35       conditions. See http://drupal.org/node/103114.
36    
37       The title and description arguments should not have strings wrapped in t(),
38       because translation of these happen in a later stage in the menu system.
39    */
40      $items['admin/settings/word2web'] = array(
41        'title' => 'Word2Web Settings',
42        'description' => 'Configure word2web nodetypes and settings.',
43        'page callback' => 'drupal_get_form',
44        'page arguments' => array('word2web_settings_form'),
45        'access arguments' => array('administer site configuration'),
46      );
47    if (is_numeric(arg(1)) && arg(0) == 'node') {    if (is_numeric(arg(1)) && arg(0) == 'node') {
48      if (variable_get('word2web_images', false)) {      if (variable_get('word2web_images', false)) {
49        $node = node_load(arg(1));        $node = node_load(arg(1));
50        $nodetypes = variable_get('word2web_nodetypes', array());        $nodetypes = variable_get('word2web_nodetypes', array());
51          if ($nodetypes[$node->type]) {          if ($nodetypes[$node->type]) {
52          $items[] = array('path' => 'node/'. arg(1) .'/manage_images',          $items['node/'. '%' .'/manage_images'] = array(
53            'title' => t('Manage Images'),            'title' => 'Manage Images',
54            'callback' => 'drupal_get_form',            'page callback' => 'drupal_get_form',
55            'callback arguments' => array('word2web_manage_images', arg(1)),            'page arguments' => array('word2web_manage_images', arg(1)),
56            'access' => user_access('administer nodes'),            'access arguments' => array('administer nodes'),
57            'type' => MENU_LOCAL_TASK,            'type' => MENU_LOCAL_TASK,
58          );          );
59        }        }
# Line 48  function word2web_menu($may_cache) { Line 65  function word2web_menu($may_cache) {
65  /**  /**
66   * Implementation off hook_form_alter()   * Implementation off hook_form_alter()
67   */   */
68  function word2web_form_alter($form_id, &$form) {  function word2web_form_alter(&$form, &$form_state, $form_id) {
69    $nodetypes = variable_get('word2web_nodetypes', array());    $nodetypes = variable_get('word2web_nodetypes', array());
70    //print_r($form);    //print_r($form);
71    if ($form['#node'] && $nodetypes[$form['#node']->type]) {    if ($form['#node'] && $nodetypes[$form['#node']->type]) {
72      $form['#attributes'] = array('enctype' => "multipart/form-data");      $form['#attributes'] = array('enctype' => "multipart/form-data");
73      $form['#validate']['word2web_validate'] = array();      $form['#validate'][] = 'word2web_validate';
74      $form['word_document'] = array(      $form['word_document'] = array(
75        '#type' => 'file',        '#type' => 'file',
76        '#title' => t('Upload Word document'),        '#title' => t('Upload Word document'),
# Line 116  function word2web_manage_images($nid) { Line 133  function word2web_manage_images($nid) {
133   * @param $form: form values   * @param $form: form values
134   */   */
135    
136  function word2web_manage_images_submit($form_id, $form) {  function word2web_manage_images_submit($form, &$form_state) {
137    $success = true;    $success = true;
138    foreach ($form as $f => $v) {    foreach ($form as $f => $v) {
139      // !== because PHP's type system is weird / sucks      // !== because PHP's type system is weird / sucks
140      if (strpos($f, 'upload') !== false) {      if (strpos($f, 'upload') !== false) {
141        if ($fi = file_check_upload($f)) {  /* TODO Modify the validators array to suit your needs.
142       This array is used in the revised file_save_upload */
143      $validators = array(
144        'file_validate_is_image' => array(),
145        'file_validate_image_resolution' => array('85x85'),
146        'file_validate_size' => array(30 * 1024),
147      );
148    
149      //TODO: check this line
150          if ($fi = file_save_upload($validators)) {
151          $new_id = _word2web_node_image($fi->filepath, $fi->filename);          $new_id = _word2web_node_image($fi->filepath, $fi->filename);
152          if ($new_id == -1) {          if ($new_id == -1) {
153            drupal_set_message("Image files could not be uploaded because the image directory is not configured correctly.");            drupal_set_message("Image files could not be uploaded because the image directory is not configured correctly.");
# Line 223  function word2web_nodeapi(&$node, $op) { Line 249  function word2web_nodeapi(&$node, $op) {
249        }        }
250      case 'submit':      case 'submit':
251      case 'update':      case 'update':
252        if ($html_file = file_check_upload('word_document')) {  /* TODO Modify the validators array to suit your needs.
253       This array is used in the revised file_save_upload */
254      $validators = array(
255        'file_validate_is_image' => array(),
256        'file_validate_image_resolution' => array('85x85'),
257        'file_validate_size' => array(30 * 1024),
258      );
259    
260          if ($html_file = file_save_upload($validators)) {
261          $path = drupal_get_path('module', 'word2web');          $path = drupal_get_path('module', 'word2web');
262          $html_raw = file_get_contents($html_file->filepath);          $html_raw = file_get_contents($html_file->filepath);
263          $html_raw = _word2web_convert_chr($html_raw);          $html_raw = _word2web_convert_chr($html_raw);

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.6.2.1

  ViewVC Help
Powered by ViewVC 1.1.2