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

Diff of /contributions/modules/pblog/pblog.module

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

revision 1.5.2.4, Wed May 7 21:18:30 2008 UTC revision 1.5.2.5, Sun May 18 15:29:31 2008 UTC
# Line 18  $items['pblog/%/%'] = array( Line 18  $items['pblog/%/%'] = array(
18      'access arguments' => array('access pblog'),      'access arguments' => array('access pblog'),
19      'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
20    );    );
21    
22     $items['admin/settings/pblog'] = array(
23        'title' => 'Pblog module settings',
24        'description' => 'Change your settings for pblog module',
25        'page callback' => 'drupal_get_form',
26        'page arguments' => array('pblog_admin'),
27        'access arguments' => array('access administration pages'),
28        'type' => MENU_NORMAL_ITEM,
29       );
30    
31    
32    return $items;    return $items;
33    
# Line 38  function pblog_node_info() { Line 48  function pblog_node_info() {
48    );    );
49  }  }
50    
51    function pblog_access($op, $node) {
52      global $user;
53    
54      if ($op == 'create') {
55        // Only users with permission to do so may create this node type.
56        return user_access('create pblog');
57      }
58    
59      // Users who create a node may edit or delete it later, assuming they have the
60      // necessary permissions.
61      if ($op == 'update' || $op == 'delete') {
62        if (user_access('edit pblog') && ($user->uid == $node->uid)) {
63          return TRUE;
64        }
65      }
66    }
67    
68  function pblog_view($node, $teaser = FALSE, $page = FALSE) {  function pblog_view($node, $teaser = FALSE, $page = FALSE) {
69    $file_dir = file_directory_path();    $file_dir = file_directory_path();
# Line 157  function pblog_image($nid = NULL, $pictu Line 183  function pblog_image($nid = NULL, $pictu
183              && preg_match("/-med.jpg$/", $file)) {              && preg_match("/-med.jpg$/", $file)) {
184              array_push($img_array, "$dir_array[$i]"."/$file");              array_push($img_array, "$dir_array[$i]"."/$file");
185            }            }
186            else if (!preg_match("/-mini.jpg$/", $file) && !preg_match("/-med.jpg$/", $file)) {            else if (!preg_match("/-mini.jpg$/", $file) && !preg_match("/-med.jpg$/", $file)
187                         && !preg_match("/-strip.jpg$/", $file)  ) {
188              array_push($fullsize_img_array, "$dir_array[$i]"."/$file");              array_push($fullsize_img_array, "$dir_array[$i]"."/$file");
189            }            }
190          }          }
# Line 235  function pblog_form($node) { Line 262  function pblog_form($node) {
262    return $form;    return $form;
263  }  }
264    
265    function pblog_update($node){
266      $file = file_save_upload('image');
267      if ($file) {
268        drupal_set_message("file_check_upload = SUCCESS", 'status');
269        // for extra debugging drupal_set_message('$file = '. print_r($file, true), 'status');
270      }
271        else {
272          drupal_set_message("file_save_upload = FAILURE ". print_r($node, true), 'error');
273          drupal_set_message("Your file could not be upload please check it is not bigger than the upload_max_filesize of: ". ini_get(upload_max_filesize), 'error');
274          return;
275        }
276    
277      // full path to the file
278      $fpath = escapeshellcmd($file->filepath);
279    
280      $image_dir = file_create_path("pblog/$node->nid");
281    
282      if (!file_exists($image_dir)) {
283        mkdir($image_dir);
284        drupal_set_message('This is weird, editing pblog but I need to creating directory '. $image_dir, 'status');
285            if (!file_exists("$image_dir")){
286                    drupal_set_message('Unable to Create Directory '. $image_dir, 'error');
287                    }
288      }
289    
290      // check what kind of file it is, zip gzip or just a pic. Then move
291      // unzip or do what ever.
292      $extension = substr(strrchr($file->filename, '.'), 0);
293      switch ($extension) {
294        case ".gz":
295          // untar and gzip stuff in dir
296          `tar xvzf $fpath --directory $image_dir`;
297          `rm /tmp/$fpath`;
298          break;
299        case        ".zip":
300          // assume unzip file into dir
301          // `unzip /tmp/$f -d $image_dir`;
302          // More complex but more portable way of doing things
303          if (class_exists('ZipArchive')) {
304            $zip = new ZipArchive;
305            if ($zip->open($fpath) === TRUE) {
306                $zip->extractTo($image_dir);
307                $zip->close();
308            }
309              else {
310                form_set_error('image', t('The uploaded file was not a zip archive.'));
311              }
312          }
313            else {
314              drupal_set_message("php does not have built in zip support using system call to the unzip binary".'status');
315              `unzip $fpath -d $image_dir`;
316            }
317    
318          `rm $fpath`;
319          break;
320        default:
321          // assume your not dealing with an idiot and copy the file across.
322          // What we actually need to do is loop through all the files and copy the ones that are useful
323          // ie jpg jpeg bmp or gif images
324          $dst = "pblog/$node->nid";
325          file_copy($fpath, $dst);
326          break;
327      }
328      // make thumbnails of all files in the dir.
329      if ($handle = opendir($image_dir)) {
330        while (false !== ($file = readdir($handle))) {
331          if ($file != '.' && $file != '..' && !preg_match("/-mini.jpg$/", $file)
332            && !preg_match("/-med.jpg$/", $file)) {
333            // do a little cleaning
334            $s = escapeshellcmd($file);
335            $s_root = substr($s, 0, -4);
336            // normal thumbnail
337            /* old school using system calls
338            $command = 'convert -size 120x120 "'. $image_dir .'/'. $s .'" -resize 120x120  +profile "*" "'. $image_dir .'/'. $s_root .'-mini.jpg"';
339            exec($command);
340            // black and white thumbnail cos its arty
341            $command2 = 'convert -size 120x120 "'. $image_dir .'/'. $s .'" -resize 120x120  +profile "*" -colorspace gray "'. $image_dir .'/'. $s_root .'-bw-mini.jpg"';
342            exec($command2);
343            // medium size for dialup losers
344            $command3 = 'convert -size 500x375 "'. $image_dir .'/'. $s .'" -resize 500x375  +profile "*"        "'. $image_dir .'/'. $s_root .'-med.jpg"';
345            exec($command3);
346            */
347            image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-strip.jpg', 90, 90);
348            if (file_exists($image_dir .'/'. $s_root .'-strip.jpg')) {
349              drupal_set_message('Creating strip '. $s_root, 'status');
350            } else {
351              drupal_set_message('Unable to creating thumbnail '. $s_root, 'error');
352            }
353    
354            image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-mini.jpg', 120, 120);
355            if (file_exists($image_dir .'/'. $s_root .'-mini.jpg')) {
356              drupal_set_message('Creating thumbnail '. $s_root, 'status');
357            } else {
358              drupal_set_message('Unable to creating thumbnail '. $s_root, 'error');
359            }
360    
361            image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-med.jpg', 500, 375);
362            if (file_exists($image_dir .'/'. $s_root .'-med.jpg')) {
363              drupal_set_message('Creating medium image '. $s_root, 'status');
364            } else {
365              drupal_set_message('Unable to creating medium image '. $s_root, 'error');
366            }
367          }
368        }
369      }
370    }
371    
372  /*  /*
373  * Function should do stuff to data from form.  * Function should do stuff to data from form.
# Line 258  function pblog_insert($node) { Line 391  function pblog_insert($node) {
391    $pblog_dir = file_create_path("/pblog");    $pblog_dir = file_create_path("/pblog");
392    if (!file_exists($pblog_dir)) {    if (!file_exists($pblog_dir)) {
393      mkdir($pblog_dir);      mkdir($pblog_dir);
     // can put another check in here  
394      drupal_set_message('Creating Directory '. $pblog_dir, 'status');      drupal_set_message('Creating Directory '. $pblog_dir, 'status');
395            if (!file_exists($pblog_dir)){
396                    drupal_set_message('Unable to Create Directory '. $image_dir, 'error');
397                    }
398    }    }
399    $image_dir = file_create_path("pblog/$node->nid");    $image_dir = file_create_path("pblog/$node->nid");
400    
401    if (!file_exists("$image_dir")) {    if (!file_exists($image_dir)) {
402      mkdir("$image_dir");      mkdir($image_dir);
403      drupal_set_message('Creating Directory '. $image_dir, 'status');      drupal_set_message('Creating Directory '. $image_dir, 'status');
404            if (!file_exists("$image_dir")){
405                    drupal_set_message('Unable to Create Directory '. $image_dir, 'error');
406                    }
407    }    }
408    
409    // check what kind of file it is, zip gzip or just a pic. Then move    // check what kind of file it is, zip gzip or just a pic. Then move
# Line 358  function pblog_delete(&$node) { Line 496  function pblog_delete(&$node) {
496    }    }
497  }  }
498    
499    function pblog_admin() {
500    
501      $form['onthisdate_maxdisp'] = array(
502        '#type' => 'textfield',
503        '#title' => t('Maximum number of links'),
504        '#default_value' => variable_get('onthisdate_maxdisp', 3),
505        '#size' => 2,
506        '#maxlength' => 2,
507        '#description' => t("The maximum number of links to display in the block."),
508        '#required' => TRUE,
509      );
510    
511      return system_settings_form($form);
512    }

Legend:
Removed from v.1.5.2.4  
changed lines
  Added in v.1.5.2.5

  ViewVC Help
Powered by ViewVC 1.1.2